Tk Source Code

Check-in [ff1b18fe]
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:Merged core-8-5-branch
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-438
Files: files | file ages | folders
SHA1: ff1b18fe04cf7352426eeb6bc8cac27dbc8c11b0
User & Date: fvogel 2015-11-28 21:39:01
Original Comment: Merged core-8-5branch
Context
2015-11-28
22:18
Fixed indentation check-in: ec3ea7f7 user: fvogel tags: tip-438
21:39
Merged core-8-5-branch check-in: ff1b18fe user: fvogel tags: tip-438
21:38
Text widget documentation updated according to TIP #438 check-in: 1e6f4294 user: fvogel tags: tip-438
2015-11-26
13:55
On cygwin, install libtk8.5.dll.a in the {prefix}/lib directory. check-in: 4300e28b user: jan.nijtmans tags: core-8-5-branch
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tkImgPhoto.c.

  2450   2450       case GrayScale:
  2451   2451       case StaticGray:
  2452   2452   	nRed = 1 << visInfoPtr->depth;
  2453   2453   	break;
  2454   2454       }
  2455   2455       XFree((char *) visInfoPtr);
  2456   2456   
  2457         -    sprintf(buf, ((mono) ? "%d": "%d/%d/%d"), nRed, nGreen, nBlue);
         2457  +    if (mono) {
         2458  +	sprintf(buf, "%d", nRed);
         2459  +    } else {
         2460  +	sprintf(buf, "%d/%d/%d", nRed, nGreen, nBlue);
         2461  +    }
  2458   2462       instancePtr->defaultPalette = Tk_GetUid(buf);
  2459   2463   
  2460   2464       /*
  2461   2465        * Make a GC with background = black and foreground = white.
  2462   2466        */
  2463   2467   
  2464   2468       white = Tk_GetColor(masterPtr->interp, tkwin, "white");

