summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXColor.c
diff options
context:
space:
mode:
authorculler <culler>2019-04-15 18:00:29 (GMT)
committerculler <culler>2019-04-15 18:00:29 (GMT)
commitaabd71aac31bdb206f316717019b6db250bc91d8 (patch)
treee0a15cf4301c9e6d7edbdd23f9bb711ccccc776f /macosx/tkMacOSXColor.c
parent1b1e4cc61c4f9772610d0e1c4c539d2562203ac6 (diff)
downloadtk-aabd71aac31bdb206f316717019b6db250bc91d8.zip
tk-aabd71aac31bdb206f316717019b6db250bc91d8.tar.gz
tk-aabd71aac31bdb206f316717019b6db250bc91d8.tar.bz2
For Aqua, simulate systemWindowBackgroundColor in older OS versions. Adjust
conditional code and formatting.
Diffstat (limited to 'macosx/tkMacOSXColor.c')
-rw-r--r--macosx/tkMacOSXColor.c111
1 files changed, 62 insertions, 49 deletions
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c
index 3885a77..ae9e9df 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(
@@ -277,13 +278,14 @@ SetCGColorComponents(
NSColor *bgColor, *color;
CGFloat rgba[4] = {0, 0, 0, 1};
NSInteger colorVariant = 1;
+
if (!deviceRGB) {
deviceRGB = [NSColorSpace deviceRGBColorSpace];
}
/*
- * This function is called before our autorelease pool is set up,
- * so it needs its own pool.
+ * This function is called before our autorelease pool is set up,
+ * so it needs its own pool.
*/
NSAutoreleasePool *pool = [NSAutoreleasePool new];
@@ -298,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;
@@ -314,20 +328,16 @@ SetCGColorComponents(
case semantic:
switch (entry.value) {
case 0:
- color = [[NSColor textColor] colorUsingColorSpace:
- deviceRGB];
+ color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
break;
case 1:
- color = [[NSColor selectedTextColor] colorUsingColorSpace:
- deviceRGB];
+ color = [[NSColor selectedTextColor] colorUsingColorSpace: deviceRGB];
break;
case 2:
#if MAC_OS_X_VERSION_MIN_REQUIRED > 101000
- color = [[NSColor labelColor] colorUsingColorSpace:
- deviceRGB];
+ color = [[NSColor labelColor] colorUsingColorSpace: deviceRGB];
#else
- color = [[NSColor textColor] colorUsingColorSpace:
- deviceRGB];
+ color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
#endif
break;
case 3:
@@ -347,36 +357,35 @@ SetCGColorComponents(
deviceRGB];
break;
case 7:
- if ([NSApp macMinorVersion] < 14) {
- colorVariant = [[NSUserDefaults standardUserDefaults]
- integerForKey:@"AppleAquaColorVariant"];
- if (colorVariant == 6) {
- color = [NSColor colorWithColorSpace: deviceRGB
- components: graphiteAccentRGBA
- count: 4];
- } else {
- color = [NSColor colorWithColorSpace: deviceRGB
- components: blueAccentRGBA
- count: 4];
- }
- } else {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
+ if ([NSApp macMinorVersion] >= 14) {
color = [[NSColor controlAccentColor] colorUsingColorSpace:
deviceRGB];
+ break;
+ }
#endif
+ colorVariant = [[NSUserDefaults standardUserDefaults]
+ integerForKey:@"AppleAquaColorVariant"];
+ if (colorVariant == 6) {
+ color = [NSColor colorWithColorSpace: deviceRGB
+ components: graphiteAccentRGBA
+ count: 4];
+ } else {
+ color = [NSColor colorWithColorSpace: deviceRGB
+ components: blueAccentRGBA
+ count: 4];
}
break;
default:
- if ([NSApp macMinorVersion] < 10) {
- color = [[NSColor textColor] colorUsingColorSpace:
- deviceRGB];
- } else {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
+ if ([NSApp macMinorVersion] >= 10) {
color = [[NSColor labelColor] colorUsingColorSpace:
deviceRGB];
-#endif
break;
}
+#endif
+ color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
+ break;
}
[color getComponents: rgba];
break;
@@ -395,7 +404,7 @@ SetCGColorComponents(
default:
break;
}
- *c = CGColorCreate(deviceRGB.CGColorSpace, rgba );
+ *c = CGColorCreate(deviceRGB.CGColorSpace, rgba);
[pool drain];
return err;
}
@@ -417,21 +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);
- if (view && [view.effectiveAppearance.name isEqualToString:darkAqua]) {
- return True;
- } else {
- return false;
+TkMacOSXInDarkMode(Tk_Window tkwin)
+{
+ int result = 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;
}
-
/*
*----------------------------------------------------------------------
@@ -462,6 +470,7 @@ TkSetMacColor(
CGColorRef *color = (CGColorRef*)macColor;
OSStatus err = -1;
struct SystemColorMapEntry entry;
+
if (GetEntryFromPixelCode((pixel >> 24) & 0xff, &entry)) {
err = ChkErr(SetCGColorComponents, entry, pixel, color);
}
@@ -607,6 +616,7 @@ TkMacOSXGetNSColor(
if (cgColor) {
NSColorSpace *colorSpace = [[NSColorSpace alloc]
initWithCGColorSpace:CGColorGetColorSpace(cgColor)];
+
nsColor = [NSColor colorWithColorSpace:colorSpace
components:CGColorGetComponents(cgColor)
count:CGColorGetNumberOfComponents(cgColor)];
@@ -648,6 +658,7 @@ TkMacOSXSetColorInContext(
int code = (pixel >> 24) & 0xff;
HIThemeBackgroundDrawInfo info = { 0, kThemeStateActive, entry.value };
static CGColorSpaceRef deviceRGBSpace = NULL;
+
if (!deviceRGBSpace) {
deviceRGBSpace = CGColorSpaceCreateDeviceRGB();
}
@@ -728,14 +739,16 @@ TkpGetColor(
if (strncasecmp(name, "system", 6) == 0) {
Tcl_Obj *strPtr = Tcl_NewStringObj(name+6, -1);
int idx, result;
+
result = Tcl_GetIndexFromObjStruct(NULL, strPtr, systemColorMap,
- sizeof(struct SystemColorMapEntry), NULL, TCL_EXACT, &idx);
+ sizeof(struct SystemColorMapEntry), NULL, TCL_EXACT, &idx);
Tcl_DecrRefCount(strPtr);
if (result == TCL_OK) {
OSStatus err;
CGColorRef c;
unsigned char pixelCode = idx + MIN_PIXELCODE;
struct SystemColorMapEntry entry = systemColorMap[idx];
+
err = ChkErr(SetCGColorComponents, entry, 0, &c);
if (err == noErr) {
const size_t n = CGColorGetNumberOfComponents(c);
@@ -751,12 +764,12 @@ TkpGetColor(
color.red = color.green = color.blue = rgba[0] * 65535.0;
break;
default:
- Tcl_Panic("CGColor with %d components", (int) n);
+ Tcl_Panic("CGColor with %d components", (int) n);
}
color.pixel = ((((((pixelCode << 8)
- | ((color.red >> 8) & 0xff)) << 8)
- | ((color.green >> 8) & 0xff)) << 8)
- | ((color.blue >> 8) & 0xff));
+ | ((color.red >> 8) & 0xff)) << 8)
+ | ((color.green >> 8) & 0xff)) << 8)
+ | ((color.blue >> 8) & 0xff));
CGColorRelease(c);
goto validXColor;
}