Import Tk 8.6.11

This commit is contained in:
Steve Dower
2021-03-30 00:54:10 +01:00
parent 42c69189d9
commit 070b8750b0
403 changed files with 21608 additions and 16269 deletions

View File

@@ -23,7 +23,7 @@
#define modalOK NSModalResponseOK
#define modalCancel NSModalResponseCancel
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090
#define modalOther -1
#define modalOther -1 // indicates that the -command option was used.
#define modalError -2
/*
@@ -52,6 +52,10 @@ typedef struct {
* filter. */
} filepanelFilterInfo;
/*
* Only one of these is needed for the application, so they can be static.
*/
static filepanelFilterInfo filterInfo;
static NSOpenPanel *openpanel;
static NSSavePanel *savepanel;
@@ -198,19 +202,24 @@ getFileURL(
@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: (NSInteger) returnCode contextInfo: (void *) contextInfo
returnCode: (NSModalResponse) returnCode
contextInfo: (void *) contextInfo
{
FilePanelCallbackInfo *callbackInfo = contextInfo;
@@ -232,7 +241,7 @@ getFileURL(
callbackInfo->cmdObj, &objc, &objv);
if (result == TCL_OK && objc) {
tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
tmpv[objc] = resultObj;
TkBackgroundEvalObjv(callbackInfo->interp, objc + 1, tmpv,
@@ -245,13 +254,13 @@ getFileURL(
} else if (returnCode == modalCancel) {
Tcl_ResetResult(callbackInfo->interp);
}
if (panel == [NSApp modalWindow]) {
[NSApp stopModalWithCode:returnCode];
}
if (callbackInfo->cmdObj) {
Tcl_DecrRefCount(callbackInfo->cmdObj);
}
if (callbackInfo) {
ckfree(callbackInfo);
}
[NSApp stopModalWithCode:returnCode];
}
- (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode
@@ -270,7 +279,7 @@ getFileURL(
callbackInfo->cmdObj, &objc, &objv);
if (result == TCL_OK && objc) {
tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
tmpv[objc] = resultObj;
TkBackgroundEvalObjv(callbackInfo->interp, objc + 1, tmpv,
@@ -293,7 +302,6 @@ getFileURL(
- (void)selectFormat:(id)sender {
NSPopUpButton *button = (NSPopUpButton *)sender;
filterInfo.fileTypeIndex = [button indexOfSelectedItem];
if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) {
[openpanel setAllowsOtherFileTypes:YES];
@@ -343,21 +351,50 @@ static NSInteger showOpenSavePanel(
{
NSInteger modalReturnCode;
if (parent && ![parent attachedSheet] && [NSApp macMinorVersion] < 15) {
if (parent && ![parent attachedSheet]) {
[panel beginSheetModalForWindow:parent
completionHandler:^(NSInteger returnCode) {
completionHandler:^(NSModalResponse returnCode) {
[NSApp tkFilePanelDidEnd:panel
returnCode:returnCode
contextInfo:callbackInfo ];
}];
modalReturnCode = callbackInfo->cmdObj ? modalOther :
[NSApp runModalForWindow:panel];
/*
* The sheet has been prepared, so now we have to run it as a modal
* window. Using [NSApp runModalForWindow:] on macOS 10.15 or later
* generates warnings on stderr. But using [NSOpenPanel runModal] or
* [NSSavePanel runModal] on 10.14 or earler does not cause the
* completion handler to run when the panel is closed.
*/
if ([NSApp macOSVersion] > 101400) {
modalReturnCode = [panel runModal];
} else {
modalReturnCode = [NSApp runModalForWindow:panel];
}
} else {
modalReturnCode = [panel runModal];
[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
contextInfo:callbackInfo];
/*
* For the standalone file dialog, completion handlers do not work
* at all on macOS 10.14 and earlier.
*/
if ([NSApp macOSVersion] > 101400) {
[panel beginWithCompletionHandler:^(NSModalResponse returnCode) {
[NSApp tkFilePanelDidEnd:panel
returnCode:returnCode
contextInfo:callbackInfo ];
}];
modalReturnCode = [panel runModal];
} else {
modalReturnCode = [panel runModal];
[NSApp tkFilePanelDidEnd:panel
returnCode:modalReturnCode
contextInfo:callbackInfo ];
[panel close];
}
}
return modalReturnCode;
return callbackInfo->cmdObj ? modalOther : modalReturnCode;
}
/*
@@ -654,8 +691,6 @@ Tk_GetOpenFileObjCmd(
NSInteger modalReturnCode = modalError;
BOOL parentIsKey = NO;
[openpanel setDelegate:NSApp];
for (i = 1; i < objc; i += 2) {
if (Tcl_GetIndexFromObjStruct(interp, objv[i], openOptionStrings,
sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
@@ -725,7 +760,7 @@ Tk_GetOpenFileObjCmd(
* panel. Prepend the title to the message in this case.
*/
if ([NSApp macMinorVersion] > 10) {
if ([NSApp macOSVersion] > 101000) {
if (message) {
NSString *fullmessage =
[[NSString alloc] initWithFormat:@"%@\n%@", title, message];
@@ -763,6 +798,7 @@ Tk_GetOpenFileObjCmd(
[label setBezeled:NO];
[label setDrawsBackground:NO];
[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
[popupButton setTarget:NSApp];
[popupButton setAction:@selector(selectFormat:)];
[accessoryView addSubview:label];
[accessoryView addSubview:popupButton];
@@ -804,7 +840,7 @@ Tk_GetOpenFileObjCmd(
}
Tcl_IncrRefCount(cmdObj);
}
callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
callbackInfo = (FilePanelCallbackInfo *)ckalloc(sizeof(FilePanelCallbackInfo));
callbackInfo->cmdObj = cmdObj;
callbackInfo->interp = interp;
callbackInfo->multiple = multiple;
@@ -814,7 +850,7 @@ Tk_GetOpenFileObjCmd(
[openpanel setDirectoryURL:fileURL];
}
if (haveParentOption) {
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
parentIsKey = parent && [parent isKeyWindow];
} else {
parent = nil;
@@ -866,15 +902,15 @@ Tk_GetOpenFileObjCmd(
selectedFilterIndex = filterInfo.fileTypeIndex; // The preselection from the typevariable
selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
} else {
NSUInteger i;
NSUInteger j;
for (i = 0; i < [filterInfo.fileTypeNames count]; i++) {
if (filterCompatible(extension, i)) {
selectedFilterIndex = i;
for (j = 0; j < [filterInfo.fileTypeNames count]; j++) {
if (filterCompatible(extension, j)) {
selectedFilterIndex = j;
break;
}
}
if (i == selectedFilterIndex) {
if (j == selectedFilterIndex) {
selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
} else {
selectedFilter = @"";
@@ -913,7 +949,7 @@ Tk_GetSaveFileObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tk_Window tkwin = clientData;
Tk_Window tkwin = (Tk_Window)clientData;
char *str;
int i, result = TCL_ERROR, haveParentOption = 0;
int confirmOverwrite = 1;
@@ -928,8 +964,6 @@ Tk_GetSaveFileObjCmd(
NSInteger modalReturnCode = modalError;
BOOL parentIsKey = NO;
[savepanel setDelegate:NSApp];
for (i = 1; i < objc; i += 2) {
if (Tcl_GetIndexFromObjStruct(interp, objv[i], saveOptionStrings,
sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
@@ -1050,8 +1084,8 @@ Tk_GetSaveFileObjCmd(
[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
[popupButton selectItemAtIndex:filterInfo.fileTypeIndex];
[popupButton setTarget:NSApp];
[popupButton setAction:@selector(saveFormat:)];
[accessoryView addSubview:label];
[accessoryView addSubview:popupButton];
@@ -1082,7 +1116,7 @@ Tk_GetSaveFileObjCmd(
}
Tcl_IncrRefCount(cmdObj);
}
callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
callbackInfo = (FilePanelCallbackInfo *)ckalloc(sizeof(FilePanelCallbackInfo));
callbackInfo->cmdObj = cmdObj;
callbackInfo->interp = interp;
callbackInfo->multiple = 0;
@@ -1102,7 +1136,7 @@ Tk_GetSaveFileObjCmd(
[savepanel setNameFieldStringValue:@""];
}
if (haveParentOption) {
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
parentIsKey = parent && [parent isKeyWindow];
} else {
parent = nil;
@@ -1157,7 +1191,7 @@ Tk_ChooseDirectoryObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tk_Window tkwin = clientData;
Tk_Window tkwin = (Tk_Window)clientData;
char *str;
int i, result = TCL_ERROR, haveParentOption = 0;
int index, len, mustexist = 0;
@@ -1171,8 +1205,6 @@ Tk_ChooseDirectoryObjCmd(
NSInteger modalReturnCode = modalError;
BOOL parentIsKey = NO;
[panel setDelegate:NSApp];
for (i = 1; i < objc; i += 2) {
if (Tcl_GetIndexFromObjStruct(interp, objv[i], chooseOptionStrings,
sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
@@ -1233,7 +1265,7 @@ Tk_ChooseDirectoryObjCmd(
}
Tcl_IncrRefCount(cmdObj);
}
callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
callbackInfo = (FilePanelCallbackInfo *)ckalloc(sizeof(FilePanelCallbackInfo));
callbackInfo->cmdObj = cmdObj;
callbackInfo->interp = interp;
callbackInfo->multiple = 0;
@@ -1246,10 +1278,10 @@ Tk_ChooseDirectoryObjCmd(
if (!directory) {
directory = @"/";
}
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
if (haveParentOption) {
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
parentIsKey = parent && [parent isKeyWindow];
} else {
parent = nil;
@@ -1283,64 +1315,9 @@ Tk_ChooseDirectoryObjCmd(
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];
/*
* This replaces the old about dialog with a standard alert that displays
* correctly on 10.14.
*/
NSString *version = @"Tcl " TCL_PATCH_LEVEL " & Tk " TCL_PATCH_LEVEL;
NSString *url = @"www.tcl-lang.org";
NSTextView *credits = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,300,300)];
NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
NSDictionary *textAttributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[credits insertText: [[NSAttributedString alloc]
initWithString:[NSString stringWithFormat: @"\n"
"Tcl and Tk are distributed under a modified BSD license: "
"www.tcl.tk/software/tcltk/license.html\n\n"
"%1$C 1987-%2$@ Tcl Core Team and Contributers.\n\n"
"%1$C 2011-%2$@ Kevin Walzer/WordTech Communications LLC.\n\n"
"%1$C 2014-%2$@ Marc Culler.\n\n"
"%1$C 2002-2012 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:textAttributes]
replacementRange:NSMakeRange(0,0)];
[credits setDrawsBackground:NO];
[credits setEditable:NO];
NSAlert *about = [[NSAlert alloc] init];
[[about window] setTitle:@"About Tcl & Tk"];
[about setMessageText: version];
[about setInformativeText:url];
about.accessoryView = credits;
[about runModal];
[about release];
[NSApp orderFrontStandardAboutPanel:nil];
}
/*
*----------------------------------------------------------------------
*
@@ -1359,7 +1336,7 @@ TkAboutDlg(void)
int
TkMacOSXStandardAboutPanelObjCmd(
ClientData clientData, /* Unused. */
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
@@ -1368,7 +1345,7 @@ TkMacOSXStandardAboutPanelObjCmd(
Tcl_WrongNumArgs(interp, 1, objv, NULL);
return TCL_ERROR;
}
TkAboutDlg();
[NSApp orderFrontStandardAboutPanel:nil];
return TCL_OK;
}
@@ -1395,7 +1372,7 @@ Tk_MessageBoxObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tk_Window tkwin = clientData;
Tk_Window tkwin = (Tk_Window)clientData;
char *str;
int i, result = TCL_ERROR, haveParentOption = 0;
int index, typeIndex, iconIndex, indexDefaultOption = 0;
@@ -1529,11 +1506,11 @@ Tk_MessageBoxObjCmd(
}
Tcl_IncrRefCount(cmdObj);
}
callbackInfo = ckalloc(sizeof(AlertCallbackInfo));
callbackInfo = (AlertCallbackInfo *)ckalloc(sizeof(AlertCallbackInfo));
callbackInfo->cmdObj = cmdObj;
callbackInfo->interp = interp;
callbackInfo->typeIndex = typeIndex;
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
parent = TkMacOSXGetNSWindowForDrawable(((TkWindow *)tkwin)->window);
if (haveParentOption && parent && ![parent attachedSheet]) {
parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
@@ -1630,6 +1607,7 @@ enum FontchooserOption {
- (void) changeFont: (id) sender
{
NSFontManager *fm = [NSFontManager sharedFontManager];
(void)sender;
if ([fm currentFontAction] == NSViaPanelFontAction) {
NSFont *font = [fm convertFont:fontPanelFont];
@@ -1653,14 +1631,16 @@ enum FontchooserOption {
}
}
- (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, _cmd, notification);
@@ -1684,7 +1664,7 @@ enum FontchooserOption {
* None.
*
* Side effects:
* Additional events may be place on the Tk event queue.
* Additional events may be placed on the Tk event queue.
*
*----------------------------------------------------------------------
*/
@@ -1718,7 +1698,7 @@ FontchooserEvent(
result = Tcl_ListObjGetElements(fontchooserInterp,
fcdPtr->cmdObj, &objc, &objv);
if (result == TCL_OK) {
tmpv = ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
tmpv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
memcpy(tmpv, objv, sizeof(Tcl_Obj *) * objc);
tmpv[objc] = fontObj;
TkBackgroundEvalObjv(fontchooserInterp, objc + 1, tmpv,
@@ -1760,7 +1740,7 @@ FontchooserCget(
case FontchooserParent:
if (fcdPtr->parent != None) {
resObj = Tcl_NewStringObj(
((TkWindow *) fcdPtr->parent)->pathName, -1);
((TkWindow *)fcdPtr->parent)->pathName, -1);
} else {
resObj = Tcl_NewStringObj(".", 1);
}
@@ -1981,14 +1961,14 @@ static int
FontchooserShowCmd(
ClientData clientData, /* Main window */
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
TCL_UNUSED(int),
TCL_UNUSED(Tcl_Obj *const *))
{
FontchooserData *fcdPtr = Tcl_GetAssocData(interp, "::tk::fontchooser",
NULL);
if (fcdPtr->parent == None) {
fcdPtr->parent = (Tk_Window) clientData;
fcdPtr->parent = (Tk_Window)clientData;
Tk_CreateEventHandler(fcdPtr->parent, StructureNotifyMask,
FontchooserParentEventHandler, fcdPtr);
}
@@ -2027,10 +2007,10 @@ FontchooserShowCmd(
static int
FontchooserHideCmd(
ClientData clientData, /* Main window */
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
TCL_UNUSED(void *), /* Main window */
TCL_UNUSED(Tcl_Interp *),
TCL_UNUSED(int),
TCL_UNUSED(Tcl_Obj *const *))
{
NSFontPanel *fp = [[NSFontManager sharedFontManager] fontPanel:NO];
@@ -2129,9 +2109,9 @@ DeleteFontchooserData(
MODULE_SCOPE int
TkInitFontchooser(
Tcl_Interp *interp,
ClientData clientData)
TCL_UNUSED(void *))
{
FontchooserData *fcdPtr = ckalloc(sizeof(FontchooserData));
FontchooserData *fcdPtr = (FontchooserData *)ckalloc(sizeof(FontchooserData));
bzero(fcdPtr, sizeof(FontchooserData));
Tcl_SetAssocData(interp, "::tk::fontchooser", DeleteFontchooserData,