Check-in [3029dbecda]
Not logged in

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

Overview
Comment:add tk upstream changes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3029dbecda00444a0c203fb6bb5aab13a85fd10b
User & Date: chw 2017-11-28 04:19:38
Context
2017-11-29
05:52
fix for ticket [ec608f3052] check-in: ba57aaa4c4 user: chw tags: trunk
2017-11-28
04:19
add tk upstream changes check-in: 3029dbecda user: chw tags: trunk
2017-11-27
21:24
add tk upstream changes check-in: af0bfe21ca user: chw tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to jni/sdl2tk/macosx/README.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
- 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 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 macOS).
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.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
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).







|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
- 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 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 macOS).
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.

- Unless weak-linking is used, Tcl/Tk built on macOS 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).
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$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 macOS 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.








|
<







58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
$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).


- 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.

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
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, 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).

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:

toplevel .f
tk::unsupported::MacWindowStyle style .f document {metal light opaque closeBox collapseBox resizable standardDocument }

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:

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

- The Cocoa-based TkAqua can be distinguished from the older Carbon-based
version via the [winfo server .] command, example output on macOS 10.5.7:
    Cocoa-based:	CG409.3 Apple AppKit GC 949.46 macOS 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. Building Tcl/Tk on macOS
------------------------------

- At least macOS 10.3 is required to build Tcl and TkX11, and macOS 10.5
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

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/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
--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 is also possible to build with the Xcode IDE via the projects in

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.







|
<
<






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|








|
|
|
<
|
>
|
<











|
>
|







174
175
176
177
178
179
180
181


182
183
184
185
186
187
































188
189
190
191
192
193
194
195
196
197
198
199

200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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



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).

































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. Building Tcl/Tk on macOS
------------------------------

- At least macOS 10.3 is required to build Tcl and TkX11, and macOS 10.6
is required to build TkAqua.  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
by running the command:
xcode-selecct --install


- Tcl/Tk are most easily built as macOS 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
--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 projects in
tk/macosx, but this has not been tested recently. 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.
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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.4
This requires at least gcc 3.1; with gcc 4 or later, set/add to CFLAGS instead:
	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.







|

|







264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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
This requires at least gcc 3.1; with gcc 4 or later, set/add to CFLAGS instead:
	export CFLAGS="-mmacosx-version-min=10.6"
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.
454
455
456
457
458
459
460
461
462
463

464
465
466
467
468
469
470
4.2 Autorelease pools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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. A bit
later on, TkpInit calls [NSAPP _setupEventLoop] which in turn calls
the [NSApp finishLaunching] method.


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
sufficient for safe memory managememt because, as was made painfully







|
|
|
>







419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
4.2 Autorelease pools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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.

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
sufficient for safe memory managememt because, as was made painfully
Changes to jni/sdl2tk/macosx/Wish-Info.plist.in.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	<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>







|







65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	<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>
Changes to jni/sdl2tk/macosx/tkMacOSXDialog.c.
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
    [TYPE_YESNOCANCEL] =	{5, 6, 4},
};

/*
 * Construct a file URL from directory and filename.  Either may
 * be nil.  If both are nil, returns nil.
 */
#if MAC_OS_X_VERSION_MIN_REQUIRED > 1050
static NSURL *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;
}
#endif

#pragma mark TKApplication(TKDialog)

@interface NSColorPanel(TKDialog)
- (void) _setUseModalAppearance: (BOOL) flag;
@end








<










<







165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
    [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 *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;
}


#pragma mark TKApplication(TKDialog)

@interface NSColorPanel(TKDialog)
- (void) _setUseModalAppearance: (BOOL) flag;
@end

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
    }

    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];
	}

	[openpanel beginSheetModalForWindow:parent
	       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
				 file:filename];
#else
	if (directory || filename ) {
	    NSURL * fileURL = getFileURL(directory, filename);
	    [openpanel setDirectoryURL:fileURL];
	}

	modalReturnCode = [openpanel runModal];
#endif
	[NSApp tkFilePanelDidEnd:openpanel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }







|
<
<
<
<
<
<
<
<
<
<










<


<
<
<
<






