Check-in [bc74183392]
Not logged in

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

Overview
Comment:add tk upstream changes
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bc74183392cb3b559ca04677be2270e2b4b05ee6
User & Date: chw 2019-07-12 04:20:39
Context
2019-07-12
04:31
add selected tcl upstream changes check-in: 83c841b3cd user: chw tags: trunk
04:20
add tk upstream changes check-in: bc74183392 user: chw tags: trunk
2019-07-10
13:05
reapplied patch for ticket [36481a3e08] check-in: e95304b5ba user: chw tags: trunk
Changes

Changes to jni/sdl2tk/macosx/tkMacOSXBitmap.c.

    45     45       {"note",		kAlertNoteIcon},
    46     46       {"caution",		kAlertCautionIcon},
    47     47       {NULL}
    48     48   };
    49     49   
    50     50   #define builtInIconSize 32
    51     51   
           52  +#define OSTYPE_TO_UTI(x) (NSString *)UTTypeCreatePreferredIdentifierForTag( \
           53  +     kUTTagClassOSType, UTCreateStringForOSType(x), nil)
           54  +
    52     55   static Tcl_HashTable iconBitmapTable = {};
    53     56   typedef struct {
    54     57       int kind, width, height;
    55     58       char *value;
    56     59   } IconBitmap;
    57     60   
    58     61   static const char *const iconBitmapOptionStrings[] = {
................................................................................
   107    110   	}
   108    111       }
   109    112   }
   110    113   
   111    114   /*
   112    115    *----------------------------------------------------------------------
   113    116    *
   114         - * GetBitmapForIcon --
          117  + * PixmapFromImage --
   115    118    *
   116    119    * Results:
   117         - *	Bitmap for the given IconRef.
          120  + *	Returns a Pixmap with an NSImage drawn into it.
   118    121    *
   119    122    * Side effects:
   120    123    *	None.
   121    124    *
   122    125    *----------------------------------------------------------------------
   123    126    */
   124    127   
   125    128   static Pixmap
   126         -GetBitmapForIcon(
          129  +PixmapFromImage(
   127    130       Display *display,
   128         -    IconRef icon,
          131  +    NSImage* image,
   129    132       CGSize size)
   130    133   {
   131    134       TkMacOSXDrawingContext dc;
   132    135       Pixmap pixmap;
   133    136   
   134    137       pixmap = Tk_GetPixmap(display, None, size.width, size.height, 0);
   135    138       if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
   136    139   	if (dc.context) {
   137         -	    const CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
          140  +	    CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
   138    141   		    .tx = 0, .ty = size.height };
   139         -	    const CGRect r = { .origin = { .x = 0, .y = 0 }, .size = size };
   140         -
   141    142   	    CGContextConcatCTM(dc.context, t);
   142         -	    PlotIconRefInContext(dc.context, &r, kAlignAbsoluteCenter,
   143         -		    kTransformNone, NULL, kPlotIconRefNormalFlags, icon);
          143  +	    [NSGraphicsContext saveGraphicsState];
          144  +	    [NSGraphicsContext setCurrentContext:[NSGraphicsContext
          145  +		graphicsContextWithGraphicsPort:dc.context
          146  +		flipped:NO]];
          147  +	    [image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
          148  +		operation:NSCompositeCopy fraction:1.0];
          149  +	    [NSGraphicsContext restoreGraphicsState];
   144    150   	}
   145    151   	TkMacOSXRestoreDrawingContext(&dc);
   146    152       }
   147    153       return pixmap;
   148    154   }
   149    155   
   150    156   /*
................................................................................
   164    170    */
   165    171   
   166    172   Pixmap
   167    173   TkpCreateNativeBitmap(
   168    174       Display *display,
   169    175       const void *source)		/* Info about the icon to build. */
   170    176   {
   171         -    Pixmap pixmap;
   172         -    IconRef icon;
   173         -    OSErr err;
   174         -
   175         -    err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
   176         -	    PTR2UINT(source), &icon);
   177         -    if (err == noErr) {
   178         -	pixmap = GetBitmapForIcon(display, icon, CGSizeMake(builtInIconSize,
   179         -		builtInIconSize));
   180         -	ReleaseIconRef(icon);
   181         -    } else {
   182         -	pixmap = Tk_GetPixmap(display, None, builtInIconSize,
   183         -		builtInIconSize, 0);
   184         -    }
          177  +    NSString *iconUTI = OSTYPE_TO_UTI(PTR2UINT(source));
          178  +    NSImage *iconImage = [[NSWorkspace sharedWorkspace]
          179  +			     iconForFileType: iconUTI];
          180  +    CGSize size = CGSizeMake(builtInIconSize, builtInIconSize);
          181  +    Pixmap pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
   185    182       return pixmap;
   186    183   }
   187    184   
   188    185   /*
   189    186    *----------------------------------------------------------------------
   190    187    *
   191    188    * OSTypeFromString --
................................................................................
   305    302   	    }
   306    303   	}
   307    304   	if (image) {
   308    305   	    size = [image size];
   309    306   	}
   310    307       }
   311    308       if (image) {
   312         -	TkMacOSXDrawingContext dc;
   313         -	int depth = 0;
   314         -
   315         -#ifdef MAC_OSX_TK_TODO
   316         -	for (NSImageRep *r in [image representations]) {
   317         -	    NSInteger bitsPerSample = [r bitsPerSample];
   318         -	    if (bitsPerSample && bitsPerSample > depth) {
   319         -		depth = bitsPerSample;
   320         -	    };
   321         -	}
   322         -	if (depth == 1) {
   323         -	    /* TODO: convert BW NSImage to CGImageMask */
   324         -	}
   325         -#endif
   326         -	pixmap = Tk_GetPixmap(display, None, size.width, size.height, depth);
   327    309   	*width = size.width;
   328    310   	*height = size.height;
   329         -	if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
   330         -	    if (dc.context) {
   331         -		CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
   332         -			.tx = 0, .ty = size.height};
   333         -
   334         -		CGContextConcatCTM(dc.context, t);
   335         -		[NSGraphicsContext saveGraphicsState];
   336         -		[NSGraphicsContext setCurrentContext:[NSGraphicsContext
   337         -			graphicsContextWithGraphicsPort:dc.context flipped:NO]];
   338         -		[image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
   339         -			operation:NSCompositeCopy fraction:1.0];
   340         -		[NSGraphicsContext restoreGraphicsState];
   341         -	    }
   342         -	    TkMacOSXRestoreDrawingContext(&dc);
   343         -	}
          311  +	pixmap = PixmapFromImage(display, image, NSSizeToCGSize(size));
   344    312       } else if (name) {
   345    313   	OSType iconType;
   346    314   	if (OSTypeFromString(name, &iconType) == TCL_OK) {
   347         -	    IconRef icon;
   348         -	    OSErr err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
   349         -		    iconType, &icon);
   350         -	    if (err == noErr) {
   351         -		pixmap = GetBitmapForIcon(display, icon, NSSizeToCGSize(size));
   352         -		*width = size.width;
   353         -		*height = size.height;
   354         -		ReleaseIconRef(icon);
   355         -	    }
          315  +	    NSString *iconUTI = OSTYPE_TO_UTI(iconType);
          316  +	    printf("Found image for UTI %s\n", iconUTI.UTF8String);
          317  +	    NSImage *iconImage = [[NSWorkspace sharedWorkspace]
          318  +				     iconForFileType: iconUTI];
          319  +	    pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
   356    320   	}
   357    321       }
   358    322       return pixmap;
   359    323   }
   360    324   
   361    325   /*
   362    326    *----------------------------------------------------------------------

Changes to jni/sdl2tk/macosx/tkMacOSXWm.c.

  5577   5577   	if ([NSApp macMinorVersion] < 9) {
  5578   5578   	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  5579   5579                   "Window appearances did not exist until OSX 10.9.", -1));
  5580   5580   	    Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);
  5581   5581   	    return TCL_ERROR;
  5582   5582   	}
  5583   5583   	if ((objc < 3) || (objc > 4)) {
  5584         -	    Tcl_WrongNumArgs(interp, 2, objv,
  5585         -		    "appearance window ?appearancename?");
         5584  +	    Tcl_WrongNumArgs(interp, 2, objv, "window ?appearancename?");
  5586   5585   	    return TCL_ERROR;
  5587   5586   	}
  5588   5587   	if (objc == 4 && [NSApp macMinorVersion] < 14) {
  5589   5588   	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
  5590   5589   		    "Window appearances cannot be changed before OSX 10.14.",
  5591   5590   		    -1));
  5592   5591   	    Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);

Changes to jni/sdl2tk/macosx/ttkMacOSXTheme.c.

  1232   1232       /*
  1233   1233        * See ButtonElementDraw for the explanation of why we always draw
  1234   1234        * PushButtons in the active state.
  1235   1235        */
  1236   1236   
  1237   1237       SInt32 HIThemeState;
  1238   1238   
         1239  +    HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);
  1239   1240       switch (params->kind) {
  1240   1241       case kThemePushButton:
  1241         -	HIThemeState = kThemeStateActive;
         1242  +	HIThemeState &= ~kThemeStateInactive;
         1243  +	HIThemeState |= kThemeStateActive;
  1242   1244   	break;
  1243   1245       default:
  1244         -	HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);
  1245   1246   	break;
  1246   1247       }
  1247   1248   
  1248   1249       const HIThemeButtonDrawInfo info = {
  1249   1250   	.version = 0,
  1250   1251   	.state = HIThemeState,
  1251   1252   	.kind = params ? params->kind : 0,