Tk Source Code

Check-in [e85ff3ff]
Login

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

Overview
Comment:Added a drawing procedure for dark CheckBoxes. Added drawing primitives to make the code DRYer.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | bug-0d63621b6c
Files: files | file ages | folders
SHA3-256: e85ff3ffe38ebceaa182eb007675e3826477e6da05c4d7da48621548c86fe6c8
User & Date: culler 2019-03-13 21:46:57.938
Context
2019-03-15
02:42
Added a drawing procedure for dark RadioButtons and dealt with many slightly wrong ttk details. check-in: 973b11e7 user: culler tags: bug-0d63621b6c
2019-03-13
21:46
Added a drawing procedure for dark CheckBoxes. Added drawing primitives to make the code DRYer. check-in: e85ff3ff user: culler tags: bug-0d63621b6c
16:08
Fix the build for 10.6 (Snow Leopard). check-in: b27a2256 user: culler tags: bug-0d63621b6c
Changes
Unified Diff Ignore Whitespace Patch
Changes to macosx/ttkMacOSXTheme.c.
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
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
368
369
370
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
 *    The HIToolbox does not support Dark Mode, and apparently never will,
 *    so to make widgets look "native" we have to provide analogues of the
 *    HITheme drawing functions to be used in DarkAqua.  We continue to use
 *    HITheme in Aqua, since it understands earlier versions of the OS.
 */


static CGFloat darkButtonFill[4] = {112.0/255, 113.0/255, 115.0/255, 1.0};
static CGFloat darkDisabledButtonFill[4] = {86.0/255, 87.0/255, 89.0/255, 1.0};
static CGFloat darkInactiveSelectedTab[4] = {159.0/255, 160.0/255, 161.0/255, 1.0};
static CGFloat darkTabSeparator[4] = {0.0, 0.0, 0.0, 0.25};
static CGFloat darkTopGradient[8] = {1.0, 1.0, 1.0, 0.3,
				     1.0, 1.0, 1.0, 0.0};
static CGFloat darkBackgroundGradient[8] = {0.0, 0.0, 0.0, 0.1,
					    0.0, 0.0, 0.0, 0.25};


static CGFloat darkSelectedGradient[8] = {23.0/255, 111.0/255, 232.0/255, 1.0,
					  20.0/255, 94.0/255,  206.0/255, 1.0};





































































































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

static void MacOSXDrawDarkButton(
    CGRect bounds,
    ThemeButtonKind kind,
    Ttk_State state,
    CGContextRef context)
{
    CGPathRef path;
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    CGGradientRef topGradient, backgroundGradient, selectedGradient;
    NSColor *fill;

    /*
     * Fill the rounded bounding rectangle with a transparent black gradient.
     */

    CGContextSetLineWidth(context, 1.0);
    CGContextClipToRect(context, bounds);

    backgroundGradient = CGGradientCreateWithColorComponents(
	deviceRGB.CGColorSpace, darkBackgroundGradient, NULL, 2);
    CGPoint backgroundEnd = {bounds.origin.x,
			     bounds.origin.y + bounds.size.height};
    CGContextBeginPath(context);
    path = CGPathCreateWithRoundedRect(bounds, 5, 5, NULL);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, backgroundGradient,
					bounds.origin, backgroundEnd, 0);
    CFRelease(backgroundGradient);


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

    bounds = CGRectInset(bounds, 1, 1);
    if (state & TTK_STATE_DISABLED) {
	fill = [NSColor colorWithColorSpace: deviceRGB
			     components: darkDisabledButtonFill
				  count: 4];
    } else {
	fill = [NSColor colorWithColorSpace: deviceRGB
				 components: darkButtonFill
				      count: 4];
    }
    CGContextSetFillColorWithColor(context, fill.CGColor);
    path = CGPathCreateWithRoundedRect(bounds, 4, 4, NULL);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    CFRelease(path);

    /*
     * If this is a popup, draw the arrow button.
     */

    if (kind == kThemePopupButton) {
	CGFloat x, y;
	CGRect arrowBounds = bounds;
	arrowBounds.size.width = 16;
	arrowBounds.origin.x += bounds.size.width - 16;
	CGContextSaveGState(context);

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

	if (!(state & TTK_STATE_BACKGROUND)) {
	    selectedGradient = CGGradientCreateWithColorComponents(
		deviceRGB.CGColorSpace, darkSelectedGradient, NULL, 2);
	    CGPoint arrowEnd = {arrowBounds.origin.x,
	     			arrowBounds.origin.y + arrowBounds.size.height};
	    CGContextBeginPath(context);
	    CGContextAddPath(context, path);
	    CGContextClip(context);
	    CGContextClipToRect(context, arrowBounds);
	    CGContextDrawLinearGradient(context, selectedGradient,
					arrowBounds.origin, arrowEnd, 0);
	    CFRelease(selectedGradient);
	}

	/*
	 * Stroke the arrows.
	 */

	CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
	CGContextSetLineWidth(context, 1.5);
	x = arrowBounds.origin.x + 5;
	y = arrowBounds.origin.y + trunc(arrowBounds.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);
    }




    /*
     * Accent the top border with a transparent white gradient.




     */










    CGPoint topEnd = {bounds.origin.x, bounds.origin.y + 3};


    topGradient = CGGradientCreateWithColorComponents(






    		      deviceRGB.CGColorSpace, darkTopGradient, NULL, 2);








    CGContextSaveGState(context);
    CGContextBeginPath(context);

    CGContextAddArc(context, bounds.origin.x + 4, bounds.origin.y + 4,
    		    4, PI, 3*PI/2, 0);
    CGContextAddArc(context, bounds.origin.x + bounds.size.width - 4,
    		    bounds.origin.y + 4, 4, 3*PI/2, 0, 0);

    CGContextReplacePathWithStrokedPath(context);
    CGContextClip(context);

    CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0);
    CGContextRestoreGState(context);
    CFRelease(topGradient);

}