<







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
    }

    callbackInfo->cmdObj = cmdObj;
    callbackInfo->interp = interp;
    callbackInfo->multiple = multiple;
    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
	parentIsKey = [parent isKeyWindow];










	if (directory || filename ) {
	    NSURL * fileURL = getFileURL(directory, filename);
	    [openpanel setDirectoryURL:fileURL];
	}

	[openpanel beginSheetModalForWindow:parent
	       completionHandler:^(NSInteger returnCode)
	       { [NSApp tkFilePanelDidEnd:openpanel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];

	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:openpanel];
    } else {




	if (directory || filename ) {
	    NSURL * fileURL = getFileURL(directory, filename);
	    [openpanel setDirectoryURL:fileURL];
	}

	modalReturnCode = [openpanel runModal];

	[NSApp tkFilePanelDidEnd:openpanel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }
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
    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]];
	}
	   /*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:@""];
	}
	[savepanel beginSheetModalForWindow:parent
	       completionHandler:^(NSInteger returnCode)
	       { [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];
#endif
	[NSApp tkFilePanelDidEnd:savepanel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }







<
<
<
<
<
<
<
<
<
|













<


<
<
<










<







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
    callbackInfo->cmdObj = cmdObj;
    callbackInfo->interp = interp;
    callbackInfo->multiple = 0;

    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
       parentIsKey = [parent isKeyWindow];









       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:@""];
	}
	[savepanel beginSheetModalForWindow:parent
	       completionHandler:^(NSInteger returnCode)
	       { [NSApp tkFilePanelDidEnd:savepanel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];

	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel];
    } 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];

	[NSApp tkFilePanelDidEnd:savepanel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }
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
    callbackInfo->multiple = 0;
    /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/
    if (!directory) {
	directory = @"/";
    }
    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
	       completionHandler:^(NSInteger returnCode)
	       { [NSApp tkFilePanelDidEnd:panel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];
#endif
	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
    } else {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
	modalReturnCode = [panel runModalForDirectory:directory file:nil];
#else
	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	modalReturnCode = [panel runModal];
#endif
	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }







|
<
<
<
<
<
<
<
<






<


<
<
<


<







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
    callbackInfo->multiple = 0;
    /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/
    if (!directory) {
	directory = @"/";
    }
    parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
    if (haveParentOption && parent && ![parent attachedSheet]) {
	parentIsKey = [parent isKeyWindow];








	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	[panel beginSheetModalForWindow:parent
	       completionHandler:^(NSInteger returnCode)
	       { [NSApp tkFilePanelDidEnd:panel
		       returnCode:returnCode
		       contextInfo:callbackInfo ]; } ];

	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
    } else {



	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
	modalReturnCode = [panel runModal];

	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
		contextInfo:callbackInfo];
    }
    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
    if (parentIsKey) {
	[parent makeKeyWindow];
    }
Changes to jni/sdl2tk/macosx/tkMacOSXEvent.c.
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    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;
}







<







<







85
86
87
88
89
90
91

92
93
94
95
96
97
98

99
100
101
102
103
104
105
    case NSApplicationDefined: {
	id win;
	win = [theEvent window];
	break;
	}
    case NSCursorUpdate:
        break;

    case NSEventTypeGesture:
    case NSEventTypeMagnify:
    case NSEventTypeRotate:
    case NSEventTypeSwipe:
    case NSEventTypeBeginGesture:
    case NSEventTypeEndGesture:
        break;

#endif

    default:
	break; /* return theEvent */
    }
    return processedEvent;
}
Changes to jni/sdl2tk/macosx/tkMacOSXInit.c.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

static char scriptPath[PATH_MAX + 1] = "";

long tkMacOSXMacOSXVersion = 0;

#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







<
<
<
<
<
<
<




<

<
<
<







29
30
31
32
33
34
35







36
37
38
39

40



41
42
43
44
45
46
47

static char scriptPath[PATH_MAX + 1] = "";

long tkMacOSXMacOSXVersion = 0;

#pragma mark TKApplication(TKInit)








@interface TKApplication(TKKeyboard)
- (void) keyboardChanged: (NSNotification *) notification;
@end


