Tk Source Code

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

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

Overview
Comment:Improve the behavior and appearance of BevelButtons.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-0d63621b6c
Files: files | file ages | folders
SHA3-256: 523b9147c1676ae9acdaebf18b8dd3c66d007e9e9db05580348470e311eb042b
User & Date: culler 2019-03-17 19:41:04
Context
2019-03-17
20:40
Added a drawing procedure for dark BevelButtons. check-in: 520a121d user: culler tags: bug-0d63621b6c
19:41
Improve the behavior and appearance of BevelButtons. check-in: 523b9147 user: culler tags: bug-0d63621b6c
14:13
Fixed error in height computation for BevelButtons. check-in: a8b91a2d user: culler tags: bug-0d63621b6c
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to library/demos/toolbar.tcl.

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
## Set up the toolbar hull
set t [frame $w.toolbar]		;# Must be a frame!
ttk::separator $w.sep
ttk::frame $t.tearoff -cursor fleur
ttk::separator $t.tearoff.to -orient vertical
ttk::separator $t.tearoff.to2 -orient vertical
pack $t.tearoff.to -fill y -expand 1 -padx 2 -side left
pack $t.tearoff.to2 -fill y -expand 1 -side left
ttk::frame $t.contents
grid $t.tearoff $t.contents -sticky nsew
grid columnconfigure $t $t.contents -weight 1
grid columnconfigure $t.contents 1000 -weight 1

## Bindings so that the toolbar can be torn off and reattached
................................................................................
}

## Some content for the rest of the toplevel
text $w.txt -width 40 -height 10
interp alias {} doInsert {} $w.txt insert end	;# Make bindings easy to write

## Arrange contents
grid $t.button $t.check $t.menu $t.combo -in $t.contents -padx 2 -sticky ns
grid $t -sticky ew
grid $w.sep -sticky ew
grid $w.msg -sticky ew
grid $w.txt -sticky nsew
grid rowconfigure $w $w.txt -weight 1
grid columnconfigure $w $w.txt -weight 1

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
grid $btns -sticky ew






|







 







|










27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
## Set up the toolbar hull
set t [frame $w.toolbar]		;# Must be a frame!
ttk::separator $w.sep
ttk::frame $t.tearoff -cursor fleur
ttk::separator $t.tearoff.to -orient vertical
ttk::separator $t.tearoff.to2 -orient vertical
pack $t.tearoff.to -fill y -expand 1 -padx 4 -side left
pack $t.tearoff.to2 -fill y -expand 1 -side left
ttk::frame $t.contents
grid $t.tearoff $t.contents -sticky nsew
grid columnconfigure $t $t.contents -weight 1
grid columnconfigure $t.contents 1000 -weight 1

## Bindings so that the toolbar can be torn off and reattached
................................................................................
}

## Some content for the rest of the toplevel
text $w.txt -width 40 -height 10
interp alias {} doInsert {} $w.txt insert end	;# Make bindings easy to write

## Arrange contents
grid $t.button $t.check $t.menu $t.combo -in $t.contents -padx 2 -pady 4 -sticky ns
grid $t -sticky ew
grid $w.sep -sticky ew
grid $w.msg -sticky ew
grid $w.txt -sticky nsew
grid rowconfigure $w $w.txt -weight 1
grid columnconfigure $w $w.txt -weight 1

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
grid $btns -sticky ew

Changes to library/ttk/aquaTheme.tcl.

22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40



41
42
43
44
45
46
47
		background systemHighlight
		!focus systemHighlightSecondary} \
	    -selectforeground {
		background systemLabelColor
		!focus systemDialogActiveText}

	# Buttons
	ttk::style configure TButton -anchor center -width -6 \

	    -foreground systemControlTextColor
	ttk::style map TButton \
	    -foreground {
		disabled systemDisabledControlTextColor}
	ttk::style map TCheckbutton \
	    -foreground {
		disabled systemDisabledControlTextColor}
	ttk::style map TRadiobutton \
	    -foreground {
		disabled systemDisabledControlTextColor}
	ttk::style configure Toolbutton -padding 4




	# Workaround for #1100117:
	# Actually, on Aqua we probably shouldn't stipple images in
	# disabled buttons even if it did work...
	ttk::style configure . -stipple {}

	# Notebook






