Tk Source Code

Check-in [cf564e76]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Dealt with dark BevelButtons and progress bars.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-0d63621b6c
Files: files | file ages | folders
SHA3-256:cf564e76871ec867ed89b2d0c5a8bd14a9a19b9cb9ebf3c76959e35e0f6e43cb
User & Date: culler 2019-03-15 21:31:44
Context
2019-03-15
23:22
Small corrections. check-in: f1d3c394 user: culler tags: bug-0d63621b6c
21:31
Dealt with dark BevelButtons and progress bars. check-in: cf564e76 user: culler tags: bug-0d63621b6c
21:14
Fix some conditional compilation misconfiguration. check-in: f1f399c4 user: culler tags: bug-0d63621b6c
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to library/ttk/aquaTheme.tcl.

    34     34   	ttk::style map TCheckbutton \
    35     35   	    -foreground {
    36     36   		disabled systemDisabledControlTextColor}
    37     37   	ttk::style map TRadiobutton \
    38     38   	    -foreground {
    39     39   		disabled systemDisabledControlTextColor}
    40     40   	ttk::style configure Toolbutton -padding 4
    41         -#	ttk::style configure Toolbutton -padding 4 -foreground black
    42         -#	ttk::style map Toolbutton \
    43         -#	    -background {
    44         -#		background systemWindowBody}
    45     41   
    46     42   	# Workaround for #1100117:
    47     43   	# Actually, on Aqua we probably shouldn't stipple images in
    48     44   	# disabled buttons even if it did work...
    49     45   	ttk::style configure . -stipple {}
    50         -
    51     46   
    52     47   	# Notebook
    53     48   	ttk::style configure TNotebook -tabmargins {10 0} -tabposition n
    54     49   	ttk::style configure TNotebook -padding {18 8 18 17}
    55     50   	ttk::style configure TNotebook.Tab -padding {12 3 12 2}
    56     51   	ttk::style configure TNotebook.Tab -foreground white
    57     52   	ttk::style map TNotebook.Tab \

Changes to macosx/ttkMacOSXTheme.c.

     4      4    *	Tk theme engine for Mac OSX, using the Appearance Manager API.
     5      5    *
     6      6    * Copyright (c) 2004 Joe English
     7      7    * Copyright (c) 2005 Neil Madden
     8      8    * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net>
     9      9    * Copyright 2008-2009, Apple Inc.
    10     10    * Copyright 2009 Kevin Walzer/WordTech Communications LLC.
           11  + * Copyright 2019 Marc Culler
    11     12    *
    12     13    * See the file "license.terms" for information on usage and redistribution
    13     14    * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    14     15    *
    15     16    * See also:
    16     17    *
    17     18    * <URL: http://developer.apple.com/documentation/Carbon/Reference/
................................................................................
    39     40   #define BEGIN_DRAWING(d) { \
    40     41       TkMacOSXDrawingContext dc; \
    41     42       if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;}
    42     43   #define END_DRAWING \
    43     44       TkMacOSXRestoreDrawingContext(&dc); }
    44     45   
    45     46   #define HIOrientation kHIThemeOrientationNormal
           47  +#define NoThemeMetric 0xFFFFFFFF
    46     48   
    47     49   #ifdef __LP64__
    48     50   #define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum))
    49     51   #else
    50     52   #define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
    51     53   #endif /* __LP64__ */
    52     54   