Changes to macosx/tkMacOSXDialog.c.

     3      3    *
     4      4    *	Contains the Mac implementation of the common dialog boxes.
     5      5    *
     6      6    * Copyright (c) 1996-1997 Sun Microsystems, Inc.
     7      7    * Copyright 2001-2009, Apple Inc.
     8      8    * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
     9      9    *
    10         - * See the file "license.terms" for information on usage and redistribution
    11         - * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    12         - */ 
           10  + * See the file "license.terms" for information on usage and redistribution of
           11  + * this file, and for a DISCLAIMER OF ALL WARRANTIES.
           12  + */
    13     13   
    14     14   #include "tkMacOSXPrivate.h"
    15     15   #include "tkFileFilter.h"
           16  +
           17  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
           18  +#define modalOK     NSOKButton
           19  +#define modalCancel NSCancelButton
           20  +#else
           21  +#define modalOK     NSModalResponseOK
           22  +#define modalCancel NSModalResponseCancel
           23  +#endif
           24  +#define modalOther  -1
           25  +#define modalError  -2
    16     26   
    17     27   static int TkBackgroundEvalObjv(Tcl_Interp *interp, int objc,
    18     28       Tcl_Obj *const *objv, int flags);
    19     29   
    20         -static const char *colorOptionStrings[] = {
           30  +static const char *const colorOptionStrings[] = {
    21     31       "-initialcolor", "-parent", "-title", NULL
    22     32   };
    23     33   enum colorOptions {
    24     34       COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE
    25     35   };
    26     36   
    27         -static const char *openOptionStrings[] = {
           37  +static const char *const openOptionStrings[] = {
    28     38       "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
    29     39       "-message", "-multiple", "-parent", "-title", "-typevariable",
    30     40       "-command", NULL
    31     41   };
    32     42   enum openOptions {
    33     43       OPEN_DEFAULT, OPEN_FILETYPES, OPEN_INITDIR, OPEN_INITFILE,
    34     44       OPEN_MESSAGE, OPEN_MULTIPLE, OPEN_PARENT, OPEN_TITLE,
    35     45       OPEN_TYPEVARIABLE, OPEN_COMMAND,
    36     46   };
    37         -static const char *saveOptionStrings[] = {
           47  +static const char *const saveOptionStrings[] = {
    38     48       "-defaultextension", "-filetypes", "-initialdir", "-initialfile",
    39     49       "-message", "-parent", "-title", "-typevariable", "-command",
    40     50       "-confirmoverwrite", NULL
    41     51   };
    42     52   enum saveOptions {
    43     53       SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE,
    44     54       SAVE_MESSAGE, SAVE_PARENT, SAVE_TITLE, SAVE_TYPEVARIABLE, SAVE_COMMAND,
    45     55       SAVE_CONFIRMOW
    46     56   };
    47         -static const char *chooseOptionStrings[] = {
           57  +static const char *const chooseOptionStrings[] = {
    48     58       "-initialdir", "-message", "-mustexist", "-parent", "-title", "-command",
    49     59       NULL
    50     60   };
    51     61   enum chooseOptions {
    52     62       CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, CHOOSE_PARENT,
    53     63       CHOOSE_TITLE, CHOOSE_COMMAND,
    54     64   };
    55     65   typedef struct {
    56     66       Tcl_Interp *interp;
    57     67       Tcl_Obj *cmdObj;
    58     68       int multiple;
    59     69   } FilePanelCallbackInfo;
    60     70   
    61         -static const char *alertOptionStrings[] = {
           71  +static const char *const alertOptionStrings[] = {
    62     72       "-default", "-detail", "-icon", "-message", "-parent", "-title",
    63     73       "-type", "-command", NULL
    64     74   };
    65     75   enum alertOptions {
    66     76       ALERT_DEFAULT, ALERT_DETAIL, ALERT_ICON, ALERT_MESSAGE, ALERT_PARENT,
    67     77       ALERT_TITLE, ALERT_TYPE, ALERT_COMMAND,
    68     78   };
    69     79   typedef struct {
    70     80       Tcl_Interp *interp;
    71     81       Tcl_Obj *cmdObj;
    72     82       int typeIndex;
    73     83   } AlertCallbackInfo;
    74         -static const char *alertTypeStrings[] = {
           84  +static const char *const alertTypeStrings[] = {
    75     85       "abortretryignore", "ok", "okcancel", "retrycancel", "yesno",
    76     86       "yesnocancel", NULL
    77     87   };
    78     88   enum alertTypeOptions {
    79     89       TYPE_ABORTRETRYIGNORE, TYPE_OK, TYPE_OKCANCEL, TYPE_RETRYCANCEL,
    80     90       TYPE_YESNO, TYPE_YESNOCANCEL
    81     91   };
    82         -static const char *alertIconStrings[] = {
           92  +static const char *const alertIconStrings[] = {
    83     93       "error", "info", "question", "warning", NULL
    84     94   };
    85     95   enum alertIconOptions {
    86     96       ICON_ERROR, ICON_INFO, ICON_QUESTION, ICON_WARNING
    87     97   };
    88         -static const char *alertButtonStrings[] = {
           98  +static const char *const alertButtonStrings[] = {
    89     99       "abort", "retry", "ignore", "ok", "cancel", "yes", "no", NULL
    90    100   };
    91    101   
    92    102   static const NSString *const alertButtonNames[][3] = {
    93    103       [TYPE_ABORTRETRYIGNORE] =   {@"Abort", @"Retry", @"Ignore"},
    94    104       [TYPE_OK] =			{@"OK"},
    95    105       [TYPE_OKCANCEL] =		{@"OK", @"Cancel"},
................................................................................
   101    111       [ICON_ERROR] =		NSWarningAlertStyle,
   102    112       [ICON_INFO] =		NSInformationalAlertStyle,
   103    113       [ICON_QUESTION] =		NSWarningAlertStyle,
   104    114       [ICON_WARNING] =		NSCriticalAlertStyle,
   105    115   };
   106    116   
   107    117   /*
   108         - * Need to map from 'alertButtonStrings' and its corresponding integer,
   109         - * index to the native button index, which is 1, 2, 3, from right to left.
   110         - * This is necessary to do for each separate '-type' of button sets.
          118  + * Need to map from 'alertButtonStrings' and its corresponding integer, index
          119  + * to the native button index, which is 1, 2, 3, from right to left. This is
          120  + * necessary to do for each separate '-type' of button sets.
   111    121    */
   112    122   
   113    123   static const short alertButtonIndexAndTypeToNativeButtonIndex[][7] = {
   114    124   			    /*  abort retry ignore ok   cancel yes   no */
   115    125       [TYPE_ABORTRETRYIGNORE] =   {1,    2,    3,    0,    0,    0,    0},
   116    126       [TYPE_OK] =			{0,    0,    0,    1,    0,    0,    0},
   117    127       [TYPE_OKCANCEL] =		{0,    0,    0,    1,    2,    0,    0},
................................................................................
   130    140       [TYPE_OK] =			{3, 0, 0},
   131    141       [TYPE_OKCANCEL] =		{3, 4, 0},
   132    142       [TYPE_RETRYCANCEL] =	{1, 4, 0},
   133    143       [TYPE_YESNO] =		{5, 6, 0},
   134    144       [TYPE_YESNOCANCEL] =	{5, 6, 4},
   135    145   };
   136    146   
          147  +/*
          148  + * Construct a file URL from directory and filename.  Either may
          149  + * be nil.  If both are nil, returns nil.
          150  + */
          151  +#if MAC_OS_X_VERSION_MIN_REQUIRED > 1050
          152  +static NSURL *getFileURL(NSString *directory, NSString *filename) {
          153  +    NSURL *url = nil;
          154  +    if (directory) {
          155  +	url = [NSURL fileURLWithPath:directory];
          156  +    }
          157  +    if (filename) {
          158  +	url = [NSURL URLWithString:filename relativeToURL:url];
          159  +    }
          160  +    return url;
          161  +}
          162  +#endif
          163  +
   137    164   #pragma mark TKApplication(TKDialog)
   138    165   
   139    166   @interface NSColorPanel(TKDialog)
   140         -- (void)_setUseModalAppearance:(BOOL)flag;
          167  +- (void) _setUseModalAppearance: (BOOL) flag;
   141    168   @end
   142    169   
   143    170   @implementation TKApplication(TKDialog)
   144         -- (void)tkFilePanelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode
   145         -	contextInfo:(void *)contextInfo {
          171  +
          172  +- (void) tkFilePanelDidEnd: (NSSavePanel *) panel
          173  +	returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
          174  +{
   146    175       FilePanelCallbackInfo *callbackInfo = contextInfo;
   147    176   
   148    177       if (returnCode == NSFileHandlingPanelOKButton) {
   149    178   	Tcl_Obj *resultObj;
          179  +
   150    180   	if (callbackInfo->multiple) {
   151    181   	    resultObj = Tcl_NewListObj(0, NULL);
   152         -	    for (NSString *name in [(NSOpenPanel*)panel filenames]) {
          182  +	    for (NSURL *url in [(NSOpenPanel*)panel URLs]) {
   153    183   		Tcl_ListObjAppendElement(callbackInfo->interp, resultObj,
   154         -			Tcl_NewStringObj([name UTF8String], -1));
          184  +			Tcl_NewStringObj([[url path] UTF8String], -1));
   155    185   	    }
   156    186   	} else {
   157         -	    resultObj = Tcl_NewStringObj([[panel filename] UTF8String], -1);
          187  +	    resultObj = Tcl_NewStringObj([[[panel URL]path] UTF8String], -1);
   158    188   	}
   159    189   	if (callbackInfo->cmdObj) {
   160    190   	    Tcl_Obj **objv, **tmpv;
   161    191   	    int objc, result = Tcl_ListObjGetElements(callbackInfo->interp,
   162    192   		    callbackInfo->cmdObj, &objc, &objv);
   163    193   	    if (result == TCL_OK && objc) {
   164    194   		tmpv = (Tcl_Obj **) ckalloc(sizeof(Tcl_Obj *) * (objc + 2));
................................................................................
   175    205   	Tcl_ResetResult(callbackInfo->interp);
   176    206       }
   177    207       if (panel == [NSApp modalWindow]) {
   178    208   	[NSApp stopModalWithCode:returnCode];
   179    209       }
   180    210       if (callbackInfo->cmdObj) {
   181    211   	Tcl_DecrRefCount(callbackInfo->cmdObj);
   182         -	ckfree((char*) callbackInfo);
          212  +	ckfree((char *)callbackInfo);
   183    213       }
   184    214   }
   185    215   - (void)tkAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode
   186    216   	contextInfo:(void *)contextInfo {
   187    217       AlertCallbackInfo *callbackInfo = contextInfo;
   188    218   
   189         -    if (returnCode != NSAlertErrorReturn) {
          219  +    if (returnCode >= NSAlertFirstButtonReturn) {
   190    220   	Tcl_Obj *resultObj = Tcl_NewStringObj(alertButtonStrings[
   191    221   		alertNativeButtonIndexAndTypeToButtonIndex[callbackInfo->
   192    222   		typeIndex][returnCode - NSAlertFirstButtonReturn]], -1);
   193    223   	if (callbackInfo->cmdObj) {
   194    224   	    Tcl_Obj **objv, **tmpv;
   195    225   	    int objc, result = Tcl_ListObjGetElements(callbackInfo->interp,
   196    226   		    callbackInfo->cmdObj, &objc, &objv);
................................................................................
   207    237   	}
   208    238       }
   209    239       if ([alert window] == [NSApp modalWindow]) {
   210    240   	[NSApp stopModalWithCode:returnCode];
   211    241       }
   212    242       if (callbackInfo->cmdObj) {
   213    243   	Tcl_DecrRefCount(callbackInfo->cmdObj);
   214         -	ckfree((char*) callbackInfo);
          244  +	ckfree((char *) callbackInfo);
   215    245       }
   216    246   }
   217    247   @end
   218    248   
   219    249   #pragma mark -
   220    250   
   221    251   /*
................................................................................
   248    278       int i;
   249    279       NSColor *color = nil, *initialColor = nil;
   250    280       NSColorPanel *colorPanel;
   251    281       NSInteger returnCode, numberOfComponents = 0;
   252    282   
   253    283       for (i = 1; i < objc; i += 2) {
   254    284   	int index;
   255         -	const char *option, *value;
          285  +	const char *value;
   256    286   
   257         -	if (Tcl_GetIndexFromObj(interp, objv[i], colorOptionStrings, "option",
   258         -		TCL_EXACT, &index) != TCL_OK) {
          287  +	if (Tcl_GetIndexFromObjStruct(interp, objv[i], colorOptionStrings,
          288  +		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
   259    289   	    goto end;
   260    290   	}
   261    291   	if (i + 1 == objc) {
   262         -	    option = Tcl_GetString(objv[i]);
   263         -	    Tcl_AppendResult(interp, "value for \"", option, "\" missing",
   264         -		    NULL);
          292  +	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
          293  +		    "value for \"%s\" missing", Tcl_GetString(objv[i])));
          294  +	    Tcl_SetErrorCode(interp, "TK", "COLORDIALOG", "VALUE", NULL);
   265    295   	    goto end;
   266    296   	}
   267    297   	value = Tcl_GetString(objv[i + 1]);
   268    298   
   269    299   	switch (index) {
   270         -	    case COLOR_INITIAL: {
   271         -		XColor *colorPtr;
   272         -
   273         -		colorPtr = Tk_GetColor(interp, tkwin, value);
   274         -		if (colorPtr == NULL) {
   275         -		    goto end;
   276         -		}
   277         -		initialColor = TkMacOSXGetNSColor(NULL, colorPtr->pixel);
   278         -		Tk_FreeColor(colorPtr);
   279         -		break;
   280         -	    }
   281         -	    case COLOR_PARENT: {
   282         -		parent = Tk_NameToWindow(interp, value, tkwin);
   283         -		if (parent == NULL) {
   284         -		    goto end;
   285         -		}
   286         -		break;
   287         -	    }
   288         -	    case COLOR_TITLE: {
   289         -		title = value;
   290         -		break;
   291         -	    }
          300  +	case COLOR_INITIAL: {
          301  +	    XColor *colorPtr;
          302  +
          303  +	    colorPtr = Tk_GetColor(interp, tkwin, value);
          304  +	    if (colorPtr == NULL) {
          305  +		goto end;
          306  +	    }
          307  +	    initialColor = TkMacOSXGetNSColor(NULL, colorPtr->pixel);
          308  +	    Tk_FreeColor(colorPtr);
          309  +	    break;
          310  +	}
          311  +	case COLOR_PARENT:
          312  +	    parent = Tk_NameToWindow(interp, value, tkwin);
          313  +	    if (parent == NULL) {
          314  +		goto end;
          315  +	    }
          316  +	    break;
          317  +	case COLOR_TITLE:
          318  +	    title = value;
          319  +	    break;
   292    320   	}
   293    321       }
   294    322       colorPanel = [NSColorPanel sharedColorPanel];
   295    323       [colorPanel orderOut:NSApp];
   296    324       [colorPanel setContinuous:NO];
   297    325       [colorPanel setBecomesKeyOnlyIfNeeded:NO];
   298    326       [colorPanel setShowsAlpha: NO];
................................................................................
   302    330   	[colorPanel setTitle:s];
   303    331   	[s release];
   304    332       }
   305    333       if (initialColor) {
   306    334   	[colorPanel setColor:initialColor];
   307    335       }
   308    336       returnCode = [NSApp runModalForWindow:colorPanel];
   309         -    if (returnCode == NSOKButton) {
          337  +    if (returnCode == modalOK) {
   310    338   	color = [[colorPanel color] colorUsingColorSpace:
   311    339   		[NSColorSpace genericRGBColorSpace]];
   312    340   	numberOfComponents = [color numberOfComponents];
   313    341       }
   314    342       if (color && numberOfComponents >= 3 && numberOfComponents <= 4) {
   315    343   	CGFloat components[4];
   316    344   	char colorstr[8];
................................................................................
   321    349   		(short)(components[1] * 255),
   322    350   		(short)(components[2] * 255));
   323    351   	Tcl_SetObjResult(interp, Tcl_NewStringObj(colorstr, 7));
   324    352       } else {
   325    353   	Tcl_ResetResult(interp);
   326    354       }
   327    355       result = TCL_OK;
          356  +
   328    357   end:
   329    358       return result;
   330    359   }
   331    360   
   332    361   /*
   333    362    *----------------------------------------------------------------------
   334    363    *
................................................................................
   361    390       FilePanelCallbackInfo callbackInfoStruct;
   362    391       FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
   363    392       NSString *directory = nil, *filename = nil;
   364    393       NSString *message, *title, *type;
   365    394       NSWindow *parent;
   366    395       NSMutableArray *fileTypes = nil;
   367    396       NSOpenPanel *panel = [NSOpenPanel openPanel];
   368         -    NSInteger returnCode = NSAlertErrorReturn;
          397  +    NSInteger modalReturnCode = modalError;
   369    398   
   370    399       TkInitFileFilters(&fl);
   371    400       for (i = 1; i < objc; i += 2) {
   372         -	if (Tcl_GetIndexFromObj(interp, objv[i], openOptionStrings, "option",
   373         -		TCL_EXACT, &index) != TCL_OK) {
          401  +	if (Tcl_GetIndexFromObjStruct(interp, objv[i], openOptionStrings,
          402  +		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
   374    403   	    goto end;
   375    404   	}
   376    405   	if (i + 1 == objc) {
   377         -	    str = Tcl_GetString(objv[i]);
   378         -	    Tcl_AppendResult(interp, "value for \"", str, "\" missing", NULL);
          406  +	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
          407  +		    "value for \"%s\" missing", Tcl_GetString(objv[i])));
          408  +	    Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL);
   379    409   	    goto end;
   380    410   	}
   381    411   	switch (index) {
   382    412   	case OPEN_DEFAULT:
   383    413   	    break;
   384    414   	case OPEN_FILETYPES:
   385    415   	    if (TkGetFileFilters(interp, &fl, objv[i + 1], 0) != TCL_OK) {
................................................................................
   430    460   	    typeVariablePtr = objv[i + 1];
   431    461   	    break;
   432    462   	case OPEN_COMMAND:
   433    463   	    cmdObj = objv[i+1];
   434    464   	    break;
   435    465   	}
   436    466       }
          467  +    [panel setAllowsMultipleSelection:multiple];
   437    468       if (fl.filters) {
   438    469   	fileTypes = [NSMutableArray array];
   439    470   	for (FileFilter *filterPtr = fl.filters; filterPtr;
   440    471   		filterPtr = filterPtr->next) {
   441    472   	    for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr;
   442    473   		    clausePtr = clausePtr->next) {
   443    474   		for (GlobPattern *globPtr = clausePtr->patterns; globPtr;
................................................................................
   462    493   			    [fileTypes addObject:type];
   463    494   			}
   464    495   		    }
   465    496   		}
   466    497   	    }
   467    498   	}
   468    499       }
   469         -    [panel setAllowsMultipleSelection:multiple];
          500  +    [panel setAllowedFileTypes:fileTypes];
   470    501       if (cmdObj) {
   471         -	callbackInfo = (FilePanelCallbackInfo *)
   472         -		ckalloc(sizeof(FilePanelCallbackInfo));
          502  +	callbackInfo = (FilePanelCallbackInfo *)ckalloc(sizeof(FilePanelCallbackInfo));
   473    503   	if (Tcl_IsShared(cmdObj)) {
   474    504   	    cmdObj = Tcl_DuplicateObj(cmdObj);
   475    505   	}
   476    506   	Tcl_IncrRefCount(cmdObj);
   477    507       }
   478    508       callbackInfo->cmdObj = cmdObj;
   479    509       callbackInfo->interp = interp;
   480    510       callbackInfo->multiple = multiple;
   481    511       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
   482    512       if (haveParentOption && parent && ![parent attachedSheet]) {
   483         -	[panel beginSheetForDirectory:directory file:filename types:fileTypes
   484         -		modalForWindow:parent modalDelegate:NSApp didEndSelector:
   485         -		@selector(tkFilePanelDidEnd:returnCode:contextInfo:)
   486         -		contextInfo:callbackInfo];
   487         -	returnCode = cmdObj ? NSAlertOtherReturn :
   488         -		[NSApp runModalForWindow:panel];
          513  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
          514  +	[panel beginSheetForDirectory:directory
          515  +	       file:filename
          516  +	       types:fileTypes
          517  +	       modalForWindow:parent
          518  +	       modalDelegate:NSApp
          519  +	       didEndSelector:
          520  +		   @selector(tkFilePanelDidEnd:returnCode:contextInfo:)
          521  +	       contextInfo:callbackInfo];
          522  +#else
          523  +	[panel setAllowedFileTypes:fileTypes];
          524  +	[panel setDirectoryURL:getFileURL(directory, filename)];
          525  +	[panel beginSheetModalForWindow:parent
          526  +	       completionHandler:^(NSInteger returnCode)
          527  +	       { [NSApp tkFilePanelDidEnd:panel
          528  +		       returnCode:returnCode
          529  +		       contextInfo:callbackInfo ]; } ];
          530  +#endif
          531  +	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
   489    532       } else {
   490         -	returnCode = [panel runModalForDirectory:directory file:filename
   491         -		types:fileTypes];
   492         -	[NSApp tkFilePanelDidEnd:panel returnCode:returnCode
          533  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
          534  +	modalReturnCode = [panel runModalForDirectory:directory
          535  +				 file:filename];
          536  +#else
          537  +	[panel setDirectoryURL:getFileURL(directory, filename)];
          538  +	modalReturnCode = [panel runModal];
          539  +#endif
          540  +	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
   493    541   		contextInfo:callbackInfo];
   494    542       }
   495         -    result = (returnCode != NSAlertErrorReturn) ? TCL_OK : TCL_ERROR;
          543  +    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
   496    544       if (typeVariablePtr && result == TCL_OK) {
   497    545   	/*
   498    546   	 * The -typevariable option is not really supported.
   499    547   	 */
   500    548   
   501         -	Tcl_SetVar(interp, Tcl_GetString(typeVariablePtr), "",
   502         -		TCL_GLOBAL_ONLY);
          549  +	Tcl_SetVar2(interp, Tcl_GetString(typeVariablePtr), NULL,
          550  +		"", TCL_GLOBAL_ONLY);
   503    551       }
   504         -end:
          552  +
          553  +  end:
   505    554       TkFreeFileFilters(&fl);
   506    555       return result;
   507    556   }
   508    557   
   509    558   /*
   510    559    *----------------------------------------------------------------------
   511    560    *
................................................................................
   539    588       FilePanelCallbackInfo callbackInfoStruct;
   540    589       FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
   541    590       NSString *directory = nil, *filename = nil, *defaultType = nil;
   542    591       NSString *message, *title, *type;
   543    592       NSWindow *parent;
   544    593       NSMutableArray *fileTypes = nil;
   545    594       NSSavePanel *panel = [NSSavePanel savePanel];
   546         -    NSInteger returnCode = NSAlertErrorReturn;
          595  +    NSInteger modalReturnCode = modalError;
   547    596   
   548    597       TkInitFileFilters(&fl);
   549    598       for (i = 1; i < objc; i += 2) {
   550         -	if (Tcl_GetIndexFromObj(interp, objv[i], saveOptionStrings, "option",
   551         -		TCL_EXACT, &index) != TCL_OK) {
          599  +	if (Tcl_GetIndexFromObjStruct(interp, objv[i], saveOptionStrings,
          600  +		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
   552    601   	    goto end;
   553    602   	}
   554    603   	if (i + 1 == objc) {
   555         -	    str = Tcl_GetString(objv[i]);
   556         -	    Tcl_AppendResult(interp, "value for \"", str, "\" missing",
   557         -		    NULL);
          604  +	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
          605  +		    "value for \"%s\" missing", Tcl_GetString(objv[i])));
          606  +	    Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL);
   558    607   	    goto end;
   559    608   	}
   560    609   	switch (index) {
   561    610   	case SAVE_DEFAULT:
   562    611   	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
   563    612   	    while (*str && (*str == '*' || *str == '.')) {
   564    613   		str++;
................................................................................
   610    659   	case SAVE_TYPEVARIABLE:
   611    660   	    break;
   612    661   	case SAVE_COMMAND:
   613    662   	    cmdObj = objv[i+1];
   614    663   	    break;
   615    664   	case SAVE_CONFIRMOW:
   616    665   	    if (Tcl_GetBooleanFromObj(interp, objv[i + 1],
   617         -				      &confirmOverwrite) != TCL_OK) {
          666  +		    &confirmOverwrite) != TCL_OK) {
   618    667   		goto end;
   619    668   	    }
   620    669   	    break;
   621    670   	}
   622    671       }
   623    672       if (fl.filters || defaultType) {
   624    673   	fileTypes = [NSMutableArray array];
................................................................................
   645    694   	}
   646    695   	[panel setAllowedFileTypes:fileTypes];
   647    696   	[panel setAllowsOtherFileTypes:YES];
   648    697       }
   649    698       [panel setCanSelectHiddenExtension:YES];
   650    699       [panel setExtensionHidden:NO];
   651    700       if (cmdObj) {
   652         -	callbackInfo = (FilePanelCallbackInfo *)
   653         -		ckalloc(sizeof(FilePanelCallbackInfo));
          701  +	callbackInfo = (FilePanelCallbackInfo *)ckalloc(sizeof(FilePanelCallbackInfo));
   654    702   	if (Tcl_IsShared(cmdObj)) {
   655    703   	    cmdObj = Tcl_DuplicateObj(cmdObj);
   656    704   	}
   657    705   	Tcl_IncrRefCount(cmdObj);
   658    706       }
   659    707       callbackInfo->cmdObj = cmdObj;
   660    708       callbackInfo->interp = interp;
   661    709       callbackInfo->multiple = 0;
   662    710       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
   663    711       if (haveParentOption && parent && ![parent attachedSheet]) {
   664         -	[panel beginSheetForDirectory:directory file:filename
   665         -		modalForWindow:parent modalDelegate:NSApp didEndSelector:
   666         -		@selector(tkFilePanelDidEnd:returnCode:contextInfo:)
   667         -		contextInfo:callbackInfo];
   668         -	returnCode = cmdObj ? NSAlertOtherReturn :
   669         -		[NSApp runModalForWindow:panel];
          712  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
          713  +	[panel beginSheetForDirectory:directory
          714  +	       file:filename
          715  +	       modalForWindow:parent
          716  +	       modalDelegate:NSApp
          717  +	       didEndSelector:
          718  +		   @selector(tkFilePanelDidEnd:returnCode:contextInfo:)
          719  +	       contextInfo:callbackInfo];
          720  +#else
          721  +	[panel setDirectoryURL:getFileURL(directory, filename)];
          722  +	[panel beginSheetModalForWindow:parent
          723  +	       completionHandler:^(NSInteger returnCode)
          724  +	       { [NSApp tkFilePanelDidEnd:panel
          725  +		       returnCode:returnCode
          726  +		       contextInfo:callbackInfo ]; } ];
          727  +#endif
          728  +	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
   670    729       } else {
   671         -	returnCode = [panel runModalForDirectory:directory file:filename];
   672         -	[NSApp tkFilePanelDidEnd:panel returnCode:returnCode
          730  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
          731  +	modalReturnCode = [panel runModalForDirectory:directory file:filename];
          732  +#else
          733  +	[panel setDirectoryURL:getFileURL(directory, filename)];
          734  +	modalReturnCode = [panel runModal];
          735  +#endif
          736  +	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
   673    737   		contextInfo:callbackInfo];
   674    738       }
   675         -    result = (returnCode != NSAlertErrorReturn) ? TCL_OK : TCL_ERROR;
   676         -end:
          739  +    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
          740  +
          741  +  end:
   677    742       TkFreeFileFilters(&fl);
   678    743       return result;
   679    744   }
   680    745   
   681    746   /*
   682    747    *----------------------------------------------------------------------
   683    748    *
................................................................................
   710    775       Tcl_Obj *cmdObj = NULL;
   711    776       FilePanelCallbackInfo callbackInfoStruct;
   712    777       FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
   713    778       NSString *directory = nil, *filename = nil;
   714    779       NSString *message, *title;
   715    780       NSWindow *parent;
   716    781       NSOpenPanel *panel = [NSOpenPanel openPanel];
   717         -    NSInteger returnCode = NSAlertErrorReturn;
          782  +    NSInteger modalReturnCode = modalError;
   718    783   
   719    784       for (i = 1; i < objc; i += 2) {
   720         -	if (Tcl_GetIndexFromObj(interp, objv[i], chooseOptionStrings, "option",
   721         -		TCL_EXACT, &index) != TCL_OK) {
          785  +	if (Tcl_GetIndexFromObjStruct(interp, objv[i], chooseOptionStrings,
          786  +		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
   722    787   	    goto end;
   723    788   	}
   724    789   	if (i + 1 == objc) {
   725         -	    str = Tcl_GetString(objv[i]);
   726         -	    Tcl_AppendResult(interp, "value for \"", str, "\" missing", NULL);
          790  +	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
          791  +		    "value for \"%s\" missing", Tcl_GetString(objv[i])));
          792  +	    Tcl_SetErrorCode(interp, "TK", "DIRDIALOG", "VALUE", NULL);
   727    793   	    goto end;
   728    794   	}
   729    795   	switch (index) {
   730    796   	case CHOOSE_INITDIR:
   731    797   	    str = Tcl_GetStringFromObj(objv[i + 1], &len);
   732    798   	    if (len) {
   733    799   		directory = [[[NSString alloc] initWithUTF8String:str]
................................................................................
   766    832   	}
   767    833       }
   768    834       [panel setPrompt:@"Choose"];
   769    835       [panel setCanChooseFiles:NO];
   770    836       [panel setCanChooseDirectories:YES];
   771    837       [panel setCanCreateDirectories:!mustexist];
   772    838       if (cmdObj) {
   773         -	callbackInfo = (FilePanelCallbackInfo *)
   774         -		ckalloc(sizeof(FilePanelCallbackInfo));
          839  +	callbackInfo = (FilePanelCallbackInfo *)ckalloc(sizeof(FilePanelCallbackInfo));
   775    840   	if (Tcl_IsShared(cmdObj)) {
   776    841   	    cmdObj = Tcl_DuplicateObj(cmdObj);
   777    842   	}
   778    843   	Tcl_IncrRefCount(cmdObj);
   779    844       }
   780    845       callbackInfo->cmdObj = cmdObj;
   781    846       callbackInfo->interp = interp;
   782    847       callbackInfo->multiple = 0;
   783    848       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
   784    849       if (haveParentOption && parent && ![parent attachedSheet]) {
   785         -	[panel beginSheetForDirectory:directory file:filename
   786         -		modalForWindow:parent modalDelegate:NSApp didEndSelector:
   787         -		@selector(tkFilePanelDidEnd:returnCode:contextInfo:)
          850  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
          851  +	[panel beginSheetForDirectory:directory
          852  +		file:filename
          853  +		modalForWindow:parent
          854  +		modalDelegate:NSApp
          855  +		didEndSelector: @selector(tkFilePanelDidEnd:returnCode:contextInfo:)
   788    856   		contextInfo:callbackInfo];
   789         -	returnCode = cmdObj ? NSAlertOtherReturn :
   790         -		[NSApp runModalForWindow:panel];
          857  +#else
          858  +	[panel setDirectoryURL:getFileURL(directory, filename)];
          859  +	[panel beginSheetModalForWindow:parent
          860  +	       completionHandler:^(NSInteger returnCode)
          861  +	       { [NSApp tkFilePanelDidEnd:panel
          862  +		       returnCode:returnCode
          863  +		       contextInfo:callbackInfo ]; } ];
          864  +#endif
          865  +	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
   791    866       } else {
   792         -	returnCode = [panel runModalForDirectory:directory file:filename];
   793         -	[NSApp tkFilePanelDidEnd:panel returnCode:returnCode
          867  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
          868  +	modalReturnCode = [panel runModalForDirectory:directory file:nil];
          869  +#else
          870  +	[panel setDirectoryURL:getFileURL(directory, filename)];
          871  +	modalReturnCode = [panel runModal];
          872  +#endif
          873  +	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
   794    874   		contextInfo:callbackInfo];
   795    875       }
   796         -    result = (returnCode != NSAlertErrorReturn) ? TCL_OK : TCL_ERROR;
   797         -end:
          876  +    result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
          877  +
          878  +  end:
   798    879       return result;
   799    880   }
   800    881   
   801    882   /*
   802    883    *----------------------------------------------------------------------
   803    884    *
   804    885    * TkAboutDlg --
................................................................................
   814    895    *----------------------------------------------------------------------
   815    896    */
   816    897   
   817    898   void
   818    899   TkAboutDlg(void)
   819    900   {
   820    901       NSImage *image;
   821         -    NSString *path = [NSApp tkFrameworkImagePath:@"Tk.tiff"];
          902  +    NSString *path = [NSApp tkFrameworkImagePath: @"Tk.tiff"];
          903  +
   822    904       if (path) {
   823    905   	image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
   824    906       } else {
   825    907   	image = [NSApp applicationIconImage];
   826    908       }
          909  +
   827    910       NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
          911  +
   828    912       [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
   829    913       [dateFormatter setDateFormat:@"Y"];
          914  +
   830    915       NSString *year = [dateFormatter stringFromDate:[NSDate date]];
          916  +
   831    917       [dateFormatter release];
   832         -    NSMutableParagraphStyle *style = [[[NSParagraphStyle defaultParagraphStyle]
   833         -	    mutableCopy] autorelease];
          918  +
          919  +    NSMutableParagraphStyle *style =
          920  +	    [[[NSParagraphStyle defaultParagraphStyle] mutableCopy]
          921  +	    autorelease];
          922  +
   834    923       [style setAlignment:NSCenterTextAlignment];
          924  +
   835    925       NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
   836    926   	    @"Tcl & Tk", @"ApplicationName",
   837    927   	    @"Tcl " TCL_VERSION " & Tk " TK_VERSION, @"ApplicationVersion",
   838    928   	    @TK_PATCH_LEVEL, @"Version",
   839    929   	    image, @"ApplicationIcon",
   840    930   	    [NSString stringWithFormat:@"Copyright %1$C 1987-%[email protected]", 0xA9,
   841    931   	    year], @"Copyright",
   842    932   	    [[[NSAttributedString alloc] initWithString:
   843    933   	    [NSString stringWithFormat:
   844    934   	    @"%1$C 1987-%[email protected] Tcl Core Team." "\n\n"
   845         -	    "%1$C 1989-%[email protected] Contributors." "\n\n"
          935  +		"%1$C 1989-%[email protected] Contributors." "\n\n"
   846    936   		"%1$C 2011-%[email protected] Kevin Walzer/WordTech Communications LLC." "\n\n"
   847    937   		"%1$C 2014-%[email protected] Marc Culler." "\n\n"
   848         -	     "%1$C 2002-%[email protected] Daniel A. Steffen." "\n\n"
   849         -	     "%1$C 2001-2009 Apple Inc." "\n\n"
   850         -	     "%1$C 2001-2002 Jim Ingham & Ian Reid" "\n\n"
   851         -	     "%1$C 1998-2000 Jim Ingham & Ray Johnson" "\n\n"
   852         -	     "%1$C 1998-2000 Scriptics Inc." "\n\n"
   853         -	     "%1$C 1996-1997 Sun Microsystems Inc.", 0xA9, year] attributes:
          938  +		"%1$C 2002-%[email protected] Daniel A. Steffen." "\n\n"
          939  +		"%1$C 2001-2009 Apple Inc." "\n\n"
          940  +		"%1$C 2001-2002 Jim Ingham & Ian Reid" "\n\n"
          941  +		"%1$C 1998-2000 Jim Ingham & Ray Johnson" "\n\n"
          942  +		"%1$C 1998-2000 Scriptics Inc." "\n\n"
          943  +		"%1$C 1996-1997 Sun Microsystems Inc.", 0xA9, year] attributes:
   854    944   	    [NSDictionary dictionaryWithObject:style
   855    945   	    forKey:NSParagraphStyleAttributeName]] autorelease], @"Credits",
   856    946   	    nil];
   857    947       [NSApp orderFrontStandardAboutPanelWithOptions:options];
   858    948   }
   859    949   
   860    950   /*
................................................................................
   880    970       int objc,			/* Number of arguments. */
   881    971       Tcl_Obj *const objv[])	/* Argument objects. */
   882    972   {
   883    973       if (objc > 1) {
   884    974   	Tcl_WrongNumArgs(interp, 1, objv, NULL);
   885    975   	return TCL_ERROR;
   886    976       }
   887         -    [NSApp orderFrontStandardAboutPanelWithOptions:nil];
          977  +    [NSApp orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionary]];
   888    978       return TCL_OK;
   889    979   }
   890    980   
   891    981   /*
   892    982    *----------------------------------------------------------------------
   893    983    *
   894    984    * Tk_MessageBoxObjCmd --
................................................................................
   918   1008       int defaultNativeButtonIndex = 1; /* 1, 2, 3: right to left */
   919   1009       Tcl_Obj *cmdObj = NULL;
   920   1010       AlertCallbackInfo callbackInfoStruct, *callbackInfo = &callbackInfoStruct;
   921   1011       NSString *message, *title;
   922   1012       NSWindow *parent;
   923   1013       NSArray *buttons;
   924   1014       NSAlert *alert = [NSAlert new];
   925         -    NSInteger returnCode = NSAlertErrorReturn;
         1015  +    NSInteger modalReturnCode = 1;
   926   1016   
   927   1017       iconIndex = ICON_INFO;
   928   1018       typeIndex = TYPE_OK;
   929   1019       for (i = 1; i < objc; i += 2) {
   930         -	if (Tcl_GetIndexFromObj(interp, objv[i], alertOptionStrings, "option",
   931         -		TCL_EXACT, &index) != TCL_OK) {
         1020  +	if (Tcl_GetIndexFromObjStruct(interp, objv[i], alertOptionStrings,
         1021  +		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
   932   1022   	    goto end;
   933   1023   	}
   934   1024   	if (i + 1 == objc) {
   935         -	    str = Tcl_GetString(objv[i]);
   936         -	    Tcl_AppendResult(interp, "value for \"", str, "\" missing", NULL);
         1025  +	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
         1026  +		    "value for \"%s\" missing", Tcl_GetString(objv[i])));
         1027  +	    Tcl_SetErrorCode(interp, "TK", "MSGBOX", "VALUE", NULL);
   937   1028   	    goto end;
   938   1029   	}
   939   1030   	switch (index) {
   940   1031   	case ALERT_DEFAULT:
   941   1032   	    /*
   942   1033   	     * Need to postpone processing of this option until we are sure to
   943   1034   	     * know the '-type' as well.
................................................................................
   950   1041   	    message = [[NSString alloc] initWithUTF8String:
   951   1042   		    Tcl_GetString(objv[i + 1])];
   952   1043   	    [alert setInformativeText:message];
   953   1044   	    [message release];
   954   1045   	    break;
   955   1046   
   956   1047   	case ALERT_ICON:
   957         -	    if (Tcl_GetIndexFromObj(interp, objv[i + 1], alertIconStrings,
   958         -		    "value", TCL_EXACT, &iconIndex) != TCL_OK) {
         1048  +	    if (Tcl_GetIndexFromObjStruct(interp, objv[i + 1], alertIconStrings,
         1049  +		    sizeof(char *), "value", TCL_EXACT, &iconIndex) != TCL_OK) {
   959   1050   		goto end;
   960   1051   	    }
   961   1052   	    break;
   962   1053   
   963   1054   	case ALERT_MESSAGE:
   964   1055   	    message = [[NSString alloc] initWithUTF8String:
   965   1056   		    Tcl_GetString(objv[i + 1])];
................................................................................
   980   1071   	    title = [[NSString alloc] initWithUTF8String:
   981   1072   		    Tcl_GetString(objv[i + 1])];
   982   1073   	    [[alert window] setTitle:title];
   983   1074   	    [title release];
   984   1075   	    break;
   985   1076   
   986   1077   	case ALERT_TYPE:
   987         -	    if (Tcl_GetIndexFromObj(interp, objv[i + 1], alertTypeStrings,
   988         -		    "value", TCL_EXACT, &typeIndex) != TCL_OK) {
         1078  +	    if (Tcl_GetIndexFromObjStruct(interp, objv[i + 1], alertTypeStrings,
         1079  +		    sizeof(char *), "value", TCL_EXACT, &typeIndex) != TCL_OK) {
   989   1080   		goto end;
   990   1081   	    }
   991   1082   	    break;
   992   1083   	case ALERT_COMMAND:
   993   1084   	    cmdObj = objv[i+1];
   994   1085   	    break;
   995   1086   	}
   996   1087       }
   997   1088       if (indexDefaultOption) {
   998   1089   	/*
   999         -	 * Any '-default' option needs to know the '-type' option, which is why
  1000         -	 * we do this here.
         1090  +	 * Any '-default' option needs to know the '-type' option, which is
         1091  +	 * why we do this here.
  1001   1092   	 */
  1002   1093   
  1003         -	if (Tcl_GetIndexFromObj(interp, objv[indexDefaultOption + 1],
  1004         -		alertButtonStrings, "value", TCL_EXACT, &index)
  1005         -		!= TCL_OK) {
         1094  +	if (Tcl_GetIndexFromObjStruct(interp, objv[indexDefaultOption + 1],
         1095  +		alertButtonStrings, sizeof(char *), "value", TCL_EXACT, &index) != TCL_OK) {
  1006   1096   	    goto end;
  1007   1097   	}
  1008   1098   
  1009   1099   	/*
  1010   1100   	 * Need to map from "ok" etc. to 1, 2, 3, right to left.
  1011   1101   	 */
  1012   1102   
  1013   1103   	defaultNativeButtonIndex =
  1014   1104   		alertButtonIndexAndTypeToNativeButtonIndex[typeIndex][index];
  1015   1105   	if (!defaultNativeButtonIndex) {
  1016   1106   	    Tcl_SetObjResult(interp,
  1017   1107   		    Tcl_NewStringObj("Illegal default option", -1));
         1108  +	    Tcl_SetErrorCode(interp, "TK", "MSGBOX", "DEFAULT", NULL);
  1018   1109   	    goto end;
  1019   1110   	}
  1020   1111       }
  1021   1112       [alert setIcon:[NSApp applicationIconImage]];
  1022   1113       [alert setAlertStyle:alertStyles[iconIndex]];
  1023   1114       i = 0;
  1024   1115       while (i < 3 && alertButtonNames[typeIndex][i]) {
  1025   1116   	[alert addButtonWithTitle:(NSString*)alertButtonNames[typeIndex][i++]];
  1026   1117       }
  1027   1118       buttons = [alert buttons];
  1028   1119       for (NSButton *b in buttons) {
  1029   1120   	NSString *ke = [b keyEquivalent];
         1121  +
  1030   1122   	if (([ke isEqualToString:@"\r"] || [ke isEqualToString:@"\033"]) &&
  1031   1123   		![b keyEquivalentModifierMask]) {
  1032   1124   	    [b setKeyEquivalent:@""];
  1033   1125   	}
  1034   1126       }
  1035         -    [[buttons objectAtIndex:[buttons count]-1] setKeyEquivalent:@"\033"];
  1036         -    [[buttons objectAtIndex:defaultNativeButtonIndex-1] setKeyEquivalent:@"\r"];
         1127  +    [[buttons objectAtIndex: [buttons count]-1] setKeyEquivalent: @"\033"];
         1128  +    [[buttons objectAtIndex: defaultNativeButtonIndex-1]
         1129  +	    setKeyEquivalent: @"\r"];
  1037   1130       if (cmdObj) {
  1038         -	callbackInfo = (AlertCallbackInfo *) ckalloc(sizeof(AlertCallbackInfo));
         1131  +	callbackInfo = (AlertCallbackInfo *)ckalloc(sizeof(AlertCallbackInfo));
  1039   1132   	if (Tcl_IsShared(cmdObj)) {
  1040   1133   	    cmdObj = Tcl_DuplicateObj(cmdObj);
  1041   1134   	}
  1042   1135   	Tcl_IncrRefCount(cmdObj);
  1043   1136       }
  1044   1137       callbackInfo->cmdObj = cmdObj;
  1045   1138       callbackInfo->interp = interp;
  1046   1139       callbackInfo->typeIndex = typeIndex;
  1047   1140       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
  1048   1141       if (haveParentOption && parent && ![parent attachedSheet]) {
  1049         -	[alert beginSheetModalForWindow:parent modalDelegate:NSApp
  1050         -		didEndSelector:@selector(tkAlertDidEnd:returnCode:contextInfo:)
  1051         -		contextInfo:callbackInfo];
  1052         -	returnCode = cmdObj ? NSAlertOtherReturn :
  1053         -		[NSApp runModalForWindow:[alert window]];
         1142  +#if MAC_OS_X_VERSION_MIN_REQUIRED > 1090
         1143  + 	[alert beginSheetModalForWindow:parent
         1144  +	       completionHandler:^(NSModalResponse returnCode)
         1145  +	       { [NSApp tkAlertDidEnd:alert
         1146  +			returnCode:returnCode
         1147  +			contextInfo:callbackInfo ]; } ];
         1148  +#else
         1149  +	[alert beginSheetModalForWindow:parent
         1150  +	       modalDelegate:NSApp
         1151  +	       didEndSelector:@selector(tkAlertDidEnd:returnCode:contextInfo:)
         1152  +	       contextInfo:callbackInfo];
         1153  +#endif
         1154  +	modalReturnCode = cmdObj ? 0 :
         1155  +	    [NSApp runModalForWindow:[alert window]];
  1054   1156       } else {
  1055         -	returnCode = [alert runModal];
  1056         -	[NSApp tkAlertDidEnd:alert returnCode:returnCode
         1157  +	modalReturnCode = [alert runModal];
         1158  +	[NSApp tkAlertDidEnd:alert returnCode:modalReturnCode
  1057   1159   		contextInfo:callbackInfo];
  1058   1160       }
  1059         -    result = (returnCode != NSAlertErrorReturn) ? TCL_OK : TCL_ERROR;
  1060         -end:
         1161  +    result = (modalReturnCode < 1) ? TCL_OK : TCL_ERROR;
         1162  + end:
  1061   1163       [alert release];
  1062   1164       return result;
  1063   1165   }
  1064   1166   
  1065   1167   /*
  1066   1168    * ----------------------------------------------------------------------
  1067   1169    *

Changes to macosx/tkMacOSXDraw.c.

   671    671   	kCGBitmapByteOrderDefault;
   672    672   #endif
   673    673   	char *data;
   674    674   	CGRect bounds = CGRectMake(0, 0, macDraw->size.width, macDraw->size.height);
   675    675   
   676    676   	if (macDraw->flags & TK_IS_BW_PIXMAP) {
   677    677   	    bitsPerPixel = 8;
   678         -	    bitmapInfo = kCGImageAlphaOnly;
          678  +	    bitmapInfo = (CGBitmapInfo)kCGImageAlphaOnly;
   679    679   	} else {
   680    680   	    colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
   681    681   	    bitsPerPixel = 32;
   682    682   	    bitmapInfo |= kCGImageAlphaPremultipliedFirst;
   683    683   	}
   684    684   	bytesPerRow = ((size_t) macDraw->size.width * bitsPerPixel + 127) >> 3
   685    685   		& ~15;

Changes to macosx/tkMacOSXFont.c.

    11     11    * See the file "license.terms" for information on usage and redistribution
    12     12    * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    13     13    */
    14     14   
    15     15   #include "tkMacOSXPrivate.h"
    16     16   #include "tkMacOSXFont.h"
    17     17   
           18  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
           19  +#define defaultOrientation kCTFontDefaultOrientation
           20  +#define verticalOrientation kCTFontVerticalOrientation
           21  +#else
           22  +#define defaultOrientation kCTFontOrientationDefault
           23  +#define verticalOrientation kCTFontOrientationVertical
           24  +#endif
           25  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
           26  +#define fixedPitch kCTFontUserFixedPitchFontType
           27  +#else
           28  +#define fixedPitch kCTFontUIFontUserFixedPitch
           29  +#endif
           30  +
    18     31   /*
    19     32   #ifdef TK_MAC_DEBUG
    20     33   #define TK_MAC_DEBUG_FONTS
    21     34   #endif
    22     35   */
    23     36   
    24     37   /*
................................................................................
   266    279        */
   267    280   
   268    281       bounds = [nsFont boundingRectForFont];
   269    282       if (CTFontGetGlyphsForCharacters((CTFontRef) nsFont, ch, glyphs, nCh)) {
   270    283   	fmPtr->fixed = [nsFont advancementForGlyph:glyphs[0]].width ==
   271    284   		[nsFont advancementForGlyph:glyphs[1]].width;
   272    285   	bounds = NSRectFromCGRect(CTFontGetBoundingRectsForGlyphs((CTFontRef)
   273         -		nsFont, kCTFontDefaultOrientation, ch, boundingRects, nCh));
          286  +		nsFont, defaultOrientation, ch, boundingRects, nCh));
   274    287   	kern = [nsFont advancementForGlyph:glyphs[2]].width -
   275    288   		[fontPtr->nsFont advancementForGlyph:glyphs[2]].width;
   276    289       }
   277    290       descent = floor(-bounds.origin.y + 0.5);
   278    291       ascent = floor(bounds.size.height + bounds.origin.y + 0.5);
   279    292       if (ascent > fmPtr->ascent) {
   280    293   	fmPtr->ascent = ascent;
................................................................................
   378    391   		CreateNamedSystemFont(interp, tkwin, systemFont->tkName1, &fa);
   379    392   	    }
   380    393   	    CFRelease(nsFont);
   381    394   	}
   382    395   	systemFont++;
   383    396       }
   384    397       TkInitFontAttributes(&fa);
   385         -    nsFont = (NSFont*) CTFontCreateUIFontForLanguage(
   386         -	    kCTFontUserFixedPitchFontType, 11, NULL);
          398  +    nsFont = (NSFont*) CTFontCreateUIFontForLanguage(fixedPitch, 11, NULL);
   387    399       if (nsFont) {
   388    400   	GetTkFontAttributesForNSFont(nsFont, &fa);
   389    401   	CFRelease(nsFont);
   390    402       } else {
   391    403   	fa.family = Tk_GetUid("Monaco");
   392    404   	fa.size = 11;
   393    405   	fa.weight = TK_FW_NORMAL;

Changes to macosx/tkMacOSXHLEvents.c.

     3      3    *
     4      4    *	Implements high level event support for the Macintosh. Currently, the
     5      5    *	only event that really does anything is the Quit event.
     6      6    *
     7      7    * Copyright (c) 1995-1997 Sun Microsystems, Inc.
     8      8    * Copyright 2001-2009, Apple Inc.
     9      9    * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
           10  + * Copyright (c) 2015 Marc Culler
    10     11    *
    11     12    * See the file "license.terms" for information on usage and redistribution
    12     13    * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    13     14    */
    14     15   
    15     16   #include "tkMacOSXPrivate.h"
           17  +#include <sys/param.h>
           18  +#define URL_MAX_LENGTH (17 + MAXPATHLEN)
    16     19   
    17     20   /*
    18     21    * This is a Tcl_Event structure that the Quit AppleEvent handler uses to
    19     22    * schedule the ReallyKillMe function.
    20     23    */
    21     24   
    22     25   typedef struct KillEvent {
................................................................................
    26     29   				 * AppleEvent */
    27     30   } KillEvent;
    28     31   
    29     32   /*
    30     33    * Static functions used only in this file.
    31     34    */
    32     35   
    33         -static OSErr		QuitHandler(const AppleEvent *event,
    34         -			    AppleEvent *reply, SRefCon handlerRefcon);
    35         -static OSErr		OappHandler(const AppleEvent *event,
    36         -			    AppleEvent *reply, SRefCon handlerRefcon);
    37         -static OSErr		RappHandler(const AppleEvent *event,
    38         -			    AppleEvent *reply, SRefCon handlerRefcon);
    39         -static OSErr		OdocHandler(const AppleEvent *event,
    40         -			    AppleEvent *reply, SRefCon handlerRefcon);
    41         -static OSErr		PrintHandler(const AppleEvent *event,
    42         -			    AppleEvent *reply, SRefCon handlerRefcon);
    43         -static OSErr		ScriptHandler(const AppleEvent *event,
    44         -			    AppleEvent *reply, SRefCon handlerRefcon);
    45         -static OSErr		PrefsHandler(const AppleEvent *event,
    46         -			    AppleEvent *reply, SRefCon handlerRefcon);
    47         -static int		MissedAnyParameters(const AppleEvent *theEvent);
    48         -static int		ReallyKillMe(Tcl_Event *eventPtr, int flags);
    49         -static OSStatus		FSRefToDString(const FSRef *fsref, Tcl_DString *ds);
           36  +static void tkMacOSXProcessFiles(NSAppleEventDescriptor* event, 
           37  +				 NSAppleEventDescriptor* replyEvent,
           38  +				 Tcl_Interp *interp,
           39  +				 char* procedure);
           40  +static int  MissedAnyParameters(const AppleEvent *theEvent);
           41  +static int  ReallyKillMe(Tcl_Event *eventPtr, int flags);
    50     42   
    51     43   #pragma mark TKApplication(TKHLEvents)
    52     44   
    53     45   @implementation TKApplication(TKHLEvents)
           46  +- (void) terminate: (id) sender
           47  +{
           48  +    [self handleQuitApplicationEvent:Nil withReplyEvent:Nil];
           49  +}
    54     50   
    55         -- (void)terminate:(id)sender {
    56         -    QuitHandler(NULL, NULL, (SRefCon) _eventInterp);
           51  +- (void) preferences: (id) sender
           52  +{
           53  +    [self handleShowPreferencesEvent:Nil withReplyEvent:Nil];
           54  +}
           55  +
           56  +- (void) handleQuitApplicationEvent: (NSAppleEventDescriptor *)event 
           57  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
           58  +{
           59  +    KillEvent *eventPtr;
           60  +
           61  +    if (_eventInterp) {
           62  +	/*
           63  +	 * Call the exit command from the event loop, since you are not
           64  +	 * supposed to call ExitToShell in an Apple Event Handler. We put this
           65  +	 * at the head of Tcl's event queue because this message usually comes
           66  +	 * when the Mac is shutting down, and we want to kill the shell as
           67  +	 * quickly as possible.
           68  +	 */
           69  +
           70  +	eventPtr = (KillEvent*)ckalloc(sizeof(KillEvent));
           71  +	eventPtr->header.proc = ReallyKillMe;
           72  +	eventPtr->interp = _eventInterp;
           73  +
           74  +	Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);
           75  +    }
           76  +}
           77  +
           78  +- (void) handleOpenApplicationEvent: (NSAppleEventDescriptor *)event 
           79  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
           80  +{
           81  +   Tcl_Interp *interp = _eventInterp;
           82  +
           83  +    if (interp &&
           84  +	Tcl_FindCommand(_eventInterp, "::tk::mac::OpenApplication", NULL, 0)){
           85  +	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::OpenApplication",
           86  +			      -1, TCL_EVAL_GLOBAL);
           87  +	if (code != TCL_OK) {
           88  +	    Tcl_BackgroundError(_eventInterp);
           89  +	}
           90  +    }
           91  +}
           92  +
           93  +- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event 
           94  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
           95  +{
           96  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
           97  +    ProcessSerialNumber thePSN = {0, kCurrentProcess};
           98  +    SetFrontProcess(&thePSN);
           99  +#else
          100  +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
          101  +#endif
          102  +    if (_eventInterp && Tcl_FindCommand(_eventInterp,
          103  +	    "::tk::mac::ReopenApplication", NULL, 0)) {
          104  +	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ReopenApplication",
          105  +			      -1, TCL_EVAL_GLOBAL);
          106  +	if (code != TCL_OK){
          107  +	    Tcl_BackgroundError(_eventInterp);
          108  +	}
          109  +    }
          110  +}
          111  +
          112  +- (void) handleShowPreferencesEvent: (NSAppleEventDescriptor *)event 
          113  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
          114  +{
          115  +    if (_eventInterp &&
          116  +	    Tcl_FindCommand(_eventInterp, "::tk::mac::ShowPreferences", NULL, 0)){
          117  +	int code = Tcl_EvalEx(_eventInterp, "::tk::mac::ShowPreferences",
          118  +			      -1, TCL_EVAL_GLOBAL);
          119  +	if (code != TCL_OK) {
          120  +	    Tcl_BackgroundError(_eventInterp);
          121  +	}
          122  +    }
          123  +}
          124  +
          125  +- (void) handleOpenDocumentsEvent: (NSAppleEventDescriptor *)event 
          126  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
          127  +{
          128  +    tkMacOSXProcessFiles(event, replyEvent, _eventInterp, "::tk::mac::OpenDocument");
          129  +}
          130  +
          131  +- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event 
          132  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
          133  +{
          134  +    tkMacOSXProcessFiles(event, replyEvent, _eventInterp, "::tk::mac::PrintDocument");
    57    135   }
    58    136   
    59         -- (void)preferences:(id)sender {
    60         -    PrefsHandler(NULL, NULL, (SRefCon) _eventInterp);
    61         -}
    62         -
          137  +- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event 
          138  +    withReplyEvent: (NSAppleEventDescriptor *)replyEvent
          139  +{
          140  +    OSStatus err;
          141  +    const AEDesc *theDesc = nil;
          142  +    DescType type = 0, initialType = 0;
          143  +    Size actual;
          144  +    int tclErr = -1;
          145  +    char URLBuffer[1 + URL_MAX_LENGTH];
          146  +    char errString[128];
          147  +    char typeString[5];
          148  +
          149  +    /*
          150  +     * The DoScript event receives one parameter that should be text data or a
          151  +     * fileURL.
          152  +     */
          153  +
          154  +    theDesc = [event aeDesc];
          155  +    if (theDesc == nil) {
          156  +	return;
          157  +    }
          158  +
          159  +    err = AEGetParamPtr(theDesc, keyDirectObject, typeWildCard, &initialType,
          160  +			NULL, 0, NULL);
          161  +    if (err != noErr) {
          162  +	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", (int)err);
          163  +	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar,
          164  +		      errString, strlen(errString));
          165  +	return;
          166  +    }
          167  +    
          168  +    if (MissedAnyParameters((AppleEvent*)theDesc)) {
          169  +    	sprintf(errString, "AEDoScriptHandler: extra parameters");
          170  +    	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar,
          171  +    		      errString, strlen(errString));
          172  +    	return;
          173  +    }
          174  +
          175  +    if (initialType == typeFileURL || initialType == typeAlias) {
          176  +	/*
          177  +	 * The descriptor can be coerced to a file url.  Source the file, or
          178  +	 * pass the path as a string argument to ::tk::mac::DoScriptFile if
          179  +	 * that procedure exists.
          180  +	 */
          181  +	err = AEGetParamPtr(theDesc, keyDirectObject, typeFileURL, &type,
          182  +			    (Ptr) URLBuffer, URL_MAX_LENGTH, &actual);
          183  +	if (err == noErr && actual > 0){
          184  +	    URLBuffer[actual] = '\0';
          185  +	    NSString *urlString = [NSString stringWithUTF8String:(char*)URLBuffer];
          186  +	    NSURL *fileURL = [NSURL URLWithString:urlString];
          187  +	    Tcl_DString command;
          188  +	    Tcl_DStringInit(&command);
          189  +	    if (Tcl_FindCommand(_eventInterp, "::tk::mac::DoScriptFile", NULL, 0)){
          190  +		Tcl_DStringAppend(&command, "::tk::mac::DoScriptFile", -1);
          191  +	    } else {
          192  +		Tcl_DStringAppend(&command, "source", -1);
          193  +	    }
          194  +	    Tcl_DStringAppendElement(&command, [[fileURL path] UTF8String]);
          195  +	    tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&command),
          196  +				 Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
          197  +	}
          198  +    } else if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
          199  +			   NULL, 0, &actual)) {
          200  +	if (actual > 0) {
          201  +	    /*
          202  +	     * The descriptor can be coerced to UTF8 text.  Evaluate as Tcl, or
          203  +	     * or pass the text as a string argument to ::tk::mac::DoScriptText
          204  +	     * if that procedure exists.
          205  +	     */ 
          206  +	    char *data = ckalloc(actual + 1);
          207  +	    if (noErr == AEGetParamPtr(theDesc, keyDirectObject, typeUTF8Text, &type,
          208  +			    data, actual, NULL)) {
          209  +		if (Tcl_FindCommand(_eventInterp, "::tk::mac::DoScriptText", NULL, 0)){
          210  +		    Tcl_DString command;
          211  +		    Tcl_DStringInit(&command);
          212  +		    Tcl_DStringAppend(&command, "::tk::mac::DoScriptText", -1);
          213  +		    Tcl_DStringAppendElement(&command, data);
          214  +		    tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&command),
          215  +				 Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
          216  +		} else {
          217  +		    tclErr = Tcl_EvalEx(_eventInterp, data, actual, TCL_EVAL_GLOBAL);
          218  +		}
          219  +	    }
          220  +	    ckfree(data);
          221  +	}
          222  +    } else {
          223  +	/*
          224  +	 * The descriptor can not be coerced to a fileURL or UTF8 text.
          225  +	 */
          226  +	for (int i = 0; i < 4; i++) {
          227  +	    typeString[i] = ((char*)&initialType)[3-i];
          228  +	}
          229  +	typeString[4] = '\0';
          230  +	sprintf(errString, "AEDoScriptHandler: invalid script type '%s', "
          231  +		"must be coercable to 'furl' or 'utf8'", typeString);
          232  +	AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar, errString,
          233  +		      strlen(errString));
          234  +    }
          235  +    /*
          236  +     * If we ran some Tcl code, put the result in the reply.
          237  +     */
          238  +    if (tclErr >= 0) {
          239  +	int reslen;
          240  +	const char *result =
          241  +	    Tcl_GetStringFromObj(Tcl_GetObjResult(_eventInterp), &reslen);
          242  +	if (tclErr == TCL_OK) {
          243  +	    AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyDirectObject, typeChar,
          244  +			  result, reslen);
          245  +	} else {
          246  +	    AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorString, typeChar,
          247  +			  result, reslen);
          248  +	    AEPutParamPtr((AppleEvent*)[replyEvent aeDesc], keyErrorNumber, typeSInt32,
          249  +			  (Ptr) &tclErr,sizeof(int));
          250  +	}
          251  +    }
          252  +    return;
          253  +}
    63    254   @end
    64    255   
    65    256   #pragma mark -
          257  +
          258  +/*
          259  + *----------------------------------------------------------------------
          260  + *
          261  + * TkMacOSXProcessFiles --
          262  + *
          263  + *	Extract a list of fileURLs from an AppleEvent and call the specified
          264  + *      procedure with the file paths as arguments.
          265  + *
          266  + * Results:
          267  + *	None.
          268  + *
          269  + * Side effects:
          270  + *	The event is handled by running the procedure.
          271  + *
          272  + *----------------------------------------------------------------------
          273  + */
          274  +
          275  +static void
          276  +tkMacOSXProcessFiles(
          277  +    NSAppleEventDescriptor* event, 
          278  +    NSAppleEventDescriptor* replyEvent,
          279  +    Tcl_Interp *interp,
          280  +    char* procedure)
          281  +{
          282  +    Tcl_Encoding utf8 = Tcl_GetEncoding(NULL, "utf-8");
          283  +    const AEDesc *fileSpecDesc = nil;
          284  +    AEDesc contents;
          285  +    char URLString[1 + URL_MAX_LENGTH];
          286  +    NSURL *fileURL;
          287  +    DescType type;
          288  +    Size actual;
          289  +    long count, index;
          290  +    AEKeyword keyword;
          291  +    Tcl_DString command, pathName;
          292  +    int code;
          293  +
          294  +    /*
          295  +     * Do nothing if we don't have an interpreter or the procedure doesn't exist.
          296  +     */
          297  +
          298  +    if (!interp || !Tcl_FindCommand(interp, procedure, NULL, 0)) {
          299  +	return;
          300  +    }
          301  +    
          302  +    fileSpecDesc = [event aeDesc];
          303  +    if (fileSpecDesc == nil ) {
          304  +    	return;
          305  +    }
          306  +    
          307  +    /*
          308  +     * The AppleEvent's descriptor should either contain a value of
          309  +     * typeObjectSpecifier or typeAEList.  In the first case, the descriptor
          310  +     * can be treated as a list of size 1 containing a value which can be
          311  +     * coerced into a fileURL. In the second case we want to work with the list
          312  +     * itself.  Values in the list will be coerced into fileURL's if possible;
          313  +     * otherwise they will be ignored.
          314  +     */
          315  +    
          316  +    /* Get a copy of the AppleEvent's descriptor. */
          317  +    AEGetParamDesc(fileSpecDesc, keyDirectObject, typeWildCard, &contents);
          318  +    if (contents.descriptorType == typeAEList) {
          319  +    	fileSpecDesc = &contents;
          320  +    }
          321  +    
          322  +    if (AECountItems(fileSpecDesc, &count) != noErr) {
          323  +	AEDisposeDesc(&contents);
          324  +    	return;
          325  +    }
          326  +    
          327  +    /*    
          328  +     * Construct a Tcl command which calls the procedure, passing the
          329  +     * paths contained in the AppleEvent as arguments.
          330  +     */
          331  +    
          332  +    Tcl_DStringInit(&command);
          333  +    Tcl_DStringAppend(&command, procedure, -1);
          334  +
          335  +    for (index = 1; index <= count; index++) {
          336  +	if (noErr != AEGetNthPtr(fileSpecDesc, index, typeFileURL, &keyword,
          337  +				 &type, (Ptr) URLString, URL_MAX_LENGTH, &actual)) {
          338  +	    continue;
          339  +	}
          340  +	if (type != typeFileURL) {
          341  +	    continue;
          342  +	}
          343  +	URLString[actual] = '\0';
          344  +	fileURL = [NSURL URLWithString:[NSString stringWithUTF8String:(char*)URLString]]; 
          345  +	if (fileURL == nil) {
          346  +	    continue;
          347  +	}
          348  +	Tcl_ExternalToUtfDString(utf8, [[fileURL path] UTF8String], -1, &pathName);
          349  +	Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
          350  +	Tcl_DStringFree(&pathName);
          351  +    }
          352  +    AEDisposeDesc(&contents);
          353  +
          354  +    /*
          355  +     * Handle the event by evaluating the Tcl expression we constructed.
          356  +     */
          357  +
          358  +    code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
          359  +	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
          360  +    if (code != TCL_OK) {
          361  +	Tcl_BackgroundError(interp);
          362  +    }
          363  +    Tcl_DStringFree(&command);
          364  +    return;
          365  +}
    66    366   
    67    367   /*
    68    368    *----------------------------------------------------------------------
    69    369    *
    70    370    * TkMacOSXInitAppleEvents --
    71    371    *
    72         - *	Initilize the Apple Events on the Macintosh. This registers the core
    73         - *	event handlers.
          372  + *	Register AppleEvent handlers with the NSAppleEventManager for
          373  + *      this NSApplication.
    74    374    *
    75    375    * Results:
    76    376    *	None.
    77    377    *
    78    378    * Side effects:
    79    379    *	None.
    80    380    *
    81    381    *----------------------------------------------------------------------
    82    382    */
    83    383   
    84    384   void
    85    385   TkMacOSXInitAppleEvents(
    86         -    Tcl_Interp *interp)		/* Interp to handle basic events. */
          386  +    Tcl_Interp *interp)   /* not used */
    87    387   {
    88         -    AEEventHandlerUPP OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP;
    89         -    AEEventHandlerUPP PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP;
    90         -    AEEventHandlerUPP PrefsHandlerUPP;
          388  +    NSAppleEventManager *aeManager = [NSAppleEventManager sharedAppleEventManager];
    91    389       static Boolean initialized = FALSE;
    92    390   
    93    391       if (!initialized) {
    94    392   	initialized = TRUE;
    95    393   
    96         -	/*
    97         -	 * Install event handlers for the core apple events.
    98         -	 */
          394  +	[aeManager setEventHandler:NSApp
          395  +	    andSelector:@selector(handleQuitApplicationEvent:withReplyEvent:)
          396  +	    forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
    99    397   
   100         -	QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler);
   101         -	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEQuitApplication,
   102         -		QuitHandlerUPP, (SRefCon) interp, false);
          398  +	[aeManager setEventHandler:NSApp
          399  +	    andSelector:@selector(handleOpenApplicationEvent:withReplyEvent:)
          400  +	    forEventClass:kCoreEventClass andEventID:kAEOpenApplication];
   103    401   
   104         -	OappHandlerUPP = NewAEEventHandlerUPP(OappHandler);
   105         -	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenApplication,
   106         -		OappHandlerUPP, (SRefCon) interp, false);
          402  +	[aeManager setEventHandler:NSApp
          403  +	    andSelector:@selector(handleReopenApplicationEvent:withReplyEvent:)
          404  +	    forEventClass:kCoreEventClass andEventID:kAEReopenApplication];
          405  +
          406  +	[aeManager setEventHandler:NSApp
          407  +	    andSelector:@selector(handleShowPreferencesEvent:withReplyEvent:)
          408  +	    forEventClass:kCoreEventClass andEventID:kAEShowPreferences];
          409  +
          410  +	[aeManager setEventHandler:NSApp
          411  +	    andSelector:@selector(handleOpenDocumentsEvent:withReplyEvent:)
          412  +	    forEventClass:kCoreEventClass andEventID:kAEOpenDocuments];
   107    413   
   108         -	RappHandlerUPP = NewAEEventHandlerUPP(RappHandler);
   109         -	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEReopenApplication,
   110         -		RappHandlerUPP, (SRefCon) interp, false);
   111         -
   112         -	OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler);
   113         -	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenDocuments,
   114         -		OdocHandlerUPP, (SRefCon) interp, false);
          414  +	[aeManager setEventHandler:NSApp
          415  +	    andSelector:@selector(handleOpenDocumentsEvent:withReplyEvent:)
          416  +	    forEventClass:kCoreEventClass andEventID:kAEPrintDocuments];
   115    417   
   116         -	PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler);
   117         -	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEPrintDocuments,
   118         -		PrintHandlerUPP, (SRefCon) interp, false);
   119         -
   120         -	PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler);
   121         -	ChkErr(AEInstallEventHandler, kCoreEventClass, kAEShowPreferences,
   122         -		PrefsHandlerUPP, (SRefCon) interp, false);
   123         -
   124         -	if (interp) {
   125         -	    ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler);
   126         -	    ChkErr(AEInstallEventHandler, kAEMiscStandards, kAEDoScript,
   127         -		    ScriptHandlerUPP, (SRefCon) interp, false);
   128         -	}
          418  +	[aeManager setEventHandler:NSApp
          419  +	    andSelector:@selector(handleDoScriptEvent:withReplyEvent:)
          420  +	    forEventClass:kAEMiscStandards andEventID:kAEDoScript];
   129    421       }
   130    422   }
   131    423   
   132    424   /*
   133    425    *----------------------------------------------------------------------
   134    426    *
   135    427    * TkMacOSXDoHLEvent --
   136    428    *
   137         - *	Dispatch incomming highlevel events.
          429  + *	Dispatch an AppleEvent.
   138    430    *
   139    431    * Results:
   140    432    *	None.
   141    433    *
   142    434    * Side effects:
   143         - *	Depends on the incoming event.
          435  + *	Depend on the AppleEvent.
   144    436    *
   145    437    *----------------------------------------------------------------------
   146    438    */
   147    439   
   148    440   int
   149    441   TkMacOSXDoHLEvent(
   150    442       void *theEvent)
   151    443   {
   152         -    return AEProcessAppleEvent((EventRecord *)theEvent);
   153         -}
   154         -
   155         -/*
   156         - *----------------------------------------------------------------------
   157         - *
   158         - * QuitHandler --
   159         - *
   160         - *	This is the 'quit' core Apple event handler.
   161         - *
   162         - * Results:
   163         - *	None.
   164         - *
   165         - * Side effects:
   166         - *	None.
   167         - *
   168         - *----------------------------------------------------------------------
   169         - */
          444  +    /* According to the NSAppleEventManager reference:
          445  +     *   "The theReply parameter always specifies a reply Apple event, never
          446  +     *   nil.  However, the handler should not fill out the reply if the
          447  +     *   descriptor type for the reply event is typeNull, indicating the sender
          448  +     *   does not want a reply."
          449  +     * The specified way to build such a non-nil descriptor is used here.  But
          450  +     * on OSX 10.11, the compiler nonetheless generates a warning.  I am
          451  +     * supressing the warning here -- maybe the warnings will stop in a future
          452  +     * compiler release.
          453  +     */
          454  +#ifdef __clang__
          455  +#pragma clang diagnostic push
          456  +#pragma clang diagnostic ignored "-Wnonnull"
          457  +#endif
          458  +
          459  +    NSAppleEventDescriptor* theReply = [NSAppleEventDescriptor nullDescriptor];
          460  +    NSAppleEventManager *aeManager = [NSAppleEventManager sharedAppleEventManager];
   170    461   
   171         -static OSErr
   172         -QuitHandler(
   173         -    const AppleEvent *event,
   174         -    AppleEvent *reply,
   175         -    SRefCon handlerRefcon)
   176         -{
   177         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   178         -    KillEvent *eventPtr;
          462  +    return [aeManager dispatchRawAppleEvent:(const AppleEvent*)theEvent
          463  +		      withRawReply: (AppleEvent *)theReply
          464  +		      handlerRefCon: (SRefCon)0];
   179    465   
   180         -    if (interp) {
   181         -	/*
   182         -	 * Call the exit command from the event loop, since you are not
   183         -	 * supposed to call ExitToShell in an Apple Event Handler. We put this
   184         -	 * at the head of Tcl's event queue because this message usually comes
   185         -	 * when the Mac is shutting down, and we want to kill the shell as
   186         -	 * quickly as possible.
   187         -	 */
   188         -
   189         -	eventPtr = (KillEvent *) ckalloc(sizeof(KillEvent));
   190         -	eventPtr->header.proc = ReallyKillMe;
   191         -	eventPtr->interp = interp;
   192         -
   193         -	Tcl_QueueEvent((Tcl_Event *) eventPtr, TCL_QUEUE_HEAD);
   194         -    }
   195         -    return noErr;
   196         -}
   197         -
   198         -/*
   199         - *----------------------------------------------------------------------
   200         - *
   201         - * OappHandler --
   202         - *
   203         - *	This is the 'oapp' core Apple event handler.
   204         - *
   205         - * Results:
   206         - *	None.
   207         - *
   208         - * Side effects:
   209         - *	None.
   210         - *
   211         - *----------------------------------------------------------------------
   212         - */
   213         -
   214         -static OSErr
   215         -OappHandler(
   216         -    const AppleEvent *event,
   217         -    AppleEvent *reply,
   218         -    SRefCon handlerRefcon)
   219         -{
   220         -    Tcl_CmdInfo dummy;
   221         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   222         -
   223         -    if (interp &&
   224         -	    Tcl_GetCommandInfo(interp, "::tk::mac::OpenApplication", &dummy)){
   225         -	int code = Tcl_EvalEx(interp, "::tk::mac::OpenApplication", -1, TCL_EVAL_GLOBAL);
   226         -	if (code != TCL_OK) {
   227         -	    Tcl_BackgroundError(interp);
   228         -	}
   229         -    }
   230         -    return noErr;
   231         -}
   232         -
   233         -/*
   234         - *----------------------------------------------------------------------
   235         - *
   236         - * RappHandler --
   237         - *
   238         - *	This is the 'rapp' core Apple event handler.
   239         - *
   240         - * Results:
   241         - *	None.
   242         - *
   243         - * Side effects:
   244         - *	None.
   245         - *
   246         - *----------------------------------------------------------------------
   247         - */
   248         -
   249         -static OSErr
   250         -RappHandler(
   251         -    const AppleEvent *event,
   252         -    AppleEvent *reply,
   253         -    SRefCon handlerRefcon)
   254         -{
   255         -    Tcl_CmdInfo dummy;
   256         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   257         -    ProcessSerialNumber thePSN = {0, kCurrentProcess};
   258         -    OSStatus err = ChkErr(SetFrontProcess, &thePSN);
   259         -
   260         -    if (interp && Tcl_GetCommandInfo(interp,
   261         -	    "::tk::mac::ReopenApplication", &dummy)) {
   262         -	int code = Tcl_EvalEx(interp, "::tk::mac::ReopenApplication", -1, TCL_EVAL_GLOBAL);
   263         -	if (code != TCL_OK){
   264         -	    Tcl_BackgroundError(interp);
   265         -	}
   266         -    }
   267         -    return err;
   268         -}
   269         -
   270         -/*
   271         - *----------------------------------------------------------------------
   272         - *
   273         - * PrefsHandler --
   274         - *
   275         - *	This is the 'pref' core Apple event handler. Called when the user
   276         - *	selects 'Preferences...' in MacOS X
   277         - *
   278         - * Results:
   279         - *	None.
   280         - *
   281         - * Side effects:
   282         - *	None.
   283         - *
   284         - *----------------------------------------------------------------------
   285         - */
   286         -
   287         -static OSErr
   288         -PrefsHandler(
   289         -    const AppleEvent *event,
   290         -    AppleEvent *reply,
   291         -    SRefCon handlerRefcon)
   292         -{
   293         -    Tcl_CmdInfo dummy;
   294         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   295         -
   296         -    if (interp &&
   297         -	    Tcl_GetCommandInfo(interp, "::tk::mac::ShowPreferences", &dummy)){
   298         -	int code = Tcl_EvalEx(interp, "::tk::mac::ShowPreferences", -1, TCL_EVAL_GLOBAL);
   299         -	if (code != TCL_OK) {
   300         -	    Tcl_BackgroundError(interp);
   301         -	}
   302         -    }
   303         -    return noErr;
   304         -}
   305         -
   306         -/*
   307         - *----------------------------------------------------------------------
   308         - *
   309         - * OdocHandler --
   310         - *
   311         - *	This is the 'odoc' core Apple event handler.
   312         - *
   313         - * Results:
   314         - *	None.
   315         - *
   316         - * Side effects:
   317         - *	None.
   318         - *
   319         - *----------------------------------------------------------------------
   320         - */
   321         -
   322         -static OSErr
   323         -OdocHandler(
   324         -    const AppleEvent *event,
   325         -    AppleEvent *reply,
   326         -    SRefCon handlerRefcon)
   327         -{
   328         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   329         -    AEDescList fileSpecList;
   330         -    FSRef file;
   331         -    DescType type;
   332         -    Size actual;
   333         -    long count, index;
   334         -    AEKeyword keyword;
   335         -    Tcl_DString command, pathName;
   336         -    Tcl_CmdInfo dummy;
   337         -    int code;
   338         -
   339         -    /*
   340         -     * Don't bother if we don't have an interp or the open document procedure
   341         -     * doesn't exist.
   342         -     */
   343         -
   344         -    if (!interp ||
   345         -	    !Tcl_GetCommandInfo(interp, "::tk::mac::OpenDocument", &dummy)) {
   346         -	return noErr;
   347         -    }
   348         -
   349         -    /*
   350         -     * If we get any errors while retrieving our parameters we just return with
   351         -     * no error.
   352         -     */
   353         -
   354         -    if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
   355         -	    &fileSpecList) != noErr) {
   356         -	return noErr;
   357         -    }
   358         -    if (MissedAnyParameters(event) != noErr) {
   359         -	return noErr;
   360         -    }
   361         -    if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
   362         -	return noErr;
   363         -    }
   364         -
   365         -    /*
   366         -     * Convert our parameters into a script to evaluate, skipping things that
   367         -     * we can't handle right.
   368         -     */
   369         -
   370         -    Tcl_DStringInit(&command);
   371         -    Tcl_DStringAppend(&command, "::tk::mac::OpenDocument", -1);
   372         -    for (index = 1; index <= count; index++) {
   373         -	if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
   374         -		&type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
   375         -	    continue;
   376         -	}
   377         -
   378         -	if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
   379         -	    Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
   380         -	    Tcl_DStringFree(&pathName);
   381         -	}
   382         -    }
   383         -
   384         -    /*
   385         -     * Now handle the event by evaluating a script.
   386         -     */
   387         -
   388         -    code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
   389         -	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
   390         -    if (code != TCL_OK) {
   391         -	Tcl_BackgroundError(interp);
   392         -    }
   393         -    Tcl_DStringFree(&command);
   394         -    return noErr;
   395         -}
   396         -
   397         -/*
   398         - *----------------------------------------------------------------------
   399         - *
   400         - * PrintHandler --
   401         - *
   402         - *	This is the 'pdoc' core Apple event handler.
   403         - *
   404         - * Results:
   405         - *	None.
   406         - *
   407         - * Side effects:
   408         - *	None.
   409         - *
   410         - *----------------------------------------------------------------------
   411         - */
   412         -
   413         -static OSErr
   414         -PrintHandler(
   415         -    const AppleEvent * event,
   416         -    AppleEvent * reply,
   417         -    SRefCon handlerRefcon)
   418         -{
   419         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   420         -    AEDescList fileSpecList;
   421         -    FSRef file;
   422         -    DescType type;
   423         -    Size actual;
   424         -    long count, index;
   425         -    AEKeyword keyword;
   426         -    Tcl_DString command, pathName;
   427         -    Tcl_CmdInfo dummy;
   428         -    int code;
   429         -
   430         -    /*
   431         -     * Don't bother if we don't have an interp or the print document procedure
   432         -     * doesn't exist.
   433         -     */
   434         -
   435         -    if (!interp ||
   436         -	    !Tcl_GetCommandInfo(interp, "::tk::mac::PrintDocument", &dummy)) {
   437         -	return noErr;
   438         -    }
   439         -
   440         -    /*
   441         -     * If we get any errors while retrieving our parameters we just return with
   442         -     * no error.
   443         -     */
   444         -
   445         -    if (ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList,
   446         -	    &fileSpecList) != noErr) {
   447         -	return noErr;
   448         -    }
   449         -    if (ChkErr(MissedAnyParameters, event) != noErr) {
   450         -	return noErr;
   451         -    }
   452         -    if (ChkErr(AECountItems, &fileSpecList, &count) != noErr) {
   453         -	return noErr;
   454         -    }
   455         -
   456         -    Tcl_DStringInit(&command);
   457         -    Tcl_DStringAppend(&command, "::tk::mac::PrintDocument", -1);
   458         -    for (index = 1; index <= count; index++) {
   459         -	if (ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword,
   460         -		&type, (Ptr) &file, sizeof(FSRef), &actual) != noErr) {
   461         -	    continue;
   462         -	}
   463         -
   464         -	if (ChkErr(FSRefToDString, &file, &pathName) == noErr) {
   465         -	    Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName));
   466         -	    Tcl_DStringFree(&pathName);
   467         -	}
   468         -    }
   469         -
   470         -    /*
   471         -     * Now handle the event by evaluating a script.
   472         -     */
   473         -
   474         -    code = Tcl_EvalEx(interp, Tcl_DStringValue(&command),
   475         -	    Tcl_DStringLength(&command), TCL_EVAL_GLOBAL);
   476         -    if (code != TCL_OK) {
   477         -	Tcl_BackgroundError(interp);
   478         -    }
   479         -    Tcl_DStringFree(&command);
   480         -    return noErr;
   481         -}
   482         -
   483         -/*
   484         - *----------------------------------------------------------------------
   485         - *
   486         - * ScriptHandler --
   487         - *
   488         - *	This handler process the script event.
   489         - *
   490         - * Results:
   491         - *	Schedules the given event to be processed.
   492         - *
   493         - * Side effects:
   494         - *	None.
   495         - *
   496         - *----------------------------------------------------------------------
   497         - */
   498         -
   499         -static OSErr
   500         -ScriptHandler(
   501         -    const AppleEvent *event,
   502         -    AppleEvent *reply,
   503         -    SRefCon handlerRefcon)
   504         -{
   505         -    OSStatus theErr;
   506         -    AEDescList theDesc;
   507         -    Size size;
   508         -    int tclErr = -1;
   509         -    Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon;
   510         -    char errString[128];
   511         -
   512         -    /*
   513         -     * The do script event receives one parameter that should be data or a
   514         -     * file.
   515         -     */
   516         -
   517         -    theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard,
   518         -	    &theDesc);
   519         -    if (theErr != noErr) {
   520         -	sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d",
   521         -		(int)theErr);
   522         -	theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString,
   523         -		strlen(errString));
   524         -    } else if (MissedAnyParameters(event)) {
   525         -	/*
   526         -	 * Return error if parameter is missing.
   527         -	 */
   528         -
   529         -	sprintf(errString, "AEDoScriptHandler: extra parameters");
   530         -	AEPutParamPtr(reply, keyErrorString, typeChar, errString,
   531         -		strlen(errString));
   532         -	theErr = -1771;
   533         -    } else if (theDesc.descriptorType == (DescType) typeAlias &&
   534         -	    AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, NULL,
   535         -	    0, &size) == noErr && size == sizeof(FSRef)) {
   536         -	/*
   537         -	 * We've had a file sent to us. Source it.
   538         -	 */
   539         -
   540         -	FSRef file;
   541         -	theErr = AEGetParamPtr(event, keyDirectObject, typeFSRef, NULL, &file,
   542         -		size, NULL);
   543         -	if (theErr == noErr) {
   544         -	    Tcl_DString scriptName;
   545         -
   546         -	    theErr = FSRefToDString(&file, &scriptName);
   547         -	    if (theErr == noErr) {
   548         -		tclErr = Tcl_EvalFile(interp, Tcl_DStringValue(&scriptName));
   549         -		Tcl_DStringFree(&scriptName);
   550         -	    } else {
   551         -		sprintf(errString, "AEDoScriptHandler: file not found");
   552         -		AEPutParamPtr(reply, keyErrorString, typeChar, errString,
   553         -			strlen(errString));
   554         -	    }
   555         -	}
   556         -    } else if (AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, NULL,
   557         -	    0, &size) == noErr && size) {
   558         -	/*
   559         -	 * We've had some data sent to us. Evaluate it.
   560         -	 */
   561         -
   562         -	char *data = ckalloc(size + 1);
   563         -	theErr = AEGetParamPtr(event, keyDirectObject, typeUTF8Text, NULL, data,
   564         -		size, NULL);
   565         -	if (theErr == noErr) {
   566         -	    tclErr = Tcl_EvalEx(interp, data, size, TCL_EVAL_GLOBAL);
   567         -	}
   568         -    } else {
   569         -	/*
   570         -	 * Umm, don't recognize what we've got...
   571         -	 */
   572         -
   573         -	sprintf(errString, "AEDoScriptHandler: invalid script type '%-4.4s', "
   574         -		"must be 'alis' or coercable to 'utf8'",
   575         -		(char*) &theDesc.descriptorType);
   576         -	AEPutParamPtr(reply, keyErrorString, typeChar, errString,
   577         -		strlen(errString));
   578         -	theErr = -1770;
   579         -    }
   580         -
   581         -    /*
   582         -     * If we actually go to run Tcl code - put the result in the reply.
   583         -     */
   584         -
   585         -    if (tclErr >= 0) {
   586         -	int reslen;
   587         -	const char *result =
   588         -		Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &reslen);
   589         -
   590         -	if (tclErr == TCL_OK) {
   591         -	    AEPutParamPtr(reply, keyDirectObject, typeChar, result, reslen);
   592         -	} else {
   593         -	    AEPutParamPtr(reply, keyErrorString, typeChar, result, reslen);
   594         -	    AEPutParamPtr(reply, keyErrorNumber, typeSInt32, (Ptr) &tclErr,
   595         -		    sizeof(int));
   596         -	}
   597         -    }
   598         -
   599         -    AEDisposeDesc(&theDesc);
   600         -    return theErr;
          466  +#ifdef __clang__
          467  +#pragma clang diagnostic pop
          468  +#endif
   601    469   }
   602    470   
   603    471   /*
   604    472    *----------------------------------------------------------------------
   605    473    *
   606    474    * ReallyKillMe --
   607    475    *
................................................................................
   612    480    *	Runs the "exit" command which might kill the shell.
   613    481    *
   614    482    * Side effects:
   615    483    *	None.
   616    484    *
   617    485    *----------------------------------------------------------------------
   618    486    */
   619         -
   620    487   static int
   621    488   ReallyKillMe(
   622    489       Tcl_Event *eventPtr,
   623    490       int flags)
   624    491   {
   625    492       Tcl_Interp *interp = ((KillEvent *) eventPtr)->interp;
   626    493       Tcl_CmdInfo dummy;
................................................................................
   662    529      OSStatus err;
   663    530   
   664    531      err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr,
   665    532   	    typeWildCard, &returnedType, NULL, 0, &actualSize);
   666    533   
   667    534      return (err != errAEDescNotFound);
   668    535   }
   669         -
   670         -/*
   671         - *----------------------------------------------------------------------
   672         - *
   673         - * FSRefToDString --
   674         - *
   675         - *	Get a POSIX path from an FSRef.
   676         - *
   677         - * Results:
   678         - *	In the parameter ds.
   679         - *
   680         - * Side effects:
   681         - *	None.
   682         - *
   683         - *----------------------------------------------------------------------
   684         - */
   685    536   
   686         -static OSStatus
   687         -FSRefToDString(
   688         -    const FSRef *fsref,
   689         -    Tcl_DString *ds)
   690         -{
   691         -    UInt8 fileName[PATH_MAX+1];
   692         -    OSStatus err;
   693         -
   694         -    err = ChkErr(FSRefMakePath, fsref, fileName, sizeof(fileName));
   695         -    if (err == noErr) {
   696         -	Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds);
   697         -    }
   698         -    return err;
   699         -}
   700         -
   701    537   /*
   702    538    * Local Variables:
   703    539    * mode: objc
   704    540    * c-basic-offset: 4
   705    541    * fill-column: 79
   706    542    * coding: utf-8
   707    543    * End:
   708    544    */