|
>










|
>
>
>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
		background systemHighlight
		!focus systemHighlightSecondary} \
	    -selectforeground {
		background systemLabelColor
		!focus systemDialogActiveText}

	# Buttons
#	ttk::style configure TButton -anchor center -width -6 \
	    ttk::style configure TButton -anchor center \
	    -foreground systemControlTextColor
	ttk::style map TButton \
	    -foreground {
		disabled systemDisabledControlTextColor}
	ttk::style map TCheckbutton \
	    -foreground {
		disabled systemDisabledControlTextColor}
	ttk::style map TRadiobutton \
	    -foreground {
		disabled systemDisabledControlTextColor}
	ttk::style map Toolbutton \
	    -foreground {
		disabled systemDisabledControlTextColor
	    }

	# Workaround for #1100117:
	# Actually, on Aqua we probably shouldn't stipple images in
	# disabled buttons even if it did work...
	ttk::style configure . -stipple {}

	# Notebook

Changes to macosx/ttkMacOSXTheme.c.

41
42
43
44
45
46
47




48
49
50
51
52
53
54
...
203
204
205
206
207
208
209
210
211
212
213
214
215



216

217
218
219
220
221
222
223
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
244
245
246
247
248
249
250




























251
252
253
254
255
256
257
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
467
468
469
470
471
472
473

474
475

476
477
478
479
480
481
482
483
...
522
523
524
525
526
527
528

529
530

531
532
533
534
535
536
537
538
...
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
631
632
633
634
635
636
637

638
639
640
641
642
643
644
645
646
647
648
649
650
...
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
...
695
696
697
698
699
700
701

702
703
704
705
706
707
708
...
755
756
757
758
759
760
761

762
763
764
765
766
767
768
769
770
771
772
773
774
775




776





777
778
779
780
781
782
783
...
813
814
815
816
817
818
819

820











821
822
823
824
825
826
827
....
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
....
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
    TkMacOSXDrawingContext dc; \
    if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;}
#define END_DRAWING \
    TkMacOSXRestoreDrawingContext(&dc); }

#define HIOrientation kHIThemeOrientationNormal
#define NoThemeMetric 0xFFFFFFFF





#ifdef __LP64__
#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum))
#else
#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
#endif /* __LP64__ */

................................................................................
    CGContextFillPath(context);
    CFRelease(path);
}

/*
 * NormalizeButtonBounds --
 *
 * Apple's Human Interface Guidelines only allow three specific heights for buttons:
 * Regular, small and mini. We always use the regular size.  However, Ttk may
 * provide an arbitrary bounding rectangle.  We always draw the button centered
 * vertically on the rectangle, and having the same width as the rectangle.
 * This function returns the actual bounding rectangle that will be used in
 * drawing the button.



 */


static CGRect NormalizeButtonBounds(
    SInt32 heightMetric,
    CGRect bounds)
{
    SInt32 height;
    if (heightMetric != NoThemeMetric) {
................................................................................
	ChkErr(GetThemeMetric, heightMetric, &height);
	bounds.origin.y += (bounds.size.height - height)/2;
	bounds.size.height = height;
    }
    return bounds;
}

/* SolidFillButtonFace --
 *
 *     Fill a rounded rectangle with a specified solid color.
 */

static void SolidFillButtonFace(
   CGContextRef context,
   CGRect bounds,
   CGFloat radius,
   NSColor *color)
{
    CGPathRef path;
    CGContextSetFillColorWithColor(context, color.CGColor);
................................................................................
    path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    CFRelease(path);
}





























#endif /* MAC_OS_X_VERSION_MIN_REQUIRED > 1080 */