/*
 * MacOSXDrawDarkTab --
 *
 *    This is a standalone drawing procedure which draws Tabbed Pane
 *    Tabs in the Dark Mode style.
 */

static void MacOSXDrawDarkTab(
    CGRect bounds,
    Ttk_State state,
    CGContextRef context)
{
    CGPathRef path;
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    CGGradientRef topGradient, backgroundGradient, selectedGradient;
    NSColor *fill, *stroke;
    CGRect originalBounds= bounds;

    CGContextSetLineWidth(context, 1.0);
    CGContextClipToRect(context, bounds);

    /*
     * Extend the bounds to one or both sides so the rounded part will be
     * clipped off.
     */

    if (!(state & TTK_STATE_FIRST_TAB)) {
	bounds.origin.x -= 10;
	bounds.size.width += 10;
    }

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

    /*
     * Fill the rounded bounding rectangle with a transparent black gradient.
     */

    backgroundGradient = CGGradientCreateWithColorComponents(
            deviceRGB.CGColorSpace, darkBackgroundGradient, NULL, 2);
    CGPoint backgroundEnd = {bounds.origin.x,
			     bounds.origin.y + bounds.size.height};
    CGContextBeginPath(context);
    path = CGPathCreateWithRoundedRect(bounds, 5, 5, NULL);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, backgroundGradient,
				bounds.origin, backgroundEnd, 0);
    CFRelease(backgroundGradient);
    bounds = CGRectInset(bounds, 1, 1);

    /*
     * Fill the button face with the button fill color.  Use the
     * background color if the tab is not selected, otherwise use a
     * blue or gray gradient.
     */


    if (!(state & TTK_STATE_SELECTED)) {
	if (state & TTK_STATE_DISABLED) {
	    fill = [NSColor colorWithColorSpace: deviceRGB
				     components: darkDisabledButtonFill
					  count: 4];
	} else {
	    fill = [NSColor colorWithColorSpace: deviceRGB
				     components: darkButtonFill
					  count: 4];
	}
	CGContextSetFillColorWithColor(context, fill.CGColor);
	path = CGPathCreateWithRoundedRect(bounds, 4, 4, NULL);
	CGContextBeginPath(context);
	CGContextAddPath(context, path);
	CGContextFillPath(context);
	CFRelease(path);

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

	if (!(state & TTK_STATE_FIRST_TAB)) {







|
|






>
>


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














<

<
|
<
<
<
<



|
<
<
<
<
<
<
<
<
<
<
<

<

|

>


|
|


|
|


<
<
<
|
<
<

















<
<
<
<
<
<
<
|
<
<
|



















>
>
>
|
<
>
>
>
>
|

>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
|
>
|
<
|
<
>
|
|
>
|
|
<
>














<

<
|




















<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|


>


|
|


|
|


<
<
<
|
<
<







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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
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
368
369
370
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446

447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

468

469
470
471
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
 *    The HIToolbox does not support Dark Mode, and apparently never will,
 *    so to make widgets look "native" we have to provide analogues of the
 *    HITheme drawing functions to be used in DarkAqua.  We continue to use
 *    HITheme in Aqua, since it understands earlier versions of the OS.
 */


static CGFloat darkButtonFace[4] = {112.0/255, 113.0/255, 115.0/255, 1.0};
static CGFloat darkDisabledButtonFace[4] = {86.0/255, 87.0/255, 89.0/255, 1.0};
static CGFloat darkInactiveSelectedTab[4] = {159.0/255, 160.0/255, 161.0/255, 1.0};
static CGFloat darkTabSeparator[4] = {0.0, 0.0, 0.0, 0.25};
static CGFloat darkTopGradient[8] = {1.0, 1.0, 1.0, 0.3,
				     1.0, 1.0, 1.0, 0.0};
static CGFloat darkBackgroundGradient[8] = {0.0, 0.0, 0.0, 0.1,
					    0.0, 0.0, 0.0, 0.25};
static CGFloat darkCheckGradient[8] = {89.0/255, 90.0/255, 93.0/255, 1.0,
				       119.0/255, 120.0/255, 122.0/255, 1.0};
static CGFloat darkSelectedGradient[8] = {23.0/255, 111.0/255, 232.0/255, 1.0,
					  20.0/255, 94.0/255,  206.0/255, 1.0};

/* FillButtonBackground --
 *
 *    Fills a rounded rectangle with a transparent black gradient.
 */

static void FillButtonBackground(
    CGContextRef context,
    CGRect bounds,
    CGFloat radius)
{
    CGPathRef path;
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    CGGradientRef backgroundGradient = CGGradientCreateWithColorComponents(
	deviceRGB.CGColorSpace, darkBackgroundGradient, NULL, 2);
    CGPoint backgroundEnd = {bounds.origin.x,
			     bounds.origin.y + bounds.size.height};
    CGContextBeginPath(context);
    path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
    CGContextAddPath(context, path);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, backgroundGradient,
				bounds.origin, backgroundEnd, 0);
    CFRelease(path);
    CFRelease(backgroundGradient);
}

/* HighlightButtonBorder --
 *
 * Accent the top border of a rounded rectangle with a transparent
 * white gradient.
 */

static void HighlightButtonBorder(
    CGContextRef context,
    CGRect bounds)
{
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    CGPoint topEnd = {bounds.origin.x, bounds.origin.y + 3};
    CGGradientRef topGradient = CGGradientCreateWithColorComponents(
    		      deviceRGB.CGColorSpace, darkTopGradient, NULL, 2);
    CGContextSaveGState(context);
    CGContextBeginPath(context);
    CGContextAddArc(context, bounds.origin.x + 4, bounds.origin.y + 4,
    		    4, PI, 3*PI/2, 0);
    CGContextAddArc(context, bounds.origin.x + bounds.size.width - 4,
    		    bounds.origin.y + 4, 4, 3*PI/2, 0, 0);
    CGContextReplacePathWithStrokedPath(context);
    CGContextClip(context);
    CGContextDrawLinearGradient(context, topGradient, bounds.origin, topEnd, 0.0);
    CGContextRestoreGState(context);
    CFRelease(topGradient);
}

/* 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);
}

/* 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);
}

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

static void MacOSXDrawDarkButton(
    CGRect bounds,
    ThemeButtonKind kind,
    Ttk_State state,
    CGContextRef context)
{

    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];

    NSColor *faceColor;





    CGContextSetLineWidth(context, 1.0);
    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 5);













    /*
     * 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];
    }



    SolidFillButtonFace(context, bounds, 4, faceColor);



    /*
     * If this is a popup, draw the arrow button.
     */

    if (kind == kThemePopupButton) {
	CGFloat x, y;
	CGRect arrowBounds = bounds;
	arrowBounds.size.width = 16;
	arrowBounds.origin.x += bounds.size.width - 16;
	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.
	 */

	CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
	CGContextSetLineWidth(context, 1.5);
	x = arrowBounds.origin.x + 5;
	y = arrowBounds.origin.y + trunc(arrowBounds.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);
    }

    HighlightButtonBorder(context, bounds);
}

/*

 * MacOSXDrawDarkCheckBox --
 *
 *    This is a standalone drawing procedure which draws Checkboxes
 *    in the Dark Mode style.
 */

static void MacOSXDrawDarkCheckBox(
    CGRect bounds,
    Ttk_State state,
    CGContextRef context)
{
    CGRect checkbounds = {{2, 3},{16, 16}};
    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
    NSColor *stroke;
    CGFloat x, y;
    bounds = CGRectOffset(checkbounds, bounds.origin.x, bounds.origin.y);
    x = bounds.origin.x;
    y = bounds.origin.y;

    CGContextClipToRect(context, bounds);
    FillButtonBackground(context, bounds, 4);
    bounds = CGRectInset(bounds, 1, 1);
    GradientFillButtonFace(context, bounds, 3, darkCheckGradient, 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 {
	    stroke = [NSColor controlTextColor];
	}
	CGContextSetStrokeColorWithColor(context, stroke.CGColor);
    }
    if (state & TTK_STATE_SELECTED) {
	CGContextSetLineWidth(context, 1.5);
	CGContextBeginPath(context);
	CGPoint check[3] = {{x+3, y+7}, {x+6.5, y+9.5}, {x+10, y+4}};
	CGContextAddLines(context, check, 3);

	CGContextStrokePath(context);

    } else if (state & TTK_STATE_ALTERNATE) {
	CGContextSetLineWidth(context, 2.0);
	CGContextBeginPath(context);
	CGPoint check[2] = {{x+4, y+7}, {x+12, y+7}};
	CGContextAddLines(context, check, 2);
	CGContextStrokePath(context);

    }
}

/*
 * MacOSXDrawDarkTab --
 *
 *    This is a standalone drawing procedure which draws Tabbed Pane
 *    Tabs in the Dark Mode style.
 */

static void MacOSXDrawDarkTab(
    CGRect bounds,
    Ttk_State state,
    CGContextRef context)
{

    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];

    NSColor *faceColor, *stroke;
    CGRect originalBounds= bounds;

    CGContextSetLineWidth(context, 1.0);
    CGContextClipToRect(context, bounds);

    /*
     * Extend the bounds to one or both sides so the rounded part will be
     * clipped off.
     */

    if (!(state & TTK_STATE_FIRST_TAB)) {
	bounds.origin.x -= 10;
	bounds.size.width += 10;
    }

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

    /*


     * Fill the tab face with the appropriate color or gradient.  Use a















     * solid color if the tab is not selected, otherwise use a blue or
     * gray gradient.
     */

    bounds = CGRectInset(bounds, 1, 1);
    if (!(state & TTK_STATE_SELECTED)) {
	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);



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

	if (!(state & TTK_STATE_FIRST_TAB)) {
444
445
446
447
448
449
450
451
452

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
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
	        originalBounds.origin.y + originalBounds.size.height - 1);
	    CGContextStrokePath(context);
	    CGContextRestoreGState(context);
	}
    } else {

	/*
	 * This is the selected tab; paint it.  If it is first, cover up
	 * the separator line drawn by the second one.

	 */

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

	if (!(state & TTK_STATE_BACKGROUND)) {
	    selectedGradient = CGGradientCreateWithColorComponents(
		deviceRGB.CGColorSpace, darkSelectedGradient, NULL, 2);
	    CGPoint end = {bounds.origin.x, bounds.origin.y + bounds.size.height};
	    path = CGPathCreateWithRoundedRect(bounds, 4, 4, NULL);
	    CGContextBeginPath(context);
	    CGContextAddPath(context, path);
	    CGContextClip(context);
	    CGContextDrawLinearGradient(context, selectedGradient,
				    bounds.origin, end, 0);
	    CFRelease(path);
	    CFRelease(selectedGradient);
	} else {
	    fill = [NSColor colorWithColorSpace: deviceRGB
				     components: darkInactiveSelectedTab
					  count: 4];
	    CGContextSetFillColorWithColor(context, fill.CGColor);
	    path = CGPathCreateWithRoundedRect(bounds, 4, 4, NULL);
	    CGContextBeginPath(context);
	    CGContextAddPath(context, path);
	    CGContextFillPath(context);
	    CFRelease(path);
	}

	/*
	 * Accent the top border with a transparent white gradient.
	 */

	CGPoint topEnd = {bounds.origin.x, bounds.origin.y + 3};
	topGradient = CGGradientCreateWithColorComponents(
		          deviceRGB.CGColorSpace, darkTopGradient, NULL, 2);
	CGContextSaveGState(context);
	CGContextBeginPath(context);
	CGContextAddArc(context, bounds.origin.x + 4, bounds.origin.y + 4,
			4, PI, 3*PI/2, 0);
	CGContextAddArc(context, bounds.origin.x + bounds.size.width - 4,
			bounds.origin.y + 4, 4, 3*PI/2, 0, 0);
	CGContextReplacePathWithStrokedPath(context);
	CGContextClip(context);
	CGContextDrawLinearGradient(context, topGradient, bounds.origin,
				    topEnd, 0.0);
	CFRelease(topGradient);
	CGContextRestoreGState(context);
    }
}

/*
 * MacOSXDrawDarkSeparator --
 *
 *    This is a standalone drawing procedure which draws a separator widget







|
|
>





<

<
|
<
<
<
<
<
<
<
<
<

|


<
<
<
<
<
<
<
|
<
<
<
|
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<







524
525
526
527
528
529
530
531
532
533
534
535
536
537
538

539

540









541
542
543
544







545



546





547









548
549
550
551
552
553
554
	        originalBounds.origin.y + originalBounds.size.height - 1);
	    CGContextStrokePath(context);
	    CGContextRestoreGState(context);
	}
    } else {

	/*
	 * This is the selected tab; paint it blue.  If it is first, cover up
	 * the separator line drawn by the second one.  (The selected tab is
	 * 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);









    }
}

/*
 * MacOSXDrawDarkSeparator --
 *
 *    This is a standalone drawing procedure which draws a separator widget
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
    NSColor *fillColor = [NSColor colorWithColorSpace: deviceRGB
					   components: fill
						count:4];
    CGContextSetFillColorWithColor(context, fillColor.CGColor);
    CGContextFillRect(context, bounds);
}

#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 101300 */

/*----------------------------------------------------------------------
 * +++ Button element: Used for elements drawn with DrawThemeButton.
 */

/*
 * Extra margins to account for drop shadow.







|







565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
    NSColor *fillColor = [NSColor colorWithColorSpace: deviceRGB
					   components: fill
						count:4];
    CGContextSetFillColorWithColor(context, fillColor.CGColor);
    CGContextFillRect(context, bounds);
}

#endif /* MAC_OS_X_VERSION_MIN_REQUIRED >101300 */

/*----------------------------------------------------------------------
 * +++ Button element: Used for elements drawn with DrawThemeButton.
 */

/*
 * Extra margins to account for drop shadow.
646
647
648
649
650
651
652
653


654
655











656
657
658
659
660
661
662
{
    BEGIN_DRAWING(d)
    ThemeButtonParams *params = clientData;
    CGRect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
    HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state);

#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
    if (TkMacOSXInDarkMode(tkwin) &&


	(info.kind == kThemePushButton || info.kind == kThemePopupButton)) {
	MacOSXDrawDarkButton(bounds, info.kind, state, dc.context);











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







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







692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
{
    BEGIN_DRAWING(d)
    ThemeButtonParams *params = clientData;
    CGRect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
    HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state);

#if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
    if (TkMacOSXInDarkMode(tkwin)) {
	switch (info.kind) {
	case kThemePushButton:
	case kThemePopupButton:
	    MacOSXDrawDarkButton(bounds, info.kind, state, dc.context);
	    break;
	case kThemeCheckBox:
	    if (!(state & (TTK_STATE_SELECTED | TTK_STATE_ALTERNATE)) ||
		(state & TTK_STATE_BACKGROUND) ||
		(state & TTK_STATE_DISABLED)) {
		MacOSXDrawDarkCheckBox(bounds, state, dc.context);
		break;
	    }
	default:
	    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
	}
    } else {
	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
    }
#else
    ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
#endif
    END_DRAWING