................................................................................
   260    262    *  Colors and gradients used in Dark Mode.
   261    263    */
   262    264   
   263    265   static CGFloat darkButtonFace[4] = {112.0/255, 113.0/255, 115.0/255, 1.0};
   264    266   static CGFloat darkDisabledButtonFace[4] = {86.0/255, 87.0/255, 89.0/255, 1.0};
   265    267   static CGFloat darkInactiveSelectedTab[4] = {159.0/255, 160.0/255, 161.0/255, 1.0};
   266    268   static CGFloat darkTabSeparator[4] = {0.0, 0.0, 0.0, 0.25};
          269  +static CGFloat darkTrack[4] = {1.0, 1.0, 1.0, 0.25};
   267    270   static CGFloat darkTopGradient[8] = {1.0, 1.0, 1.0, 0.3,
   268    271   				     1.0, 1.0, 1.0, 0.0};
   269    272   static CGFloat darkBackgroundGradient[8] = {0.0, 0.0, 0.0, 0.1,
   270    273   					    0.0, 0.0, 0.0, 0.25};
   271    274   static CGFloat darkInactiveGradient[8] = {89.0/255, 90.0/255, 93.0/255, 1.0,
   272    275   				       119.0/255, 120.0/255, 122.0/255, 1.0};
   273    276   static CGFloat darkSelectedGradient[8] = {23.0/255, 111.0/255, 232.0/255, 1.0,
................................................................................
   657    660   
   658    661   #endif /* MAC_OS_X_VERSION_MIN_REQUIRED >101300 */
   659    662   
   660    663   /*----------------------------------------------------------------------
   661    664    * +++ Button element: Used for elements drawn with DrawThemeButton.
   662    665    */
   663    666   
   664         -#define NoThemeMetric 0xFFFFFFFF
   665    667   
   666    668   typedef struct {
   667    669       ThemeButtonKind kind;
   668    670       ThemeMetric heightMetric;
   669    671   } ThemeButtonParams;
   670    672   
   671    673   static ThemeButtonParams
................................................................................
   694    696   
   695    697   /*
   696    698    * computeButtonDrawInfo --
   697    699    *    Fill in an appearance manager HIThemeButtonDrawInfo record.
   698    700    */
   699    701   
   700    702   static inline HIThemeButtonDrawInfo computeButtonDrawInfo(
   701         -    ThemeButtonParams *params, Ttk_State state)
          703  +    ThemeButtonParams *params,
          704  +    Ttk_State state,
          705  +    Tk_Window tkwin)
   702    706   {
   703    707       /*
   704    708        *  See ButtonElementDraw for the explanation of why we always draw
   705         -     *  PushButtons in the active state.
          709  +     *  PushButtons in the active state.  The deprecated BezelButton can be
          710  +     *  faked to at least be usable in Dark Mode if it is always drawn as
          711  +     *  inactive.
   706    712        */
   707         -    
          713  +
          714  +    SInt32 HIThemeState;
          715  +    switch (params->kind) {
          716  +    case kThemePushButton:
          717  +	HIThemeState = kThemeStateActive;
          718  +	break;
          719  +    case kThemeBevelButton:
          720  +	if (TkMacOSXInDarkMode(tkwin)) {
          721  +	    HIThemeState = kThemeStateInactive;
          722  +	    break;
          723  +	}
          724  +    default:
          725  +	HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);
          726  +	break;
          727  +    }
          728  +	
   708    729       const HIThemeButtonDrawInfo info = {
   709    730   	.version = 0,
   710         -	.state = params && params->kind == kThemePushButton ?
   711         -	    kThemeStateActive : Ttk_StateTableLookup(ThemeStateTable, state),
          731  +	.state = HIThemeState,
   712    732   	.kind = params ? params->kind : 0,
   713    733   	.value = Ttk_StateTableLookup(ButtonValueTable, state),
   714    734   	.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state),
   715    735       };
   716    736       return info;
   717    737   }
   718    738   
................................................................................
   731    751   }
   732    752   
   733    753   static void ButtonElementSize(
   734    754       void *clientData, void *elementRecord, Tk_Window tkwin,
   735    755       int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
   736    756   {
   737    757       ThemeButtonParams *params = clientData;
   738         -    const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0);
          758  +    const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin);
   739    759       static const CGRect scratchBounds = {{0, 0}, {100, 100}};
   740    760       CGRect contentBounds;
   741    761   
   742    762       ButtonElementSizeNoPadding( clientData, elementRecord, tkwin,
   743    763       	widthPtr, heightPtr, paddingPtr);
   744    764   
   745    765       /*
................................................................................
   758    778   static void ButtonElementDraw(
   759    779       void *clientData, void *elementRecord, Tk_Window tkwin,
   760    780       Drawable d, Ttk_Box b, Ttk_State state)
   761    781   {
   762    782       BEGIN_DRAWING(d)
   763    783       ThemeButtonParams *params = clientData;
   764    784       CGRect bounds = BoxToRect(d, b);
   765         -    HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state);
          785  +    HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state, tkwin);
   766    786       bounds = NormalizeButtonBounds(params->heightMetric, bounds);
   767    787   
   768    788       if (TkMacOSXInDarkMode(tkwin)) {
   769    789   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
   770    790   	switch (info.kind) {
   771    791   	case kThemePushButton:
   772    792   	case kThemePopupButton:
................................................................................
   776    796   	    DrawDarkCheckBox(bounds, state, dc.context);
   777    797   	    break;
   778    798   	case kThemeRadioButton:
   779    799   	    DrawDarkRadioButton(bounds, state, dc.context);
   780    800   	    break;
   781    801   	default:
   782    802   	    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
          803  +	}
   783    804   #endif
   784    805       } else {
   785    806   	/*
   786    807   	 *  Apple's PushButton and PopupButton do not change their (white) fill
   787    808   	 *  color when the window is inactive although, except in 10.7 (Lion),
   788    809   	 *  the color of the arrow button on a PopupButton does change.  For
   789    810   	 *  some reason HITheme fills inactive buttons with a transparent color
................................................................................
  1184   1205   
  1185   1206   
  1186   1207   /*----------------------------------------------------------------------
  1187   1208    * +++ DrawThemeTrack-based elements --
  1188   1209    *    Progress bars and scales. (See also: <<NOTE-TRACKS>>)
  1189   1210    */
  1190   1211   
         1212  +/*
         1213  + * Apple does not change the appearance of a slider when the window
         1214  + * becomes inactive.  So we shouldn't either.
         1215  + */
         1216  +
  1191   1217   static Ttk_StateTable ThemeTrackEnableTable[] = {
  1192   1218       { kThemeTrackDisabled, TTK_STATE_DISABLED, 0 },
  1193         -    { kThemeTrackInactive, TTK_STATE_BACKGROUND, 0 },
         1219  +    { kThemeTrackActive, TTK_STATE_BACKGROUND, 0 },
  1194   1220       { kThemeTrackActive, 0, 0 }
  1195   1221       /* { kThemeTrackNothingToScroll, ?, ? }, */
  1196   1222   };
  1197   1223   
  1198   1224   typedef struct {	/* TrackElement client data */
  1199   1225       ThemeTrackKind	kind;
  1200   1226       SInt32		thicknessMetric;
................................................................................
  1259   1285   	.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state),
  1260   1286   	.trackInfo.progress.phase = 0,
  1261   1287       };
  1262   1288   
  1263   1289       if (info.kind == kThemeSlider) {
  1264   1290   	info.trackInfo.slider.pressState = state & TTK_STATE_PRESSED ?
  1265   1291   		kThemeThumbPressed : 0;
  1266         -	info.trackInfo.slider.thumbDir = kThemeThumbPlain;
         1292  +	if (state & TTK_STATE_ALTERNATE) {
         1293  +	    info.trackInfo.slider.thumbDir = kThemeThumbDownward;
         1294  +	} else {
         1295  +	    info.trackInfo.slider.thumbDir = kThemeThumbPlain;
         1296  +	}
  1267   1297       }
  1268   1298   
  1269   1299   
  1270   1300       BEGIN_DRAWING(d)
         1301  +#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
         1302  +    if (TkMacOSXInDarkMode(tkwin)) {
         1303  +	CGRect bounds = BoxToRect(d, b);
         1304  +	NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
         1305  +	NSColor *trackColor = [NSColor colorWithColorSpace: deviceRGB
         1306  +	 					components: darkTrack
         1307  +	 					     count: 4];
         1308  +	if (orientation == TTK_ORIENT_HORIZONTAL) {
         1309  +	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 3); 
         1310  +	} else {
         1311  +	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1); 
         1312  +	}
         1313  +	SolidFillButtonFace(dc.context, bounds, 3, trackColor);
         1314  +    }
         1315  +#endif
  1271   1316       ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
  1272   1317       END_DRAWING
  1273   1318   }
  1274   1319   
  1275   1320   static Ttk_ElementSpec TrackElementSpec = {
  1276   1321       TK_STYLE_VERSION_2,
  1277   1322       sizeof(TrackElement),
................................................................................
  1338   1383   static void PbarElementSize(
  1339   1384       void *clientData, void *elementRecord, Tk_Window tkwin,
  1340   1385       int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
  1341   1386   {
  1342   1387       SInt32 size = 24;	/* @@@ Check HIG for correct default */
  1343   1388   
  1344   1389       ChkErr(GetThemeMetric, kThemeMetricLargeProgressBarThickness, &size);
  1345         -    *widthPtr = *heightPtr = size;
         1390  +    //    *widthPtr = *heightPtr = size;
         1391  +    *heightPtr = size;
  1346   1392   }
  1347   1393   
  1348   1394   static void PbarElementDraw(
  1349   1395       void *clientData, void *elementRecord, Tk_Window tkwin,
  1350   1396       Drawable d, Ttk_Box b, Ttk_State state)
  1351   1397   {
  1352   1398       PbarElement *pbar = elementRecord;
................................................................................
  1371   1417   		(orientation == TTK_ORIENT_HORIZONTAL ?
  1372   1418   		kThemeTrackHorizontal : 0),
  1373   1419   	.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state),
  1374   1420   	.trackInfo.progress.phase = phase,
  1375   1421       };
  1376   1422   
  1377   1423       BEGIN_DRAWING(d)
         1424  +#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
         1425  +    if (TkMacOSXInDarkMode(tkwin)) {
         1426  +	CGRect bounds = BoxToRect(d, b);
         1427  +	NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
         1428  +	NSColor *trackColor = [NSColor colorWithColorSpace: deviceRGB
         1429  +	 					components: darkTrack
         1430  +	 					     count: 4];
         1431  +	if (orientation == TTK_ORIENT_HORIZONTAL) {
         1432  +	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 3); 
         1433  +	} else {
         1434  +	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1); 
         1435  +	}
         1436  +	SolidFillButtonFace(dc.context, bounds, 3, trackColor);
         1437  +    }
         1438  +#endif
  1378   1439       ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
  1379   1440       END_DRAWING
  1380   1441   }
  1381   1442   
  1382   1443   static Ttk_ElementSpec PbarElementSpec = {
  1383   1444       TK_STYLE_VERSION_2,
  1384   1445       sizeof(PbarElement),
................................................................................
  1818   1879   	&DisclosureElementSpec, &DisclosureParams);
  1819   1880       Ttk_RegisterElementSpec(themePtr, "Treeheading.cell",
  1820   1881   	&TreeHeaderElementSpec, &ListHeaderParams);
  1821   1882   
  1822   1883       Ttk_RegisterElementSpec(themePtr, "Notebook.tab", &TabElementSpec, 0);
  1823   1884       Ttk_RegisterElementSpec(themePtr, "Notebook.client", &PaneElementSpec, 0);
  1824   1885   
  1825         -    Ttk_RegisterElementSpec(themePtr, "Labelframe.border",&GroupElementSpec,0);
  1826         -    Ttk_RegisterElementSpec(themePtr, "Entry.field",&EntryElementSpec,0);
  1827         -    Ttk_RegisterElementSpec(themePtr, "Spinbox.field",&EntryElementSpec,0);
         1886  +    Ttk_RegisterElementSpec(themePtr, "Labelframe.border", &GroupElementSpec,0);
         1887  +    Ttk_RegisterElementSpec(themePtr, "Entry.field", &EntryElementSpec,0);
         1888  +    Ttk_RegisterElementSpec(themePtr, "Spinbox.field", &EntryElementSpec,0);
  1828   1889   
  1829         -    Ttk_RegisterElementSpec(themePtr, "separator",&SeparatorElementSpec,0);
  1830         -    Ttk_RegisterElementSpec(themePtr, "hseparator",&SeparatorElementSpec,0);
  1831         -    Ttk_RegisterElementSpec(themePtr, "vseparator",&SeparatorElementSpec,0);
         1890  +    Ttk_RegisterElementSpec(themePtr, "separator", &SeparatorElementSpec,0);
         1891  +    Ttk_RegisterElementSpec(themePtr, "hseparator", &SeparatorElementSpec,0);
         1892  +    Ttk_RegisterElementSpec(themePtr, "vseparator", &SeparatorElementSpec,0);
  1832   1893   
  1833         -    Ttk_RegisterElementSpec(themePtr, "sizegrip",&SizegripElementSpec,0);
         1894  +    Ttk_RegisterElementSpec(themePtr, "sizegrip", &SizegripElementSpec,0);
  1834   1895   
  1835   1896       /*
  1836   1897        * <<NOTE-TRACKS>>
  1837   1898        * The Progressbar widget adjusts the size of the pbar element.
  1838   1899        * In the Aqua theme, the appearance manager computes the bar geometry;
  1839   1900        * we do all the drawing in the ".track" element and leave the .pbar out.
  1840   1901        */
  1841   1902       Ttk_RegisterElementSpec(themePtr,"Scale.trough",
  1842   1903   	&TrackElementSpec, &ScaleData);
  1843         -    Ttk_RegisterElementSpec(themePtr,"Scale.slider",&SliderElementSpec,0);
         1904  +    Ttk_RegisterElementSpec(themePtr,"Scale.slider", &SliderElementSpec,0);
  1844   1905       Ttk_RegisterElementSpec(themePtr,"Progressbar.track", &PbarElementSpec, 0);
  1845   1906   
  1846   1907       /*
  1847   1908        * Layouts:
  1848   1909        */
  1849   1910       Ttk_RegisterLayouts(themePtr, LayoutTable);
  1850   1911