#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
/*----------------------------------------------------------------------
 * +++ Drawing procedures for widgets in Apple's "Dark Mode" (10.14 and up).
 *
 *    The HIToolbox does not support Dark Mode, and apparently never will,
................................................................................
    CGContextReplacePathWithStrokedPath(context);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0);
    CGContextRestoreGState(context);
    CFRelease(topGradient);
}

/* GradientFillButtonFace --
 *
 *     Fill a rounded rectangle with a specified gradient.
 */

static void GradientFillButtonFace(
   CGContextRef context,
   CGRect bounds,
   CGFloat radius,
   CGFloat* colors,
   int numColors)
{
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    CGPathRef path;
    CGPoint end = {bounds.origin.x,
		   bounds.origin.y + bounds.size.height};
    CGGradientRef gradient = CGGradientCreateWithColorComponents(
	 deviceRGB.CGColorSpace, colors, NULL, numColors);
    path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0);
    CFRelease(path);
    CFRelease(gradient);
}

/*
 * DrawDarkButton --
 *
 *    This is a standalone drawing procedure which draws PushButtons and
 *    PopupButtons in the Dark Mode style.
 */

................................................................................

    /*
     * Fill the button face with the appropriate color.
     */

    bounds = CGRectInset(bounds, 1, 1);
    if (kind == kThemePushButton && (state & TTK_STATE_PRESSED)) {
	GradientFillButtonFace(context, bounds, 4,
				   darkSelectedGradient, 2);
    } else {
	if (state & TTK_STATE_DISABLED) {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
					  components: darkDisabledButtonFace
					       count: 4];
	} else {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
					  components: darkButtonFace
					       count: 4];
	}
	SolidFillButtonFace(context, bounds, 4, faceColor);
    }
	
    /*
     * If this is a popup, draw the arrow button.
     */

    if (kind == kThemePopupButton) {
................................................................................
	CGContextSaveGState(context);

	/*
	 * If the toplevel is front, paint the button blue.
	 */

	if (!(state & TTK_STATE_BACKGROUND)) {
	    GradientFillButtonFace(context, arrowBounds, 4,
				   darkSelectedGradient, 2);
	}

	/*
	 * Stroke the arrows.
	 */

................................................................................

    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 4);
    bounds = CGRectInset(bounds, 1, 1);
    if (!(state & TTK_STATE_BACKGROUND) &&
	!(state & TTK_STATE_DISABLED) &&
	((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) {

	GradientFillButtonFace(context, bounds, 3, darkSelectedGradient, 2);
    } else {

	GradientFillButtonFace(context, bounds, 3, darkInactiveGradient, 2);
    }
    HighlightButtonBorder(context, bounds);
    if ((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE)) {
	CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
	if (state & TTK_STATE_DISABLED) {
	    stroke = [NSColor disabledControlTextColor];
	} else {
................................................................................

    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 9);
    bounds = CGRectInset(bounds, 1, 1);
    if (!(state & TTK_STATE_BACKGROUND) &&
	!(state & TTK_STATE_DISABLED) &&
	((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) {

	GradientFillButtonFace(context, bounds, 8, darkSelectedGradient, 2);
    } else {

	GradientFillButtonFace(context, bounds, 8, darkInactiveGradient, 2);
    }
    HighlightButtonBorder(context, bounds);
    if ((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE)) {
	CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
	if (state & TTK_STATE_DISABLED) {
	    fill = [NSColor disabledControlTextColor];
	} else {
................................................................................
				     components: darkDisabledButtonFace
					  count: 4];
	} else {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
				     components: darkButtonFace
					  count: 4];
	}
	SolidFillButtonFace(context, bounds, 4, faceColor);

	/*
	 * Draw a separator line on the left side of the tab if it
	 * not first.
	 */

	if (!(state & TTK_STATE_FIRST_TAB)) {
................................................................................
	 * always drawn last.)
	 */

	if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) {
	    bounds.size.width += 1;
	}
	if (!(state & TTK_STATE_BACKGROUND)) {

	    GradientFillButtonFace(context, bounds, 4, darkSelectedGradient, 2);
	} else {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
				     components: darkInactiveSelectedTab
					  count: 4];
	    SolidFillButtonFace(context, bounds, 4, faceColor);
	}
	HighlightButtonBorder(context, bounds);
    }
}

