diff options
author | culler <culler> | 2019-04-04 17:02:00 (GMT) |
---|---|---|
committer | culler <culler> | 2019-04-04 17:02:00 (GMT) |
commit | 04bf6f37b10cf10187fa12370fa5ef2daccb6b15 (patch) | |
tree | 3e565ac0aac80df355d18ee2ec4cddca39d3ba45 | |
parent | 91172dfcd45a3cf4a60fcd083f9e96202b2adefb (diff) | |
download | tk-04bf6f37b10cf10187fa12370fa5ef2daccb6b15.zip tk-04bf6f37b10cf10187fa12370fa5ef2daccb6b15.tar.gz tk-04bf6f37b10cf10187fa12370fa5ef2daccb6b15.tar.bz2 |
Rework how contrasting backgrounds are handled.
-rw-r--r-- | generic/tk.h | 11 | ||||
-rw-r--r-- | generic/tkGeometry.c | 4 | ||||
-rw-r--r-- | generic/tkInt.h | 5 | ||||
-rw-r--r-- | generic/tkWindow.c | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXInt.h | 12 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 101 |
6 files changed, 74 insertions, 61 deletions
diff --git a/generic/tk.h b/generic/tk.h index 2162346..966a453 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -761,7 +761,6 @@ typedef XActivateDeactivateEvent XDeactivateEvent; #define Tk_MinReqHeight(tkwin) (((Tk_FakeWin *) (tkwin))->minReqHeight) #define Tk_Parent(tkwin) (((Tk_FakeWin *) (tkwin))->parentPtr) #define Tk_Colormap(tkwin) (((Tk_FakeWin *) (tkwin))->atts.colormap) -#define Tk_GeomMaster(tkwin) (((Tk_FakeWin *) (tkwin))->geomMasterPtr) /* * The structure below is needed by the macros above so that they can access @@ -804,13 +803,13 @@ typedef struct Tk_FakeWin { char *dummy14; /* geomMgrPtr */ ClientData dummy15; /* geomData */ char *dummy16; /* geomMgrName */ - Tk_Window geomMasterPtr; + Tk_Window dummy17; /* maintainerPtr */ int reqWidth, reqHeight; int internalBorderLeft; - char *dummy17; /* wmInfoPtr */ - char *dummy18; /* classProcPtr */ - ClientData dummy19; /* instanceData */ - char *dummy20; /* privatePtr */ + char *dummy18; /* wmInfoPtr */ + char *dummy19; /* classProcPtr */ + ClientData dummy20; /* instanceData */ + char *dummy21; /* privatePtr */ int internalBorderRight; int internalBorderTop; int internalBorderBottom; diff --git a/generic/tkGeometry.c b/generic/tkGeometry.c index f65dc84..11db8e8 100644 --- a/generic/tkGeometry.c +++ b/generic/tkGeometry.c @@ -425,7 +425,7 @@ Tk_MaintainGeometry( Tk_Window ancestor, parent; TkDisplay *dispPtr = ((TkWindow *) master)->dispPtr; - Tk_GeomMaster(slave) = master; + ((TkWindow *)slave)->maintainerPtr = (TkWindow *)master; if (master == Tk_Parent(slave)) { /* @@ -572,7 +572,7 @@ Tk_UnmaintainGeometry( Tk_Window ancestor; TkDisplay *dispPtr = ((TkWindow *) slave)->dispPtr; - Tk_GeomMaster(slave) = NULL; + ((TkWindow *)slave)->maintainerPtr = NULL; if (master == Tk_Parent(slave)) { /* diff --git a/generic/tkInt.h b/generic/tkInt.h index c50a75c..2020486 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -323,6 +323,9 @@ typedef struct TkDisplay { * by that master. */ int geomInit; +#define Tk_GetGeomMaster(tkwin) (((TkWindow *)tkwin)->maintainerPtr != NULL ? \ + ((TkWindow *)tkwin)->maintainerPtr : ((TkWindow *)tkwin)->parentPtr) + /* * Information used by tkGet.c only: */ @@ -770,7 +773,7 @@ typedef struct TkWindow { * window. */ ClientData geomData; /* Argument for geometry manager functions. */ char *geomMgrName; /* Records the name of the geometry manager. */ - struct TkWindow *geomMasterPtr; + struct TkWindow *maintainerPtr; /* The master assigned by Tk_MaintainGeometry.*/ int reqWidth, reqHeight; /* Arguments from last call to * Tk_GeometryRequest, or 0's if diff --git a/generic/tkWindow.c b/generic/tkWindow.c index 04c7ea2..917d3bd 100644 --- a/generic/tkWindow.c +++ b/generic/tkWindow.c @@ -665,7 +665,7 @@ TkAllocWindow( winPtr->geomMgrPtr = NULL; winPtr->geomData = NULL; winPtr->geomMgrName = NULL; - winPtr->geomMasterPtr = NULL; + winPtr->maintainerPtr = NULL; winPtr->reqWidth = winPtr->reqHeight = 1; winPtr->internalBorderLeft = 0; winPtr->wmInfoPtr = NULL; diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index ce79498..22d7d2c 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -71,6 +71,7 @@ struct TkWindowPrivate { * gone. */ struct TkWindowPrivate *toplevel; /* Pointer to the toplevel datastruct. */ + CGFloat fillRGBA[4]; /* Background used by the ttk FillElement */ int flags; /* Various state see defines below. */ }; typedef struct TkWindowPrivate MacDrawable; @@ -86,7 +87,7 @@ typedef struct TkWindowPrivate MacDrawable; #define TK_IS_PIXMAP 0x10 #define TK_IS_BW_PIXMAP 0x20 #define TK_DO_NOT_DRAW 0x40 -#define TTK_HAS_DARKER_BG 0x80 +#define TTK_HAS_CONTRASTING_BG 0x80 /* * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags @@ -211,3 +212,12 @@ MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin); #include "tkIntPlatDecls.h" #endif /* _TKMACINT */ + +/* + * Local Variables: + * mode: objc + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index 99ec71b..94c074f 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -144,59 +144,61 @@ static CGRect NormalizeButtonBounds( static CGFloat windowBackground[4] = {235.0/255, 235.0/255, 235.0/255, 1.0}; /* - * GetBoxColor -- + * GetBackgroundColor -- * - * Compute a contrasting box color, based on nesting depth, and save the - * RGBA components in an array. Used by the Fill and Background elements. + * Fills the array rgba with the color coordinates for a background color. + * Start with the background color of a window's geometry master, or the + * standard ttk window background if not. If the contrast parameter is nonzero + * modify this color to be darker, for the aqua appearance, or lighter for the + * DarkAqua appearance. This is used by the Fill and Background elements. */ -static int GetBoxColor( +static void GetBackgroundColor( CGContextRef context, Tk_Window tkwin, - int depth, - CGFloat *fill) + int contrast, + CGFloat *rgba) { - NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; - if ([NSApp macMinorVersion] > 13) { - NSColor *windowColor = [[NSColor windowBackgroundColor] - colorUsingColorSpace: deviceRGB]; - [windowColor getComponents: fill]; - } else { - for (int i = 0; i < 4; i++) { - fill[i] = windowBackground[i]; + TkWindow *winPtr = (TkWindow *)tkwin; + TkWindow *masterPtr = (TkWindow *)Tk_GetGeomMaster(tkwin); + while (masterPtr != NULL) { + if (masterPtr->privatePtr->flags & TTK_HAS_CONTRASTING_BG) { + break; } + masterPtr = (TkWindow *)Tk_GetGeomMaster(masterPtr); } - int isDark = (fill[0] + fill[1] + fill[2] < 1.5); - - /* - * Compute the nesting depth of the widget. - */ - - for (TkWindow *masterPtr = (TkWindow *)Tk_GeomMaster(tkwin); masterPtr != NULL; - masterPtr = (TkWindow *)Tk_GeomMaster(masterPtr)) { - if (masterPtr->privatePtr && - (masterPtr->privatePtr->flags & TTK_HAS_DARKER_BG)) { - depth++; + if (masterPtr) { + for (int i = 0; i < 4; i++) { + rgba[i] = masterPtr->privatePtr->fillRGBA[i]; } - if (depth > 7) { - break; + } else { + if ([NSApp macMinorVersion] > 13) { + NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; + NSColor *windowColor = [[NSColor windowBackgroundColor] + colorUsingColorSpace: deviceRGB]; + [windowColor getComponents: rgba]; + } else { + for (int i = 0; i < 4; i++) { + rgba[i] = windowBackground[i]; + } } } - - /* - * Increase the contrast by one step for each level of nesting. - */ - - if (isDark) { - for (int i=0; i<3; i++) { - fill[i] += (1.0 + depth*7.0)/255.0; + if (contrast) { + int isDark = (rgba[0] + rgba[1] + rgba[2] < 1.5); + if (isDark) { + for (int i=0; i<3; i++) { + rgba[i] += 8.0/255.0; + } + } else { + for (int i=0; i<3; i++) { + rgba[i] -= 8.0/255.0; + } } - } else { - for (int i=0; i<3; i++) { - fill[i] -= (depth*8.0)/255.0; + winPtr->privatePtr->flags |= TTK_HAS_CONTRASTING_BG; + for (int i = 0; i < 4; i++) { + winPtr->privatePtr->fillRGBA[i] = rgba[i]; } } - return depth; } /* @@ -216,7 +218,7 @@ static void DrawGroupBox( NSColor *borderColor, *bgColor; static CGFloat border[4] = {1.0, 1.0, 1.0, 0.25}; CGFloat fill[4]; - GetBoxColor(context, tkwin, 1, fill); + GetBackgroundColor(context, tkwin, 1, fill); bgColor = [NSColor colorWithColorSpace: deviceRGB components: fill count: 4]; CGContextSetFillColorSpace(context, deviceRGB.CGColorSpace); @@ -816,6 +818,10 @@ static void DrawDarkSeparator( * +++ Button element: Used for elements drawn with DrawThemeButton. */ +/* + * When Ttk draws the various types of buttons, a pointer to one of these + * is passed as the clientData. + */ typedef struct { ThemeButtonKind kind; @@ -1174,9 +1180,6 @@ static void PaneElementDraw( #endif END_DRAWING [TkMacOSXDrawableView(macWin) setNeedsDisplay:YES]; - if (macWin != NULL) { - macWin->flags |= TTK_HAS_DARKER_BG; - } } static Ttk_ElementSpec PaneElementSpec = { @@ -1209,7 +1212,6 @@ static void GroupElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - TkWindow *winPtr = (TkWindow *)tkwin; CGRect bounds = BoxToRect(d, b); BEGIN_DRAWING(d) @@ -1224,9 +1226,6 @@ static void GroupElementDraw( ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation); #endif END_DRAWING - if (winPtr->privatePtr != NULL) { - winPtr->privatePtr->flags |= TTK_HAS_DARKER_BG; - } } static Ttk_ElementSpec GroupElementSpec = { @@ -2112,26 +2111,28 @@ static void FillElementDraw( Drawable d, Ttk_Box b, Ttk_State state) { CGRect bounds = BoxToRect(d, b); - BEGIN_DRAWING(d) #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080 NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *bgColor; CGFloat fill[4]; - GetBoxColor(dc.context, tkwin, 0, fill); + BEGIN_DRAWING(d) + GetBackgroundColor(dc.context, tkwin, 0, fill); bgColor = [NSColor colorWithColorSpace: deviceRGB components: fill count: 4]; CGContextSetFillColorSpace(dc.context, deviceRGB.CGColorSpace); CGContextSetFillColorWithColor(dc.context, bgColor.CGColor); CGContextFillRect(dc.context, bounds); + END_DRAWING #else ThemeBrush brush = (state & TTK_STATE_BACKGROUND) ? kThemeBrushModelessDialogBackgroundInactive : kThemeBrushModelessDialogBackgroundActive; + BEGIN_DRAWING(d) ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation); //QDSetPatternOrigin(PatternOrigin(tkwin, d)); CGContextFillRect(dc.context, bounds); -#endif END_DRAWING +#endif } static void BackgroundElementDraw( |