#define TKApplication_NSApplicationDelegate <NSApplicationDelegate>



@interface TKApplication(TKWindowEvent) TKApplication_NSApplicationDelegate
- (void) _setupWindowNotifications;
@end

@interface TKApplication(TKMenus)
- (void) _setupMenus;
@end
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    observe(NSApplicationDidBecomeActiveNotification, applicationActivate:);
    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)applicationWillFinishLaunching:(NSNotification *)aNotification
{

    /*
     * Initialize notifications.







<
<
<







91
92
93
94
95
96
97



98
99
100
101
102
103
104
    observe(NSApplicationDidBecomeActiveNotification, applicationActivate:);
    observe(NSApplicationDidResignActiveNotification, applicationDeactivate:);
    observe(NSApplicationDidUnhideNotification, applicationShowHide:);
    observe(NSApplicationDidHideNotification, applicationShowHide:);
    observe(NSApplicationDidChangeScreenParametersNotification, displayChanged:);
    observe(NSTextInputContextKeyboardSelectionDidChangeNotification, keyboardChanged:);
#undef observe



}

-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{

    /*
     * Initialize notifications.
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

	initialized = 1;

	/*
	 * Initialize/check OS version variable for runtime checks.
	 */

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
#   error Mac OS X 10.5 required
#endif

	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) {







|
|







255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

	initialized = 1;

	/*
	 * Initialize/check OS version variable for runtime checks.
	 */

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#   error Mac OS X 10.6 required
#endif

	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) {
Changes to jni/sdl2tk/macosx/tkMacOSXMenu.c.
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@interface TKMenu(TKMenuPrivate)
- (id) initWithTkMenu: (TkMenu *) tkMenu;
- (TkMenu *) tkMenu;
- (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");







<

<
<
<







113
114
115
116
117
118
119

120



121
122
123
124
125
126
127
@interface TKMenu(TKMenuPrivate)
- (id) initWithTkMenu: (TkMenu *) tkMenu;
- (TkMenu *) tkMenu;
- (int) tkIndexOfItem: (NSMenuItem *) menuItem;
- (void) insertItem: (NSMenuItem *) newItem atTkIndex: (NSInteger) index;
@end


#define TKMenu_NSMenuDelegate <NSMenuDelegate>



@interface TKMenu(TKMenuDelegate) TKMenu_NSMenuDelegate
@end

@implementation TKMenu
- (void) setSpecial: (NSUInteger) special
{
    NSAssert(!_tkSpecial, @"Cannot change specialness of a special menu");
Changes to jni/sdl2tk/macosx/tkMacOSXNotify.c.
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
	do {
	    modalSession = TkMacOSXGetModalSession();
	    	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:NO];
	    /* 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];
	    if (currentEvent) {
		/* Generate Xevents. */
		int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);







<



<
<
<
<
<







272
273
274
275
276
277
278

279
280
281





282
283
284
285
286
287
288
	do {
	    modalSession = TkMacOSXGetModalSession();
	    	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:NO];
	    /* We must not steal any events during LiveResize. */

	    if (testEvent && [[testEvent window] inLiveResize]) {
		break;
	    }





	    currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
					      untilDate:[NSDate distantPast]
						 inMode:GetRunLoopMode(modalSession)
						dequeue:YES];
	    if (currentEvent) {
		/* Generate Xevents. */
		int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
Changes to jni/sdl2tk/macosx/tkMacOSXPrivate.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
	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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







55
56
57
58
59
60
61





















62
63
64
65
66
67
68
	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__






















/*
 * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h.
 */

#undef kComponentSignatureString
#undef COMPONENT_SIGNATURE
Changes to jni/sdl2tk/macosx/tkMacOSXWindowEvent.c.
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#pragma mark TKApplication(TKWindowEvent)

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
extern NSString *NSWindowWillOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOnScreenNotification;
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, _cmd, notification);







<
<
<
<

<
|
<







38
39
40
41
42
43
44




45

46

47
48
49
50
51
52
53

#pragma mark TKApplication(TKWindowEvent)

#ifdef TK_MAC_DEBUG_NOTIFICATIONS
extern NSString *NSWindowWillOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOnScreenNotification;
extern NSString *NSWindowDidOrderOffScreenNotification;




#endif




@implementation TKApplication(TKWindowEvent)

- (void) windowActivation: (NSNotification *) notification
{
#ifdef TK_MAC_DEBUG_NOTIFICATIONS
    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
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
 *
 *----------------------------------------------------------------------
 */

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
    isFrontProcess = [NSRunningApplication currentApplication].active;
#endif
    return (isFrontProcess == true);
}

#pragma mark TKContentView

#import <ApplicationServices/ApplicationServices.h>

/*







<
<
<
<
<
<
<
<
|
<
<







740
741
742
743
744
745
746








747


748
749
750
751
752
753
754
 *
 *----------------------------------------------------------------------
 */

int
Tk_MacOSXIsAppInFront(void)
{








    return ([NSRunningApplication currentApplication].active == true);


}

#pragma mark TKContentView

#import <ApplicationServices/ApplicationServices.h>

/*
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

- (BOOL) isOpaque
{
    NSWindow *w = [self window];

    if (opaqueTag) {
      return YES;
	} else {

     return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
    	    ![w isOpaque]) ? NO : YES);
    }
}

- (BOOL) wantsDefaultClipping
{
    return NO;
}








<
<
<
<
|

<







954
955
956
957
958
959
960




961
962

963
964
965
966
967
968
969
    Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
}

- (BOOL) isOpaque
{
    NSWindow *w = [self window];





      return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) ||
    	    ![w isOpaque]) ? NO : YES);

}

- (BOOL) wantsDefaultClipping
{
    return NO;
}

Changes to jni/sdl2tk/macosx/tkMacOSXWm.c.
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	| 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, },







<
<
<







52
53
54
55
56
57
58



59
60
61
62
63
64
65
	| kWindowHideOnFullScreenAttribute  | kWindowNoConstrainAttribute \
	| kWindowNoShadowAttribute	    | kWindowLiveResizeAttribute \
	| kWindowOpaqueForEventsAttribute   | kWindowIgnoreClicksAttribute \
	| kWindowDoesNotCycleAttribute	    | tkWindowDoesNotHideAttribute \
	| tkCanJoinAllSpacesAttribute	    | tkMoveToActiveSpaceAttribute \
	| tkNonactivatingPanelAttribute	    | tkHUDWindowAttribute)





static const struct {
    const UInt64 validAttrs, defaultAttrs, forceOnAttrs, forceOffAttrs;
    int flags; NSUInteger styleMask;
} macClassAttrs[] = {
    [kAlertWindowClass] = {
	.defaultAttrs = kWindowDoesNotCycleAttribute, },
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
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);

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
#define TK_GOT_AT_LEAST_SNOW_LEOPARD 1
#endif

#pragma mark TKWindow(TKWm)

#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
@interface NSWindow(TkWm)
- (void) setCanCycle: (BOOL) canCycleFlag;
@end
#endif

@interface NSDrawerWindow : NSWindow
{
    id _i1, _i2;
}
@end









<
<
<
<


<
<
<
<
<
<







359
360
361
362
363
364
365




366
367






368
369
370
371
372
373
374
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);





#pragma mark TKWindow(TKWm)







@interface NSDrawerWindow : NSWindow
{
    id _i1, _i2;
}
@end


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
    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)) {







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







5241
5242
5243
5244
5245
5246
5247









































5248
5249
5250
5251
5252
5253
5254
    int index, i;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option 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)) {
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
        /*
	 * 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;







<
<
<
<
<
<
<
<
<
<
<
<
<
<







5622
5623
5624
5625
5626
5627
5628














5629
5630
5631
5632
5633
5634
5635
        /*
	 * Workaround for [Bug 2824538]: Texured windows are draggable
	 *                               from opaque content.
	 */
	[window setMovableByWindowBackground:NO];
    }















    [window setDocumentEdited:NO];
    wmPtr->window = window;
    macWin->view = window.contentView;
    TkMacOSXApplyWindowAttributes(winPtr, window);

    NSRect geometry = InitialWindowBounds(winPtr, window);
    geometry.size.width +=  structureRect.size.width;
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
		initial) {
	    NSWindowCollectionBehavior b = NSWindowCollectionBehaviorDefault;
	    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:
		    [NSPanel class]] && [macWindow isFloatingPanel] ?
		    kCGFloatingWindowLevel : kCGNormalWindowLevel)];
	}