/*
 * DrawDarkSeparator --
................................................................................
    ThemeMetric heightMetric;
} ThemeButtonParams;

static ThemeButtonParams
    PushButtonParams = { kThemePushButton, kThemeMetricPushButtonHeight },
    CheckBoxParams = { kThemeCheckBox, kThemeMetricCheckBoxHeight },
    RadioButtonParams = { kThemeRadioButton, kThemeMetricRadioButtonHeight },
    BevelButtonParams = { kThemeBevelButton, NoThemeMetric },
    PopupButtonParams = { kThemePopupButton, kThemeMetricPopupButtonHeight },
    DisclosureParams = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight },
    ListHeaderParams = { kThemeListHeaderButton, kThemeMetricListHeaderHeight };

static Ttk_StateTable ButtonValueTable[] = {
    { kThemeButtonMixed, TTK_STATE_ALTERNATE, 0 },
    { kThemeButtonOn, TTK_STATE_SELECTED, 0 },
................................................................................
/* Others: kThemeDisclosureRight, kThemeDisclosureDown, kThemeDisclosureLeft */
};

static Ttk_StateTable ButtonAdornmentTable[] = {
    { kThemeAdornmentDefault | kThemeAdornmentFocus,
	TTK_STATE_ALTERNATE | TTK_STATE_FOCUS, 0 },
    { kThemeAdornmentDefault, TTK_STATE_ALTERNATE, 0 },

    { kThemeAdornmentFocus, TTK_STATE_FOCUS, 0 },
    { kThemeAdornmentNone, 0, 0 }};

/*
 * computeButtonDrawInfo --
 *    Fill in an appearance manager HIThemeButtonDrawInfo record.
 */
................................................................................
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ThemeButtonParams *params = clientData;
    const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin);
    static const CGRect scratchBounds = {{0, 0}, {100, 100}};
    CGRect contentBounds;


    ButtonElementSizeNoPadding( clientData, elementRecord, tkwin,
    	widthPtr, heightPtr, paddingPtr);

    /*
     * To compute internal padding, query the appearance manager
     * for the content bounds of a dummy rectangle, then use
     * the difference as the padding.
     */

    ChkErr(HIThemeGetButtonContentBounds,
	&scratchBounds, &info, &contentBounds);

    paddingPtr->left = CGRectGetMinX(contentBounds);




    paddingPtr->right = CGRectGetMaxX(scratchBounds) - CGRectGetMaxX(contentBounds);





}

static void ButtonElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
{
    BEGIN_DRAWING(d)
................................................................................
	 *  inconsistent behavior.  We work around this by filling behind an
	 *  inactive PopupButton with a white color before asking HIToolbox to
	 *  draw it.  PopupButton.  For PushButtons, we simply draw them in the
	 *  active state.
	 */
	if (info.kind == kThemePopupButton && (state & TTK_STATE_BACKGROUND)) {
	    CGRect innerBounds = CGRectInset(bounds, 1, 1);

	    SolidFillButtonFace(dc.context, innerBounds, 4, [NSColor whiteColor]);











	}
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec ButtonElementSpec = {
................................................................................
	 					components: darkTrack
	 					     count: 4];
	if (orientation == TTK_ORIENT_HORIZONTAL) {
	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 2); 
	} else {
	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 2); 
	}
	SolidFillButtonFace(dc.context, bounds, 2, trackColor);
    }
#endif
    ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    END_DRAWING
}

static Ttk_ElementSpec TrackElementSpec = {
................................................................................
	 					components: darkTrack
	 					     count: 4];
	if (orientation == TTK_ORIENT_HORIZONTAL) {
	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 3); 
	} else {
	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1); 
	}
	SolidFillButtonFace(dc.context, bounds, 3, trackColor);
    }
#endif
    ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    END_DRAWING
}

