diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/README | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXBitmap.c | 23 | ||||
-rw-r--r-- | macosx/tkMacOSXColor.c | 29 | ||||
-rw-r--r-- | macosx/tkMacOSXDialog.c | 115 | ||||
-rw-r--r-- | macosx/tkMacOSXFileTypes.c | 112 | ||||
-rw-r--r-- | macosx/tkMacOSXFileTypes.h | 144 | ||||
-rw-r--r-- | macosx/tkMacOSXFont.c | 6 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 37 | ||||
-rw-r--r-- | macosx/tkMacOSXMenu.c | 88 | ||||
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 7 | ||||
-rw-r--r-- | macosx/tkMacOSXNotify.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXPrivate.h | 13 | ||||
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 4 | ||||
-rw-r--r-- | macosx/tkMacOSXTest.c | 4 | ||||
-rw-r--r-- | macosx/tkMacOSXWindowEvent.c | 4 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 15 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 2 |
17 files changed, 479 insertions, 128 deletions
diff --git a/macosx/README b/macosx/README index 4ed334f..db51db2 100644 --- a/macosx/README +++ b/macosx/README @@ -548,7 +548,7 @@ 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 +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 diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c index 4f51fc6..30ed5fe 100644 --- a/macosx/tkMacOSXBitmap.c +++ b/macosx/tkMacOSXBitmap.c @@ -13,6 +13,7 @@ #include "tkMacOSXPrivate.h" #include "tkMacOSXConstants.h" + /* * This structure holds information about native bitmaps. */ @@ -174,9 +175,8 @@ TkpCreateNativeBitmap( Display *display, const void *source) /* Info about the icon to build. */ { - NSString *iconUTI = OSTYPE_TO_UTI(PTR2UINT(source)); - NSImage *iconImage = [[NSWorkspace sharedWorkspace] - iconForFileType: iconUTI]; + NSString *filetype = [NSString stringWithUTF8String:(char *)source]; + NSImage *iconImage = TkMacOSXIconForFileType(filetype); CGSize size = CGSizeMake(builtInIconSize, builtInIconSize); Pixmap pixmap = PixmapFromImage(display, iconImage, size); return pixmap; @@ -253,7 +253,6 @@ TkpGetNativeAppBitmap( NSString *string; NSImage *image = nil; NSSize size = { .width = builtInIconSize, .height = builtInIconSize }; - if (iconBitmapTable.buckets && (hPtr = Tcl_FindHashEntry(&iconBitmapTable, name))) { OSType type; @@ -268,12 +267,12 @@ TkpGetNativeAppBitmap( break; case ICON_FILETYPE: string = [NSString stringWithUTF8String:iconBitmap->value]; - image = [[NSWorkspace sharedWorkspace] iconForFileType:string]; + image = TkMacOSXIconForFileType(string); break; case ICON_OSTYPE: if (OSTypeFromString(iconBitmap->value, &type) == TCL_OK) { - string = NSFileTypeForHFSTypeCode(type); - image = [[NSWorkspace sharedWorkspace] iconForFileType:string]; + string = [NSString stringWithUTF8String:iconBitmap->value]; + image = TkMacOSXIconForFileType(string); } break; case ICON_SYSTEMTYPE: @@ -312,11 +311,15 @@ TkpGetNativeAppBitmap( *height = size.height; pixmap = PixmapFromImage(display, image, NSSizeToCGSize(size)); } 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) { - NSString *iconUTI = OSTYPE_TO_UTI(iconType); - NSImage *iconImage = [[NSWorkspace sharedWorkspace] - iconForFileType: iconUTI]; + NSString *iconUTI = TkMacOSXOSTypeToUTI(iconType); + NSImage *iconImage = TkMacOSXIconForFileType(iconUTI); pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size)); } } diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 3951683..39e443e 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -31,6 +31,7 @@ static SystemColorDatum **systemColorIndex; static NSAppearance *lightAqua = nil; static NSAppearance *darkAqua = nil; #endif + static NSColorSpace* sRGB = NULL; static const CGFloat WINDOWBACKGROUND[4] = {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0}; @@ -299,7 +300,7 @@ GetRGBA( /* * Prior to OSX 10.14, getComponents returns black when applied to - * windowBackGroundColor. + * windowBackgroundColor. */ if ([NSApp macOSVersion] < 101400) { @@ -417,6 +418,7 @@ SetCGColorComponents( if (entry->type == HIBrush) { OSStatus err = ChkErr(HIThemeBrushCreateCGColor, entry->value, c); + [pool drain]; return err == noErr; } GetRGBA(entry, pixel, rgba); @@ -456,7 +458,7 @@ TkMacOSXInDarkMode(Tk_Window tkwin) if (view) { name = [[view effectiveAppearance] name]; } else { - name = [[NSAppearance currentAppearance] name]; + name = [[NSApp effectiveAppearance] name]; } return (name == NSAppearanceNameDarkAqua); } @@ -630,11 +632,9 @@ TkpGetColor( Colormap colormap = tkwin ? Tk_Colormap(tkwin) : noColormap; NSView *view = nil; static Bool initialized = NO; - static NSColorSpace* sRGB = nil; if (!initialized) { initialized = YES; - sRGB = [NSColorSpace sRGBColorSpace]; initColorTable(); } if (tkwin) { @@ -662,19 +662,30 @@ TkpGetColor( CGFloat rgba[4]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 if (@available(macOS 10.14, *)) { - NSAppearance *savedAppearance = [NSAppearance currentAppearance]; - NSAppearance *windowAppearance = savedAppearance; + NSAppearance *windowAppearance; if (view) { windowAppearance = [view effectiveAppearance]; + } else { + windowAppearance = [NSApp effectiveAppearance]; } if ([windowAppearance name] == NSAppearanceNameDarkAqua) { colormap = darkColormap; } else { colormap = lightColormap; } - [NSAppearance setCurrentAppearance:windowAppearance]; - GetRGBA(entry, p.ulong, rgba); - [NSAppearance setCurrentAppearance:savedAppearance]; + if (@available(macOS 11.0, *)) { + CGFloat *rgbaPtr = rgba; + [windowAppearance performAsCurrentDrawingAppearance:^{ + GetRGBA(entry, p.ulong, rgbaPtr); + }]; + } 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); } diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index f850fbb..8af298b 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -6,7 +6,8 @@ * Copyright (c) 1996-1997 Sun Microsystems, Inc. * Copyright (c) 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> - * Copyright (c) 2017 Christian Gollwitzer. + * Copyright (c) 2017 Christian Gollwitzer + * 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. @@ -26,6 +27,30 @@ #define modalOther -1 // indicates that the -command option was used. #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. */ @@ -93,7 +118,7 @@ static const char *const chooseOptionStrings[] = { }; enum chooseOptions { CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, CHOOSE_PARENT, - CHOOSE_TITLE, CHOOSE_COMMAND, + CHOOSE_TITLE, CHOOSE_COMMAND }; typedef struct { Tcl_Interp *interp; @@ -107,7 +132,7 @@ static const char *const alertOptionStrings[] = { }; 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; @@ -302,11 +327,11 @@ getFileURL( * any file. */ - [openpanel setAllowedFileTypes:nil]; + setAllowedFileTypes(openpanel, nil); } else { NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; - [openpanel setAllowedFileTypes:allowedtypes]; + setAllowedFileTypes(openpanel, allowedtypes); [openpanel setAllowsOtherFileTypes:NO]; } @@ -319,11 +344,11 @@ getFileURL( if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) { [savepanel setAllowsOtherFileTypes:YES]; - [savepanel setAllowedFileTypes:nil]; + setAllowedFileTypes(savepanel, nil); } else { NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; - [savepanel setAllowedFileTypes:allowedtypes]; + setAllowedFileTypes(savepanel, allowedtypes); [savepanel setAllowsOtherFileTypes:NO]; } @@ -461,7 +486,7 @@ Tk_ChooseColorObjCmd( [colorPanel setShowsAlpha: NO]; [colorPanel _setUseModalAppearance:YES]; if (title) { - NSString *s = [[NSString alloc] initWithUTF8String:title]; + NSString *s = [[TKNSString alloc] initWithTclUtfBytes:title length:-1]; [colorPanel setTitle:s]; [s release]; @@ -533,7 +558,7 @@ parseFileFilters( if (filterInfo.doFileTypes) { for (FileFilter *filterPtr = fl.filters; filterPtr; filterPtr = filterPtr->next) { - NSString *name = [[NSString alloc] initWithUTF8String: filterPtr->name]; + NSString *name = [[TKNSString alloc] initWithTclUtfBytes: filterPtr->name length:-1]; [filterInfo.fileTypeNames addObject:name]; [name release]; @@ -551,7 +576,7 @@ parseFileFilters( str++; } if (*str) { - NSString *extension = [[NSString alloc] initWithUTF8String:str]; + NSString *extension = [[TKNSString alloc] initWithTclUtfBytes:str length:-1]; if (![filterInfo.allowedExtensions containsObject:extension]) { [filterInfo.allowedExtensions addObject:extension]; } @@ -604,7 +629,7 @@ parseFileFilters( const char *selectedFileType = Tcl_GetString(selectedFileTypeObj); NSString *selectedFileTypeStr = - [[NSString alloc] initWithUTF8String:selectedFileType]; + [[TKNSString alloc] initWithTclUtfBytes:selectedFileType length:-1]; NSUInteger index = [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr]; @@ -695,20 +720,21 @@ Tk_GetOpenFileObjCmd( case OPEN_INITDIR: str = Tcl_GetStringFromObj(objv[i + 1], &len); if (len) { - directory = [[[NSString alloc] initWithUTF8String:str] + directory = [[[TKNSString alloc] initWithTclUtfBytes:str length:len] autorelease]; } break; case OPEN_INITFILE: str = Tcl_GetStringFromObj(objv[i + 1], &len); if (len) { - filename = [[[NSString alloc] initWithUTF8String:str] + filename = [[[TKNSString alloc] initWithTclUtfBytes:str length:len] autorelease]; } break; case OPEN_MESSAGE: - message = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetStringFromObj(objv[i + 1], &len); + message = [[TKNSString alloc] initWithTclUtfBytes: + str length:len]; break; case OPEN_MULTIPLE: if (Tcl_GetBooleanFromObj(interp, objv[i + 1], @@ -725,8 +751,9 @@ Tk_GetOpenFileObjCmd( haveParentOption = 1; break; case OPEN_TITLE: - title = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetStringFromObj(objv[i + 1], &len); + title = [[TKNSString alloc] initWithTclUtfBytes: + str length:len]; break; case OPEN_TYPEVARIABLE: typeVariablePtr = objv[i + 1]; @@ -801,9 +828,9 @@ Tk_GetOpenFileObjCmd( [openpanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]]; */ - [openpanel setAllowedFileTypes:filterInfo.allowedExtensions]; + setAllowedFileTypes(openpanel, filterInfo.allowedExtensions); } else { - [openpanel setAllowedFileTypes:filterInfo.allowedExtensions]; + setAllowedFileTypes(openpanel, filterInfo.allowedExtensions); } if (filterInfo.allowedExtensionsAllowAll) { [openpanel setAllowsOtherFileTypes:YES]; @@ -960,10 +987,10 @@ Tk_GetSaveFileObjCmd( case SAVE_DEFAULT: str = Tcl_GetStringFromObj(objv[i + 1], &len); while (*str && (*str == '*' || *str == '.')) { - str++; + str++; len--; } if (*str) { - defaultType = [[[NSString alloc] initWithUTF8String:str] + defaultType = [[[TKNSString alloc] initWithTclUtfBytes:str length:len] autorelease]; } break; @@ -973,21 +1000,22 @@ Tk_GetSaveFileObjCmd( case SAVE_INITDIR: str = Tcl_GetStringFromObj(objv[i + 1], &len); if (len) { - directory = [[[NSString alloc] initWithUTF8String:str] + directory = [[[TKNSString alloc] initWithTclUtfBytes:str length:len] autorelease]; } break; case SAVE_INITFILE: str = Tcl_GetStringFromObj(objv[i + 1], &len); if (len) { - filename = [[[NSString alloc] initWithUTF8String:str] + filename = [[[TKNSString alloc] initWithTclUtfBytes:str length:len] autorelease]; [savepanel setNameFieldStringValue:filename]; } break; case SAVE_MESSAGE: - message = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetStringFromObj(objv[i + 1], &len); + message = [[TKNSString alloc] initWithTclUtfBytes: + str length:len]; break; case SAVE_PARENT: str = Tcl_GetStringFromObj(objv[i + 1], &len); @@ -998,8 +1026,9 @@ Tk_GetSaveFileObjCmd( haveParentOption = 1; break; case SAVE_TITLE: - title = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetStringFromObj(objv[i + 1], &len); + title = [[TKNSString alloc] initWithTclUtfBytes: + str length:len]; break; case SAVE_TYPEVARIABLE: typeVariablePtr = objv[i + 1]; @@ -1072,7 +1101,8 @@ Tk_GetSaveFileObjCmd( [savepanel setAccessoryView:accessoryView]; - [savepanel setAllowedFileTypes:[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]]; + setAllowedFileTypes(savepanel, + [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]); [savepanel setAllowsOtherFileTypes:filterInfo.allowedExtensionsAllowAll]; } else if (defaultType) { /* @@ -1084,7 +1114,7 @@ Tk_GetSaveFileObjCmd( NSMutableArray *AllowedFileTypes = [NSMutableArray array]; [AllowedFileTypes addObject:defaultType]; - [savepanel setAllowedFileTypes:AllowedFileTypes]; + setAllowedFileTypes(savepanel, AllowedFileTypes); [savepanel setAllowsOtherFileTypes:YES]; } @@ -1198,13 +1228,14 @@ Tk_ChooseDirectoryObjCmd( case CHOOSE_INITDIR: str = Tcl_GetStringFromObj(objv[i + 1], &len); if (len) { - directory = [[[NSString alloc] initWithUTF8String:str] + directory = [[[TKNSString alloc] initWithTclUtfBytes:str length:len] autorelease]; } break; case CHOOSE_MESSAGE: - message = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetStringFromObj(objv[i + 1], &len); + message = [[TKNSString alloc] initWithTclUtfBytes: + str length:len]; [panel setMessage:message]; [message release]; break; @@ -1223,8 +1254,9 @@ Tk_ChooseDirectoryObjCmd( haveParentOption = 1; break; case CHOOSE_TITLE: - title = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetStringFromObj(objv[i + 1], &len); + title = [[TKNSString alloc] initWithTclUtfBytes: + str length:len]; [panel setTitle:title]; [title release]; break; @@ -1387,8 +1419,9 @@ Tk_MessageBoxObjCmd( break; case ALERT_DETAIL: - message = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetString(objv[i + 1]); + message = [[TKNSString alloc] initWithTclUtfBytes: + str length:-1]; [alert setInformativeText:message]; [message release]; break; @@ -1401,8 +1434,9 @@ Tk_MessageBoxObjCmd( break; case ALERT_MESSAGE: - message = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetString(objv[i + 1]); + message = [[TKNSString alloc] initWithTclUtfBytes: + str length:-1]; [alert setMessageText:message]; [message release]; break; @@ -1417,8 +1451,9 @@ Tk_MessageBoxObjCmd( break; case ALERT_TITLE: - title = [[NSString alloc] initWithUTF8String: - Tcl_GetString(objv[i + 1])]; + str = Tcl_GetString(objv[i + 1]); + title = [[TKNSString alloc] initWithTclUtfBytes: + str length:-1]; [[alert window] setTitle:title]; [title release]; break; diff --git a/macosx/tkMacOSXFileTypes.c b/macosx/tkMacOSXFileTypes.c new file mode 100644 index 0000000..c89328d --- /dev/null +++ b/macosx/tkMacOSXFileTypes.c @@ -0,0 +1,112 @@ +/* +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" +#include "tkMacOSXFileTypes.h" +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 +#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h> +#endif + +#define CHARS_TO_OSTYPE(string) (OSType) string[0] << 24 | \ + (OSType) string[1] << 16 | \ + (OSType) string[2] << 8 | \ + (OSType) string[3] + +static BOOL initialized = false; +static Tcl_HashTable ostype2identifier; +static void initOSTypeTable(void) { + int newPtr; + Tcl_HashEntry *hPtr; + const IdentifierForOSType *entry; + Tcl_InitHashTable(&ostype2identifier, TCL_ONE_WORD_KEYS); + for (entry = OSTypeDB; entry->ostype != NULL; entry++) { + const char *key = INT2PTR(CHARS_TO_OSTYPE(entry->ostype)); + hPtr = Tcl_CreateHashEntry(&ostype2identifier, key, &newPtr); + if (newPtr) { + Tcl_SetHashValue(hPtr, entry->identifier); + } + } + initialized = true; +} + +MODULE_SCOPE NSString *TkMacOSXOSTypeToUTI(OSType ostype) { + if (!initialized) { + initOSTypeTable(); + } + Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&ostype2identifier, INT2PTR(ostype)); + if (hPtr) { + char *UTI = Tcl_GetHashValue(hPtr); + return [[NSString alloc] initWithCString:UTI + encoding:NSASCIIStringEncoding]; + } + return nil; +} + +/* + * 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 >= 101300 + if (!initialized) { + initOSTypeTable(); + } + if (@available(macOS 11.0, *)) { + UTType *uttype = [UTType typeWithIdentifier: filetype]; + if (![uttype isDeclared]) { + uttype = [UTType typeWithFilenameExtension: filetype]; + } + if (![uttype isDeclared] && [filetype length] == 4) { + OSType ostype = CHARS_TO_OSTYPE(filetype.UTF8String); + NSString *UTI = TkMacOSXOSTypeToUTI(ostype); + uttype = [UTType typeWithIdentifier:UTI]; + } + if (![uttype isDeclared]) { + return nil; + } + return [[NSWorkspace sharedWorkspace] iconForContentType:uttype]; + } else { +/* Despite Apple's claims, @available does not prevent deprecation warnings. */ +# if MAC_OS_X_VERSION_MIN_REQUIRED < 110000 + return [[NSWorkspace sharedWorkspace] iconForFileType:filetype]; +#else + return nil; /* Never executed. */ +#endif + } +#else /* @available is not available. */ + return [[NSWorkspace sharedWorkspace] iconForFileType:filetype]; +#endif +} + +/* + * Local Variables: + * mode: objc + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ diff --git a/macosx/tkMacOSXFileTypes.h b/macosx/tkMacOSXFileTypes.h new file mode 100644 index 0000000..1c11d29 --- /dev/null +++ b/macosx/tkMacOSXFileTypes.h @@ -0,0 +1,144 @@ +/* +Apple never published a database of OSType codes for File Types. However, +a database of known OSType codes representing Creators and File Types used on +Apple systems prior to 2003 is available at: + + http://www.lacikam.co.il/tcdb/download/TCDBdata.zip + +Among the 12034 distinct OSType codes for File Types that are listed in the TCDB +database, there are 121 for which the UTTypeCreatePreferredIdentifierForTag +function (deprecated in macOS 12.0) was able to generate a Uniform Type +Identifier on macOS 12.5.1. The mapping from those OSTypes to Uniform Type +identifiers is given by the following array, in which OSTypes are represented as +strings of length 4. +*/ + +typedef struct { + char *ostype; + char *identifier; +} IdentifierForOSType; + +static const IdentifierForOSType OSTypeDB[] = { + {".SGI", "com.sgi.sgi-image"}, + {".WAV", "com.microsoft.waveform-audio"}, + {"8BPS", "com.adobe.photoshop-image"}, + {"ABPR", "com.apple.addressbook.person"}, + {"AIFC", "public.aifc-audio"}, + {"AIFF", "public.aiff-audio"}, + {"APPC", "com.apple.deprecated-application-file"}, + {"APPD", "com.apple.deprecated-application-file"}, + {"APPL", "com.apple.application-bundle"}, + {"ASF_", "com.microsoft.advanced-systems-format"}, + {"ASX_", "com.microsoft.advanced-stream-redirector"}, + {"BMP ", "com.microsoft.bmp"}, + {"BMPf", "com.microsoft.bmp"}, + {"BNDL", "com.apple.generic-bundle"}, + {"DDim", "com.apple.disk-image-raw"}, + {"DICM", "org.nema.dicom"}, + {"DOTM", "org.openxmlformats.wordprocessingml.template.macro-enabled"}, + {"EM3F", "com.apple.logic-song"}, + {"EPSF", "com.adobe.encapsulated-postscript"}, + {"FFIL", "com.apple.font-suitcase"}, + {"FLI ", "public.flc-animation"}, + {"FNDR", "com.apple.legacy.finder-icon"}, + {"GIFf", "com.compuserve.gif"}, + {"HTML", "public.html"}, + {"JPEG", "public.jpeg"}, + {"LWFN", "com.adobe.postscript-lwfn-font"}, + {"MP3 ", "public.mp3"}, + {"MP3!", "public.mp3"}, + {"MP3U", "com.apple.tv.m3u-playlist"}, + {"MPEG", "public.mpeg"}, + {"MPG ", "public.mpeg"}, + {"MPG2", "com.apple.music.mp2"}, + {"MPG3", "public.mp3"}, + {"Midi", "public.midi-audio"}, + {"MooV", "com.apple.quicktime-movie"}, + {"Mp3 ", "public.mp3"}, + {"PAT ", "org.gimp.pat"}, + {"PDF ", "com.adobe.pdf"}, + {"PICT", "com.apple.pict"}, + {"PNGf", "public.png"}, + {"PNRA", "com.real.realaudio"}, + {"PNRM", "com.real.realmedia"}, + {"PNTG", "com.apple.macpaint-image"}, + {"PPOT", "com.microsoft.powerpoint.pot"}, + {"PPSS", "com.microsoft.powerpoint.pps"}, + {"RTF ", "public.rtf"}, + {"SDP ", "public.sdp"}, + {"SIT5", "com.stuffit.archive.sit"}, + {"SLD8", "com.microsoft.powerpoint.ppt"}, + {"Sd2f", "com.digidesign.sd2-audio"}, + {"TEXT", "com.apple.traditional-mac-plain-text"}, + {"TIFF", "public.tiff"}, + {"TPIC", "com.truevision.tga-image"}, + {"ULAW", "public.ulaw-audio"}, + {"VfW ", "public.avi"}, + {"W8BN", "com.microsoft.word.doc"}, + {"W8TN", "com.microsoft.word.dot"}, + {"WAVE", "com.microsoft.waveform-audio"}, + {"XLA5", "com.microsoft.excel.xla"}, + {"XLS8", "com.microsoft.excel.xls"}, + {"XLW8", "com.microsoft.excel.xlw"}, + {"alis", "com.apple.alias-record"}, + {"appe", "com.apple.deprecated-application-file"}, + {"cdev", "com.apple.deprecated-application-file"}, + {"clpp", "com.apple.finder.pictclipping"}, + {"clps", "com.apple.finder.sound-clipping"}, + {"clpt", "com.apple.finder.textclipping"}, + {"clpu", "com.apple.finder.clipping"}, + {"ctrl", "com.apple.legacy.finder-icon"}, + {"dfil", "com.apple.deprecated-application-file"}, + {"dict", "com.apple.document-type.dictionary"}, + {"disk", "public.volume"}, + {"docs", "com.apple.documents-folder"}, + {"dvc!", "public.dv-movie"}, + {"ffil", "com.apple.font-suitcase"}, + {"flpy", "com.apple.storage-removable"}, + {"fold", "public.folder"}, + {"font", "com.apple.legacy.finder-icon"}, + {"grup", "com.apple.user-group"}, + {"hdrv", "com.apple.disk-image-raw"}, + {"hdsk", "com.apple.storage-internal"}, + {"help", "com.apple.help-document"}, + {"hkdb", "com.apple.itunes.db"}, + {"hvpl", "com.apple.music.visual"}, + {"ilaf", "com.apple.afp-internet-location"}, + {"ilfi", "com.apple.file-internet-location"}, + {"ilft", "com.apple.ftp-internet-location"}, + {"ilge", "com.apple.generic-internet-location"}, + {"ilht", "com.apple.web-internet-location"}, + {"ilma", "com.apple.mail-internet-location"}, + {"ilnw", "com.apple.news-internet-location"}, + {"macD", "com.apple.legacy.finder-icon"}, + {"mp3!", "public.mp3"}, + {"mpg3", "public.mp3"}, + {"note", "com.apple.alert-note"}, + {"osas", "com.apple.applescript.script"}, + {"plug", "com.apple.plugin"}, + {"pref", "com.apple.legacy.finder-icon"}, + {"prfb", "com.apple.icon-overlay.private-folder-badge"}, + {"prof", "com.apple.colorsync-profile"}, + {"qtif", "com.apple.quicktime-image"}, + {"sLS8", "com.microsoft.excel.xlt"}, + {"sM3F", "com.apple.logic-song"}, + {"sbBF", "com.apple.finder.burn-folder"}, + {"scrp", "com.apple.legacy.finder-icon"}, + {"sdoc", "com.apple.generic-stationery"}, + {"sfnt", "com.apple.font-suitcase"}, + {"shlb", "com.apple.legacy.finder-icon"}, + {"srvr", "com.apple.file-server"}, + {"svg ", "public.svg-image"}, + {"svgz", "public.svg-image"}, + {"tDoc", "com.apple.documents-folder"}, + {"tfil", "com.apple.font-suitcase"}, + {"trsh", "com.apple.trash-empty"}, + {"ttcf", "public.truetype-collection-font"}, + {"ttro", "com.apple.traditional-mac-plain-text"}, + {"txtn", "com.apple.txn.text-multimedia-data"}, + {"url ", "public.url"}, + {"user", "com.apple.user"}, + {"utxt", "public.utf16-plain-text"}, + {"vCrd", "public.vcard"}, + {NULL, NULL} +}; diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index d9c1c01..b33de0a 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -4,9 +4,9 @@ * Contains the Macintosh implementation of the platform-independent font * package interface. * - * Copyright 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de + * Copyright (c) 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> - * Copyright 2008-2009, Apple Inc. + * Copyright (c) 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. @@ -244,7 +244,7 @@ FindNSFont( NSString *family; if (familyName) { - family = [[[NSString alloc] initWithUTF8String:familyName] autorelease]; + family = [[[TKNSString alloc] initWithTclUtfBytes:familyName length:-1] autorelease]; } else { family = [defaultFont familyName]; } diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index d9f3d12..a9b459a 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -45,8 +45,41 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, @synthesize needsToDraw = _needsToDraw; @synthesize tkLiveResizeEnded = _tkLiveResizeEnded; @synthesize tkPointerWindow = _tkPointerWindow; +- (void) setTkPointerWindow: (TkWindow *)winPtr +{ + if (_tkPointerWindow) { + Tcl_Release(_tkPointerWindow); + } + if (winPtr) { + Tcl_Preserve(winPtr); + } + _tkPointerWindow = winPtr; + return; +} @synthesize tkEventTarget = _tkEventTarget; +- (void) setTkEventTarget: (TkWindow *)winPtr +{ + if (_tkEventTarget) { + Tcl_Release(_tkEventTarget); + } + if (winPtr) { + Tcl_Preserve(winPtr); + } + _tkEventTarget = winPtr; + return; +} @synthesize tkDragTarget = _tkDragTarget; +- (void) setTkDragTarget: (TkWindow *)winPtr +{ + if (_tkDragTarget) { + Tcl_Release(_tkDragTarget); + } + if (winPtr) { + Tcl_Preserve(winPtr); + } + _tkDragTarget = winPtr; + return; +} @synthesize tkButtonState = _tkButtonState; @end @@ -415,7 +448,7 @@ TkpInit( /* * TkpInit can be called multiple times with different interpreters. But - * The application initialization should only be done onece. + * The application initialization should only be done once. */ if (!initialized) { @@ -476,7 +509,7 @@ TkpInit( * 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 - * ApplEvent later, after the required procedure has been defined. + * AppleEvent later, after the required procedure has been defined. */ [NSApp _setup:interp]; diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index cc3ab7f..b690d9d 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -3,8 +3,8 @@ * * This module implements the Mac-platform specific features of menus. * - * Copyright (c) 1996-1997 by Sun Microsystems, Inc. - * Copyright 2001-2009, Apple Inc. + * Copyright (c) 1996-1997 Sun Microsystems, Inc. + * Copyright (c) 2001-2009 Apple Inc. * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2012 Adrian Robert. * @@ -94,7 +94,7 @@ static const struct { static int gNoTkMenus = 0; /* This is used by Tk_MacOSXTurnOffMenus as * the flag that Tk is not to draw any * menus. */ -static int inPostMenu = 0; +static Bool inPostMenu = true; static SInt32 menuMarkColumnWidth = 0, menuIconTrailingEdgeMargin = 0; static SInt32 menuTextLeadingEdgeMargin = 0, menuTextTrailingEdgeMargin = 0; static SInt16 menuItemExtraHeight = 0, menuItemExtraWidth = 0; @@ -124,7 +124,7 @@ static int ModifierCharWidth(Tk_Font tkfont); * demo would cause the animation to stop. This was also the case for * menubuttons. * - * The TKBackground object below works around this problem, and allows a Tk + * 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 @@ -200,25 +200,36 @@ TKBackgroundLoop *backgroundLoop = nil; * 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. - * - * The performKeyEquivalent callback method is being overridden here to work - * around a bug reported in [1626ed65b8]. When a dead key that is also as a - * KeyEquivalent is pressed, a KeyDown event with no characters is passed to - * performKeyEquivalent. The default implementation provided by Apple will - * 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, but does not prevent the KeyEquivalent action from being - * invoked, presumably because the event does get correctly handled higher in - * the responder chain. + * 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) { + if ([[event characters] length] == 0) { return NO; } - return [super performKeyEquivalent:event]; + runMenuCommand = false; + /* Make the menu flash and call tkMenuItemInvoke. */ + return [super performKeyEquivalent: event]; } @end @@ -239,8 +250,8 @@ TKBackgroundLoop *backgroundLoop = nil; - (id) initWithTkMenu: (TkMenu *) tkMenu { - NSString *title = [[NSString alloc] initWithUTF8String: - Tk_PathName(tkMenu->tkwin)]; + NSString *title = [[TKNSString alloc] initWithTclUtfBytes: + Tk_PathName(tkMenu->tkwin) length:-1]; self = [self initWithTitle:title]; [title release]; @@ -332,11 +343,19 @@ TKBackgroundLoop *backgroundLoop = nil; - (void) tkMenuItemInvoke: (id) sender { + if (!runMenuCommand) { + + /* + * We are being called for a menu accelerator. Tk will handle it. + * Just update the runMenuCommand flag. + */ + + runMenuCommand = true; + return; + } + /* - * With the delegate matching key equivalents, when a menu action is sent - * in response to a key equivalent, the sender is the whole menu and not the - * specific menu item. We use this to ignore key equivalents for Tk - * menus (as Tk handles them directly via bindings). + * We are being called for an actual menu item selection; run the command. */ if ([sender isKindOfClass:[NSMenuItem class]]) { @@ -736,14 +755,9 @@ TkpConfigureMenuEntry( [menuItem setImage:image]; if ((!image || mePtr->compound != COMPOUND_NONE) && mePtr->labelPtr && mePtr->labelLength) { - Tcl_DString ds; - Tcl_DStringInit(&ds); - Tcl_UtfToUniCharDString(Tcl_GetString(mePtr->labelPtr), - mePtr->labelLength, &ds); - title = [[NSString alloc] - initWithCharacters:(unichar *)Tcl_DStringValue(&ds) - length:Tcl_DStringLength(&ds)>>1]; - Tcl_DStringFree(&ds); + title = [[TKNSString alloc] + initWithTclUtfBytes:Tcl_GetString(mePtr->labelPtr) + length:mePtr->labelLength]; if ([title hasSuffix:@"..."]) { title = [NSString stringWithFormat:@"%@%C", [title substringToIndex:[title length] - 3], 0x2026]; @@ -814,7 +828,7 @@ TkpConfigureMenuEntry( if ([submenu supermenu] && [menuItem submenu] != submenu) { /* * This happens during a clone, where the parent menu is - * cloned before its children, so just ignore this temprary + * cloned before its children, so just ignore this temporary * setting, it will be changed shortly (c.f. tkMenu.c * CloneMenu()) */ @@ -943,10 +957,10 @@ TkpPostMenu( NSMenuItem *item = nil; NSPoint location = NSMakePoint(x, TkMacOSXZeroScreenHeight() - y); - inPostMenu = 1; + inPostMenu = true; result = TkPreprocessMenu(menuPtr); if (result != TCL_OK) { - inPostMenu = 0; + inPostMenu = false; return result; } if (itemIndex >= numItems) { @@ -968,7 +982,7 @@ TkpPostMenu( [menu popUpMenuPositioningItem:item atLocation:[win tkConvertPointFromScreen:location] inView:view]; - inPostMenu = 0; + inPostMenu = false; return TCL_OK; } @@ -1314,7 +1328,7 @@ ParseAccelerator( if (ch) { return [[[NSString alloc] initWithCharacters:&ch length:1] autorelease]; } else { - return [[[[NSString alloc] initWithUTF8String:accel] autorelease] + return [[[[TKNSString alloc] initWithTclUtfBytes:accel length:-1] autorelease] lowercaseString]; } } @@ -1324,7 +1338,7 @@ ParseAccelerator( * * ModifierCharWidth -- * - * Helper mesuring width of command char in given font. + * Helper measuring width of command char in given font. * * Results: * Width of command char. diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index fd9bbc1..e33f787 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -133,6 +133,7 @@ enum { buttonState &= ~TkGetButtonMask(button); break; case NSLeftMouseDragged: + buttonState |= TkGetButtonMask(button); if (![NSApp tkDragTarget]) { if (isOutside) { ignoreDrags = YES; @@ -248,7 +249,7 @@ enum { } /* - * If this click will change the focus, the Tk event event should + * 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. */ @@ -404,7 +405,6 @@ enum { * not in the grabber's subtree. */ - 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. */ @@ -500,7 +500,7 @@ enum { Tk_UpdatePointer((Tk_Window) [NSApp tkDragTarget], global.x, global.y, state); } else { - Tk_UpdatePointer(NULL, global.x, global.y, state); + Tk_UpdatePointer(NULL, global.x, global.y, state); } } else if (eventType == NSMouseMoved || eventType == NSLeftMouseDragged) { @@ -818,7 +818,6 @@ GenerateButtonEvent( 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; } diff --git a/macosx/tkMacOSXNotify.c b/macosx/tkMacOSXNotify.c index 208d846..3cb6c48 100644 --- a/macosx/tkMacOSXNotify.c +++ b/macosx/tkMacOSXNotify.c @@ -341,7 +341,7 @@ TkMacOSXNotifyExitHandler( * 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 addDirtyRect method + * 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 diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index 3b03139..bc6b49c 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -28,6 +28,9 @@ #import <ApplicationServices/ApplicationServices.h> #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 @@ -294,7 +297,9 @@ MODULE_SCOPE void TkMacOSXWinNSBounds(TkWindow *winPtr, NSView *view, MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin); MODULE_SCOPE void TkMacOSXDrawAllViews(ClientData clientData); MODULE_SCOPE unsigned long TkMacOSXClearPixel(void); - +MODULE_SCOPE NSString* TkMacOSXOSTypeToUTI(OSType ostype); +MODULE_SCOPE NSImage* TkMacOSXIconForFileType(NSString *filetype); + #pragma mark Private Objective-C Classes #define VISIBILITY_HIDDEN __attribute__((visibility("hidden"))) @@ -351,9 +356,9 @@ VISIBILITY_HIDDEN * Persistent state variables used by processMouseEvent. */ -@property TkWindow *tkPointerWindow; -@property TkWindow *tkEventTarget; -@property TkWindow *tkDragTarget; +@property(nonatomic) TkWindow *tkPointerWindow; +@property(nonatomic) TkWindow *tkEventTarget; +@property(nonatomic) TkWindow *tkDragTarget; @property unsigned int tkButtonState; @end diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index dbae21e..5d61981 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -308,9 +308,6 @@ XUnmapWindow( TkWindow *winPtr = macWin->winPtr; TkWindow *parentPtr = winPtr->parentPtr; NSWindow *win = TkMacOSXGetNSWindowForDrawable(window); - NSPoint mouse = [NSEvent mouseLocation]; - int x = mouse.x, y = TkMacOSXZeroScreenHeight() - mouse.y; - int state = TkMacOSXButtonKeyState(); if (!window) { return BadWindow; @@ -371,7 +368,6 @@ XUnmapWindow( if (view != [NSView focusView]) { [view addTkDirtyRect:[view bounds]]; } - Tk_UpdatePointer(NULL, x, y, state); return Success; } diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index ec19ec5..a4a6aa8 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -295,8 +295,8 @@ InjectKeyEventObjCmd( Tcl_WrongNumArgs(interp, 1, objv, "option keysym ?arg?"); return TCL_ERROR; } - 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; } type = types[index]; diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 5769369..a806729 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -457,7 +457,7 @@ static void RefocusGrabWindow(void *data) { * 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 and Expose event, from within drawRect. + * 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 @@ -1014,7 +1014,7 @@ ConfigureRestrictProc( /* * Make sure that the layer uses a contentScale that matches the - * backing scale factor of the screen. This avoids blurry text whe + * 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. */ diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index f8561bf..b72c5a7 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -6,7 +6,7 @@ * the "wm" command and passes geometry information to the window manager. * * Copyright (c) 1994-1997 Sun Microsystems, Inc. - * Copyright 2001-2009, Apple Inc. + * Copyright (c) 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2010 Kevin Walzer/WordTech Communications LLC. * Copyright (c) 2017-2019 Marc Culler. @@ -2596,7 +2596,7 @@ WmIconphotoCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { Tk_Image tk_icon; - int width, height, isDefault = 0; + int width, height; NSImage *newIcon = NULL; if (objc < 4) { @@ -2610,7 +2610,6 @@ WmIconphotoCmd( */ if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { - isDefault = 1; if (objc == 4) { Tcl_WrongNumArgs(interp, 2, objv, "window ?-default? image1 ?image2 ...?"); @@ -5420,7 +5419,7 @@ TkSetWMName( return; } - NSString *title = [[NSString alloc] initWithUTF8String:titleUid]; + NSString *title = [[TKNSString alloc] initWithTclUtfBytes:titleUid length:-1]; [TkMacOSXGetNSWindowForDrawable(winPtr->window) setTitle:title]; [title release]; } @@ -5968,7 +5967,7 @@ WmWinTabbingId( * allows you to get or set the appearance for the NSWindow associated * with a Tk Window. The syntax is: * - * tk::unsupported::MacWindowStyle tabbingid window ?newAppearance? + * tk::unsupported::MacWindowStyle appearance window ?newAppearance? * * Allowed appearance names are "aqua", "darkaqua", and "auto". * @@ -6034,9 +6033,9 @@ WmWinAppearance( if (objc == 4) { int index; if (Tcl_GetIndexFromObjStruct(interp, objv[3], appearanceStrings, - sizeof(char *), "appearancename", 0, &index) != TCL_OK) { - return TCL_ERROR; - } + sizeof(char *), "appearancename", 0, &index) != TCL_OK) { + return TCL_ERROR; + } switch ((enum appearances) index) { case APPEARANCE_AQUA: win.appearance = [NSAppearance appearanceNamed: diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index ddaa226..38e6fa3 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -236,7 +236,7 @@ static CGRect NormalizeButtonBounds( */ /* - * For systems older than 10.14, [NSColor windowBackGroundColor] generates + * 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 |