summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorculler <culler>2019-03-26 16:06:55 (GMT)
committerculler <culler>2019-03-26 16:06:55 (GMT)
commit7ffe9f76440019f4fea87c29f2b42a543066ea3b (patch)
treecbe816425380c59d32984b309919c949143be3cb /macosx
parent524655affdae491aad1119f37f59df0109de17e8 (diff)
downloadtk-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.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXColor.c45
-rw-r--r--macosx/ttkMacOSXTheme.c56
2 files changed, 81 insertions, 20 deletions
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);