Changes to macosx/tkMacOSXMenu.c.

   788    788       inPostMenu = 1;
   789    789   
   790    790       int oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE);
   791    791       NSView *view = [win contentView];
   792    792       NSRect frame = NSMakeRect(x + 9, tkMacOSXZeroScreenHeight - y - 9, 1, 1);
   793    793   
   794    794       frame.origin = [view convertPoint:
   795         -	    [win convertScreenToBase:frame.origin] fromView:nil];
          795  +	    [win convertPointFromScreen:frame.origin] fromView:nil];
   796    796   
   797    797       NSMenu *menu = (NSMenu *) menuPtr->platformData;
   798    798       NSPopUpButtonCell *popUpButtonCell = [[NSPopUpButtonCell alloc]
   799    799   	    initTextCell:@"" pullsDown:NO];
   800    800   
   801    801       [popUpButtonCell setAltersStateOfSelectedItem:NO];
   802    802       [popUpButtonCell setMenu:menu];

Changes to macosx/tkMacOSXMouseEvent.c.

    22     22       Window window;
    23     23       Point global;
    24     24       Point local;
    25     25   } MouseEventData;
    26     26   
    27     27   static int		GenerateButtonEvent(MouseEventData *medPtr);
    28     28   static unsigned int	ButtonModifiers2State(UInt32 buttonState,
    29         -			    UInt32 keyModifiers);
    30         -
    31         -#pragma mark NSWindow(TKMouseEvent)
    32         -
    33         -/* Conversion of coordinates between window and screen */
    34         -@interface NSWindow(TKWm)
    35         -- (NSPoint) convertPointToScreen:(NSPoint)point;
    36         -- (NSPoint) convertPointFromScreen:(NSPoint)point;
    37         -@end
    38         -
    39         -@implementation NSWindow(TKMouseEvent)
    40         -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
    41         -- (NSPoint) convertPointToScreen: (NSPoint) point
    42         -{
    43         -    return [self convertBaseToScreen:point];
    44         -}
    45         -- (NSPoint) convertPointFromScreen: (NSPoint)point
    46         -{
    47         -    return [self convertScreenToBase:point];
    48         -}
    49         -@end
    50         -#else
    51         -- (NSPoint) convertPointToScreen: (NSPoint)point
    52         -{
    53         -    NSRect pointrect;
    54         -    pointrect.origin = point;
    55         -    pointrect.size.width = 0;
    56         -    pointrect.size.height = 0;
    57         -    return [self convertRectToScreen:pointrect].origin;
    58         -}
    59         -- (NSPoint) convertPointFromScreen: (NSPoint)point
    60         -{
    61         -    NSRect pointrect;
    62         -    pointrect.origin = point;
    63         -    pointrect.size.width = 0;
    64         -    pointrect.size.height = 0;
    65         -    return [self convertRectFromScreen:pointrect].origin;
    66         -}
    67         -@end
    68         -#endif
    69         -
    70         -#pragma mark -
    71         -
           29  +					      UInt32 keyModifiers);
    72     30   
    73     31   #pragma mark TKApplication(TKMouseEvent)
    74     32   
    75     33   enum {
    76     34       NSWindowWillMoveEventType = 20
    77     35   };
           36  +
    78     37   /*
    79     38    * In OS X 10.6 an NSEvent of type NSMouseMoved would always have a non-Nil
    80         - * window attribute when the mouse was inside a window.  As of 10.8 this
    81         - * behavior had changed.  The new behavior was that if the mouse were ever
    82         - * moved outside of a window, all subsequent NSMouseMoved NSEvents would have a
    83         - * Nil window attribute.  To work around this we remember which window the
    84         - * mouse is in by saving the window attribute of each NSEvent of type
    85         - * NSMouseEntered.  If an NSEvent has a Nil window attribute we use our saved
    86         - * window.  It may be the case that the mouse has actually left the window, but
    87         - * this is harmless since Tk will ignore the event in that case.
           39  + * window attribute pointing to the active window.  As of 10.8 this behavior
           40  + * had changed.  The new behavior was that if the mouse were ever moved outside
           41  + * of a window, all subsequent NSMouseMoved NSEvents would have a Nil window
           42  + * attribute.  To work around this the TKApplication remembers the last non-Nil
           43  + * window that it received in a mouse event. If it receives an NSEvent with a
           44  + * Nil window attribute then the saved window is used.
    88     45    */
    89     46   
    90     47   @implementation TKApplication(TKMouseEvent)
    91     48   - (NSEvent *)tkProcessMouseEvent:(NSEvent *)theEvent {
    92     49   #ifdef TK_MAC_DEBUG_EVENTS
    93     50       TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
    94     51   #endif
    95         -    id          win;
    96         -    NSEventType	type = [theEvent type];
           52  +    NSWindow*    eventWindow = [theEvent window];
           53  +    NSEventType	 eventType = [theEvent type];
    97     54   #if 0
    98     55       NSTrackingArea  *trackingArea = nil;
    99     56       NSInteger eventNumber, clickCount, buttonNumber;
   100     57   #endif
   101     58   
   102         -    switch (type) {
           59  +    switch (eventType) {
   103     60       case NSMouseEntered:
   104     61   	/* Remember which window has the mouse. */
   105     62   	if (_windowWithMouse) {
   106     63   	    [_windowWithMouse release];
   107     64   	}
   108     65   	_windowWithMouse = [theEvent window];
   109     66   	if (_windowWithMouse) {
................................................................................
   129     86   	    buttonNumber = [theEvent buttonNumber];
   130     87   	}
   131     88   #endif
   132     89       case NSTabletPoint:
   133     90       case NSTabletProximity:
   134     91       case NSScrollWheel:
   135     92           break;
   136         -
   137     93       default: /* Unrecognized mouse event. */
   138     94   	return theEvent;
   139     95       }
           96  +
           97  +    /* Remember the window in case we need it next time. */
           98  +    if (eventWindow && eventWindow != _windowWithMouse) {
           99  +	if (_windowWithMouse) {
          100  +	    [_windowWithMouse release];
          101  +	}
          102  +	_windowWithMouse = eventWindow;
          103  +	[_windowWithMouse retain];
          104  +    }
   140    105   
   141    106       /* Create an Xevent to add to the Tk queue. */
   142         -    win = [theEvent window];
   143         -    NSWindow *nswindow = (NSWindow *)win;
   144    107       NSPoint global, local = [theEvent locationInWindow];
   145         -    if (win) { /* local will be in window coordinates. */
   146         -	global = [nswindow convertPointToScreen: local];
   147         -	local.y = [win frame].size.height - local.y;
          108  +    if (eventWindow) { /* local will be in window coordinates. */
          109  +	global = [eventWindow convertPointToScreen: local];
          110  +	local.y = [eventWindow frame].size.height - local.y;
   148    111   	global.y = tkMacOSXZeroScreenHeight - global.y;
   149    112       } else { /* local will be in screen coordinates. */
   150    113   	if (_windowWithMouse ) {
   151         -	    win = _windowWithMouse;
          114  +	    eventWindow = _windowWithMouse;
   152    115   	    global = local;
   153         -	    local = [nswindow convertPointFromScreen: local];
   154         -	    local.y = [win frame].size.height - local.y;
          116  +	    local = [eventWindow convertPointFromScreen: local];
          117  +	    local.y = [eventWindow frame].size.height - local.y;
   155    118   	    global.y = tkMacOSXZeroScreenHeight - global.y;
   156    119   	} else { /* We have no window. Use the screen???*/
   157    120   	    local.y = tkMacOSXZeroScreenHeight - local.y;
   158    121   	    global = local;
   159    122   	}
   160    123       }
   161    124   
   162         -    Window window = TkMacOSXGetXWindow(win);
          125  +    Window window = TkMacOSXGetXWindow(eventWindow);
   163    126       Tk_Window tkwin = window ? Tk_IdToWindow(TkGetDisplayList()->display,
   164    127   	    window) : NULL;
   165    128       if (!tkwin) {
   166    129   	tkwin = TkMacOSXGetCapture();
   167    130       }
   168    131       if (!tkwin) {
   169    132   	return theEvent; /* Give up.  No window for this event. */
................................................................................
   183    146       UInt32 buttons;
   184    147       OSStatus err = GetEventParameter(eventRef, kEventParamMouseChord,
   185    148   	    typeUInt32, NULL, sizeof(UInt32), NULL, &buttons);
   186    149       if (err == noErr) {
   187    150   	state |= (buttons & ((1<<5) - 1)) << 8;
   188    151       } else {
   189    152   	if (button < 5) {
   190         -	    switch (type) {
          153  +	    switch (eventType) {
   191    154   	    case NSLeftMouseDown:
   192    155   	    case NSRightMouseDown:
   193    156   	    case NSLeftMouseDragged:
   194    157   	    case NSRightMouseDragged:
   195    158   	    case NSOtherMouseDown:
   196    159   		state |= 1 << (button + 8);
   197    160   		break;
................................................................................
   220    183       if (modifiers & NSNumericPadKeyMask) {
   221    184   	state |= Mod3Mask;
   222    185       }
   223    186       if (modifiers & NSFunctionKeyMask) {
   224    187   	state |= Mod4Mask;
   225    188       }
   226    189   
   227         -    if (type != NSScrollWheel) {
          190  +    if (eventType != NSScrollWheel) {
   228    191   #ifdef TK_MAC_DEBUG_EVENTS
   229    192   	TKLog(@"UpdatePointer %p x %f.0 y %f.0 %d", tkwin, global.x, global.y, state);
   230    193   #endif
   231    194   	Tk_UpdatePointer(tkwin, global.x, global.y, state);
   232         -    } else {
          195  +    } else { /* handle scroll wheel event */
   233    196   	CGFloat delta;
   234    197   	int coarseDelta;
   235    198   	XEvent xEvent;
   236    199   
   237    200   	xEvent.type = MouseWheelEvent;
   238    201   	xEvent.xbutton.x = local.x;
   239    202   	xEvent.xbutton.y = local.y;
................................................................................
   241    204   	xEvent.xbutton.y_root = global.y;
   242    205   	xEvent.xany.send_event = false;
   243    206   	xEvent.xany.display = Tk_Display(tkwin);
   244    207   	xEvent.xany.window = Tk_WindowId(tkwin);
   245    208   
   246    209   	delta = [theEvent deltaY];
   247    210   	if (delta != 0.0) {
   248         -	    coarseDelta = (delta > -1.0 && delta < 1.0) ? (signbit(delta) ? -1 : 1) : lround(delta);
          211  +	    coarseDelta = (delta > -1.0 && delta < 1.0) ?
          212  +		(signbit(delta) ? -1 : 1) : lround(delta);
   249    213   	    xEvent.xbutton.state = state;
   250    214   	    xEvent.xkey.keycode = coarseDelta;
   251    215   	    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
   252    216   	    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
   253    217   	}
   254    218   	delta = [theEvent deltaX];
   255    219   	if (delta != 0.0) {
   256         -	    coarseDelta = (delta > -1.0 && delta < 1.0) ? (signbit(delta) ? -1 : 1) : lround(delta);
          220  +	    coarseDelta = (delta > -1.0 && delta < 1.0) ?
          221  +		(signbit(delta) ? -1 : 1) : lround(delta);
   257    222   	    xEvent.xbutton.state = state | ShiftMask;
   258    223   	    xEvent.xkey.keycode = coarseDelta;
   259    224   	    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
   260    225   	    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
   261    226   	}
   262    227       }
   263    228       return theEvent;
................................................................................
   420    385   	if (getLocal) {
   421    386   	    MacDrawable *macWin = (MacDrawable *) w;
   422    387   	    NSWindow *win = TkMacOSXDrawableWindow(w);
   423    388   
   424    389   	    if (win) {
   425    390   		NSPoint local;
   426    391   
   427         -		local = [win convertScreenToBase:global];
          392  +		local = [win convertPointFromScreen:global];
   428    393   		local.y = [win frame].size.height - local.y;
   429    394   		if (macWin->winPtr && macWin->winPtr->wmInfoPtr) {
   430    395   		    local.x -= macWin->winPtr->wmInfoPtr->xInParent;
   431    396   		    local.y -= macWin->winPtr->wmInfoPtr->yInParent;
   432    397   		}
   433    398   		*win_x_return = local.x;
   434    399   		*win_y_return = local.y;
................................................................................
   518    483       med.global.h = x;
   519    484       med.global.v = y;
   520    485       med.local = med.global;
   521    486   
   522    487       if (win) {
   523    488   	NSPoint local = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);
   524    489   
   525         -	local = [win convertScreenToBase:local];
          490  +	local = [win convertPointFromScreen:local];
   526    491   	local.y = [win frame].size.height - local.y;
   527    492   	if (macWin->winPtr && macWin->winPtr->wmInfoPtr) {
   528    493   	    local.x -= macWin->winPtr->wmInfoPtr->xInParent;
   529    494   	    local.y -= macWin->winPtr->wmInfoPtr->yInParent;
   530    495   	}
   531    496   	med.local.h = local.x;
   532    497   	med.local.v = tkMacOSXZeroScreenHeight - local.y;

Changes to macosx/tkMacOSXPrivate.h.

   290    290   @interface TKApplication(TKMenu)
   291    291   - (void)tkSetMainMenu:(TKMenu *)menu;
   292    292   @end
   293    293   @interface TKApplication(TKClipboard)
   294    294   - (void)tkProvidePasteboard:(TkDisplay *)dispPtr;
   295    295   - (void)tkCheckPasteboard;
   296    296   @end
          297  +@interface TKApplication(TKHLEvents)
          298  +- (void) terminate: (id) sender;
          299  +- (void) preferences: (id) sender;
          300  +- (void) handleQuitApplicationEvent:   (NSAppleEventDescriptor *)event 
          301  +		     withReplyEvent:   (NSAppleEventDescriptor *)replyEvent;
          302  +- (void) handleOpenApplicationEvent:   (NSAppleEventDescriptor *)event 
          303  +		     withReplyEvent:   (NSAppleEventDescriptor *)replyEvent;
          304  +- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event 
          305  +		       withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
          306  +- (void) handleShowPreferencesEvent:   (NSAppleEventDescriptor *)event
          307  +		     withReplyEvent:   (NSAppleEventDescriptor *)replyEvent;
          308  +- (void) handleOpenDocumentsEvent:     (NSAppleEventDescriptor *)event 
          309  +		   withReplyEvent:     (NSAppleEventDescriptor *)replyEvent;
          310  +- (void) handlePrintDocumentsEvent:    (NSAppleEventDescriptor *)event 
          311  +		   withReplyEvent:     (NSAppleEventDescriptor *)replyEvent;
          312  +- (void) handleDoScriptEvent:          (NSAppleEventDescriptor *)event 
          313  +		   withReplyEvent:     (NSAppleEventDescriptor *)replyEvent;
          314  +@end
   297    315   
   298    316   VISIBILITY_HIDDEN
   299    317   @interface TKContentView : NSView <NSTextInput> {
   300    318   @private
   301    319     /*Remove private API calls.*/
   302    320   #if 0
   303    321       id _savedSubviews;
................................................................................
   322    340   - (BOOL) acceptsFirstResponder;
   323    341   - (void) keyDown: (NSEvent *) theEvent;
   324    342   @end
   325    343   
   326    344   VISIBILITY_HIDDEN
   327    345   @interface TKWindow : NSWindow
   328    346   @end
          347  +
          348  +@interface NSWindow(TKWm)
          349  +- (NSPoint) convertPointToScreen:(NSPoint)point;
          350  +- (NSPoint) convertPointFromScreen:(NSPoint)point;
          351  +@end
   329    352   
   330    353   #pragma mark NSMenu & NSMenuItem Utilities
   331    354   
   332    355   @interface NSMenu(TKUtils)
   333    356   + (id)menuWithTitle:(NSString *)title;
   334    357   + (id)menuWithTitle:(NSString *)title menuItems:(NSArray *)items;
   335    358   + (id)menuWithTitle:(NSString *)title submenus:(NSArray *)submenus;
................................................................................
   351    374   	keyEquivalent:(NSString *)keyEquivalent
   352    375   	keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask;
   353    376   + (id)itemWithTitle:(NSString *)title action:(SEL)action
   354    377   	target:(id)target keyEquivalent:(NSString *)keyEquivalent
   355    378   	keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask;
   356    379   @end
   357    380   
   358         -
   359         -/* Helper functions from tkMacOSXDeprecations.c */
   360         -
   361         -extern NSPoint convertWindowToScreen( NSWindow *window, NSPoint point);
   362         -
   363    381   #endif /* _TKMACPRIV */

Changes to macosx/tkMacOSXWindowEvent.c.

   743    743    *
   744    744    *----------------------------------------------------------------------
   745    745    */
   746    746   
   747    747   int
   748    748   Tk_MacOSXIsAppInFront(void)
   749    749   {
   750         -    OSStatus err;
          750  +    Boolean isFrontProcess = true;
          751  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
   751    752       ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess};
   752         -    Boolean isFrontProcess = true;
   753    753   
   754         -    err = ChkErr(GetFrontProcess, &frontPsn);
   755         -    if (err == noErr) {
   756         -	ChkErr(SameProcess, &frontPsn, &ourPsn, &isFrontProcess);
          754  +    if (noErr == GetFrontProcess(&frontPsn)){
          755  +	SameProcess(&frontPsn, &ourPsn, &isFrontProcess);
   757    756       }
   758         -
          757  +#else
          758  +    isFrontProcess = [NSRunningApplication currentApplication].active;
          759  +#endif
   759    760       return (isFrontProcess == true);
   760    761   }
   761    762   
   762    763   #pragma mark TKContentView
   763    764   
   764    765   #import <ApplicationServices/ApplicationServices.h>
   765    766   

Changes to macosx/tkMacOSXWm.c.

   195    195   
   196    196   /*
   197    197    * Hash table for Mac Window -> TkWindow mapping.
   198    198    */
   199    199   
   200    200   static Tcl_HashTable windowTable;
   201    201   static int windowHashInit = false;
          202  +
          203  +
          204  +
          205  +#pragma mark NSWindow(TKWm)
          206  +
          207  +/*
          208  + * Conversion of coordinates between window and screen.
          209  + */
          210  +
          211  +@implementation NSWindow(TKWm)
          212  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
          213  +- (NSPoint) convertPointToScreen: (NSPoint) point
          214  +{
          215  +    return [self convertBaseToScreen:point];
          216  +}
          217  +- (NSPoint) convertPointFromScreen: (NSPoint)point
          218  +{
          219  +    return [self convertScreenToBase:point];
          220  +}
          221  +@end
          222  +#else
          223  +- (NSPoint) convertPointToScreen: (NSPoint) point
          224  +{
          225  +    NSRect pointrect;
          226  +    pointrect.origin = point;
          227  +    pointrect.size.width = 0;
          228  +    pointrect.size.height = 0;
          229  +    return [self convertRectToScreen:pointrect].origin;
          230  +}
          231  +- (NSPoint) convertPointFromScreen: (NSPoint)point
          232  +{
          233  +    NSRect pointrect;
          234  +    pointrect.origin = point;
          235  +    pointrect.size.width = 0;
          236  +    pointrect.size.height = 0;
          237  +    return [self convertRectFromScreen:pointrect].origin;
          238  +}
          239  +@end
          240  +#endif
          241  +
          242  +#pragma mark -
          243  +
   202    244   
   203    245   /*
   204    246    * Forward declarations for procedures defined in this file:
   205    247    */
   206    248   
   207    249   static NSRect		InitialWindowBounds(TkWindow *winPtr,
   208    250   			    NSWindow *macWindow);

Changes to macosx/tkMacOSXXStubs.c.

   177    177   	display->proto_minor_version = [[cgVers objectAtIndex:2] integerValue];
   178    178       }
   179    179       if (!vendor[0]) {
   180    180   	snprintf(vendor, sizeof(vendor), "Apple AppKit %g",
   181    181   		NSAppKitVersionNumber);
   182    182       }
   183    183       display->vendor = vendor;
   184         -    Gestalt(gestaltSystemVersion, (SInt32 *) &display->release);
          184  +    {
          185  +	int major, minor, patch;
          186  +
          187  +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
          188  +	Gestalt(gestaltSystemVersionMajor, (SInt32*)&major);
          189  +	Gestalt(gestaltSystemVersionMinor, (SInt32*)&minor);
          190  +	Gestalt(gestaltSystemVersionBugFix, (SInt32*)&patch);
          191  +#else
          192  +	NSOperatingSystemVersion systemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
          193  +	major = systemVersion.majorVersion;
          194  +	minor = systemVersion.minorVersion;
          195  +	patch = systemVersion.patchVersion;
          196  +#endif
          197  +	display->release = major << 16 | minor << 8 | patch;
          198  +    }
   185    199   
   186    200       /*
   187    201        * These screen bits never change
   188    202        */
   189    203       screen->root	= ROOT_ID;
   190    204       screen->display	= display;
   191    205       screen->black_pixel = 0x00000000 | PIXEL_MAGIC << 24;

Changes to unix/configure.

  7082   7082   
  7083   7083       if test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""; then
  7084   7084   
  7085   7085           LIB_SUFFIX=${SHARED_LIB_SUFFIX}
  7086   7086           MAKE_LIB='${SHLIB_LD} -o [email protected] ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
  7087   7087           if test "${SHLIB_SUFFIX}" = ".dll"; then
  7088   7088   
  7089         -            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)"'
         7089  +            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)";if test -f $(LIB_FILE).a; then $(INSTALL_DATA) $(LIB_FILE).a "$(LIB_INSTALL_DIR)"; fi;'
  7090   7090               DLL_INSTALL_DIR="\$(BIN_INSTALL_DIR)"
  7091   7091   
  7092   7092   else
  7093   7093   
  7094   7094               INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)/$(LIB_FILE)"'
  7095   7095   
  7096   7096   fi

Changes to unix/tcl.m4.

  2065   2065   	UNSHARED_LIB_SUFFIX='${VERSION}.a'])
  2066   2066       DLL_INSTALL_DIR="\$(LIB_INSTALL_DIR)"
  2067   2067   
  2068   2068       AS_IF([test "${SHARED_BUILD}" = 1 -a "${SHLIB_SUFFIX}" != ""], [
  2069   2069           LIB_SUFFIX=${SHARED_LIB_SUFFIX}
  2070   2070           MAKE_LIB='${SHLIB_LD} -o [$]@ ${OBJS} ${SHLIB_LD_LIBS} ${TCL_SHLIB_LD_EXTRAS} ${TK_SHLIB_LD_EXTRAS} ${LD_SEARCH_FLAGS}'
  2071   2071           AS_IF([test "${SHLIB_SUFFIX}" = ".dll"], [
  2072         -            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)"'
         2072  +            INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(BIN_INSTALL_DIR)/$(LIB_FILE)";if test -f $(LIB_FILE).a; then $(INSTALL_DATA) $(LIB_FILE).a "$(LIB_INSTALL_DIR)"; fi;'
  2073   2073               DLL_INSTALL_DIR="\$(BIN_INSTALL_DIR)"
  2074   2074           ], [
  2075   2075               INSTALL_LIB='$(INSTALL_LIBRARY) $(LIB_FILE) "$(LIB_INSTALL_DIR)/$(LIB_FILE)"'
  2076   2076           ])
  2077   2077       ], [
  2078   2078           LIB_SUFFIX=${UNSHARED_LIB_SUFFIX}
  2079   2079