Tk Source Code

Check-in [663e4bc3]
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:On macOS, squelch more availability warnings. Fix a hard to find bug [40ada90762] which could sometimes cause a segfault.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-6-branch
Files: files | file ages | folders
SHA3-256: 663e4bc3d6721424e388c71a90318f472286943e24ad1cfd92dc8188414c0acc
User & Date: culler 2019-04-20 03:40:21
Original Comment: On macOS, squelch more availability warnings. Fix a hard to find bug which could sometimes cause a segfault.
References
2019-05-08
20:16 Closed ticket [40ada907]: macOS: race condition leading to crash in entry.test plus 6 other changes artifact: 7557a9a0 user: fvogel
Context
2019-04-20
15:03
On macOS, edit comments and documentation; fix compiler warnings. check-in: 476cf7ba user: culler tags: core-8-6-branch
03:41
On macOS, squelch more availability warnings. Fix a hard to find bug [40ada90762] which could sometimes cause a segfault. check-in: 229db0f7 user: culler tags: trunk
03:40
On macOS, squelch more availability warnings. Fix a hard to find bug [40ada90762] which could sometimes cause a segfault. check-in: 663e4bc3 user: culler tags: core-8-6-branch
2019-04-19
19:03
Put the brace outside the #endif where it belongs. check-in: a3572e7e user: culler tags: core-8-6-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXButton.c.

181
182
183
184
185
186
187
188



189
190
191
192
193
194
195
{
    MacButton *macButtonPtr = clientData;
    TkButton *butPtr = clientData;
    Tk_Window tkwin = butPtr->tkwin;
    Pixmap pixmap;
    DrawParams* dpPtr = &macButtonPtr->drawParams;
    int needhighlight = 0;




    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));







|
>
>
>







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
    MacButton *macButtonPtr = clientData;
    TkButton *butPtr = clientData;
    Tk_Window tkwin = butPtr->tkwin;
    Pixmap pixmap;
    DrawParams* dpPtr = &macButtonPtr->drawParams;
    int needhighlight = 0;
    
    if (butPtr->flags & BUTTON_DELETED) {
	return;
    }
    butPtr->flags &= ~REDRAW_PENDING;
    if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
	return;
    }
    pixmap = (Pixmap) Tk_WindowId(tkwin);
    TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));

Changes to macosx/tkMacOSXColor.c.

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
...
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
...
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
...
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
...
694
695
696
697
698
699
700

701
702
703
704
705
706
707
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static NSColorSpace* deviceRGB = NULL;
static CGFloat blueAccentRGBA[4] = {0, 122.0/255, 1.0, 1.0};
static CGFloat graphiteAccentRGBA[4] = {152.0/255, 152.0/255, 152.0/255, 1.0};
static CGFloat windowBackground[4] = {236.0/255, 236.0/255, 236.0/255, 1.0};

static OSStatus
SetCGColorComponents(
    struct SystemColorMapEntry entry,
    unsigned long pixel,
    CGColorRef *c)
{
    OSStatus err = noErr;
    NSColor *bgColor, *color;
    CGFloat rgba[4] = {0, 0, 0, 1};

    NSInteger colorVariant = 1;




    if (!deviceRGB) {
	deviceRGB = [NSColorSpace deviceRGBColorSpace];
    }

    /*
     * This function is called before our autorelease pool is set up,
................................................................................
	} else {
	    bgColor = [[NSColor windowBackgroundColor] colorUsingColorSpace:
			    deviceRGB];
	    [bgColor getComponents: rgba];
	}
	if (rgba[0] + rgba[1] + rgba[2] < 1.5) {
	    for (int i=0; i<3; i++) {
		rgba[i] += entry.value*8.0/255.0;
	    }
	} else {
	    for (int i=0; i<3; i++) {
		rgba[i] -= entry.value*8.0/255.0;
	    }
	}
	break;
    case semantic:
	switch (entry.value) {
	case 0:
	    color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
	    break;
	case 1:
	    color = [[NSColor selectedTextColor] colorUsingColorSpace: deviceRGB];
	    break;
	case 2:
#if MAC_OS_X_VERSION_MIN_REQUIRED > 101000
	    color = [[NSColor labelColor] colorUsingColorSpace: deviceRGB];
#else
	    color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
#endif
	    break;
	case 3:
	    color = [[NSColor controlTextColor] colorUsingColorSpace:
................................................................................
			  deviceRGB];
	    break;
	case 7:
	    color = [[NSColor selectedTextBackgroundColor] colorUsingColorSpace:
			  deviceRGB];
	    break;
	case 8:
	    if ([NSApp macMinorVersion] >= 14) {
#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
		if (@available(macOS 10.14, *)) {
		    color = [[NSColor controlAccentColor] colorUsingColorSpace:
							      deviceRGB];
		    break;
		} else {
		    color = [NSColor colorWithColorSpace: deviceRGB
					      components: blueAccentRGBA
						   count: 4];
		}
#endif
	    } else {
		colorVariant = [[NSUserDefaults standardUserDefaults]
				       integerForKey:@"AppleAquaColorVariant"];
		if (colorVariant == 6) {
		    color = [NSColor colorWithColorSpace: deviceRGB
					      components: graphiteAccentRGBA
						   count: 4];
		} else {
		    color = [NSColor colorWithColorSpace: deviceRGB
					      components: blueAccentRGBA
						   count: 4];
		}
	    }

	    break;
	default:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
	    if ([NSApp macMinorVersion] >= 10) {
		color = [[NSColor labelColor] colorUsingColorSpace:
			      deviceRGB];
		break;
................................................................................
    CGContextRef context)
{
    OSStatus err = noErr;
    CGColorRef cgColor = nil;
    struct SystemColorMapEntry entry;
    CGRect rect;
    int code = (pixel >> 24) & 0xff;
    HIThemeBackgroundDrawInfo info = { 0, kThemeStateActive, entry.value };
    static CGColorSpaceRef deviceRGBSpace = NULL;

    if (!deviceRGBSpace) {
	deviceRGBSpace = CGColorSpaceCreateDeviceRGB();
    }
    if (code < FIRST_SEMANTIC_COLOR) {
	cgColor = CopyCachedColor(gc, pixel);
................................................................................
	    }
	    break;
	case HIText:
	    err = ChkErr(HIThemeSetTextFill, entry.value, NULL, context,
		    kHIThemeOrientationNormal);
	    break;
	case HIBackground:

	    rect = CGContextGetClipBoundingBox(context);
	    err = ChkErr(HIThemeApplyBackground, &rect, &info,
		    context, kHIThemeOrientationNormal);
	    break;
	default:
	    err = ChkErr(SetCGColorComponents, entry, pixel, &cgColor);
	    if (err == noErr) {






|
|
|










>
|
>
>
>







 







|



|












|







 







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







 







|







 







>







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
...
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
...
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
...
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
...
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static NSColorSpace* deviceRGB = NULL;
static CGFloat blueAccentRGBA[4] = {0, 122.0 / 255, 1.0, 1.0};
static CGFloat windowBackground[4] = 
    {236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0};

static OSStatus
SetCGColorComponents(
    struct SystemColorMapEntry entry,
    unsigned long pixel,
    CGColorRef *c)
{
    OSStatus err = noErr;
    NSColor *bgColor, *color;
    CGFloat rgba[4] = {0, 0, 0, 1};
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101400
    NSInteger colorVariant; 
    static CGFloat graphiteAccentRGBA[4] =
	{152.0 / 255, 152.0 / 255, 152.0 / 255, 1.0};
#endif

    if (!deviceRGB) {
	deviceRGB = [NSColorSpace deviceRGBColorSpace];
    }

    /*
     * This function is called before our autorelease pool is set up,
................................................................................
	} else {
	    bgColor = [[NSColor windowBackgroundColor] colorUsingColorSpace:
			    deviceRGB];
	    [bgColor getComponents: rgba];
	}
	if (rgba[0] + rgba[1] + rgba[2] < 1.5) {
	    for (int i=0; i<3; i++) {
		rgba[i] += entry.value*8.0 / 255.0;
	    }
	} else {
	    for (int i=0; i<3; i++) {
		rgba[i] -= entry.value*8.0 / 255.0;
	    }
	}
	break;
    case semantic:
	switch (entry.value) {
	case 0:
	    color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
	    break;
	case 1:
	    color = [[NSColor selectedTextColor] colorUsingColorSpace: deviceRGB];
	    break;
	case 2:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
	    color = [[NSColor labelColor] colorUsingColorSpace: deviceRGB];
#else
	    color = [[NSColor textColor] colorUsingColorSpace: deviceRGB];
#endif
	    break;
	case 3:
	    color = [[NSColor controlTextColor] colorUsingColorSpace:
................................................................................
			  deviceRGB];
	    break;
	case 7:
	    color = [[NSColor selectedTextBackgroundColor] colorUsingColorSpace:
			  deviceRGB];
	    break;
	case 8:

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
	    if (@available(macOS 10.14, *)) {
		color = [[NSColor controlAccentColor] colorUsingColorSpace:
							  deviceRGB];

	    } else {
		color = [NSColor colorWithColorSpace: deviceRGB
				 components: blueAccentRGBA
				 count: 4];
	    }

#else
	    colorVariant = [[NSUserDefaults standardUserDefaults]
			       integerForKey:@"AppleAquaColorVariant"];
	    if (colorVariant == 6) {
		color = [NSColor colorWithColorSpace: deviceRGB
				 components: graphiteAccentRGBA
				 count: 4];
	    } else {
		color = [NSColor colorWithColorSpace: deviceRGB
				 components: blueAccentRGBA
				 count: 4];
	    }

#endif
	    break;
	default:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
	    if ([NSApp macMinorVersion] >= 10) {
		color = [[NSColor labelColor] colorUsingColorSpace:
			      deviceRGB];
		break;
................................................................................
    CGContextRef context)
{
    OSStatus err = noErr;
    CGColorRef cgColor = nil;
    struct SystemColorMapEntry entry;
    CGRect rect;
    int code = (pixel >> 24) & 0xff;
    HIThemeBackgroundDrawInfo info = {0, kThemeStateActive, 0};;
    static CGColorSpaceRef deviceRGBSpace = NULL;

    if (!deviceRGBSpace) {
	deviceRGBSpace = CGColorSpaceCreateDeviceRGB();
    }
    if (code < FIRST_SEMANTIC_COLOR) {
	cgColor = CopyCachedColor(gc, pixel);
................................................................................
	    }
	    break;
	case HIText:
	    err = ChkErr(HIThemeSetTextFill, entry.value, NULL, context,
		    kHIThemeOrientationNormal);
	    break;
	case HIBackground:
	    info.kind = entry.value; 
	    rect = CGContextGetClipBoundingBox(context);
	    err = ChkErr(HIThemeApplyBackground, &rect, &info,
		    context, kHIThemeOrientationNormal);
	    break;
	default:
	    err = ChkErr(SetCGColorComponents, entry, pixel, &cgColor);
	    if (err == noErr) {

Changes to tests/frame.test.

660
661
662
663
664
665
666
667
668
669
670
671






672
673
674
675
676
677
678
} -setup {
	deleteWindows
} -body {
    toplevel .t -container 1 -width 300 -height 120
    wm geometry .t +0+0
    toplevel .x -width 140 -height 300 -use [winfo id .t] -bg green
    tkwait visibility .x
    update idletasks
    list [expr {[winfo rootx .x] - [winfo rootx .t]}] \
	    [expr {[winfo rooty .x] - [winfo rooty .t]}] \
	    [winfo width .t] [winfo height .t]
} -cleanup {






    deleteWindows
} -result {0 0 140 300}
test frame-3.10 {TkCreateFrame procedure, -use option} -constraints {
    unix
} -setup {
    deleteWindows
} -body {






<




>
>
>
>
>
>







660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
} -setup {
	deleteWindows
} -body {
    toplevel .t -container 1 -width 300 -height 120
    wm geometry .t +0+0
    toplevel .x -width 140 -height 300 -use [winfo id .t] -bg green
    tkwait visibility .x

    list [expr {[winfo rootx .x] - [winfo rootx .t]}] \
	    [expr {[winfo rooty .x] - [winfo rooty .t]}] \
	    [winfo width .t] [winfo height .t]
} -cleanup {
# This call to update idletasks was added to prevent a crash that was
# observed on OSX 10.12 (Sierra) only.  Any change, such as using the
# Development version to make debugging symbols available, adding a print
# statement, or calling update idletasks here, would make the test pass
# with no segfault.
    update idletasks
    deleteWindows
} -result {0 0 140 300}
test frame-3.10 {TkCreateFrame procedure, -use option} -constraints {
    unix
} -setup {
    deleteWindows
} -body {