From a872071b3c86d4de2e5cb8e9a0d6e876064e561d Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 29 Jul 2020 03:11:02 +0000 Subject: Clean up tkMacOSXColor.c so it is not so painful to add new colors. --- macosx/tkMacOSXColor.c | 425 ++++++++++++++--------------------------------- macosx/tkMacOSXDraw.c | 9 +- macosx/tkMacOSXImage.c | 2 +- macosx/tkMacOSXPort.h | 22 +-- macosx/tkMacOSXPrivate.h | 5 +- macosx/tkMacOSXXStubs.c | 4 +- 6 files changed, 139 insertions(+), 328 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 5a06c39..8b193b8 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -16,217 +16,78 @@ #include "tkMacOSXPrivate.h" #include "tkColor.h" +#include "tkMacOSXColor.h" -/* - * The colorType specifies how the color value should be interpreted. For the - * unique rgbColor entry, the RGB values are generated from the pixel value of - * an XColor. The ttkBackground and semantic types are dynamic, meaning - * that they change when dark mode is enabled on OSX 10.13 and later. - */ - -enum colorType { - clearColor, /* There should be only one of these. */ - rgbColor, /* There should be only one of these. */ - appearance, /* There should be only one of these. */ - HIBrush, /* The value is a HITheme brush color table index. */ - HIText, /* The value is a HITheme text color table index. */ - HIBackground, /* The value is a HITheme background color table index. */ - ttkBackground, /* The value can be used as a parameter.*/ - semantic, /* The value can be used as a parameter.*/ -}; - -/* +static Tcl_HashTable systemColorMap; +static int systemColorMapSize; +SystemColorMapEntry **systemColorIndex; - */ - -struct SystemColorMapEntry { - const char *name; - enum colorType type; - long value; -}; /* unsigned char pixelCode; */ - -/* - * Array of system color definitions: the array index is required to equal the - * color's (pixelCode - MIN_PIXELCODE), i.e. the array order needs to be kept - * in sync with the public pixel code values in tkMacOSXPort.h ! - */ +void initColorTable() +{ + Tcl_InitHashTable(&systemColorMap, TCL_STRING_KEYS); + SystemColorMapEntry *entry; + Tcl_HashSearch search; + Tcl_HashEntry *hPtr; + int newPtr = 0, index = 0; + for (entry = systemColorMapData; entry->name != NULL; entry++) { + hPtr = Tcl_CreateHashEntry(&systemColorMap, entry->name, &newPtr); + if (entry->type == semantic) { + NSString *selector = [[NSString alloc] + initWithCString:entry->macName + encoding:NSUTF8StringEncoding]; + if (![NSColor respondsToSelector: NSSelectorFromString(selector)]) { + continue; + } + [selector retain]; + entry->selector = selector; + } + if (!newPtr) { + index--; + } + entry->index = index++; + Tcl_SetHashValue(hPtr, entry); + } + systemColorMapSize = index; + systemColorIndex = ckalloc(systemColorMapSize * sizeof(SystemColorMapEntry*)); + for (hPtr = Tcl_FirstHashEntry(&systemColorMap, &search); hPtr != NULL; + hPtr = Tcl_NextHashEntry(&search)) { + entry = (SystemColorMapEntry *) Tcl_GetHashValue(hPtr); + systemColorIndex[entry->index] = entry; + } +} -#define MIN_PIXELCODE 30 -static const struct SystemColorMapEntry systemColorMap[] = { - { "Transparent", clearColor, 0 }, /* 30: TRANSPARENT_PIXEL */ - { "Highlight", HIBrush, kThemeBrushPrimaryHighlightColor }, /* 31 */ - { "HighlightSecondary", HIBrush, kThemeBrushSecondaryHighlightColor }, /* 32 */ - { "HighlightText", HIBrush, kThemeBrushBlack }, /* 33 */ - { "HighlightAlternate", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, /* 34 */ - { "ButtonText", HIText, kThemeTextColorPushButtonActive }, /* 35 */ - { "PrimaryHighlightColor", HIBrush, kThemeBrushPrimaryHighlightColor }, /* 36 */ - { "ButtonFace", HIBrush, kThemeBrushButtonFaceActive }, /* 37 */ - { "SecondaryHighlightColor", HIBrush, kThemeBrushSecondaryHighlightColor }, /* 38 */ - { "ButtonFrame", HIBrush, kThemeBrushButtonFrameActive }, /* 39 */ - { "AlternatePrimaryHighlightColor", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, /* 40 */ - { "WindowBody", HIBrush, kThemeBrushDocumentWindowBackground }, /* 41 */ - { "SheetBackground", HIBrush, kThemeBrushSheetBackground }, /* 42 */ - { "MenuActive", HIBrush, kThemeBrushMenuBackgroundSelected }, /* 43 */ - { "Black", HIBrush, kThemeBrushBlack }, /* 44 */ - { "MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, /* 45 */ - { "White", HIBrush, kThemeBrushWhite }, /* 46 */ - { "Menu", HIBrush, kThemeBrushMenuBackground }, /* 47 */ - { "DialogBackgroundActive", HIBrush, kThemeBrushDialogBackgroundActive }, /* 48 */ - { "MenuDisabled", HIText, kThemeTextColorMenuItemDisabled }, /* 49 */ - { "DialogBackgroundInactive", HIBrush, kThemeBrushDialogBackgroundInactive }, /* 50 */ - { "MenuText", HIText, kThemeTextColorMenuItemActive }, /* 51 */ - { "AppearanceColor", appearance, 0 }, /* 52: APPEARANCE_PIXEL */ - { "AlertBackgroundActive", HIBrush, kThemeBrushAlertBackgroundActive }, /* 53 */ - { "AlertBackgroundInactive", HIBrush, kThemeBrushAlertBackgroundInactive }, /* 54 */ - { "ModelessDialogBackgroundActive", HIBrush, kThemeBrushModelessDialogBackgroundActive }, /* 55 */ - { "ModelessDialogBackgroundInactive", HIBrush, kThemeBrushModelessDialogBackgroundInactive }, /* 56 */ - { "UtilityWindowBackgroundActive", HIBrush, kThemeBrushUtilityWindowBackgroundActive }, /* 57 */ - { "UtilityWindowBackgroundInactive", HIBrush, kThemeBrushUtilityWindowBackgroundInactive }, /* 58 */ - { "ListViewSortColumnBackground", HIBrush, kThemeBrushListViewSortColumnBackground }, /* 59 */ - { "ListViewBackground", HIBrush, kThemeBrushListViewBackground }, /* 60 */ - { "IconLabelBackground", HIBrush, kThemeBrushIconLabelBackground }, /* 61 */ - { "ListViewSeparator", HIBrush, kThemeBrushListViewSeparator }, /* 62 */ - { "ChasingArrows", HIBrush, kThemeBrushChasingArrows }, /* 63 */ - { "DragHilite", HIBrush, kThemeBrushDragHilite }, /* 64 */ - { "DocumentWindowBackground", HIBrush, kThemeBrushDocumentWindowBackground }, /* 65 */ - { "FinderWindowBackground", HIBrush, kThemeBrushFinderWindowBackground }, /* 66 */ - { "ScrollBarDelimiterActive", HIBrush, kThemeBrushScrollBarDelimiterActive }, /* 67 */ - { "ScrollBarDelimiterInactive", HIBrush, kThemeBrushScrollBarDelimiterInactive }, /* 68 */ - { "FocusHighlight", HIBrush, kThemeBrushFocusHighlight }, /* 69 */ - { "PopupArrowActive", HIBrush, kThemeBrushPopupArrowActive }, /* 70 */ - { "PopupArrowPressed", HIBrush, kThemeBrushPopupArrowPressed }, /* 71 */ - { "PopupArrowInactive", HIBrush, kThemeBrushPopupArrowInactive }, /* 72 */ - { "AppleGuideCoachmark", HIBrush, kThemeBrushAppleGuideCoachmark }, /* 73 */ - { "IconLabelBackgroundSelected", HIBrush, kThemeBrushIconLabelBackgroundSelected }, /* 74 */ - { "StaticAreaFill", HIBrush, kThemeBrushStaticAreaFill }, /* 75 */ - { "ActiveAreaFill", HIBrush, kThemeBrushActiveAreaFill }, /* 76 */ - { "ButtonFrameActive", HIBrush, kThemeBrushButtonFrameActive }, /* 77 */ - { "ButtonFrameInactive", HIBrush, kThemeBrushButtonFrameInactive }, /* 78 */ - { "ButtonFaceActive", HIBrush, kThemeBrushButtonFaceActive }, /* 79 */ - { "ButtonFaceInactive", HIBrush, kThemeBrushButtonFaceInactive }, /* 80 */ - { "ButtonFacePressed", HIBrush, kThemeBrushButtonFacePressed }, /* 81 */ - { "ButtonActiveDarkShadow", HIBrush, kThemeBrushButtonActiveDarkShadow }, /* 82 */ - { "ButtonActiveDarkHighlight", HIBrush, kThemeBrushButtonActiveDarkHighlight }, /* 83 */ - { "ButtonActiveLightShadow", HIBrush, kThemeBrushButtonActiveLightShadow }, /* 84 */ - { "ButtonActiveLightHighlight", HIBrush, kThemeBrushButtonActiveLightHighlight }, /* 85 */ - { "ButtonInactiveDarkShadow", HIBrush, kThemeBrushButtonInactiveDarkShadow }, /* 86 */ - { "ButtonInactiveDarkHighlight", HIBrush, kThemeBrushButtonInactiveDarkHighlight }, /* 87 */ - { "ButtonInactiveLightShadow", HIBrush, kThemeBrushButtonInactiveLightShadow }, /* 88 */ - { "ButtonInactiveLightHighlight", HIBrush, kThemeBrushButtonInactiveLightHighlight }, /* 89 */ - { "ButtonPressedDarkShadow", HIBrush, kThemeBrushButtonPressedDarkShadow }, /* 90 */ - { "ButtonPressedDarkHighlight", HIBrush, kThemeBrushButtonPressedDarkHighlight }, /* 91 */ - { "ButtonPressedLightShadow", HIBrush, kThemeBrushButtonPressedLightShadow }, /* 92 */ - { "ButtonPressedLightHighlight", HIBrush, kThemeBrushButtonPressedLightHighlight }, /* 93 */ - { "BevelActiveLight", HIBrush, kThemeBrushBevelActiveLight }, /* 94 */ - { "BevelActiveDark", HIBrush, kThemeBrushBevelActiveDark }, /* 95 */ - { "BevelInactiveLight", HIBrush, kThemeBrushBevelInactiveLight }, /* 96 */ - { "BevelInactiveDark", HIBrush, kThemeBrushBevelInactiveDark }, /* 97 */ - { "NotificationWindowBackground", HIBrush, kThemeBrushNotificationWindowBackground }, /* 98 */ - { "MovableModalBackground", HIBrush, kThemeBrushMovableModalBackground }, /* 99 */ - { "SheetBackgroundOpaque", HIBrush, kThemeBrushSheetBackgroundOpaque }, /* 100 */ - { "DrawerBackground", HIBrush, kThemeBrushDrawerBackground }, /* 101 */ - { "ToolbarBackground", HIBrush, kThemeBrushToolbarBackground }, /* 102 */ - { "SheetBackgroundTransparent", HIBrush, kThemeBrushSheetBackgroundTransparent }, /* 103 */ - { "MenuBackground", HIBrush, kThemeBrushMenuBackground }, /* 104 */ - { "Pixel", rgbColor, 0 }, /* 105: PIXEL_MAGIC */ - { "MenuBackgroundSelected", HIBrush, kThemeBrushMenuBackgroundSelected }, /* 106 */ - { "ListViewOddRowBackground", HIBrush, kThemeBrushListViewOddRowBackground }, /* 107 */ - { "ListViewEvenRowBackground", HIBrush, kThemeBrushListViewEvenRowBackground }, /* 108 */ - { "ListViewColumnDivider", HIBrush, kThemeBrushListViewColumnDivider }, /* 109 */ - { "BlackText", HIText, kThemeTextColorBlack }, /* 110 */ - { "DialogActiveText", HIText, kThemeTextColorDialogActive }, /* 111 */ - { "DialogInactiveText", HIText, kThemeTextColorDialogInactive }, /* 112 */ - { "AlertActiveText", HIText, kThemeTextColorAlertActive }, /* 113 */ - { "AlertInactiveText", HIText, kThemeTextColorAlertInactive }, /* 114 */ - { "ModelessDialogActiveText", HIText, kThemeTextColorModelessDialogActive }, /* 115 */ - { "ModelessDialogInactiveText", HIText, kThemeTextColorModelessDialogInactive }, /* 116 */ - { "WindowHeaderActiveText", HIText, kThemeTextColorWindowHeaderActive }, /* 117 */ - { "WindowHeaderInactiveText", HIText, kThemeTextColorWindowHeaderInactive }, /* 118 */ - { "PlacardActiveText", HIText, kThemeTextColorPlacardActive }, /* 119 */ - { "PlacardInactiveText", HIText, kThemeTextColorPlacardInactive }, /* 120 */ - { "PlacardPressedText", HIText, kThemeTextColorPlacardPressed }, /* 121 */ - { "PushButtonActiveText", HIText, kThemeTextColorPushButtonActive }, /* 122 */ - { "PushButtonInactiveText", HIText, kThemeTextColorPushButtonInactive }, /* 123 */ - { "PushButtonPressedText", HIText, kThemeTextColorPushButtonPressed }, /* 124 */ - { "BevelButtonActiveText", HIText, kThemeTextColorBevelButtonActive }, /* 125 */ - { "BevelButtonInactiveText", HIText, kThemeTextColorBevelButtonInactive }, /* 126 */ - { "BevelButtonPressedText", HIText, kThemeTextColorBevelButtonPressed }, /* 127 */ - { "PopupButtonActiveText", HIText, kThemeTextColorPopupButtonActive }, /* 128 */ - { "PopupButtonInactiveText", HIText, kThemeTextColorPopupButtonInactive }, /* 129 */ - { "PopupButtonPressedText", HIText, kThemeTextColorPopupButtonPressed }, /* 130 */ - { "IconLabelText", HIText, kThemeTextColorIconLabel }, /* 131 */ - { "ListViewText", HIText, kThemeTextColorListView }, /* 132 */ - { "DocumentWindowTitleActiveText", HIText, kThemeTextColorDocumentWindowTitleActive }, /* 133 */ - { "DocumentWindowTitleInactiveText", HIText, kThemeTextColorDocumentWindowTitleInactive }, /* 134 */ - { "MovableModalWindowTitleActiveText", HIText, kThemeTextColorMovableModalWindowTitleActive }, /* 135 */ - { "MovableModalWindowTitleInactiveText",HIText, kThemeTextColorMovableModalWindowTitleInactive }, /* 136 */ - { "UtilityWindowTitleActiveText", HIText, kThemeTextColorUtilityWindowTitleActive }, /* 137 */ - { "UtilityWindowTitleInactiveText", HIText, kThemeTextColorUtilityWindowTitleInactive }, /* 138 */ - { "PopupWindowTitleActiveText", HIText, kThemeTextColorPopupWindowTitleActive }, /* 139 */ - { "PopupWindowTitleInactiveText", HIText, kThemeTextColorPopupWindowTitleInactive }, /* 140 */ - { "RootMenuActiveText", HIText, kThemeTextColorRootMenuActive }, /* 141 */ - { "RootMenuSelectedText", HIText, kThemeTextColorRootMenuSelected }, /* 142 */ - { "RootMenuDisabledText", HIText, kThemeTextColorRootMenuDisabled }, /* 143 */ - { "MenuItemActiveText", HIText, kThemeTextColorMenuItemActive }, /* 144 */ - { "MenuItemSelectedText", HIText, kThemeTextColorMenuItemSelected }, /* 145 */ - { "MenuItemDisabledText", HIText, kThemeTextColorMenuItemDisabled }, /* 146 */ - { "PopupLabelActiveText", HIText, kThemeTextColorPopupLabelActive }, /* 147 */ - { "PopupLabelInactiveText", HIText, kThemeTextColorPopupLabelInactive }, /* 148 */ - { "TabFrontActiveText", HIText, kThemeTextColorTabFrontActive }, /* 149 */ - { "TabNonFrontActiveText", HIText, kThemeTextColorTabNonFrontActive }, /* 150 */ - { "TabNonFrontPressedText", HIText, kThemeTextColorTabNonFrontPressed }, /* 151 */ - { "TabFrontInactiveText", HIText, kThemeTextColorTabFrontInactive }, /* 152 */ - { "TabNonFrontInactiveText", HIText, kThemeTextColorTabNonFrontInactive }, /* 153 */ - { "IconLabelSelectedText", HIText, kThemeTextColorIconLabelSelected }, /* 154 */ - { "BevelButtonStickyActiveText", HIText, kThemeTextColorBevelButtonStickyActive }, /* 155 */ - { "BevelButtonStickyInactiveText", HIText, kThemeTextColorBevelButtonStickyInactive }, /* 156 */ - { "NotificationText", HIText, kThemeTextColorNotification }, /* 157 */ - { "SystemDetailText", HIText, kThemeTextColorSystemDetail }, /* 158 */ - { "WhiteText", HIText, kThemeTextColorWhite }, /* 159 */ - { "TabPaneBackground", HIBackground, kThemeBackgroundTabPane }, /* 160 */ - { "PlacardBackground", HIBackground, kThemeBackgroundPlacard }, /* 161 */ - { "WindowHeaderBackground", HIBackground, kThemeBackgroundWindowHeader }, /* 162 */ - { "ListViewWindowHeaderBackground", HIBackground, kThemeBackgroundListViewWindowHeader }, /* 163 */ - { "SecondaryGroupBoxBackground", HIBackground, kThemeBackgroundSecondaryGroupBox }, /* 164 */ - { "MetalBackground", HIBackground, kThemeBackgroundMetal }, /* 165 */ +MODULE_SCOPE +unsigned long TkMacOSXRGBPixel( + unsigned int red, + unsigned int green, + unsigned int blue) +{ + MacPixel p; + p.pixel.value = (red >> 8) << 16 | (green >> 8) << 8 | (blue >> 8); + p.pixel.colortype = rgbColor; + return p.ulong; +} - /* - * Colors based on "semantic" NSColors. - */ +MODULE_SCOPE +unsigned long TkMacOSXClearPixel( + void) +{ + MacPixel p; + p.pixel.value = 0; + p.pixel.colortype = clearColor; + return p.ulong; +} - { "WindowBackgroundColor", ttkBackground, 0 }, /* 166 */ - { "WindowBackgroundColor1", ttkBackground, 1 }, /* 167 */ - { "WindowBackgroundColor2", ttkBackground, 2 }, /* 168 */ - { "WindowBackgroundColor3", ttkBackground, 3 }, /* 169 */ - { "WindowBackgroundColor4", ttkBackground, 4 }, /* 170 */ - { "WindowBackgroundColor5", ttkBackground, 5 }, /* 171 */ - { "WindowBackgroundColor6", ttkBackground, 6 }, /* 172 */ - { "WindowBackgroundColor7", ttkBackground, 7 }, /* 173 */ - { "TextColor", semantic, 0 }, /* 174 */ - { "SelectedTextColor", semantic, 1 }, /* 175 */ - { "LabelColor", semantic, 2 }, /* 176 */ - { "ControlTextColor", semantic, 3 }, /* 177 */ - { "DisabledControlTextColor", semantic, 4 }, /* 178 */ - { "SelectedTabTextColor", semantic, 5 }, /* 179 */ - { "TextBackgroundColor", semantic, 6 }, /* 180 */ - { "SelectedTextBackgroundColor", semantic, 7 }, /* 181 */ - { "ControlAccentColor", semantic, 8 }, /* 182 */ - /* Apple's SecondaryLabelColor is the same as their LabelColor so we roll our own. */ - { "SecondaryLabelColor", ttkBackground, 14 }, /* 183 */ - { "LinkColor", semantic, 9 }, /* 184 */ - { NULL, 0, 0 } -}; -#define FIRST_SEMANTIC_COLOR 166 -#define MAX_PIXELCODE 184 /* *---------------------------------------------------------------------- * - * GetEntryFromPixelCode -- + * GetEntryFromPixel -- * * Extract a SystemColorMapEntry from the table. * * Results: + * Returns false if the code is out of bounds. * * Side effects: @@ -236,12 +97,19 @@ static const struct SystemColorMapEntry systemColorMap[] = { */ static bool -GetEntryFromPixelCode( - unsigned char code, - struct SystemColorMapEntry *entry) +GetEntryFromPixel( + unsigned long pixel, + SystemColorMapEntry *entry) { - if (code >= MIN_PIXELCODE && code <= MAX_PIXELCODE) { - *entry = systemColorMap[code - MIN_PIXELCODE]; + MacPixel p; + unsigned int index = 0; //FIX ME + + p.ulong = pixel; + if (p.pixel.colortype != rgbColor) { + index = p.pixel.value; + } + if (index < systemColorMapSize) { + *entry = *systemColorIndex[index]; return true; } else { return false; @@ -268,6 +136,26 @@ GetEntryFromPixelCode( */ /* + * Definitions to prevent compiler warnings about nonexistent properties of NSColor. + */ + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 + #define LABEL_COLOR labelColor +#else + #define LABEL_COLOR textColor +#endif +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 + #define LINK_COLOR linkColor +#else + #define LINK_COLOR blueColor +#endif +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 + #define CONTROL_ACCENT_COLOR controlAccentColor +#else + #define CONTROL_ACCENT_COLOR colorForControlTint:[NSColor currentControlTint] +#endif + +/* * Apple claims that linkColor is available in 10.10 but the declaration * does not appear in NSColor.h until later. Declaring it in a category * appears to be harmless and stops the compiler warnings. @@ -289,14 +177,15 @@ static CGFloat windowBackground[4] = static OSStatus SetCGColorComponents( - struct SystemColorMapEntry entry, + SystemColorMapEntry entry, unsigned long pixel, CGColorRef *c) { OSStatus err = noErr; NSColor *bgColor, *color = nil; CGFloat rgba[4] = {0, 0, 0, 1}; - + static Bool initialized = 0; + NSString *selector; if (!sRGB) { sRGB = [NSColorSpace sRGBColorSpace]; } @@ -307,7 +196,6 @@ SetCGColorComponents( */ NSAutoreleasePool *pool = [NSAutoreleasePool new]; - switch (entry.type) { case HIBrush: err = ChkErr(HIThemeBrushCreateCGColor, entry.value, c); @@ -343,76 +231,7 @@ SetCGColorComponents( } break; case semantic: - switch (entry.value) { - case 0: - color = [[NSColor textColor] colorUsingColorSpace:sRGB]; - break; - case 1: - color = [[NSColor selectedTextColor] colorUsingColorSpace:sRGB]; - break; - case 2: - if ([NSApp macOSVersion] > 100900) { - -#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 - color = [[NSColor labelColor] colorUsingColorSpace:sRGB]; -#endif - } else { - color = [[NSColor textColor] colorUsingColorSpace:sRGB]; - } - break; - case 3: - color = [[NSColor controlTextColor] colorUsingColorSpace:sRGB]; - break; - case 4: - color = [[NSColor disabledControlTextColor] - colorUsingColorSpace:sRGB]; - break; - case 5: - if ([NSApp macOSVersion] > 100600) { - color = [[NSColor whiteColor] colorUsingColorSpace:sRGB]; - } else { - color = [[NSColor blackColor] colorUsingColorSpace:sRGB]; - } - break; - case 6: - color = [[NSColor textBackgroundColor] colorUsingColorSpace:sRGB]; - break; - case 7: - color = [[NSColor selectedTextBackgroundColor] - colorUsingColorSpace:sRGB]; - break; - case 8: -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - if (@available(macOS 14, *)) { - color = [[NSColor controlAccentColor] colorUsingColorSpace:sRGB]; -#else - if(false) { -#endif - } else { - color = [[NSColor - colorForControlTint:[NSColor currentControlTint]] - colorUsingColorSpace: sRGB]; - } - break; - case 9: - if ([NSApp macOSVersion] >= 101100) { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 - color = [[NSColor linkColor] colorUsingColorSpace:sRGB]; -#endif - } else { - color = [[NSColor blueColor] colorUsingColorSpace:sRGB]; - } - break; - default: - if ([NSApp macOSVersion] >= 101000) { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 - color = [[NSColor labelColor] colorUsingColorSpace:sRGB]; -#endif - } else { - color = [[NSColor textColor] colorUsingColorSpace:sRGB]; - } - break; - } + color = [[NSColor valueForKey:entry.selector] colorUsingColorSpace:sRGB]; [color getComponents: rgba]; break; case clearColor: @@ -483,7 +302,7 @@ TkMacOSXInDarkMode(Tk_Window tkwin) * TkSetMacColor -- * * Sets the components of a CGColorRef from an XColor pixel value. - * The high order byte of the pixel value is used as an index into + * XXXX The high order byte of the pixel value is used as an index into * the system color table, and then SetCGColorComponents is called * with the table entry and the pixel value. * @@ -505,9 +324,10 @@ TkSetMacColor( { CGColorRef *color = (CGColorRef*)macColor; OSStatus err = -1; - struct SystemColorMapEntry entry; + SystemColorMapEntry entry; - if (GetEntryFromPixelCode((pixel >> 24) & 0xff, &entry)) { + // if (GetEntryFromPixelCode((pixel >> 24) & 0xff, &entry)) { + if (GetEntryFromPixel(pixel, &entry)) { err = ChkErr(SetCGColorComponents, entry, pixel, color); } return (err == noErr); @@ -689,15 +509,14 @@ TkMacOSXSetColorInContext( { OSStatus err = noErr; CGColorRef cgColor = nil; - struct SystemColorMapEntry entry; + SystemColorMapEntry entry; CGRect rect; - int code = (pixel >> 24) & 0xff; HIThemeBackgroundDrawInfo info = {0, kThemeStateActive, 0};; - if (code < FIRST_SEMANTIC_COLOR) { - cgColor = CopyCachedColor(gc, pixel); - } - if (!cgColor && GetEntryFromPixelCode(code, &entry)) { + // if (code < FIRST_SEMANTIC_COLOR) { + // cgColor = CopyCachedColor(gc, pixel); + // } + if (!cgColor && GetEntryFromPixel(pixel, &entry)) { switch (entry.type) { case HIBrush: err = ChkErr(HIThemeSetFill, entry.value, NULL, context, @@ -763,6 +582,13 @@ TkpGetColor( Colormap colormap = tkwin!= None ? Tk_Colormap(tkwin) : None; TkColor *tkColPtr; XColor color; + static Bool initialized = NO; + static NSColorSpace* sRGB = NULL; + if (!initialized) { + initialized = YES; + sRGB = [NSColorSpace sRGBColorSpace]; + initColorTable(); + } /* * Check to see if this is a system color. Otherwise, XParseColor @@ -770,20 +596,18 @@ 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); - Tcl_DecrRefCount(strPtr); - if (result == TCL_OK) { + Tcl_HashEntry *hPtr = NULL; + SystemColorMapEntry *entry; + hPtr = Tcl_FindHashEntry(&systemColorMap, name + 6); + if (hPtr != NULL) { + entry = (SystemColorMapEntry *)Tcl_GetHashValue(hPtr); OSStatus err; CGColorRef c; - unsigned char pixelCode = idx + MIN_PIXELCODE; - struct SystemColorMapEntry entry = systemColorMap[idx]; - - err = ChkErr(SetCGColorComponents, entry, 0, &c); + unsigned char pixelCode = entry->index; + err = ChkErr(SetCGColorComponents, *entry, 0, &c); if (err == noErr) { + MacPixel p; + const size_t n = CGColorGetNumberOfComponents(c); const CGFloat *rgba = CGColorGetComponents(c); @@ -799,10 +623,9 @@ TkpGetColor( default: 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)); + p.pixel.value = pixelCode; + p.pixel.colortype = entry->type; + color.pixel = p.ulong; CGColorRelease(c); goto validXColor; } @@ -854,7 +677,7 @@ TkpGetColorByValue( tkColPtr->color.red = colorPtr->red; tkColPtr->color.green = colorPtr->green; tkColPtr->color.blue = colorPtr->blue; - tkColPtr->color.pixel = TkpGetPixel(&tkColPtr->color); + tkColPtr->color.pixel = TkpGetPixel(colorPtr); return tkColPtr; } diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index fd8a1eb..645b72b 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -43,6 +43,7 @@ static int cgAntiAliasLimit = 0; static int useThemedToplevel = 0; static int useThemedFrame = 0; +static unsigned long transparentColor; /* * Prototypes for functions used only in this file. @@ -99,6 +100,7 @@ TkMacOSXInitCGDrawing( (char *) &useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) { Tcl_ResetResult(interp); } + transparentColor = TkMacOSXClearPixel(); } return TCL_OK; } @@ -545,7 +547,7 @@ TkMacOSXGetNSImageWithBitmap( unsigned long origBackground = gc->background; - gc->background = TRANSPARENT_PIXEL << 24; + gc->background = transparentColor; XSetClipOrigin(display, gc, 0, 0); XCopyPlane(display, bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1); gc->background = origBackground; @@ -664,17 +666,18 @@ TkMacOSXDrawCGImage( dstBounds = CGRectOffset(dstBounds, macDraw->xOff, macDraw->yOff); if (CGImageIsMask(image)) { if (macDraw->flags & TK_IS_BW_PIXMAP) { + /* * Set fill color to black; background comes from the context, * or is transparent. */ - if (imageBackground != TRANSPARENT_PIXEL << 24) { + if (imageBackground != transparentColor) { CGContextClearRect(context, dstBounds); } CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0); } else { - if (imageBackground != TRANSPARENT_PIXEL << 24) { + if (imageBackground != transparentColor) { TkMacOSXSetColorInContext(gc, imageBackground, context); CGContextFillRect(context, dstBounds); } diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 2e576a5..4691e41 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -358,7 +358,7 @@ ImageGetPixel( break; } } - return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b; + return TkMacOSXRGBPixel(r, g, b); } /* diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index 71797b0..b81455c 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -161,27 +161,9 @@ #define TK_NO_DOUBLE_BUFFERING 1 /* - * Magic pixel code values for system colors. - * - * NOTE: values must be kept in sync with indices into the - * systemColorMap array in tkMacOSXColor.c ! - */ - -#define TRANSPARENT_PIXEL 30 -#define APPEARANCE_PIXEL 52 -#define PIXEL_MAGIC ((unsigned char) 0x69) - -/* - * The following macro returns the pixel value that corresponds to the - * 16-bit RGB values in the given XColor structure. - * The format is: (PIXEL_MAGIC <<< 24) | (R << 16) | (G << 8) | B - * where each of R, G and B is the high order byte of a 16-bit component. + * Used by xcolor.c */ -#define TkpGetPixel(p) ((((((PIXEL_MAGIC << 8) \ - | (((p)->red >> 8) & 0xff)) << 8) \ - | (((p)->green >> 8) & 0xff)) << 8) \ - | (((p)->blue >> 8) & 0xff)) - +#define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red, p->green, p->blue)) #endif /* _TKMACPORT */ diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index a77282c..8ba7541 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -150,7 +150,7 @@ typedef union MacKeycode_t { keycode_v v; keycode_x x; } MacKeycode; - + /* * Macros used in tkMacOSXKeyboard.c and tkMacOSXKeyEvent.c. * Note that 0x7f is del and 0xF8FF is the Apple Logo character. @@ -310,6 +310,9 @@ MODULE_SCOPE unsigned TkMacOSXAddVirtual(unsigned int keycode); MODULE_SCOPE void TkMacOSXWinNSBounds(TkWindow *winPtr, NSView *view, NSRect *bounds); MODULE_SCOPE void TkMacOSXDrawAllViews(ClientData clientData); +MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned int red, unsigned int green, + unsigned int blue); +MODULE_SCOPE unsigned long TkMacOSXClearPixel(void); #pragma mark Private Objective-C Classes diff --git a/macosx/tkMacOSXXStubs.c b/macosx/tkMacOSXXStubs.c index 107f712..dc9ea32 100644 --- a/macosx/tkMacOSXXStubs.c +++ b/macosx/tkMacOSXXStubs.c @@ -250,8 +250,8 @@ TkpOpenDisplay( */ screen->root = ROOT_ID; screen->display = display; - screen->black_pixel = 0x00000000 | PIXEL_MAGIC << 24; - screen->white_pixel = 0x00FFFFFF | PIXEL_MAGIC << 24; + screen->black_pixel = 0x00000000; + screen->white_pixel = 0x00FFFFFF; screen->ext_data = (XExtData *) &maxBounds; screen->root_visual = ckalloc(sizeof(Visual)); -- cgit v0.12 From 18690594d7c9f8a57946fc6d838930b09e104754 Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 29 Jul 2020 03:25:00 +0000 Subject: Add the new header file too. --- macosx/tkMacOSXColor.h | 250 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 macosx/tkMacOSXColor.h diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h new file mode 100644 index 0000000..a4acc08 --- /dev/null +++ b/macosx/tkMacOSXColor.h @@ -0,0 +1,250 @@ +#ifndef MACOSXCOLOR_H +#define MACOSXCOLOR_H +/* + * The generic Tk code uses the X11 GC type to describe a graphics context. + * (A GC is a pointer to a struct XGCValues). The foreground and background + * colors in a GC are unsigned longs. These are meant to be used as indexes + * into a table of XColors, where an XColor is declared in Xlib.h as: + * typedef struct { + * unsigned long pixel; + * unsigned short red, green, blue; + * char flags; + * char pad; + * } XColor; + * + * The xlib function XParseColor creates XColors from strings. It recognizes + * literal hexadecimal color specifications such as "#RRGGBB" as well as the + * standard X11 color names. When XParseColor creates an XColor it fills in + * all of the fields except for the pixel field, and then passes the XColor + * to TkpGetPixel to get a value to use for the pixel field. Since TkpGetPixel + * is platform specific, each platform is free to choose a value which can + * be used to set the foreground or background color in the platform's graphics + * context. + * + * Tk represents a color by a struct TkColor, which extends the XColor struct. + * Tk provides a mapping from color names to TkColors which extends the mapping + * provided by XParseColor but also allows for platform specific color names. + * By convention, these platform specific color names begin with the string + * "system". The mapping from names to TkColors is implemented by the function + * TkpGetColor defined for the Macintosh in this file. The pixel field in the + * XColor contained in a TkColor will be stored in the X11 graphics context. + * In X11 the pixel field is used as an index into a colormap. On the Mac + * the high order byte of the pixel is used to indicate a color type and + * the low 24 bits are either used as an rgb value (if the type is rgbColor) + * or as an index into a table of color descriptions. + */ + +enum colorType { + rgbColor, /* The 24 bit value is an rgb color. */ + clearColor, /* The unique rgba color with all channels 0. */ + HIBrush, /* A HITheme brush color.*/ + HIText, /* A HITheme text color. */ + HIBackground, /* A HITheme background color. */ + ttkBackground, /* A background color which indicates nesting level.*/ + semantic, /* A semantic NSColor.*/ +}; + +typedef struct xpixel_t { + unsigned value: 24; /* Either RGB or an index into systemColorMap. */ + unsigned colortype: 8; +} xpixel; + +typedef union MacPixel_t { + unsigned long ulong; + xpixel pixel; +} MacPixel; + +/* + * In TkMacOSXColor.c a Tk hash table is constructed from the static data + * below to map system color names to CGColors. + */ + +typedef struct { + const char *name; + enum colorType type; + long value; + char *macName; + NSString *selector; /* Filled in if used. */ + int index; /* Filled in when the hash table is constructed. */ +} SystemColorMapEntry; + +static SystemColorMapEntry systemColorMapData[] = { +{"Pixel", rgbColor, 0 }, /* This must be first. */ +{"Transparent", clearColor, 0 }, + + +{"Highlight", HIBrush, kThemeBrushPrimaryHighlightColor }, +{"HighlightSecondary", HIBrush, kThemeBrushSecondaryHighlightColor }, +{"HighlightText", HIBrush, kThemeBrushBlack }, +{"HighlightAlternate", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, +{"PrimaryHighlightColor", HIBrush, kThemeBrushPrimaryHighlightColor }, +{"ButtonFace", HIBrush, kThemeBrushButtonFaceActive }, +{"SecondaryHighlightColor", HIBrush, kThemeBrushSecondaryHighlightColor }, +{"ButtonFrame", HIBrush, kThemeBrushButtonFrameActive }, +{"AlternatePrimaryHighlightColor", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, +{"WindowBody", HIBrush, kThemeBrushDocumentWindowBackground }, +{"SheetBackground", HIBrush, kThemeBrushSheetBackground }, +{"MenuActive", HIBrush, kThemeBrushMenuBackgroundSelected }, +{"Menu", HIBrush, kThemeBrushMenuBackground }, +{"DialogBackgroundInactive", HIBrush, kThemeBrushDialogBackgroundInactive }, +{"DialogBackgroundActive", HIBrush, kThemeBrushDialogBackgroundActive }, +{"AlertBackgroundActive", HIBrush, kThemeBrushAlertBackgroundActive }, +{"AlertBackgroundInactive", HIBrush, kThemeBrushAlertBackgroundInactive }, +{"ModelessDialogBackgroundActive", HIBrush, kThemeBrushModelessDialogBackgroundActive }, +{"ModelessDialogBackgroundInactive", HIBrush, kThemeBrushModelessDialogBackgroundInactive }, +{"UtilityWindowBackgroundActive", HIBrush, kThemeBrushUtilityWindowBackgroundActive }, +{"UtilityWindowBackgroundInactive", HIBrush, kThemeBrushUtilityWindowBackgroundInactive }, +{"ListViewSortColumnBackground", HIBrush, kThemeBrushListViewSortColumnBackground }, +{"ListViewBackground", HIBrush, kThemeBrushListViewBackground }, +{"IconLabelBackground", HIBrush, kThemeBrushIconLabelBackground }, +{"ListViewSeparator", HIBrush, kThemeBrushListViewSeparator }, +{"ChasingArrows", HIBrush, kThemeBrushChasingArrows }, +{"DragHilite", HIBrush, kThemeBrushDragHilite }, +{"DocumentWindowBackground", HIBrush, kThemeBrushDocumentWindowBackground }, +{"FinderWindowBackground", HIBrush, kThemeBrushFinderWindowBackground }, +{"ScrollBarDelimiterActive", HIBrush, kThemeBrushScrollBarDelimiterActive }, +{"ScrollBarDelimiterInactive", HIBrush, kThemeBrushScrollBarDelimiterInactive }, +{"FocusHighlight", HIBrush, kThemeBrushFocusHighlight }, +{"PopupArrowActive", HIBrush, kThemeBrushPopupArrowActive }, +{"PopupArrowPressed", HIBrush, kThemeBrushPopupArrowPressed }, +{"PopupArrowInactive", HIBrush, kThemeBrushPopupArrowInactive }, +{"AppleGuideCoachmark", HIBrush, kThemeBrushAppleGuideCoachmark }, +{"IconLabelBackgroundSelected", HIBrush, kThemeBrushIconLabelBackgroundSelected }, +{"StaticAreaFill", HIBrush, kThemeBrushStaticAreaFill }, +{"ActiveAreaFill", HIBrush, kThemeBrushActiveAreaFill }, +{"ButtonFrameActive", HIBrush, kThemeBrushButtonFrameActive }, +{"ButtonFrameInactive", HIBrush, kThemeBrushButtonFrameInactive }, +{"ButtonFaceActive", HIBrush, kThemeBrushButtonFaceActive }, +{"ButtonFaceInactive", HIBrush, kThemeBrushButtonFaceInactive }, +{"ButtonFacePressed", HIBrush, kThemeBrushButtonFacePressed }, +{"ButtonActiveDarkShadow", HIBrush, kThemeBrushButtonActiveDarkShadow }, +{"ButtonActiveDarkHighlight", HIBrush, kThemeBrushButtonActiveDarkHighlight }, +{"ButtonActiveLightShadow", HIBrush, kThemeBrushButtonActiveLightShadow }, +{"ButtonActiveLightHighlight", HIBrush, kThemeBrushButtonActiveLightHighlight }, +{"ButtonInactiveDarkShadow", HIBrush, kThemeBrushButtonInactiveDarkShadow }, +{"ButtonInactiveDarkHighlight", HIBrush, kThemeBrushButtonInactiveDarkHighlight }, +{"ButtonInactiveLightShadow", HIBrush, kThemeBrushButtonInactiveLightShadow }, +{"ButtonInactiveLightHighlight", HIBrush, kThemeBrushButtonInactiveLightHighlight }, +{"ButtonPressedDarkShadow", HIBrush, kThemeBrushButtonPressedDarkShadow }, +{"ButtonPressedDarkHighlight", HIBrush, kThemeBrushButtonPressedDarkHighlight }, +{"ButtonPressedLightShadow", HIBrush, kThemeBrushButtonPressedLightShadow }, +{"ButtonPressedLightHighlight", HIBrush, kThemeBrushButtonPressedLightHighlight }, +{"BevelActiveLight", HIBrush, kThemeBrushBevelActiveLight }, +{"BevelActiveDark", HIBrush, kThemeBrushBevelActiveDark }, +{"BevelInactiveLight", HIBrush, kThemeBrushBevelInactiveLight }, +{"BevelInactiveDark", HIBrush, kThemeBrushBevelInactiveDark }, +{"NotificationWindowBackground", HIBrush, kThemeBrushNotificationWindowBackground }, +{"MovableModalBackground", HIBrush, kThemeBrushMovableModalBackground }, +{"SheetBackgroundOpaque", HIBrush, kThemeBrushSheetBackgroundOpaque }, +{"DrawerBackground", HIBrush, kThemeBrushDrawerBackground }, +{"ToolbarBackground", HIBrush, kThemeBrushToolbarBackground }, +{"SheetBackgroundTransparent", HIBrush, kThemeBrushSheetBackgroundTransparent }, +{"MenuBackground", HIBrush, kThemeBrushMenuBackground }, +{"MenuBackgroundSelected", HIBrush, kThemeBrushMenuBackgroundSelected }, +{"ListViewOddRowBackground", HIBrush, kThemeBrushListViewOddRowBackground }, +{"ListViewEvenRowBackground", HIBrush, kThemeBrushListViewEvenRowBackground }, +{"ListViewColumnDivider", HIBrush, kThemeBrushListViewColumnDivider }, + + +{"ButtonText", HIText, kThemeTextColorPushButtonActive }, +{"MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, +{"MenuDisabled", HIText, kThemeTextColorMenuItemDisabled }, +{"MenuText", HIText, kThemeTextColorMenuItemActive }, +{"BlackText", HIText, kThemeTextColorBlack }, +{"DialogActiveText", HIText, kThemeTextColorDialogActive }, +{"DialogInactiveText", HIText, kThemeTextColorDialogInactive }, +{"AlertActiveText", HIText, kThemeTextColorAlertActive }, +{"AlertInactiveText", HIText, kThemeTextColorAlertInactive }, +{"ModelessDialogActiveText", HIText, kThemeTextColorModelessDialogActive }, +{"ModelessDialogInactiveText", HIText, kThemeTextColorModelessDialogInactive }, +{"WindowHeaderActiveText", HIText, kThemeTextColorWindowHeaderActive }, +{"WindowHeaderInactiveText", HIText, kThemeTextColorWindowHeaderInactive }, +{"PlacardActiveText", HIText, kThemeTextColorPlacardActive }, +{"PlacardInactiveText", HIText, kThemeTextColorPlacardInactive }, +{"PlacardPressedText", HIText, kThemeTextColorPlacardPressed }, +{"PushButtonActiveText", HIText, kThemeTextColorPushButtonActive }, +{"PushButtonInactiveText", HIText, kThemeTextColorPushButtonInactive }, +{"PushButtonPressedText", HIText, kThemeTextColorPushButtonPressed }, +{"BevelButtonActiveText", HIText, kThemeTextColorBevelButtonActive }, +{"BevelButtonInactiveText", HIText, kThemeTextColorBevelButtonInactive }, +{"BevelButtonPressedText", HIText, kThemeTextColorBevelButtonPressed }, +{"PopupButtonActiveText", HIText, kThemeTextColorPopupButtonActive }, +{"PopupButtonInactiveText", HIText, kThemeTextColorPopupButtonInactive }, +{"PopupButtonPressedText", HIText, kThemeTextColorPopupButtonPressed }, +{"IconLabelText", HIText, kThemeTextColorIconLabel }, +{"ListViewText", HIText, kThemeTextColorListView }, +{"DocumentWindowTitleActiveText", HIText, kThemeTextColorDocumentWindowTitleActive }, +{"DocumentWindowTitleInactiveText", HIText, kThemeTextColorDocumentWindowTitleInactive }, +{"MovableModalWindowTitleActiveText", HIText, kThemeTextColorMovableModalWindowTitleActive }, +{"MovableModalWindowTitleInactiveText", HIText, kThemeTextColorMovableModalWindowTitleInactive }, +{"UtilityWindowTitleActiveText", HIText, kThemeTextColorUtilityWindowTitleActive }, +{"UtilityWindowTitleInactiveText", HIText, kThemeTextColorUtilityWindowTitleInactive }, +{"PopupWindowTitleActiveText", HIText, kThemeTextColorPopupWindowTitleActive }, +{"PopupWindowTitleInactiveText", HIText, kThemeTextColorPopupWindowTitleInactive }, +{"RootMenuActiveText", HIText, kThemeTextColorRootMenuActive }, +{"RootMenuSelectedText", HIText, kThemeTextColorRootMenuSelected }, +{"RootMenuDisabledText", HIText, kThemeTextColorRootMenuDisabled }, +{"MenuItemActiveText", HIText, kThemeTextColorMenuItemActive }, +{"MenuItemSelectedText", HIText, kThemeTextColorMenuItemSelected }, +{"MenuItemDisabledText", HIText, kThemeTextColorMenuItemDisabled }, +{"PopupLabelActiveText", HIText, kThemeTextColorPopupLabelActive }, +{"PopupLabelInactiveText", HIText, kThemeTextColorPopupLabelInactive }, +{"TabFrontActiveText", HIText, kThemeTextColorTabFrontActive }, +{"TabNonFrontActiveText", HIText, kThemeTextColorTabNonFrontActive }, +{"TabNonFrontPressedText", HIText, kThemeTextColorTabNonFrontPressed }, +{"TabFrontInactiveText", HIText, kThemeTextColorTabFrontInactive }, +{"TabNonFrontInactiveText", HIText, kThemeTextColorTabNonFrontInactive }, +{"IconLabelSelectedText", HIText, kThemeTextColorIconLabelSelected }, +{"BevelButtonStickyActiveText", HIText, kThemeTextColorBevelButtonStickyActive }, +{"BevelButtonStickyInactiveText", HIText, kThemeTextColorBevelButtonStickyInactive }, +{"NotificationText", HIText, kThemeTextColorNotification }, +{"SystemDetailText", HIText, kThemeTextColorSystemDetail }, +{"PlacardBackground", HIBackground, kThemeBackgroundPlacard }, +{"WindowHeaderBackground", HIBackground, kThemeBackgroundWindowHeader }, +{"ListViewWindowHeaderBackground", HIBackground, kThemeBackgroundListViewWindowHeader }, +{"MetalBackground", HIBackground, kThemeBackgroundMetal }, + +{"SecondaryGroupBoxBackground", HIBackground, kThemeBackgroundSecondaryGroupBox }, +{"TabPaneBackground", HIBackground, kThemeBackgroundTabPane }, +{"WhiteText", HIText, kThemeTextColorWhite }, +{"Black", HIBrush, kThemeBrushBlack }, +{"White", HIBrush, kThemeBrushWhite }, + + /* + * Dynamic Colors + */ + +{"WindowBackgroundColor", ttkBackground, 0 }, +{"WindowBackgroundColor1", ttkBackground, 1 }, +{"WindowBackgroundColor2", ttkBackground, 2 }, +{"WindowBackgroundColor3", ttkBackground, 3 }, +{"WindowBackgroundColor4", ttkBackground, 4 }, +{"WindowBackgroundColor5", ttkBackground, 5 }, +{"WindowBackgroundColor6", ttkBackground, 6 }, +{"WindowBackgroundColor7", ttkBackground, 7 }, +/* Apple's SecondaryLabelColor is the same as their LabelColor so we roll our own. */ +{"SecondaryLabelColor", ttkBackground, 14 }, + +{"TextColor", semantic, 0, "textColor" }, +{"SelectedTextColor", semantic, 0, "selectedTextColor" }, +{"LabelColor", semantic, 0, "labelColor"}, +{"ControlTextColor", semantic, 0, "controlTextColor" }, +{"DisabledControlTextColor", semantic, 0, "disabledControlTextColor" }, +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1060 +{"SelectedTabTextColor", semantic, 0, "whiteColor" }, +#else +{"SelectedTabTextColor", semantic, 0, "blackColor" }, +#endif +{"TextBackgroundColor", semantic, 0, "textBackgroundColor" }, +{"SelectedTextBackgroundColor", semantic, 0, "selectedTextBackgroundColor" }, +{"ControlAccentColor", semantic, 0, "controlAccentColor" }, +{"LinkColor", semantic, 0, "blueColor" }, +{"LinkColor", semantic, 0, "linkColor" }, +{"PlaceholderTextColor", semantic, 0, "grayColor" }, +{"PlaceholderTextColor", semantic, 0, "placeholderTextColor" }, +{"SeparatorColor", semantic, 0, "grayColor" }, +{"SeparatorColor", semantic, 0, "separatorColor" }, +{NULL, 0, 0 } +}; + +#endif -- cgit v0.12 From 549b6fe77986ec243d198acfdff6f244249c1ba9 Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 29 Jul 2020 03:51:19 +0000 Subject: Remove lines that were commented out. --- macosx/tkMacOSXColor.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 8b193b8..8e286fa 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -102,7 +102,8 @@ GetEntryFromPixel( SystemColorMapEntry *entry) { MacPixel p; - unsigned int index = 0; //FIX ME + // Should make sure this is the rgbColor index, even if the data gets shuffled. + unsigned int index = 0; p.ulong = pixel; if (p.pixel.colortype != rgbColor) { @@ -326,7 +327,6 @@ TkSetMacColor( OSStatus err = -1; SystemColorMapEntry entry; - // if (GetEntryFromPixelCode((pixel >> 24) & 0xff, &entry)) { if (GetEntryFromPixel(pixel, &entry)) { err = ChkErr(SetCGColorComponents, entry, pixel, color); } @@ -513,9 +513,6 @@ TkMacOSXSetColorInContext( CGRect rect; HIThemeBackgroundDrawInfo info = {0, kThemeStateActive, 0};; - // if (code < FIRST_SEMANTIC_COLOR) { - // cgColor = CopyCachedColor(gc, pixel); - // } if (!cgColor && GetEntryFromPixel(pixel, &entry)) { switch (entry.type) { case HIBrush: -- cgit v0.12 From a012b4334ab20bcfd26b43f6f32bca1a1d66b50e Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 29 Jul 2020 14:48:46 +0000 Subject: Fix the hash table logic and some build issues. --- macosx/tkMacOSXColor.c | 81 +++++++++++++++++++++++++++++++++++++++++------- macosx/tkMacOSXPort.h | 3 +- macosx/tkMacOSXPrivate.h | 2 -- 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 8e286fa..dd51a66 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -25,28 +25,44 @@ SystemColorMapEntry **systemColorIndex; void initColorTable() { Tcl_InitHashTable(&systemColorMap, TCL_STRING_KEYS); - SystemColorMapEntry *entry; + SystemColorMapEntry *entry, *oldEntry; Tcl_HashSearch search; Tcl_HashEntry *hPtr; - int newPtr = 0, index = 0; + int newPtr, index = 0; + + /* + * Build a hash table for looking up a color by its name. + */ + for (entry = systemColorMapData; entry->name != NULL; entry++) { hPtr = Tcl_CreateHashEntry(&systemColorMap, entry->name, &newPtr); if (entry->type == semantic) { NSString *selector = [[NSString alloc] initWithCString:entry->macName encoding:NSUTF8StringEncoding]; + /* + * Ignore this entry if NSColor does not recognize it. + */ + if (![NSColor respondsToSelector: NSSelectorFromString(selector)]) { continue; } [selector retain]; entry->selector = selector; } - if (!newPtr) { - index--; + if (newPtr == 0) { + oldEntry = (SystemColorMapEntry *) Tcl_GetHashValue(hPtr); + entry->index = oldEntry->index; + } else { + entry->index = index++; } - entry->index = index++; Tcl_SetHashValue(hPtr, entry); } + + /* + * Build an array for looking up a color by its index. + */ + systemColorMapSize = index; systemColorIndex = ckalloc(systemColorMapSize * sizeof(SystemColorMapEntry*)); for (hPtr = Tcl_FirstHashEntry(&systemColorMap, &search); hPtr != NULL; @@ -56,18 +72,60 @@ void initColorTable() } } +/* + *---------------------------------------------------------------------- + * + * TkMacOSXRGBPixel -- + * + * Return an unsigned long value suitable for use in the pixel + * field of an XColor with the specified red, green and blue + * intensities. The inputs are cast as unsigned longs but are + * expected to have values representable by an unsigned short + * as used in the XColor struct. These values are divided by + * 256 tp generate a 24-bit RGB pixel value. + * + * This is called by the TkpGetPixel macro, used in xcolor.c. + * + * Results: + * An unsigned long that can be used as the pixel field of an XColor. + * + * Side effects: + * None. + *---------------------------------------------------------------------- + */ MODULE_SCOPE -unsigned long TkMacOSXRGBPixel( - unsigned int red, - unsigned int green, - unsigned int blue) +unsigned long +TkMacOSXRGBPixel( + unsigned long red, + unsigned long green, + unsigned long blue) { MacPixel p; - p.pixel.value = (red >> 8) << 16 | (green >> 8) << 8 | (blue >> 8); p.pixel.colortype = rgbColor; + p.pixel.value = (((red >> 8) & 0xff) << 16) | + (((green >> 8) & 0xff) << 8) | + ((blue >> 8) & 0xff); return p.ulong; } - + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXClearPixel -- + * + * Return the unsigned long value that appears in the pixel + * field of the XColor for systemTransparentColor. + * + * This is used in tkMacOSXImage.c. + * + * Results: + * The unsigned long that appears in the pixel field of the XColor + * for systemTransparentPixel. + * + * Side effects: + * None. + *---------------------------------------------------------------------- + */ MODULE_SCOPE unsigned long TkMacOSXClearPixel( void) @@ -186,7 +244,6 @@ SetCGColorComponents( NSColor *bgColor, *color = nil; CGFloat rgba[4] = {0, 0, 0, 1}; static Bool initialized = 0; - NSString *selector; if (!sRGB) { sRGB = [NSColorSpace sRGBColorSpace]; } diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index b81455c..8d92601 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -163,7 +163,8 @@ /* * Used by xcolor.c */ - +MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned long red, unsigned long green, + unsigned long blue); #define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red, p->green, p->blue)) #endif /* _TKMACPORT */ diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index 8ba7541..ceca8f8 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -310,8 +310,6 @@ MODULE_SCOPE unsigned TkMacOSXAddVirtual(unsigned int keycode); MODULE_SCOPE void TkMacOSXWinNSBounds(TkWindow *winPtr, NSView *view, NSRect *bounds); MODULE_SCOPE void TkMacOSXDrawAllViews(ClientData clientData); -MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned int red, unsigned int green, - unsigned int blue); MODULE_SCOPE unsigned long TkMacOSXClearPixel(void); #pragma mark Private Objective-C Classes -- cgit v0.12 From c640e7311ee1bb1794a76c03caafc60f8e3a461e Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 29 Jul 2020 21:20:42 +0000 Subject: Clean up a few more things. --- macosx/tkMacOSXColor.c | 181 ++++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 93 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index dd51a66..3e8e065 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -146,18 +146,18 @@ unsigned long TkMacOSXClearPixel( * * Results: - * Returns false if the code is out of bounds. + * A pointer to a SystemColorMapEntry, or NULL if the pixel value is + * invalid. * * Side effects: - * None. + * None * *---------------------------------------------------------------------- */ -static bool +SystemColorMapEntry* GetEntryFromPixel( - unsigned long pixel, - SystemColorMapEntry *entry) + unsigned long pixel) { MacPixel p; // Should make sure this is the rgbColor index, even if the data gets shuffled. @@ -168,10 +168,9 @@ GetEntryFromPixel( index = p.pixel.value; } if (index < systemColorMapSize) { - *entry = *systemColorIndex[index]; - return true; + return systemColorIndex[index]; } else { - return false; + return NULL; } } @@ -185,8 +184,13 @@ GetEntryFromPixel( * the color is of type rgbColor. In that case the normalized XColor RGB * values are copied into the CGColorRef. * + * In 64 bit macOS systems there are no HITheme functions which convert + * HIText or HIBackground colors to CGColors. (GetThemeTextColor was + * removed, and it was never possible with backgrounds.) If we get one of + * these we return black. + * * Results: - * OSStatus + * True if the function succeeds, false otherwise. * * Side effects: * None. @@ -194,70 +198,28 @@ GetEntryFromPixel( *---------------------------------------------------------------------- */ -/* - * Definitions to prevent compiler warnings about nonexistent properties of NSColor. - */ - -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 - #define LABEL_COLOR labelColor -#else - #define LABEL_COLOR textColor -#endif -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 - #define LINK_COLOR linkColor -#else - #define LINK_COLOR blueColor -#endif #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 #define CONTROL_ACCENT_COLOR controlAccentColor #else #define CONTROL_ACCENT_COLOR colorForControlTint:[NSColor currentControlTint] #endif -/* - * Apple claims that linkColor is available in 10.10 but the declaration - * does not appear in NSColor.h until later. Declaring it in a category - * appears to be harmless and stops the compiler warnings. - */ - -@interface NSColor(TkColor) -#if MAC_OS_X_VERSION_MAX_ALLOWED > 101200 -@property(class, strong, readonly) NSColor *linkColor; -#elif MAC_OS_X_VERSION_MAX_ALLOWED > 1080 -@property(strong, readonly) NSColor *linkColor; -#else -@property(assign, readonly) NSColor *linkColor; -#endif -@end - static NSColorSpace* sRGB = NULL; static CGFloat windowBackground[4] = {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0}; -static OSStatus -SetCGColorComponents( - SystemColorMapEntry entry, +static void +GetRGBA( + SystemColorMapEntry *entry, unsigned long pixel, - CGColorRef *c) + CGFloat *rgba) { - OSStatus err = noErr; NSColor *bgColor, *color = nil; - CGFloat rgba[4] = {0, 0, 0, 1}; - static Bool initialized = 0; + if (!sRGB) { sRGB = [NSColorSpace sRGBColorSpace]; } - - /* - * This function is called before our autorelease pool is set up, - * so it needs its own pool. - */ - - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - switch (entry.type) { - case HIBrush: - err = ChkErr(HIThemeBrushCreateCGColor, entry.value, c); - return err; + switch (entry->type) { case rgbColor: rgba[0] = ((pixel >> 16) & 0xff) / 255.0; rgba[1] = ((pixel >> 8) & 0xff) / 255.0; @@ -280,36 +242,48 @@ SetCGColorComponents( } if (rgba[0] + rgba[1] + rgba[2] < 1.5) { for (int i=0; i<3; i++) { - rgba[i] += entry.value*8.0 / 255.0; + rgba[i] += entry->value*8.0 / 255.0; } } else { for (int i=0; i<3; i++) { - rgba[i] -= entry.value*8.0 / 255.0; + rgba[i] -= entry->value*8.0 / 255.0; } } break; case semantic: - color = [[NSColor valueForKey:entry.selector] colorUsingColorSpace:sRGB]; + color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; [color getComponents: rgba]; break; case clearColor: - rgba[3] = 0.0; + rgba[3] = 0; + default: break; + } +} + +static Bool +SetCGColorComponents( + SystemColorMapEntry *entry, + unsigned long pixel, + CGColorRef *c) +{ + CGFloat rgba[4] = {0, 0, 0, 1}; /* - * There are no HITheme functions which convert Text or background colors - * to CGColors. (GetThemeTextColor has been removed, and it was never - * possible with backgrounds.) If we get one of these we return black. + * This function is called before our autorelease pool is set up, + * so it needs its own pool. */ - case HIText: - case HIBackground: - default: - break; + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + + if (entry->type == HIBrush) { + OSStatus err = ChkErr(HIThemeBrushCreateCGColor, entry->value, c); + return err == noErr; } + GetRGBA(entry, pixel, rgba); *c = CGColorCreate(sRGB.CGColorSpace, rgba); [pool drain]; - return err; + return true; } /* @@ -359,14 +333,13 @@ TkMacOSXInDarkMode(Tk_Window tkwin) * * TkSetMacColor -- * - * Sets the components of a CGColorRef from an XColor pixel value. - * XXXX The high order byte of the pixel value is used as an index into - * the system color table, and then SetCGColorComponents is called - * with the table entry and the pixel value. + * Sets the components of a CGColorRef from an XColor pixel value. The + * pixel value is used to look up the color in the system color table, and + * then SetCGColorComponents is called with the table entry and the pixel + * value. * * Results: - * Returns false if the high order byte is not a valid index, true - * otherwise. + * Returns false if the color is not found, true otherwise. * * Side effects: * The variable macColor is set to a new CGColorRef, the caller is @@ -381,13 +354,13 @@ TkSetMacColor( void *macColor) /* CGColorRef to modify. */ { CGColorRef *color = (CGColorRef*)macColor; - OSStatus err = -1; - SystemColorMapEntry entry; + SystemColorMapEntry *entry = GetEntryFromPixel(pixel); - if (GetEntryFromPixel(pixel, &entry)) { - err = ChkErr(SetCGColorComponents, entry, pixel, color); + if (entry) { + return SetCGColorComponents(entry, pixel, color); + } else { + return false; } - return (err == noErr); } /* @@ -566,33 +539,32 @@ TkMacOSXSetColorInContext( { OSStatus err = noErr; CGColorRef cgColor = nil; - SystemColorMapEntry entry; + SystemColorMapEntry *entry = GetEntryFromPixel(pixel); CGRect rect; HIThemeBackgroundDrawInfo info = {0, kThemeStateActive, 0};; - if (!cgColor && GetEntryFromPixel(pixel, &entry)) { - switch (entry.type) { + if (entry) { + switch (entry->type) { case HIBrush: - err = ChkErr(HIThemeSetFill, entry.value, NULL, context, + err = ChkErr(HIThemeSetFill, entry->value, NULL, context, kHIThemeOrientationNormal); if (err == noErr) { - err = ChkErr(HIThemeSetStroke, entry.value, NULL, context, + err = ChkErr(HIThemeSetStroke, entry->value, NULL, context, kHIThemeOrientationNormal); } break; case HIText: - err = ChkErr(HIThemeSetTextFill, entry.value, NULL, context, + err = ChkErr(HIThemeSetTextFill, entry->value, NULL, context, kHIThemeOrientationNormal); break; case HIBackground: - info.kind = entry.value; + info.kind = entry->value; rect = CGContextGetClipBoundingBox(context); err = ChkErr(HIThemeApplyBackground, &rect, &info, context, kHIThemeOrientationNormal); break; default: - err = ChkErr(SetCGColorComponents, entry, pixel, &cgColor); - if (err == noErr) { + if (SetCGColorComponents(entry, pixel, &cgColor)){ SetCachedColor(gc, pixel, cgColor); } break; @@ -608,6 +580,31 @@ TkMacOSXSetColorInContext( } } + +/* + * Recompute the red, green and blue values of an XColor from its pixel value. + * To do this we need to know which window the color is being used in, so we + * can figure out if that window is in dark mode or not. And we will probably + * need to involve drawRect somehow since the correct color values are only + * available when a valid graphics context is available. + */ + +MODULE_SCOPE +void TkMacOSXUpdateXColor( + XColor *color, + Tk_Window tkwin) +{ + MacPixel p; + CGFloat rgba[4] = {0, 0, 0, 1}; + SystemColorMapEntry *entry = GetEntryFromPixel(color->pixel); + + p.ulong = color->pixel; + if (p.pixel.colortype == semantic || p.pixel.colortype == ttkBackground) { + printf("Updating %s in window %s for %s Mode\n", + entry->name, Tk_PathName(tkwin), + TkMacOSXInDarkMode(tkwin) ? "Dark" : "Light"); + } +} /* *---------------------------------------------------------------------- * @@ -655,11 +652,9 @@ TkpGetColor( hPtr = Tcl_FindHashEntry(&systemColorMap, name + 6); if (hPtr != NULL) { entry = (SystemColorMapEntry *)Tcl_GetHashValue(hPtr); - OSStatus err; CGColorRef c; - unsigned char pixelCode = entry->index; - err = ChkErr(SetCGColorComponents, *entry, 0, &c); - if (err == noErr) { + unsigned int pixelCode = entry->index; + if (SetCGColorComponents(entry, 0, &c)) { MacPixel p; const size_t n = CGColorGetNumberOfComponents(c); -- cgit v0.12 From 52a5bc561398bf552709b4ab92c8588d2d66f800 Mon Sep 17 00:00:00 2001 From: culler Date: Thu, 30 Jul 2020 20:32:44 +0000 Subject: Change terminology. Keep separate TkColors for light and dark mode. --- macosx/tkMacOSXColor.c | 62 ++++++++++++++++++++++++++------------------------ macosx/tkMacOSXColor.h | 4 ++-- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 3e8e065..6c43e33 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -18,14 +18,14 @@ #include "tkColor.h" #include "tkMacOSXColor.h" -static Tcl_HashTable systemColorMap; -static int systemColorMapSize; -SystemColorMapEntry **systemColorIndex; +static Tcl_HashTable systemColors; +static int numSystemColors; +SystemColorDatum **systemColorIndex; void initColorTable() { - Tcl_InitHashTable(&systemColorMap, TCL_STRING_KEYS); - SystemColorMapEntry *entry, *oldEntry; + Tcl_InitHashTable(&systemColors, TCL_STRING_KEYS); + SystemColorDatum *entry, *oldEntry; Tcl_HashSearch search; Tcl_HashEntry *hPtr; int newPtr, index = 0; @@ -34,8 +34,8 @@ void initColorTable() * Build a hash table for looking up a color by its name. */ - for (entry = systemColorMapData; entry->name != NULL; entry++) { - hPtr = Tcl_CreateHashEntry(&systemColorMap, entry->name, &newPtr); + for (entry = systemColorData; entry->name != NULL; entry++) { + hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr); if (entry->type == semantic) { NSString *selector = [[NSString alloc] initWithCString:entry->macName @@ -51,7 +51,7 @@ void initColorTable() entry->selector = selector; } if (newPtr == 0) { - oldEntry = (SystemColorMapEntry *) Tcl_GetHashValue(hPtr); + oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); entry->index = oldEntry->index; } else { entry->index = index++; @@ -63,11 +63,11 @@ void initColorTable() * Build an array for looking up a color by its index. */ - systemColorMapSize = index; - systemColorIndex = ckalloc(systemColorMapSize * sizeof(SystemColorMapEntry*)); - for (hPtr = Tcl_FirstHashEntry(&systemColorMap, &search); hPtr != NULL; + numSystemColors = index; + systemColorIndex = ckalloc(numSystemColors * sizeof(SystemColorDatum*)); + for (hPtr = Tcl_FirstHashEntry(&systemColors, &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - entry = (SystemColorMapEntry *) Tcl_GetHashValue(hPtr); + entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); systemColorIndex[entry->index] = entry; } } @@ -142,11 +142,11 @@ unsigned long TkMacOSXClearPixel( * * GetEntryFromPixel -- * - * Extract a SystemColorMapEntry from the table. + * Extract a SystemColorDatum from the table. * * Results: - * A pointer to a SystemColorMapEntry, or NULL if the pixel value is + * A pointer to a SystemColorDatum, or NULL if the pixel value is * invalid. * * Side effects: @@ -155,7 +155,7 @@ unsigned long TkMacOSXClearPixel( *---------------------------------------------------------------------- */ -SystemColorMapEntry* +SystemColorDatum* GetEntryFromPixel( unsigned long pixel) { @@ -167,7 +167,7 @@ GetEntryFromPixel( if (p.pixel.colortype != rgbColor) { index = p.pixel.value; } - if (index < systemColorMapSize) { + if (index < numSystemColors) { return systemColorIndex[index]; } else { return NULL; @@ -210,7 +210,7 @@ static CGFloat windowBackground[4] = static void GetRGBA( - SystemColorMapEntry *entry, + SystemColorDatum *entry, unsigned long pixel, CGFloat *rgba) { @@ -263,7 +263,7 @@ GetRGBA( static Bool SetCGColorComponents( - SystemColorMapEntry *entry, + SystemColorDatum *entry, unsigned long pixel, CGColorRef *c) { @@ -354,7 +354,7 @@ TkSetMacColor( void *macColor) /* CGColorRef to modify. */ { CGColorRef *color = (CGColorRef*)macColor; - SystemColorMapEntry *entry = GetEntryFromPixel(pixel); + SystemColorDatum *entry = GetEntryFromPixel(pixel); if (entry) { return SetCGColorComponents(entry, pixel, color); @@ -539,7 +539,7 @@ TkMacOSXSetColorInContext( { OSStatus err = noErr; CGColorRef cgColor = nil; - SystemColorMapEntry *entry = GetEntryFromPixel(pixel); + SystemColorDatum *entry = GetEntryFromPixel(pixel); CGRect rect; HIThemeBackgroundDrawInfo info = {0, kThemeStateActive, 0};; @@ -595,8 +595,7 @@ void TkMacOSXUpdateXColor( Tk_Window tkwin) { MacPixel p; - CGFloat rgba[4] = {0, 0, 0, 1}; - SystemColorMapEntry *entry = GetEntryFromPixel(color->pixel); + SystemColorDatum *entry = GetEntryFromPixel(color->pixel); p.ulong = color->pixel; if (p.pixel.colortype == semantic || p.pixel.colortype == ttkBackground) { @@ -610,15 +609,18 @@ void TkMacOSXUpdateXColor( * * TkpGetColor -- * - * Allocate a new TkColor for the color with the given name. + * Create a new TkColor for the color with the given name. The colormap + * field is set to 1 if passed a window with a LightAqua appearance or 2 + * if passed a window with a DarkAqua appearance. These will be managed + * separately in the per-display table of TkColors maintained by Tk. This + * function is called by Tk_Color. * * Results: * Returns a newly allocated TkColor, or NULL on failure. * * Side effects: - * May invalidate the colormap cache associated with tkwin upon - * allocating a new colormap entry. Allocates a new TkColor - * structure. + * + * Allocates memory for the TkColor structure. * *---------------------------------------------------------------------- */ @@ -630,7 +632,7 @@ TkpGetColor( * suitable for passing to XParseColor). */ { Display *display = tkwin != None ? Tk_Display(tkwin) : NULL; - Colormap colormap = tkwin!= None ? Tk_Colormap(tkwin) : None; + Colormap colormap = tkwin!= None ? 1 + TkMacOSXInDarkMode(tkwin) : None; TkColor *tkColPtr; XColor color; static Bool initialized = NO; @@ -648,10 +650,10 @@ TkpGetColor( if (strncasecmp(name, "system", 6) == 0) { Tcl_HashEntry *hPtr = NULL; - SystemColorMapEntry *entry; - hPtr = Tcl_FindHashEntry(&systemColorMap, name + 6); + SystemColorDatum *entry; + hPtr = Tcl_FindHashEntry(&systemColors, name + 6); if (hPtr != NULL) { - entry = (SystemColorMapEntry *)Tcl_GetHashValue(hPtr); + entry = (SystemColorDatum *)Tcl_GetHashValue(hPtr); CGColorRef c; unsigned int pixelCode = entry->index; if (SetCGColorComponents(entry, 0, &c)) { diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h index a4acc08..7675037 100644 --- a/macosx/tkMacOSXColor.h +++ b/macosx/tkMacOSXColor.h @@ -66,9 +66,9 @@ typedef struct { char *macName; NSString *selector; /* Filled in if used. */ int index; /* Filled in when the hash table is constructed. */ -} SystemColorMapEntry; +} SystemColorDatum; -static SystemColorMapEntry systemColorMapData[] = { +static SystemColorDatum systemColorData[] = { {"Pixel", rgbColor, 0 }, /* This must be first. */ {"Transparent", clearColor, 0 }, -- cgit v0.12 From 41650692a4d8914df2e78b8bb957e16676cb12e8 Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 31 Jul 2020 15:00:49 +0000 Subject: Make winfo rgb work correctly with the light and dark colormaps --- macosx/tkMacOSXColor.c | 95 ++++++++++++++++++++++++++++++++------------------ macosx/tkMacOSXColor.h | 34 +++++++++++++----- 2 files changed, 87 insertions(+), 42 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 6c43e33..e67cbf7 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -20,7 +20,10 @@ static Tcl_HashTable systemColors; static int numSystemColors; -SystemColorDatum **systemColorIndex; +static int rgbColorIndex; +static SystemColorDatum **systemColorIndex; +static NSAppearance *darkAqua; +static NSAppearance *lightAqua; void initColorTable() { @@ -29,6 +32,8 @@ void initColorTable() Tcl_HashSearch search; Tcl_HashEntry *hPtr; int newPtr, index = 0; + darkAqua = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; + lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; /* * Build a hash table for looking up a color by its name. @@ -37,22 +42,19 @@ void initColorTable() for (entry = systemColorData; entry->name != NULL; entry++) { hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr); if (entry->type == semantic) { - NSString *selector = [[NSString alloc] + NSString *colorName = [[NSString alloc] initWithCString:entry->macName encoding:NSUTF8StringEncoding]; - /* - * Ignore this entry if NSColor does not recognize it. - */ - - if (![NSColor respondsToSelector: NSSelectorFromString(selector)]) { + SEL colorSelector = NSSelectorFromString(colorName); + if (![NSColor respondsToSelector:colorSelector]) { continue; } - [selector retain]; - entry->selector = selector; + entry->selector = [colorName retain]; } if (newPtr == 0) { oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); entry->index = oldEntry->index; + [oldEntry->selector release]; } else { entry->index = index++; } @@ -62,7 +64,7 @@ void initColorTable() /* * Build an array for looking up a color by its index. */ - + numSystemColors = index; systemColorIndex = ckalloc(numSystemColors * sizeof(SystemColorDatum*)); for (hPtr = Tcl_FirstHashEntry(&systemColors, &search); hPtr != NULL; @@ -70,6 +72,14 @@ void initColorTable() entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); systemColorIndex[entry->index] = entry; } + + /* + * Remember the index of the rgbColor entry, + */ + + hPtr = Tcl_FindHashEntry(&systemColors, "Pixel"); + entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); + rgbColorIndex = entry->index; } /* @@ -160,8 +170,7 @@ GetEntryFromPixel( unsigned long pixel) { MacPixel p; - // Should make sure this is the rgbColor index, even if the data gets shuffled. - unsigned int index = 0; + unsigned int index = rgbColorIndex; p.ulong = pixel; if (p.pixel.colortype != rgbColor) { @@ -214,7 +223,7 @@ GetRGBA( unsigned long pixel, CGFloat *rgba) { - NSColor *bgColor, *color = nil; + NSColor *bgColor, *color; if (!sRGB) { sRGB = [NSColorSpace sRGBColorSpace]; @@ -251,7 +260,7 @@ GetRGBA( } break; case semantic: - color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; + color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; [color getComponents: rgba]; break; case clearColor: @@ -308,7 +317,6 @@ TkMacOSXInDarkMode(Tk_Window tkwin) int result = false; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - static NSAppearanceName darkAqua = @"NSAppearanceNameDarkAqua"; if ([NSApp macOSVersion] >= 101400) { TkWindow *winPtr = (TkWindow*) tkwin; @@ -317,10 +325,9 @@ TkMacOSXInDarkMode(Tk_Window tkwin) view = TkMacOSXDrawableView(winPtr->privatePtr); } if (view) { - result = [view.effectiveAppearance.name isEqualToString:darkAqua]; + result = (view.effectiveAppearance.name == NSAppearanceNameDarkAqua); } else { - result = [[NSAppearance currentAppearance].name - isEqualToString:darkAqua]; + result = ([NSAppearance currentAppearance].name == NSAppearanceNameDarkAqua); } } #endif @@ -631,34 +638,59 @@ TkpGetColor( Tk_Uid name) /* Name of color to be allocated (in form * suitable for passing to XParseColor). */ { - Display *display = tkwin != None ? Tk_Display(tkwin) : NULL; - Colormap colormap = tkwin!= None ? 1 + TkMacOSXInDarkMode(tkwin) : None; + Display *display = NULL; + Colormap colormap = noColormap; TkColor *tkColPtr; XColor color; static Bool initialized = NO; static NSColorSpace* sRGB = NULL; + if (!initialized) { initialized = YES; sRGB = [NSColorSpace sRGBColorSpace]; initColorTable(); } + if (tkwin) { + display = Tk_Display(tkwin); + colormap = TkMacOSXInDarkMode(tkwin) ? darkColormap : lightColormap; + } + /* - * Check to see if this is a system color. Otherwise, XParseColor - * will do all the work. + * Check to see if this is a system color. If not, just call XParseColor. */ if (strncasecmp(name, "system", 6) == 0) { - Tcl_HashEntry *hPtr = NULL; - SystemColorDatum *entry; - hPtr = Tcl_FindHashEntry(&systemColors, name + 6); + Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&systemColors, name + 6); + MacPixel p; + if (hPtr != NULL) { - entry = (SystemColorDatum *)Tcl_GetHashValue(hPtr); + SystemColorDatum *entry = (SystemColorDatum *)Tcl_GetHashValue(hPtr); CGColorRef c; - unsigned int pixelCode = entry->index; - if (SetCGColorComponents(entry, 0, &c)) { - MacPixel p; + p.pixel.colortype = entry->type; + p.pixel.value = entry->index; + color.pixel = p.ulong; + if (entry->type == semantic) { + CGFloat rgba[4]; + NSAppearance *savedAppearance = [NSAppearance currentAppearance]; + switch(colormap) { + case lightColormap: + [NSAppearance setCurrentAppearance:lightAqua]; + break; + case darkColormap: + [NSAppearance setCurrentAppearance:darkAqua]; + break; + default: + break; + } + GetRGBA(entry, p.ulong, rgba); + color.red = rgba[0] * 65535.0; + color.green = rgba[1] * 65535.0; + color.blue = rgba[2] * 65535.0; + [NSAppearance setCurrentAppearance:savedAppearance]; + goto validXColor; + } else if (SetCGColorComponents(entry, 0, &c)) { const size_t n = CGColorGetNumberOfComponents(c); const CGFloat *rgba = CGColorGetComponents(c); @@ -674,16 +706,12 @@ TkpGetColor( default: Tcl_Panic("CGColor with %d components", (int) n); } - p.pixel.value = pixelCode; - p.pixel.colortype = entry->type; - color.pixel = p.ulong; CGColorRelease(c); goto validXColor; } CGColorRelease(c); } } - if (TkParseColor(display, colormap, name, &color) == 0) { return NULL; } @@ -691,7 +719,6 @@ TkpGetColor( validXColor: tkColPtr = ckalloc(sizeof(TkColor)); tkColPtr->color = color; - return tkColPtr; } diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h index 7675037..9cbe8a3 100644 --- a/macosx/tkMacOSXColor.h +++ b/macosx/tkMacOSXColor.h @@ -55,6 +55,17 @@ typedef union MacPixel_t { } MacPixel; /* + * We maintain two colormaps, one for the LightAqua appearance and one for the + * DarkAqua appearance. + */ + +enum macColormap { + noColormap, + lightColormap, + darkColormap, +}; + +/* * In TkMacOSXColor.c a Tk hash table is constructed from the static data * below to map system color names to CGColors. */ @@ -62,17 +73,17 @@ typedef union MacPixel_t { typedef struct { const char *name; enum colorType type; - long value; + int value; char *macName; - NSString *selector; /* Filled in if used. */ - int index; /* Filled in when the hash table is constructed. */ + /* Fields below are filled in after or during construction of the hash table. */ + int index; + NSString *selector; } SystemColorDatum; static SystemColorDatum systemColorData[] = { -{"Pixel", rgbColor, 0 }, /* This must be first. */ +{"Pixel", rgbColor, 0 }, {"Transparent", clearColor, 0 }, - {"Highlight", HIBrush, kThemeBrushPrimaryHighlightColor }, {"HighlightSecondary", HIBrush, kThemeBrushSecondaryHighlightColor }, {"HighlightText", HIBrush, kThemeBrushBlack }, @@ -145,9 +156,8 @@ static SystemColorDatum systemColorData[] = { {"ListViewEvenRowBackground", HIBrush, kThemeBrushListViewEvenRowBackground }, {"ListViewColumnDivider", HIBrush, kThemeBrushListViewColumnDivider }, - -{"ButtonText", HIText, kThemeTextColorPushButtonActive }, -{"MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, +{"ButtonText", HIText, kThemeTextColorPushButtonActive }, +{"MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, {"MenuDisabled", HIText, kThemeTextColorMenuItemDisabled }, {"MenuText", HIText, kThemeTextColorMenuItemActive }, {"BlackText", HIText, kThemeTextColorBlack }, @@ -248,3 +258,11 @@ static SystemColorDatum systemColorData[] = { }; #endif +/* + * Local Variables: + * mode: objc + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ -- cgit v0.12 From ec1fbf2bb9c415c33579658a7a0ebfffcddc19d1 Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 31 Jul 2020 17:09:38 +0000 Subject: Tidying up a few loose ends. --- macosx/tkMacOSXColor.c | 105 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index e67cbf7..e576dd7 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -21,9 +21,14 @@ static Tcl_HashTable systemColors; static int numSystemColors; static int rgbColorIndex; +static int controlAccentIndex; +static Bool useFakeAccentColor = NO; static SystemColorDatum **systemColorIndex; static NSAppearance *darkAqua; static NSAppearance *lightAqua; +static NSColorSpace* sRGB = NULL; +static CGFloat windowBackground[4] = + {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0}; void initColorTable() { @@ -47,7 +52,11 @@ void initColorTable() encoding:NSUTF8StringEncoding]; SEL colorSelector = NSSelectorFromString(colorName); if (![NSColor respondsToSelector:colorSelector]) { - continue; + if ([colorName isEqualToString:@"controlAccentColor"]) { + useFakeAccentColor = YES; + } else { + continue; + } } entry->selector = [colorName retain]; } @@ -74,12 +83,15 @@ void initColorTable() } /* - * Remember the index of the rgbColor entry, + * Remember the indexes of some special entries. */ hPtr = Tcl_FindHashEntry(&systemColors, "Pixel"); entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); rgbColorIndex = entry->index; + hPtr = Tcl_FindHashEntry(&systemColors, "ControlAccentColor"); + entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); + controlAccentIndex = entry->index; } /* @@ -155,7 +167,6 @@ unsigned long TkMacOSXClearPixel( * Extract a SystemColorDatum from the table. * * Results: - * A pointer to a SystemColorDatum, or NULL if the pixel value is * invalid. * @@ -183,40 +194,27 @@ GetEntryFromPixel( } } + /* *---------------------------------------------------------------------- * - * SetCGColorComponents -- - * - * Set the components of a CGColorRef from an XColor pixel value and a - * system color map entry. The pixel value is only used in the case where - * the color is of type rgbColor. In that case the normalized XColor RGB - * values are copied into the CGColorRef. + * GetRGB -- * - * In 64 bit macOS systems there are no HITheme functions which convert - * HIText or HIBackground colors to CGColors. (GetThemeTextColor was - * removed, and it was never possible with backgrounds.) If we get one of - * these we return black. + * 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 + * RGBColor datum, the unsigned long pixel value containing the RGB values + * must also be provided as the pixel parameter. Otherwise the pixel + * parameter is ignored. * * Results: - * True if the function succeeds, false otherwise. + * None * * Side effects: - * None. + * The array rgba is filled in. * *---------------------------------------------------------------------- */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - #define CONTROL_ACCENT_COLOR controlAccentColor -#else - #define CONTROL_ACCENT_COLOR colorForControlTint:[NSColor currentControlTint] -#endif - -static NSColorSpace* sRGB = NULL; -static CGFloat windowBackground[4] = - {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0}; - static void GetRGBA( SystemColorDatum *entry, @@ -242,7 +240,7 @@ GetRGBA( */ if ([NSApp macOSVersion] < 101400) { - for (int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { rgba[i] = windowBackground[i]; } } else { @@ -260,15 +258,65 @@ GetRGBA( } break; case semantic: - color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; + if (entry->index == controlAccentIndex && useFakeAccentColor) { + color = [NSColor colorForControlTint: [NSColor currentControlTint]]; + } else { + color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; + } [color getComponents: rgba]; break; case clearColor: rgba[3] = 0; + case HIText: +#ifdef __LP64__ + color = [[NSColor textColor] colorUsingColorSpace:sRGB]; + [color getComponents: rgba]; +#else + { + RGBColor rgb; + err = GetThemeTextColor(kThemeTextColorPushButtonActive, 32, + true, &rgb); + if (err == noErr) { + rgba[0] = (CGFLoat) rgb.red / 65535; + rgba[1] = (CGFLoat) rgb.green / 65535; + rgba[2] = (CGFLoat) rgb.blue / 65535; + } + } +#endif + break; + case HIBackground: + color = [[NSColor windowBackgroundColor] colorUsingColorSpace:sRGB]; + [color getComponents: rgba]; + break; default: break; } } + +/* + *---------------------------------------------------------------------- + * + * SetCGColorComponents -- + * + * Set the components of a CGColorRef from an XColor pixel value and a + * system color map entry. The pixel value is only used in the case where + * the color is of type rgbColor. In that case the normalized XColor RGB + * values are copied into the CGColorRef. + * + * In 64 bit macOS systems there are no HITheme functions which convert + * HIText or HIBackground colors to CGColors. (GetThemeTextColor was + * removed, and it was never possible with backgrounds.) On 64-bit systems + * we replace all HIText colors by systemTextColor and all HIBackground + * colors by systemWindowBackgroundColor. + * + * Results: + * True if the function succeeds, false otherwise. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ static Bool SetCGColorComponents( @@ -685,10 +733,10 @@ TkpGetColor( break; } GetRGBA(entry, p.ulong, rgba); + [NSAppearance setCurrentAppearance:savedAppearance]; color.red = rgba[0] * 65535.0; color.green = rgba[1] * 65535.0; color.blue = rgba[2] * 65535.0; - [NSAppearance setCurrentAppearance:savedAppearance]; goto validXColor; } else if (SetCGColorComponents(entry, 0, &c)) { const size_t n = CGColorGetNumberOfComponents(c); @@ -709,7 +757,6 @@ TkpGetColor( CGColorRelease(c); goto validXColor; } - CGColorRelease(c); } } if (TkParseColor(display, colormap, name, &color) == 0) { -- cgit v0.12 From 33c01e381216e12ecd1375775ca7ef7cf332b7d5 Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 31 Jul 2020 18:29:50 +0000 Subject: Fix the build for systems without darkAqua. --- macosx/tkMacOSXColor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index e576dd7..276fa68 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -37,7 +37,9 @@ void initColorTable() Tcl_HashSearch search; Tcl_HashEntry *hPtr; int newPtr, index = 0; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 darkAqua = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; +#endif lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; /* @@ -722,6 +724,7 @@ TkpGetColor( if (entry->type == semantic) { CGFloat rgba[4]; NSAppearance *savedAppearance = [NSAppearance currentAppearance]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 switch(colormap) { case lightColormap: [NSAppearance setCurrentAppearance:lightAqua]; @@ -732,6 +735,7 @@ TkpGetColor( default: break; } +#endif GetRGBA(entry, p.ulong, rgba); [NSAppearance setCurrentAppearance:savedAppearance]; color.red = rgba[0] * 65535.0; -- cgit v0.12 From f75f4370274d507d9b3488cece85d3e49df019e4 Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 31 Jul 2020 18:44:30 +0000 Subject: Prevent a warning on systems without darkAqua. --- macosx/tkMacOSXColor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 276fa68..370e8a5 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -24,8 +24,10 @@ static int rgbColorIndex; static int controlAccentIndex; static Bool useFakeAccentColor = NO; static SystemColorDatum **systemColorIndex; -static NSAppearance *darkAqua; static NSAppearance *lightAqua; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 +static NSAppearance *darkAqua; +#endif static NSColorSpace* sRGB = NULL; static CGFloat windowBackground[4] = {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0}; -- cgit v0.12 From 76f6c8ed20f1b31eb53111b9ad3363f3998c271c Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 31 Jul 2020 20:34:29 +0000 Subject: Remove an unused function. Deal with colors which are not supported on older systems (10.9) --- macosx/tkMacOSXColor.c | 31 ++++++------------------------- macosx/tkMacOSXColor.h | 8 ++++++++ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 370e8a5..b77adf3 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -1,5 +1,5 @@ /* - * tkMacOSXColor.c -- + * TkMacOSXColor.c -- * * This file maintains a database of color values for the Tk * toolkit, in order to avoid round-trips to the server to @@ -59,6 +59,8 @@ void initColorTable() if ([colorName isEqualToString:@"controlAccentColor"]) { useFakeAccentColor = YES; } else { + /* Uncomment to print all unsupported colors: */ + /* printf("Unsupported color %s\n", colorName.UTF8String); */ continue; } } @@ -83,6 +85,9 @@ void initColorTable() for (hPtr = Tcl_FirstHashEntry(&systemColors, &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); + if (entry == NULL) { + Tcl_Panic("Unsupported semantic color with no supported backup!"); + } systemColorIndex[entry->index] = entry; } @@ -639,30 +644,6 @@ TkMacOSXSetColorInContext( } } - -/* - * Recompute the red, green and blue values of an XColor from its pixel value. - * To do this we need to know which window the color is being used in, so we - * can figure out if that window is in dark mode or not. And we will probably - * need to involve drawRect somehow since the correct color values are only - * available when a valid graphics context is available. - */ - -MODULE_SCOPE -void TkMacOSXUpdateXColor( - XColor *color, - Tk_Window tkwin) -{ - MacPixel p; - SystemColorDatum *entry = GetEntryFromPixel(color->pixel); - - p.ulong = color->pixel; - if (p.pixel.colortype == semantic || p.pixel.colortype == ttkBackground) { - printf("Updating %s in window %s for %s Mode\n", - entry->name, Tk_PathName(tkwin), - TkMacOSXInDarkMode(tkwin) ? "Dark" : "Light"); - } -} /* *---------------------------------------------------------------------- * diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h index 9cbe8a3..82c88c9 100644 --- a/macosx/tkMacOSXColor.h +++ b/macosx/tkMacOSXColor.h @@ -80,6 +80,13 @@ typedef struct { NSString *selector; } SystemColorDatum; +/* + * WARNING: Semantic colors which are not supported on all systems must be + * preceded by a backup color with the same name which *is* supported. Systems + * which do support the color will replace the backup value when the table is + * constructed. Failing to ensure this will result in a Tcl_Panic abort. + */ + static SystemColorDatum systemColorData[] = { {"Pixel", rgbColor, 0 }, {"Transparent", clearColor, 0 }, @@ -237,6 +244,7 @@ static SystemColorDatum systemColorData[] = { {"TextColor", semantic, 0, "textColor" }, {"SelectedTextColor", semantic, 0, "selectedTextColor" }, +{"LabelColor", semantic, 0, "textColor"}, {"LabelColor", semantic, 0, "labelColor"}, {"ControlTextColor", semantic, 0, "controlTextColor" }, {"DisabledControlTextColor", semantic, 0, "disabledControlTextColor" }, -- cgit v0.12 From e6d961299e585273d99aa80444ad9237449c512a Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 31 Jul 2020 21:10:41 +0000 Subject: Adjust some unixEmbed tests which were failing sporadically. --- tests/unixEmbed.test | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unixEmbed.test b/tests/unixEmbed.test index 2ebf9c2..428e510 100644 --- a/tests/unixEmbed.test +++ b/tests/unixEmbed.test @@ -1238,13 +1238,12 @@ test unixEmbed-10.1 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} -con deleteWindows } -body { frame .f1 -container 1 -width 200 -height 50 - update pack .f1 - update + update idletasks toplevel .t1 -use [winfo id .f1] -width 150 -height 80 - update + update idletasks wm geometry .t1 +40+50 - update + update idletasks wm geometry .t1 } -cleanup { deleteWindows @@ -1256,10 +1255,11 @@ test unixEmbed-10.2 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} -con } -body { frame .f1 -container 1 -width 200 -height 50 pack .f1 + update idletasks toplevel .t1 -use [winfo id .f1] -width 150 -height 80 - update + update idletasks wm geometry .t1 70x300+10+20 - update + update idletasks wm geometry .t1 } -cleanup { deleteWindows -- cgit v0.12 From 0266964e830c47c5a6e12654b8e84378dfe97ca5 Mon Sep 17 00:00:00 2001 From: culler Date: Sat, 1 Aug 2020 16:12:43 +0000 Subject: The colormaps do not fix winfo rgb. Handle that directly. And deal with Big Sur deprecations. --- generic/tkCmds.c | 16 ++++++++++++++++ macosx/tkMacOSXColor.c | 38 ++++++++++++++++++++------------------ macosx/tkMacOSXConstants.h | 4 +++- macosx/tkMacOSXPort.h | 3 +++ macosx/tkMacOSXWindowEvent.c | 7 ------- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/generic/tkCmds.c b/generic/tkCmds.c index 7f4c49b..1bc4f8c 100644 --- a/generic/tkCmds.c +++ b/generic/tkCmds.c @@ -1748,7 +1748,23 @@ Tk_WinfoObjCmd( if (TkGetWindowFromObj(interp, tkwin, objv[2], &tkwin) != TCL_OK) { return TCL_ERROR; } +#ifdef TK_HAS_DYNAMIC_COLORS + + /* + * Make sure that the TkColor used for the winfo rgb command is + * destroyed when we are through with it, so we do not get stale RGB + * values next time. + */ + + { + Colormap temp = Tk_Colormap(tkwin); + Tk_Colormap(tkwin) = TK_DYNAMIC_COLORMAP; + colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3])); + Tk_Colormap(tkwin) = temp; + } +#else colorPtr = Tk_GetColor(interp, tkwin, Tcl_GetString(objv[3])); +#endif if (colorPtr == NULL) { return TCL_ERROR; } diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index b77adf3..2a78c97 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -24,9 +24,9 @@ static int rgbColorIndex; static int controlAccentIndex; static Bool useFakeAccentColor = NO; static SystemColorDatum **systemColorIndex; -static NSAppearance *lightAqua; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 -static NSAppearance *darkAqua; +static NSAppearance *lightAqua = nil; +static NSAppearance *darkAqua = nil; #endif static NSColorSpace* sRGB = NULL; static CGFloat windowBackground[4] = @@ -41,8 +41,8 @@ void initColorTable() int newPtr, index = 0; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 darkAqua = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; -#endif lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua]; +#endif /* * Build a hash table for looking up a color by its name. @@ -230,7 +230,7 @@ GetRGBA( unsigned long pixel, CGFloat *rgba) { - NSColor *bgColor, *color; + NSColor *bgColor, *color = nil; if (!sRGB) { sRGB = [NSColorSpace sRGBColorSpace]; @@ -268,7 +268,9 @@ GetRGBA( break; case semantic: if (entry->index == controlAccentIndex && useFakeAccentColor) { +#if MAC_OS_X_VERSION_MAX_ALLOWED < 101500 color = [NSColor colorForControlTint: [NSColor currentControlTint]]; +#endif } else { color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB]; } @@ -672,9 +674,9 @@ TkpGetColor( * suitable for passing to XParseColor). */ { Display *display = NULL; - Colormap colormap = noColormap; TkColor *tkColPtr; XColor color; + Colormap colormap = tkwin ? Tk_Colormap(tkwin) : noColormap; static Bool initialized = NO; static NSColorSpace* sRGB = NULL; @@ -683,10 +685,8 @@ TkpGetColor( sRGB = [NSColorSpace sRGBColorSpace]; initColorTable(); } - if (tkwin) { display = Tk_Display(tkwin); - colormap = TkMacOSXInDarkMode(tkwin) ? darkColormap : lightColormap; } /* @@ -706,21 +706,22 @@ TkpGetColor( color.pixel = p.ulong; if (entry->type == semantic) { CGFloat rgba[4]; - NSAppearance *savedAppearance = [NSAppearance currentAppearance]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 - switch(colormap) { - case lightColormap: - [NSAppearance setCurrentAppearance:lightAqua]; - break; - case darkColormap: - [NSAppearance setCurrentAppearance:darkAqua]; - break; - default: - break; + NSAppearance *savedAppearance = [NSAppearance currentAppearance]; + NSAppearance *windowAppearance; + if (TkMacOSXInDarkMode(tkwin)) { + windowAppearance = darkAqua; + colormap = darkColormap; + } else { + windowAppearance = lightAqua; + colormap = lightColormap; } -#endif + [NSAppearance setCurrentAppearance:windowAppearance]; GetRGBA(entry, p.ulong, rgba); [NSAppearance setCurrentAppearance:savedAppearance]; +#else + GetRGBA(entry, p.ulong, rgba); +#endif color.red = rgba[0] * 65535.0; color.green = rgba[1] * 65535.0; color.blue = rgba[2] * 65535.0; @@ -752,6 +753,7 @@ TkpGetColor( validXColor: tkColPtr = ckalloc(sizeof(TkColor)); + tkColPtr->colormap = colormap; tkColPtr->color = color; return tkColPtr; } diff --git a/macosx/tkMacOSXConstants.h b/macosx/tkMacOSXConstants.h index e019ea1..19ffd2c 100644 --- a/macosx/tkMacOSXConstants.h +++ b/macosx/tkMacOSXConstants.h @@ -106,6 +106,8 @@ typedef NSInteger NSModalResponse; #define graphicsContextWithGraphicsPort graphicsContextWithCGContext #endif - +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 110000 +#define NSWindowStyleMaskTexturedBackground 0 #endif +#endif diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index 8d92601..f5c3689 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -159,10 +159,13 @@ */ #define TK_NO_DOUBLE_BUFFERING 1 +#define TK_HAS_DYNAMIC_COLORS 1 +#define TK_DYNAMIC_COLORMAP 0x0fffffff /* * Used by xcolor.c */ + MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned long red, unsigned long green, unsigned long blue); #define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red, p->green, p->blue)) diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 5f52ea7..a23a6d7 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -1137,13 +1137,6 @@ ConfigureRestrictProc( Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL); } -- (BOOL) isOpaque -{ - NSWindow *w = [self window]; - return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) || - ![w isOpaque]) ? NO : YES); -} - /* * On Catalina this is never called and drawRect clips to the rect that * is passed to it by AppKit. -- cgit v0.12 From 78ff00814bd1260e38a3990c46571c8f5ff94c5d Mon Sep 17 00:00:00 2001 From: culler Date: Sun, 2 Aug 2020 14:13:58 +0000 Subject: Edit comments --- macosx/tkMacOSXColor.c | 77 +++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 2a78c97..b4347b8 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -9,6 +9,7 @@ * Copyright (c) 1994-1996 Sun Microsystems, Inc. * Copyright 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen + * Copyright (c) 2020 Marc Culler * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -47,7 +48,7 @@ void initColorTable() /* * Build a hash table for looking up a color by its name. */ - + for (entry = systemColorData; entry->name != NULL; entry++) { hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr); if (entry->type == semantic) { @@ -75,7 +76,7 @@ void initColorTable() } Tcl_SetHashValue(hPtr, entry); } - + /* * Build an array for looking up a color by its index. */ @@ -94,7 +95,7 @@ void initColorTable() /* * Remember the indexes of some special entries. */ - + hPtr = Tcl_FindHashEntry(&systemColors, "Pixel"); entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr); rgbColorIndex = entry->index; @@ -113,7 +114,7 @@ void initColorTable() * intensities. The inputs are cast as unsigned longs but are * expected to have values representable by an unsigned short * as used in the XColor struct. These values are divided by - * 256 tp generate a 24-bit RGB pixel value. + * 256 to generate a 24-bit RGB pixel value. * * This is called by the TkpGetPixel macro, used in xcolor.c. * @@ -173,7 +174,8 @@ unsigned long TkMacOSXClearPixel( * * GetEntryFromPixel -- * - * Extract a SystemColorDatum from the table. + * Look up a SystemColorDatum which describes the XColor with + * the specified value as its pixel field. * * Results: * A pointer to a SystemColorDatum, or NULL if the pixel value is @@ -285,7 +287,7 @@ GetRGBA( #else { RGBColor rgb; - err = GetThemeTextColor(kThemeTextColorPushButtonActive, 32, + err = GetThemeTextColor(kThemeTextColorPushButtonActive, 32, true, &rgb); if (err == noErr) { rgba[0] = (CGFLoat) rgb.red / 65535; @@ -310,9 +312,10 @@ GetRGBA( * SetCGColorComponents -- * * Set the components of a CGColorRef from an XColor pixel value and a - * system color map entry. The pixel value is only used in the case where + * SystemColorDatum. The pixel value is only used in the case where * the color is of type rgbColor. In that case the normalized XColor RGB - * values are copied into the CGColorRef. + * values are copied into the CGColorRef. Otherwise the components are + * computed from the SystemColorDatum. * * In 64 bit macOS systems there are no HITheme functions which convert * HIText or HIBackground colors to CGColors. (GetThemeTextColor was @@ -328,7 +331,7 @@ GetRGBA( * *---------------------------------------------------------------------- */ - + static Bool SetCGColorComponents( SystemColorDatum *entry, @@ -384,7 +387,7 @@ TkMacOSXInDarkMode(Tk_Window tkwin) view = TkMacOSXDrawableView(winPtr->privatePtr); } if (view) { - result = (view.effectiveAppearance.name == NSAppearanceNameDarkAqua); + result = (view.effectiveAppearance.name == NSAppearanceNameDarkAqua); } else { result = ([NSAppearance currentAppearance].name == NSAppearanceNameDarkAqua); } @@ -547,9 +550,10 @@ TkMacOSXCreateCGColor( * TkMacOSXGetNSColor -- * * Creates an autoreleased NSColor from a X style pixel value. + * The return value is nil if the pixel value is invalid. * * Results: - * Returns nil if not a real pixel, NSColor* otherwise. + * A possibly nil pointer to an NSColor. * * Side effects: * None @@ -583,10 +587,9 @@ TkMacOSXGetNSColor( * * TkMacOSXSetColorInContext -- * - * Sets fill and stroke color in the given CG context from an X - * pixel value, or if the pixel code indicates a system color, - * sets the corresponding brush, textColor or background via - * HITheme APIs if available or Appearance mgr APIs. + * Sets the fill and stroke colors in the given CGContext to the CGColor + * which corresponds to the XColor having the specified value for its pixel + * field. * * Results: * None. @@ -651,17 +654,19 @@ TkMacOSXSetColorInContext( * * TkpGetColor -- * - * Create a new TkColor for the color with the given name. The colormap - * field is set to 1 if passed a window with a LightAqua appearance or 2 - * if passed a window with a DarkAqua appearance. These will be managed - * separately in the per-display table of TkColors maintained by Tk. This - * function is called by Tk_Color. + * Create a new TkColor for the color with the given name, for use in the + * specified window. The colormap field is set to lightColormap if the + * window has a LightAqua appearance, or darkColormap if the window has a + * DarkAqua appearance. TkColors with different colormaps are managed + * separately in the per-display table of TkColors maintained by Tk. + * + * This function is called by Tk_GetColor. * * Results: * Returns a newly allocated TkColor, or NULL on failure. * * Side effects: - * + * * Allocates memory for the TkColor structure. * *---------------------------------------------------------------------- @@ -708,7 +713,7 @@ TkpGetColor( CGFloat rgba[4]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 NSAppearance *savedAppearance = [NSAppearance currentAppearance]; - NSAppearance *windowAppearance; + NSAppearance *windowAppearance; if (TkMacOSXInDarkMode(tkwin)) { windowAppearance = darkAqua; colormap = darkColormap; @@ -721,7 +726,7 @@ TkpGetColor( [NSAppearance setCurrentAppearance:savedAppearance]; #else GetRGBA(entry, p.ulong, rgba); -#endif +#endif color.red = rgba[0] * 65535.0; color.green = rgba[1] * 65535.0; color.blue = rgba[2] * 65535.0; @@ -763,19 +768,19 @@ validXColor: * * TkpGetColorByValue -- * - * Given a desired set of red-green-blue intensities for a color, - * locate a pixel value to use to draw that color in a given - * window. + * Given an pointer to an XColor, construct a TkColor whose red, green and + * blue intensities match those of the XColor as closely as possible. For + * the Macintosh, this means that the colortype bitfield of the pixel + * value will be RGBColor and that the color intensities stored in its + * 24-bit value bitfield are computed from the 16-bit red green and blue + * values in the XColor by dividing by 256. * * Results: - * The return value is a pointer to an TkColor structure that - * indicates the closest red, blue, and green intensities available - * to those specified in colorPtr, and also specifies a pixel - * value to use to draw in that color. + * A pointer to a newly allocated TkColor structure. * * Side effects: * May invalidate the colormap cache for the specified window. - * Allocates a new TkColor structure. + * Allocates memory for a TkColor structure. * *---------------------------------------------------------------------- */ @@ -830,10 +835,11 @@ XCreateColormap( Visual *visual, /* Not used. */ int alloc) /* Not used. */ { - static Colormap index = 1; + static Colormap index = 16; /* - * Just return a new value each time. + * Just return a new value each time, large enough that it will not + * conflict with any value of the macColormap enum. */ return index++; } @@ -855,9 +861,8 @@ XFreeColors( unsigned long planes) /* Number of pixel planes. */ { /* - * The Macintosh version of Tk uses TrueColor. Nothing - * needs to be done to release colors as there really is - * no colormap in the Tk sense. + * Nothing needs to be done to release colors as there really is no + * colormap in the Tk sense. */ return Success; } -- cgit v0.12 From 6adf699f287514c469d4827316e856204f4f84c6 Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 3 Aug 2020 01:28:50 +0000 Subject: Fix [fca13549b6]: TkMacOSXRGBPixel() used incorrectly in ImageGetPixel() --- macosx/tkMacOSXImage.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 4691e41..8a7aac4 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -314,7 +314,12 @@ ImageGetPixel( int x, int y) { - unsigned char r = 0, g = 0, b = 0; + unsigned short r = 0, g = 0, b = 0; + + /* + * Compute 8 bit red green and blue values, which are multiplied by 256 and + * ed as inputs to TkMacOSXRGBPixel. + */ if (image && image->data) { unsigned char *srcPtr = ((unsigned char*) image->data) @@ -322,7 +327,7 @@ ImageGetPixel( + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); switch (image->bits_per_pixel) { - case 32: + case 32: /* 8 bits per channel */ r = (*((unsigned int*) srcPtr) >> 16) & 0xff; g = (*((unsigned int*) srcPtr) >> 8) & 0xff; b = (*((unsigned int*) srcPtr) ) & 0xff; @@ -332,12 +337,12 @@ ImageGetPixel( r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; }*/ break; - case 16: + case 16: /* 5 bits per channel */ r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; b = (*((unsigned short*) srcPtr) << 3) & 0xf8; break; - case 8: + case 8: /* 2 bits per channel */ r = (*srcPtr << 2) & 0xc0; g = (*srcPtr << 4) & 0xc0; b = (*srcPtr << 6) & 0xc0; @@ -345,7 +350,7 @@ ImageGetPixel( g |= g >> 2 | g >> 4 | g >> 6; b |= b >> 2 | b >> 4 | b >> 6; break; - case 4: { + case 4: { /* 1 bit per channel */ unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); r = (c & 0x04) ? 0xff : 0; @@ -353,12 +358,13 @@ ImageGetPixel( b = (c & 0x01) ? 0xff : 0; break; } - case 1: + case 1: /* Black-white bitmap. */ r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; break; } } - return TkMacOSXRGBPixel(r, g, b); + + return TkMacOSXRGBPixel(r<<8, g<<8, b<<8); } /* -- cgit v0.12 From d67e38a86d79f6df28051611978dcaac8b1be9cc Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 3 Aug 2020 02:16:07 +0000 Subject: Be a little more efficient. --- macosx/tkMacOSXColor.c | 13 ++++++------- macosx/tkMacOSXImage.c | 4 ++-- macosx/tkMacOSXPort.h | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index b4347b8..ce91520 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -112,11 +112,10 @@ void initColorTable() * Return an unsigned long value suitable for use in the pixel * field of an XColor with the specified red, green and blue * intensities. The inputs are cast as unsigned longs but are - * expected to have values representable by an unsigned short - * as used in the XColor struct. These values are divided by - * 256 to generate a 24-bit RGB pixel value. + * expected to have values representable by an unsigned char. * - * This is called by the TkpGetPixel macro, used in xcolor.c. + * This is called in the TkpGetPixel macro, used in xcolor.c, + * and in ImageGetPixel. * * Results: * An unsigned long that can be used as the pixel field of an XColor. @@ -134,9 +133,9 @@ TkMacOSXRGBPixel( { MacPixel p; p.pixel.colortype = rgbColor; - p.pixel.value = (((red >> 8) & 0xff) << 16) | - (((green >> 8) & 0xff) << 8) | - ((blue >> 8) & 0xff); + p.pixel.value = ((red & 0xff) << 16) | + ((green & 0xff) << 8) | + (blue & 0xff); return p.ulong; } diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 8a7aac4..2967bb0 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -314,7 +314,7 @@ ImageGetPixel( int x, int y) { - unsigned short r = 0, g = 0, b = 0; + unsigned char r = 0, g = 0, b = 0; /* * Compute 8 bit red green and blue values, which are multiplied by 256 and @@ -364,7 +364,7 @@ ImageGetPixel( } } - return TkMacOSXRGBPixel(r<<8, g<<8, b<<8); + return TkMacOSXRGBPixel(r, g, b); } /* diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index f5c3689..4347766 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -168,6 +168,6 @@ MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned long red, unsigned long green, unsigned long blue); -#define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red, p->green, p->blue)) +#define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red >> 8, p->green >> 8, p->blue >> 8)) #endif /* _TKMACPORT */ -- cgit v0.12 From 2c6e31f7fd99017ab613b39e77357ad91b0be8c7 Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 3 Aug 2020 12:41:10 +0000 Subject: Edit comments. --- macosx/tkMacOSXImage.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 2967bb0..0e33b23 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -300,7 +300,11 @@ DestroyImage( * Get a single pixel from an image. * * Results: - * Returns the 32 bit pixel value. + * The XColor structure contains an unsigned long field named pixel which + * identifies the color. This function returns the unsigned long that + * would be used as the pixel value of an XColor that has the same red + * green and blue components as the XImage pixel at the specified + * location. * * Side effects: * None. @@ -317,8 +321,8 @@ ImageGetPixel( unsigned char r = 0, g = 0, b = 0; /* - * Compute 8 bit red green and blue values, which are multiplied by 256 and - * ed as inputs to TkMacOSXRGBPixel. + * Compute 8 bit red green and blue values, which are passed as inputs to + * TkMacOSXRGBPixel to produce the pixel value. */ if (image && image->data) { -- cgit v0.12 From 35b2870cff97386ce7ea956ee317bec123017d52 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 3 Aug 2020 17:25:02 +0000 Subject: end-of-line spacing cleanup --- generic/tkCmds.c | 2 +- generic/tkTest.c | 2 +- macosx/tkMacOSXColor.h | 58 ++++++++++++++++++++++----------------------- macosx/tkMacOSXPrivate.h | 2 +- macosx/tkMacOSXSubwindows.c | 4 ++-- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/generic/tkCmds.c b/generic/tkCmds.c index 1bc4f8c..89b5254 100644 --- a/generic/tkCmds.c +++ b/generic/tkCmds.c @@ -1755,7 +1755,7 @@ Tk_WinfoObjCmd( * destroyed when we are through with it, so we do not get stale RGB * values next time. */ - + { Colormap temp = Tk_Colormap(tkwin); Tk_Colormap(tkwin) = TK_DYNAMIC_COLORMAP; diff --git a/generic/tkTest.c b/generic/tkTest.c index c22e649..26b3fa5 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -1592,7 +1592,7 @@ ImageDisplay( * Drawing is not possible on the first call to DisplayImage. * Save the message, but do not log it until the actual display. */ - + if (instPtr->displayFailed == False) { sprintf(instPtr->buffer, "%s display %d %d %d %d", instPtr->masterPtr->imageName, imageX, imageY, width, height); diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h index 82c88c9..89d147d 100644 --- a/macosx/tkMacOSXColor.h +++ b/macosx/tkMacOSXColor.h @@ -6,7 +6,7 @@ * colors in a GC are unsigned longs. These are meant to be used as indexes * into a table of XColors, where an XColor is declared in Xlib.h as: * typedef struct { - * unsigned long pixel; + * unsigned long pixel; * unsigned short red, green, blue; * char flags; * char pad; @@ -48,7 +48,7 @@ typedef struct xpixel_t { unsigned value: 24; /* Either RGB or an index into systemColorMap. */ unsigned colortype: 8; } xpixel; - + typedef union MacPixel_t { unsigned long ulong; xpixel pixel; @@ -64,11 +64,11 @@ enum macColormap { lightColormap, darkColormap, }; - + /* * In TkMacOSXColor.c a Tk hash table is constructed from the static data * below to map system color names to CGColors. - */ + */ typedef struct { const char *name; @@ -96,15 +96,15 @@ static SystemColorDatum systemColorData[] = { {"HighlightText", HIBrush, kThemeBrushBlack }, {"HighlightAlternate", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, {"PrimaryHighlightColor", HIBrush, kThemeBrushPrimaryHighlightColor }, -{"ButtonFace", HIBrush, kThemeBrushButtonFaceActive }, +{"ButtonFace", HIBrush, kThemeBrushButtonFaceActive }, {"SecondaryHighlightColor", HIBrush, kThemeBrushSecondaryHighlightColor }, -{"ButtonFrame", HIBrush, kThemeBrushButtonFrameActive }, +{"ButtonFrame", HIBrush, kThemeBrushButtonFrameActive }, {"AlternatePrimaryHighlightColor", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, -{"WindowBody", HIBrush, kThemeBrushDocumentWindowBackground }, +{"WindowBody", HIBrush, kThemeBrushDocumentWindowBackground }, {"SheetBackground", HIBrush, kThemeBrushSheetBackground }, {"MenuActive", HIBrush, kThemeBrushMenuBackgroundSelected }, {"Menu", HIBrush, kThemeBrushMenuBackground }, -{"DialogBackgroundInactive", HIBrush, kThemeBrushDialogBackgroundInactive }, +{"DialogBackgroundInactive", HIBrush, kThemeBrushDialogBackgroundInactive }, {"DialogBackgroundActive", HIBrush, kThemeBrushDialogBackgroundActive }, {"AlertBackgroundActive", HIBrush, kThemeBrushAlertBackgroundActive }, {"AlertBackgroundInactive", HIBrush, kThemeBrushAlertBackgroundInactive }, @@ -113,28 +113,28 @@ static SystemColorDatum systemColorData[] = { {"UtilityWindowBackgroundActive", HIBrush, kThemeBrushUtilityWindowBackgroundActive }, {"UtilityWindowBackgroundInactive", HIBrush, kThemeBrushUtilityWindowBackgroundInactive }, {"ListViewSortColumnBackground", HIBrush, kThemeBrushListViewSortColumnBackground }, -{"ListViewBackground", HIBrush, kThemeBrushListViewBackground }, +{"ListViewBackground", HIBrush, kThemeBrushListViewBackground }, {"IconLabelBackground", HIBrush, kThemeBrushIconLabelBackground }, -{"ListViewSeparator", HIBrush, kThemeBrushListViewSeparator }, +{"ListViewSeparator", HIBrush, kThemeBrushListViewSeparator }, {"ChasingArrows", HIBrush, kThemeBrushChasingArrows }, -{"DragHilite", HIBrush, kThemeBrushDragHilite }, -{"DocumentWindowBackground", HIBrush, kThemeBrushDocumentWindowBackground }, +{"DragHilite", HIBrush, kThemeBrushDragHilite }, +{"DocumentWindowBackground", HIBrush, kThemeBrushDocumentWindowBackground }, {"FinderWindowBackground", HIBrush, kThemeBrushFinderWindowBackground }, -{"ScrollBarDelimiterActive", HIBrush, kThemeBrushScrollBarDelimiterActive }, -{"ScrollBarDelimiterInactive", HIBrush, kThemeBrushScrollBarDelimiterInactive }, +{"ScrollBarDelimiterActive", HIBrush, kThemeBrushScrollBarDelimiterActive }, +{"ScrollBarDelimiterInactive", HIBrush, kThemeBrushScrollBarDelimiterInactive }, {"FocusHighlight", HIBrush, kThemeBrushFocusHighlight }, -{"PopupArrowActive", HIBrush, kThemeBrushPopupArrowActive }, -{"PopupArrowPressed", HIBrush, kThemeBrushPopupArrowPressed }, -{"PopupArrowInactive", HIBrush, kThemeBrushPopupArrowInactive }, -{"AppleGuideCoachmark", HIBrush, kThemeBrushAppleGuideCoachmark }, +{"PopupArrowActive", HIBrush, kThemeBrushPopupArrowActive }, +{"PopupArrowPressed", HIBrush, kThemeBrushPopupArrowPressed }, +{"PopupArrowInactive", HIBrush, kThemeBrushPopupArrowInactive }, +{"AppleGuideCoachmark", HIBrush, kThemeBrushAppleGuideCoachmark }, {"IconLabelBackgroundSelected", HIBrush, kThemeBrushIconLabelBackgroundSelected }, {"StaticAreaFill", HIBrush, kThemeBrushStaticAreaFill }, {"ActiveAreaFill", HIBrush, kThemeBrushActiveAreaFill }, {"ButtonFrameActive", HIBrush, kThemeBrushButtonFrameActive }, -{"ButtonFrameInactive", HIBrush, kThemeBrushButtonFrameInactive }, -{"ButtonFaceActive", HIBrush, kThemeBrushButtonFaceActive }, -{"ButtonFaceInactive", HIBrush, kThemeBrushButtonFaceInactive }, -{"ButtonFacePressed", HIBrush, kThemeBrushButtonFacePressed }, +{"ButtonFrameInactive", HIBrush, kThemeBrushButtonFrameInactive }, +{"ButtonFaceActive", HIBrush, kThemeBrushButtonFaceActive }, +{"ButtonFaceInactive", HIBrush, kThemeBrushButtonFaceInactive }, +{"ButtonFacePressed", HIBrush, kThemeBrushButtonFacePressed }, {"ButtonActiveDarkShadow", HIBrush, kThemeBrushButtonActiveDarkShadow }, {"ButtonActiveDarkHighlight", HIBrush, kThemeBrushButtonActiveDarkHighlight }, {"ButtonActiveLightShadow", HIBrush, kThemeBrushButtonActiveLightShadow }, @@ -163,10 +163,10 @@ static SystemColorDatum systemColorData[] = { {"ListViewEvenRowBackground", HIBrush, kThemeBrushListViewEvenRowBackground }, {"ListViewColumnDivider", HIBrush, kThemeBrushListViewColumnDivider }, -{"ButtonText", HIText, kThemeTextColorPushButtonActive }, -{"MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, -{"MenuDisabled", HIText, kThemeTextColorMenuItemDisabled }, -{"MenuText", HIText, kThemeTextColorMenuItemActive }, +{"ButtonText", HIText, kThemeTextColorPushButtonActive }, +{"MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, +{"MenuDisabled", HIText, kThemeTextColorMenuItemDisabled }, +{"MenuText", HIText, kThemeTextColorMenuItemActive }, {"BlackText", HIText, kThemeTextColorBlack }, {"DialogActiveText", HIText, kThemeTextColorDialogActive }, {"DialogInactiveText", HIText, kThemeTextColorDialogInactive }, @@ -192,8 +192,8 @@ static SystemColorDatum systemColorData[] = { {"ListViewText", HIText, kThemeTextColorListView }, {"DocumentWindowTitleActiveText", HIText, kThemeTextColorDocumentWindowTitleActive }, {"DocumentWindowTitleInactiveText", HIText, kThemeTextColorDocumentWindowTitleInactive }, -{"MovableModalWindowTitleActiveText", HIText, kThemeTextColorMovableModalWindowTitleActive }, -{"MovableModalWindowTitleInactiveText", HIText, kThemeTextColorMovableModalWindowTitleInactive }, +{"MovableModalWindowTitleActiveText", HIText, kThemeTextColorMovableModalWindowTitleActive }, +{"MovableModalWindowTitleInactiveText", HIText, kThemeTextColorMovableModalWindowTitleInactive }, {"UtilityWindowTitleActiveText", HIText, kThemeTextColorUtilityWindowTitleActive }, {"UtilityWindowTitleInactiveText", HIText, kThemeTextColorUtilityWindowTitleInactive }, {"PopupWindowTitleActiveText", HIText, kThemeTextColorPopupWindowTitleActive }, @@ -231,7 +231,7 @@ static SystemColorDatum systemColorData[] = { * Dynamic Colors */ -{"WindowBackgroundColor", ttkBackground, 0 }, +{"WindowBackgroundColor", ttkBackground, 0 }, {"WindowBackgroundColor1", ttkBackground, 1 }, {"WindowBackgroundColor2", ttkBackground, 2 }, {"WindowBackgroundColor3", ttkBackground, 3 }, diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index ceca8f8..9005d82 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -150,7 +150,7 @@ typedef union MacKeycode_t { keycode_v v; keycode_x x; } MacKeycode; - + /* * Macros used in tkMacOSXKeyboard.c and tkMacOSXKeyEvent.c. * Note that 0x7f is del and 0xF8FF is the Apple Logo character. diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index a58bab4..8b316fa 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -211,7 +211,7 @@ XMapWindow( * we handle this event immediately and then process the idle * events that it generates. */ - + Tk_HandleEvent(&event); while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {} } else { @@ -329,7 +329,7 @@ XUnmapWindow( * we handle this event immediately and then process the idle * events that it generates. */ - + Tk_HandleEvent(&event); while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {} } else { -- cgit v0.12