static Ttk_ElementSpec PbarElementSpec = {






>
>
>
>







 







|
|
|
|
|
|
>
>
>

>







 







|




|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|











|







 







|







 







>
|

>
|







 







>
|

>
|







 







|







 







>
|




|







 







|







 







>







 







>













|
>
>
>
>
|
>
>
>
>
>







 







>
|
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
...
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
363
364
365
366
367
368
369



























370
371
372
373
374
375
376
...
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
...
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
...
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
...
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
...
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
...
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
....
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
....
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
    TkMacOSXDrawingContext dc; \
    if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;}
#define END_DRAWING \
    TkMacOSXRestoreDrawingContext(&dc); }

#define HIOrientation kHIThemeOrientationNormal
#define NoThemeMetric 0xFFFFFFFF
#define BEVEL_XPAD 6
#define BEVEL_YPAD 6
static Ttk_Padding BevelButtonMargins = {BEVEL_XPAD, BEVEL_YPAD,
					 BEVEL_XPAD, BEVEL_YPAD};

#ifdef __LP64__
#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum))
#else
#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
#endif /* __LP64__ */

................................................................................
    CGContextFillPath(context);
    CFRelease(path);
}

/*
 * NormalizeButtonBounds --
 *
 * Apple's Human Interface Guidelines only allow three specific heights for
 * most buttons: Regular, small and mini. We always use the regular size.
 * However, Ttk may provide an arbitrary bounding rectangle.  We always draw
 * the button centered vertically on the rectangle, and having the same width
 * as the rectangle.  This function returns the actual bounding rectangle that
 * will be used in drawing the button.
 * 
 * The BevelButton is allowed to have arbitrary size, and also has external
 * padding.  This is handled separately here. 
 */


static CGRect NormalizeButtonBounds(
    SInt32 heightMetric,
    CGRect bounds)
{
    SInt32 height;
    if (heightMetric != NoThemeMetric) {
................................................................................
	ChkErr(GetThemeMetric, heightMetric, &height);
	bounds.origin.y += (bounds.size.height - height)/2;
	bounds.size.height = height;
    }
    return bounds;
}

/* SolidFillRoundedRectangle --
 *
 *     Fill a rounded rectangle with a specified solid color.
 */

static void SolidFillRoundedRectangle(
   CGContextRef context,
   CGRect bounds,
   CGFloat radius,
   NSColor *color)
{
    CGPathRef path;
    CGContextSetFillColorWithColor(context, color.CGColor);
................................................................................
    path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    CFRelease(path);
}


/* GradientFillRoundedRectangle --
 *
 *     Fill a rounded rectangle with a specified gradient.
 */

static void GradientFillRoundedRectangle(
   CGContextRef context,
   CGRect bounds,
   CGFloat radius,
   CGFloat* colors,
   int numColors)
{
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    CGPathRef path;
    CGPoint end = {bounds.origin.x,
		   bounds.origin.y + bounds.size.height};
    CGGradientRef gradient = CGGradientCreateWithColorComponents(
	 deviceRGB.CGColorSpace, colors, NULL, numColors);
    path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0);
    CFRelease(path);
    CFRelease(gradient);
}

#endif /* MAC_OS_X_VERSION_MIN_REQUIRED > 1080 */

#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
/*----------------------------------------------------------------------
 * +++ Drawing procedures for widgets in Apple's "Dark Mode" (10.14 and up).
 *
 *    The HIToolbox does not support Dark Mode, and apparently never will,
................................................................................
    CGContextReplacePathWithStrokedPath(context);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0);
    CGContextRestoreGState(context);
    CFRelease(topGradient);
}




























/*
 * DrawDarkButton --
 *
 *    This is a standalone drawing procedure which draws PushButtons and
 *    PopupButtons in the Dark Mode style.
 */

................................................................................

    /*
     * Fill the button face with the appropriate color.
     */

    bounds = CGRectInset(bounds, 1, 1);
    if (kind == kThemePushButton && (state & TTK_STATE_PRESSED)) {
	GradientFillRoundedRectangle(context, bounds, 4,
				   darkSelectedGradient, 2);
    } else {
	if (state & TTK_STATE_DISABLED) {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
					  components: darkDisabledButtonFace
					       count: 4];
	} else {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
					  components: darkButtonFace
					       count: 4];
	}
	SolidFillRoundedRectangle(context, bounds, 4, faceColor);
    }
	
    /*
     * If this is a popup, draw the arrow button.
     */

    if (kind == kThemePopupButton) {
................................................................................
	CGContextSaveGState(context);

	/*
	 * If the toplevel is front, paint the button blue.
	 */

	if (!(state & TTK_STATE_BACKGROUND)) {
	    GradientFillRoundedRectangle(context, arrowBounds, 4,
				   darkSelectedGradient, 2);
	}

	/*
	 * Stroke the arrows.
	 */

................................................................................

    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 4);
    bounds = CGRectInset(bounds, 1, 1);
    if (!(state & TTK_STATE_BACKGROUND) &&
	!(state & TTK_STATE_DISABLED) &&
	((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) {
	GradientFillRoundedRectangle(context, bounds, 3,
				     darkSelectedGradient, 2);
    } else {
	GradientFillRoundedRectangle(context, bounds, 3,
				     darkInactiveGradient, 2);
    }
    HighlightButtonBorder(context, bounds);
    if ((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE)) {
	CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
	if (state & TTK_STATE_DISABLED) {
	    stroke = [NSColor disabledControlTextColor];
	} else {
................................................................................

    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 9);
    bounds = CGRectInset(bounds, 1, 1);
    if (!(state & TTK_STATE_BACKGROUND) &&
	!(state & TTK_STATE_DISABLED) &&
	((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE))) {
	GradientFillRoundedRectangle(context, bounds, 8,
				     darkSelectedGradient, 2);
    } else {
	GradientFillRoundedRectangle(context, bounds, 8,
				     darkInactiveGradient, 2);
    }
    HighlightButtonBorder(context, bounds);
    if ((state  & TTK_STATE_SELECTED) || (state & TTK_STATE_ALTERNATE)) {
	CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
	if (state & TTK_STATE_DISABLED) {
	    fill = [NSColor disabledControlTextColor];
	} else {
................................................................................
				     components: darkDisabledButtonFace
					  count: 4];
	} else {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
				     components: darkButtonFace
					  count: 4];
	}
	SolidFillRoundedRectangle(context, bounds, 4, faceColor);

	/*
	 * Draw a separator line on the left side of the tab if it
	 * not first.
	 */

	if (!(state & TTK_STATE_FIRST_TAB)) {
................................................................................
	 * always drawn last.)
	 */

	if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) {
	    bounds.size.width += 1;
	}
	if (!(state & TTK_STATE_BACKGROUND)) {
	    GradientFillRoundedRectangle(context, bounds, 4,
					 darkSelectedGradient, 2);
	} else {
	    faceColor = [NSColor colorWithColorSpace: deviceRGB
				     components: darkInactiveSelectedTab
					  count: 4];
	    SolidFillRoundedRectangle(context, bounds, 4, faceColor);
	}
	HighlightButtonBorder(context, bounds);
    }
}

/*
 * DrawDarkSeparator --
................................................................................
    ThemeMetric heightMetric;
} ThemeButtonParams;

static ThemeButtonParams
    PushButtonParams = { kThemePushButton, kThemeMetricPushButtonHeight },
    CheckBoxParams = { kThemeCheckBox, kThemeMetricCheckBoxHeight },
    RadioButtonParams = { kThemeRadioButton, kThemeMetricRadioButtonHeight },
    BevelButtonParams = { kThemeRoundedBevelButton, NoThemeMetric },
    PopupButtonParams = { kThemePopupButton, kThemeMetricPopupButtonHeight },
    DisclosureParams = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight },
    ListHeaderParams = { kThemeListHeaderButton, kThemeMetricListHeaderHeight };

static Ttk_StateTable ButtonValueTable[] = {
    { kThemeButtonMixed, TTK_STATE_ALTERNATE, 0 },
    { kThemeButtonOn, TTK_STATE_SELECTED, 0 },
................................................................................
/* Others: kThemeDisclosureRight, kThemeDisclosureDown, kThemeDisclosureLeft */
};

static Ttk_StateTable ButtonAdornmentTable[] = {
    { kThemeAdornmentDefault | kThemeAdornmentFocus,
	TTK_STATE_ALTERNATE | TTK_STATE_FOCUS, 0 },
    { kThemeAdornmentDefault, TTK_STATE_ALTERNATE, 0 },
    { kThemeAdornmentNone, TTK_STATE_ALTERNATE, 0 },
    { kThemeAdornmentFocus, TTK_STATE_FOCUS, 0 },
    { kThemeAdornmentNone, 0, 0 }};

/*
 * computeButtonDrawInfo --
 *    Fill in an appearance manager HIThemeButtonDrawInfo record.
 */
................................................................................
    void *clientData, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    ThemeButtonParams *params = clientData;
    const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin);
    static const CGRect scratchBounds = {{0, 0}, {100, 100}};
    CGRect contentBounds;
    int verticalPad;

    ButtonElementSizeNoPadding( clientData, elementRecord, tkwin,
    	widthPtr, heightPtr, paddingPtr);

    /*
     * To compute internal padding, query the appearance manager
     * for the content bounds of a dummy rectangle, then use
     * the difference as the padding.
     */

    ChkErr(HIThemeGetButtonContentBounds,
	&scratchBounds, &info, &contentBounds);

    CGRect backgroundBounds;
    ChkErr(HIThemeGetButtonBackgroundBounds,
	   &scratchBounds, &info, &backgroundBounds);

    paddingPtr->left = contentBounds.origin.x - backgroundBounds.origin.x;
    paddingPtr->right = CGRectGetMaxX(backgroundBounds) - CGRectGetMaxX(contentBounds);
    verticalPad = contentBounds.origin.y - backgroundBounds.origin.y;
    verticalPad += CGRectGetMaxY(backgroundBounds) - CGRectGetMaxY(contentBounds);
    paddingPtr->top = verticalPad /2;
    paddingPtr->bottom = verticalPad - paddingPtr->top;

}

static void ButtonElementDraw(
    void *clientData, void *elementRecord, Tk_Window tkwin,
    Drawable d, Ttk_Box b, Ttk_State state)
{
    BEGIN_DRAWING(d)
................................................................................
	 *  inconsistent behavior.  We work around this by filling behind an
	 *  inactive PopupButton with a white color before asking HIToolbox to
	 *  draw it.  PopupButton.  For PushButtons, we simply draw them in the
	 *  active state.
	 */
	if (info.kind == kThemePopupButton && (state & TTK_STATE_BACKGROUND)) {
	    CGRect innerBounds = CGRectInset(bounds, 1, 1);
	    NSColor *white = [NSColor whiteColor];
	    SolidFillRoundedRectangle(dc.context, innerBounds, 4, white);
	}

	/*
	 * A BevelButton with mixed value is drawn borderless, which does make
	 * much sense for us.
	 */
	
	if (info.kind == kThemeRoundedBevelButton &&
	    info.value ==  kThemeButtonMixed) {
	    info.value = kThemeButtonOff;
	    info.state = kThemeStateInactive;
	}
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec ButtonElementSpec = {
................................................................................
	 					components: darkTrack
	 					     count: 4];
	if (orientation == TTK_ORIENT_HORIZONTAL) {
	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 2); 
	} else {
	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 2); 
	}
	SolidFillRoundedRectangle(dc.context, bounds, 2, trackColor);
    }
#endif
    ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    END_DRAWING
}

static Ttk_ElementSpec TrackElementSpec = {
................................................................................
	 					components: darkTrack
	 					     count: 4];
	if (orientation == TTK_ORIENT_HORIZONTAL) {
	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 3); 
	} else {
	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1); 
	}
	SolidFillRoundedRectangle(dc.context, bounds, 3, trackColor);
    }
#endif
    ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
    END_DRAWING
}

static Ttk_ElementSpec PbarElementSpec = {