Tk Source Code

Check-in [ccb69d7c]
Login

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

Overview
Comment:Added a drawing procedure for Spinboxes in Dark Mode.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | bug-0d63621b6c
Files: files | file ages | folders
SHA3-256: ccb69d7c0f8cbfe2b79c94debcd8080a26341bf218f5273dd96ed465f1ddc00e
User & Date: culler 2019-03-29 17:24:33.266
Context
2019-03-29
17:37
Added a comment. check-in: cc87e3a3 user: culler tags: bug-0d63621b6c
17:24
Added a drawing procedure for Spinboxes in Dark Mode. check-in: ccb69d7c user: culler tags: bug-0d63621b6c
14:46
Make the ttk::spinbutton text field work correctly in Dark Mode. check-in: 7c7664da user: culler tags: bug-0d63621b6c
Changes
Unified Diff Ignore Whitespace Patch
Changes to library/ttk/aquaTheme.tcl.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
		!focus systemTextBackgroundColor
		focus systemSelectedTextBackgroundColor
	    }

	# Spinbox
	ttk::style configure TSpinbox \
	    -foreground systemTextColor \
	    -background systemTransparent \
	    -selectforeground systemSelectedTextColor \
	    -selectbackground systemSelectedTextBackgroundColor
	ttk::style map TSpinbox \
	    -foreground {
		disabled systemDisabledControlTextColor
	    } \
	    -selectforeground {







|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
		!focus systemTextBackgroundColor
		focus systemSelectedTextBackgroundColor
	    }

	# Spinbox
	ttk::style configure TSpinbox \
	    -foreground systemTextColor \
	    -background systemTextBackgroundColor \
	    -selectforeground systemSelectedTextColor \
	    -selectbackground systemSelectedTextBackgroundColor
	ttk::style map TSpinbox \
	    -foreground {
		disabled systemDisabledControlTextColor
	    } \
	    -selectforeground {
Changes to macosx/ttkMacOSXTheme.c.
371
372
373
374
375
376
377

378
379

380
381
382
383
384
385
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
413
414
415
    CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0);
    CGContextRestoreGState(context);
    CFRelease(topGradient);
}


static void DrawUpDownArrows(

    CGRect bounds,
    CGContextRef context)

{
    CGFloat x, y;
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + 5;
    y = bounds.origin.y + trunc(bounds.size.height/2);
    CGContextBeginPath(context);
    CGPoint bottomArrow[3] = {{x, y+2}, {x+3.5, y+5.5}, {x+7, y+2}};
    CGContextAddLines(context, bottomArrow, 3);
    CGPoint topArrow[3] = {{x, y-2}, {x+3.5, y-5.5}, {x+7, y-2}};
    CGContextAddLines(context, topArrow, 3);
    CGContextStrokePath(context);
    CGContextRestoreGState(context);
}

static void DrawDownArrow(

    CGRect bounds,
    CGContextRef context)

{
    CGFloat x, y;
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + 5;
    y = bounds.origin.y + trunc(bounds.size.height/2);
    CGContextBeginPath(context);
    CGPoint bottomArrow[3] = {{x, y-3}, {x+3.5, y+3}, {x+7, y-3}};
    CGContextAddLines(context, bottomArrow, 3);
    CGContextStrokePath(context);
    CGContextRestoreGState(context);
}

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







>

|
>




|


|

|


<



>

|
>




|


|


<







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
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
413
414
415
416
417
    CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0);
    CGContextRestoreGState(context);
    CFRelease(topGradient);
}


static void DrawUpDownArrows(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size)
{
    CGFloat x, y;
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height/2);
    CGContextBeginPath(context);
    CGPoint bottomArrow[3] = {{x, y+2}, {x+size/2, y+2+size/2}, {x+size, y+2}};
    CGContextAddLines(context, bottomArrow, 3);
    CGPoint topArrow[3] = {{x, y-2}, {x+size/2, y-2-size/2}, {x+size, y-2}};
    CGContextAddLines(context, topArrow, 3);
    CGContextStrokePath(context);

}

static void DrawDownArrow(
    CGContextRef context,
    CGRect bounds,
    CGFloat inset,
    CGFloat size)
{
    CGFloat x, y;
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextSetLineWidth(context, 1.5);
    x = bounds.origin.x + inset;
    y = bounds.origin.y + trunc(bounds.size.height/2);
    CGContextBeginPath(context);
    CGPoint bottomArrow[3] = {{x, y-size/2}, {x+size/2, y+size/2}, {x+size, y-size/2}};
    CGContextAddLines(context, bottomArrow, 3);
    CGContextStrokePath(context);

}

/*
 * DrawDarkButton --
 *
 *    This is a standalone drawing procedure which draws PushButtons and
 *    PopupButtons in the Dark Mode style.
470
471
472
473
474
475
476
477
478
479
480
481
482
























































483
484
485
486
487
488
489
	 */

	if (!(state & TTK_STATE_BACKGROUND)) {
	    GradientFillRoundedRectangle(context, arrowBounds, 4,
				   darkSelectedGradient, 2);
	}
	if (kind == kThemePopupButton) {
	    DrawUpDownArrows(arrowBounds, context);
	} else {
	    DrawDownArrow(arrowBounds, context);
	}
    }

























































    HighlightButtonBorder(context, bounds);
}

/*
 * DrawDarkBevelButton --
 *
 *    This is a standalone drawing procedure which draws







|

|



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







472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
	 */

	if (!(state & TTK_STATE_BACKGROUND)) {
	    GradientFillRoundedRectangle(context, arrowBounds, 4,
				   darkSelectedGradient, 2);
	}
	if (kind == kThemePopupButton) {
	    DrawUpDownArrows(context, arrowBounds, 5, 7);
	} else {
	    DrawDownArrow(context, arrowBounds, 5, 7);
	}
    }

    HighlightButtonBorder(context, bounds);
}

/*
 * DrawDarkIncDecButton --
 *
 *    This is a standalone drawing procedure which draws an IncDecButton
 *    (as used in a Spinbox) in the Dark Mode style.
 */

static void DrawDarkIncDecButton(
    CGRect bounds,
    ThemeDrawState drawState,
    Ttk_State state,
    CGContextRef context)
{
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    NSColor *faceColor;

    bounds = CGRectInset(bounds, 0, -1);
    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 6);

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

    bounds = CGRectInset(bounds, 1, 1);
    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 pressed, paint the appropriate half blue.
     */
    
    if (state & TTK_STATE_PRESSED) {
	CGRect clip = bounds;
	clip.size.height /= 2;
	CGContextSaveGState(context);
	if (drawState == kThemeStatePressedDown) {
	    clip.origin.y += clip.size.height;
	}
	CGContextClipToRect(context, clip);
	GradientFillRoundedRectangle(context, bounds, 5,
				   darkSelectedGradient, 2);
	CGContextRestoreGState(context);
    }
    DrawUpDownArrows(context, bounds, 3, 5);
    HighlightButtonBorder(context, bounds);
}

/*
 * DrawDarkBevelButton --
 *
 *    This is a standalone drawing procedure which draws
1363
1364
1365
1366
1367
1368
1369
1370
1371



1372

1373
1374
1375
1376
1377
1378
1379
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = infoState,
	.kind = kThemeIncDecButton,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = kThemeAdornmentNone,
    };

    BEGIN_DRAWING(d)



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

    END_DRAWING
}

static Ttk_ElementSpec SpinButtonUpElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,







<

>
>
>
|
>







1421
1422
1423
1424
1425
1426
1427

1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
    const HIThemeButtonDrawInfo info = {
	.version = 0,
	.state = infoState,
	.kind = kThemeIncDecButton,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = kThemeAdornmentNone,
    };

    BEGIN_DRAWING(d)
    if (TkMacOSXInDarkMode(tkwin)) {
	DrawDarkIncDecButton(bounds, infoState, state, dc.context);
    } else {
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec SpinButtonUpElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,
1411
1412
1413
1414
1415
1416
1417



1418

1419
1420
1421
1422
1423
1424
1425
	.state = infoState,
	.kind = kThemeIncDecButton,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = kThemeAdornmentNone,
    };

    BEGIN_DRAWING(d)



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

    END_DRAWING
}

static Ttk_ElementSpec SpinButtonDownElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,







>
>
>
|
>







1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
	.state = infoState,
	.kind = kThemeIncDecButton,
	.value = Ttk_StateTableLookup(ButtonValueTable, state),
	.adornment = kThemeAdornmentNone,
    };

    BEGIN_DRAWING(d)
    if (TkMacOSXInDarkMode(tkwin)) {
	DrawDarkIncDecButton(bounds, infoState, state, dc.context);
    } else {
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
    }
    END_DRAWING
}

static Ttk_ElementSpec SpinButtonDownElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(NullElement),
    TtkNullElementOptions,