diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-07-07 22:00:15 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-07-07 22:00:15 (GMT) |
commit | 8acb512c92c1b619073eac7d604ab9791ef0e713 (patch) | |
tree | 3e9691c13e240731e5cf78e7e27ff536d68a4bab /macosx | |
parent | 90b1090817bbf37d8787cc9ed77f2a4ca7460bb7 (diff) | |
parent | 2d8d71bb9e77b74a29295db7280e8383c4ac4df0 (diff) | |
download | tk-8acb512c92c1b619073eac7d604ab9791ef0e713.zip tk-8acb512c92c1b619073eac7d604ab9791ef0e713.tar.gz tk-8acb512c92c1b619073eac7d604ab9791ef0e713.tar.bz2 |
Merge trunk
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/README | 25 | ||||
-rw-r--r-- | macosx/tkMacOSXBitmap.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXClipboard.c | 8 | ||||
-rw-r--r-- | macosx/tkMacOSXConstants.h | 44 | ||||
-rw-r--r-- | macosx/tkMacOSXDialog.c | 17 | ||||
-rw-r--r-- | macosx/tkMacOSXEvent.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXFont.c | 12 | ||||
-rw-r--r-- | macosx/tkMacOSXFont.h | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 71 | ||||
-rw-r--r-- | macosx/tkMacOSXKeyEvent.c | 3 | ||||
-rw-r--r-- | macosx/tkMacOSXMenu.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXPrivate.h | 12 | ||||
-rw-r--r-- | macosx/tkMacOSXScrlbr.c | 136 | ||||
-rw-r--r-- | macosx/tkMacOSXServices.c | 15 | ||||
-rw-r--r-- | macosx/tkMacOSXTest.c | 3 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 2 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 54 |
18 files changed, 239 insertions, 173 deletions
diff --git a/macosx/README b/macosx/README index c2fa040..7df4893 100644 --- a/macosx/README +++ b/macosx/README @@ -26,7 +26,7 @@ before asking on the list, many questions have already been answered). --------------------------- - 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. +aqua widgets and look&feel, and TkX11 using the traditional unix X11 widgets. 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]. @@ -490,7 +490,7 @@ The macOS Tk application does not call the [NSApp run] method at all. Instead it uses the event loop built in to Tk. So the application must take care to replicate the important features of the method ourselves. The way that autorelease pools are handled is -discussed in 4.2 below. Here we discuss the event handling itself. +discussed in 5.2 below. Here we discuss the event handling itself. The Tcl event loop simply consists of repeated calls to TclDoOneEvent. Each call to TclDoOneEvent begins by collecting all pending events from @@ -523,7 +523,7 @@ event to the Tcl queue. 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 +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 @@ -548,7 +548,7 @@ in nested calls to CheckProc. One additional minor caveat for developers is that there are several steps of the Tk initialization which precede the call to TkpInit. Notably, the font package is initialized first. Since there is no -NSAUtoreleasePool in scope prior to calling TkpInit, the functions +NSAutoreleasePool in scope prior to calling TkpInit, the functions called in these preliminary stages need to create and drain their own NSAutoreleasePools whenever they call methods of Appkit objects (e.g. NSFont). @@ -568,7 +568,7 @@ window. (Normally, the clipping rectangle is the same as the bounding rectangle, but drawing can be clipped to a smaller rectangle by calling TkpClipDrawableToRect.) The aboveVisRgn is the intersection of the window's bounding rectangle with the bounding rectangle of the -parent window. Much of the code in tkMacOSXSubindows.c is devoted to +parent window. Much of the code in tkMacOSXSubwindows.c is devoted to rebuilding these clipping regions whenever something changes in the layout of the windows. This turns out to be a tricky thing to do and it is extremely prone to errors which can be difficult to trace. @@ -663,16 +663,15 @@ source and destination rectangles for the scrolling. The embedded windows are redrawn within the DisplayText function by some conditional code which is only used for macOS. -6. Virtual events on 10.14 ---------------------------- +6.0 Virtual events on 10.14 +~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10.14 supports system appearance changes, and has added a "Dark Mode" -that casts all window frames and menus as black. Tk 8.6.9 supports Dark -Mode by having the window decorations, menus, and dialogs automatically -take on the appropriate appearance when the system appearance is changed. -Because the window content itself is drawn by Tk, it will not change when -the system mode changes. - +that casts all window frames and menus as black. Tk 8.6.9 has added two +virtual events, <<LightAqua>> and <<DarkAqua>>, to allow you to update +your Tk app's appearance when the system appearance changes. Just bind +your appearance-updating code to these virtual events and you will see +it triggered when the system appearance toggles between dark and light. 7.0 Mac Services ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c index f779097..6ec4048 100644 --- a/macosx/tkMacOSXBitmap.c +++ b/macosx/tkMacOSXBitmap.c @@ -334,7 +334,7 @@ TkpGetNativeAppBitmap( CGContextConcatCTM(dc.context, t); [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:dc.context flipped:NO]]; + graphicsContextWithCGContext:dc.context flipped:NO]]; [image drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; [NSGraphicsContext restoreGraphicsState]; diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c index 6cbcdf6..2ae02e8 100644 --- a/macosx/tkMacOSXClipboard.c +++ b/macosx/tkMacOSXClipboard.c @@ -28,7 +28,7 @@ static Tk_Window clipboardOwner = NULL; NSMutableString *string = [NSMutableString new]; if (dispPtr && dispPtr->clipboardActive && - [type isEqualToString:NSStringPboardType]) { + [type isEqualToString:NSPasteboardTypeString]) { for (TkClipboardTarget *targetPtr = dispPtr->clipTargetPtr; targetPtr; targetPtr = targetPtr->nextPtr) { if (targetPtr->type == XA_STRING || @@ -55,7 +55,7 @@ static Tk_Window clipboardOwner = NULL; if (dispPtr && dispPtr->clipboardActive) { [self tkProvidePasteboard:dispPtr pasteboard:[NSPasteboard generalPasteboard] - provideDataForType:NSStringPboardType]; + provideDataForType:NSPasteboardTypeString]; } } @@ -132,7 +132,7 @@ TkSelGetSelection( NSString *string = nil; NSPasteboard *pb = [NSPasteboard generalPasteboard]; NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject: - NSStringPboardType]]; + NSPasteboardTypeString]]; if (type) { string = [pb stringForType:type]; @@ -236,7 +236,7 @@ TkSelUpdateClipboard( { NSPasteboard *pb = [NSPasteboard generalPasteboard]; - changeCount = [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] + changeCount = [pb addTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:NSApp]; } diff --git a/macosx/tkMacOSXConstants.h b/macosx/tkMacOSXConstants.h index 0badf1a..388d619 100644 --- a/macosx/tkMacOSXConstants.h +++ b/macosx/tkMacOSXConstants.h @@ -25,21 +25,23 @@ * of constants. */ -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 -#define kCTFontDefaultOrientation kCTFontOrientationDefault -#define kCTFontVerticalOrientation kCTFontOrientationVertical +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 +#define kCTFontOrientationDefault kCTFontDefaultOrientation +#define kCTFontOrientationVertical kCTFontVerticalOrientation +#define NSModalResponseCancel NSCancelButton #endif -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 -#define NSOKButton NSModalResponseOK +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000 +#define NSModalResponseOK NSOKButton #endif -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 -#define kCTFontUserFixedPitchFontType kCTFontUIFontUserFixedPitch +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 +#define kCTFontUIFontUserFixedPitch kCTFontUserFixedPitchFontType #endif -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 -#define NSAppKitDefined NSEventTypeAppKitDefined +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200 +#define NSEventTypeAppKitDefined NSAppKitDefined +#else #define NSApplicationDefined NSEventTypeApplicationDefined #define NSApplicationActivatedEventType NSEventSubtypeApplicationActivated #define NSApplicationDeactivatedEventType NSEventSubtypeApplicationDeactivated @@ -79,22 +81,8 @@ #define NSInformationalAlertStyle NSAlertStyleInformational #define NSCriticalAlertStyle NSAlertStyleCritical #define NSCenterTextAlignment NSTextAlignmentCenter -#define NSDeviceIndependentModifierFlagsMask NSEventModifierFlagDeviceIndependentFlagsMask -#define NSCommandKeyMask NSEventModifierFlagCommand -#define NSShiftKeyMask NSEventModifierFlagShift -#define NSAlphaShiftKeyMask NSEventModifierFlagCapsLock -#define NSAlternateKeyMask NSEventModifierFlagOption -#define NSControlKeyMask NSEventModifierFlagControl -#define NSNumericPadKeyMask NSEventModifierFlagNumericPad -#define NSFunctionKeyMask NSEventModifierFlagFunction -#define NSKeyUp NSEventTypeKeyUp -#define NSKeyDown NSEventTypeKeyDown -#define NSFlagsChanged NSEventTypeFlagsChanged -#define NSAlphaShiftKeyMask NSEventModifierFlagCapsLock -#define NSShiftKeyMask NSEventModifierFlagShift #define NSAnyEventMask NSEventMaskAny #define NSApplicationDefinedMask NSEventMaskApplicationDefined -#define NSTexturedBackgroundWindowMask NSWindowStyleMaskTexturedBackground #define NSUtilityWindowMask NSWindowStyleMaskUtilityWindow #define NSNonactivatingPanelMask NSWindowStyleMaskNonactivatingPanel #define NSDocModalWindowMask NSWindowStyleMaskDocModalWindow @@ -108,12 +96,12 @@ #define NSFullScreenWindowMask NSWindowStyleMaskFullScreen #endif -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 -#define NSStringPboardType NSPasteboardTypeString -#define NSOnState NSControlStateValueOn -#define NSOffState NSControlStateValueOff +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101400 +#define NSControlStateValueOn NSOnState +#define NSControlStateValueOff NSOffState +#define NSPasteboardTypeString NSStringPboardType // Now we are also changing names of methods! -#define graphicsContextWithGraphicsPort graphicsContextWithCGContext +#define graphicsContextWithCGContext graphicsContextWithGraphicsPort #endif diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index ad952e8..a149bca 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -16,13 +16,6 @@ #include "tkFileFilter.h" #include "tkMacOSXConstants.h" -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 -#define modalOK NSOKButton -#define modalCancel NSCancelButton -#else -#define modalOK NSModalResponseOK -#define modalCancel NSModalResponseCancel -#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090 #define modalOther -1 #define modalError -2 @@ -202,7 +195,7 @@ getFileURL( { FilePanelCallbackInfo *callbackInfo = contextInfo; - if (returnCode == modalOK) { + if (returnCode == NSModalResponseOK) { Tcl_Obj *resultObj; if (callbackInfo->multiple) { @@ -230,7 +223,7 @@ getFileURL( } else { Tcl_SetObjResult(callbackInfo->interp, resultObj); } - } else if (returnCode == modalCancel) { + } else if (returnCode == NSModalResponseCancel) { Tcl_ResetResult(callbackInfo->interp); } if (panel == [NSApp modalWindow]) { @@ -411,7 +404,7 @@ Tk_ChooseColorObjCmd( [colorPanel setColor:initialColor]; } returnCode = [NSApp runModalForWindow:colorPanel]; - if (returnCode == modalOK) { + if (returnCode == NSModalResponseOK) { color = [[colorPanel color] colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; numberOfComponents = [color numberOfComponents]; @@ -810,7 +803,7 @@ Tk_GetOpenFileObjCmd( [parent makeKeyWindow]; } - if ((typeVariablePtr && (modalReturnCode == NSOKButton)) + if ((typeVariablePtr && (modalReturnCode == NSModalResponseOK)) && filterInfo.doFileTypes) { /* * The -typevariable must be set to the selected file type, if the @@ -1122,7 +1115,7 @@ Tk_GetSaveFileObjCmd( [parent makeKeyWindow]; } - if (typeVariablePtr && (modalReturnCode == NSOKButton) + if (typeVariablePtr && (modalReturnCode == NSModalResponseOK) && filterInfo.doFileTypes) { /* * The -typevariable must be set to the selected file type, if the diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c index b9c9b6a..6e778a4 100644 --- a/macosx/tkMacOSXEvent.c +++ b/macosx/tkMacOSXEvent.c @@ -34,7 +34,7 @@ enum { NSInteger subtype; switch ((NSInteger)type) { - case NSAppKitDefined: + case NSEventTypeAppKitDefined: subtype = [theEvent subtype]; switch (subtype) { diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 7f1cc72..e4f7e82 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -1,7 +1,7 @@ /* * tkMacOSXFont.c -- * - * Contains the Macintosh implementation of the platform-independant font + * Contains the Macintosh implementation of the platform-independent font * package interface. * * Copyright 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de @@ -16,10 +16,6 @@ #include "tkMacOSXFont.h" #include "tkMacOSXConstants.h" -#define defaultOrientation kCTFontDefaultOrientation -#define verticalOrientation kCTFontVerticalOrientation -#define fixedPitch kCTFontUserFixedPitchFontType - /* #ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_FONTS @@ -277,7 +273,7 @@ InitFont( fmPtr->fixed = [nsFont advancementForGlyph:glyphs[0]].width == [nsFont advancementForGlyph:glyphs[1]].width; bounds = NSRectFromCGRect(CTFontGetBoundingRectsForGlyphs((CTFontRef) - nsFont, defaultOrientation, ch, boundingRects, nCh)); + nsFont, kCTFontOrientationDefault, ch, boundingRects, nCh)); kern = [nsFont advancementForGlyph:glyphs[2]].width - [fontPtr->nsFont advancementForGlyph:glyphs[2]].width; } @@ -394,7 +390,7 @@ TkpFontPkgInit( systemFont++; } TkInitFontAttributes(&fa); - nsFont = (NSFont*) CTFontCreateUIFontForLanguage(fixedPitch, 11, NULL); + nsFont = (NSFont*) CTFontCreateUIFontForLanguage(kCTFontUIFontUserFixedPitch, 11, NULL); if (nsFont) { GetTkFontAttributesForNSFont(nsFont, &fa); CFRelease(nsFont); @@ -1109,7 +1105,7 @@ DrawCharsInContext( [attributes setObject:(id)fg forKey:(id)kCTForegroundColorAttributeName]; CFRelease(fg); nsFont = [attributes objectForKey:NSFontAttributeName]; - [nsFont setInContext:[NSGraphicsContext graphicsContextWithGraphicsPort: + [nsFont setInContext:[NSGraphicsContext graphicsContextWithCGContext: context flipped:NO]]; CGContextSetTextMatrix(context, CGAffineTransformIdentity); attributedString = [[NSAttributedString alloc] initWithString:string diff --git a/macosx/tkMacOSXFont.h b/macosx/tkMacOSXFont.h index 08380c4..7fc9265 100644 --- a/macosx/tkMacOSXFont.h +++ b/macosx/tkMacOSXFont.h @@ -1,7 +1,7 @@ /* * tkMacOSXFont.h -- * - * Contains the Macintosh implementation of the platform-independant + * Contains the Macintosh implementation of the platform-independent * font package interface. * * Copyright (c) 1990-1994 The Regents of the University of California. diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 946bf30..cc7c23a 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -28,6 +28,13 @@ static char tkLibPath[PATH_MAX + 1] = ""; static char scriptPath[PATH_MAX + 1] = ""; +/* + * Forward declarations... + */ + +static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, + int objc, Tcl_Obj *const objv[]); + #pragma mark TKApplication(TKInit) @implementation TKApplication @@ -388,7 +395,8 @@ TkpInit( TkMacOSXRegisterServiceWidgetObjCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "::tk::mac::iconBitmap", TkMacOSXIconBitmapObjCmd, NULL, NULL); - Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", TkMacOSXGetAppPath,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); + Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", + TkMacOSXGetAppPathCmd, NULL, NULL); /* * Initialize the NSServices object here. Apple's docs say to do this @@ -437,11 +445,11 @@ TkpGetAppName( } Tcl_DStringAppend(namePtr, name, -1); } - + /* *---------------------------------------------------------------------- * - * TkMacOSXGetAppPath -- + * TkMacOSXGetAppPathCmd -- * * Returns the path of the Wish application bundle. * @@ -453,42 +461,39 @@ TkpGetAppName( * *---------------------------------------------------------------------- */ -int TkMacOSXGetAppPath( - ClientData cd, - Tcl_Interp *ip, - int objc, - Tcl_Obj *CONST objv[]) -{ - - CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - - - /* - * Convert the URL reference into a string reference. - */ - - CFStringRef appPath = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle); - /* - * Get the system encoding method. - */ - - CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); +static int +TkMacOSXGetAppPathCmd( + ClientData ignored, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + if (objc != 1) { + Tcl_WrongNumArgs(interp, 1, objv, NULL); + return TCL_ERROR; + } - /* - * Convert the string reference into a C string. - */ + /* + * Get the application path URL and convert it to a string path reference. + */ - char *path = (char *) CFStringGetCStringPtr(appPath, encodingMethod); + CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFStringRef appPath = + CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle); - Tcl_SetResult(ip, path, NULL); + /* + * Convert (and copy) the string reference into a Tcl result. + */ - CFRelease(mainBundleURL); - CFRelease(appPath); - return TCL_OK; + Tcl_SetObjResult(interp, Tcl_NewStringObj( + CFStringGetCStringPtr(appPath, CFStringGetSystemEncoding()), -1)); + CFRelease(mainBundleURL); + CFRelease(appPath); + return TCL_OK; } - + /* *---------------------------------------------------------------------- * @@ -555,7 +560,7 @@ TkMacOSXDefaultStartupScript(void) CFURLRef scriptFldrURL; char startupScript[PATH_MAX + 1]; - if (CFURLGetFileSystemRepresentation (appMainURL, true, + if (CFURLGetFileSystemRepresentation(appMainURL, true, (unsigned char *) startupScript, PATH_MAX)) { Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL); scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL, diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c index 8691ce2..65b7aee 100644 --- a/macosx/tkMacOSXKeyEvent.c +++ b/macosx/tkMacOSXKeyEvent.c @@ -259,7 +259,8 @@ unsigned short releaseCode; @implementation TKContentView -(id)init { - if (self = [super init]) { + self = [super init]; + if (self) { _needsRedisplay = NO; } return self; diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index 790b6ff..b6fca79 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -662,7 +662,7 @@ TkpConfigureMenuEntry( [menuItem setEnabled:!(mePtr->state == ENTRY_DISABLED)]; [menuItem setState:((mePtr->type == CHECK_BUTTON_ENTRY || mePtr->type == RADIO_BUTTON_ENTRY) && mePtr->indicatorOn && - (mePtr->entryFlags & ENTRY_SELECTED) ? NSOnState : NSOffState)]; + (mePtr->entryFlags & ENTRY_SELECTED) ? NSControlStateValueOn : NSControlStateValueOff)]; if (mePtr->type != CASCADE_ENTRY && mePtr->accelPtr && mePtr->accelLength) { keyEquivalent = ParseAccelerator(Tcl_GetString(mePtr->accelPtr), &modifierMask); diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index 0cf7cd6..2517769 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -51,7 +51,7 @@ enum { { NSWindow *eventWindow = [theEvent window]; NSEventType eventType = [theEvent type]; - TkWindow *winPtr, *grabWinPtr; + TkWindow *winPtr = NULL, *grabWinPtr; Tk_Window tkwin; NSPoint local, global; #if 0 diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index a67f894..60b24f6 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -115,9 +115,10 @@ * Macro abstracting use of TkMacOSXGetNamedSymbol to init named symbols. */ +#define UNINITIALISED_SYMBOL ((void*)(-1L)) #define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \ - static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \ - if (symbol == (void*)(-1L)) { \ + static ret (* symbol)(__VA_ARGS__) = UNINITIALISED_SYMBOL; \ + if (symbol == UNINITIALISED_SYMBOL) { \ symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \ STRINGIFY(symbol)); \ } @@ -341,10 +342,7 @@ VISIBILITY_HIDDEN { @private NSString *privateWorkingText; -#ifdef __i386__ - /* The Objective C runtime used on i386 requires this. */ Bool _needsRedisplay; -#endif } @property Bool needsRedisplay; @end @@ -430,9 +428,7 @@ VISIBILITY_HIDDEN @end #endif /* _TKMACPRIV */ - -int TkMacOSXGetAppPath(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]); - + /* * Local Variables: * mode: objc diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c index 06e0a64..0f92c70 100644 --- a/macosx/tkMacOSXScrlbr.c +++ b/macosx/tkMacOSXScrlbr.c @@ -8,7 +8,7 @@ * Copyright 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2015 Kevin Walzer/WordTech Commununications LLC. - * Copyright (c) 2018 Marc Culler + * Copyright (c) 2018-2019 Marc Culler * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -18,14 +18,13 @@ #include "tkScrollbar.h" #include "tkMacOSXPrivate.h" -#define MIN_SCROLLBAR_VALUE 0 - /* * Minimum slider length, in pixels (designed to make sure that the slider is * always easy to grab with the mouse). */ -#define MIN_SLIDER_LENGTH 5 +#define MIN_SLIDER_LENGTH 18 +#define MIN_GAP 4 /* * Borrowed from ttkMacOSXTheme.c to provide appropriate scaling. @@ -88,7 +87,8 @@ typedef struct ScrollbarMetrics { } ScrollbarMetrics; static ScrollbarMetrics metrics = { - 15, 54, 26, 14, 14, kControlSizeNormal /* kThemeScrollBarMedium */ + /* kThemeScrollBarMedium */ + 15, MIN_SLIDER_LENGTH, 26, 14, 14, kControlSizeNormal }; /* @@ -160,6 +160,80 @@ TkpCreateScrollbar( *-------------------------------------------------------------- */ +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1080 + +/* + * This stand-alone drawing function is used on macOS 10.9 and newer because + * the HIToolbox does not draw the scrollbar thumb at the expected size on + * those systems. The thumb is drawn too large, causing a mouse click on the + * thumb to be interpreted as a mouse click in the trough. + */ + +static void drawMacScrollbar( + TkScrollbar *scrollPtr, + MacScrollbar *msPtr, + CGContextRef context) +{ + MacDrawable *macWin = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin); + NSView *view = TkMacOSXDrawableView(macWin); + CGPathRef path; + CGPoint inner[2], outer[2], thumbOrigin; + CGSize thumbSize; + CGRect troughBounds = msPtr->info.bounds; + troughBounds.origin.y = [view bounds].size.height - + (troughBounds.origin.y + troughBounds.size.height); + if (scrollPtr->vertical) { + thumbOrigin.x = troughBounds.origin.x + MIN_GAP; + thumbOrigin.y = troughBounds.origin.y + scrollPtr->sliderFirst; + thumbSize.width = troughBounds.size.width - 2*MIN_GAP + 1; + thumbSize.height = scrollPtr->sliderLast - scrollPtr->sliderFirst; + inner[0] = troughBounds.origin; + inner[1] = CGPointMake(inner[0].x, + inner[0].y + troughBounds.size.height); + outer[0] = CGPointMake(inner[0].x + troughBounds.size.width - 1, + inner[0].y); + outer[1] = CGPointMake(outer[0].x, inner[1].y); + } else { + thumbOrigin.x = troughBounds.origin.x + scrollPtr->sliderFirst; + thumbOrigin.y = troughBounds.origin.y + MIN_GAP; + thumbSize.width = scrollPtr->sliderLast - scrollPtr->sliderFirst; + thumbSize.height = troughBounds.size.height - 2*MIN_GAP + 1; + inner[0] = troughBounds.origin; + inner[1] = CGPointMake(inner[0].x + troughBounds.size.width, + inner[0].y + 1); + outer[0] = CGPointMake(inner[0].x, + inner[0].y + troughBounds.size.height); + outer[1] = CGPointMake(inner[1].x, outer[0].y); + } + CGContextSetShouldAntialias(context, false); + CGContextSetGrayFillColor(context, 250.0 / 255, 1.0); + CGContextFillRect(context, troughBounds); + CGContextSetGrayStrokeColor(context, 232.0 / 255, 1.0); + CGContextStrokeLineSegments(context, inner, 2); + CGContextSetGrayStrokeColor(context, 238.0 / 255, 1.0); + CGContextStrokeLineSegments(context, outer, 2); + + /* + * Do not display the thumb unless scrolling is possible. + */ + + if (scrollPtr->firstFraction > 0.0 || scrollPtr->lastFraction < 1.0) { + CGRect thumbBounds = {thumbOrigin, thumbSize}; + path = CGPathCreateWithRoundedRect(thumbBounds, 4, 4, NULL); + CGContextBeginPath(context); + CGContextAddPath(context, path); + if (msPtr->info.trackInfo.scrollbar.pressState != 0) { + CGContextSetGrayFillColor(context, 133.0 / 255, 1.0); + } else { + CGContextSetGrayFillColor(context, 200.0 / 255, 1.0); + } + CGContextSetShouldAntialias(context, true); + CGContextFillPath(context); + CFRelease(path); + } +} +#endif + void TkpDisplayScrollbar( ClientData clientData) /* Information about window. */ @@ -185,6 +259,10 @@ TkpDisplayScrollbar( return; } + /* + * Transform NSView coordinates to CoreGraphics coordinates. + */ + CGFloat viewHeight = [view bounds].size.height; CGAffineTransform t = { .a = 1, .b = 0, @@ -229,13 +307,22 @@ TkpDisplayScrollbar( if (SNOW_LEOPARD_STYLE) { HIThemeDrawTrack(&msPtr->info, 0, dc.context, - kHIThemeOrientationInverted); - } else { + kHIThemeOrientationInverted); + } else if ([NSApp macMinorVersion] <= 8) { HIThemeDrawTrack(&msPtr->info, 0, dc.context, - kHIThemeOrientationNormal); + kHIThemeOrientationNormal); + } else { +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1080 + + /* + * Switch back to NSView coordinates and draw a modern scrollbar. + */ + + CGContextConcatCTM(dc.context, t); + drawMacScrollbar(scrollPtr, msPtr, dc.context); +#endif } TkMacOSXRestoreDrawingContext(&dc); - scrollPtr->flags &= ~REDRAW_PENDING; } @@ -297,23 +384,24 @@ TkpComputeScrollbarGeometry( scrollPtr->sliderLast = fieldLength*scrollPtr->lastFraction; /* - * Adjust the slider so that some piece of it is always displayed in the - * scrollbar and so that it has at least a minimal width (so it can be - * grabbed with the mouse). + * Adjust the slider so that it has at least a minimal size and so there + * is a small gap on either end which can be used to scroll by one page. */ + if (scrollPtr->sliderFirst < MIN_GAP) { + scrollPtr->sliderFirst = MIN_GAP; + scrollPtr->sliderLast += MIN_GAP; + } + if (scrollPtr->sliderLast > fieldLength - MIN_GAP) { + scrollPtr->sliderLast = fieldLength - MIN_GAP; + scrollPtr->sliderFirst -= MIN_GAP; + } if (scrollPtr->sliderFirst > fieldLength - MIN_SLIDER_LENGTH) { scrollPtr->sliderFirst = fieldLength - MIN_SLIDER_LENGTH; } - if (scrollPtr->sliderFirst < 0) { - scrollPtr->sliderFirst = 0; - } if (scrollPtr->sliderLast < scrollPtr->sliderFirst + MIN_SLIDER_LENGTH) { scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH; } - if (scrollPtr->sliderLast > fieldLength) { - scrollPtr->sliderLast = fieldLength; - } scrollPtr->sliderFirst += -scrollPtr->arrowLength + scrollPtr->inset; scrollPtr->sliderLast += scrollPtr->inset; @@ -511,7 +599,7 @@ UpdateControlValues( msPtr->info.bounds = contrlRect; width = contrlRect.size.width; - height = contrlRect.size.height; + height = contrlRect.size.height - scrollPtr->arrowLength; /* * Ensure we set scrollbar control bounds only once all size adjustments @@ -535,10 +623,9 @@ UpdateControlValues( * the view area. */ - double maximum = 100, factor = RangeToFactor(maximum); - + double factor = RangeToFactor(100.0); dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction) * factor; - msPtr->info.max = MIN_SCROLLBAR_VALUE + factor - dViewSize; + msPtr->info.max = factor - dViewSize; msPtr->info.trackInfo.scrollbar.viewsize = dViewSize; if (scrollPtr->vertical) { if (SNOW_LEOPARD_STYLE) { @@ -548,8 +635,7 @@ UpdateControlValues( factor * scrollPtr->firstFraction; } } else { - msPtr->info.value = MIN_SCROLLBAR_VALUE + - factor * scrollPtr->firstFraction; + msPtr->info.value = factor * scrollPtr->firstFraction; } if ((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0) @@ -616,6 +702,7 @@ ScrollbarEvent( kThemeBottomTrackPressed; break; case TOP_ARROW: + /* * This looks wrong and the docs say it is wrong but it works. */ @@ -647,6 +734,7 @@ ScrollbarEvent( msPtr->info.trackInfo.scrollbar.pressState = 0; } } + TkScrollbarEventuallyRedraw(scrollPtr); return TCL_OK; } diff --git a/macosx/tkMacOSXServices.c b/macosx/tkMacOSXServices.c index af40a91..f1e5951 100644 --- a/macosx/tkMacOSXServices.c +++ b/macosx/tkMacOSXServices.c @@ -1,6 +1,6 @@ /* * tkMacOSXServices.c -- - * + *\ * This file allows the integration of Tk and the Cocoa NSServices API. * * Copyright (c) 2010-2019 Kevin Walzer/WordTech Communications LLC. @@ -54,7 +54,6 @@ ServicesEventProc( NSArray *sendTypes = [NSArray arrayWithObjects:@"NSStringPboardType", @"NSPasteboardTypeString", nil]; [NSApp registerServicesMenuSendTypes:sendTypes returnTypes:sendTypes]; - NSUpdateDynamicServices(); return; } @@ -121,7 +120,7 @@ ServicesEventProc( userData:(NSString *)data error:(NSString **)error { - NSString *pboardString, *pboardType; + NSString *pboardString = nil, *pboardType = nil; NSArray *types = [pboard types]; Tcl_Event *event; @@ -157,16 +156,16 @@ ServicesEventProc( int TkMacOSXRegisterServiceWidgetObjCmd( ClientData cd, - Tcl_Interp *ip, + Tcl_Interp *interp, int objc, - Tcl_Obj *CONST objv[]) + Tcl_Obj *const objv[]) { /* * Need proper number of args. */ if (objc != 2) { - Tcl_WrongNumArgs(ip, 1, objv, "path?"); + Tcl_WrongNumArgs(interp, 1, objv, "path?"); return TCL_ERROR; } @@ -176,8 +175,8 @@ TkMacOSXRegisterServiceWidgetObjCmd( Rect bounds; NSRect frame; - Tk_Window path = - Tk_NameToWindow(ip, Tcl_GetString(objv[1]), Tk_MainWindow(ip)); + Tk_Window path = Tk_NameToWindow(interp, + Tcl_GetString(objv[1]), Tk_MainWindow(interp)); if (path == NULL) { return TCL_ERROR; diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index eabc14e..f109b7a 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -50,8 +50,7 @@ TkplatformtestInit( */ #if MAC_OS_X_VERSION_MAX_ALLOWED < 1080 - Tcl_CreateObjCommand(interp, "debugger", DebuggerObjCmd, - (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "debugger", DebuggerObjCmd, NULL, NULL); #endif return TCL_OK; diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 767b9b4..b510d07 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -1015,7 +1015,7 @@ TkWmDeadWindow( */ if (winPtr->parentPtr) { - while (Tk_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {} + while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {} } [NSApp _resetAutoreleasePool]; #if DEBUG_ZOMBIES > 0 diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index 66cd611..c664cb1 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -1042,7 +1042,6 @@ static void DrawDarkFocusRing( {x, y + h}, {x, y + 1}, {x + w - 1, y + 1}, {x + w - 1, y + h} }; CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}}; - CGRect outerRect = CGRectInset(bounds, -3, -3); CGContextSaveGState(context); CGContextSetShouldAntialias(context, false); @@ -1061,7 +1060,8 @@ static void DrawDarkFocusRing( CGContextStrokePath(context); CGContextSetShouldAntialias(context, true); CGContextSetFillColorWithColor(context, CGCOLOR(fillColor)); - CGPathRef path = CGPathCreateWithRoundedRect(outerRect, 4, 4, NULL); + CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(bounds, -3, -3), + 4, 4, NULL); CGContextBeginPath(context); CGContextAddPath(context, path); CGContextAddRect(context, bounds); @@ -1091,6 +1091,7 @@ static void DrawDarkFrame( }; CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}}; CGPoint accent[2] = {{x, y + 1}, {x + w, y + 1}}; + switch (kind) { case kHIThemeFrameTextFieldSquare: CGContextSaveGState(context); @@ -2346,11 +2347,13 @@ static void ThumbElementSize( int orientation = TTK_ORIENT_HORIZONTAL; Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation); - if (orientation == TTK_ORIENT_HORIZONTAL) { - *minHeight = 8; - } else { + if (orientation == TTK_ORIENT_VERTICAL) { + *minHeight = 18; *minWidth = 8; - } + } else { + *minHeight = 8; + *minWidth = 18; + } } static void ThumbElementDraw( @@ -2371,15 +2374,11 @@ static void ThumbElementDraw( * able to display the thumb element at the size and location which the ttk * scrollbar widget requests. The algorithm that HIToolbox uses to * determine the thumb geometry from the input values of min, max, value - * and viewSize is, of course, undocumented. And this turns out to be a - * hard reverse engineering problem. A seemingly natural algorithm is - * implemented below, but it does not correctly compute the same thumb - * geometry as HITools (which also apparently does not agree with - * NSScrollbar). This code uses that algorithm for older OS versions, + * and viewSize is undocumented. A seemingly natural algorithm is + * implemented below. This code uses that algorithm for older OS versions, * because using HITools also handles drawing the buttons and 3D thumb used - * on those systems. The incorrect geometry is annoying but not completely - * unusable. For newer systems the cleanest approach is to just draw the - * thumb directly. + * on those systems. For newer systems the cleanest approach is to just + * draw the thumb directly. */ if ([NSApp macMinorVersion] > 8) { @@ -2407,7 +2406,7 @@ static void ThumbElementDraw( SolidFillRoundedRectangle(dc.context, thumbBounds, 4, thumbColor); END_DRAWING } else { - double thumbSize, trackSize, visibleSize, viewSize; + double thumbSize, trackSize, visibleSize, factor, fraction; MacDrawable *macWin = (MacDrawable *) Tk_WindowId(tkwin); CGRect troughBounds = {{macWin->xOff, macWin->yOff}, {Tk_Width(tkwin), Tk_Height(tkwin)}}; @@ -2421,7 +2420,6 @@ static void ThumbElementDraw( * largest int. */ - viewSize = RangeToFactor(100.0); HIThemeTrackDrawInfo info = { .version = 0, .bounds = troughBounds, @@ -2430,19 +2428,24 @@ static void ThumbElementDraw( kThemeTrackThumbRgnIsNotGhost, .enableState = kThemeTrackActive }; - info.trackInfo.scrollbar.viewsize = viewSize * .8; + factor = RangeToFactor(100.0); if (orientation == TTK_ORIENT_HORIZONTAL) { trackSize = troughBounds.size.width; thumbSize = b.width; - visibleSize = (thumbSize / trackSize) * viewSize; - info.max = viewSize - visibleSize; - info.value = info.max * (b.x / (trackSize - thumbSize)); + fraction = b.x / trackSize; } else { - thumbSize = b.height; trackSize = troughBounds.size.height; - visibleSize = (thumbSize / trackSize) * viewSize; - info.max = viewSize - visibleSize; - info.value = info.max * (b.y / (trackSize - thumbSize)); + thumbSize = b.height; + fraction = b.y / trackSize; + } + visibleSize = (thumbSize / trackSize) * factor; + info.max = factor - visibleSize; + info.trackInfo.scrollbar.viewsize = visibleSize; + if ([NSApp macMinorVersion] < 8 || + orientation == TTK_ORIENT_HORIZONTAL) { + info.value = factor * fraction; + } else { + info.value = info.max - factor * fraction; } if ((state & TTK_STATE_PRESSED) || (state & TTK_STATE_HOVER)) { @@ -3120,8 +3123,7 @@ static int AquaTheme_Init( /* * <<NOTE-TRACKS>> - * In some themes the Layouts for a progress bar has a trough element and - *a + * In some themes the Layouts for a progress bar has a trough element and a * pbar element. But in our case the appearance manager draws both parts * of the progress bar, so we just have a single element called ".track". */ |