summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorculler <culler>2019-04-15 18:08:39 (GMT)
committerculler <culler>2019-04-15 18:08:39 (GMT)
commit845459f9fd4222d82d04de9282235999501948dc (patch)
treef6f3d48437f3c68e59eca8f9921192f8af879edb /macosx
parent969a623434fafc0d7393a379934cc7472e0819db (diff)
parent3c20b73064392e201bf678e471789379e5b27c53 (diff)
downloadtk-845459f9fd4222d82d04de9282235999501948dc.zip
tk-845459f9fd4222d82d04de9282235999501948dc.tar.gz
tk-845459f9fd4222d82d04de9282235999501948dc.tar.bz2
For Aqua, simulate systemWindowBackgroundColor in older OS versions. Adjust
conditional code and formatting.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXColor.c41
-rw-r--r--macosx/ttkMacOSXTheme.c112
2 files changed, 84 insertions, 69 deletions
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c
index a3efca1..e89d42d 100644
--- a/macosx/tkMacOSXColor.c
+++ b/macosx/tkMacOSXColor.c
@@ -266,6 +266,7 @@ GetEntryFromPixelCode(
static NSColorSpace* deviceRGB = NULL;
static CGFloat blueAccentRGBA[4] = {0, 122.0/255, 1.0, 1.0};
static CGFloat graphiteAccentRGBA[4] = {152.0/255, 152.0/255, 152.0/255, 1.0};
+static CGFloat windowBackground[4] = {236.0/255, 236.0/255, 236.0/255, 1.0};
static OSStatus
SetCGColorComponents(
@@ -299,9 +300,21 @@ SetCGColorComponents(
rgba[2] = ((pixel ) & 0xff) / 255.0;
break;
case ttkBackground:
- bgColor = [[NSColor windowBackgroundColor] colorUsingColorSpace:
- deviceRGB];
- [bgColor getComponents: rgba];
+
+ /*
+ * Prior to OSX 10.14, getComponents returns black when applied to
+ * windowBackGroundColor.
+ */
+
+ if ([NSApp macMinorVersion] < 14) {
+ for (int i=0; i<3; i++) {
+ rgba[i] = windowBackground[i];
+ }
+ } else {
+ bgColor = [[NSColor windowBackgroundColor] colorUsingColorSpace:
+ deviceRGB];
+ [bgColor getComponents: rgba];
+ }
if (rgba[0] + rgba[1] + rgba[2] < 1.5) {
for (int i=0; i<3; i++) {
rgba[i] += entry.value*8.0/255.0;
@@ -413,20 +426,20 @@ SetCGColorComponents(
*/
MODULE_SCOPE Bool
-TkMacOSXInDarkMode(Tk_Window tkwin) {
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 101300
- return false;
-#else
- static NSAppearanceName darkAqua = @"NSAppearanceNameDarkAqua";
- TkWindow *winPtr = (TkWindow*) tkwin;
- NSView *view = TkMacOSXDrawableView(winPtr->privatePtr);
+TkMacOSXInDarkMode(Tk_Window tkwin)
+{
+ int result = false;
- if (view && [view.effectiveAppearance.name isEqualToString:darkAqua]) {
- return True;
- } else {
- return false;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
+ if ([NSApp macMinorVersion] >= 14) {
+ static NSAppearanceName darkAqua = @"NSAppearanceNameDarkAqua";
+ TkWindow *winPtr = (TkWindow*) tkwin;
+ NSView *view = TkMacOSXDrawableView(winPtr->privatePtr);
+ result = (view &&
+ [view.effectiveAppearance.name isEqualToString:darkAqua]);
}
#endif
+ return result;
}
/*
diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c
index 84e5b5f..12667e1 100644
--- a/macosx/ttkMacOSXTheme.c
+++ b/macosx/ttkMacOSXTheme.c
@@ -124,7 +124,7 @@ static CGRect NormalizeButtonBounds(
return bounds;
}
-#if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
+#if MAC_OS_X_VERSION_MAX_ALLOWED > 1080
/*----------------------------------------------------------------------
* +++ Support for contrasting background colors when GroupBoxes or Tabbed
* panes are nested inside each other. Early versions of macOS used ridged
@@ -139,8 +139,7 @@ static CGRect NormalizeButtonBounds(
* support Dark Mode anyway.
*/
-static CGFloat windowBackground[4] = {235.0/255, 235.0/255, 235.0/255, 1.0};
-static CGFloat whiteRGBA[4] = {1.0, 1.0, 1.0, 1.0};
+static CGFloat windowBackground[4] = {236.0/255, 236.0/255, 236.0/255, 1.0};
static CGFloat blackRGBA[4] = {0.0, 0.0, 0.0, 1.0};
/*----------------------------------------------------------------------
@@ -264,56 +263,6 @@ static void SolidFillRoundedRectangle(
CFRelease(path);
}
-/*----------------------------------------------------------------------
- * GradientFillRoundedRectangle --
- *
- * Fill a rounded rectangle with a specified gradient.
- */
-
-static void GradientFillRoundedRectangle(
- CGContextRef context,
- CGRect bounds,
- CGFloat radius,
- CGFloat* colors,
- int numColors)
-{
- NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
- CGPathRef path;
- CGPoint end = {
- bounds.origin.x,
- bounds.origin.y + bounds.size.height
- };
- CGGradientRef gradient = CGGradientCreateWithColorComponents(
- deviceRGB.CGColorSpace, colors, NULL, numColors);
- path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
- CGContextBeginPath(context);
- CGContextAddPath(context, path);
- CGContextClip(context);
- CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0);
- CFRelease(path);
- CFRelease(gradient);
-}
-
-static void DrawUpDownArrows(
- CGContextRef context,
- CGRect bounds,
- CGFloat inset,
- CGFloat size,
- CGFloat *rgba)
-{
- CGFloat x, y;
- CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
- CGContextSetLineWidth(context, 1.5);
- x = bounds.origin.x + inset;
- y = bounds.origin.y + trunc(bounds.size.height/2);
- CGContextBeginPath(context);
- CGPoint bottomArrow[3] = {{x, y+2}, {x+size/2, y+2+size/2}, {x+size, y+2}};
- CGContextAddLines(context, bottomArrow, 3);
- CGPoint topArrow[3] = {{x, y-2}, {x+size/2, y-2-size/2}, {x+size, y-2}};
- CGContextAddLines(context, topArrow, 3);
- CGContextStrokePath(context);
-}
-
static void DrawDownArrow(
CGContextRef context,
CGRect bounds,
@@ -429,9 +378,9 @@ static void DrawListHeader(
}
}
-#endif /* MAC_OS_X_VERSION_MIN_REQUIRED > 1080 */
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED > 1080 */
-#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
+#if MAC_OS_X_VERSION_MAX_ALLOWED > 101300
/*----------------------------------------------------------------------
* +++ Drawing procedures for widgets in Apple's "Dark Mode" (10.14 and up).
*
@@ -464,6 +413,57 @@ static CGFloat darkInactiveGradient[8] = {89.0/255, 90.0/255, 93.0/255, 1.0,
static CGFloat darkSelectedGradient[8] = {23.0/255, 111.0/255, 232.0/255, 1.0,
20.0/255, 94.0/255, 206.0/255, 1.0};
+
+/*----------------------------------------------------------------------
+ * GradientFillRoundedRectangle --
+ *
+ * Fill a rounded rectangle with a specified gradient.
+ */
+
+static void GradientFillRoundedRectangle(
+ CGContextRef context,
+ CGRect bounds,
+ CGFloat radius,
+ CGFloat* colors,
+ int numColors)
+{
+ NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
+ CGPathRef path;
+ CGPoint end = {
+ bounds.origin.x,
+ bounds.origin.y + bounds.size.height
+ };
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(
+ deviceRGB.CGColorSpace, colors, NULL, numColors);
+ path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
+ CGContextBeginPath(context);
+ CGContextAddPath(context, path);
+ CGContextClip(context);
+ CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0);
+ CFRelease(path);
+ CFRelease(gradient);
+}
+
+static void DrawUpDownArrows(
+ CGContextRef context,
+ CGRect bounds,
+ CGFloat inset,
+ CGFloat size,
+ CGFloat *rgba)
+{
+ CGFloat x, y;
+ CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
+ CGContextSetLineWidth(context, 1.5);
+ x = bounds.origin.x + inset;
+ y = bounds.origin.y + trunc(bounds.size.height/2);
+ CGContextBeginPath(context);
+ CGPoint bottomArrow[3] = {{x, y+2}, {x+size/2, y+2+size/2}, {x+size, y+2}};
+ CGContextAddLines(context, bottomArrow, 3);
+ CGPoint topArrow[3] = {{x, y-2}, {x+size/2, y-2-size/2}, {x+size, y-2}};
+ CGContextAddLines(context, topArrow, 3);
+ CGContextStrokePath(context);
+}
+
/*----------------------------------------------------------------------
* FillButtonBackground --
*
@@ -528,6 +528,8 @@ static void HighlightButtonBorder(
* PopupButtons in the Dark Mode style.
*/
+static CGFloat whiteRGBA[4] = {1.0, 1.0, 1.0, 1.0};
+
static void DrawDarkButton(
CGRect bounds,
ThemeButtonKind kind,