<





<

<
<
<
<
<
<
<
<
<
<







6312
6313
6314
6315
6316
6317
6318

6319
6320
6321
6322
6323

6324










6325
6326
6327
6328
6329
6330
6331
		initial) {
	    NSWindowCollectionBehavior b = NSWindowCollectionBehaviorDefault;
	    if (newAttributes & tkCanJoinAllSpacesAttribute) {
		b |= NSWindowCollectionBehaviorCanJoinAllSpaces;
	    } else if (newAttributes & tkMoveToActiveSpaceAttribute) {
		b |= NSWindowCollectionBehaviorMoveToActiveSpace;
	    }

	    if (newAttributes & kWindowDoesNotCycleAttribute) {
		b |= NSWindowCollectionBehaviorIgnoresCycle;
	    } else {
		b |= NSWindowCollectionBehaviorParticipatesInCycle;
	    }

	    [macWindow setCollectionBehavior:b];










	}
	if ((wmPtr->flags & WM_TOPMOST) != (oldFlags & WM_TOPMOST)) {
	    [macWindow setLevel:(wmPtr->flags & WM_TOPMOST) ?
		    kCGUtilityWindowLevel : ([macWindow isKindOfClass:
		    [NSPanel class]] && [macWindow isFloatingPanel] ?
		    kCGFloatingWindowLevel : kCGNormalWindowLevel)];
	}
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
    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.







