diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-08-14 08:30:49 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-08-14 08:30:49 (GMT) |
commit | 499d2cfd016df0e17cfd7b96fe70d61a7964a644 (patch) | |
tree | 7cad7402662fce0760e1c14940052e16e052b84d | |
parent | f8e123a7ce6504a4682cc507edae2eb8b696621f (diff) | |
parent | 9e7ea957b3c08bb06ba7a98956bfc39fca90f3cb (diff) | |
download | tk-499d2cfd016df0e17cfd7b96fe70d61a7964a644.zip tk-499d2cfd016df0e17cfd7b96fe70d61a7964a644.tar.gz tk-499d2cfd016df0e17cfd7b96fe70d61a7964a644.tar.bz2 |
Merge trunk
-rw-r--r-- | doc/colors.n | 26 | ||||
-rw-r--r-- | generic/tkBusy.c | 6 | ||||
-rw-r--r-- | generic/tkFont.c | 4 | ||||
-rw-r--r-- | generic/tkPanedWindow.c | 2 | ||||
-rw-r--r-- | generic/ttk/ttkTreeview.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXColor.c | 53 | ||||
-rw-r--r-- | macosx/tkMacOSXColor.h | 15 | ||||
-rw-r--r-- | macosx/tkMacOSXMenu.c | 4 | ||||
-rw-r--r-- | tests/busy.test | 4 | ||||
-rw-r--r-- | tests/font.test | 10 | ||||
-rw-r--r-- | tests/textMark.test | 2 |
11 files changed, 87 insertions, 41 deletions
diff --git a/doc/colors.n b/doc/colors.n index 6a99362..3747ee8 100644 --- a/doc/colors.n +++ b/doc/colors.n @@ -868,12 +868,16 @@ systemWindowBody .DE .RE . -The group of MacOS colors below are based on Apple's "semantic" -NSColors. On OSX 10.14 (Mojave) and later these colors change value -when Dark Mode is enabled. The numbered systemWindowBackgroundColors -are used in the \fBttk::notebook\fR and \fBttk::labelframe\fR widgets -to provide a contrasting background. Each numbered color constrasts -with its predecessor. +Tk supports all of the NSColors in the macOS System ColorList. The +convention for naming these colors is that the Tk name is generated by +capitalizing the macOS name and adding the prefix "system". On OSX +10.14 (Mojave) and later many of these "semantic" colors will appear +differently depending on whether the NSWindow in which they are used has +the Aqua or DarkAqua appearance. The System ColorList differs between +releases of macOS and some colors, such as systemLinkColor and +systemControlAccentColor, are simulated on older systems which did not +provide them. All of the colors below are available on all supported +macOS releases, but newer systems will support additional colors. .RS .DS systemControlAccentColor @@ -887,6 +891,15 @@ systemSelectedTextColor systemSeparatorColor systemTextBackgroundColor systemTextColor +.DE +.RE +. +The numbered systemWindowBackgroundColors below +are used in the \fBttk::notebook\fR and \fBttk::labelframe\fR widgets +to provide a contrasting background. Each numbered color constrasts +with its predecessor. +.RS +.DS systemWindowBackgroundColor systemWindowBackgroundColor1 systemWindowBackgroundColor2 @@ -899,7 +912,6 @@ systemWindowBackgroundColor7 .RE .TP - \fBWindows\fR . On Windows, the following additional system colors are available diff --git a/generic/tkBusy.c b/generic/tkBusy.c index cad4032..cf66b9e 100644 --- a/generic/tkBusy.c +++ b/generic/tkBusy.c @@ -819,7 +819,7 @@ Tk_BusyObjCmd( if (Tcl_GetString(objv[1])[0] == '.') { if (objc%2 == 1) { - Tcl_WrongNumArgs(interp, 1, objv, "window ?option value ...?"); + Tcl_WrongNumArgs(interp, 1, objv, "window ?-option value ...?"); return TCL_ERROR; } return HoldBusy(busyTablePtr, interp, objv[1], objc-2, objv+2); @@ -865,7 +865,7 @@ Tk_BusyObjCmd( case BUSY_CONFIGURE: if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "window ?option? ?value ...?"); + Tcl_WrongNumArgs(interp, 2, objv, "window ?-option? ?value ...?"); return TCL_ERROR; } busyPtr = GetBusy(interp, busyTablePtr, objv[2]); @@ -922,7 +922,7 @@ Tk_BusyObjCmd( case BUSY_HOLD: if (objc < 3 || objc%2 != 1) { - Tcl_WrongNumArgs(interp, 2, objv, "window ?option value ...?"); + Tcl_WrongNumArgs(interp, 2, objv, "window ?-option value ...?"); return TCL_ERROR; } return HoldBusy(busyTablePtr, interp, objv[2], objc-3, objv+3); diff --git a/generic/tkFont.c b/generic/tkFont.c index dbc00e4..d2aa6d2 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -556,7 +556,7 @@ Tk_FontObjCmd( if (objc < 3 || n < objc) { Tcl_WrongNumArgs(interp, 2, objv, - "font ?-displayof window? ?option? ?--? ?char?"); + "font ?-displayof window? ?-option? ?--? ?char?"); return TCL_ERROR; } @@ -753,7 +753,7 @@ Tk_FontObjCmd( } if ((objc < 3) || ((objc - skip) > 4)) { Tcl_WrongNumArgs(interp, 2, objv, - "font ?-displayof window? ?option?"); + "font ?-displayof window? ?-option?"); return TCL_ERROR; } tkfont = Tk_AllocFontFromObj(interp, tkwin, objv[2]); diff --git a/generic/tkPanedWindow.c b/generic/tkPanedWindow.c index bef8c52..b6f64f2 100644 --- a/generic/tkPanedWindow.c +++ b/generic/tkPanedWindow.c @@ -690,7 +690,7 @@ PanedWindowWidgetObjCmd( case PW_PANECONFIGURE: if (objc < 3) { Tcl_WrongNumArgs(interp, 2, objv, - "pane ?option? ?value option value ...?"); + "pane ?-option? ?value -option value ...?"); result = TCL_ERROR; break; } diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index cab9c34..e506b25 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -2377,7 +2377,7 @@ static int TreeviewItemCommand( TreeItem *item; if (objc < 3) { - Tcl_WrongNumArgs(interp, 2, objv, "item ?option ?value??..."); + Tcl_WrongNumArgs(interp, 2, objv, "item ?-option ?value??..."); return TCL_ERROR; } if (!(item = FindItem(interp, tv, objv[2]))) { diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 12924ee..01732c0 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -35,11 +35,14 @@ static CGFloat windowBackground[4] = void initColorTable() { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; Tcl_InitHashTable(&systemColors, TCL_STRING_KEYS); SystemColorDatum *entry, *oldEntry; Tcl_HashSearch search; Tcl_HashEntry *hPtr; int newPtr, index = 0; + NSColorList *systemColorList = [NSColorList colorListNamed:@"System"]; + NSString *key; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 if (@available(macOS 10.14, *)) { @@ -50,6 +53,7 @@ void initColorTable() /* * Build a hash table for looking up a color by its name. + * First add all of the static entries from tkMacOSXColor.h */ for (entry = systemColorData; entry->name != NULL; entry++) { @@ -81,6 +85,40 @@ void initColorTable() } /* + * Add all of the colors in the System ColorList. + */ + + for (key in [systemColorList allKeys]) { + int length = [key lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + char *name; + entry = ckalloc(sizeof(SystemColorDatum)); + bzero(entry, sizeof(SystemColorDatum)); + name = ckalloc(length + 1); + strcpy(name, key.UTF8String); + name[0] = toupper(name[0]); + if (!strcmp(name, "WindowBackgroundColor")) { + + /* + * Avoid black windows on old systems. + */ + + continue; + } + entry->type=semantic; + entry->name = name; + entry->selector = [key retain]; + hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr); + if (newPtr == 0) { + oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); + entry->index = oldEntry->index; + [oldEntry->selector release]; + } else { + entry->index = index++; + } + Tcl_SetHashValue(hPtr, entry); + } + + /* * Build an array for looking up a color by its index. */ @@ -105,6 +143,7 @@ void initColorTable() hPtr = Tcl_FindHashEntry(&systemColors, "ControlAccentColor"); entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); controlAccentIndex = entry->index; + [pool drain]; } /* @@ -211,7 +250,7 @@ GetEntryFromPixel( /* *---------------------------------------------------------------------- * - * GetRGB -- + * GetRGBA -- * * Given a SystemColorDatum and a pointer to an array of 4 CGFloats, store * the associated RGBA color values in the array. In the case of the @@ -273,7 +312,8 @@ GetRGBA( case semantic: if (entry->index == controlAccentIndex && useFakeAccentColor) { #if MAC_OS_X_VERSION_MAX_ALLOWED < 101500 - color = [NSColor colorForControlTint: [NSColor currentControlTint]]; + color = [[NSColor colorForControlTint: [NSColor currentControlTint]] + colorUsingColorSpace:sRGB]; #endif } else { color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; @@ -351,23 +391,24 @@ SetCGColorComponents( MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin) { - int result = false; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 if (@available(macOS 10.14, *)) { TkWindow *winPtr = (TkWindow*) tkwin; + NSAppearanceName name; NSView *view = nil; if (winPtr && winPtr->privatePtr) { view = TkMacOSXDrawableView(winPtr->privatePtr); } if (view) { - result = (view.effectiveAppearance == darkAqua); + name = [[view effectiveAppearance] name]; } else { - result = ([NSAppearance currentAppearance] == darkAqua); + name = [[NSAppearance currentAppearance] name]; } + return (name == NSAppearanceNameDarkAqua); } #endif - return result; + return false; } /* diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h index 1c5e3bb..58f8060 100644 --- a/macosx/tkMacOSXColor.h +++ b/macosx/tkMacOSXColor.h @@ -175,28 +175,19 @@ static SystemColorDatum systemColorData[] = { {"WindowBackgroundColor7", ttkBackground, 7, NULL, 0, NULL }, /* Apple's SecondaryLabelColor is the same as their LabelColor so we roll our own. */ {"SecondaryLabelColor", ttkBackground, 14, NULL, 0, NULL }, - -{"TextColor", semantic, 0, "textColor", 0, NULL }, -{"SelectedTextColor", semantic, 0, "selectedTextColor", 0, NULL }, -{"LabelColor", semantic, 0, "textColor", 0, NULL }, -{"LabelColor", semantic, 0, "labelColor", 0, NULL }, -{"ControlTextColor", semantic, 0, "controlTextColor", 0, NULL }, -{"DisabledControlTextColor", semantic, 0, "disabledControlTextColor", 0, NULL }, +/* Color to use for notebook tab labels. */ #if MAC_OS_X_VERSION_MAX_ALLOWED > 1060 {"SelectedTabTextColor", semantic, 0, "whiteColor", 0, NULL }, #else {"SelectedTabTextColor", semantic, 0, "blackColor", 0, NULL }, #endif -{"TextBackgroundColor", semantic, 0, "textBackgroundColor", 0, NULL }, -{"SelectedTextBackgroundColor", semantic, 0, "selectedTextBackgroundColor", 0, NULL }, +/* Semantic colors that we simulate on older systems which don't supoort them. */ {"SelectedMenuItemTextColor", semantic, 0, "selectedMenuItemTextColor", 0, NULL }, {"ControlAccentColor", semantic, 0, "controlAccentColor", 0, NULL }, +{"LabelColor", semantic, 0, "blackColor", 0, NULL }, {"LinkColor", semantic, 0, "blueColor", 0, NULL }, -{"LinkColor", semantic, 0, "linkColor", 0, NULL }, {"PlaceholderTextColor", semantic, 0, "grayColor", 0, NULL }, -{"PlaceholderTextColor", semantic, 0, "placeholderTextColor", 0, NULL }, {"SeparatorColor", semantic, 0, "grayColor", 0, NULL }, -{"SeparatorColor", semantic, 0, "separatorColor", 0, NULL }, {NULL, 0, 0, NULL, 0, NULL } }; diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index c03bda3..dace0a1 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -138,6 +138,7 @@ static int ModifierCharWidth(Tk_Font tkfont); @implementation TKBackgroundLoop - (void) main { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSArray *modeArray = [NSArray arrayWithObjects: NSEventTrackingRunLoopMode, nil]; while(1) { @@ -150,7 +151,7 @@ static int ModifierCharWidth(Tk_Font tkfont); withObject:nil waitUntilDone:true modes:modeArray]; - if (self.cancelled) { + if ([self isCancelled]) { [NSThread exit]; } @@ -160,6 +161,7 @@ static int ModifierCharWidth(Tk_Font tkfont); [NSThread sleepForTimeInterval:0.001]; } + [pool drain]; } @end diff --git a/tests/busy.test b/tests/busy.test index 6a1263f..c743cec 100644 --- a/tests/busy.test +++ b/tests/busy.test @@ -21,7 +21,7 @@ test busy-1.1 {Tk_BusyObjCmd} -returnCodes error -body { test busy-2.1 {tk busy hold} -returnCodes error -body { tk busy hold -} -result {wrong # args: should be "tk busy hold window ?option value ...?"} +} -result {wrong # args: should be "tk busy hold window ?-option value ...?"} test busy-2.2 {tk busy hold root window} -body { set res [tk busy hold .] update @@ -182,7 +182,7 @@ test busy-3.7 {tk busy cget unix} -setup { test busy-4.1 {tk busy configure no window} -returnCodes error -body { tk busy configure -} -result {wrong # args: should be "tk busy configure window ?option? ?value ...?"} +} -result {wrong # args: should be "tk busy configure window ?-option? ?value ...?"} test busy-4.2 {tk busy configure invalid window} -body { tk busy configure .f diff --git a/tests/font.test b/tests/font.test index 92894d1..aa7137a 100644 --- a/tests/font.test +++ b/tests/font.test @@ -114,11 +114,11 @@ test font-4.1 {font command: actual: arguments} -body { test font-4.2 {font command: actual: arguments} -body { # (objc < 3) font actual -} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"} +} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"} test font-4.3 {font command: actual: arguments} -body { # (objc - skip > 4) when skip == 0 font actual xyz abc def -} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"} +} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"} test font-4.4 {font command: actual: displayof specified, so skip to next} -body { catch {font actual xyz -displayof . -size} } -result 0 @@ -128,7 +128,7 @@ test font-4.5 {font command: actual: displayof specified, so skip to next} -body test font-4.6 {font command: actual: arguments} -body { # (objc - skip > 4) when skip == 2 font actual xyz -displayof . abc def -} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"} +} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"} test font-4.7 {font command: actual: arguments} -constraints noExceed -body { # (tkfont == NULL) font actual "\{xyz" @@ -430,11 +430,11 @@ test font-10.2 {font command: metrics: arguments} -body { test font-10.3 {font command: metrics: arguments} -body { # (objc < 3) font metrics -} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?option?"} +} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?-option?"} test font-10.4 {font command: metrics: arguments} -body { # (objc - skip) > 4) when skip == 0 font metrics xyz abc def -} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?option?"} +} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?-option?"} test font-10.5 {font command: metrics: arguments} -body { # (objc - skip) > 4) when skip == 2 font metrics xyz -displayof . abc diff --git a/tests/textMark.test b/tests/textMark.test index 043ff82..b4b781c 100644 --- a/tests/textMark.test +++ b/tests/textMark.test @@ -52,7 +52,7 @@ test textMark-1.4 {TkTextMarkCmd - "gravity" option} -body { } -result {right 1.4} test textMark-1.5 {TkTextMarkCmd - "gravity" option} -body { .t mark set x 1.3 - .t mark g x left + .t mark gr x left .t insert 1.3 x list [.t mark gravity x] [.t index x] } -result {left 1.3} |