diff options
author | culler <culler> | 2019-06-28 22:23:52 (GMT) |
---|---|---|
committer | culler <culler> | 2019-06-28 22:23:52 (GMT) |
commit | 26cd390c97c1fce54db1123b1c35fd381ac721bf (patch) | |
tree | 7c4ed7995db9769d6c29fe6749b8252ba8be8738 /macosx | |
parent | fde1c03942e4b7b565abc9532cf439bbe42643f7 (diff) | |
parent | 805e7986218616c662f180c3e0ae30844d0ad5c7 (diff) | |
download | tk-26cd390c97c1fce54db1123b1c35fd381ac721bf.zip tk-26cd390c97c1fce54db1123b1c35fd381ac721bf.tar.gz tk-26cd390c97c1fce54db1123b1c35fd381ac721bf.tar.bz2 |
Fix Tk scrollbar and merge core-8-6-branch
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/README | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXHLEvents.c | 8 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 34 | ||||
-rw-r--r-- | macosx/tkMacOSXPrivate.h | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXScrlbr.c | 104 | ||||
-rw-r--r-- | macosx/tkMacOSXServices.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXTest.c | 3 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 2 |
8 files changed, 115 insertions, 42 deletions
diff --git a/macosx/README b/macosx/README index f35c128..7df4893 100644 --- a/macosx/README +++ b/macosx/README @@ -702,7 +702,7 @@ that LaunchServices is launching the correct Wish.app. Instructions for doing this are provided below. The command line tool which manages the LaunchServices database has -an amazingly unwieldy path name. So, first, run this command: +an amazingly unwieldy path name. So, first, run this command: alias lsregister='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister' diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c index d2843a8..0f63ea6 100644 --- a/macosx/tkMacOSXHLEvents.c +++ b/macosx/tkMacOSXHLEvents.c @@ -126,7 +126,7 @@ static int ReallyKillMe(Tcl_Event *eventPtr, int flags); - (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { - + NSString* file = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; const char *printFile=[file UTF8String]; @@ -134,7 +134,7 @@ static int ReallyKillMe(Tcl_Event *eventPtr, int flags); Tcl_DStringInit(&print); if (Tcl_FindCommand(_eventInterp, "::tk::mac::PrintDocument", NULL, 0)) { Tcl_DStringAppend(&print, "::tk::mac::PrintDocument", -1); - } + } Tcl_DStringAppendElement(&print, printFile); int tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&print), Tcl_DStringLength(&print), TCL_EVAL_GLOBAL); @@ -272,7 +272,7 @@ static int ReallyKillMe(Tcl_Event *eventPtr, int flags); Tcl_DStringInit(&launch); if (Tcl_FindCommand(_eventInterp, "::tk::mac::LaunchURL", NULL, 0)) { Tcl_DStringAppend(&launch, "::tk::mac::LaunchURL", -1); - } + } Tcl_DStringAppendElement(&launch, cURL); int tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&launch), Tcl_DStringLength(&launch), TCL_EVAL_GLOBAL); @@ -454,7 +454,7 @@ TkMacOSXInitAppleEvents( [aeManager setEventHandler:NSApp andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; - + } } diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 3efe0c6..bf0b9f2 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -388,14 +388,14 @@ 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", TkMacOSXGetAppPath, NULL, NULL); /* * Initialize the NSServices object here. Apple's docs say to do this - * in applicationDidFinishLaunching, but the Tcl interpreter is not - * initialized until this function call. + * in applicationDidFinishLaunching, but the Tcl interpreter is not + * initialized until this function call. */ - + TkMacOSXServices_Init(interp); return TCL_OK; @@ -457,28 +457,28 @@ int TkMacOSXGetAppPath( ClientData cd, Tcl_Interp *ip, int objc, - Tcl_Obj *CONST objv[]) + Tcl_Obj *const objv[]) { CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - - /* - * Convert the URL reference into a string reference. + + /* + * Convert the URL reference into a string reference. */ - + CFStringRef appPath = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle); - - /* - * Get the system encoding method. + + /* + * Get the system encoding method. */ - + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); - - /* - * Convert the string reference into a C string. + + /* + * Convert the string reference into a C string. */ - + char *path = (char *) CFStringGetCStringPtr(appPath, encodingMethod); Tcl_SetResult(ip, path, NULL); diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index a67f894..98ee54f 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -431,7 +431,7 @@ VISIBILITY_HIDDEN #endif /* _TKMACPRIV */ -int TkMacOSXGetAppPath(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]); +int TkMacOSXGetAppPath(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *const objv[]); /* * Local Variables: diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c index 06e0a64..1928886 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. @@ -25,7 +25,8 @@ * always easy to grab with the mouse). */ -#define MIN_SLIDER_LENGTH 5 +#define MIN_SLIDER_LENGTH 8 +#define MIN_GAP 4 /* * Borrowed from ttkMacOSXTheme.c to provide appropriate scaling. @@ -160,6 +161,63 @@ TkpCreateScrollbar( *-------------------------------------------------------------- */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 + +static void drawMacScrollbar( + TkScrollbar *scrollPtr, + MacScrollbar *msPtr, + CGContextRef context) +{ + MacDrawable *macWin = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin); + NSView *view = TkMacOSXDrawableView(macWin); + NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; + CGPathRef path; + CGPoint inner[2], outer[2]; + NSColor *troughColor, *thumbColor; + CGFloat *rgba; + CGRect troughBounds = msPtr->info.bounds, thumbBounds; + troughBounds.origin.y = [view bounds].size.height - + (troughBounds.origin.y + troughBounds.size.height); + if (scrollPtr->vertical) { + thumbBounds.origin.x = troughBounds.origin.x + MIN_GAP; + thumbBounds.origin.y = troughBounds.origin.y + scrollPtr->sliderFirst; + thumbBounds.size.width = troughBounds.size.width - 2*MIN_GAP; + thumbBounds.size.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 { + thumbBounds.origin.x = troughBounds.origin.x + scrollPtr->sliderFirst + MIN_GAP; + thumbBounds.origin.y = troughBounds.origin.x + MIN_GAP; + thumbBounds.size.width = scrollPtr->sliderLast - scrollPtr->sliderFirst; + thumbBounds.size.height -= troughBounds.size.height - 2*MIN_GAP; + inner[0] = troughBounds.origin; + inner[1] = CGPointMake(inner[0].x + troughBounds.size.width, inner[0].y); + 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); + 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 +243,10 @@ TkpDisplayScrollbar( return; } + /* + * Transform NSView coordinates to CoreGraphics coordinates. + */ + CGFloat viewHeight = [view bounds].size.height; CGAffineTransform t = { .a = 1, .b = 0, @@ -229,13 +291,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 +368,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; @@ -616,6 +688,7 @@ ScrollbarEvent( kThemeBottomTrackPressed; break; case TOP_ARROW: + /* * This looks wrong and the docs say it is wrong but it works. */ @@ -647,6 +720,7 @@ ScrollbarEvent( msPtr->info.trackInfo.scrollbar.pressState = 0; } } + TkScrollbarEventuallyRedraw(scrollPtr); return TCL_OK; } diff --git a/macosx/tkMacOSXServices.c b/macosx/tkMacOSXServices.c index 6ecb12d..809c708 100644 --- a/macosx/tkMacOSXServices.c +++ b/macosx/tkMacOSXServices.c @@ -158,7 +158,7 @@ TkMacOSXRegisterServiceWidgetObjCmd( ClientData cd, Tcl_Interp *ip, int objc, - Tcl_Obj *CONST objv[]) + Tcl_Obj *const objv[]) { /* * Need proper number of args. 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 c58dd5a..1353577 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -1015,7 +1015,7 @@ TkWmDeadWindow( */ if (winPtr->parentPtr) { - while (Tcl_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {} + while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT)) {} } [NSApp _resetAutoreleasePool]; #if DEBUG_ZOMBIES > 0 |