<

<







6449
6450
6451
6452
6453
6454
6455

6456

6457
6458
6459
6460
6461
6462
6463
    TkWindow *winPtr,
    NSWindow *window,
    int fullscreen,
    Tcl_Interp *interp)
{
    WmInfo *wmPtr = winPtr->wmInfoPtr;
    int result = TCL_OK, wasFullscreen = (wmPtr->flags & WM_FULLSCREEN);

    static unsigned long prevMask = 0, prevPres = 0;


    if (fullscreen) {
	int screenWidth =  WidthOfScreen(Tk_Screen(winPtr));
	int screenHeight = HeightOfScreen(Tk_Screen(winPtr));

	/*
	 * Check max width and height if set by the user.
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
		[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];
	Tk_MapWindow((Tk_Window) winPtr);
#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)) {
	Tk_UnmapWindow((Tk_Window) winPtr);
	UInt64 oldAttributes = wmPtr->attributes;
	NSRect bounds = NSMakeRect(wmPtr->configX, tkMacOSXZeroScreenHeight -
		(wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight),







<
<
<
<
<
<
<
<






<


<
<


<







6490
6491
6492
6493
6494
6495
6496








6497
6498
6499
6500
6501
6502

6503
6504


6505
6506

6507
6508
6509
6510
6511
6512
6513
		[window setFrame:[window frameRectForContentRect:
			screenBounds] display:YES];
		wmPtr->flags &= ~WM_SYNC_PENDING;
	    }
	    wmPtr->flags |= WM_FULLSCREEN;
	}









	prevMask = [window styleMask];
	prevPres = [NSApp presentationOptions];
	[window setStyleMask: NSBorderlessWindowMask];
	[NSApp setPresentationOptions: NSApplicationPresentationAutoHideDock
	                          | NSApplicationPresentationAutoHideMenuBar];
	Tk_MapWindow((Tk_Window) winPtr);

    } else {
	wmPtr->flags &= ~WM_FULLSCREEN;


	[NSApp setPresentationOptions: prevPres];
	[window setStyleMask: prevMask];

    }

    if (wasFullscreen && !(wmPtr->flags & WM_FULLSCREEN)) {
	Tk_UnmapWindow((Tk_Window) winPtr);
	UInt64 oldAttributes = wmPtr->attributes;
	NSRect bounds = NSMakeRect(wmPtr->configX, tkMacOSXZeroScreenHeight -
		(wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight),