diff options
author | culler <culler> | 2019-03-26 16:06:55 (GMT) |
---|---|---|
committer | culler <culler> | 2019-03-26 16:06:55 (GMT) |
commit | 7ffe9f76440019f4fea87c29f2b42a543066ea3b (patch) | |
tree | cbe816425380c59d32984b309919c949143be3cb | |
parent | 524655affdae491aad1119f37f59df0109de17e8 (diff) | |
download | tk-7ffe9f76440019f4fea87c29f2b42a543066ea3b.zip tk-7ffe9f76440019f4fea87c29f2b42a543066ea3b.tar.gz tk-7ffe9f76440019f4fea87c29f2b42a543066ea3b.tar.bz2 |
Add a few more semantic colors to make ttk::Entry and ttk::Treeview work
in dark mode.
-rw-r--r-- | generic/ttk/ttkTheme.h | 6 | ||||
-rw-r--r-- | library/ttk/aquaTheme.tcl | 48 | ||||
-rw-r--r-- | macosx/tkMacOSXColor.c | 45 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 56 |
4 files changed, 115 insertions, 40 deletions
diff --git a/generic/ttk/ttkTheme.h b/generic/ttk/ttkTheme.h index 9251dea..cf0a07c 100644 --- a/generic/ttk/ttkTheme.h +++ b/generic/ttk/ttkTheme.h @@ -29,9 +29,13 @@ extern "C" { * +++ Defaults for element option specifications. */ #define DEFAULT_FONT "TkDefaultFont" +#ifdef MAC_OSX_TK +#define DEFAULT_BACKGROUND "systemTextBackgroundColor" +#define DEFAULT_FOREGROUND "systemTextColor" +#else #define DEFAULT_BACKGROUND "#d9d9d9" #define DEFAULT_FOREGROUND "black" - +#endif /*------------------------------------------------------------------------ * +++ Widget states. * Keep in sync with stateNames[] in tkstate.c. diff --git a/library/ttk/aquaTheme.tcl b/library/ttk/aquaTheme.tcl index e32d984..50fcd7a 100644 --- a/library/ttk/aquaTheme.tcl +++ b/library/ttk/aquaTheme.tcl @@ -25,7 +25,7 @@ namespace eval ttk::theme::aqua { background systemLabelColor !focus systemDialogActiveText} - # Buttons + # Button ttk::style configure TButton -anchor center -width -6\ -foreground systemControlTextColor ttk::style map TButton \ @@ -37,12 +37,22 @@ namespace eval ttk::theme::aqua { ttk::style map TRadiobutton \ -foreground { disabled systemDisabledControlTextColor} + ttk::style configure TMenubutton -anchor center -padding {2 0 0 2} ttk::style configure Toolbutton -anchor center ttk::style map Toolbutton \ -foreground { disabled systemDisabledControlTextColor } + # Entry + ttk::style configure TEntry \ + -foreground systemTextColor \ + -background systemTextBackgroundColor \ + -selectforeground systemSelectedTextColor + ttk::style map TEntry \ + -foreground { + disabled systemDisabledControlTextColor} + # Workaround for #1100117: # Actually, on Aqua we probably shouldn't stipple images in # disabled buttons even if it did work... @@ -56,39 +66,39 @@ namespace eval ttk::theme::aqua { ttk::style map TNotebook.Tab \ -foreground { {background !disabled !selected} systemControlTextColor - {background selected} black + {background selected} systemTextBackgroundColor disabled systemDisabledControlTextColor !selected systemControlTextColor} # Combobox: - # We do not have a drawing procedure for Dark Comboboxes. - # This fakes the color in Dark Mode by using the system - # background color for (light) inactive widgets, and uses a - # white background for active Comboboxes, even in Dark Mode. - ttk::style configure TCombobox -selectforeground black + ttk::style configure TCombobox -selectforeground black \ + -background systemTextBackgroundColor ttk::style map TCombobox \ -foreground { disabled systemDisabledControlTextColor focus black {} black - !active systemControlTextColor + !active systemTextColor } \ -selectbackground { !focus white + } # Treeview: - ttk::style configure Heading -font TkHeadingFont - ttk::style configure Treeview -rowheight 18 -background White \ - -foreground black - ttk::style map Treeview \ - -background { - disabled systemDialogBackgroundInactive - {selected background} systemHighlightSecondary - selected systemHighlight} \ - -foreground { - !active black - } + ttk::style configure Heading -font TkHeadingFont -foreground black + ttk::style configure Treeview -rowheight 18 \ + -fieldbackground systemTextBackgroundColor \ + -background systemTextBackgroundColor \ + -foreground systemTextColor + # ttk::style map Treeview \ + # -background { + # disabled systemDialogBackgroundInactive + # {selected background} systemHighlightSecondary + # selected systemHighlight} \ + # -foreground { + # !active black + # } # Enable animation for ttk::progressbar widget: ttk::style configure TProgressbar -period 100 -maxphase 255 diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 3ca813c..f0bcb7c 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -20,7 +20,7 @@ /* * 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 ttkForeground types are dynamic, meaning + * an XColor. The ttkBackground and semantic types are dynamic, meaning * that they change when dark mode is enabled on OSX 10.13 and later. */ @@ -32,7 +32,7 @@ enum colorType { 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.*/ - ttkForeground, /* The value can be used as a parameter.*/ + semantic, /* The value can be used as a parameter.*/ }; /* @@ -197,13 +197,16 @@ static const struct SystemColorMapEntry systemColorMap[] = { { "TtkBackground5", ttkBackground, 5 }, /* 171 */ { "TtkBackground6", ttkBackground, 6 }, /* 172 */ { "TtkBackground7", ttkBackground, 7 }, /* 173 */ - { "LabelColor", ttkForeground, 0 }, /* 174 */ - { "ControlTextColor", ttkForeground, 1 }, /* 175 */ - { "DisabledControlTextColor", ttkForeground, 2 }, /* 176 */ + { "TextColor", semantic, 0 }, /* 174 */ + { "SelectedTextColor", semantic, 1 }, /* 175 */ + { "LabelColor", semantic, 2 }, /* 176 */ + { "ControlTextColor", semantic, 3 }, /* 177 */ + { "DisabledControlTextColor", semantic, 4 }, /* 178 */ + { "TextBackgroundColor", semantic, 5 }, /* 179 */ { NULL, 0, 0 } }; #define FIRST_SEMANTIC_COLOR 166 -#define MAX_PIXELCODE 176 +#define MAX_PIXELCODE 179 /* *---------------------------------------------------------------------- @@ -260,7 +263,7 @@ SetCGColorComponents( CGColorRef *c) { OSStatus err = noErr; - NSColor *bgColor, *fgColor; + NSColor *bgColor, *color; CGFloat rgba[4] = {0, 0, 0, 1}; static CGColorSpaceRef deviceRGBSpace = NULL; if (!deviceRGBSpace) { @@ -284,29 +287,45 @@ SetCGColorComponents( rgba[i] -= entry.value*(8.0/255.0); } break; - case ttkForeground: + case semantic: switch (entry.value) { + case 0: + color = [[NSColor textColor] colorUsingColorSpace: + [NSColorSpace deviceRGBColorSpace]]; + break; case 1: - fgColor = [[NSColor controlTextColor] colorUsingColorSpace: + color = [[NSColor selectedTextColor] colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; break; case 2: - fgColor = [[NSColor disabledControlTextColor] colorUsingColorSpace: + color = [[NSColor labelColor] colorUsingColorSpace: + [NSColorSpace deviceRGBColorSpace]]; + break; + case 3: + color = [[NSColor controlTextColor] colorUsingColorSpace: + [NSColorSpace deviceRGBColorSpace]]; + break; + case 4: + color = [[NSColor disabledControlTextColor] colorUsingColorSpace: + [NSColorSpace deviceRGBColorSpace]]; + break; + case 5: + color = [[NSColor textBackgroundColor] colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; break; default: if ([NSApp macMinorVersion] < 10) { - fgColor = [[NSColor textColor] colorUsingColorSpace: + color = [[NSColor textColor] colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; } else { #if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 - fgColor = [[NSColor labelColor] colorUsingColorSpace: + color = [[NSColor labelColor] colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; #endif break; } } - [fgColor getComponents: rgba]; + [color getComponents: rgba]; break; case clearColor: rgba[3] = 0.0; diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index d136b99..6d6e90c 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -1200,7 +1200,7 @@ static void EntryElementDraw( XFillRectangle(Tk_Display(tkwin), d, Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC), - inner.x,inner.y, inner.width, inner.height); + inner.x, inner.y, inner.width, inner.height); BEGIN_DRAWING(d) ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation); @@ -1268,9 +1268,9 @@ static void ComboboxElementDraw( bounds.size.height += 1; } else if ((state & TTK_STATE_BACKGROUND) && !(state & TTK_STATE_DISABLED)) { + NSColor *background = [NSColor textBackgroundColor]; CGRect innerBounds = CGRectInset(bounds, 1, 2); - NSColor *white = [NSColor whiteColor]; - SolidFillRoundedRectangle(dc.context, innerBounds, 4, white); + SolidFillRoundedRectangle(dc.context, innerBounds, 4, background); } bounds.origin.y += 1; ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); @@ -1807,6 +1807,41 @@ static Ttk_ElementSpec ToolbarBackgroundElementSpec = { }; /*---------------------------------------------------------------------- + * +++ Field element: + * Used for the Treeview widget. This is like the BackgroundElement + * except that the fieldbackground color is configureable. + */ + +typedef struct { + Tcl_Obj *backgroundObj; +} FieldElement; + +static Ttk_ElementOptionSpec FieldElementOptions[] = { + { "-fieldbackground", TK_OPTION_BORDER, + Tk_Offset(FieldElement, backgroundObj), "white" }, + { NULL, 0, 0, NULL } +}; + +static void FieldElementDraw( + void *clientData, void *elementRecord, Tk_Window tkwin, + Drawable d, Ttk_Box b, Ttk_State state) +{ + FieldElement *e = elementRecord; + Tk_3DBorder backgroundPtr = Tk_Get3DBorderFromObj(tkwin,e->backgroundObj); + XFillRectangle(Tk_Display(tkwin), d, + Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC), + b.x, b.y, b.width, b.height); +} + +static Ttk_ElementSpec FieldElementSpec = { + TK_STYLE_VERSION_2, + sizeof(FieldElement), + FieldElementOptions, + TtkNullElementSize, + FieldElementDraw +}; + +/*---------------------------------------------------------------------- * +++ Treeview header * Redefine the header to use a kThemeListHeaderButton. */ @@ -1851,7 +1886,7 @@ static Ttk_ElementSpec TreeHeaderElementSpec = { TK_STYLE_VERSION_2, sizeof(NullElement), TtkNullElementOptions, - ButtonElementMinSize, + ButtonElementSize, TreeHeaderElementDraw }; @@ -1938,7 +1973,7 @@ TTK_LAYOUT("TMenubutton", TTK_LAYOUT("TCombobox", TTK_GROUP("Combobox.button", TTK_FILL_BOTH, TTK_GROUP("Combobox.padding", TTK_FILL_BOTH, - TTK_NODE("Combobox.textarea", TTK_FILL_X)))) + TTK_NODE("Combobox.textarea", TTK_FILL_BOTH)))) /* Notebook tabs -- no focus ring */ TTK_LAYOUT("Tab", @@ -1955,11 +1990,17 @@ TTK_LAYOUT("TSpinbox", TTK_LAYOUT("TProgressbar", TTK_NODE("Progressbar.track", TTK_EXPAND|TTK_FILL_BOTH)) +/* Treeview -- no border. */ +TTK_LAYOUT("Treeview", + TTK_GROUP("Treeview.field", TTK_FILL_BOTH, + TTK_GROUP("Treeview.padding", TTK_FILL_BOTH, + TTK_NODE("Treeview.treearea", TTK_FILL_BOTH)))) + /* Tree heading -- no border, fixed height */ TTK_LAYOUT("Heading", - TTK_NODE("Treeheading.cell", TTK_FILL_X) + TTK_NODE("Treeheading.cell", TTK_FILL_BOTH) TTK_NODE("Treeheading.image", TTK_PACK_RIGHT) - TTK_NODE("Treeheading.text", 0)) + TTK_NODE("Treeheading.text", TTK_PACK_TOP)) /* Tree items -- omit focus ring */ TTK_LAYOUT("Item", @@ -1987,6 +2028,7 @@ static int AquaTheme_Init(Tcl_Interp *interp) */ Ttk_RegisterElementSpec(themePtr, "background", &BackgroundElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "fill", &FillElementSpec, 0); + Ttk_RegisterElementSpec(themePtr, "field", &FieldElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Toolbar.background", &ToolbarBackgroundElementSpec, 0); |