Tk Source Code

Check-in [764eaf89]
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:Mitigate future merge conflict headaches.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-6-branch
Files: files | file ages | folders
SHA3-256: 764eaf89d5376b14457aeb9f68224ae740cfda8e367ee332431609d416281116
User & Date: culler 2019-04-17 14:05:33
Context
2019-04-17
14:30
Add a couple of blank lines. check-in: 3a29febb user: culler tags: core-8-6-branch
14:05
Mitigate future merge conflict headaches. check-in: 764eaf89 user: culler tags: core-8-6-branch
2019-04-15
20:48
Adjust conditional code to fix compiler warnings on macOS 10.9. check-in: e3a0be7d user: culler tags: core-8-6-branch
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXButton.c.

     1      1   /*
     2      2    * tkMacOSXButton.c --
     3      3    *
     4         - *	This file implements the Macintosh specific portion of the
     5         - *	button widgets.
            4  + *	This file implements the Macintosh specific portion of the button
            5  + *	widgets.
     6      6    *
     7      7    * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
     8      8    * Copyright 2001, Apple Computer, Inc.
     9      9    * Copyright (c) 2006-2007 Daniel A. Steffen <[email protected]>
    10     10    * Copyright 2007 Revar Desmera.
    11     11    * Copyright 2015 Kevin Walzer/WordTech Communications LLC.
    12     12    * Copyright 2015 Marc Culler.
................................................................................
    66     66       Tcl_TimerToken defaultPulseHandler;
    67     67   } MacButton;
    68     68   
    69     69   /*
    70     70    * Forward declarations for procedures defined later in this file:
    71     71    */
    72     72   
    73         -
    74         -static void ButtonBackgroundDrawCB (const HIRect *btnbounds, MacButton *ptr,
    75         -        SInt16 depth, Boolean isColorDev);
    76         -static void ButtonContentDrawCB (const HIRect *bounds, ThemeButtonKind kind,
    77         -        const HIThemeButtonDrawInfo *info, MacButton *ptr, SInt16 depth,
    78         -	Boolean isColorDev);
    79         -static void ButtonEventProc(ClientData clientData, XEvent *eventPtr);
    80         -static void TkMacOSXComputeButtonParams (TkButton * butPtr, ThemeButtonKind* btnkind,
    81         -	HIThemeButtonDrawInfo* drawinfo);
    82         -static int TkMacOSXComputeButtonDrawParams (TkButton * butPtr, DrawParams * dpPtr);
    83         -static void TkMacOSXDrawButton (MacButton *butPtr, GC gc, Pixmap pixmap);
    84         -static void DrawButtonImageAndText(TkButton* butPtr);
    85         -static void PulseDefaultButtonProc(ClientData clientData);
    86         -
           73  +static void		ButtonBackgroundDrawCB(const HIRect *btnbounds,
           74  +			    MacButton *ptr, SInt16 depth, Boolean isColorDev);
           75  +static void		ButtonContentDrawCB(const HIRect *bounds,
           76  +			    ThemeButtonKind kind,
           77  +			    const HIThemeButtonDrawInfo *info, MacButton *ptr,
           78  +			    SInt16 depth, Boolean isColorDev);
           79  +static void		ButtonEventProc(ClientData clientData,
           80  +			    XEvent *eventPtr);
           81  +static void		TkMacOSXComputeButtonParams(TkButton *butPtr,
           82  +			    ThemeButtonKind *btnkind,
           83  +			    HIThemeButtonDrawInfo *drawinfo);
           84  +static int		TkMacOSXComputeButtonDrawParams(TkButton *butPtr,
           85  +			    DrawParams * dpPtr);
           86  +static void		TkMacOSXDrawButton(MacButton *butPtr, GC gc,
           87  +			    Pixmap pixmap);
           88  +static void		DrawButtonImageAndText(TkButton *butPtr);
           89  +static void		PulseDefaultButtonProc(ClientData clientData);
    87     90   
    88     91   /*
    89     92    * The class procedure table for the button widgets.
    90     93    */
    91     94   
    92     95   const Tk_ClassProcs tkpButtonProcs = {
    93     96       sizeof(Tk_ClassProcs),	/* size */
    94     97       TkButtonWorldChanged,	/* worldChangedProc */
    95     98   };
    96     99   
    97    100   static int bCount;
    98         -
          101  +
    99    102   /*
   100    103    *----------------------------------------------------------------------
   101    104    *
   102    105    * TkpButtonSetDefaults --
   103    106    *
   104         - *	This procedure is invoked before option tables are created for
   105         - *	buttons. It modifies some of the default values to match the current
   106         - *	values defined for this platform.
          107  + *	This procedure is invoked before option tables are created for buttons.
          108  + *	It modifies some of the default values to match the current values
          109  + *	defined for this platform.
   107    110    *
   108    111    * Results:
   109    112    *	Some of the default values in *specPtr are modified.
   110    113    *
   111    114    * Side effects:
   112    115    *	Updates some of.
   113    116    *
   114    117    *----------------------------------------------------------------------
   115    118    */
   116    119   
   117    120   void
   118    121   TkpButtonSetDefaults()
   119    122   {
   120         -/*No-op.*/
          123  +    /*No-op.*/
   121    124   }
   122         -
   123    125   
   124    126   /*
   125    127    *----------------------------------------------------------------------
   126    128    *
   127    129    * TkpCreateButton --
   128    130    *
   129    131    *	Allocate a new TkButton structure.
................................................................................
   137    139    *----------------------------------------------------------------------
   138    140    */
   139    141   
   140    142   TkButton *
   141    143   TkpCreateButton(
   142    144       Tk_Window tkwin)
   143    145   {
   144         -    MacButton *macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton));
          146  +    MacButton *macButtonPtr = ckalloc(sizeof(MacButton));
   145    147   
   146    148       Tk_CreateEventHandler(tkwin, ActivateMask,
   147         -	    ButtonEventProc, (ClientData) macButtonPtr);
          149  +	    ButtonEventProc, macButtonPtr);
   148    150       macButtonPtr->id = bCount++;
   149    151       macButtonPtr->flags = FIRST_DRAW;
   150    152       macButtonPtr->btnkind = kThemePushButton;
   151    153       macButtonPtr->defaultPulseHandler = NULL;
   152    154       bzero(&macButtonPtr->drawinfo, sizeof(macButtonPtr->drawinfo));
   153    155       bzero(&macButtonPtr->lastdrawinfo, sizeof(macButtonPtr->lastdrawinfo));
   154    156   
   155         -    return (TkButton *)macButtonPtr;
          157  +    return (TkButton *) macButtonPtr;
   156    158   }
   157    159   
   158    160   /*
   159    161    *----------------------------------------------------------------------
   160    162    *
   161    163    * TkpDisplayButton --
   162    164    *
   163         - *	This procedure is invoked to display a button widget. It is
   164         - *	normally invoked as an idle handler.
          165  + *	This procedure is invoked to display a button widget. It is normally
          166  + *	invoked as an idle handler.
   165    167    *
   166    168    * Results:
   167    169    *	None.
   168    170    *
   169    171    * Side effects:
   170         - *	Commands are output to X to display the button in its
   171         - *	current mode. The REDRAW_PENDING flag is cleared.
          172  + *	Commands are output to X to display the button in its current mode. The
          173  + *	REDRAW_PENDING flag is cleared.
   172    174    *
   173    175    *----------------------------------------------------------------------
   174    176    */
   175    177   
   176    178   void
   177    179   TkpDisplayButton(
   178    180       ClientData clientData)	/* Information about widget. */
   179    181   {
   180         -    MacButton *macButtonPtr = (MacButton *) clientData;
   181         -    TkButton *butPtr = (TkButton *) clientData;
          182  +    MacButton *macButtonPtr = clientData;
          183  +    TkButton *butPtr = clientData;
   182    184       Tk_Window tkwin = butPtr->tkwin;
   183    185       Pixmap pixmap;
   184    186       DrawParams* dpPtr = &macButtonPtr->drawParams;
   185    187       int needhighlight = 0;
   186    188   
   187    189       butPtr->flags &= ~REDRAW_PENDING;
   188    190       if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
   189    191   	return;
   190    192       }
   191    193       pixmap = (Pixmap) Tk_WindowId(tkwin);
   192    194       TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin));
   193    195   
   194         -    if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr) ) {
          196  +    if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr)) {
   195    197   	macButtonPtr->useTkText = 0;
   196    198       } else {
   197    199   	macButtonPtr->useTkText = 1;
   198    200       }
   199    201   
   200         -
   201    202       /*
   202         -     * Set up clipping region. Make sure the we are using the port
   203         -     * for this button, or we will set the wrong window's clip.
          203  +     * Set up clipping region. Make sure the we are using the port for this
          204  +     * button, or we will set the wrong window's clip.
   204    205        */
   205    206   
   206    207       if (macButtonPtr->useTkText) {
   207    208   	if (butPtr->type == TYPE_BUTTON) {
   208    209   	    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
   209    210   		    Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
   210    211   	} else {
   211    212   	    Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
   212    213   		    Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
   213    214   	}
   214    215   
   215         -        /* Display image or bitmap or text for labels or custom controls.  */
          216  +        /*
          217  +	 * Display image or bitmap or text for labels or custom controls.
          218  +	 */
          219  +
   216    220   	DrawButtonImageAndText(butPtr);
   217         -        needhighlight  = 1;
          221  +        needhighlight = 1;
   218    222       } else {
   219         -        /* Draw the native portion of the buttons. */
          223  +        /*
          224  +	 * Draw the native portion of the buttons.
          225  +	 */
          226  +
   220    227           TkMacOSXDrawButton(macButtonPtr, dpPtr->gc, pixmap);
   221    228   
   222         -        /* Draw highlight border, if needed. */
          229  +        /*
          230  +	 * Ask for the highlight border, if needed.
          231  +	 */
          232  +
   223    233           if (butPtr->highlightWidth < 3) {
   224    234               needhighlight = 1;
   225    235           }
   226    236       }
   227    237   
   228         -    /* Draw highlight border, if needed. */
   229         -    if (needhighlight) {
   230         -        if ((butPtr->flags & GOT_FOCUS)) {
   231         -            Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
          238  +    /*
          239  +     * Draw highlight border.
          240  +     */
          241  +
          242  +    if (needhighlight && (butPtr->flags & GOT_FOCUS)) {
          243  +	Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
   232    244                   Tk_Width(tkwin), Tk_Height(tkwin),
   233    245                   butPtr->highlightWidth, TK_RELIEF_SOLID);
   234         -        }
   235    246       }
   236    247   }
   237    248   
   238    249   /*
   239    250    *----------------------------------------------------------------------
   240    251    *
   241    252    * TkpComputeButtonGeometry --
   242    253    *
   243         - *	After changes in a button's text or bitmap, this procedure
   244         - *	recomputes the button's geometry and passes this information
   245         - *	along to the geometry manager for the window.
          254  + *	After changes in a button's text or bitmap, this procedure recomputes
          255  + *	the button's geometry and passes this information along to the geometry
          256  + *	manager for the window.
   246    257    *
   247    258    * Results:
   248    259    *	None.
   249    260    *
   250    261    * Side effects:
   251    262    *	The button's window may change size.
   252    263    *
................................................................................
   255    266   
   256    267   void
   257    268   TkpComputeButtonGeometry(
   258    269       TkButton *butPtr)		/* Button whose geometry may have changed. */
   259    270   {
   260    271       int width = 0, height = 0, charWidth = 1, haveImage = 0, haveText = 0;
   261    272       int txtWidth = 0, txtHeight = 0;
   262         -    MacButton *mbPtr = (MacButton*)butPtr;
          273  +    MacButton *mbPtr = (MacButton *) butPtr;
   263    274       Tk_FontMetrics fm;
   264    275       char *text = Tcl_GetString(butPtr->textPtr);
   265    276   
   266    277       TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
   267    278   
   268    279       /*
   269    280        * If the indicator is on, get its size.
   270    281        */
   271    282   
   272    283       if (butPtr->indicatorOn) {
   273         -      switch (butPtr->type) {
   274         -      case TYPE_RADIO_BUTTON:
   275         -	GetThemeMetric(kThemeMetricRadioButtonWidth, (SInt32 *)&butPtr->indicatorDiameter);
   276         -	  break;
   277         -      case TYPE_CHECK_BUTTON:
   278         -	GetThemeMetric(kThemeMetricCheckBoxWidth, (SInt32 *)&butPtr->indicatorDiameter);
   279         -	  break;
   280         -      default:
   281         -	break;
   282         -      }
   283         -      /* Allow 2px extra space next to the indicator. */
   284         -      butPtr->indicatorSpace = butPtr->indicatorDiameter + 2;
          284  +	switch (butPtr->type) {
          285  +	case TYPE_RADIO_BUTTON:
          286  +	    GetThemeMetric(kThemeMetricRadioButtonWidth,
          287  +		    (SInt32 *) &butPtr->indicatorDiameter);
          288  +	    break;
          289  +	case TYPE_CHECK_BUTTON:
          290  +	    GetThemeMetric(kThemeMetricCheckBoxWidth,
          291  +		    (SInt32 *) &butPtr->indicatorDiameter);
          292  +	    break;
          293  +	default:
          294  +	    break;
          295  +	}
          296  +
          297  +	/*
          298  +	 * Allow 2px extra space next to the indicator.
          299  +	 */
          300  +
          301  +	butPtr->indicatorSpace = butPtr->indicatorDiameter + 2;
   285    302       } else {
   286         -      butPtr->indicatorSpace = 0;
   287         -      butPtr->indicatorDiameter = 0;
          303  +	butPtr->indicatorSpace = 0;
          304  +	butPtr->indicatorDiameter = 0;
   288    305       }
   289    306   
   290    307       if (butPtr->image != NULL) {
   291    308   	Tk_SizeOfImage(butPtr->image, &width, &height);
   292    309   	haveImage = 1;
   293    310       } else if (butPtr->bitmap != None) {
   294    311   	Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
................................................................................
   304    321   	txtWidth = butPtr->textWidth + 2*butPtr->padX;
   305    322   	txtHeight = butPtr->textHeight + 2*butPtr->padY;
   306    323   	haveText = 1;
   307    324       }
   308    325   
   309    326       if (haveImage && haveText) { /* Image and Text */
   310    327   	switch ((enum compound) butPtr->compound) {
   311         -	    case COMPOUND_TOP:
   312         -	    case COMPOUND_BOTTOM:
   313         -
   314         -		/*
   315         -		 * Image is above or below text.
   316         -		 */
   317         -
   318         -		height += txtHeight + butPtr->padY;
   319         -		width = (width > txtWidth ? width : txtWidth);
   320         -		break;
   321         -	    case COMPOUND_LEFT:
   322         -	    case COMPOUND_RIGHT:
   323         -
   324         -		/*
   325         -		 * Image is left or right of text.
   326         -		 */
   327         -
   328         -		width += txtWidth + 2*butPtr->padX;
   329         -		height = (height > txtHeight ? height : txtHeight);
   330         -		break;
   331         -	    case COMPOUND_CENTER:
   332         -
   333         -		/*
   334         -		 * Image and text are superimposed.
   335         -		 */
   336         -
   337         -		width = (width > txtWidth ? width : txtWidth);
   338         -		height = (height > txtHeight ? height : txtHeight);
   339         -		break;
   340         -	    default:
   341         -		break;
          328  +	case COMPOUND_TOP:
          329  +	case COMPOUND_BOTTOM:
          330  +	    /*
          331  +	     * Image is above or below text.
          332  +	     */
          333  +
          334  +	    height += txtHeight + butPtr->padY;
          335  +	    width = (width > txtWidth ? width : txtWidth);
          336  +	    break;
          337  +	case COMPOUND_LEFT:
          338  +	case COMPOUND_RIGHT:
          339  +	    /*
          340  +	     * Image is left or right of text.
          341  +	     */
          342  +
          343  +	    width += txtWidth + 2*butPtr->padX;
          344  +	    height = (height > txtHeight ? height : txtHeight);
          345  +	    break;
          346  +	case COMPOUND_CENTER:
          347  +	    /*
          348  +	     * Image and text are superimposed.
          349  +	     */
          350  +
          351  +	    width = (width > txtWidth ? width : txtWidth);
          352  +	    height = (height > txtHeight ? height : txtHeight);
          353  +	    break;
          354  +	default:
          355  +	    break;
   342    356   	}
   343    357   	width += butPtr->indicatorSpace;
   344    358       } else if (haveImage) { /* Image only */
   345    359   	width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace;
   346    360   	height = butPtr->height > 0 ? butPtr->height : height;
   347    361   	if (butPtr->type == TYPE_BUTTON) {
   348         -	    /* Allow room to shift the image. */
          362  +	    /*
          363  +	     * Allow room to shift the image.
          364  +	     */
   349    365   	    width += 2;
   350    366   	    height += 2;
   351    367   	}
   352    368       } else { /* Text only */
   353    369           width = txtWidth + butPtr->indicatorSpace;
   354    370   	height = txtHeight;
   355    371   	if (butPtr->width > 0) {
................................................................................
   371    387       }
   372    388   
   373    389       butPtr->inset = butPtr->borderWidth + butPtr->highlightWidth;
   374    390   
   375    391       width += butPtr->inset*2;
   376    392       height += butPtr->inset*2;
   377    393       if ([NSApp macMinorVersion] == 6) {
   378         -      width += 12;
          394  +	width += 12;
   379    395       }
   380    396       if (mbPtr->btnkind == kThemePushButton) {
   381    397           HIRect tmpRect;
   382    398       	HIRect contBounds;
   383    399   
   384    400   	/*
   385         -	 * A PushButton has a minimum size.  We make sure that we
   386         -	 * are not underestimating the size by requesting the content
   387         -	 * size of a Pushbutton whose overall size is our content size
   388         -	 * expanded by the standard padding.
          401  +	 * A PushButton has a minimum size.  We make sure that we are not
          402  +	 * underestimating the size by requesting the content size of a
          403  +	 * Pushbutton whose overall size is our content size expanded by the
          404  +	 * standard padding.
   389    405   	 */
   390         -	
          406  +
   391    407   	tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY);
   392    408           HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds);
   393    409           if (height < contBounds.size.height) {
   394    410   	    height = contBounds.size.height;
   395    411           }
   396    412           if (width < contBounds.size.width) {
   397    413   	    width = contBounds.size.width;
................................................................................
   398    414           }
   399    415   	height += 2*HI_PADY;
   400    416   	width += 2*HI_PADX;
   401    417       }
   402    418       Tk_GeometryRequest(butPtr->tkwin, width, height);
   403    419       Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
   404    420   }
   405         -
          421  +
   406    422   /*
   407    423    *----------------------------------------------------------------------
   408    424    *
   409    425    * DrawButtonImageAndText --
   410    426    *
   411         - *        Draws the image and text associated with a button or label.
          427  + *	Draws the image and text associated with a button or label.
   412    428    *
   413    429    * Results:
   414         - *        None.
          430  + *	None.
   415    431    *
   416    432    * Side effects:
   417         - *        The image and text are drawn.
          433  + *	The image and text are drawn.
   418    434    *
   419    435    *----------------------------------------------------------------------
   420    436    */
   421    437   static void
   422    438   DrawButtonImageAndText(
   423         -    TkButton* butPtr)
          439  +    TkButton *butPtr)
   424    440   {
   425    441   
   426         -    MacButton *mbPtr = (MacButton*)butPtr;
   427         -    Tk_Window  tkwin  = butPtr->tkwin;
   428         -    Pixmap     pixmap;
   429         -    int        haveImage = 0;
   430         -    int        haveText = 0;
   431         -    int        imageWidth = 0;
   432         -    int        imageHeight = 0;
   433         -    int        imageXOffset = 0;
   434         -    int        imageYOffset = 0;
   435         -    int        textXOffset = 0;
   436         -    int        textYOffset = 0;
   437         -    int        width = 0;
   438         -    int        height = 0;
   439         -    int        fullWidth = 0;
   440         -    int        fullHeight = 0;
   441         -    int        pressed = 0;
   442         -
          442  +    MacButton *mbPtr = (MacButton *) butPtr;
          443  +    Tk_Window tkwin = butPtr->tkwin;
          444  +    Pixmap pixmap;
          445  +    int haveImage = 0, haveText = 0, pressed = 0;
          446  +    int imageWidth = 0, imageHeight = 0;
          447  +    int imageXOffset = 0, imageYOffset = 0;
          448  +    int textXOffset = 0, textYOffset = 0;
          449  +    int width = 0, height = 0;
          450  +    int fullWidth = 0, fullHeight = 0;
   443    451   
   444    452       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   445    453           return;
   446    454       }
   447    455   
   448         -    DrawParams* dpPtr = &mbPtr->drawParams;
   449         -    pixmap = (Pixmap)Tk_WindowId(tkwin);
          456  +    DrawParams *dpPtr = &mbPtr->drawParams;
          457  +    pixmap = (Pixmap) Tk_WindowId(tkwin);
   450    458   
   451    459       if (butPtr->image != None) {
   452    460           Tk_SizeOfImage(butPtr->image, &width, &height);
   453    461           haveImage = 1;
   454    462       } else if (butPtr->bitmap != None) {
   455    463           Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
   456    464           haveImage = 1;
   457    465       }
   458    466   
   459         -    imageWidth  = width;
          467  +    imageWidth = width;
   460    468       imageHeight = height;
   461    469   
   462    470       if (mbPtr->drawinfo.state == kThemeStatePressed) {
   463         -        /* Offset bitmaps by a bit when the button is pressed. */
          471  +        /*
          472  +	 * Offset bitmaps by a bit when the button is pressed.
          473  +	 */
          474  +
   464    475           pressed = 1;
   465    476       }
   466    477   
   467    478       haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
   468    479       if (haveImage && haveText) { /* Image and Text */
   469         -        int x;
   470         -        int y;
   471         -        textXOffset = 0;
   472         -        textYOffset = 0;
   473         -        fullWidth = 0;
   474         -        fullHeight = 0;
          480  +        int x, y;
   475    481   
   476    482           switch ((enum compound) butPtr->compound) {
   477    483   	case COMPOUND_TOP:
   478         -	case COMPOUND_BOTTOM: {
   479         -	  /* Image is above or below text */
   480         -	  if (butPtr->compound == COMPOUND_TOP) {
   481         -	    textYOffset = height + butPtr->padY;
   482         -	  } else {
   483         -	    imageYOffset = butPtr->textHeight + butPtr->padY;
   484         -	  }
   485         -	  fullHeight = height + butPtr->textHeight + butPtr->padY;
   486         -	  fullWidth = (width > butPtr->textWidth ? width :
   487         -		       butPtr->textWidth);
   488         -	  textXOffset = (fullWidth - butPtr->textWidth)/2;
   489         -	  imageXOffset = (fullWidth - width)/2;
   490         -	  break;
   491         -	}
          484  +	case COMPOUND_BOTTOM:
          485  +	    /* Image is above or below text */
          486  +	    if (butPtr->compound == COMPOUND_TOP) {
          487  +		textYOffset = height + butPtr->padY;
          488  +	    } else {
          489  +		imageYOffset = butPtr->textHeight + butPtr->padY;
          490  +	    }
          491  +	    fullHeight = height + butPtr->textHeight + butPtr->padY;
          492  +	    fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth);
          493  +	    textXOffset = (fullWidth - butPtr->textWidth)/2;
          494  +	    imageXOffset = (fullWidth - width)/2;
          495  +	    break;
   492    496   	case COMPOUND_LEFT:
   493         -	case COMPOUND_RIGHT: {
   494         -	  /*
   495         -	   * Image is left or right of text
   496         -	   */
   497         -
   498         -	  if (butPtr->compound == COMPOUND_LEFT) {
   499         -	    textXOffset = width + butPtr->padX;
   500         -	  } else {
   501         -	    imageXOffset = butPtr->textWidth + butPtr->padX;
   502         -	  }
   503         -	  fullWidth = butPtr->textWidth + butPtr->padX + width;
   504         -	  fullHeight = (height > butPtr->textHeight ? height :
   505         -                        butPtr->textHeight);
   506         -	  textYOffset = (fullHeight - butPtr->textHeight)/2;
   507         -	  imageYOffset = (fullHeight - height)/2;
   508         -	  break;
   509         -	}
   510         -	case COMPOUND_CENTER: {
   511         -	  /*
   512         -	   * Image and text are superimposed
   513         -	   */
   514         -
   515         -	  fullWidth = (width > butPtr->textWidth ? width :
   516         -		       butPtr->textWidth);
   517         -	  fullHeight = (height > butPtr->textHeight ? height :
   518         -                        butPtr->textHeight);
   519         -	  textXOffset = (fullWidth - butPtr->textWidth)/2;
   520         -	  imageXOffset = (fullWidth - width)/2;
   521         -	  textYOffset = (fullHeight - butPtr->textHeight)/2;
   522         -	  imageYOffset = (fullHeight - height)/2;
   523         -	  break;
   524         -	}
          497  +	case COMPOUND_RIGHT:
          498  +	    /*
          499  +	     * Image is left or right of text
          500  +	     */
          501  +
          502  +	    if (butPtr->compound == COMPOUND_LEFT) {
          503  +		textXOffset = width + butPtr->padX;
          504  +	    } else {
          505  +		imageXOffset = butPtr->textWidth + butPtr->padX;
          506  +	    }
          507  +	    fullWidth = butPtr->textWidth + butPtr->padX + width;
          508  +	    fullHeight = (height > butPtr->textHeight ? height :
          509  +		    butPtr->textHeight);
          510  +	    textYOffset = (fullHeight - butPtr->textHeight)/2;
          511  +	    imageYOffset = (fullHeight - height)/2;
          512  +	    break;
          513  +	case COMPOUND_CENTER:
          514  +	    /*
          515  +	     * Image and text are superimposed
          516  +	     */
          517  +
          518  +	    fullWidth = (width > butPtr->textWidth ? width :
          519  +		    butPtr->textWidth);
          520  +	    fullHeight = (height > butPtr->textHeight ? height :
          521  +		    butPtr->textHeight);
          522  +	    textXOffset = (fullWidth - butPtr->textWidth)/2;
          523  +	    imageXOffset = (fullWidth - width)/2;
          524  +	    textYOffset = (fullHeight - butPtr->textHeight)/2;
          525  +	    imageYOffset = (fullHeight - height)/2;
          526  +	    break;
   525    527   	default:
   526         -	  break;
          528  +	    break;
   527    529   	}
   528    530   
   529    531           TkComputeAnchor(butPtr->anchor, tkwin,
   530    532                   butPtr->padX + butPtr->borderWidth,
   531    533                   butPtr->padY + butPtr->borderWidth,
   532    534                   fullWidth + butPtr->indicatorSpace, fullHeight, &x, &y);
   533    535   	x += butPtr->indicatorSpace;
................................................................................
   543    545               x += dpPtr->offset;
   544    546               y += dpPtr->offset;
   545    547           }
   546    548           imageXOffset += x;
   547    549           imageYOffset += y;
   548    550   
   549    551           if (butPtr->image != NULL) {
   550         -	  if ((butPtr->selectImage != NULL) &&
   551         -	      (butPtr->flags & SELECTED)) {
   552         -	    Tk_RedrawImage(butPtr->selectImage, 0, 0,
   553         -			   width, height, pixmap, imageXOffset, imageYOffset);
   554         -	  } else if ((butPtr->tristateImage != NULL) &&
   555         -		     (butPtr->flags & TRISTATED)) {
   556         -	    Tk_RedrawImage(butPtr->tristateImage, 0, 0,
   557         -			   width, height, pixmap, imageXOffset, imageYOffset);
   558         -	  } else {
   559         -	    Tk_RedrawImage(butPtr->image, 0, 0, width,
   560         -			   height, pixmap, imageXOffset, imageYOffset);
   561         -	  }
          552  +	    if ((butPtr->selectImage != NULL) &&
          553  +		    (butPtr->flags & SELECTED)) {
          554  +		Tk_RedrawImage(butPtr->selectImage, 0, 0,
          555  +			width, height, pixmap, imageXOffset, imageYOffset);
          556  +	    } else if ((butPtr->tristateImage != NULL) &&
          557  +		    (butPtr->flags & TRISTATED)) {
          558  +		Tk_RedrawImage(butPtr->tristateImage, 0, 0,
          559  +			width, height, pixmap, imageXOffset, imageYOffset);
          560  +	    } else {
          561  +		Tk_RedrawImage(butPtr->image, 0, 0, width,
          562  +			height, pixmap, imageXOffset, imageYOffset);
          563  +	    }
   562    564           } else {
   563         -	  XSetClipOrigin(butPtr->display, dpPtr->gc,
   564         -			 imageXOffset, imageYOffset);
   565         -	  XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
   566         -		     0, 0, (unsigned int) width, (unsigned int) height,
   567         -		     imageXOffset, imageYOffset, 1);
   568         -	  XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
          565  +	    XSetClipOrigin(butPtr->display, dpPtr->gc,
          566  +		    imageXOffset, imageYOffset);
          567  +	    XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
          568  +		    0, 0, (unsigned int) width, (unsigned int) height,
          569  +		    imageXOffset, imageYOffset, 1);
          570  +	    XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
   569    571           }
   570    572   
   571    573   	y += 1; /* Tweak to match native buttons. */
   572    574           Tk_DrawTextLayout(butPtr->display, pixmap,
   573    575                   dpPtr->gc, butPtr->textLayout,
   574    576                   x + textXOffset, y + textYOffset, 0, -1);
   575    577           Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
   576    578                   butPtr->textLayout,
   577    579                   x + textXOffset, y + textYOffset,
   578    580                   butPtr->underline);
   579    581       } else if (haveImage) { /* Image only */
   580         -        int x = 0;
   581         -	int y;
          582  +        int x = 0, y;
          583  +
   582    584   	TkComputeAnchor(butPtr->anchor, tkwin,
   583         -			butPtr->padX + butPtr->borderWidth,
   584         -			butPtr->padY + butPtr->borderWidth,
   585         -			width + butPtr->indicatorSpace,
   586         -			height, &x, &y);
          585  +		butPtr->padX + butPtr->borderWidth,
          586  +		butPtr->padY + butPtr->borderWidth,
          587  +		width + butPtr->indicatorSpace, height, &x, &y);
   587    588           x += butPtr->indicatorSpace;
   588    589   	if (pressed) {
   589         -	  x += dpPtr->offset;
   590         -	  y += dpPtr->offset;
          590  +	    x += dpPtr->offset;
          591  +	    y += dpPtr->offset;
   591    592   	}
   592    593   	imageXOffset += x;
   593    594   	imageYOffset += y;
   594    595   
   595    596   	if (butPtr->image != NULL) {
   596         -
   597         -	  if ((butPtr->selectImage != NULL) &&
   598         -	      (butPtr->flags & SELECTED)) {
   599         -	    Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
   600         -			   height, pixmap, imageXOffset, imageYOffset);
   601         -	  } else if ((butPtr->tristateImage != NULL) &&
   602         -		     (butPtr->flags & TRISTATED)) {
   603         -	    Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
   604         -			   height, pixmap, imageXOffset, imageYOffset);
   605         -	  } else {
   606         -	    Tk_RedrawImage(butPtr->image, 0, 0, width, height,
   607         -			   pixmap, imageXOffset, imageYOffset);
   608         -	  }
          597  +	    if ((butPtr->selectImage != NULL) &&
          598  +		    (butPtr->flags & SELECTED)) {
          599  +		Tk_RedrawImage(butPtr->selectImage, 0, 0, width,
          600  +			height, pixmap, imageXOffset, imageYOffset);
          601  +	    } else if ((butPtr->tristateImage != NULL) &&
          602  +		    (butPtr->flags & TRISTATED)) {
          603  +		Tk_RedrawImage(butPtr->tristateImage, 0, 0, width,
          604  +			height, pixmap, imageXOffset, imageYOffset);
          605  +	    } else {
          606  +		Tk_RedrawImage(butPtr->image, 0, 0, width, height,
          607  +			pixmap, imageXOffset, imageYOffset);
          608  +	    }
   609    609   	} else {
   610         -	  XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
   611         -	  XCopyPlane(butPtr->display, butPtr->bitmap,
   612         -		     pixmap, dpPtr->gc,
   613         -		     0, 0, (unsigned int) width,
   614         -		     (unsigned int) height,
   615         -		     imageXOffset, imageYOffset, 1);
   616         -	  XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
          610  +	    XSetClipOrigin(butPtr->display, dpPtr->gc, x, y);
          611  +	    XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
          612  +		    0, 0, (unsigned int) width, (unsigned int) height,
          613  +		    imageXOffset, imageYOffset, 1);
          614  +	    XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
   617    615   	}
   618    616       } else { /* Text only */
   619    617           int x, y;
          618  +
   620    619   	TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
   621         -			butPtr->textWidth + butPtr->indicatorSpace,
   622         -			  butPtr->textHeight, &x, &y);
          620  +		butPtr->textWidth + butPtr->indicatorSpace,
          621  +		butPtr->textHeight, &x, &y);
   623    622   	x += butPtr->indicatorSpace;
   624    623   	y += 1; /* Tweak to match native buttons */
   625         -	Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout,
   626         -			  x, y, 0, -1);
          624  +	Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
          625  +		butPtr->textLayout, x, y, 0, -1);
   627    626       }
   628    627   
   629    628       /*
   630    629        * If the button is disabled with a stipple rather than a special
   631         -     * foreground color, generate the stippled effect.  If the widget
   632         -     * is selected and we use a different background color when selected,
   633         -     * must temporarily modify the GC so the stippling is the right color.
          630  +     * foreground color, generate the stippled effect.  If the widget is
          631  +     * selected and we use a different background color when selected, must
          632  +     * temporarily modify the GC so the stippling is the right color.
   634    633        */
   635    634   
   636    635       if (mbPtr->useTkText) {
   637    636           if ((butPtr->state == STATE_DISABLED)
   638    637                   && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) {
   639    638               if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn
   640    639                       && (butPtr->selectBorder != NULL)) {
................................................................................
   664    663   
   665    664           /*
   666    665            * Draw the border and traversal highlight last.  This way, if the
   667    666            * button's contents overflow they'll be covered up by the border.
   668    667            */
   669    668   
   670    669           if (dpPtr->relief != TK_RELIEF_FLAT) {
   671         -            int inset = butPtr->highlightWidth;
   672         -            Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
   673         -                Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
   674         -                butPtr->borderWidth, dpPtr->relief);
          670  +	    int inset = butPtr->highlightWidth;
          671  +
          672  +	    Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset,
          673  +		    Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset,
          674  +		    butPtr->borderWidth, dpPtr->relief);
   675    675           }
   676    676       }
   677         -
   678         -   }
   679         -
   680         -
   681         -
   682         -
          677  +}
          678  +
   683    679   /*
   684    680    *----------------------------------------------------------------------
   685    681    *
   686    682    * TkpDestroyButton --
   687    683    *
   688    684    *	Free data structures associated with the button control.
   689    685    *
................................................................................
   697    693    */
   698    694   
   699    695   void
   700    696   TkpDestroyButton(
   701    697       TkButton *butPtr)
   702    698   {
   703    699       MacButton *mbPtr = (MacButton *) butPtr; /* Mac button. */
          700  +
   704    701       if (mbPtr->defaultPulseHandler) {
   705    702           Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
   706    703       }
   707    704   }
   708    705   
   709    706   /*
   710    707    *--------------------------------------------------------------
   711    708    *
   712    709    * TkMacOSXDrawButton --
   713    710    *
   714         - *        This function draws the tk button using Mac controls
   715         - *        In addition, this code may apply custom colors passed
   716         - *        in the TkButton.
          711  + *        This function draws the tk button using Mac controls. In addition,
          712  + *        this code may apply custom colors passed in the TkButton.
   717    713    *
   718    714    * Results:
   719    715    *        None.
   720    716    *
   721    717    * Side effects:
   722    718    *      The control is created, or reinitialised as needed
   723    719    *
................................................................................
   728    724   TkMacOSXDrawButton(
   729    725       MacButton *mbPtr,    /* Mac button. */
   730    726       GC gc,               /* The GC we are drawing into - needed for
   731    727                             * the bevel button */
   732    728       Pixmap pixmap)       /* The pixmap we are drawing into - needed
   733    729                             * for the bevel button */
   734    730   {
   735         -    TkButton * butPtr = ( TkButton *)mbPtr;
   736         -    TkWindow * winPtr;
   737         -    HIRect      cntrRect;
          731  +    TkButton *butPtr = (TkButton *) mbPtr;
          732  +    TkWindow *winPtr = (TkWindow *) butPtr->tkwin;
          733  +    HIRect cntrRect;
   738    734       TkMacOSXDrawingContext dc;
   739         -    DrawParams* dpPtr = &mbPtr->drawParams;
          735  +    DrawParams *dpPtr = &mbPtr->drawParams;
   740    736       int useNewerHITools = 1;
   741    737   
   742         -    winPtr = (TkWindow *)butPtr->tkwin;
   743         -
   744    738       TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
   745    739   
   746         -    cntrRect = CGRectMake(winPtr->privatePtr->xOff,
   747         -			  winPtr->privatePtr->yOff,
   748         -			  Tk_Width(butPtr->tkwin),
   749         -			  Tk_Height(butPtr->tkwin));
          740  +    cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff,
          741  +	    Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin));
   750    742   
   751         -     cntrRect = CGRectInset(cntrRect,  butPtr->inset, butPtr->inset);
          743  +    cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset);
   752    744   
   753    745       if (useNewerHITools == 1) {
   754    746           HIRect contHIRec;
   755    747           static HIThemeButtonDrawInfo hiinfo;
   756    748   
   757    749           ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true);
   758    750   
   759    751   	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
   760    752   	    return;
   761    753   	}
   762    754   
   763    755           hiinfo.version = 0;
   764    756           hiinfo.state = mbPtr->drawinfo.state;
   765         -        hiinfo.kind  = mbPtr->btnkind;
          757  +        hiinfo.kind = mbPtr->btnkind;
   766    758           hiinfo.value = mbPtr->drawinfo.value;
   767    759           hiinfo.adornment = mbPtr->drawinfo.adornment;
   768    760           hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
   769    761           if (hiinfo.animation.time.start == 0) {
   770    762               hiinfo.animation.time.start = hiinfo.animation.time.current;
   771    763           }
   772    764   
   773    765   	/*
   774    766   	 * To avoid buttons with white text on a white background, we always
   775         -	 * set the state to inactive in Dark Mode.  It isn't perfect but
   776         -	 * it is usable.  Using a ttk::button would be a better choice,
   777         -	 * however.
          767  +	 * set the state to inactive in Dark Mode.  It isn't perfect but it is
          768  +	 * usable.  Using a ttk::button would be a better choice, however.
   778    769   	 */
   779    770   
   780    771   	if (TkMacOSXInDarkMode(butPtr->tkwin)) {
   781    772   	    hiinfo.state = kThemeStateInactive;
   782    773   	}
   783         -	HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal,
   784         -			  &contHIRec);
          774  +	HIThemeDrawButton(&cntrRect, &hiinfo, dc.context,
          775  +		kHIThemeOrientationNormal, &contHIRec);
   785    776   
   786    777   	TkMacOSXRestoreDrawingContext(&dc);
   787    778           ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo,
   788         -			    (MacButton *)mbPtr, 32, true);
   789         -
          779  +		(MacButton *) mbPtr, 32, true);
   790    780       } else {
   791    781   	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
   792    782   	    return;
   793    783   	}
   794    784   
   795    785   	TkMacOSXRestoreDrawingContext(&dc);
   796    786       }
................................................................................
   798    788   }
   799    789   
   800    790   /*
   801    791    *--------------------------------------------------------------
   802    792    *
   803    793    * ButtonBackgroundDrawCB --
   804    794    *
   805         - *        This function draws the background that
   806         - *        lies under checkboxes and radiobuttons.
          795  + *        This function draws the background that lies under checkboxes and
          796  + *        radiobuttons.
   807    797    *
   808    798    * Results:
   809    799    *        None.
   810    800    *
   811    801    * Side effects:
   812    802    *        The background gets updated to the current color.
   813    803    *
   814    804    *--------------------------------------------------------------
   815    805    */
          806  +
   816    807   static void
   817         -ButtonBackgroundDrawCB (
   818         -    const HIRect * btnbounds,
          808  +ButtonBackgroundDrawCB(
          809  +    const HIRect *btnbounds,
   819    810       MacButton *ptr,
   820    811       SInt16 depth,
   821    812       Boolean isColorDev)
   822    813   {
   823         -    MacButton* mbPtr = (MacButton*)ptr;
   824         -    TkButton* butPtr = (TkButton*)mbPtr;
   825         -    Tk_Window  tkwin  = butPtr->tkwin;
          814  +    MacButton *mbPtr = (MacButton *) ptr;
          815  +    TkButton *butPtr = (TkButton *) mbPtr;
          816  +    Tk_Window tkwin = butPtr->tkwin;
   826    817       Pixmap pixmap;
   827    818       int usehlborder = 0;
   828    819   
   829    820       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   830    821           return;
   831    822       }
   832         -    pixmap = (Pixmap)Tk_WindowId(tkwin);
          823  +    pixmap = (Pixmap) Tk_WindowId(tkwin);
   833    824   
   834    825       if (butPtr->type != TYPE_LABEL) {
   835    826           switch (mbPtr->btnkind) {
   836         -            case kThemeSmallBevelButton:
   837         -            case kThemeBevelButton:
   838         -            case kThemeRoundedBevelButton:
   839         -            case kThemePushButton:
   840         -                usehlborder = 1;
   841         -                break;
          827  +	case kThemeSmallBevelButton:
          828  +	case kThemeBevelButton:
          829  +	case kThemeRoundedBevelButton:
          830  +	case kThemePushButton:
          831  +	    usehlborder = 1;
          832  +	    break;
   842    833           }
   843    834       }
   844    835       if (usehlborder) {
   845    836           Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0,
   846    837               Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
   847    838       } else {
   848    839           Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
................................................................................
   870    861       const HIRect * btnbounds,
   871    862       ThemeButtonKind kind,
   872    863       const HIThemeButtonDrawInfo *drawinfo,
   873    864       MacButton *ptr,
   874    865       SInt16 depth,
   875    866       Boolean isColorDev)
   876    867   {
   877         -    TkButton  *butPtr = (TkButton *)ptr;
   878         -    Tk_Window  tkwin  = butPtr->tkwin;
          868  +    TkButton *butPtr = (TkButton *) ptr;
          869  +    Tk_Window tkwin = butPtr->tkwin;
   879    870   
   880    871       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   881    872           return;
   882    873       }
   883    874   
   884    875       /*
   885         -     * Overlay Tk elements over button native region: drawing elements
   886         -     * within button boundaries/native region causes unpredictable metrics.
          876  +     * Overlay Tk elements over button native region: drawing elements within
          877  +     * button boundaries/native region causes unpredictable metrics.
   887    878        */
          879  +
   888    880       DrawButtonImageAndText( butPtr);
   889    881   }
   890    882   
   891    883   /*
   892    884    *--------------------------------------------------------------
   893    885    *
   894    886    * ButtonEventProc --
   895    887    *
   896         - *	This procedure is invoked by the Tk dispatcher for various
   897         - *	events on buttons.
          888  + *	This procedure is invoked by the Tk dispatcher for various events on
          889  + *	buttons.
   898    890    *
   899    891    * Results:
   900    892    *	None.
   901    893    *
   902    894    * Side effects:
   903    895    *	When it gets exposed, it is redisplayed.
   904    896    *
................................................................................
   906    898    */
   907    899   
   908    900   static void
   909    901   ButtonEventProc(
   910    902       ClientData clientData,	/* Information about window. */
   911    903       XEvent *eventPtr)		/* Information about event. */
   912    904   {
   913         -    TkButton *buttonPtr = (TkButton *) clientData;
   914         -    MacButton *mbPtr = (MacButton *) clientData;
          905  +    TkButton *buttonPtr = clientData;
          906  +    MacButton *mbPtr = clientData;
   915    907   
   916    908       if (eventPtr->type == ActivateNotify
   917    909   	    || eventPtr->type == DeactivateNotify) {
   918    910   	if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) {
   919    911   	    return;
   920    912   	}
   921    913   	if (eventPtr->type == ActivateNotify) {
   922    914   	    mbPtr->flags |= ACTIVE;
   923    915   	} else {
   924    916   	    mbPtr->flags &= ~ACTIVE;
   925    917   	}
   926    918   	if ((buttonPtr->flags & REDRAW_PENDING) == 0) {
   927         -	    Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr);
          919  +	    Tcl_DoWhenIdle(TkpDisplayButton, buttonPtr);
   928    920   	    buttonPtr->flags |= REDRAW_PENDING;
   929    921   	}
   930    922       }
   931    923   }
   932    924   
   933    925   /*
   934    926    *----------------------------------------------------------------------
   935    927    *
   936    928    * TkMacOSXComputeButtonParams --
   937    929    *
   938         - *      This procedure computes the various parameters used
   939         - *        when creating a Carbon Appearance control.
   940         - *	These are determined by the various tk button parameters
          930  + *      This procedure computes the various parameters used when creating a
          931  + *      Carbon Appearance control.  These are determined by the various tk
          932  + *      button parameters
   941    933    *
   942    934    * Results:
   943    935    *	None.
   944    936    *
   945    937    * Side effects:
   946    938    *        Sets the btnkind and drawinfo parameters
   947    939    *
   948    940    *----------------------------------------------------------------------
   949    941    */
   950    942   
   951    943   static void
   952    944   TkMacOSXComputeButtonParams(
   953         -        TkButton * butPtr,
   954         -        ThemeButtonKind* btnkind,
   955         -	HIThemeButtonDrawInfo *drawinfo)
          945  +    TkButton *butPtr,
          946  +    ThemeButtonKind *btnkind,
          947  +    HIThemeButtonDrawInfo *drawinfo)
   956    948   {
   957         -    MacButton *mbPtr = (MacButton *)butPtr;
          949  +    MacButton *mbPtr = (MacButton *) butPtr;
   958    950   
   959    951       if (butPtr->borderWidth <= 2) {
   960    952           *btnkind = kThemeSmallBevelButton;
   961    953       } else if (butPtr->borderWidth == 3) {
   962    954           *btnkind = kThemeBevelButton;
   963    955       } else if (butPtr->borderWidth == 4) {
   964    956           *btnkind = kThemeRoundedBevelButton;
   965    957       } else {
   966    958           *btnkind = kThemePushButton;
   967    959       }
   968    960   
   969    961       if ((butPtr->image == None) && (butPtr->bitmap == None)) {
   970    962           switch (butPtr->type) {
   971         -            case TYPE_BUTTON:
   972         -                *btnkind = kThemePushButton;
   973         -                break;
   974         -            case TYPE_RADIO_BUTTON:
   975         -                if (butPtr->borderWidth <= 1) {
   976         -                    *btnkind = kThemeSmallRadioButton;
   977         -		} else {
   978         -                    *btnkind = kThemeRadioButton;
   979         -		}
   980         -		break;
   981         -	    case TYPE_CHECK_BUTTON:
   982         -                if (butPtr->borderWidth <= 1) {
   983         -                    *btnkind = kThemeSmallCheckBox;
   984         -	        } else {
   985         -                    *btnkind = kThemeCheckBox;
   986         -		}
   987         -		break;
          963  +	case TYPE_BUTTON:
          964  +	    *btnkind = kThemePushButton;
          965  +	    break;
          966  +	case TYPE_RADIO_BUTTON:
          967  +	    if (butPtr->borderWidth <= 1) {
          968  +		*btnkind = kThemeSmallRadioButton;
          969  +	    } else {
          970  +		*btnkind = kThemeRadioButton;
          971  +	    }
          972  +	    break;
          973  +	case TYPE_CHECK_BUTTON:
          974  +	    if (butPtr->borderWidth <= 1) {
          975  +		*btnkind = kThemeSmallCheckBox;
          976  +	    } else {
          977  +		*btnkind = kThemeCheckBox;
          978  +	    }
          979  +	    break;
   988    980   	}
   989    981       }
   990    982   
   991    983       if (butPtr->indicatorOn) {
   992    984           switch (butPtr->type) {
   993         -            case TYPE_RADIO_BUTTON:
   994         -                if (butPtr->borderWidth <= 1) {
   995         -                    *btnkind = kThemeSmallRadioButton;
   996         -                } else {
   997         -                    *btnkind = kThemeRadioButton;
   998         -                }
   999         -                break;
  1000         -            case TYPE_CHECK_BUTTON:
  1001         -                if (butPtr->borderWidth <= 1) {
  1002         -                    *btnkind = kThemeSmallCheckBox;
  1003         -                } else {
  1004         -                    *btnkind = kThemeCheckBox;
  1005         -                }
  1006         -                break;
          985  +	case TYPE_RADIO_BUTTON:
          986  +	    if (butPtr->borderWidth <= 1) {
          987  +		*btnkind = kThemeSmallRadioButton;
          988  +	    } else {
          989  +		*btnkind = kThemeRadioButton;
          990  +	    }
          991  +	    break;
          992  +	case TYPE_CHECK_BUTTON:
          993  +	    if (butPtr->borderWidth <= 1) {
          994  +		*btnkind = kThemeSmallCheckBox;
          995  +	    } else {
          996  +		*btnkind = kThemeCheckBox;
          997  +	    }
          998  +	    break;
  1007    999           }
  1008   1000       } else {
  1009   1001           if (butPtr->type == TYPE_RADIO_BUTTON ||
  1010         -	    butPtr->type == TYPE_CHECK_BUTTON
  1011         -	) {
         1002  +		butPtr->type == TYPE_CHECK_BUTTON) {
  1012   1003   	    if (*btnkind == kThemePushButton) {
  1013   1004   		*btnkind = kThemeBevelButton;
  1014   1005   	    }
  1015   1006           }
  1016   1007       }
  1017   1008   
  1018   1009       if (butPtr->flags & SELECTED) {
................................................................................
  1046   1037       }
  1047   1038   
  1048   1039       drawinfo->adornment = kThemeAdornmentNone;
  1049   1040       if (butPtr->defaultState == DEFAULT_ACTIVE) {
  1050   1041           drawinfo->adornment |= kThemeAdornmentDefault;
  1051   1042           if (!mbPtr->defaultPulseHandler) {
  1052   1043               mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
  1053         -                    PULSE_TIMER_MSECS, PulseDefaultButtonProc,
  1054         -                    (ClientData) butPtr);
         1044  +                    PULSE_TIMER_MSECS, PulseDefaultButtonProc, butPtr);
  1055   1045           }
  1056   1046       } else if (mbPtr->defaultPulseHandler) {
  1057   1047           Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler);
  1058   1048       }
  1059   1049       if (butPtr->highlightWidth >= 3) {
  1060   1050           if ((butPtr->flags & GOT_FOCUS)) {
  1061   1051               drawinfo->adornment |= kThemeAdornmentFocus;
................................................................................
  1064   1054   }
  1065   1055   
  1066   1056   /*
  1067   1057    *----------------------------------------------------------------------
  1068   1058    *
  1069   1059    * TkMacOSXComputeButtonDrawParams --
  1070   1060    *
  1071         - *	This procedure computes the various parameters used
  1072         - *	when drawing a button
  1073         - *	These are determined by the various tk button parameters
         1061  + *	This procedure computes the various parameters used when drawing a
         1062  + *	button. These are determined by the various tk button parameters
  1074   1063    *
  1075   1064    * Results:
  1076   1065    *	1 if control will be used, 0 otherwise.
  1077   1066    *
  1078   1067    * Side effects:
  1079   1068    *	Sets the button draw parameters
  1080   1069    *
................................................................................
  1082   1071    */
  1083   1072   
  1084   1073   static int
  1085   1074   TkMacOSXComputeButtonDrawParams(
  1086   1075       TkButton *butPtr,
  1087   1076       DrawParams *dpPtr)
  1088   1077   {
  1089         -    MacButton *mbPtr = (MacButton *)butPtr;
         1078  +    MacButton *mbPtr = (MacButton *) butPtr;
  1090   1079   
  1091   1080       dpPtr->hasImageOrBitmap = ((butPtr->image != NULL)
  1092   1081   	    || (butPtr->bitmap != None));
  1093   1082   
  1094   1083       if (butPtr->type != TYPE_LABEL) {
  1095   1084           dpPtr->offset = 0;
  1096   1085           if (dpPtr->hasImageOrBitmap) {
  1097   1086               switch (mbPtr->btnkind) {
  1098         -                case kThemeSmallBevelButton:
  1099         -                case kThemeBevelButton:
  1100         -                case kThemeRoundedBevelButton:
  1101         -                case kThemePushButton:
  1102         -                    dpPtr->offset = 1;
  1103         -                    break;
         1087  +	    case kThemeSmallBevelButton:
         1088  +	    case kThemeBevelButton:
         1089  +	    case kThemeRoundedBevelButton:
         1090  +	    case kThemePushButton:
         1091  +		dpPtr->offset = 1;
         1092  +		break;
  1104   1093               }
  1105   1094           }
  1106   1095       }
  1107   1096   
  1108   1097       dpPtr->border = butPtr->normalBorder;
  1109   1098       if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
  1110   1099   	dpPtr->gc = butPtr->disabledGC;
................................................................................
  1117   1106   
  1118   1107       if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE)
  1119   1108   	    && (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) {
  1120   1109   	dpPtr->border = butPtr->selectBorder;
  1121   1110       }
  1122   1111   
  1123   1112       /*
  1124         -     * Override the relief specified for the button if this is a
  1125         -     * checkbutton or radiobutton and there's no indicator.
         1113  +     * Override the relief specified for the button if this is a checkbutton or
         1114  +     * radiobutton and there's no indicator.
  1126   1115        */
  1127   1116   
  1128   1117       dpPtr->relief = butPtr->relief;
  1129   1118   
  1130   1119       if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) {
  1131   1120   	if (!dpPtr->hasImageOrBitmap) {
  1132   1121   	    dpPtr->relief = (butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN
  1133   1122   		    : TK_RELIEF_RAISED;
  1134   1123   	}
  1135   1124       }
  1136   1125   
  1137         -    if (butPtr->type != TYPE_LABEL &&
  1138         -	(butPtr->type == TYPE_BUTTON ||
  1139         -	 butPtr->indicatorOn         ||
  1140         -	 dpPtr->hasImageOrBitmap)) {
  1141         -	
         1126  +    if (butPtr->type != TYPE_LABEL && (butPtr->type == TYPE_BUTTON ||
         1127  +	    butPtr->indicatorOn || dpPtr->hasImageOrBitmap)) {
  1142   1128   	/*
  1143   1129   	 * Draw this widget as a native control.
  1144   1130   	 */
  1145         -	
         1131  +
  1146   1132   	return 1;
  1147   1133       } else {
  1148         -
  1149   1134   	/*
  1150   1135   	 * Draw this widget from scratch.
  1151   1136   	 */
  1152         -	
         1137  +
  1153   1138   	return 0;
  1154   1139       }
  1155   1140   }
  1156   1141   
  1157   1142   /*
  1158   1143    *--------------------------------------------------------------
  1159   1144    *
................................................................................
  1169   1154    *     Sets a timer to run itself again.
  1170   1155    *
  1171   1156    *--------------------------------------------------------------
  1172   1157    */
  1173   1158   static void
  1174   1159   PulseDefaultButtonProc(ClientData clientData)
  1175   1160   {
  1176         -    MacButton *mbPtr = (MacButton *)clientData;
         1161  +    MacButton *mbPtr = clientData;
         1162  +
  1177   1163       TkpDisplayButton(clientData);
  1178   1164       mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler(
  1179   1165               PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData);
  1180   1166   }
  1181         -
         1167  +
  1182   1168   /*
  1183   1169    * Local Variables:
  1184   1170    * mode: objc
  1185   1171    * c-basic-offset: 4
  1186   1172    * fill-column: 79
  1187   1173    * coding: utf-8
  1188   1174    * End:
  1189   1175    */

Changes to macosx/tkMacOSXClipboard.c.

   119    119   				 * returned. */
   120    120       Tk_GetSelProc *proc,	/* Procedure to call to process the selection,
   121    121   				 * once it has been retrieved. */
   122    122       ClientData clientData)	/* Arbitrary value to pass to proc. */
   123    123   {
   124    124       int result = TCL_ERROR;
   125    125       TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
          126  +    int haveExternalClip =
          127  +	    ([[NSPasteboard generalPasteboard] changeCount] != changeCount);
   126    128   
   127         -    int haveExternalClip = ([[NSPasteboard generalPasteboard] changeCount] != changeCount);
   128    129       if (dispPtr && (haveExternalClip || dispPtr->clipboardActive)
   129    130   	        && selection == dispPtr->clipboardAtom
   130    131   	        && (target == XA_STRING || target == dispPtr->utf8Atom)) {
   131    132   	NSString *string = nil;
   132    133   	NSPasteboard *pb = [NSPasteboard generalPasteboard];
   133    134   	NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:
   134    135   		NSStringPboardType]];
................................................................................
   173    174   {
   174    175       TkDisplay *dispPtr = TkGetDisplayList();
   175    176   
   176    177       if (dispPtr && selection == dispPtr->clipboardAtom) {
   177    178   	clipboardOwner = owner ? Tk_IdToWindow(display, owner) : NULL;
   178    179   	if (!dispPtr->clipboardActive) {
   179    180   	    NSPasteboard *pb = [NSPasteboard generalPasteboard];
          181  +
   180    182   	    changeCount = [pb declareTypes:[NSArray array] owner:NSApp];
   181    183   	}
   182    184       }
   183    185       return Success;
   184    186   }
   185    187   
   186    188   /*
   187    189    *----------------------------------------------------------------------
   188    190    *
   189    191    * TkMacOSXSelDeadWindow --
   190    192    *
   191         - *	This function is invoked just before a TkWindow is deleted. It
   192         - *	performs selection-related cleanup.
          193  + *	This function is invoked just before a TkWindow is deleted. It performs
          194  + *	selection-related cleanup.
   193    195    *
   194    196    * Results:
   195    197    *	None.
   196    198    *
   197    199    * Side effects:
   198    200    *	clipboardOwner is cleared.
   199    201    *

Changes to macosx/tkMacOSXCursor.c.

   181    181       {NULL}
   182    182   };
   183    183   
   184    184   /*
   185    185    * Declarations of static variables used in this file.
   186    186    */
   187    187   
   188         -static TkMacOSXCursor * gCurrentCursor = NULL;
          188  +static TkMacOSXCursor *gCurrentCursor = NULL;
   189    189   				/* A pointer to the current cursor. */
   190    190   static int gResizeOverride = false;
   191    191   				/* A boolean indicating whether we should use
   192    192   				 * the resize cursor during installations. */
   193    193   static int gTkOwnsCursor = true;/* A boolean indicating whether Tk owns the
   194    194   				 * cursor. If not (for instance, in the case
   195    195   				 * where a Tk window is embedded in another
   196    196   				 * app's window, and the cursor is out of the
   197         -				 * tk window, we will not attempt to adjust
          197  +				 * Tk window, we will not attempt to adjust
   198    198   				 * the cursor. */
   199    199   
   200    200   /*
   201    201    * Declarations of procedures local to this file
   202    202    */
   203    203   
   204    204   static void FindCursorByName(TkMacOSXCursor *macCursorPtr, const char *string);
................................................................................
   274    274   		NSBitmapImageRep *bitmapImageRep = NULL;
   275    275   		CGImageRef img = NULL, mask = NULL, maskedImg = NULL;
   276    276   		static const CGFloat decodeWB[] = {1, 0};
   277    277   		CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(
   278    278   			kCGColorSpaceGenericGray);
   279    279   		CGDataProviderRef provider = CGDataProviderCreateWithData(NULL,
   280    280   			bitmap, pix*pix/8, NULL);
          281  +
   281    282   		if (provider) {
   282    283   		    img = CGImageCreate(pix, pix, 1, 1, pix/8, colorspace,
   283    284   			    kCGBitmapByteOrderDefault, provider, decodeWB, 0,
   284    285   			    kCGRenderingIntentDefault);
   285    286   		    CFRelease(provider);
   286    287   		}
   287    288   		provider = CGDataProviderCreateWithData(NULL, bitmap +
................................................................................
   295    296   		    maskedImg = CGImageCreateWithMask(img, mask);
   296    297   		}
   297    298   		if (maskedImg) {
   298    299   		    bitmapImageRep = [[NSBitmapImageRep alloc]
   299    300   			    initWithCGImage:maskedImg];
   300    301   		    CFRelease(maskedImg);
   301    302   		}
   302         -		if (mask) { CFRelease(mask); }
   303         -		if (img)  { CFRelease(img); }
   304         -		if (colorspace) { CFRelease(colorspace); }
          303  +		if (mask) {
          304  +		    CFRelease(mask);
          305  +		}
          306  +		if (img) {
          307  +		    CFRelease(img);
          308  +		}
          309  +		if (colorspace) {
          310  +		    CFRelease(colorspace);
          311  +		}
   305    312   		if (bitmapImageRep) {
   306    313   		    image = [[NSImage alloc] initWithSize:NSMakeSize(pix, pix)];
   307    314   		    [image addRepresentation:bitmapImageRep];
   308    315   		    [bitmapImageRep release];
   309    316   		}
          317  +
   310    318   		uint16_t *hotSpotData = (uint16_t*)(bitmap + 2*pix*pix/8);
   311    319   		hotSpot.y = CFSwapInt16BigToHost(*hotSpotData++);
   312    320   		hotSpot.x = CFSwapInt16BigToHost(*hotSpotData);
   313    321   		haveHotSpot = 1;
   314    322   		break;
   315    323   	    }
   316    324   	    }

Changes to macosx/tkMacOSXDialog.c.

    18     18   
    19     19   #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
    20     20   #define modalOK     NSOKButton
    21     21   #define modalCancel NSCancelButton
    22     22   #else
    23     23   #define modalOK     NSModalResponseOK
    24     24   #define modalCancel NSModalResponseCancel
    25         -#endif
           25  +#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090
    26     26   #define modalOther  -1
    27     27   #define modalError  -2
    28     28   
    29         -/*Vars for filtering in "open file" and "save file" dialogs.*/
           29  +/*
           30  + * Vars for filtering in "open file" and "save file" dialogs.
           31  + */
           32  +
    30     33   typedef struct {
    31         -    bool doFileTypes; // show the accessory view which displays the filter menu
    32         -    bool preselectFilter; // a filter was selected by the typevariable
    33         -    bool userHasSelectedFilter; // The user has changed the filter in the accessory view
    34         -
    35         -    NSMutableArray *fileTypeNames; // array of names, e.g. "Text document"
    36         -    NSMutableArray *fileTypeExtensions; // array of allowed extensions per name, e.g. "txt", "doc"
    37         -    NSMutableArray *fileTypeLabels; // displayed string, e.g. "Text document (.txt, .doc)"
    38         -    NSMutableArray *fileTypeAllowsAll; // boolean if the all pattern (*.*) is included
    39         -
    40         -    NSMutableArray *allowedExtensions; // set of all allowed extensions
    41         -    bool allowedExtensionsAllowAll; // set of all allowed extensions includes *.*
    42         -
    43         -    NSUInteger fileTypeIndex; // index of currently selected filter
           34  +    bool doFileTypes;			/* Show the accessory view which
           35  +					 * displays the filter menu */
           36  +    bool preselectFilter;		/* A filter was selected by the
           37  +					 * typevariable. */
           38  +    bool userHasSelectedFilter;		/* The user has changed the filter in
           39  +					 * the accessory view. */
           40  +    NSMutableArray *fileTypeNames;	/* Array of names, e.g. "Text
           41  +					 * document". */
           42  +    NSMutableArray *fileTypeExtensions;	/* Array of allowed extensions per
           43  +					 * name, e.g. "txt", "doc". */
           44  +    NSMutableArray *fileTypeLabels;	/* Displayed string, e.g. "Text
           45  +					 * document (.txt, .doc)". */ 
           46  +    NSMutableArray *fileTypeAllowsAll;	/* Boolean if the all pattern (*.*) is
           47  +					 * included. */
           48  +    NSMutableArray *allowedExtensions;	/* Set of all allowed extensions. */
           49  +    bool allowedExtensionsAllowAll;	/* Set of all allowed extensions
           50  +					 * includes *.* */
           51  +    NSUInteger fileTypeIndex;		/* Index of currently selected
           52  +					 * filter. */
    44     53   } filepanelFilterInfo;
    45     54   
    46         -filepanelFilterInfo filterInfo;
    47         -
    48         -NSOpenPanel *openpanel;
    49         -NSSavePanel *savepanel;
           55  +static filepanelFilterInfo filterInfo;
           56  +static NSOpenPanel *openpanel;
           57  +static NSSavePanel *savepanel;
    50     58   
    51     59   static const char *const colorOptionStrings[] = {
    52     60       "-initialcolor", "-parent", "-title", NULL
    53     61   };
    54     62   enum colorOptions {
    55     63       COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE
    56     64   };
................................................................................
   162    170       [TYPE_OKCANCEL] =		{3, 4, 0},
   163    171       [TYPE_RETRYCANCEL] =	{1, 4, 0},
   164    172       [TYPE_YESNO] =		{6, 5, 0},
   165    173       [TYPE_YESNOCANCEL] =	{6, 5, 4},
   166    174   };
   167    175   
   168    176   /*
   169         - * Construct a file URL from directory and filename.  Either may
   170         - * be nil.  If both are nil, returns nil.
          177  + * Construct a file URL from directory and filename. Either may be nil. If both
          178  + * are nil, returns nil.
   171    179    */
   172         -static NSURL *getFileURL(NSString *directory, NSString *filename) {
          180  +
          181  +static NSURL *
          182  +getFileURL(
          183  +    NSString *directory,
          184  +    NSString *filename)
          185  +{
   173    186       NSURL *url = nil;
   174    187       if (directory) {
   175    188   	url = [NSURL fileURLWithPath:directory isDirectory:YES];
   176    189       }
   177    190       if (filename) {
   178    191   	url = [NSURL URLWithString:filename relativeToURL:url];
   179    192       }
................................................................................
   225    238       }
   226    239       if (callbackInfo->cmdObj) {
   227    240   	Tcl_DecrRefCount(callbackInfo->cmdObj);
   228    241   	ckfree(callbackInfo);
   229    242       }
   230    243   }
   231    244   
   232         -
   233    245   - (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode
   234    246   	contextInfo: (void *) contextInfo
   235    247   {
   236    248       AlertCallbackInfo *callbackInfo = contextInfo;
   237    249   
   238    250       if (returnCode >= NSAlertFirstButtonReturn) {
   239    251   	Tcl_Obj *resultObj = Tcl_NewStringObj(alertButtonStrings[
................................................................................
   268    280   
   269    281   - (void)selectFormat:(id)sender  {
   270    282       NSPopUpButton *button      = (NSPopUpButton *)sender;
   271    283       filterInfo.fileTypeIndex   = [button indexOfSelectedItem];
   272    284   
   273    285       if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) {
   274    286   	[openpanel setAllowsOtherFileTypes:YES];
   275         -	/* setAllowsOtherFileTypes might have no effect; it's inherited from the
   276         -	 * NSSavePanel, where it has the effect that it does not append an extension
   277         -	 * Setting the allowed file types to nil allows selecting any file */
          287  +
          288  +	/*
          289  +	 * setAllowsOtherFileTypes might have no effect; it's inherited from
          290  +	 * the NSSavePanel, where it has the effect that it does not append an
          291  +	 * extension. Setting the allowed file types to nil allows selecting
          292  +	 * any file.
          293  +	 */
          294  +
   278    295   	[openpanel setAllowedFileTypes:nil];
   279    296       } else {
   280         -	NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
          297  +	NSMutableArray *allowedtypes =
          298  +		[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
   281    299   	[openpanel setAllowedFileTypes:allowedtypes];
   282    300   	[openpanel setAllowsOtherFileTypes:NO];
   283    301       }
   284    302   
   285    303       filterInfo.userHasSelectedFilter = true;
   286    304   }
   287    305   
................................................................................
   289    307       NSPopUpButton *button     = (NSPopUpButton *)sender;
   290    308       filterInfo.fileTypeIndex  = [button indexOfSelectedItem];
   291    309   
   292    310       if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) {
   293    311   	[savepanel setAllowsOtherFileTypes:YES];
   294    312   	[savepanel setAllowedFileTypes:nil];
   295    313       } else {
   296         -	NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
          314  +	NSMutableArray *allowedtypes =
          315  +		[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
   297    316   	[savepanel setAllowedFileTypes:allowedtypes];
   298    317   	[savepanel setAllowsOtherFileTypes:NO];
   299    318       }
   300    319   
   301    320       filterInfo.userHasSelectedFilter = true;
   302    321   }
   303    322   
................................................................................
   380    399       [colorPanel orderOut:NSApp];
   381    400       [colorPanel setContinuous:NO];
   382    401       [colorPanel setBecomesKeyOnlyIfNeeded:NO];
   383    402       [colorPanel setShowsAlpha: NO];
   384    403       [colorPanel _setUseModalAppearance:YES];
   385    404       if (title) {
   386    405   	NSString *s = [[NSString alloc] initWithUTF8String:title];
          406  +
   387    407   	[colorPanel setTitle:s];
   388    408   	[s release];
   389    409       }
   390    410       if (initialColor) {
   391    411   	[colorPanel setColor:initialColor];
   392    412       }
   393    413       returnCode = [NSApp runModalForWindow:colorPanel];
................................................................................
   411    431       }
   412    432       result = TCL_OK;
   413    433   
   414    434   end:
   415    435       return result;
   416    436   }
   417    437   
   418         -/* dissect the -filetype nested lists and store the information
   419         - * in the filterInfo structure */
   420         -int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVariablePtr) {
          438  +/*
          439  + * Dissect the -filetype nested lists and store the information in the
          440  + * filterInfo structure.
          441  + */
          442  +
          443  +static int
          444  +parseFileFilters(
          445  +    Tcl_Interp *interp,
          446  +    Tcl_Obj *fileTypesPtr,
          447  +    Tcl_Obj *typeVariablePtr)
          448  +{
   421    449   
   422    450       if (!fileTypesPtr) {
   423    451   	filterInfo.doFileTypes = false;
   424    452   	return TCL_OK;
   425    453       }
   426    454   
   427    455       FileFilterList fl;
          456  +
   428    457       TkInitFileFilters(&fl);
   429    458       if (TkGetFileFilters(interp, &fl, fileTypesPtr, 0) != TCL_OK) {
   430    459   	TkFreeFileFilters(&fl);
   431    460   	return TCL_ERROR;
   432    461       }
   433    462   
   434    463       filterInfo.doFileTypes = (fl.filters != NULL);
................................................................................
   441    470   
   442    471       filterInfo.allowedExtensions = [NSMutableArray array];
   443    472       filterInfo.allowedExtensionsAllowAll = NO;
   444    473   
   445    474       if (filterInfo.doFileTypes) {
   446    475   	for (FileFilter *filterPtr = fl.filters; filterPtr;
   447    476   		filterPtr = filterPtr->next) {
   448         -	    NSString * name = [[NSString alloc] initWithUTF8String: filterPtr -> name];
          477  +	    NSString *name = [[NSString alloc] initWithUTF8String: filterPtr->name];
          478  +
   449    479   	    [filterInfo.fileTypeNames addObject:name];
   450    480   	    [name release];
   451         -	    NSMutableArray * clauseextensions = [NSMutableArray array];
   452         -	    NSMutableArray * displayextensions = [NSMutableArray array];
          481  +	    NSMutableArray *clauseextensions = [NSMutableArray array];
          482  +	    NSMutableArray *displayextensions = [NSMutableArray array];
   453    483   	    bool allowsAll = NO;
   454    484   
   455    485   	    for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr;
   456    486   		    clausePtr = clausePtr->next) {
   457    487   
   458    488   		for (GlobPattern *globPtr = clausePtr->patterns; globPtr;
   459    489   			globPtr = globPtr->next) {
   460    490   		    const char *str = globPtr->pattern;
   461    491   		    while (*str && (*str == '*' || *str == '.')) {
   462    492   		    	str++;
   463         -		     }
          493  +		    }
   464    494   		    if (*str) {
   465    495   			NSString *extension = [[NSString alloc] initWithUTF8String:str];
   466    496   			if (![filterInfo.allowedExtensions containsObject:extension]) {
   467    497   			    [filterInfo.allowedExtensions addObject:extension];
   468    498   			}
   469    499   
   470    500   			[clauseextensions addObject:extension];
   471    501   			[displayextensions addObject:[@"." stringByAppendingString:extension]];
   472    502   
   473    503   			[extension release];
   474    504   		    } else {
   475         -			// it is the all pattern (*, .* or *.*)
          505  +			/*
          506  +			 * It is the all pattern (*, .* or *.*)
          507  +			 */
          508  +
   476    509   			allowsAll = YES;
   477    510   			filterInfo.allowedExtensionsAllowAll = YES;
   478    511   			[displayextensions addObject:@"*"];
   479    512   		    }
   480    513   		}
   481    514   	    }
   482    515   	    [filterInfo.fileTypeExtensions addObject:clauseextensions];
   483    516   	    [filterInfo.fileTypeAllowsAll addObject:[NSNumber numberWithBool:allowsAll]];
   484    517   
   485         -	    NSMutableString * label = [[NSMutableString alloc] initWithString:name];
          518  +	    NSMutableString *label = [[NSMutableString alloc] initWithString:name];
   486    519   	    [label appendString:@" ("];
   487    520   	    [label appendString:[displayextensions componentsJoinedByString:@", "]];
   488    521   	    [label appendString:@")"];
   489    522   	    [filterInfo.fileTypeLabels addObject:label];
   490    523   	    [label release];
   491         -
   492    524   	}
   493    525   
   494         -	/* Check if the typevariable exists and matches one of the names */
          526  +	/*
          527  +	 * Check if the typevariable exists and matches one of the names.
          528  +	 */
          529  +
   495    530   	filterInfo.preselectFilter = false;
   496    531   	filterInfo.userHasSelectedFilter = false;
   497    532   	if (typeVariablePtr) {
   498         -	    /* extract the variable content as a NSString */
   499         -	    Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp, typeVariablePtr, NULL, TCL_GLOBAL_ONLY);
          533  +	    /*
          534  +	     * Extract the variable content as a NSString.
          535  +	     */
   500    536   
   501         -	    /* check that the typevariable exists */
          537  +	    Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp,
          538  +		    typeVariablePtr, NULL, TCL_GLOBAL_ONLY);
          539  +
          540  +	    /*
          541  +	     * Check that the typevariable exists.
          542  +	     */
          543  +
   502    544   	    if (selectedFileTypeObj != NULL) {
   503         -		const char *selectedFileType = Tcl_GetString(selectedFileTypeObj);
   504         -		NSString *selectedFileTypeStr = [[NSString alloc] initWithUTF8String:selectedFileType];
   505         -		NSUInteger index = [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr];
          545  +		const char *selectedFileType =
          546  +			Tcl_GetString(selectedFileTypeObj);
          547  +		NSString *selectedFileTypeStr =
          548  +			[[NSString alloc] initWithUTF8String:selectedFileType];
          549  +		NSUInteger index =
          550  +			[filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr];
   506    551   
   507    552   		if (index != NSNotFound) {
   508    553   		    filterInfo.fileTypeIndex = index;
   509    554   		    filterInfo.preselectFilter = true;
   510    555   		}
   511    556   	    }
   512    557   	}
................................................................................
   513    558   
   514    559       }
   515    560   
   516    561       TkFreeFileFilters(&fl);
   517    562       return TCL_OK;
   518    563   }
   519    564   
   520         -bool filterCompatible(NSString *extension, int filterIndex) {
   521         -    NSMutableArray *allowedExtensions = [filterInfo.fileTypeExtensions objectAtIndex: filterIndex];
          565  +static bool
          566  +filterCompatible(
          567  +    NSString *extension,
          568  +    int filterIndex)
          569  +{
          570  +    NSMutableArray *allowedExtensions =
          571  +	    [filterInfo.fileTypeExtensions objectAtIndex: filterIndex];
   522    572   
   523         -    /* If this contains the all pattern, accept any extension */
          573  +    /*
          574  +     * If this contains the all pattern, accept any extension.
          575  +     */
          576  +
   524    577       if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterIndex] boolValue]) {
   525    578   	return true;
   526    579       }
   527    580   
   528    581       return [allowedExtensions containsObject: extension];
   529    582   }
   530         -
   531    583   
   532    584   /*
   533    585    *----------------------------------------------------------------------
   534    586    *
   535    587    * Tk_GetOpenFileObjCmd --
   536    588    *
   537    589    *	This procedure implements the "open file" dialog box for the Mac
................................................................................
   627    679   	    break;
   628    680   	}
   629    681       }
   630    682   
   631    683       if (title) {
   632    684   	[openpanel setTitle:title];
   633    685   
   634         -	/* From OSX 10.11, the title string is silently ignored in the open panel.
   635         -	 * Prepend the title to the message in this case
   636         -	 * NOTE should be conditional on OSX version, but
   637         -	 * -mmacosx-version-min does not revert this behaviour*/
          686  +	/*
          687  +	 * From OSX 10.11, the title string is silently ignored in the open
          688  +	 * panel.  Prepend the title to the message in this case.  NOTE should
          689  +	 * be conditional on OSX version, but -mmacosx-version-min does not
          690  +	 * revert this behaviour
          691  +	 */
   638    692   
   639    693   	if (message) {
   640         -	    NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
          694  +	    NSString *fullmessage =
          695  +		    [[NSString alloc] initWithFormat:@"%@\n%@", title, message];
   641    696   	    [message release];
   642    697   	    [title release];
   643    698   	    message = fullmessage;
   644    699   	} else {
   645    700   	    message = title;
   646    701   	}
   647    702       }
................................................................................
   654    709       [openpanel setAllowsMultipleSelection:multiple];
   655    710   
   656    711       if (parseFileFilters(interp, fileTypesPtr, typeVariablePtr) != TCL_OK) {
   657    712   	goto end;
   658    713       }
   659    714   
   660    715       if (filterInfo.doFileTypes) {
   661         -	NSView  *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
   662         -	NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
          716  +	NSView *accessoryView = [[NSView alloc]
          717  +		initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
          718  +	NSTextField *label = [[NSTextField alloc]
          719  +		initWithFrame:NSMakeRect(0, 0, 60, 22)];
          720  +
   663    721   	[label setEditable:NO];
   664    722   	[label setStringValue:@"Filter:"];
   665    723   	[label setBordered:NO];
   666    724   	[label setBezeled:NO];
   667    725   	[label setDrawsBackground:NO];
   668    726   
   669         -	NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO];
          727  +	NSPopUpButton *popupButton = [[NSPopUpButton alloc]
          728  +		initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO];
          729  +
   670    730   	[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
   671    731   	[popupButton setAction:@selector(selectFormat:)];
   672    732   
   673    733   	[accessoryView addSubview:label];
   674    734   	[accessoryView addSubview:popupButton];
   675    735   
   676    736   	if (filterInfo.preselectFilter) {
   677         -	    /* A specific filter was selected from the typevariable. Select it and
   678         -	     * open the accessory view */
          737  +	    /*
          738  +	     * A specific filter was selected from the typevariable. Select it
          739  +	     * and open the accessory view.
          740  +	     */
          741  +
   679    742   	    [popupButton selectItemAtIndex:filterInfo.fileTypeIndex];
   680         -	    /* on OSX > 10.11, the optons are not visible by default. Ergo allow all file types
          743  +
          744  +	    /*
          745  +	     * On OSX > 10.11, the options are not visible by default. Ergo
          746  +	     * allow all file types
   681    747   	    [openpanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]];
   682    748   	    */
   683    749   	    [openpanel setAllowedFileTypes:filterInfo.allowedExtensions];
   684    750   	} else {
   685    751   	    [openpanel setAllowedFileTypes:filterInfo.allowedExtensions];
   686    752   	}
   687    753   
................................................................................
   689    755   	    [openpanel setAllowsOtherFileTypes:YES];
   690    756   	} else {
   691    757   	    [openpanel setAllowsOtherFileTypes:NO];
   692    758   	}
   693    759   
   694    760   	[openpanel setAccessoryView:accessoryView];
   695    761       } else {
   696         -	/* No filters are given. Allow picking all files */
          762  +	/*
          763  +	 * No filters are given. Allow picking all files.
          764  +	 */
          765  +
   697    766   	[openpanel setAllowsOtherFileTypes:YES];
   698    767       }
   699    768   
   700    769       if (cmdObj) {
   701    770   	callbackInfo = ckalloc(sizeof(FilePanelCallbackInfo));
   702    771   	if (Tcl_IsShared(cmdObj)) {
   703    772   	    cmdObj = Tcl_DuplicateObj(cmdObj);
................................................................................
   707    776   
   708    777       callbackInfo->cmdObj = cmdObj;
   709    778       callbackInfo->interp = interp;
   710    779       callbackInfo->multiple = multiple;
   711    780       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
   712    781       if (haveParentOption && parent && ![parent attachedSheet]) {
   713    782   	parentIsKey = [parent isKeyWindow];
   714         -	if (directory || filename ) {
   715         -	    NSURL * fileURL = getFileURL(directory, filename);
          783  +	if (directory || filename) {
          784  +	    NSURL *fileURL = getFileURL(directory, filename);
          785  +
   716    786   	    [openpanel setDirectoryURL:fileURL];
   717    787   	}
   718    788   
   719    789   	[openpanel beginSheetModalForWindow:parent
   720         -	       completionHandler:^(NSInteger returnCode)
   721         -	       { [NSApp tkFilePanelDidEnd:openpanel
          790  +	       completionHandler:^(NSInteger returnCode) {
          791  +	    [NSApp tkFilePanelDidEnd:openpanel
   722    792   		       returnCode:returnCode
   723         -		       contextInfo:callbackInfo ]; } ];
   724         -	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:openpanel];
          793  +		       contextInfo:callbackInfo ];
          794  +	}];
          795  +	modalReturnCode = cmdObj ? modalOther :
          796  +		[NSApp runModalForWindow:openpanel];
   725    797       } else {
   726         -	if (directory || filename ) {
   727         -	    NSURL * fileURL = getFileURL(directory, filename);
          798  +	if (directory || filename) {
          799  +	    NSURL *fileURL = getFileURL(directory, filename);
          800  +
   728    801   	    [openpanel setDirectoryURL:fileURL];
   729    802   	}
   730    803   
   731    804   	modalReturnCode = [openpanel runModal];
   732    805   	[NSApp tkFilePanelDidEnd:openpanel returnCode:modalReturnCode
   733    806   		contextInfo:callbackInfo];
   734    807       }
   735    808       result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
   736    809       if (parentIsKey) {
   737    810   	[parent makeKeyWindow];
   738    811       }
   739    812   
   740         -    if ((typeVariablePtr && (modalReturnCode == NSOKButton)) &&
   741         -	filterInfo.doFileTypes) {
          813  +    if ((typeVariablePtr && (modalReturnCode == NSOKButton))
          814  +	    && filterInfo.doFileTypes) {
   742    815   	/*
   743         -	 * The -typevariable must be set to the selected file type, if the dialog was not cancelled
          816  +	 * The -typevariable must be set to the selected file type, if the
          817  +	 * dialog was not cancelled.
   744    818   	 */
          819  +
   745    820   	NSUInteger selectedFilterIndex = filterInfo.fileTypeIndex;
   746    821   	NSString *selectedFilter = NULL;
          822  +
   747    823   	if (filterInfo.userHasSelectedFilter) {
   748    824   	    selectedFilterIndex = filterInfo.fileTypeIndex;
   749    825   	    selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
   750    826   	} else {
   751         -	    /* Difficult case: the user has not touched the filter settings, but we must
   752         -	     * return something in the typevariable. First check if the preselected type is compatible
   753         -	     * with the selected file, otherwise choose the first compatible type from the list,
   754         -	     * finally fall back to the empty string */
          827  +	    /*
          828  +	     * Difficult case: the user has not touched the filter settings,
          829  +	     * but we must return something in the typevariable. First check if
          830  +	     * the preselected type is compatible with the selected file,
          831  +	     * otherwise choose the first compatible type from the list,
          832  +	     * finally fall back to the empty string.
          833  +	     */
          834  +
   755    835   	    NSURL *selectedFile;
          836  +
   756    837   	    if (multiple) {
   757         -		// Use the first file in the case of multiple selection
   758         -		// Anyway it is not overly useful here
          838  +		/*
          839  +		 * Use the first file in the case of multiple selection.
          840  +		 * Anyway it is not overly useful here.
          841  +		 */
   759    842   		selectedFile = [[openpanel URLs] objectAtIndex:0];
   760    843   	    } else {
   761    844   		selectedFile = [openpanel URL];
   762    845   	    }
   763    846   
   764    847   	    NSString *extension = [selectedFile pathExtension];
          848  +
   765    849   	    if (filterInfo.preselectFilter &&
   766         -		filterCompatible(extension, filterInfo.fileTypeIndex)) {
          850  +		    filterCompatible(extension, filterInfo.fileTypeIndex)) {
   767    851   		selectedFilterIndex = filterInfo.fileTypeIndex;  // The preselection from the typevariable
   768    852   		selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
   769    853   	    } else {
   770    854   		// scan the list
   771    855   		NSUInteger i;
          856  +
   772    857   		for (i = 0; i < [filterInfo.fileTypeNames count]; i++) {
   773    858   		    if (filterCompatible(extension, i)) {
   774    859   			selectedFilterIndex = i;
   775    860   			break;
   776    861   		    }
   777    862   		}
   778    863   		if (i == selectedFilterIndex) {
   779    864   		    selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
   780    865   		} else {
   781    866   		    selectedFilter = @"";
   782    867   		}
   783         -
   784    868   	    }
   785    869   	}
   786    870   
   787    871   	Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
   788         -		Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY);
          872  +		Tcl_NewStringObj([selectedFilter UTF8String], -1),
          873  +		TCL_GLOBAL_ONLY);
   789    874       }
   790         -
   791    875   
   792    876     end:
   793    877       return result;
   794    878   }
   795         -
   796    879   
   797    880   /*
   798    881    *----------------------------------------------------------------------
   799    882    *
   800    883    * Tk_GetSaveFileObjCmd --
   801    884    *
   802    885    *	This procedure implements the "save file" dialog box for the Mac
................................................................................
   803    886    *	platform. See the user documentation for details on what it does.
   804    887    *
   805    888    * Results:
   806    889    *	A standard Tcl result.
   807    890    *
   808    891    * Side effects:
   809    892    *	See user documentation.
          893  + *
   810    894    *----------------------------------------------------------------------
   811    895    */
   812    896   
   813    897   int
   814    898   Tk_GetSaveFileObjCmd(
   815    899       ClientData clientData,	/* Main window associated with interpreter. */
   816    900       Tcl_Interp *interp,		/* Current interpreter. */
................................................................................
   824    908       int index, len;
   825    909       Tcl_Obj *cmdObj = NULL, *typeVariablePtr = NULL, *fileTypesPtr = NULL;
   826    910       FilePanelCallbackInfo callbackInfoStruct;
   827    911       FilePanelCallbackInfo *callbackInfo = &callbackInfoStruct;
   828    912       NSString *directory = nil, *filename = nil, *defaultType = nil;
   829    913       NSString *message = nil, *title = nil;
   830    914       NSWindow *parent;
   831         -    savepanel =  [NSSavePanel savePanel];
          915  +    savepanel = [NSSavePanel savePanel];
   832    916       NSInteger modalReturnCode = modalError;
   833    917       BOOL parentIsKey = NO;
   834    918   
   835    919       for (i = 1; i < objc; i += 2) {
   836    920   	if (Tcl_GetIndexFromObjStruct(interp, objv[i], saveOptionStrings,
   837    921   		sizeof(char *), "option", TCL_EXACT, &index) != TCL_OK) {
   838    922   	    goto end;
................................................................................
   902    986   		break;
   903    987   	}
   904    988       }
   905    989   
   906    990       if (title) {
   907    991   	[savepanel setTitle:title];
   908    992   
   909         -	/* From OSX 10.11, the title string is silently ignored, if the save panel is a sheet.
   910         -	 * Prepend the title to the message in this case
   911         -	 * NOTE should be conditional on OSX version, but
   912         -	 * -mmacosx-version-min does not revert this behaviour*/
          993  +	/*
          994  +	 * From OSX 10.11, the title string is silently ignored, if the save
          995  +	 * panel is a sheet.  Prepend the title to the message in this case.
          996  +	 * NOTE: should be conditional on OSX version, but -mmacosx-version-min
          997  +	 * does not revert this behaviour.
          998  +	 */
          999  +
   913   1000   	if (haveParentOption) {
   914   1001   	    if (message) {
   915         -		NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
         1002  +		NSString *fullmessage =
         1003  +		    [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
   916   1004   		[message release];
   917   1005   		[title release];
   918   1006   		message = fullmessage;
   919   1007   	    } else {
   920   1008   		message = title;
   921   1009   	    }
   922   1010   	}
................................................................................
   928   1016       }
   929   1017   
   930   1018       if (parseFileFilters(interp, fileTypesPtr, typeVariablePtr) != TCL_OK) {
   931   1019   	goto end;
   932   1020       }
   933   1021   
   934   1022       if (filterInfo.doFileTypes) {
   935         -	NSView  *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
   936         -	NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
         1023  +	NSView *accessoryView = [[NSView alloc]
         1024  +		initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
         1025  +	NSTextField *label = [[NSTextField alloc]
         1026  +		initWithFrame:NSMakeRect(0, 0, 60, 22)];
         1027  +
   937   1028   	[label setEditable:NO];
   938   1029   	[label setStringValue:NSLocalizedString(@"Format:", nil)];
   939   1030   	[label setBordered:NO];
   940   1031   	[label setBezeled:NO];
   941   1032   	[label setDrawsBackground:NO];
   942   1033   
   943         -	NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO];
         1034  +	NSPopUpButton *popupButton = [[NSPopUpButton alloc]
         1035  +		initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO];
         1036  +
   944   1037   	[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
   945   1038   	[popupButton selectItemAtIndex:filterInfo.fileTypeIndex];
   946   1039   	[popupButton setAction:@selector(saveFormat:)];
   947   1040   
   948   1041   	[accessoryView addSubview:label];
   949   1042   	[accessoryView addSubview:popupButton];
   950   1043   
   951   1044   	[savepanel setAccessoryView:accessoryView];
   952   1045   
   953   1046   	[savepanel setAllowedFileTypes:[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]];
   954   1047   	[savepanel setAllowsOtherFileTypes:filterInfo.allowedExtensionsAllowAll];
   955   1048       } else if (defaultType) {
   956         -	/* If no filetypes are given, defaultextension is an alternative way
   957         -	 * to specify the attached extension. Just propose this extension,
   958         -	 * but don't display an accessory view */
         1049  +	/*
         1050  +	 * If no filetypes are given, defaultextension is an alternative way to
         1051  +	 * specify the attached extension. Just propose this extension, but
         1052  +	 * don't display an accessory view.
         1053  +	 */
         1054  +
   959   1055   	NSMutableArray *AllowedFileTypes = [NSMutableArray array];
         1056  +
   960   1057   	[AllowedFileTypes addObject:defaultType];
   961   1058   	[savepanel setAllowedFileTypes:AllowedFileTypes];
   962   1059   	[savepanel setAllowsOtherFileTypes:YES];
   963   1060       }
   964   1061   
   965   1062       [savepanel setCanSelectHiddenExtension:YES];
   966   1063       [savepanel setExtensionHidden:NO];
................................................................................
   974   1071       }
   975   1072       callbackInfo->cmdObj = cmdObj;
   976   1073       callbackInfo->interp = interp;
   977   1074       callbackInfo->multiple = 0;
   978   1075   
   979   1076       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
   980   1077       if (haveParentOption && parent && ![parent attachedSheet]) {
   981         -       parentIsKey = [parent isKeyWindow];
   982         -       if (directory) {
         1078  +	parentIsKey = [parent isKeyWindow];
         1079  +	if (directory) {
   983   1080   	    [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
   984   1081   	}
   985         -	   /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
         1082  +
         1083  +	/*
         1084  +	 * Check for file name, otherwise set to empty string; crashes with
         1085  +	 * uncaught exception if set to nil.
         1086  +	 */
         1087  +
   986   1088   	if (filename) {
   987   1089   	    [savepanel setNameFieldStringValue:filename];
   988   1090   	} else {
   989   1091   	    [savepanel setNameFieldStringValue:@""];
   990   1092   	}
   991   1093   	[savepanel beginSheetModalForWindow:parent
   992         -	       completionHandler:^(NSInteger returnCode)
   993         -	       { [NSApp tkFilePanelDidEnd:savepanel
         1094  +		completionHandler:^(NSInteger returnCode) {
         1095  +	    [NSApp tkFilePanelDidEnd:savepanel
   994   1096   		       returnCode:returnCode
   995         -		       contextInfo:callbackInfo ]; } ];
   996         -	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel];
         1097  +		       contextInfo:callbackInfo];
         1098  +	}];
         1099  +	modalReturnCode = cmdObj ? modalOther :
         1100  +		[NSApp runModalForWindow:savepanel];
   997   1101       } else {
   998   1102   	if (directory) {
   999   1103   	    [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
  1000   1104   	}
  1001         -	 /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
         1105  +
         1106  +	/*
         1107  +	 * Check for file name, otherwise set to empty string; crashes with
         1108  +	 * uncaught exception if set to nil.
         1109  +	 */
         1110  +
  1002   1111   	if (filename) {
  1003   1112   	    [savepanel setNameFieldStringValue:filename];
  1004   1113   	} else {
  1005   1114   	    [savepanel setNameFieldStringValue:@""];
  1006   1115   	}
  1007   1116   	modalReturnCode = [savepanel runModal];
  1008   1117   	[NSApp tkFilePanelDidEnd:savepanel returnCode:modalReturnCode
................................................................................
  1009   1118   		contextInfo:callbackInfo];
  1010   1119       }
  1011   1120       result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR;
  1012   1121       if (parentIsKey) {
  1013   1122   	[parent makeKeyWindow];
  1014   1123       }
  1015   1124   
  1016         -    if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && filterInfo.doFileTypes) {
         1125  +    if (typeVariablePtr && (modalReturnCode == NSOKButton)
         1126  +	    && filterInfo.doFileTypes) {
  1017   1127   	/*
  1018         -	 * The -typevariable must be set to the selected file type, if the dialog was not cancelled
         1128  +	 * The -typevariable must be set to the selected file type, if the
         1129  +	 * dialog was not cancelled.
  1019   1130   	 */
  1020         -	NSString * selectedFilter = [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex];
         1131  +
         1132  +	NSString *selectedFilter =
         1133  +	    [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex];
  1021   1134   	Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
  1022         -		Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY);
         1135  +		Tcl_NewStringObj([selectedFilter UTF8String], -1),
         1136  +		TCL_GLOBAL_ONLY);
  1023   1137       }
  1024         -
  1025   1138   
  1026   1139     end:
  1027   1140       return result;
  1028   1141   }
  1029   1142   
  1030   1143   /*
  1031   1144    *----------------------------------------------------------------------
................................................................................
  1126   1239   	    cmdObj = Tcl_DuplicateObj(cmdObj);
  1127   1240   	}
  1128   1241   	Tcl_IncrRefCount(cmdObj);
  1129   1242       }
  1130   1243       callbackInfo->cmdObj = cmdObj;
  1131   1244       callbackInfo->interp = interp;
  1132   1245       callbackInfo->multiple = 0;
  1133         -    /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/
         1246  +
         1247  +    /*
         1248  +     * Check for directory value, set to root if not specified; otherwise
         1249  +     * crashes with exception because of nil string parameter.
         1250  +     */
         1251  +
  1134   1252       if (!directory) {
  1135   1253   	directory = @"/";
  1136   1254       }
  1137   1255       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
  1138   1256       if (haveParentOption && parent && ![parent attachedSheet]) {
  1139   1257   	parentIsKey = [parent isKeyWindow];
  1140   1258   	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
  1141   1259   	[panel beginSheetModalForWindow:parent
  1142         -	       completionHandler:^(NSInteger returnCode)
  1143         -	       { [NSApp tkFilePanelDidEnd:panel
  1144         -		       returnCode:returnCode
  1145         -		       contextInfo:callbackInfo ]; } ];
         1260  +		completionHandler:^(NSInteger returnCode) {
         1261  +	    [NSApp tkFilePanelDidEnd:panel
         1262  +		    returnCode:returnCode
         1263  +		    contextInfo:callbackInfo];
         1264  +	}];
  1146   1265   	modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
  1147   1266       } else {
  1148   1267   	[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
  1149   1268   	modalReturnCode = [panel runModal];
  1150   1269   	[NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode
  1151   1270   		contextInfo:callbackInfo];
  1152   1271       }
................................................................................
  1197   1316   
  1198   1317       /*
  1199   1318        * This replaces the old about dialog with a standard alert that displays
  1200   1319        * correctly on 10.14.
  1201   1320        */
  1202   1321   
  1203   1322       NSString *version =  @"Tcl " TCL_PATCH_LEVEL " & Tk " TCL_PATCH_LEVEL;
  1204         -    NSString *url =   @"www.tcl-lang.org";
         1323  +    NSString *url = @"www.tcl-lang.org";
  1205   1324       NSTextView *credits = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,300,300)];
  1206   1325       NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
  1207   1326       NSDictionary *textAttributes = [NSDictionary dictionaryWithObject:font
  1208   1327   					        forKey:NSFontAttributeName];
         1328  +
  1209   1329       [credits insertText: [[NSAttributedString alloc]
  1210   1330   		 initWithString:[NSString stringWithFormat: @"\n"
  1211   1331   		"Tcl and Tk are distributed under a modified BSD license: "
  1212   1332   		"www.tcl.tk/software/tcltk/license.html\n\n"
  1213   1333   		"%1$C 1987-%[email protected] Tcl Core Team and Contributers.\n\n"
  1214   1334   		"%1$C 2011-%[email protected] Kevin Walzer/WordTech Communications LLC.\n\n"
  1215   1335   		"%1$C 2014-%[email protected] Marc Culler.\n\n"
  1216   1336   		"%1$C 2002-2012 Daniel A. Steffen.\n\n"
  1217   1337   		"%1$C 2001-2009 Apple Inc.\n\n"
  1218   1338   		"%1$C 2001-2002 Jim Ingham & Ian Reid\n\n"
  1219   1339   		"%1$C 1998-2000 Jim Ingham & Ray Johnson\n\n"
  1220   1340   		"%1$C 1998-2000 Scriptics Inc.\n\n"
  1221   1341   		"%1$C 1996-1997 Sun Microsystems Inc.", 0xA9, year]
  1222         -	     attributes:textAttributes]
  1223         -             replacementRange:NSMakeRange(0,0)];
         1342  +	    attributes:textAttributes]
         1343  +            replacementRange:NSMakeRange(0,0)];
  1224   1344       [credits setDrawsBackground:NO];
  1225   1345       [credits setEditable:NO];
  1226         -     NSAlert *about = [[NSAlert alloc] init];
         1346  +
         1347  +    NSAlert *about = [[NSAlert alloc] init];
         1348  +
  1227   1349       [[about window] setTitle:@"About Tcl & Tk"];
  1228   1350       [about setMessageText: version];
  1229   1351       [about setInformativeText:url];
  1230   1352       about.accessoryView = credits;
  1231   1353       [about runModal];
  1232   1354       [about release];
  1233   1355   }
................................................................................
  1374   1496       if (indexDefaultOption) {
  1375   1497   	/*
  1376   1498   	 * Any '-default' option needs to know the '-type' option, which is
  1377   1499   	 * why we do this here.
  1378   1500   	 */
  1379   1501   
  1380   1502   	if (Tcl_GetIndexFromObjStruct(interp, objv[indexDefaultOption + 1],
  1381         -		alertButtonStrings, sizeof(char *), "-default value", TCL_EXACT, &index) != TCL_OK) {
         1503  +		alertButtonStrings, sizeof(char *), "-default value",
         1504  +		TCL_EXACT, &index) != TCL_OK) {
  1382   1505   	    goto end;
  1383   1506   	}
  1384   1507   
  1385   1508   	/*
  1386   1509   	 * Need to map from "ok" etc. to 1, 2, 3, right to left.
  1387   1510   	 */
  1388   1511   
................................................................................
  1395   1518   	    goto end;
  1396   1519   	}
  1397   1520       }
  1398   1521       [alert setIcon:[NSApp applicationIconImage]];
  1399   1522       [alert setAlertStyle:alertStyles[iconIndex]];
  1400   1523       i = 0;
  1401   1524       while (i < 3 && alertButtonNames[typeIndex][i]) {
  1402         -	[alert addButtonWithTitle:(NSString*)alertButtonNames[typeIndex][i++]];
         1525  +	[alert addButtonWithTitle:(NSString*) alertButtonNames[typeIndex][i++]];
  1403   1526       }
  1404   1527       buttons = [alert buttons];
  1405   1528       for (NSButton *b in buttons) {
  1406   1529   	NSString *ke = [b keyEquivalent];
  1407   1530   
  1408   1531   	if (([ke isEqualToString:@"\r"] || [ke isEqualToString:@"\033"]) &&
  1409   1532   		![b keyEquivalentModifierMask]) {
................................................................................
  1424   1547       callbackInfo->interp = interp;
  1425   1548       callbackInfo->typeIndex = typeIndex;
  1426   1549       parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
  1427   1550       if (haveParentOption && parent && ![parent attachedSheet]) {
  1428   1551   	parentIsKey = [parent isKeyWindow];
  1429   1552   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1090
  1430   1553    	[alert beginSheetModalForWindow:parent
  1431         -	       completionHandler:^(NSModalResponse returnCode)
  1432         -	       { [NSApp tkAlertDidEnd:alert
  1433         -			returnCode:returnCode
  1434         -			contextInfo:callbackInfo ]; } ];
         1554  +	       completionHandler:^(NSModalResponse returnCode) {
         1555  +	    [NSApp tkAlertDidEnd:alert
         1556  +		    returnCode:returnCode
         1557  +		    contextInfo:callbackInfo];
         1558  +	}];
  1435   1559   #else
  1436   1560   	[alert beginSheetModalForWindow:parent
  1437   1561   	       modalDelegate:NSApp
  1438   1562   	       didEndSelector:@selector(tkAlertDidEnd:returnCode:contextInfo:)
  1439   1563   	       contextInfo:callbackInfo];
  1440   1564   #endif
  1441   1565   	modalReturnCode = cmdObj ? 0 :
................................................................................
  1467   1591   
  1468   1592   typedef struct FontchooserData {
  1469   1593       Tcl_Obj *titleObj;
  1470   1594       Tcl_Obj *cmdObj;
  1471   1595       Tk_Window parent;
  1472   1596   } FontchooserData;
  1473   1597   
  1474         -enum FontchooserEvent { FontchooserClosed, FontchooserSelection };
         1598  +enum FontchooserEvent {
         1599  +    FontchooserClosed,
         1600  +    FontchooserSelection
         1601  +};
  1475   1602   
  1476   1603   static void		FontchooserEvent(int kind);
  1477   1604   static Tcl_Obj *	FontchooserCget(FontchooserData *fcdPtr,
  1478   1605   			    int optionIndex);
  1479   1606   static int		FontchooserConfigureCmd(ClientData clientData,
  1480   1607   			    Tcl_Interp *interp, int objc,
  1481   1608   			    Tcl_Obj *const objv[]);
................................................................................
  1559   1686   @end
  1560   1687   
  1561   1688   /*
  1562   1689    *----------------------------------------------------------------------
  1563   1690    *
  1564   1691    * FontchooserEvent --
  1565   1692    *
  1566         - *	This processes events generated by user interaction with the
  1567         - *	font panel.
         1693  + *	This processes events generated by user interaction with the font
         1694  + *	panel.
  1568   1695    *
  1569   1696    * Results:
  1570   1697    *	None.
  1571   1698    *
  1572   1699    * Side effects:
  1573   1700    *	Additional events may be place on the Tk event queue.
  1574   1701    *
................................................................................
  1619   1746   }
  1620   1747   
  1621   1748   /*
  1622   1749    *----------------------------------------------------------------------
  1623   1750    *
  1624   1751    * FontchooserCget --
  1625   1752    *
  1626         - *	Helper for the FontchooserConfigure command to return the
  1627         - *	current value of any of the options (which may be NULL in
  1628         - *	the structure)
         1753  + *	Helper for the FontchooserConfigure command to return the current value
         1754  + *	of any of the options (which may be NULL in the structure).
  1629   1755    *
  1630   1756    * Results:
  1631   1757    *	Tcl object of option value.
  1632   1758    *
  1633   1759    * Side effects:
  1634   1760    *	None.
  1635   1761    *
................................................................................
  1684   1810   }
  1685   1811   
  1686   1812   /*
  1687   1813    * ----------------------------------------------------------------------
  1688   1814    *
  1689   1815    * FontchooserConfigureCmd --
  1690   1816    *
  1691         - *	Implementation of the 'tk fontchooser configure' ensemble command.
  1692         - *	See the user documentation for what it does.
         1817  + *	Implementation of the 'tk fontchooser configure' ensemble command.  See
         1818  + *	the user documentation for what it does.
  1693   1819    *
  1694   1820    * Results:
  1695   1821    *	See the user documentation.
  1696   1822    *
  1697   1823    * Side effects:
  1698   1824    *	Per-interp data structure may be modified
  1699   1825    *
................................................................................
  1818   1944   	    NSFontPanel *fp = [fm fontPanel:NO];
  1819   1945   
  1820   1946   	    [fp setPanelFont:fontPanelFont isMultiple:NO];
  1821   1947   	    [fm setSelectedFont:fontPanelFont isMultiple:NO];
  1822   1948   	    [fm setSelectedAttributes:fontPanelFontAttributes
  1823   1949   		    isMultiple:NO];
  1824   1950   	    if ([fp isVisible]) {
  1825         -		TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL);
         1951  +		TkSendVirtualEvent(fcdPtr->parent,
         1952  +			"TkFontchooserFontChanged", NULL);
  1826   1953   	    }
  1827   1954   	    break;
  1828   1955   	case FontchooserCmd:
  1829   1956   	    if (fcdPtr->cmdObj) {
  1830   1957   		Tcl_DecrRefCount(fcdPtr->cmdObj);
  1831   1958   	    }
  1832   1959   	    Tcl_GetStringFromObj(objv[i+1], &len);
................................................................................
  1846   1973   }
  1847   1974   
  1848   1975   /*
  1849   1976    * ----------------------------------------------------------------------
  1850   1977    *
  1851   1978    * FontchooserShowCmd --
  1852   1979    *
  1853         - *	Implements the 'tk fontchooser show' ensemble command. The
  1854         - *	per-interp configuration data for the dialog is held in an interp
  1855         - *	associated structure.
         1980  + *	Implements the 'tk fontchooser show' ensemble command. The per-interp
         1981  + *	configuration data for the dialog is held in an interp associated
         1982  + *	structure.
  1856   1983    *
  1857   1984    * Results:
  1858   1985    *	See the user documentation.
  1859   1986    *
  1860   1987    * Side effects:
  1861   1988    *	Font Panel may be shown.
  1862   1989    *
................................................................................
  1874   2001   	    NULL);
  1875   2002   
  1876   2003       if (fcdPtr->parent == None) {
  1877   2004   	fcdPtr->parent = (Tk_Window) clientData;
  1878   2005   	Tk_CreateEventHandler(fcdPtr->parent, StructureNotifyMask,
  1879   2006   		FontchooserParentEventHandler, fcdPtr);
  1880   2007       }
         2008  +
  1881   2009       NSFontManager *fm = [NSFontManager sharedFontManager];
  1882   2010       NSFontPanel *fp = [fm fontPanel:YES];
         2011  +
  1883   2012       if ([fp delegate] != NSApp) {
  1884   2013   	[fp setDelegate:NSApp];
  1885   2014       }
  1886   2015       if (![fp isVisible]) {
  1887   2016   	[fm orderFrontFontPanel:NSApp];
  1888   2017   	TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL);
  1889   2018       }
................................................................................
  1893   2022   }
  1894   2023   
  1895   2024   /*
  1896   2025    * ----------------------------------------------------------------------
  1897   2026    *
  1898   2027    * FontchooserHideCmd --
  1899   2028    *
  1900         - *	Implementation of the 'tk fontchooser hide' ensemble. See the
  1901         - *	user documentation for details.
         2029  + *	Implementation of the 'tk fontchooser hide' ensemble. See the user
         2030  + *	documentation for details.
  1902   2031    *
  1903   2032    * Results:
  1904   2033    *	See the user documentation.
  1905   2034    *
  1906   2035    * Side effects:
  1907   2036    *	Font Panel may be hidden.
  1908   2037    *
................................................................................
  1913   2042   FontchooserHideCmd(
  1914   2043       ClientData clientData,	/* Main window */
  1915   2044       Tcl_Interp *interp,
  1916   2045       int objc,
  1917   2046       Tcl_Obj *const objv[])
  1918   2047   {
  1919   2048       NSFontPanel *fp = [[NSFontManager sharedFontManager] fontPanel:NO];
         2049  +
  1920   2050       if ([fp isVisible]) {
  1921   2051   	[fp orderOut:NSApp];
  1922   2052       }
  1923   2053       return TCL_OK;
  1924   2054   }
  1925   2055   
  1926   2056   /*
................................................................................
  1993   2123   }
  1994   2124   
  1995   2125   /*
  1996   2126    * ----------------------------------------------------------------------
  1997   2127    *
  1998   2128    * TkInitFontchooser --
  1999   2129    *
  2000         - *	Associate the font chooser configuration data with the Tcl
  2001         - *	interpreter. There is one font chooser per interp.
         2130  + *	Associate the font chooser configuration data with the Tcl interpreter.
         2131  + *	There is one font chooser per interp.
  2002   2132    *
  2003   2133    * Results:
  2004   2134    *	None.
  2005   2135    *
  2006   2136    * Side effects:
  2007   2137    *	per-interp configuration data is destroyed.
  2008   2138    *

Changes to macosx/tkMacOSXDraw.c.

     1      1   /*
     2      2    * tkMacOSXDraw.c --
     3      3    *
     4         - *	This file contains functions that perform drawing to
     5         - *	Xlib windows. Most of the functions simple emulate
     6         - *	Xlib functions.
            4  + *	This file contains functions that perform drawing to Xlib windows. Most
            5  + *	of the functions simple emulate Xlib functions.
     7      6    *
     8      7    * Copyright (c) 1995-1997 Sun Microsystems, Inc.
     9      8    * Copyright 2001-2009, Apple Inc.
    10      9    * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
    11     10    * Copyright 2014 Marc Culler.
    12     11    *
    13     12    * See the file "license.terms" for information on usage and redistribution
................................................................................
    27     26   /*
    28     27   #ifdef TK_MAC_DEBUG
    29     28   #define TK_MAC_DEBUG_DRAWING
    30     29   #define TK_MAC_DEBUG_IMAGE_DRAWING
    31     30   #endif
    32     31   */
    33     32   
    34         -#define radians(d) ((d) * (M_PI/180.0))
           33  +#define radians(d)	((d) * (M_PI/180.0))
    35     34   
    36     35   /*
    37     36    * Non-antialiased CG drawing looks better and more like X11 drawing when using
    38     37    * very fine lines, so decrease all linewidths by the following constant.
    39     38    */
    40     39   #define NON_AA_CG_OFFSET .999
    41     40   
    42     41   static int cgAntiAliasLimit = 0;
    43         -#define notAA(w) ((w) < cgAntiAliasLimit)
           42  +#define notAA(w)	((w) < cgAntiAliasLimit)
    44     43   
    45     44   static int useThemedToplevel = 0;
    46     45   static int useThemedFrame = 0;
    47     46   
    48     47   /*
    49     48    * Prototypes for functions used only in this file.
    50     49    */
................................................................................
   115    114    *      implementation does not work correctly.  Originally it relied on
   116    115    *      [NSBitmapImageRep initWithFocusedViewRect:view_rect] which was
   117    116    *      deprecated by Apple in OSX 10.14 and also required the use of other
   118    117    *      deprecated functions such as [NSView lockFocus]. Apple's suggested
   119    118    *      replacement is [NSView cacheDisplayInRect: toBitmapImageRep:] and that
   120    119    *      is what is being used here.  However, that method only works when the
   121    120    *      view has a valid CGContext, and a view is only guaranteed to have a
   122         - *      valid context during a call to [NSView drawRect].  To further
   123         - *      complicate matters, cacheDisplayInRect calls [NSView drawRect].
   124         - *      Essentially it is asking the view to draw a subrectangle of itself into
   125         - *      a special graphics context which is linked to the BitmapImageRep.  But
   126         - *      our implementation of [NSView drawRect] does not allow recursive calls.
   127         - *      If called recursively it returns immediately without doing any drawing.
          121  + *      valid context during a call to [NSView drawRect]. To further complicate
          122  + *      matters, cacheDisplayInRect calls [NSView drawRect]. Essentially it is
          123  + *      asking the view to draw a subrectangle of itself into a special
          124  + *      graphics context which is linked to the BitmapImageRep. But our
          125  + *      implementation of [NSView drawRect] does not allow recursive calls. If
          126  + *      called recursively it returns immediately without doing any drawing.
   128    127    *      So the bottom line is that this function either returns a NULL pointer
   129         - *      or a black image.  To make it useful would require a significant amount
   130         - *      of rewriting of the drawRect method.  Perhaps the next release of OSX
          128  + *      or a black image. To make it useful would require a significant amount
          129  + *      of rewriting of the drawRect method. Perhaps the next release of OSX
   131    130    *      will include some more helpful ways of doing this.
   132    131    *
   133    132    * Results:
   134         - *	Returns an NSBitmapRep representing the image of the given
   135         - *      rectangle of the given drawable.  This object is retained.
   136         - *      The caller is responsible for releasing it.
          133  + *	Returns an NSBitmapRep representing the image of the given rectangle of
          134  + *      the given drawable. This object is retained. The caller is responsible
          135  + *      for releasing it.
   137    136    *
   138         - *      NOTE: The x,y coordinates should be relative to a coordinate system with
   139         - *      origin at the top left, as used by XImage and CGImage, not bottom
          137  + *      NOTE: The x,y coordinates should be relative to a coordinate system
          138  + *      with origin at the top left, as used by XImage and CGImage, not bottom
   140    139    *      left as used by NSView.
   141    140    *
   142    141    * Side effects:
   143    142    *     None
   144    143    *
   145    144    *----------------------------------------------------------------------
   146    145    */
   147         -NSBitmapImageRep*
          146  +
          147  +NSBitmapImageRep *
   148    148   TkMacOSXBitmapRepFromDrawableRect(
   149         -        Drawable drawable,
   150         -	int x,
   151         -	int y,
   152         -	unsigned int width,
   153         -	unsigned int height)
          149  +    Drawable drawable,
          150  +    int x,
          151  +    int y,
          152  +    unsigned int width,
          153  +    unsigned int height)
   154    154   {
   155    155       MacDrawable *mac_drawable = (MacDrawable *) drawable;
   156    156       CGContextRef cg_context = NULL;
   157         -    CGImageRef cg_image=NULL, sub_cg_image = NULL;
          157  +    CGImageRef cg_image = NULL, sub_cg_image = NULL;
   158    158       NSBitmapImageRep *bitmap_rep = NULL;
   159         -    NSView *view=NULL;
   160         -    if ( mac_drawable->flags & TK_IS_PIXMAP ) {
   161         -
          159  +    NSView *view = NULL;
          160  +    if (mac_drawable->flags & TK_IS_PIXMAP) {
   162    161   	/*
   163    162   	 * This MacDrawable is a bitmap, so its view is NULL.
   164    163   	 */
   165    164   
   166         -	cg_context = TkMacOSXGetCGContextForDrawable(drawable);
   167    165   	CGRect image_rect = CGRectMake(x, y, width, height);
   168         -	cg_image = CGBitmapContextCreateImage( (CGContextRef) cg_context);
          166  +
          167  +	cg_context = TkMacOSXGetCGContextForDrawable(drawable);
          168  +	cg_image = CGBitmapContextCreateImage((CGContextRef) cg_context);
   169    169   	sub_cg_image = CGImageCreateWithImageInRect(cg_image, image_rect);
   170         -	if ( sub_cg_image ) {
          170  +	if (sub_cg_image) {
   171    171   	    bitmap_rep = [NSBitmapImageRep alloc];
   172    172   	    [bitmap_rep initWithCGImage:sub_cg_image];
   173    173   	}
   174         -	if ( cg_image ) {
          174  +	if (cg_image) {
   175    175   	    CGImageRelease(cg_image);
   176    176   	}
   177         -    } else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) {
   178         -
          177  +    } else if ((view = TkMacOSXDrawableView(mac_drawable)) != NULL) {
   179    178   	/*
   180    179   	 * Convert Tk top-left to NSView bottom-left coordinates.
   181    180   	 */
   182    181   
   183    182   	int view_height = [view bounds].size.height;
   184    183   	NSRect view_rect = NSMakeRect(x + mac_drawable->xOff,
   185         -			       view_height - height - y - mac_drawable->yOff,
   186         -			       width, height);
          184  +		view_height - height - y - mac_drawable->yOff,
          185  +		width, height);
   187    186   
   188    187   	/*
   189    188   	 * Attempt to copy from the view to a bitmapImageRep.  If the view does
   190    189   	 * not have a valid CGContext, doing this will silently corrupt memory
   191    190   	 * and make a big mess. So, in that case, we mark the view as needing
   192    191   	 * display and return NULL.
   193    192   	 */
................................................................................
   214    213    *
   215    214    *	Copies data from one drawable to another.
   216    215    *
   217    216    * Results:
   218    217    *	None.
   219    218    *
   220    219    * Side effects:
   221         - *	Data is moved from a window or bitmap to a second window or
   222         - *	bitmap.
          220  + *	Data is moved from a window or bitmap to a second window or bitmap.
   223    221    *
   224    222    *----------------------------------------------------------------------
   225    223    */
   226    224   
   227    225   void
   228    226   XCopyArea(
   229    227       Display *display,		/* Display. */
   230    228       Drawable src,		/* Source drawable. */
   231    229       Drawable dst,		/* Destination drawable. */
   232         -    GC gc,				/* GC to use. */
          230  +    GC gc,			/* GC to use. */
   233    231       int src_x,			/* X & Y, width & height */
   234    232       int src_y,			/* define the source rectangle */
   235         -    unsigned int width,	/* that will be copied. */
          233  +    unsigned int width,		/* that will be copied. */
   236    234       unsigned int height,
   237    235       int dest_x,			/* Dest X & Y on dest rect. */
   238    236       int dest_y)
   239    237   {
   240    238       TkMacOSXDrawingContext dc;
   241    239       MacDrawable *srcDraw = (MacDrawable *) src;
   242    240       NSBitmapImageRep *bitmap_rep = NULL;
................................................................................
   245    243   
   246    244       display->request++;
   247    245       if (!width || !height) {
   248    246   	return;
   249    247       }
   250    248   
   251    249       if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) {
   252         -	return;
   253    250   	TkMacOSXDbgMsg("Failed to setup drawing context.");
          251  +	return;
   254    252       }
   255    253   
   256         -    if ( dc.context ) {
   257         -	if (srcDraw->flags & TK_IS_PIXMAP) {
   258         -	    img = TkMacOSXCreateCGImageWithDrawable(src);
   259         -	}else if (TkMacOSXDrawableWindow(src)) {
   260         -	    bitmap_rep =  TkMacOSXBitmapRepFromDrawableRect(src,
   261         -				   src_x, src_y, width, height);
   262         -	    if ( bitmap_rep ) {
   263         -		img = [bitmap_rep CGImage];
   264         -	    }
   265         -	} else {
   266         -	    TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap.");
   267         -	}
   268         -
   269         -	if (img) {
   270         -	    bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
   271         -	    srcRect = CGRectMake(src_x, src_y, width, height);
   272         -	    dstRect = CGRectMake(dest_x, dest_y, width, height);
   273         -	    TkMacOSXDrawCGImage(dst, gc, dc.context, img,
   274         -		     gc->foreground, gc->background, bounds, srcRect, dstRect);
   275         -	    CFRelease(img);
   276         -	} else {
   277         -	    TkMacOSXDbgMsg("Failed to construct CGImage.");
   278         -	}
   279         -
   280         -    } else {
          254  +    if (!dc.context) {
   281    255   	TkMacOSXDbgMsg("Invalid destination drawable - no context.");
   282    256   	return;
   283    257       }
          258  +
          259  +    if (srcDraw->flags & TK_IS_PIXMAP) {
          260  +	img = TkMacOSXCreateCGImageWithDrawable(src);
          261  +    } else if (TkMacOSXDrawableWindow(src)) {
          262  +	bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src,
          263  +		src_x, src_y, width, height);
          264  +	if (bitmap_rep) {
          265  +	    img = [bitmap_rep CGImage];
          266  +	}
          267  +    } else {
          268  +	TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap.");
          269  +    }
          270  +
          271  +    if (img) {
          272  +	bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
          273  +	srcRect = CGRectMake(src_x, src_y, width, height);
          274  +	dstRect = CGRectMake(dest_x, dest_y, width, height);
          275  +	TkMacOSXDrawCGImage(dst, gc, dc.context, img,
          276  +		gc->foreground, gc->background, bounds, srcRect, dstRect);
          277  +	CFRelease(img);
          278  +    } else {
          279  +	TkMacOSXDbgMsg("Failed to construct CGImage.");
          280  +    }
   284    281   
   285    282       TkMacOSXRestoreDrawingContext(&dc);
   286    283   }
   287    284   
   288    285   /*
   289    286    *----------------------------------------------------------------------
   290    287    *
   291    288    * XCopyPlane --
   292    289    *
   293         - *	Copies a bitmap from a source drawable to a destination
   294         - *	drawable. The plane argument specifies which bit plane of
   295         - *	the source contains the bitmap. Note that this implementation
   296         - *	ignores the gc->function.
          290  + *	Copies a bitmap from a source drawable to a destination drawable. The
          291  + *	plane argument specifies which bit plane of the source contains the
          292  + *	bitmap. Note that this implementation ignores the gc->function.
   297    293    *
   298    294    * Results:
   299    295    *	None.
   300    296    *
   301    297    * Side effects:
   302    298    *	Changes the destination drawable.
   303    299    *
................................................................................
   330    326       if (plane != 1) {
   331    327   	Tcl_Panic("Unexpected plane specified for XCopyPlane");
   332    328       }
   333    329       if (srcDraw->flags & TK_IS_PIXMAP) {
   334    330   	if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) {
   335    331   	    return;
   336    332   	}
          333  +
   337    334   	CGContextRef context = dc.context;
          335  +
   338    336   	if (context) {
   339    337   	    CGImageRef img = TkMacOSXCreateCGImageWithDrawable(src);
          338  +
   340    339   	    if (img) {
   341    340   		TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
   342    341   		unsigned long imageBackground  = gc->background;
   343         -                if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP){
          342  +
          343  +                if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP) {
   344    344   		    srcRect = CGRectMake(src_x, src_y, width, height);
   345         -		    CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(clipPtr->value.pixmap);
   346         -		    CGImageRef submask = CGImageCreateWithImageInRect(img, srcRect);
          345  +		    CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(
          346  +			    clipPtr->value.pixmap);
          347  +		    CGImageRef submask = CGImageCreateWithImageInRect(
          348  +			    img, srcRect);
   347    349   		    CGRect rect = CGRectMake(dest_x, dest_y, width, height);
          350  +
   348    351   		    rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff);
   349    352   		    CGContextSaveGState(context);
   350         -		    /* Move the origin of the destination to top left. */
   351         -		    CGContextTranslateCTM(context, 0, rect.origin.y + CGRectGetMaxY(rect));
          353  +
          354  +		    /*
          355  +		     * Move the origin of the destination to top left.
          356  +		     */
          357  +
          358  +		    CGContextTranslateCTM(context,
          359  +			    0, rect.origin.y + CGRectGetMaxY(rect));
   352    360   		    CGContextScaleCTM(context, 1, -1);
   353         -		    /* Fill with the background color, clipping to the mask. */
          361  +
          362  +		    /*
          363  +		     * Fill with the background color, clipping to the mask.
          364  +		     */
          365  +
   354    366   		    CGContextClipToMask(context, rect, submask);
   355    367   		    TkMacOSXSetColorInContext(gc, gc->background, dc.context);
   356    368   		    CGContextFillRect(context, rect);
   357         -		    /* Fill with the foreground color, clipping to the
   358         -		       intersection of img and mask. */
   359         -		    CGImageRef subimage = CGImageCreateWithImageInRect(img, srcRect);
          369  +
          370  +		    /*
          371  +		     * Fill with the foreground color, clipping to the
          372  +		     * intersection of img and mask.
          373  +		     */
          374  +
          375  +		    CGImageRef subimage = CGImageCreateWithImageInRect(
          376  +			    img, srcRect);
   360    377   		    CGContextClipToMask(context, rect, subimage);
   361    378   		    TkMacOSXSetColorInContext(gc, gc->foreground, context);
   362    379   		    CGContextFillRect(context, rect);
   363    380   		    CGContextRestoreGState(context);
   364    381   		    CGImageRelease(img);
   365    382   		    CGImageRelease(mask);
   366    383   		    CGImageRelease(submask);
   367    384   		    CGImageRelease(subimage);
   368    385   		} else {
   369         -		    bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
          386  +		    bounds = CGRectMake(0, 0,
          387  +			    srcDraw->size.width, srcDraw->size.height);
   370    388   		    srcRect = CGRectMake(src_x, src_y, width, height);
   371    389   		    dstRect = CGRectMake(dest_x, dest_y, width, height);
   372         -		    TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground,
   373         -					imageBackground, bounds, srcRect, dstRect);
          390  +		    TkMacOSXDrawCGImage(dst, gc, dc.context, img,
          391  +			    gc->foreground, imageBackground, bounds,
          392  +			    srcRect, dstRect);
   374    393   		    CGImageRelease(img);
   375    394   		}
   376         -	    } else { /* no image */
          395  +	    } else {
          396  +		/* no image */
   377    397   		TkMacOSXDbgMsg("Invalid source drawable");
   378    398   	    }
   379    399   	} else {
   380         -	    TkMacOSXDbgMsg("Invalid destination drawable - could not get a bitmap context.");
          400  +	    TkMacOSXDbgMsg("Invalid destination drawable - "
          401  +		    "could not get a bitmap context.");
   381    402   	}
   382    403   	TkMacOSXRestoreDrawingContext(&dc);
   383         -    } else { /* source drawable is a window, not a Pixmap */
   384         -	XCopyArea(display, src, dst, gc, src_x, src_y, width, height, dest_x, dest_y);
          404  +    } else {
          405  +	/*
          406  +	 * Source drawable is a Window, not a Pixmap.
          407  +	 */
          408  +
          409  +	XCopyArea(display, src, dst, gc, src_x, src_y, width, height,
          410  +		dest_x, dest_y);
   385    411       }
   386    412   }
   387    413   
   388    414   /*
   389    415    *----------------------------------------------------------------------
   390    416    *
   391    417    * TkMacOSXCreateCGImageWithDrawable --
................................................................................
   426    452    *
   427    453    * Side effects:
   428    454    *	None.
   429    455    *
   430    456    *----------------------------------------------------------------------
   431    457    */
   432    458   
   433         -static NSImage*
          459  +static NSImage *
   434    460   CreateNSImageWithPixmap(
   435    461       Pixmap pixmap,
   436    462       int width,
   437    463       int height)
   438    464   {
   439    465       CGImageRef cgImage;
   440    466       NSImage *nsImage;
................................................................................
   462    488    *
   463    489    * Side effects:
   464    490    *	None.
   465    491    *
   466    492    *----------------------------------------------------------------------
   467    493    */
   468    494   
   469         -NSImage*
          495  +NSImage *
   470    496   TkMacOSXGetNSImageWithTkImage(
   471    497       Display *display,
   472    498       Tk_Image image,
   473    499       int width,
   474    500       int height)
   475    501   {
   476    502       Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0);
................................................................................
   495    521    *
   496    522    * Side effects:
   497    523    *	None.
   498    524    *
   499    525    *----------------------------------------------------------------------
   500    526    */
   501    527   
   502         -NSImage*
          528  +NSImage *
   503    529   TkMacOSXGetNSImageWithBitmap(
   504    530       Display *display,
   505    531       Pixmap bitmap,
   506    532       GC gc,
   507    533       int width,
   508    534       int height)
   509    535   {
................................................................................
   546    572   
   547    573       if (macDraw && (macDraw->flags & TK_IS_PIXMAP) && !macDraw->context) {
   548    574   	const size_t bitsPerComponent = 8;
   549    575   	size_t bitsPerPixel, bytesPerRow, len;
   550    576   	CGColorSpaceRef colorspace = NULL;
   551    577   	CGBitmapInfo bitmapInfo =
   552    578   #ifdef __LITTLE_ENDIAN__
   553         -	kCGBitmapByteOrder32Host;
          579  +		kCGBitmapByteOrder32Host;
   554    580   #else
   555         -	kCGBitmapByteOrderDefault;
          581  +		kCGBitmapByteOrderDefault;
   556    582   #endif
   557    583   	char *data;
   558         -	CGRect bounds = CGRectMake(0, 0, macDraw->size.width, macDraw->size.height);
          584  +	CGRect bounds = CGRectMake(0, 0,
          585  +		macDraw->size.width, macDraw->size.height);
   559    586   
   560    587   	if (macDraw->flags & TK_IS_BW_PIXMAP) {
   561    588   	    bitsPerPixel = 8;
   562         -	    bitmapInfo = (CGBitmapInfo)kCGImageAlphaOnly;
          589  +	    bitmapInfo = (CGBitmapInfo) kCGImageAlphaOnly;
   563    590   	} else {
   564    591   	    colorspace = CGColorSpaceCreateDeviceRGB();
   565    592   	    bitsPerPixel = 32;
   566    593   	    bitmapInfo |= kCGImageAlphaPremultipliedFirst;
   567    594   	}
   568         -	bytesPerRow = ((size_t) macDraw->size.width * bitsPerPixel + 127) >> 3
   569         -		& ~15;
          595  +	bytesPerRow = ((size_t)
          596  +		macDraw->size.width * bitsPerPixel + 127) >> 3 & ~15;
   570    597   	len = macDraw->size.height * bytesPerRow;
   571    598   	data = ckalloc(len);
   572    599   	bzero(data, len);
   573    600   	macDraw->context = CGBitmapContextCreate(data, macDraw->size.width,
   574    601   		macDraw->size.height, bitsPerComponent, bytesPerRow,
   575    602   		colorspace, bitmapInfo);
   576    603   	if (macDraw->context) {
................................................................................
   626    653   	    if (subImage) {
   627    654   		image = subImage;
   628    655   	    }
   629    656   	}
   630    657   	dstBounds = CGRectOffset(dstBounds, macDraw->xOff, macDraw->yOff);
   631    658   	if (CGImageIsMask(image)) {
   632    659   	    if (macDraw->flags & TK_IS_BW_PIXMAP) {
   633         -
   634         -		/* Set fill color to black; background comes from the context,
          660  +		/*
          661  +		 * Set fill color to black; background comes from the context,
   635    662   		 * or is transparent.
   636    663   		 */
   637    664   
   638    665   		if (imageBackground != TRANSPARENT_PIXEL << 24) {
   639    666   		    CGContextClearRect(context, dstBounds);
   640    667   		}
   641    668   		CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
................................................................................
   651    678   #ifdef TK_MAC_DEBUG_IMAGE_DRAWING
   652    679   	CGContextSaveGState(context);
   653    680   	CGContextSetLineWidth(context, 1.0);
   654    681   	CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.1);
   655    682   	CGContextSetRGBFillColor(context, 0, 1, 0, 0.1);
   656    683   	CGContextFillRect(context, dstBounds);
   657    684   	CGContextStrokeRect(context, dstBounds);
          685  +
   658    686   	CGPoint p[4] = {dstBounds.origin,
   659    687   	    CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMaxY(dstBounds)),
   660    688   	    CGPointMake(CGRectGetMinX(dstBounds), CGRectGetMaxY(dstBounds)),
   661    689   	    CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMinY(dstBounds))
   662    690   	};
          691  +
   663    692   	CGContextStrokeLineSegments(context, p, 4);
   664    693   	CGContextRestoreGState(context);
   665    694   	TkMacOSXDbgMsg("Drawing CGImage at (x=%f, y=%f), (w=%f, h=%f)",
   666    695   		dstBounds.origin.x, dstBounds.origin.y,
   667    696   		dstBounds.size.width, dstBounds.size.height);
   668    697   #else /* TK_MAC_DEBUG_IMAGE_DRAWING */
   669    698   	CGContextSaveGState(context);
................................................................................
   732    761   			macWin->yOff + points[i].y + o);
   733    762   	    } else {
   734    763   		prevx += points[i].x;
   735    764   		prevy += points[i].y;
   736    765   		CGContextAddLineToPoint(dc.context, prevx, prevy);
   737    766   	    }
   738    767   	}
          768  +
   739    769           /*
   740         -         * In the case of closed polylines, the first and last points
   741         -         * are the same. We want miter or bevel join be rendered also
   742         -         * at this point, this needs telling CoreGraphics that the
   743         -         * path is closed.
          770  +         * In the case of closed polylines, the first and last points are the
          771  +         * same. We want miter or bevel join be rendered also at this point,
          772  +         * this needs telling CoreGraphics that the path is closed.
   744    773            */
          774  +
   745    775           if ((points[0].x == points[npoints-1].x) &&
   746    776                   (points[0].y == points[npoints-1].y)) {
   747    777               CGContextClosePath(dc.context);
   748    778           }
   749    779   	CGContextStrokePath(dc.context);
   750    780       }
   751    781       TkMacOSXRestoreDrawingContext(&dc);
................................................................................
   816    846    *	Draws a filled polygon on the specified drawable.
   817    847    *
   818    848    *----------------------------------------------------------------------
   819    849    */
   820    850   
   821    851   void
   822    852   XFillPolygon(
   823         -    Display* display,		/* Display. */
          853  +    Display *display,		/* Display. */
   824    854       Drawable d,			/* Draw on this. */
   825    855       GC gc,			/* Use this GC. */
   826         -    XPoint* points,		/* Array of points. */
          856  +    XPoint *points,		/* Array of points. */
   827    857       int npoints,		/* Number of points. */
   828    858       int shape,			/* Shape to draw. */
   829    859       int mode)			/* Drawing mode. */
   830    860   {
   831    861       MacDrawable *macWin = (MacDrawable *) d;
   832    862       TkMacOSXDrawingContext dc;
   833    863       int i;
................................................................................
   898    928   	return;
   899    929       }
   900    930       if (dc.context) {
   901    931   	CGRect rect;
   902    932   	double o = (lw % 2) ? .5 : 0;
   903    933   
   904    934   	rect = CGRectMake(
   905         -		macWin->xOff + x + o,
   906         -		macWin->yOff + y + o,
          935  +		macWin->xOff + x + o, macWin->yOff + y + o,
   907    936   		width, height);
   908    937   	CGContextStrokeRect(dc.context, rect);
   909    938       }
   910    939       TkMacOSXRestoreDrawingContext(&dc);
   911    940   }
   912    941   
   913    942   #ifdef TK_MACOSXDRAW_UNUSED
   914    943   /*
   915    944    *----------------------------------------------------------------------
   916    945    *
   917    946    * XDrawRectangles --
   918    947    *
   919         - *	Draws the outlines of the specified rectangles as if a
   920         - *	five-point PolyLine protocol request were specified for each
   921         - *	rectangle:
          948  + *	Draws the outlines of the specified rectangles as if a five-point
          949  + *	PolyLine protocol request were specified for each rectangle:
   922    950    *
   923    951    *	    [x,y] [x+width,y] [x+width,y+height] [x,y+height] [x,y]
   924    952    *
   925         - *	For the specified rectangles, these functions do not draw a
   926         - *	pixel more than once. XDrawRectangles draws the rectangles in
   927         - *	the order listed in the array. If rectangles intersect, the
   928         - *	intersecting pixels are drawn multiple times. Draws a
   929         - *	rectangle.
          953  + *	For the specified rectangles, these functions do not draw a pixel more
          954  + *	than once. XDrawRectangles draws the rectangles in the order listed in
          955  + *	the array. If rectangles intersect, the intersecting pixels are drawn
          956  + *	multiple times. Draws a rectangle.
   930    957    *
   931    958    * Results:
   932    959    *	None.
   933    960    *
   934    961    * Side effects:
   935    962    *	Draws rectangles on the specified drawable.
   936    963    *
................................................................................
   987   1014    *	Draws onto the specified drawable.
   988   1015    *
   989   1016    *----------------------------------------------------------------------
   990   1017    */
   991   1018   
   992   1019   int
   993   1020   XFillRectangles(
   994         -    Display* display,		/* Display. */
         1021  +    Display *display,		/* Display. */
   995   1022       Drawable d,			/* Draw on this. */
   996   1023       GC gc,			/* Use this GC. */
   997   1024       XRectangle *rectangles,	/* Rectangle array. */
   998   1025       int n_rectangles)		/* Number of rectangles. */
   999   1026   {
  1000   1027       MacDrawable *macWin = (MacDrawable *) d;
  1001   1028       TkMacOSXDrawingContext dc;
................................................................................
  1038   1065    *	Draws an arc on the specified drawable.
  1039   1066    *
  1040   1067    *----------------------------------------------------------------------
  1041   1068    */
  1042   1069   
  1043   1070   void
  1044   1071   XDrawArc(
  1045         -    Display* display,		/* Display. */
         1072  +    Display *display,		/* Display. */
  1046   1073       Drawable d,			/* Draw on this. */
  1047   1074       GC gc,			/* Use this GC. */
  1048   1075       int x, int y,		/* Upper left of bounding rect. */
  1049   1076       unsigned int width,		/* Width & height. */
  1050   1077       unsigned int height,
  1051   1078       int angle1,			/* Staring angle of arc. */
  1052   1079       int angle2)			/* Extent of arc. */
................................................................................
  1095   1122   
  1096   1123   #ifdef TK_MACOSXDRAW_UNUSED
  1097   1124   /*
  1098   1125    *----------------------------------------------------------------------
  1099   1126    *
  1100   1127    * XDrawArcs --
  1101   1128    *
  1102         - *	Draws multiple circular or elliptical arcs. Each arc is
  1103         - *	specified by a rectangle and two angles. The center of the
  1104         - *	circle or ellipse is the center of the rect- angle, and the
  1105         - *	major and minor axes are specified by the width and height.
  1106         - *	Positive angles indicate counterclock- wise motion, and
  1107         - *	negative angles indicate clockwise motion. If the magnitude
  1108         - *	of angle2 is greater than 360 degrees, XDrawArcs truncates it
  1109         - *	to 360 degrees.
         1129  + *	Draws multiple circular or elliptical arcs. Each arc is specified by a
         1130  + *	rectangle and two angles. The center of the circle or ellipse is the
         1131  + *	center of the rect- angle, and the major and minor axes are specified
         1132  + *	by the width and height.  Positive angles indicate counterclock- wise
         1133  + *	motion, and negative angles indicate clockwise motion. If the magnitude
         1134  + *	of angle2 is greater than 360 degrees, XDrawArcs truncates it to 360
         1135  + *	degrees.
  1110   1136    *
  1111   1137    * Results:
  1112   1138    *	None.
  1113   1139    *
  1114   1140    * Side effects:
  1115   1141    *	Draws an arc for each array element on the specified drawable.
  1116   1142    *
................................................................................
  1121   1147   XDrawArcs(
  1122   1148       Display *display,
  1123   1149       Drawable d,
  1124   1150       GC gc,
  1125   1151       XArc *arcArr,
  1126   1152       int nArcs)
  1127   1153   {
  1128         -
  1129   1154       MacDrawable *macWin = (MacDrawable *) d;
  1130   1155       TkMacOSXDrawingContext dc;
  1131   1156       XArc *arcPtr;
  1132   1157       int i, lw = gc->line_width;
  1133   1158   
  1134   1159       display->request++;
  1135   1160       if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
................................................................................
  1191   1216    *	Draws a filled arc on the specified drawable.
  1192   1217    *
  1193   1218    *----------------------------------------------------------------------
  1194   1219    */
  1195   1220   
  1196   1221   void
  1197   1222   XFillArc(
  1198         -    Display* display,		/* Display. */
         1223  +    Display *display,		/* Display. */
  1199   1224       Drawable d,			/* Draw on this. */
  1200   1225       GC gc,			/* Use this GC. */
  1201   1226       int x, int y,		/* Upper left of bounding rect. */
  1202   1227       unsigned int width,		/* Width & height. */
  1203   1228       unsigned int height,
  1204   1229       int angle1,			/* Staring angle of arc. */
  1205   1230       int angle2)			/* Extent of arc. */
................................................................................
  1356   1381   #endif
  1357   1382   
  1358   1383   /*
  1359   1384    *----------------------------------------------------------------------
  1360   1385    *
  1361   1386    * TkScrollWindow --
  1362   1387    *
  1363         - *	Scroll a rectangle of the specified window and accumulate
  1364         - *	a damage region.
         1388  + *	Scroll a rectangle of the specified window and accumulate a damage
         1389  + *	region.
  1365   1390    *
  1366   1391    * Results:
  1367         - *	Returns 0 if the scroll generated no additional damage.
  1368         - *	Otherwise, sets the region that needs to be repainted after
  1369         - *	scrolling and returns 1.
         1392  + *	Returns 0 if the scroll generated no additional damage. Otherwise, sets
         1393  + *	the region that needs to be repainted after scrolling and returns 1.
  1370   1394    *
  1371   1395    * Side effects:
  1372   1396    *	Scrolls the bits in the window.
  1373   1397    *
  1374   1398    *----------------------------------------------------------------------
  1375   1399    */
  1376   1400   
................................................................................
  1381   1405       int x, int y,		/* Position rectangle to be scrolled. */
  1382   1406       int width, int height,
  1383   1407       int dx, int dy,		/* Distance rectangle should be moved. */
  1384   1408       TkRegion damageRgn)		/* Region to accumulate damage in. */
  1385   1409   {
  1386   1410       Drawable drawable = Tk_WindowId(tkwin);
  1387   1411       MacDrawable *macDraw = (MacDrawable *) drawable;
  1388         -    TKContentView *view = (TKContentView *)TkMacOSXDrawableView(macDraw);
         1412  +    TKContentView *view = (TKContentView *) TkMacOSXDrawableView(macDraw);
  1389   1413       CGRect srcRect, dstRect;
  1390   1414       HIShapeRef dmgRgn = NULL, extraRgn = NULL;
  1391   1415       NSRect bounds, visRect, scrollSrc, scrollDst;
  1392   1416       int result = 0;
  1393   1417   
  1394         -    if ( view ) {
  1395         -  	/*  Get the scroll area in NSView coordinates (origin at bottom left). */
         1418  +    if (view) {
         1419  +  	/*
         1420  +	 * Get the scroll area in NSView coordinates (origin at bottom left).
         1421  +	 */
         1422  +
  1396   1423     	bounds = [view bounds];
  1397   1424    	scrollSrc = NSMakeRect(macDraw->xOff + x,
  1398         -			       bounds.size.height - height - (macDraw->yOff + y),
  1399         -			       width, height);
         1425  +		bounds.size.height - height - (macDraw->yOff + y),
         1426  +		width, height);
  1400   1427    	scrollDst = NSOffsetRect(scrollSrc, dx, -dy);
  1401   1428   
  1402         -  	/* Limit scrolling to the window content area. */
         1429  +  	/*
         1430  +	 * Limit scrolling to the window content area.
         1431  +	 */
         1432  +
  1403   1433    	visRect = [view visibleRect];
  1404   1434    	scrollSrc = NSIntersectionRect(scrollSrc, visRect);
  1405   1435    	scrollDst = NSIntersectionRect(scrollDst, visRect);
  1406         - 	if ( !NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst) ) {
         1436  + 	if (!NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst)) {
  1407   1437     	    /*
  1408   1438     	     * Mark the difference between source and destination as damaged.
  1409         -	     * This region is described in NSView coordinates (y=0 at the bottom)
  1410         -	     * and converted to Tk coordinates later.
         1439  +	     * This region is described in NSView coordinates (y=0 at the
         1440  +	     * bottom) and converted to Tk coordinates later.
  1411   1441     	     */
  1412   1442   
  1413   1443   	    srcRect = CGRectMake(x, y, width, height);
  1414   1444   	    dstRect = CGRectOffset(srcRect, dx, dy);
  1415   1445   
  1416         -	    /* Compute the damage. */
         1446  +	    /*
         1447  +	     * Compute the damage.
         1448  +	     */
         1449  +
  1417   1450     	    dmgRgn = HIShapeCreateMutableWithRect(&srcRect);
  1418   1451    	    extraRgn = HIShapeCreateWithRect(&dstRect);
  1419         - 	    ChkErr(HIShapeDifference, dmgRgn, extraRgn, (HIMutableShapeRef) dmgRgn);
         1452  + 	    ChkErr(HIShapeDifference, dmgRgn, extraRgn,
         1453  +		    (HIMutableShapeRef) dmgRgn);
  1420   1454   	    result = HIShapeIsEmpty(dmgRgn) ? 0 : 1;
  1421   1455   
  1422         -	    /* Convert to Tk coordinates, offset by the window origin. */
         1456  +	    /*
         1457  +	     * Convert to Tk coordinates, offset by the window origin.
         1458  +	     */
         1459  +
  1423   1460   	    TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
  1424   1461   	    if (extraRgn) {
  1425   1462   		CFRelease(extraRgn);
  1426   1463   	    }
  1427   1464   
  1428         - 	    /* Scroll the rectangle. */
         1465  + 	    /*
         1466  +	     * Scroll the rectangle.
         1467  +	     */
         1468  +
  1429   1469    	    [view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)];
  1430   1470     	}
  1431   1471       } else {
  1432   1472   	dmgRgn = HIShapeCreateEmpty();
  1433   1473   	TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
  1434   1474       }
  1435   1475   
................................................................................
  1468   1508    *----------------------------------------------------------------------
  1469   1509    *
  1470   1510    * TkMacOSXSetUpDrawingContext --
  1471   1511    *
  1472   1512    *	Set up a drawing context for the given drawable and GC.
  1473   1513    *
  1474   1514    * Results:
  1475         - *	Boolean indicating whether it is ok to draw; if false, drawing
  1476         - *	context was not setup, so do not attempt to draw and do not call
         1515  + *	Boolean indicating whether it is ok to draw; if false, drawing context
         1516  + *	was not setup, so do not attempt to draw and do not call
  1477   1517    *	TkMacOSXRestoreDrawingContext().
  1478   1518    *
  1479   1519    * Side effects:
  1480   1520    *	None.
  1481   1521    *
  1482   1522    *----------------------------------------------------------------------
  1483   1523    */
  1484   1524   
  1485   1525   Bool
  1486   1526   TkMacOSXSetupDrawingContext(
  1487   1527       Drawable d,
  1488   1528       GC gc,
  1489         -    int useCG, /* advisory only ! */
         1529  +    int useCG,			/* advisory only ! */
  1490   1530       TkMacOSXDrawingContext *dcPtr)
  1491   1531   {
  1492         -    MacDrawable *macDraw = ((MacDrawable*)d);
         1532  +    MacDrawable *macDraw = (MacDrawable *) d;
  1493   1533       Bool canDraw = true;
  1494   1534       NSWindow *win = NULL;
  1495   1535       TkMacOSXDrawingContext dc = {};
  1496   1536       CGRect clipBounds;
  1497   1537   
  1498   1538       /*
  1499         -     * If the drawable is not a pixmap and it has an associated
  1500         -     * NSWindow then we know we are drawing to a window.
         1539  +     * If the drawable is not a pixmap and it has an associated NSWindow then
         1540  +     * we know we are drawing to a window.
  1501   1541        */
  1502   1542   
  1503   1543       if (!(macDraw->flags & TK_IS_PIXMAP)) {
  1504   1544   	win = TkMacOSXDrawableWindow(d);
  1505   1545       }
  1506   1546   
  1507   1547       /*
................................................................................
  1512   1552       ClipToGC(d, gc, &dc.clipRgn);
  1513   1553       if (dc.clipRgn && HIShapeIsEmpty(dc.clipRgn)) {
  1514   1554   	canDraw = false;
  1515   1555   	goto end;
  1516   1556       }
  1517   1557   
  1518   1558       /*
  1519         -     * If we already have a CGContext, use it.  Otherwise, if we
  1520         -     * are drawing to a window then we can get one from the
  1521         -     * window.
         1559  +     * If we already have a CGContext, use it.  Otherwise, if we are drawing to
         1560  +     * a window then we can get one from the window.
  1522   1561        */
  1523   1562   
  1524   1563       dc.context = TkMacOSXGetCGContextForDrawable(d);
  1525   1564       if (dc.context) {
  1526   1565   	dc.portBounds = clipBounds = CGContextGetClipBoundingBox(dc.context);
  1527   1566       } else if (win) {
  1528   1567   	NSView *view = TkMacOSXDrawableView(macDraw);
  1529         -	if (view) {
  1530   1568   
  1531         -	    /*
  1532         -	     * We can only draw into the view when the current CGContext is
  1533         -	     * valid and belongs to the view.  Validity can only be guaranteed
  1534         -	     * inside of a view's drawRect or setFrame methods.  The isDrawing
  1535         -	     * attribute tells us whether we are being called from one of those
  1536         -	     * methods.
  1537         -	     *
  1538         -	     * If the CGContext is not valid, or belongs to a different View,
  1539         -	     * then we mark our view as needing display and return failure.
  1540         -	     * It should get drawn in a later call to drawRect.
  1541         -	     */
  1542         -
  1543         -           if (view != [NSView focusView]) {
  1544         -	       [view setNeedsDisplay:YES];
  1545         -	       canDraw = false;
  1546         -	       goto end;
  1547         -	   }
  1548         -	    dc.view = view;
  1549         -	    dc.context = GET_CGCONTEXT;
  1550         -	    dc.portBounds = NSRectToCGRect([view bounds]);
  1551         -	    if (dc.clipRgn) {
  1552         -		clipBounds = CGContextGetClipBoundingBox(dc.context);
  1553         -	    }
  1554         -	} else {
         1569  +	if (!view) {
  1555   1570   	    Tcl_Panic("TkMacOSXSetupDrawingContext(): "
  1556   1571   		    "no NSView to draw into !");
  1557   1572   	}
         1573  +
         1574  +	/*
         1575  +	 * We can only draw into the view when the current CGContext is valid
         1576  +	 * and belongs to the view.  Validity can only be guaranteed inside of
         1577  +	 * a view's drawRect or setFrame methods.  The isDrawing attribute
         1578  +	 * tells us whether we are being called from one of those methods.
         1579  +	 *
         1580  +	 * If the CGContext is not valid, or belongs to a different View, then
         1581  +	 * we mark our view as needing display and return failure. It should
         1582  +	 * get drawn in a later call to drawRect.
         1583  +	 */
         1584  +
         1585  +	if (view != [NSView focusView]) {
         1586  +	    [view setNeedsDisplay:YES];
         1587  +	    canDraw = false;
         1588  +	    goto end;
         1589  +	}
         1590  +	dc.view = view;
         1591  +	dc.context = GET_CGCONTEXT;
         1592  +	dc.portBounds = NSRectToCGRect([view bounds]);
         1593  +	if (dc.clipRgn) {
         1594  +	    clipBounds = CGContextGetClipBoundingBox(dc.context);
         1595  +	}
  1558   1596       } else {
  1559   1597   	Tcl_Panic("TkMacOSXSetupDrawingContext(): "
  1560   1598   		"no context to draw into !");
  1561   1599       }
  1562   1600   
  1563   1601       /*
  1564   1602        * Configure the drawing context.
  1565   1603        */
  1566   1604   
  1567   1605       if (dc.context) {
  1568         -	CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
  1569         -		.ty = dc.portBounds.size.height};
         1606  +	CGAffineTransform t = {
         1607  +	    .a = 1, .b = 0,
         1608  +	    .c = 0, .d = -1,
         1609  +	    .tx = 0,
         1610  +	    .ty = dc.portBounds.size.height
         1611  +	};
         1612  +
  1570   1613   	dc.portBounds.origin.x += macDraw->xOff;
  1571   1614   	dc.portBounds.origin.y += macDraw->yOff;
  1572   1615   	CGContextSaveGState(dc.context);
  1573   1616   	CGContextSetTextDrawingMode(dc.context, kCGTextFill);
  1574   1617   	CGContextConcatCTM(dc.context, t);
  1575   1618   	if (dc.clipRgn) {
  1576   1619   #ifdef TK_MAC_DEBUG_DRAWING
................................................................................
  1577   1620   	    CGContextSaveGState(dc.context);
  1578   1621   	    ChkErr(HIShapeReplacePathInCGContext, dc.clipRgn, dc.context);
  1579   1622   	    CGContextSetRGBFillColor(dc.context, 1.0, 0.0, 0.0, 0.1);
  1580   1623   	    CGContextEOFillPath(dc.context);
  1581   1624   	    CGContextRestoreGState(dc.context);
  1582   1625   #endif /* TK_MAC_DEBUG_DRAWING */
  1583   1626   	    CGRect r;
         1627  +
  1584   1628   	    if (!HIShapeIsRectangular(dc.clipRgn) || !CGRectContainsRect(
  1585   1629   		    *HIShapeGetBounds(dc.clipRgn, &r),
  1586   1630   		    CGRectApplyAffineTransform(clipBounds, t))) {
  1587   1631   		ChkErr(HIShapeReplacePathInCGContext, dc.clipRgn, dc.context);
  1588   1632   		CGContextEOClip(dc.context);
  1589   1633   	    }
  1590   1634   	}
................................................................................
  1604   1648   	    double w = gc->line_width;
  1605   1649   
  1606   1650   	    TkMacOSXSetColorInContext(gc, gc->foreground, dc.context);
  1607   1651   	    if (win) {
  1608   1652   		CGContextSetPatternPhase(dc.context, CGSizeMake(
  1609   1653   			dc.portBounds.size.width, dc.portBounds.size.height));
  1610   1654   	    }
  1611         -	    if(gc->function != GXcopy) {
         1655  +	    if (gc->function != GXcopy) {
  1612   1656   		TkMacOSXDbgMsg("Logical functions other than GXcopy are "
  1613   1657   			"not supported for CG drawing!");
  1614   1658   	    }
  1615         -	    /* When should we antialias? */
         1659  +
         1660  +	    /*
         1661  +	     * When should we antialias?
         1662  +	     */
         1663  +
  1616   1664   	    shouldAntialias = !notAA(gc->line_width);
  1617   1665   	    if (!shouldAntialias) {
  1618         -		/* Make non-antialiased CG drawing look more like X11 */
         1666  +		/*
         1667  +		 * Make non-antialiased CG drawing look more like X11.
         1668  +		 */
         1669  +
  1619   1670   		w -= (gc->line_width ? NON_AA_CG_OFFSET : 0);
  1620   1671   	    }
  1621   1672   	    CGContextSetShouldAntialias(dc.context, shouldAntialias);
  1622   1673   	    CGContextSetLineWidth(dc.context, w);
  1623   1674   	    if (gc->line_style != LineSolid) {
  1624   1675   		int num = 0;
  1625         -		char *p = &(gc->dashes);
         1676  +		char *p = &gc->dashes;
  1626   1677   		CGFloat dashOffset = gc->dash_offset;
  1627   1678   		CGFloat lengths[10];
  1628   1679   
  1629   1680   		while (p[num] != '\0' && num < 10) {
  1630   1681   		    lengths[num] = p[num];
  1631   1682   		    num++;
  1632   1683   		}
  1633   1684   		CGContextSetLineDash(dc.context, dashOffset, lengths, num);
  1634   1685   	    }
  1635         -	    if ((unsigned)gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) {
         1686  +	    if ((unsigned) gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) {
  1636   1687   		CGContextSetLineCap(dc.context,
  1637         -			cgCap[(unsigned)gc->cap_style]);
         1688  +			cgCap[(unsigned) gc->cap_style]);
  1638   1689   	    }
  1639   1690   	    if ((unsigned)gc->join_style < sizeof(cgJoin)/sizeof(CGLineJoin)) {
  1640   1691   		CGContextSetLineJoin(dc.context,
  1641         -			cgJoin[(unsigned)gc->join_style]);
         1692  +			cgJoin[(unsigned) gc->join_style]);
  1642   1693   	    }
  1643   1694   	}
  1644   1695       }
  1645   1696   
  1646   1697   end:
  1647   1698   #ifdef TK_MAC_DEBUG_DRAWING
  1648   1699       if (!canDraw && win != NULL) {
  1649   1700   	TkWindow *winPtr = TkMacOSXGetTkWindow(win);
  1650         -	if (winPtr) fprintf(stderr, "Cannot draw in %s - postponing.\n",
  1651         -			    Tk_PathName(winPtr));
         1701  +
         1702  +	if (winPtr) {
         1703  +	    fprintf(stderr, "Cannot draw in %s - postponing.\n",
         1704  +		    Tk_PathName(winPtr));
         1705  +	}
  1652   1706       }
  1653   1707   #endif
  1654   1708       if (!canDraw && dc.clipRgn) {
  1655   1709   	CFRelease(dc.clipRgn);
  1656   1710   	dc.clipRgn = NULL;
  1657   1711       }
  1658   1712       *dcPtr = dc;
................................................................................
  1715   1769       MacDrawable *macDraw = (MacDrawable *) drawable;
  1716   1770       HIShapeRef clipRgn = NULL;
  1717   1771   
  1718   1772       if (macDraw->winPtr && macDraw->flags & TK_CLIP_INVALID) {
  1719   1773   	TkMacOSXUpdateClipRgn(macDraw->winPtr);
  1720   1774   #ifdef TK_MAC_DEBUG_DRAWING
  1721   1775   	TkMacOSXDbgMsg("%s", macDraw->winPtr->pathName);
         1776  +
  1722   1777   	NSView *view = TkMacOSXDrawableView(macDraw);
         1778  +
  1723   1779   	CGContextSaveGState(context);
  1724   1780   	CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0,
  1725   1781   	      -1.0, 0.0, [view bounds].size.height));
  1726   1782   	ChkErr(HIShapeReplacePathInCGContext, macDraw->visRgn, context);
  1727   1783   	CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.1);
  1728   1784   	CGContextEOFillPath(context);
  1729   1785   	CGContextRestoreGState(context);
................................................................................
  1739   1795   }
  1740   1796   
  1741   1797   /*
  1742   1798    *----------------------------------------------------------------------
  1743   1799    *
  1744   1800    * TkMacOSXSetUpClippingRgn --
  1745   1801    *
  1746         - *	Set up the clipping region so that drawing only occurs on the
  1747         - *	specified X subwindow.
         1802  + *	Set up the clipping region so that drawing only occurs on the specified
         1803  + *	X subwindow.
  1748   1804    *
  1749   1805    * Results:
  1750   1806    *	None.
  1751   1807    *
  1752   1808    * Side effects:
  1753   1809    *	None.
  1754   1810    *
................................................................................
  1762   1818   }
  1763   1819   
  1764   1820   /*
  1765   1821    *----------------------------------------------------------------------
  1766   1822    *
  1767   1823    * TkpClipDrawableToRect --
  1768   1824    *
  1769         - *	Clip all drawing into the drawable d to the given rectangle.
  1770         - *	If width or height are negative, reset to no clipping.
         1825  + *	Clip all drawing into the drawable d to the given rectangle. If width
         1826  + *	or height are negative, reset to no clipping.
  1771   1827    *
  1772   1828    * Results:
  1773   1829    *	None.
  1774   1830    *
  1775   1831    * Side effects:
  1776   1832    *	Subsequent drawing into d is offset and clipped as specified.
  1777   1833    *
................................................................................
  1828   1884   static void
  1829   1885   ClipToGC(
  1830   1886       Drawable d,
  1831   1887       GC gc,
  1832   1888       HIShapeRef *clipRgnPtr) /* must point to initialized variable */
  1833   1889   {
  1834   1890       if (gc && gc->clip_mask &&
  1835         -	    ((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) {
  1836         -	TkRegion gcClip = ((TkpClipMask*)gc->clip_mask)->value.region;
         1891  +	    ((TkpClipMask *) gc->clip_mask)->type == TKP_CLIP_REGION) {
         1892  +	TkRegion gcClip = ((TkpClipMask *) gc->clip_mask)->value.region;
  1837   1893   	int xOffset = ((MacDrawable *) d)->xOff + gc->clip_x_origin;
  1838   1894   	int yOffset = ((MacDrawable *) d)->yOff + gc->clip_y_origin;
  1839   1895   	HIShapeRef clipRgn = *clipRgnPtr, gcClipRgn;
  1840   1896   
  1841   1897   	TkMacOSXOffsetRegion(gcClip, xOffset, yOffset);
  1842   1898   	gcClipRgn = TkMacOSXGetNativeRegion(gcClip);
  1843   1899   	if (clipRgn) {
................................................................................
  1852   1908   }
  1853   1909   
  1854   1910   /*
  1855   1911    *----------------------------------------------------------------------
  1856   1912    *
  1857   1913    * TkMacOSXMakeStippleMap --
  1858   1914    *
  1859         - *	Given a drawable and a stipple pattern this function draws the
  1860         - *	pattern repeatedly over the drawable. The drawable can then
  1861         - *	be used as a mask for bit-bliting a stipple pattern over an
  1862         - *	object.
         1915  + *	Given a drawable and a stipple pattern this function draws the pattern
         1916  + *	repeatedly over the drawable. The drawable can then be used as a mask
         1917  + *	for bit-bliting a stipple pattern over an object.
  1863   1918    *
  1864   1919    * Results:
  1865   1920    *	A BitMap data structure.
  1866   1921    *
  1867   1922    * Side effects:
  1868   1923    *	None.
  1869   1924    *
................................................................................
  1879   1934   }
  1880   1935   
  1881   1936   /*
  1882   1937    *----------------------------------------------------------------------
  1883   1938    *
  1884   1939    * TkpDrawHighlightBorder --
  1885   1940    *
  1886         - *	This procedure draws a rectangular ring around the outside of
  1887         - *	a widget to indicate that it has received the input focus.
         1941  + *	This procedure draws a rectangular ring around the outside of a widget
         1942  + *	to indicate that it has received the input focus.
  1888   1943    *
  1889         - *	On the Macintosh, this puts a 1 pixel border in the bgGC color
  1890         - *	between the widget and the focus ring, except in the case where
  1891         - *	highlightWidth is 1, in which case the border is left out.
         1944  + *	On the Macintosh, this puts a 1 pixel border in the bgGC color between
         1945  + *	the widget and the focus ring, except in the case where highlightWidth
         1946  + *	is 1, in which case the border is left out.
  1892   1947    *
  1893   1948    *	For proper Mac L&F, use highlightWidth of 3.
  1894   1949    *
  1895   1950    * Results:
  1896   1951    *	None.
  1897   1952    *
  1898   1953    * Side effects:
  1899         - *	A rectangle "width" pixels wide is drawn in "drawable",
  1900         - *	corresponding to the outer area of "tkwin".
         1954  + *	A rectangle "width" pixels wide is drawn in "drawable", corresponding
         1955  + *	to the outer area of "tkwin".
  1901   1956    *
  1902   1957    *----------------------------------------------------------------------
  1903   1958    */
  1904   1959   
  1905   1960   void
  1906   1961   TkpDrawHighlightBorder (
  1907   1962       Tk_Window tkwin,
................................................................................
  1922   1977   }
  1923   1978   
  1924   1979   /*
  1925   1980    *----------------------------------------------------------------------
  1926   1981    *
  1927   1982    * TkpDrawFrame --
  1928   1983    *
  1929         - *	This procedure draws the rectangular frame area. If the user
  1930         - *	has requested themeing, it draws with the background theme.
         1984  + *	This procedure draws the rectangular frame area. If the user has
         1985  + *	requested themeing, it draws with the background theme.
  1931   1986    *
  1932   1987    * Results:
  1933   1988    *	None.
  1934   1989    *
  1935   1990    * Side effects:
  1936   1991    *	Draws inside the tkwin area.
  1937   1992    *

Changes to macosx/tkMacOSXEmbed.c.

   330    330       /*
   331    331        * Make a copy of the TK_EMBEDDED flag, since sometimes we need this to
   332    332        * get the port after the TkWindow structure has been freed.
   333    333        */
   334    334   
   335    335       macWin->flags |= TK_EMBEDDED;
   336    336       macWin->xOff = parent->winPtr->privatePtr->xOff +
   337         -	parent->winPtr->changes.border_width +
   338         -	winPtr->changes.x;
          337  +	    parent->winPtr->changes.border_width +
          338  +	    winPtr->changes.x;
   339    339       macWin->yOff = parent->winPtr->privatePtr->yOff +
   340         -	parent->winPtr->changes.border_width +
   341         -	winPtr->changes.y;
          340  +	    parent->winPtr->changes.border_width +
          341  +	    winPtr->changes.y;
   342    342   
   343    343       /*
   344         -     * Finish filling up the container structure with the embedded
   345         -     * window's information.
          344  +     * Finish filling up the container structure with the embedded window's
          345  +     * information.
   346    346        */
   347    347   
   348    348       containerPtr->embedded = (Window) macWin;
   349    349       containerPtr->embeddedPtr = macWin->winPtr;
   350    350   
   351    351       /*
   352    352        * Create an event handler to clean up the Container structure when
   353    353        * tkwin is eventually deleted.
   354    354        */
   355    355   
   356         -    Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc,
   357         -			  winPtr);
          356  +    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
          357  +	    EmbeddedEventProc, winPtr);
   358    358   
   359    359       return TCL_OK;
   360    360   }
   361    361   
   362    362   /*
   363    363    *----------------------------------------------------------------------
   364    364    *
................................................................................
   584    584   	if (containerPtr->parentPtr != NULL) {
   585    585   	    parentInterp = containerPtr->parentPtr->mainPtr->interp;
   586    586   	}
   587    587   	if (embeddedInterp != interp && parentInterp != interp) {
   588    588   	    continue;
   589    589   	}
   590    590   	Tcl_DStringStartSublist(&dString);
   591         -	/* Parent id */
          591  +
          592  +	/*
          593  +	 * Parent id
          594  +	 */
          595  +
   592    596   	if (containerPtr->parent == None) {
   593    597   	    Tcl_DStringAppendElement(&dString, "");
   594    598   	} else if (all) {
   595    599   	    sprintf(buffer, "0x%lx", containerPtr->parent);
   596    600   	    Tcl_DStringAppendElement(&dString, buffer);
   597    601   	} else {
   598    602   	    Tcl_DStringAppendElement(&dString, "XXX");
   599    603   	}
   600         -	/* Parent pathName */
          604  +
          605  +	/*
          606  +	 * Parent pathName
          607  +	 */
          608  +
   601    609   	if (containerPtr->parentPtr == NULL ||
   602    610   	    parentInterp != interp) {
   603    611   	    Tcl_DStringAppendElement(&dString, "");
   604    612   	} else {
   605    613   	    Tcl_DStringAppendElement(&dString,
   606    614   		    containerPtr->parentPtr->pathName);
   607    615   	}
          616  +
   608    617   	/*
   609    618   	 * On X11 embedded is a wrapper, which does not exist on macOS.
   610    619   	 */
          620  +
   611    621   	Tcl_DStringAppendElement(&dString, "");
   612         -	/* Embedded window pathName */
          622  +
          623  +	/*
          624  +	 * Embedded window pathName
          625  +	 */
          626  +
   613    627   	if (containerPtr->embeddedPtr == NULL ||
   614    628   	    embeddedInterp != interp) {
   615    629   	    Tcl_DStringAppendElement(&dString, "");
   616    630   	} else {
   617    631   	    Tcl_DStringAppendElement(&dString,
   618    632   		    containerPtr->embeddedPtr->pathName);
   619    633   	}
................................................................................
   764    778       Container *containerPtr;
   765    779       Tk_ErrorHandler errHandler;
   766    780   
   767    781       if (!firstContainerPtr) {
   768    782   	/*
   769    783   	 * When the interpreter is being dismantled this can be nil.
   770    784   	 */
          785  +
   771    786   	return;
   772    787       }
   773    788   
   774    789       /*
   775    790        * Ignore any X protocol errors that happen in this procedure (almost any
   776    791        * operation could fail, for example, if the embedded application has
   777    792        * deleted its window).
................................................................................
   916    931   
   917    932   static void
   918    933   EmbedActivateProc(
   919    934       ClientData clientData,	/* Token for container window. */
   920    935       XEvent *eventPtr)		/* ResizeRequest event. */
   921    936   {
   922    937       Container *containerPtr = clientData;
          938  +
   923    939       if (containerPtr->embeddedPtr != NULL) {
   924    940   	if (eventPtr->type == ActivateNotify) {
   925    941   	    TkGenerateActivateEvents(containerPtr->embeddedPtr,1);
   926    942   	} else if (eventPtr->type == DeactivateNotify) {
   927    943   	    TkGenerateActivateEvents(containerPtr->embeddedPtr,0);
   928    944   	}
   929    945       }
................................................................................
  1020   1036       int width, int height)	/* Size that the child has requested. */
  1021   1037   {
  1022   1038       TkWindow *winPtr = containerPtr->parentPtr;
  1023   1039   
  1024   1040       /*
  1025   1041        * Forward the requested size into our geometry management hierarchy via
  1026   1042        * the container window. We need to send a Configure event back to the
  1027         -     * embedded application if we decide not to honor its request; to make
  1028         -     * this happen, process all idle event handlers synchronously here (so
  1029         -     * that the geometry managers have had a chance to do whatever they want
  1030         -     * to do), and if the window's size didn't change then generate a
  1031         -     * configure event.
         1043  +     * embedded application if we decide not to honor its request; to make this
         1044  +     * happen, process all idle event handlers synchronously here (so that the
         1045  +     * geometry managers have had a chance to do whatever they want to do), and
         1046  +     * if the window's size didn't change then generate a configure event.
  1032   1047        */
  1033   1048   
  1034   1049       Tk_GeometryRequest((Tk_Window) winPtr, width, height);
  1035   1050       while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {
  1036   1051   	/* Empty loop body. */
  1037   1052       }
  1038   1053       if ((winPtr->changes.width != width)
................................................................................
  1046   1061    *
  1047   1062    * EmbedSendConfigure --
  1048   1063    *
  1049   1064    *	This is currently a stub. It is called to notify an embedded
  1050   1065    *	application of its current size and location. This procedure is called
  1051   1066    *	when the embedded application made a geometry request that we did not
  1052   1067    *	grant, so that the embedded application knows that its geometry didn't
  1053         - *	change after all. It is a response to ConfigureRequest events, which
  1054         - *	we do not currently synthesize on the Mac
         1068  + *	change after all. It is a response to ConfigureRequest events, which we
         1069  + *	do not currently synthesize on the Mac
  1055   1070    *
  1056   1071    * Results:
  1057   1072    *	None.
  1058   1073    *
  1059   1074    * Side effects:
  1060   1075    *	None.
  1061   1076    *
................................................................................
  1107   1122   	     * Fabricate an event to do this.
  1108   1123   	     */
  1109   1124   
  1110   1125   	    if (containerPtr->parentPtr != NULL &&
  1111   1126   		    containerPtr->parentPtr->flags & TK_BOTH_HALVES) {
  1112   1127   		XEvent event;
  1113   1128   
  1114         -		event.xany.serial =
  1115         -			LastKnownRequestProcessed(Tk_Display(containerPtr->parentPtr));
         1129  +		event.xany.serial = LastKnownRequestProcessed(
         1130  +			Tk_Display(containerPtr->parentPtr));
  1116   1131   		event.xany.send_event = False;
  1117   1132   		event.xany.display = Tk_Display(containerPtr->parentPtr);
  1118   1133   
  1119   1134   		event.xany.type = DestroyNotify;
  1120   1135   		event.xany.window = containerPtr->parent;
  1121   1136   		event.xdestroywindow.event = containerPtr->parent;
  1122   1137   		Tk_QueueWindowEvent(&event, TCL_QUEUE_HEAD);

Changes to macosx/tkMacOSXFont.c.

     1      1   /*
     2      2    * tkMacOSXFont.c --
     3      3    *
     4         - *	Contains the Macintosh implementation of the platform-independant
     5         - *	font package interface.
            4  + *	Contains the Macintosh implementation of the platform-independant font
            5  + *	package interface.
     6      6    *
     7      7    * Copyright 2002-2004 Benjamin Riefenstahl, [email protected]
     8      8    * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
     9      9    * Copyright 2008-2009, Apple Inc.
    10     10    *
    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.
................................................................................
    28     28   
    29     29   /*
    30     30    * The following structure represents our Macintosh-specific implementation
    31     31    * of a font object.
    32     32    */
    33     33   
    34     34   typedef struct {
    35         -    TkFont font;		/* Stuff used by generic font package. Must
    36         -				 * be first in structure. */
    37         -
           35  +    TkFont font;		/* Stuff used by generic font package. Must be
           36  +				 * first in structure. */
    38     37       NSFont *nsFont;
    39     38       NSDictionary *nsAttributes;
    40     39   } MacFont;
    41     40   
    42     41   /*
    43     42    * The names for our "native" fonts.
    44     43    */
................................................................................
    79     78   };
    80     79   #undef ThemeFont
    81     80   
    82     81   static int antialiasedTextEnabled = -1;
    83     82   static NSCharacterSet *whitespaceCharacterSet = nil;
    84     83   static NSCharacterSet *lineendingCharacterSet = nil;
    85     84   
    86         -static void GetTkFontAttributesForNSFont(NSFont *nsFont,
    87         -	TkFontAttributes *faPtr);
    88         -static NSFont *FindNSFont(const char *familyName, NSFontTraitMask traits,
    89         -	NSInteger weight, CGFloat size, int fallbackToDefault);
    90         -static void InitFont(NSFont *nsFont, const TkFontAttributes *reqFaPtr,
    91         -	MacFont * fontPtr);
    92         -static int CreateNamedSystemFont(Tcl_Interp *interp, Tk_Window tkwin,
    93         -	const char* name, TkFontAttributes *faPtr);
    94         -static void DrawCharsInContext(Display *display, Drawable drawable, GC gc,
    95         -	Tk_Font tkfont, const char *source, int numBytes, int rangeStart,
    96         -	int rangeLength, int x, int y, double angle);
           85  +static void		GetTkFontAttributesForNSFont(NSFont *nsFont,
           86  +			    TkFontAttributes *faPtr);
           87  +static NSFont *		FindNSFont(const char *familyName,
           88  +			    NSFontTraitMask traits, NSInteger weight,
           89  +			    CGFloat size, int fallbackToDefault);
           90  +static void		InitFont(NSFont *nsFont,
           91  +			    const TkFontAttributes *reqFaPtr,
           92  +			    MacFont *fontPtr);
           93  +static int		CreateNamedSystemFont(Tcl_Interp *interp,
           94  +			    Tk_Window tkwin, const char *name,
           95  +			    TkFontAttributes *faPtr);
           96  +static void		DrawCharsInContext(Display *display, Drawable drawable,
           97  +			    GC gc, Tk_Font tkfont, const char *source,
           98  +			    int numBytes, int rangeStart, int rangeLength,
           99  +			    int x, int y, double angle);
    97    100   
    98    101   #pragma mark -
    99    102   #pragma mark Font Helpers:
   100    103   
   101    104   #define GetNSFontTraitsFromTkFontAttributes(faPtr) \
   102    105   	((faPtr)->weight == TK_FW_BOLD ? NSBoldFontMask : NSUnboldFontMask) | \
   103    106   	((faPtr)->slant == TK_FS_ITALIC ? NSItalicFontMask : NSUnitalicFontMask)
................................................................................
   228    231       NSDictionary *nsAttributes;
   229    232       NSRect bounds;
   230    233       CGFloat kern = 0.0;
   231    234       NSFontRenderingMode renderingMode = NSFontDefaultRenderingMode;
   232    235       int ascent, descent/*, dontAA*/;
   233    236       static const UniChar ch[] = {'.', 'W', ' ', 0xc4, 0xc1, 0xc2, 0xc3, 0xc7};
   234    237   			/* ., W, Space, Auml, Aacute, Acirc, Atilde, Ccedilla */
   235         -    #define nCh (sizeof(ch) / sizeof(UniChar))
          238  +#define nCh	(sizeof(ch) / sizeof(UniChar))
   236    239       CGGlyph glyphs[nCh];
   237    240       CGRect boundingRects[nCh];
   238    241   
   239    242       fontPtr->font.fid = (Font) fontPtr;
   240    243       faPtr = &fontPtr->font.fa;
   241    244       if (reqFaPtr) {
   242    245   	*faPtr = *reqFaPtr;
   243    246       } else {
   244    247   	TkInitFontAttributes(faPtr);
   245    248       }
   246    249       fontPtr->nsFont = nsFont;
   247         -    // some don't like antialiasing on fixed-width even if bigger than limit
          250  +
          251  +    /*
          252  +     * Some don't like antialiasing on fixed-width even if bigger than limit
          253  +     */
          254  +
   248    255       // dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10;
   249    256       if (antialiasedTextEnabled >= 0/* || dontAA*/) {
   250    257   	renderingMode = (antialiasedTextEnabled == 0/* || dontAA*/) ?
   251    258   		NSFontIntegerAdvancementsRenderingMode :
   252    259   		NSFontAntialiasedRenderingMode;
   253    260       }
   254    261       nsFont = [nsFont screenFontWithRenderingMode:renderingMode];
................................................................................
   290    297   	    [NSNumber numberWithInt:faPtr->overstrike ?
   291    298   		NSUnderlineStyleSingle|NSUnderlinePatternSolid :
   292    299   		NSUnderlineStyleNone], NSStrikethroughStyleAttributeName,
   293    300   	    [NSNumber numberWithInt:fmPtr->fixed ? 0 : 1],
   294    301   		NSLigatureAttributeName,
   295    302   	    [NSNumber numberWithDouble:kern], NSKernAttributeName, nil];
   296    303       fontPtr->nsAttributes = [nsAttributes retain];
   297         -    #undef nCh
          304  +#undef nCh
   298    305   }
   299    306   
   300    307   /*
   301    308    *-------------------------------------------------------------------------
   302    309    *
   303    310    * CreateNamedSystemFont --
   304    311    *
................................................................................
   354    361   {
   355    362       Tcl_Interp *interp = mainPtr->interp;
   356    363       Tk_Window tkwin = (Tk_Window) mainPtr->winPtr;
   357    364       const struct SystemFontMapEntry *systemFont = systemFontMap;
   358    365       NSFont *nsFont;
   359    366       TkFontAttributes fa;
   360    367       NSMutableCharacterSet *cs;
   361         -    /* Since we called before TkpInit, we need our own autorelease pool. */
          368  +    /*
          369  +     * Since we called before TkpInit, we need our own autorelease pool.
          370  +     */
   362    371       NSAutoreleasePool *pool = [NSAutoreleasePool new];
   363    372   
   364         -    /* force this for now */
          373  +    /*
          374  +     * Force this for now.
          375  +     */
   365    376       if (!mainPtr->winPtr->mainPtr) {
   366    377   	mainPtr->winPtr->mainPtr = mainPtr;
   367    378       }
   368    379       while (systemFont->systemName) {
   369    380   	nsFont = (NSFont*) CTFontCreateUIFontForLanguage(
   370    381   		HIThemeGetUIFontType(systemFont->id), 0, NULL);
   371    382   	if (nsFont) {
................................................................................
   409    420    *---------------------------------------------------------------------------
   410    421    *
   411    422    * TkpGetNativeFont --
   412    423    *
   413    424    *	Map a platform-specific native font name to a TkFont.
   414    425    *
   415    426    * Results:
   416         - *	The return value is a pointer to a TkFont that represents the
   417         - *	native font. If a native font by the given name could not be
   418         - *	found, the return value is NULL.
          427  + *	The return value is a pointer to a TkFont that represents the native
          428  + *	font. If a native font by the given name could not be found, the return
          429  + *	value is NULL.
   419    430    *
   420         - *	Every call to this procedure returns a new TkFont structure, even
   421         - *	if the name has already been seen before. The caller should call
          431  + *	Every call to this procedure returns a new TkFont structure, even if
          432  + *	the name has already been seen before. The caller should call
   422    433    *	TkpDeleteFont() when the font is no longer needed.
   423    434    *
   424         - *	The caller is responsible for initializing the memory associated
   425         - *	with the generic TkFont when this function returns and releasing
   426         - *	the contents of the generics TkFont before calling TkpDeleteFont().
          435  + *	The caller is responsible for initializing the memory associated with
          436  + *	the generic TkFont when this function returns and releasing the
          437  + *	contents of the generics TkFont before calling TkpDeleteFont().
   427    438    *
   428    439    * Side effects:
   429    440    *	None.
   430    441    *
   431    442    *---------------------------------------------------------------------------
   432    443    */
   433    444   
................................................................................
   445    456       } else if (strcmp(name, APPLFONT_NAME) == 0) {
   446    457   	themeFontId = kThemeApplicationFont;
   447    458       } else if (strcmp(name, MENUITEMFONT_NAME) == 0) {
   448    459   	themeFontId = kThemeMenuItemFont;
   449    460       } else {
   450    461   	return NULL;
   451    462       }
   452         -    ctFont = CTFontCreateUIFontForLanguage(HIThemeGetUIFontType(
   453         -	    themeFontId), 0, NULL);
          463  +    ctFont = CTFontCreateUIFontForLanguage(
          464  +	    HIThemeGetUIFontType(themeFontId), 0, NULL);
   454    465       if (ctFont) {
   455    466   	fontPtr = ckalloc(sizeof(MacFont));
   456    467   	InitFont((NSFont*) ctFont, NULL, fontPtr);
   457    468       }
   458    469   
   459    470       return (TkFont *) fontPtr;
   460    471   }
................................................................................
   464    475    *
   465    476    * TkpGetFontFromAttributes --
   466    477    *
   467    478    *	Given a desired set of attributes for a font, find a font with the
   468    479    *	closest matching attributes.
   469    480    *
   470    481    * Results:
   471         - *	The return value is a pointer to a TkFont that represents the font
   472         - *	with the desired attributes. If a font with the desired attributes
   473         - *	could not be constructed, some other font will be substituted
   474         - *	automatically.
          482  + *	The return value is a pointer to a TkFont that represents the font with
          483  + *	the desired attributes. If a font with the desired attributes could not
          484  + *	be constructed, some other font will be substituted automatically.
   475    485    *
   476         - *	Every call to this procedure returns a new TkFont structure, even
   477         - *	if the specified attributes have already been seen before. The
   478         - *	caller should call TkpDeleteFont() to free the platform- specific
   479         - *	data when the font is no longer needed.
          486  + *	Every call to this procedure returns a new TkFont structure, even if
          487  + *	the specified attributes have already been seen before. The caller
          488  + *	should call TkpDeleteFont() to free the platform- specific data when
          489  + *	the font is no longer needed.
   480    490    *
   481         - *	The caller is responsible for initializing the memory associated
   482         - *	with the generic TkFont when this function returns and releasing
   483         - *	the contents of the generic TkFont before calling TkpDeleteFont().
          491  + *	The caller is responsible for initializing the memory associated with
          492  + *	the generic TkFont when this function returns and releasing the
          493  + *	contents of the generic TkFont before calling TkpDeleteFont().
   484    494    *
   485    495    * Side effects:
   486    496    *	None.
   487    497    *
   488    498    *---------------------------------------------------------------------------
   489    499    */
   490    500   
   491    501   TkFont *
   492    502   TkpGetFontFromAttributes(
   493    503       TkFont *tkFontPtr,		/* If non-NULL, store the information in this
   494    504   				 * existing TkFont structure, rather than
   495         -				 * allocating a new structure to hold the
   496         -				 * font; the existing contents of the font
   497         -				 * will be released. If NULL, a new TkFont
   498         -				 * structure is allocated. */
          505  +				 * allocating a new structure to hold the font;
          506  +				 * the existing contents of the font will be
          507  +				 * released. If NULL, a new TkFont structure is
          508  +				 * allocated. */
   499    509       Tk_Window tkwin,		/* For display where font will be used. */
   500    510       const TkFontAttributes *faPtr)
   501    511   				/* Set of attributes to match. */
   502    512   {
   503    513       MacFont *fontPtr;
   504         -    int points = (int)(TkFontGetPoints(tkwin, faPtr->size) + 0.5);
          514  +    int points = (int) (TkFontGetPoints(tkwin, faPtr->size) + 0.5);
   505    515       NSFontTraitMask traits = GetNSFontTraitsFromTkFontAttributes(faPtr);
   506    516       NSInteger weight = (faPtr->weight == TK_FW_BOLD ? 9 : 5);
   507    517       NSFont *nsFont;
   508    518   
   509    519       nsFont = FindNSFont(faPtr->family, traits, weight, points, 0);
   510    520       if (!nsFont) {
   511    521   	const char *const *aliases = TkFontGetAliasList(faPtr->family);
................................................................................
   534    544   
   535    545   /*
   536    546    *---------------------------------------------------------------------------
   537    547    *
   538    548    * TkpDeleteFont --
   539    549    *
   540    550    *	Called to release a font allocated by TkpGetNativeFont() or
   541         - *	TkpGetFontFromAttributes(). The caller should have already
   542         - *	released the fields of the TkFont that are used exclusively by the
   543         - *	generic TkFont code.
          551  + *	TkpGetFontFromAttributes(). The caller should have already released the
          552  + *	fields of the TkFont that are used exclusively by the generic TkFont
          553  + *	code.
   544    554    *
   545    555    * Results:
   546    556    *	TkFont is deallocated.
   547    557    *
   548    558    * Side effects:
   549    559    *	None.
   550    560    *
................................................................................
   563    573   }
   564    574   
   565    575   /*
   566    576    *---------------------------------------------------------------------------
   567    577    *
   568    578    * TkpGetFontFamilies --
   569    579    *
   570         - *	Return information about the font families that are available on
   571         - *	the display of the given window.
          580  + *	Return information about the font families that are available on the
          581  + *	display of the given window.
   572    582    *
   573    583    * Results:
   574    584    *	Modifies interp's result object to hold a list of all the available
   575    585    *	font families.
   576    586    *
   577    587    * Side effects:
   578    588    *	None.
................................................................................
   596    606   }
   597    607   
   598    608   /*
   599    609    *-------------------------------------------------------------------------
   600    610    *
   601    611    * TkpGetSubFonts --
   602    612    *
   603         - *	A function used by the testing package for querying the actual
   604         - *	screen fonts that make up a font object.
          613  + *	A function used by the testing package for querying the actual screen
          614  + *	fonts that make up a font object.
   605    615    *
   606    616    * Results:
   607         - *	Modifies interp's result object to hold a list containing the names
   608         - *	of the screen fonts that make up the given font object.
          617  + *	Modifies interp's result object to hold a list containing the names of
          618  + *	the screen fonts that make up the given font object.
   609    619    *
   610    620    * Side effects:
   611    621    *	None.
   612    622    *
   613    623    *-------------------------------------------------------------------------
   614    624    */
   615    625   
................................................................................
   638    648   }
   639    649   
   640    650   /*
   641    651    *----------------------------------------------------------------------
   642    652    *
   643    653    * TkpGetFontAttrsForChar --
   644    654    *
   645         - *	Retrieve the font attributes of the actual font used to render a
   646         - *	given character.
          655  + *	Retrieve the font attributes of the actual font used to render a given
          656  + *	character.
   647    657    *
   648    658    * Results:
   649    659    *	None.
   650    660    *
   651    661    * Side effects:
   652    662    *	The font attributes are stored in *faPtr.
   653    663    *
................................................................................
   741    751    *	that TkpDrawCharsInContext() will be used to actually display the
   742    752    *	characters.
   743    753    *
   744    754    *	This one is almost the same as Tk_MeasureChars(), but with access to
   745    755    *	all the characters on the line for context.
   746    756    *
   747    757    * Results:
   748         - *	The return value is the number of bytes from source that
   749         - *	fit into the span that extends from 0 to maxLength. *lengthPtr is
   750         - *	filled with the x-coordinate of the right edge of the last
   751         - *	character that did fit.
          758  + *	The return value is the number of bytes from source that fit into the
          759  + *	span that extends from 0 to maxLength. *lengthPtr is filled with the
          760  + *	x-coordinate of the right edge of the last character that did fit.
   752    761    *
   753    762    * Side effects:
   754    763    *	None.
   755    764    *
   756    765    *---------------------------------------------------------------------------
   757    766    */
   758    767   
................................................................................
   770    779   				 * character that would cross this x-position.
   771    780   				 * If < 0, then line length is unbounded and
   772    781   				 * the flags argument is ignored. */
   773    782       int flags,			/* Various flag bits OR-ed together:
   774    783   				 * TK_PARTIAL_OK means include the last char
   775    784   				 * which only partially fits on this line.
   776    785   				 * TK_WHOLE_WORDS means stop on a word
   777         -				 * boundary, if possible. TK_AT_LEAST_ONE
   778         -				 * means return at least one character even
   779         -				 * if no characters fit.  If TK_WHOLE_WORDS
   780         -				 * and TK_AT_LEAST_ONE are set and the first
   781         -				 * word doesn't fit, we return at least one
          786  +				 * boundary, if possible. TK_AT_LEAST_ONE means
          787  +				 * return at least one character even if no
          788  +				 * characters fit.  If TK_WHOLE_WORDS and
          789  +				 * TK_AT_LEAST_ONE are set and the first word
          790  +				 * doesn't fit, we return at least one
   782    791   				 * character or whatever characters fit into
   783    792   				 * maxLength.  TK_ISOLATE_END means that the
   784    793   				 * last character should not be considered in
   785    794   				 * context with the rest of the string (used
   786    795   				 * for breaking lines). */
   787    796       int *lengthPtr)		/* Filled with x-location just after the
   788    797   				 * terminating character. */
................................................................................
   860    869   		whitespaceCharacterSet : lineendingCharacterSet;
   861    870   	while (index > start &&
   862    871   		[cs characterIsMember:[string characterAtIndex:(index - 1)]]) {
   863    872   	    index--;
   864    873   	}
   865    874   
   866    875           /*
   867         -         * If there is no line breakpoint in the source string between
   868         -         * its start and the index position that fits in maxWidth, then
          876  +         * If there is no line breakpoint in the source string between its
          877  +         * start and the index position that fits in maxWidth, then
   869    878            * CTTypesetterSuggestLineBreak() returns that very last index.
   870         -         * However if the TK_WHOLE_WORDS flag is set, we want to break
   871         -         * at a word boundary. In this situation, unless TK_AT_LEAST_ONE
   872         -         * is set, we must report that zero chars actually fit (in other
   873         -         * words the smallest word of the source string is still larger
   874         -         * than maxWidth).
          879  +         * However if the TK_WHOLE_WORDS flag is set, we want to break at a
          880  +         * word boundary. In this situation, unless TK_AT_LEAST_ONE is set, we
          881  +         * must report that zero chars actually fit (in other words the
          882  +         * smallest word of the source string is still larger than maxWidth).
   875    883            */
   876    884   
   877    885           if ((index >= start) && (index < len) &&
   878    886                   (flags & TK_WHOLE_WORDS) && !(flags & TK_AT_LEAST_ONE) &&
   879    887                   ![cs characterIsMember:[string characterAtIndex:index]]) {
   880    888               index = start;
   881    889           }
................................................................................
   899    907   	if (width < maxWidth && (flags & TK_PARTIAL_OK) && index < len) {
   900    908   	    range.length = ++index;
   901    909   	    line = CTTypesetterCreateLine(typesetter, range);
   902    910   	    width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
   903    911   	    CFRelease(line);
   904    912   	}
   905    913   
   906         -        /* The call to CTTypesetterSuggestClusterBreak above will always
   907         -           return at least one character regardless of whether it exceeded
   908         -           it or not.  Clean that up now. */
          914  +        /*
          915  +	 * The call to CTTypesetterSuggestClusterBreak above will always return
          916  +	 * at least one character regardless of whether it exceeded it or not.
          917  +	 * Clean that up now.
          918  +	 */
          919  +
   909    920   	while (width > maxWidth && !(flags & TK_PARTIAL_OK)
   910    921   		&& index > start+(flags & TK_AT_LEAST_ONE)) {
   911    922   	    range.length = --index;
   912    923   	    line = CTTypesetterCreateLine(typesetter, range);
   913    924   	    width = CTLineGetTypographicBounds(line, NULL, NULL, NULL);
   914    925   	    CFRelease(line);
   915    926   	}
................................................................................
   942    953    *
   943    954    *	Draw a string of characters on the screen.
   944    955    *
   945    956    *	With ATSUI we need the line context to do this right, so we have the
   946    957    *	actual implementation in TkpDrawCharsInContext().
   947    958    *
   948    959    * Results:
   949         -  *	None.
          960  + *	None.
   950    961    *
   951    962    * Side effects:
   952    963    *	Information gets drawn on the screen.
   953    964    *
   954    965    *---------------------------------------------------------------------------
   955    966    */
   956    967   
................................................................................
   960    971       Drawable drawable,		/* Window or pixmap in which to draw. */
   961    972       GC gc,			/* Graphics context for drawing characters. */
   962    973       Tk_Font tkfont,		/* Font in which characters will be drawn; must
   963    974   				 * be the same as font used in GC. */
   964    975       const char *source,		/* UTF-8 string to be displayed. Need not be
   965    976   				 * '\0' terminated. All Tk meta-characters
   966    977   				 * (tabs, control characters, and newlines)
   967         -				 * should be stripped out of the string that
   968         -				 * is passed to this function. If they are not
          978  +				 * should be stripped out of the string that is
          979  +				 * passed to this function. If they are not
   969    980   				 * stripped out, they will be displayed as
   970    981   				 * regular printing characters. */
   971    982       int numBytes,		/* Number of bytes in string. */
   972    983       int x, int y)		/* Coordinates at which to place origin of the
   973    984   				 * string when drawing. */
   974    985   {
   975    986       DrawCharsInContext(display, drawable, gc, tkfont, source, numBytes,
................................................................................
   982    993       Drawable drawable,		/* Window or pixmap in which to draw. */
   983    994       GC gc,			/* Graphics context for drawing characters. */
   984    995       Tk_Font tkfont,		/* Font in which characters will be drawn;
   985    996   				 * must be the same as font used in GC. */
   986    997       const char *source,		/* UTF-8 string to be displayed. Need not be
   987    998   				 * '\0' terminated. All Tk meta-characters
   988    999   				 * (tabs, control characters, and newlines)
   989         -				 * should be stripped out of the string that
   990         -				 * is passed to this function. If they are not
         1000  +				 * should be stripped out of the string that is
         1001  +				 * passed to this function. If they are not
   991   1002   				 * stripped out, they will be displayed as
   992   1003   				 * regular printing characters. */
   993   1004       int numBytes,		/* Number of bytes in string. */
   994   1005       double x, double y,		/* Coordinates at which to place origin of
   995   1006   				 * string when drawing. */
   996   1007       double angle)		/* What angle to put text at, in degrees. */
   997   1008   {
................................................................................
  1025   1036       Drawable drawable,		/* Window or pixmap in which to draw. */
  1026   1037       GC gc,			/* Graphics context for drawing characters. */
  1027   1038       Tk_Font tkfont,		/* Font in which characters will be drawn; must
  1028   1039   				 * be the same as font used in GC. */
  1029   1040       const char * source,	/* UTF-8 string to be displayed. Need not be
  1030   1041   				 * '\0' terminated. All Tk meta-characters
  1031   1042   				 * (tabs, control characters, and newlines)
  1032         -				 * should be stripped out of the string that
  1033         -				 * is passed to this function. If they are not
         1043  +				 * should be stripped out of the string that is
         1044  +				 * passed to this function. If they are not
  1034   1045   				 * stripped out, they will be displayed as
  1035   1046   				 * regular printing characters. */
  1036   1047       int numBytes,		/* Number of bytes in string. */
  1037   1048       int rangeStart,		/* Index of first byte to draw. */
  1038   1049       int rangeLength,		/* Length of range to draw in bytes. */
  1039   1050       int x, int y)		/* Coordinates at which to place origin of the
  1040   1051   				 * whole (not just the range) string when
................................................................................
  1050   1061       Drawable drawable,		/* Window or pixmap in which to draw. */
  1051   1062       GC gc,			/* Graphics context for drawing characters. */
  1052   1063       Tk_Font tkfont,		/* Font in which characters will be drawn; must
  1053   1064   				 * be the same as font used in GC. */
  1054   1065       const char * source,	/* UTF-8 string to be displayed. Need not be
  1055   1066   				 * '\0' terminated. All Tk meta-characters
  1056   1067   				 * (tabs, control characters, and newlines)
  1057         -				 * should be stripped out of the string that
  1058         -				 * is passed to this function. If they are not
         1068  +				 * should be stripped out of the string that is
         1069  +				 * passed to this function. If they are not
  1059   1070   				 * stripped out, they will be displayed as
  1060   1071   				 * regular printing characters. */
  1061   1072       int numBytes,		/* Number of bytes in string. */
  1062   1073       int rangeStart,		/* Index of first byte to draw. */
  1063   1074       int rangeLength,		/* Length of range to draw in bytes. */
  1064   1075       int x, int y,		/* Coordinates at which to place origin of the
  1065   1076   				 * whole (not just the range) string when
................................................................................
  1087   1098   	return;
  1088   1099       }
  1089   1100       string = [[NSString alloc] initWithBytesNoCopy:(void*)source
  1090   1101   		length:numBytes encoding:NSUTF8StringEncoding freeWhenDone:NO];
  1091   1102       if (!string) {
  1092   1103   	return;
  1093   1104       }
         1105  +
  1094   1106       context = drawingContext.context;
  1095   1107       fg = TkMacOSXCreateCGColor(gc, gc->foreground);
  1096   1108       attributes = [fontPtr->nsAttributes mutableCopy];
  1097   1109       [attributes setObject:(id)fg forKey:(id)kCTForegroundColorAttributeName];
  1098   1110       CFRelease(fg);
  1099   1111       nsFont = [attributes objectForKey:NSFontAttributeName];
  1100   1112       [nsFont setInContext:[NSGraphicsContext graphicsContextWithGraphicsPort:
................................................................................
  1115   1127       }
  1116   1128       CGContextConcatCTM(context, t);
  1117   1129       CGContextSetTextPosition(context, x, y);
  1118   1130       start = Tcl_NumUtfChars(source, rangeStart);
  1119   1131       len = Tcl_NumUtfChars(source, rangeStart + rangeLength);
  1120   1132       if (start > 0) {
  1121   1133   	CGRect clipRect = CGRectInfinite, startBounds;
         1134  +
  1122   1135   	line = CTTypesetterCreateLine(typesetter, CFRangeMake(0, start));
  1123   1136   	startBounds = CTLineGetImageBounds(line, context);
  1124   1137   	CFRelease(line);
  1125   1138   	clipRect.origin.x = startBounds.origin.x + startBounds.size.width;
  1126   1139   	CGContextClipToRect(context, clipRect);
  1127   1140       }
  1128   1141       line = CTTypesetterCreateLine(typesetter, CFRangeMake(0, len));
................................................................................
  1237   1250       if (nsFont && familyName) {
  1238   1251   	NSFontTraitMask traits = [[NSFontManager sharedFontManager]
  1239   1252   		traitsOfFont:nsFont];
  1240   1253   	id underline = [nsAttributes objectForKey:
  1241   1254   		NSUnderlineStyleAttributeName];
  1242   1255   	id strikethrough = [nsAttributes objectForKey:
  1243   1256   		NSStrikethroughStyleAttributeName];
         1257  +
  1244   1258   	objv[i++] = Tcl_NewStringObj(familyName, -1);
  1245   1259   	objv[i++] = Tcl_NewIntObj([nsFont pointSize]);
  1246         -#define S(s) Tcl_NewStringObj(STRINGIFY(s),(int)(sizeof(STRINGIFY(s))-1))
         1260  +#define S(s)    Tcl_NewStringObj(STRINGIFY(s),(int)(sizeof(STRINGIFY(s))-1))
  1247   1261   	objv[i++] = (traits & NSBoldFontMask)	? S(bold)   : S(normal);
  1248   1262   	objv[i++] = (traits & NSItalicFontMask)	? S(italic) : S(roman);
  1249   1263   	if ([underline respondsToSelector:@selector(intValue)] &&
  1250   1264   		([underline intValue] & (NSUnderlineStyleSingle |
  1251   1265   		NSUnderlineStyleThick | NSUnderlineStyleDouble))) {
  1252   1266   	    objv[i++] = S(underline);
  1253   1267   	}
................................................................................
  1263   1277   
  1264   1278   /*
  1265   1279    *----------------------------------------------------------------------
  1266   1280    *
  1267   1281    * TkMacOSXUseAntialiasedText --
  1268   1282    *
  1269   1283    *	Enables or disables application-wide use of antialiased text (where
  1270         - *	available). Sets up a linked Tcl global variable to allow
  1271         - *	disabling of antialiased text from tcl.
         1284  + *	available). Sets up a linked Tcl global variable to allow disabling of
         1285  + *	antialiased text from Tcl.
         1286  + *
  1272   1287    *	The possible values for this variable are:
  1273   1288    *
  1274   1289    *	-1 - Use system default as configurable in "System Prefs" -> "General".
  1275   1290    *	 0 - Unconditionally disable antialiasing.
  1276   1291    *	 1 - Unconditionally enable antialiasing.
  1277   1292    *
  1278   1293    * Results:

Changes to macosx/tkMacOSXImage.c.

    19     19   
    20     20   int
    21     21   _XInitImageFuncPtrs(
    22     22       XImage *image)
    23     23   {
    24     24       return 0;
    25     25   }
    26         -
           26  +
    27     27   /*
    28     28    *----------------------------------------------------------------------
    29     29    *
    30     30    * TkMacOSXCreateCGImageWithXImage --
    31     31    *
    32     32    *	Create CGImage from XImage, copying the image data.  Called
    33     33    *      in Tk_PutImage and (currently) nowhere else.
................................................................................
    77     77   	    while (srcPtr < endPtr) {
    78     78   		*destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))];
    79     79   	    }
    80     80   	} else {
    81     81   	    data = memcpy(ckalloc(len), image->data + image->xoffset, len);
    82     82   	}
    83     83   	if (data) {
    84         -	    provider = CGDataProviderCreateWithData(data, data, len, releaseData);
           84  +	    provider = CGDataProviderCreateWithData(data, data, len,
           85  +		    releaseData);
    85     86   	}
    86     87   	if (provider) {
    87         -	    img = CGImageMaskCreate(image->width, image->height, bitsPerComponent,
    88         -				    bitsPerPixel, image->bytes_per_line, provider, decode, 0);
           88  +	    img = CGImageMaskCreate(image->width, image->height,
           89  +		    bitsPerComponent, bitsPerPixel, image->bytes_per_line,
           90  +		    provider, decode, 0);
    89     91   	}
    90         -    } else if (image->format == ZPixmap && image->bits_per_pixel == 32) {
    91         -
           92  +    } else if ((image->format == ZPixmap) && (image->bits_per_pixel == 32)) {
    92     93   	/*
    93     94   	 * Color image
    94     95   	 */
    95     96   
    96     97   	CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    97     98   
    98     99   	if (image->width == 0 && image->height == 0) {
    99         -
   100    100   	    /*
   101    101   	     * CGCreateImage complains on early macOS releases.
   102    102   	     */
   103    103   
   104    104   	    return NULL;
   105    105   	}
   106    106   	bitsPerComponent = 8;
   107    107   	bitsPerPixel = 32;
   108    108   	bitmapInfo = (image->byte_order == MSBFirst ?
   109         -		      kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big);
          109  +		kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big);
   110    110   	bitmapInfo |= kCGImageAlphaLast;
   111    111   	data = memcpy(ckalloc(len), image->data + image->xoffset, len);
   112    112   	if (data) {
   113         -	    provider = CGDataProviderCreateWithData(data, data, len, releaseData);
          113  +	    provider = CGDataProviderCreateWithData(data, data, len,
          114  +		    releaseData);
   114    115   	}
   115    116   	if (provider) {
   116    117   	    img = CGImageCreate(image->width, image->height, bitsPerComponent,
   117    118   		    bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo,
   118    119   		    provider, decode, 0, kCGRenderingIntentDefault);
   119    120   	    CFRelease(provider);
   120    121   	}
................................................................................
   123    124   	}
   124    125       } else {
   125    126   	TkMacOSXDbgMsg("Unsupported image type");
   126    127       }
   127    128       return img;
   128    129   }
   129    130   
   130         -
   131    131   /*
   132    132    *----------------------------------------------------------------------
   133    133    *
   134    134    * XGetImage --
   135    135    *
   136    136    *	This function copies data from a pixmap or window into an XImage.  It
   137    137    *      is essentially never used. At one time it was called by
................................................................................
   175    175       unsigned int bytes_per_row, size, row, n, m;
   176    176       unsigned int scalefactor=1, scaled_height=height, scaled_width=width;
   177    177       NSWindow *win = TkMacOSXDrawableWindow(drawable);
   178    178       static enum {unknown, no, yes} has_retina = unknown;
   179    179   
   180    180       if (win && has_retina == unknown) {
   181    181   #ifdef __clang__
   182         -	has_retina = [win respondsToSelector:@selector(backingScaleFactor)]?
   183         -	    yes : no;
          182  +	has_retina = [win respondsToSelector:@selector(backingScaleFactor)] ?
          183  +		yes : no;
   184    184   #else
   185    185   	has_retina = no;
   186    186   #endif
   187    187       }
   188    188   
   189    189       if (has_retina == yes) {
   190         -
   191    190   	/*
   192    191   	 * We only allow scale factors 1 or 2, as Apple currently does.
   193    192   	 */
   194    193   
   195    194   #ifdef __clang__
   196    195   	scalefactor = [win backingScaleFactor] == 2.0 ? 2 : 1;
   197    196   #endif
................................................................................
   201    200   
   202    201       if (format == ZPixmap) {
   203    202   	if (width == 0 || height == 0) {
   204    203   	    return NULL;
   205    204   	}
   206    205   
   207    206   	bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(drawable,
   208         -			  x, y, width, height);
          207  +		x, y, width, height);
   209    208   	if (!bitmap_rep) {
   210    209   	    TkMacOSXDbgMsg("XGetImage: Failed to construct NSBitmapRep");
   211    210   	    return NULL;
   212    211   	}
   213    212   	bitmap_fmt = [bitmap_rep bitmapFormat];
   214    213   	size = [bitmap_rep bytesPerPlane];
   215    214   	bytes_per_row = [bitmap_rep bytesPerRow];
   216    215   	bitmap = ckalloc(size);
   217         -	if (!bitmap                              ||
   218         -	    (bitmap_fmt != 0 && bitmap_fmt != 1) ||
   219         -	    [bitmap_rep samplesPerPixel] != 4    ||
   220         -	    [bitmap_rep isPlanar] != 0           ||
   221         -	    bytes_per_row < 4 * scaled_width    ||
   222         -	    size != bytes_per_row*scaled_height  ) {
          216  +	if (!bitmap
          217  +		|| (bitmap_fmt != 0 && bitmap_fmt != 1)
          218  +		|| [bitmap_rep samplesPerPixel] != 4
          219  +		|| [bitmap_rep isPlanar] != 0
          220  +		|| bytes_per_row < 4 * scaled_width
          221  +		|| size != bytes_per_row * scaled_height) {
   223    222   	    TkMacOSXDbgMsg("XGetImage: Unrecognized bitmap format");
   224    223   	    CFRelease(bitmap_rep);
   225    224   	    return NULL;
   226    225   	}
   227    226   	memcpy(bitmap, (char *)[bitmap_rep bitmapData], size);
   228    227   	CFRelease(bitmap_rep);
   229    228   
   230    229   	/*
   231         -	 * When Apple extracts a bitmap from an NSView, it may be in
   232         -	 * either BGRA or ABGR format.  For an XImage we need RGBA.
          230  +	 * When Apple extracts a bitmap from an NSView, it may be in either
          231  +	 * BGRA or ABGR format.  For an XImage we need RGBA.
   233    232   	 */
   234    233   
   235    234   	struct pixel_fmt pixel = bitmap_fmt == 0 ? bgra : abgr;
   236    235   
   237    236   	for (row = 0, n = 0; row < scaled_height; row++, n += bytes_per_row) {
   238    237   	    for (m = n; m < n + 4*scaled_width; m += 4) {
   239    238   		R = *(bitmap + m + pixel.r);
................................................................................
   244    243   		*(bitmap + m)     = R;
   245    244   		*(bitmap + m + 1) = G;
   246    245   		*(bitmap + m + 2) = B;
   247    246   		*(bitmap + m + 3) = A;
   248    247   	    }
   249    248   	}
   250    249   	imagePtr = XCreateImage(display, NULL, depth, format, offset,
   251         -				(char*)bitmap, scaled_width, scaled_height,
   252         -				bitmap_pad, bytes_per_row);
          250  +		(char*) bitmap, scaled_width, scaled_height,
          251  +		bitmap_pad, bytes_per_row);
   253    252   	if (scalefactor == 2) {
   254    253   	    imagePtr->pixelpower = 1;
   255    254   	}
   256    255       } else {
   257    256   	/*
   258         -	 * There are some calls to XGetImage in the generic Tk
   259         -	 * code which pass an XYPixmap rather than a ZPixmap.
   260         -	 * XYPixmaps should be handled here.
          257  +	 * There are some calls to XGetImage in the generic Tk code which pass
          258  +	 * an XYPixmap rather than a ZPixmap.  XYPixmaps should be handled
          259  +	 * here.
   261    260   	 */
   262    261   	TkMacOSXDbgMsg("XGetImage does not handle XYPixmaps at the moment.");
   263    262       }
   264    263       return imagePtr;
   265    264   }
   266    265   
   267    266   /*
................................................................................
   319    318   
   320    319       if (image && image->data) {
   321    320   	unsigned char *srcPtr = ((unsigned char*) image->data)
   322    321   		+ (y * image->bytes_per_line)
   323    322   		+ (((image->xoffset + x) * image->bits_per_pixel) / NBBY);
   324    323   
   325    324   	switch (image->bits_per_pixel) {
   326         -	    case 32: {
   327         -		r = (*((unsigned int*) srcPtr) >> 16) & 0xff;
   328         -		g = (*((unsigned int*) srcPtr) >>  8) & 0xff;
   329         -		b = (*((unsigned int*) srcPtr)      ) & 0xff;
   330         -		/*if (image->byte_order == LSBFirst) {
   331         -		    r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0];
   332         -		} else {
   333         -		    r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3];
   334         -		}*/
   335         -		break;
   336         -	    }
   337         -	    case 16:
   338         -		r = (*((unsigned short*) srcPtr) >> 7) & 0xf8;
   339         -		g = (*((unsigned short*) srcPtr) >> 2) & 0xf8;
   340         -		b = (*((unsigned short*) srcPtr) << 3) & 0xf8;
   341         -		break;
   342         -	    case 8:
   343         -		r = (*srcPtr << 2) & 0xc0;
   344         -		g = (*srcPtr << 4) & 0xc0;
   345         -		b = (*srcPtr << 6) & 0xc0;
   346         -		r |= r >> 2 | r >> 4 | r >> 6;
   347         -		g |= g >> 2 | g >> 4 | g >> 6;
   348         -		b |= b >> 2 | b >> 4 | b >> 6;
   349         -		break;
   350         -	    case 4: {
   351         -		unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4);
   352         -		r = (c & 0x04) ? 0xff : 0;
   353         -		g = (c & 0x02) ? 0xff : 0;
   354         -		b = (c & 0x01) ? 0xff : 0;
   355         -		break;
   356         -		}
   357         -	    case 1:
   358         -		r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0;
   359         -		break;
          325  +	case 32:
          326  +	    r = (*((unsigned int*) srcPtr) >> 16) & 0xff;
          327  +	    g = (*((unsigned int*) srcPtr) >>  8) & 0xff;
          328  +	    b = (*((unsigned int*) srcPtr)      ) & 0xff;
          329  +	    /*if (image->byte_order == LSBFirst) {
          330  +		r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0];
          331  +	    } else {
          332  +		r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3];
          333  +	    }*/
          334  +	    break;
          335  +	case 16:
          336  +	    r = (*((unsigned short*) srcPtr) >> 7) & 0xf8;
          337  +	    g = (*((unsigned short*) srcPtr) >> 2) & 0xf8;
          338  +	    b = (*((unsigned short*) srcPtr) << 3) & 0xf8;
          339  +	    break;
          340  +	case 8:
          341  +	    r = (*srcPtr << 2) & 0xc0;
          342  +	    g = (*srcPtr << 4) & 0xc0;
          343  +	    b = (*srcPtr << 6) & 0xc0;
          344  +	    r |= r >> 2 | r >> 4 | r >> 6;
          345  +	    g |= g >> 2 | g >> 4 | g >> 6;
          346  +	    b |= b >> 2 | b >> 4 | b >> 6;
          347  +	    break;
          348  +	case 4: {
          349  +	    unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4);
          350  +
          351  +	    r = (c & 0x04) ? 0xff : 0;
          352  +	    g = (c & 0x02) ? 0xff : 0;
          353  +	    b = (c & 0x01) ? 0xff : 0;
          354  +	    break;
          355  +	}
          356  +	case 1:
          357  +	    r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0;
          358  +	    break;
   360    359   	}
   361    360       }
   362    361       return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b;
   363    362   }
   364    363   
   365    364   /*
   366    365    *----------------------------------------------------------------------
................................................................................
   385    384       int y,
   386    385       unsigned long pixel)
   387    386   {
   388    387       if (image && image->data) {
   389    388   	unsigned char *dstPtr = ((unsigned char*) image->data)
   390    389   		+ (y * image->bytes_per_line)
   391    390   		+ (((image->xoffset + x) * image->bits_per_pixel) / NBBY);
          391  +
   392    392   	if (image->bits_per_pixel == 32) {
   393    393   	    *((unsigned int*) dstPtr) = pixel;
   394    394   	} else {
   395    395   	    unsigned char r = ((pixel & image->red_mask)   >> 16) & 0xff;
   396    396   	    unsigned char g = ((pixel & image->green_mask) >>  8) & 0xff;
   397    397   	    unsigned char b = ((pixel & image->blue_mask)       ) & 0xff;
   398    398   	    switch (image->bits_per_pixel) {
................................................................................
   416    416   			(*dstPtr & ~(0x80 >> (x % 8)));
   417    417   		break;
   418    418   	    }
   419    419   	}
   420    420       }
   421    421       return 0;
   422    422   }
   423         -
          423  +
   424    424   /*
   425    425    *----------------------------------------------------------------------
   426    426    *
   427    427    * XCreateImage --
   428    428    *
   429    429    *	Allocates storage for a new XImage.
   430    430    *
................................................................................
   447    447       char* data,
   448    448       unsigned int width,
   449    449       unsigned int height,
   450    450       int bitmap_pad,
   451    451       int bytes_per_line)
   452    452   {
   453    453       XImage *ximage;
          454  +
   454    455       display->request++;
   455    456       ximage = ckalloc(sizeof(XImage));
   456    457   
   457    458       ximage->height = height;
   458    459       ximage->width = width;
   459    460       ximage->depth = depth;
   460    461       ximage->xoffset = offset;
   461    462       ximage->format = format;
   462    463       ximage->data = data;
   463    464       ximage->obdata = NULL;
   464         -    /* The default pixelpower is 0.  This must be explicitly set to 1 in the
          465  +
          466  +    /*
          467  +     * The default pixelpower is 0.  This must be explicitly set to 1 in the
   465    468        * case of an XImage extracted from a Retina display.
   466    469        */
          470  +
   467    471       ximage->pixelpower = 0;
   468    472   
   469    473       if (format == ZPixmap) {
   470    474   	ximage->bits_per_pixel = 32;
   471    475   	ximage->bitmap_unit = 32;
   472    476       } else {
   473    477   	ximage->bits_per_pixel = 1;
   474    478   	ximage->bitmap_unit = 8;
   475    479       }
   476    480       if (bitmap_pad) {
   477    481   	ximage->bitmap_pad = bitmap_pad;
   478    482       } else {
   479         -	/* Use 16 byte alignment for best Quartz perfomance */
          483  +	/*
          484  +	 * Use 16 byte alignment for best Quartz perfomance.
          485  +	 */
          486  +
   480    487   	ximage->bitmap_pad = 128;
   481    488       }
   482    489       if (bytes_per_line) {
   483    490   	ximage->bytes_per_line = bytes_per_line;
   484    491       } else {
   485    492   	ximage->bytes_per_line = ((width * ximage->bits_per_pixel +
   486    493   		(ximage->bitmap_pad - 1)) >> 3) &
................................................................................
   507    514   }
   508    515   
   509    516   /*
   510    517    *----------------------------------------------------------------------
   511    518    *
   512    519    * TkPutImage --
   513    520    *
   514         - *	Copies a rectangular subimage of an XImage into a drawable.
   515         - *      Currently this is only called by TkImgPhotoDisplay, using
   516         - *      a Window as the drawable.
          521  + *	Copies a rectangular subimage of an XImage into a drawable.  Currently
          522  + *      this is only called by TkImgPhotoDisplay, using a Window as the
          523  + *      drawable.
   517    524    *
   518    525    * Results:
   519    526    *	None.
   520    527    *
   521    528    * Side effects:
   522    529    *	Draws the image on the specified drawable.
   523    530    *
................................................................................
   555    562   	 */
   556    563   
   557    564   	if (!(macDraw->flags & TK_IS_PIXMAP)) {
   558    565   	    CGContextSetBlendMode(dc.context, kCGBlendModeSourceAtop);
   559    566   	}
   560    567   	if (img) {
   561    568   
   562         -	    /* If the XImage has big pixels, the source is rescaled to reflect
          569  +	    /*
          570  +	     * If the XImage has big pixels, the source is rescaled to reflect
   563    571   	     * the actual pixel dimensions.  This is not currently used, but
   564    572   	     * could arise if the image were copied from a retina monitor and
   565    573   	     * redrawn on an ordinary monitor.
   566    574   	     */
   567    575   
   568    576   	    int pp = image->pixelpower;
          577  +
   569    578   	    bounds = CGRectMake(0, 0, image->width, image->height);
   570    579   	    srcRect = CGRectMake(src_x<<pp, src_y<<pp, width<<pp, height<<pp);
   571    580   	    dstRect = CGRectMake(dest_x, dest_y, width, height);
   572    581   	    TkMacOSXDrawCGImage(drawable, gc, dc.context,
   573    582   				img, gc->foreground, gc->background,
   574    583   				bounds, srcRect, dstRect);
   575    584   	    CFRelease(img);

Changes to macosx/tkMacOSXInit.c.

    41     41    * called while the pool is locked.
    42     42    */
    43     43   #undef DEBUG_LOCK
    44     44   
    45     45   @implementation TKApplication(TKInit)
    46     46   - (void) _resetAutoreleasePool
    47     47   {
    48         -    if([self poolLock] == 0) {
           48  +    if ([self poolLock] == 0) {
    49     49   	[_mainPool drain];
    50     50   	_mainPool = [NSAutoreleasePool new];
    51     51       } else {
    52     52   #ifdef DEBUG_LOCK
    53     53   	fprintf(stderr, "Pool is locked with count %d!!!!\n", [self poolLock]);
    54     54   #endif
    55     55       }
................................................................................
   114    114       TkMacOSXUseAntialiasedText(_eventInterp, -1);
   115    115       TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0);
   116    116   }
   117    117   
   118    118   -(void)applicationDidFinishLaunching:(NSNotification *)notification
   119    119   {
   120    120       /*
   121         -     * It is not safe to force activation of the NSApp until this
   122         -     * method is called.  Activating too early can cause the menu
   123         -     * bar to be unresponsive.
          121  +     * It is not safe to force activation of the NSApp until this method is
          122  +     * called. Activating too early can cause the menu bar to be unresponsive.
   124    123        */
   125    124   
   126    125       [NSApp activateIgnoringOtherApps: YES];
   127    126   
   128    127       /*
   129         -     * Process events to ensure that the root window is fully
   130         -     * initialized. See ticket 56a1823c73.
          128  +     * Process events to ensure that the root window is fully initialized. See
          129  +     * ticket 56a1823c73.
   131    130        */
   132    131       
   133    132       [NSApp _lockAutoreleasePool];
   134    133       while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS| TCL_DONT_WAIT)) {}
   135    134       [NSApp _unlockAutoreleasePool];
   136    135   }
   137    136   
................................................................................
   307    306   
   308    307   	if (getenv("XCNOSTDIN") != NULL) {
   309    308   	    close(0);
   310    309   	    close(1);
   311    310   	}
   312    311   
   313    312   	/*
   314         -	 * Instantiate our NSApplication object. This needs to be
   315         -	 * done before we check whether to open a console window.
          313  +	 * Instantiate our NSApplication object. This needs to be done before
          314  +	 * we check whether to open a console window.
   316    315   	 */
   317    316   
   318    317   	NSAutoreleasePool *pool = [NSAutoreleasePool new];
   319    318   	[[NSUserDefaults standardUserDefaults] registerDefaults:
   320    319   		[NSDictionary dictionaryWithObjectsAndKeys:
   321    320   				  [NSNumber numberWithBool:YES],
   322    321   			      @"_NSCanWrapButtonTitles",
................................................................................
   339    338   		(S_ISCHR(st.st_mode) && st.st_blocks == 0)))) {
   340    339   	    Tk_InitConsoleChannels(interp);
   341    340   	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
   342    341   	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
   343    342   	    Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
   344    343   
   345    344   	    /*
   346         -	     * Only show the console if we don't have a startup script
   347         -	     * and tcl_interactive hasn't been set already.
          345  +	     * Only show the console if we don't have a startup script and
          346  +	     * tcl_interactive hasn't been set already.
   348    347   	     */
   349    348   
   350    349   	    if (Tcl_GetStartupScript(NULL) == NULL) {
   351    350   		const char *intvar = Tcl_GetVar2(interp,
   352    351   			"tcl_interactive", NULL, TCL_GLOBAL_ONLY);
   353    352   
   354    353   		if (intvar == NULL) {

Changes to macosx/tkMacOSXKeyEvent.c.

    23     23   #endif
    24     24   */
    25     25   #define NS_KEYLOG 0
    26     26   
    27     27   static Tk_Window keyboardGrabWinPtr = NULL;
    28     28   				/* Current keyboard grab window. */
    29     29   static NSWindow *keyboardGrabNSWindow = nil;
    30         -                               /* NSWindow for the current keyboard grab window. */
           30  +				/* NSWindow for the current keyboard grab
           31  +				 * window. */
    31     32   static NSModalSession modalSession = nil;
    32         -
    33     33   static BOOL processingCompose = NO;
    34     34   static BOOL finishedCompose = NO;
    35         -
    36     35   static int caret_x = 0, caret_y = 0, caret_height = 0;
    37     36   
    38         -static void setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state);
    39         -static unsigned isFunctionKey(unsigned int code);
           37  +static void		setupXEvent(XEvent *xEvent, NSWindow *w,
           38  +			    unsigned int state);
           39  +static unsigned		isFunctionKey(unsigned int code);
    40     40   
    41     41   unsigned short releaseCode;
    42     42   
    43     43   
    44     44   #pragma mark TKApplication(TKKeyEvent)
    45     45   
    46     46   @implementation TKApplication(TKKeyEvent)
    47     47   
    48     48   - (NSEvent *) tkProcessKeyEvent: (NSEvent *) theEvent
    49     49   {
    50     50   #ifdef TK_MAC_DEBUG_EVENTS
    51     51       TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
    52     52   #endif
    53         -    NSWindow*	    w;
    54         -    NSEventType	    type = [theEvent type];
           53  +    NSWindow *w;
           54  +    NSEventType type = [theEvent type];
    55     55       NSUInteger modifiers = ([theEvent modifierFlags] &
    56     56   			    NSDeviceIndependentModifierFlagsMask);
    57         -    NSUInteger	    len = 0;
    58         -    BOOL	    repeat = NO;
    59         -    unsigned short  keyCode = [theEvent keyCode];
    60         -    NSString	    *characters = nil, *charactersIgnoringModifiers = nil;
           57  +    NSUInteger len = 0;
           58  +    BOOL repeat = NO;
           59  +    unsigned short keyCode = [theEvent keyCode];
           60  +    NSString *characters = nil, *charactersIgnoringModifiers = nil;
    61     61       static NSUInteger savedModifiers = 0;
    62     62       static NSMutableArray *nsEvArray;
    63     63   
    64         -    if (nsEvArray == nil)
    65         -      {
           64  +    if (nsEvArray == nil) {
    66     65           nsEvArray = [[NSMutableArray alloc] initWithCapacity: 1];
    67     66           processingCompose = NO;
    68         -      }
           67  +    }
    69     68   
    70     69       w = [theEvent window];
    71     70       TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    72     71       Tk_Window tkwin = (Tk_Window) winPtr;
    73     72       XEvent xEvent;
    74     73   
    75     74       if (!winPtr) {
................................................................................
   105    104   #endif
   106    105   	break;
   107    106   
   108    107       default:
   109    108   	return theEvent; /* Unrecognized key event. */
   110    109       }
   111    110   
   112         -    /* Create an Xevent to add to the Tk queue. */
          111  +    /*
          112  +     * Create an Xevent to add to the Tk queue.
          113  +     */
          114  +
   113    115       if (!processingCompose) {
   114    116           unsigned int state = 0;
   115    117   
   116    118           if (modifiers & NSAlphaShiftKeyMask) {
   117         -          state |= LockMask;
          119  +	    state |= LockMask;
   118    120           }
   119    121           if (modifiers & NSShiftKeyMask) {
   120         -          state |= ShiftMask;
          122  +	    state |= ShiftMask;
   121    123           }
   122    124           if (modifiers & NSControlKeyMask) {
   123         -          state |= ControlMask;
          125  +	    state |= ControlMask;
   124    126           }
   125    127           if (modifiers & NSCommandKeyMask) {
   126         -          state |= Mod1Mask;		/* command key */
          128  +	    state |= Mod1Mask;		/* command key */
   127    129           }
   128    130           if (modifiers & NSAlternateKeyMask) {
   129         -          state |= Mod2Mask;		/* option key */
          131  +	    state |= Mod2Mask;		/* option key */
   130    132           }
   131    133           if (modifiers & NSNumericPadKeyMask) {
   132         -          state |= Mod3Mask;
          134  +	    state |= Mod3Mask;
   133    135           }
   134    136           if (modifiers & NSFunctionKeyMask) {
   135         -          state |= Mod4Mask;
          137  +	    state |= Mod4Mask;
   136    138           }
   137    139   
   138    140           /*
   139         -         * Events are only received for the front Window on the Macintosh.
   140         -	 * So to build an XEvent we look up the Tk window associated to the
   141         -	 * Front window. If a different window has a local grab we ignore
   142         -	 * the event.
          141  +         * Events are only received for the front Window on the Macintosh. So
          142  +	 * to build an XEvent we look up the Tk window associated to the Front
          143  +	 * window. If a different window has a local grab we ignore the event.
   143    144            */
   144    145   
   145    146           TkWindow *winPtr = TkMacOSXGetTkWindow(w);
   146    147           Tk_Window tkwin = (Tk_Window) winPtr;
   147    148   
   148    149   	if (tkwin) {
   149    150   	    TkWindow *grabWinPtr = winPtr->dispPtr->grabWinPtr;
   150         -	    if (grabWinPtr &&
   151         -		grabWinPtr != winPtr &&
   152         -		!winPtr->dispPtr->grabFlags && /* this means the grab is local. */
   153         -		grabWinPtr->mainPtr == winPtr->mainPtr) {
          151  +
          152  +	    if (grabWinPtr
          153  +		    && grabWinPtr != winPtr
          154  +		    && !winPtr->dispPtr->grabFlags /* this means the grab is local. */
          155  +		    && grabWinPtr->mainPtr == winPtr->mainPtr) {
   154    156   		return theEvent;
   155    157   	    }
   156    158   	} else {
   157    159   	    tkwin = (Tk_Window) winPtr->dispPtr->focusPtr;
   158    160   	}
   159    161           if (!tkwin) {
   160         -          TkMacOSXDbgMsg("tkwin == NULL");
   161         -          return theEvent;  /* Give up. No window for this event. */
          162  +	    TkMacOSXDbgMsg("tkwin == NULL");
          163  +	    return theEvent;  /* Give up. No window for this event. */
   162    164           }
   163    165   
   164    166           /*
   165         -         * If it's a function key, or we have modifiers other than Shift or Alt,
   166         -         * pass it straight to Tk.  Otherwise we'll send for input processing.
          167  +         * If it's a function key, or we have modifiers other than Shift or
          168  +         * Alt, pass it straight to Tk.  Otherwise we'll send for input
          169  +         * processing.
   167    170            */
   168    171   
   169         -        int code = (len == 0) ?
   170         -          0 : [charactersIgnoringModifiers characterAtIndex: 0];
          172  +        int code = (len == 0) ? 0 :
          173  +		[charactersIgnoringModifiers characterAtIndex: 0];
   171    174           if (type != NSKeyDown || isFunctionKey(code)
   172         -            || (len > 0 && state & (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask))) {
   173         -
          175  +		|| (len > 0 && state & (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask))) {
   174    176               XEvent xEvent;
          177  +
   175    178               setupXEvent(&xEvent, w, state);
   176         -
   177    179               if (type == NSFlagsChanged) {
   178         -              if (savedModifiers > modifiers) {
   179         -                xEvent.xany.type = KeyRelease;
   180         -              } else {
   181         -                xEvent.xany.type = KeyPress;
   182         -              }
          180  +		if (savedModifiers > modifiers) {
          181  +		    xEvent.xany.type = KeyRelease;
          182  +		} else {
          183  +		    xEvent.xany.type = KeyPress;
          184  +		}
   183    185   
   184         -              /*
   185         -               * Use special '-1' to signify a special keycode to our platform
   186         -               * specific code in tkMacOSXKeyboard.c. This is rather like what
   187         -               * happens on Windows.
   188         -               */
          186  +		/*
          187  +		 * Use special '-1' to signify a special keycode to our
          188  +		 * platform specific code in tkMacOSXKeyboard.c. This is rather
          189  +		 * like what happens on Windows.
          190  +		 */
   189    191   
   190         -              xEvent.xany.send_event = -1;
          192  +		xEvent.xany.send_event = -1;
   191    193   
   192         -              /*
   193         -               * Set keycode (which was zero) to the changed modifier
   194         -               */
          194  +		/*
          195  +		 * Set keycode (which was zero) to the changed modifier
          196  +		 */
   195    197   
   196         -              xEvent.xkey.keycode = (modifiers ^ savedModifiers);
          198  +		xEvent.xkey.keycode = (modifiers ^ savedModifiers);
   197    199               } else {
   198         -              if (type == NSKeyUp || repeat) {
   199         -		  xEvent.xany.type = KeyRelease;
   200         -              } else {
   201         -                xEvent.xany.type = KeyPress;
   202         -              }
   203         -
   204         -              /* For command key, take input manager's word so things
   205         -                 like dvorak / qwerty layout work. */
   206         -              if ((modifiers & NSCommandKeyMask) == NSCommandKeyMask
   207         -                  && (modifiers & NSAlternateKeyMask) != NSAlternateKeyMask
   208         -                  && len > 0 && !isFunctionKey(code)) {
   209         -                // head off keycode-based translation in tkMacOSXKeyboard.c
   210         -                xEvent.xkey.nbytes = [characters length]; //len
   211         -              }
   212         -
   213         -              if ([characters length] > 0) {
   214         -                xEvent.xkey.keycode =
   215         -                  (keyCode << 16) | (UInt16) [characters characterAtIndex:0];
   216         -                if (![characters getCString:xEvent.xkey.trans_chars
   217         -                                  maxLength:XMaxTransChars encoding:NSUTF8StringEncoding]) {
   218         -                  /* prevent SF bug 2907388 (crash on some composite chars) */
   219         -                  //PENDING: we might not need this anymore
   220         -                  TkMacOSXDbgMsg("characters too long");
   221         -                  return theEvent;
   222         -                }
   223         -              }
   224         -
   225         -              if (repeat) {
   226         -                Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
   227         -                xEvent.xany.type = KeyPress;
   228         -                xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
   229         -              }
          200  +		if (type == NSKeyUp || repeat) {
          201  +		    xEvent.xany.type = KeyRelease;
          202  +		} else {
          203  +		    xEvent.xany.type = KeyPress;
          204  +		}
          205  +
          206  +		/*
          207  +		 * For command key, take input manager's word so things like
          208  +		 * dvorak / qwerty layout work.
          209  +		 */
          210  +
          211  +		if ((modifiers & NSCommandKeyMask) == NSCommandKeyMask
          212  +			&& (modifiers & NSAlternateKeyMask) != NSAlternateKeyMask
          213  +			&& len > 0 && !isFunctionKey(code)) {
          214  +		    // head off keycode-based translation in tkMacOSXKeyboard.c
          215  +		    xEvent.xkey.nbytes = [characters length]; //len
          216  +		}
          217  +
          218  +		if ([characters length] > 0) {
          219  +		    xEvent.xkey.keycode = (keyCode << 16) |
          220  +			    (UInt16) [characters characterAtIndex:0];
          221  +		    if (![characters getCString:xEvent.xkey.trans_chars
          222  +			    maxLength:XMaxTransChars encoding:NSUTF8StringEncoding]) {
          223  +			/* prevent SF bug 2907388 (crash on some composite chars) */
          224  +			//PENDING: we might not need this anymore
          225  +			TkMacOSXDbgMsg("characters too long");
          226  +			return theEvent;
          227  +		    }
          228  +		}
          229  +
          230  +		if (repeat) {
          231  +		    Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
          232  +		    xEvent.xany.type = KeyPress;
          233  +		    xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
          234  +		}
   230    235               }
   231    236               Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
   232    237               savedModifiers = modifiers;
   233    238               return theEvent;
   234         -          }  /* if send straight to TK */
   235         -
   236         -      }  /* if not processing compose */
          239  +	}  /* if send straight to TK */
          240  +    }  /* if not processing compose */
   237    241   
   238    242       if (type == NSKeyDown) {
   239         -        if (NS_KEYLOG)
   240         -          fprintf (stderr, "keyDown: %s compose sequence.\n",
   241         -                   processingCompose == YES ? "Continue" : "Begin");
          243  +        if (NS_KEYLOG) {
          244  +	    TKLog(@"keyDown: %s compose sequence.\n",
          245  +		    processingCompose == YES ? "Continue" : "Begin");
          246  +	}
   242    247           processingCompose = YES;
   243    248           [nsEvArray addObject: theEvent];
   244    249           [[w contentView] interpretKeyEvents: nsEvArray];
   245    250           [nsEvArray removeObject: theEvent];
   246         -      }
          251  +    }
   247    252   
   248    253       savedModifiers = modifiers;
   249         -
   250    254       return theEvent;
   251    255   }
   252    256   @end
   253         -
   254    257   
   255    258   
   256    259   @implementation TKContentView
   257    260   /* <NSTextInput> implementation (called through interpretKeyEvents:]). */
   258    261   
   259    262   /* <NSTextInput>: called when done composing;
   260    263      NOTE: also called when we delete over working text, followed immed.
   261    264            by doCommandBySelector: deleteBackward: */
   262    265   - (void)insertText: (id)aString
   263    266   {
   264         -  int i, len = [(NSString *)aString length];
   265         -  XEvent xEvent;
   266         -
   267         -  if (NS_KEYLOG)
   268         -    TKLog (@"insertText '%@'\tlen = %d", aString, len);
   269         -  processingCompose = NO;
   270         -  finishedCompose = YES;
   271         -
   272         -  /* first, clear any working text */
   273         -  if (privateWorkingText != nil)
   274         -    [self deleteWorkingText];
   275         -
   276         -  /* now insert the string as keystrokes */
   277         -  setupXEvent(&xEvent, [self window], 0);
   278         -  xEvent.xany.type = KeyPress;
   279         -
   280         -  for (i =0; i<len; i++)
   281         -      {
   282         -	  xEvent.xkey.keycode = (UInt16) [aString characterAtIndex: i];
   283         -	  [[aString substringWithRange: NSMakeRange(i,1)]
          267  +    int i, len = [(NSString *) aString length];
          268  +    XEvent xEvent;
          269  +
          270  +    if (NS_KEYLOG) {
          271  +	TKLog(@"insertText '%@'\tlen = %d", aString, len);
          272  +    }
          273  +    processingCompose = NO;
          274  +    finishedCompose = YES;
          275  +
          276  +    /*
          277  +     * First, clear any working text.
          278  +     */
          279  +
          280  +    if (privateWorkingText != nil) {
          281  +	[self deleteWorkingText];
          282  +    }
          283  +
          284  +    /*
          285  +     * Now insert the string as keystrokes.
          286  +     */
          287  +
          288  +    setupXEvent(&xEvent, [self window], 0);
          289  +    xEvent.xany.type = KeyPress;
          290  +
          291  +    for (i =0; i<len; i++) {
          292  +	xEvent.xkey.keycode = (UInt16) [aString characterAtIndex: i];
          293  +	[[aString substringWithRange: NSMakeRange(i,1)]
   284    294   	      getCString: xEvent.xkey.trans_chars
   285    295   	       maxLength: XMaxTransChars encoding: NSUTF8StringEncoding];
   286         -	  xEvent.xkey.nbytes = strlen(xEvent.xkey.trans_chars);
   287         -	  xEvent.xany.type = KeyPress;
   288         -	  releaseCode =  (UInt16) [aString characterAtIndex: 0];
   289         -	  Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
   290         -      }
   291         -  releaseCode =  (UInt16) [aString characterAtIndex: 0];
          296  +	xEvent.xkey.nbytes = strlen(xEvent.xkey.trans_chars);
          297  +	xEvent.xany.type = KeyPress;
          298  +	releaseCode = (UInt16) [aString characterAtIndex: 0];
          299  +	Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
          300  +    }
          301  +    releaseCode = (UInt16) [aString characterAtIndex: 0];
   292    302   }
   293    303   
   294    304   
   295    305   /* <NSTextInput>: inserts display of composing characters */
   296    306   - (void)setMarkedText: (id)aString selectedRange: (NSRange)selRange
   297    307   {
   298         -  NSString *str = [aString respondsToSelector: @selector (string)] ?
   299         -    [aString string] : aString;
   300         -  if (NS_KEYLOG)
   301         -    TKLog (@"setMarkedText '%@' len =%lu range %lu from %lu", str,
   302         -	   (unsigned long) [str length], (unsigned long) selRange.length,
   303         -	   (unsigned long) selRange.location);
          308  +    NSString *str = [aString respondsToSelector: @selector (string)] ?
          309  +	[aString string] : aString;
          310  +    if (NS_KEYLOG) {
          311  +	TKLog(@"setMarkedText '%@' len =%lu range %lu from %lu", str,
          312  +	      (unsigned long) [str length], (unsigned long) selRange.length,
          313  +	      (unsigned long) selRange.location);
          314  +    }
   304    315   
   305         -  if (privateWorkingText != nil)
   306         -    [self deleteWorkingText];
   307         -  if ([str length] == 0)
   308         -    return;
          316  +    if (privateWorkingText != nil) {
          317  +	[self deleteWorkingText];
          318  +    }
          319  +    if ([str length] == 0) {
          320  +	return;
          321  +    }
   309    322   
   310         -  processingCompose = YES;
   311         -  privateWorkingText = [str copy];
          323  +    processingCompose = YES;
          324  +    privateWorkingText = [str copy];
   312    325   
   313         -  //PENDING: insert workingText underlined
          326  +    //PENDING: insert workingText underlined
   314    327   }
   315    328   
   316    329   
   317    330   - (BOOL)hasMarkedText
   318    331   {
   319         -  return privateWorkingText != nil;
          332  +    return privateWorkingText != nil;
   320    333   }
   321    334   
   322    335   
   323    336   - (NSRange)markedRange
   324    337   {
   325         -  NSRange rng = privateWorkingText != nil
   326         -    ? NSMakeRange (0, [privateWorkingText length]) : NSMakeRange (NSNotFound, 0);
   327         -  if (NS_KEYLOG)
   328         -    TKLog (@"markedRange request");
   329         -  return rng;
          338  +    NSRange rng = privateWorkingText != nil
          339  +	? NSMakeRange(0, [privateWorkingText length])
          340  +	: NSMakeRange(NSNotFound, 0);
          341  +
          342  +    if (NS_KEYLOG) {
          343  +	TKLog(@"markedRange request");
          344  +    }
          345  +    return rng;
   330    346   }
   331    347   
   332    348   
   333    349   - (void)unmarkText
   334    350   {
   335         -  if (NS_KEYLOG)
   336         -    TKLog (@"unmark (accept) text");
   337         -  [self deleteWorkingText];
   338         -  processingCompose = NO;
          351  +    if (NS_KEYLOG) {
          352  +	TKLog(@"unmark (accept) text");
          353  +    }
          354  +    [self deleteWorkingText];
          355  +    processingCompose = NO;
   339    356   }
   340    357   
   341    358   
   342    359   /* used to position char selection windows, etc. */
   343    360   - (NSRect)firstRectForCharacterRange: (NSRange)theRange
   344    361   {
   345         -  NSRect rect;
   346         -  NSPoint pt;
          362  +    NSRect rect;
          363  +    NSPoint pt;
   347    364   
   348         -  pt.x = caret_x;
   349         -  pt.y = caret_y;
          365  +    pt.x = caret_x;
          366  +    pt.y = caret_y;
   350    367   
   351         -  pt = [self convertPoint: pt toView: nil];
   352         -  pt = [[self window] tkConvertPointToScreen: pt];
   353         -  pt.y -= caret_height;
          368  +    pt = [self convertPoint: pt toView: nil];
          369  +    pt = [[self window] tkConvertPointToScreen: pt];
          370  +    pt.y -= caret_height;
   354    371   
   355         -  rect.origin = pt;
   356         -  rect.size.width = caret_height;
   357         -  rect.size.height = caret_height;
   358         -  return rect;
          372  +    rect.origin = pt;
          373  +    rect.size.width = caret_height;
          374  +    rect.size.height = caret_height;
          375  +    return rect;
   359    376   }
   360    377   
   361    378   
   362    379   - (NSInteger)conversationIdentifier
   363    380   {
   364         -  return (NSInteger)self;
          381  +    return (NSInteger) self;
   365    382   }
   366    383   
   367    384   
   368    385   - (void)doCommandBySelector: (SEL)aSelector
   369    386   {
   370         -  if (NS_KEYLOG)
   371         -    TKLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector));
   372         -  processingCompose = NO;
   373         -  if (aSelector == @selector (deleteBackward:))
   374         -    {
   375         -      /* happens when user backspaces over an ongoing composition:
   376         -         throw a 'delete' into the event queue */
   377         -      XEvent xEvent;
   378         -      setupXEvent(&xEvent, [self window], 0);
   379         -      xEvent.xany.type = KeyPress;
   380         -      xEvent.xkey.nbytes = 1;
   381         -      xEvent.xkey.keycode = (0x33 << 16) | 0x7F;
   382         -      xEvent.xkey.trans_chars[0] = 0x7F;
   383         -      xEvent.xkey.trans_chars[1] = 0x0;
   384         -      Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
          387  +    if (NS_KEYLOG) {
          388  +	TKLog(@"doCommandBySelector: %@", NSStringFromSelector(aSelector));
          389  +    }
          390  +    processingCompose = NO;
          391  +    if (aSelector == @selector (deleteBackward:)) {
          392  +	/*
          393  +	 * Happens when user backspaces over an ongoing composition:
          394  +	 * throw a 'delete' into the event queue.
          395  +	 */
          396  +
          397  +	XEvent xEvent;
          398  +
          399  +	setupXEvent(&xEvent, [self window], 0);
          400  +	xEvent.xany.type = KeyPress;
          401  +	xEvent.xkey.nbytes = 1;
          402  +	xEvent.xkey.keycode = (0x33 << 16) | 0x7F;
          403  +	xEvent.xkey.trans_chars[0] = 0x7F;
          404  +	xEvent.xkey.trans_chars[1] = 0x0;
          405  +	Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
   385    406       }
   386    407   }
   387    408   
   388    409   
   389    410   - (NSArray *)validAttributesForMarkedText
   390    411   {
   391         -  static NSArray *arr = nil;
   392         -  if (arr == nil) arr = [NSArray new];
   393         - /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
   394         -  return arr;
          412  +    static NSArray *arr = nil;
          413  +
          414  +    if (arr == nil) {
          415  +	arr = [NSArray new];
          416  +    }
          417  +    /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
          418  +    return arr;
   395    419   }
   396    420   
   397    421   
   398    422   - (NSRange)selectedRange
   399    423   {
   400         -  if (NS_KEYLOG)
   401         -    TKLog (@"selectedRange request");
   402         -  return NSMakeRange (NSNotFound, 0);
          424  +    if (NS_KEYLOG) {
          425  +	TKLog(@"selectedRange request");
          426  +    }
          427  +    return NSMakeRange(NSNotFound, 0);
   403    428   }
   404    429   
   405    430   
   406    431   - (NSUInteger)characterIndexForPoint: (NSPoint)thePoint
   407    432   {
   408         -  if (NS_KEYLOG)
   409         -    TKLog (@"characterIndexForPoint request");
   410         -  return 0;
          433  +    if (NS_KEYLOG) {
          434  +	TKLog(@"characterIndexForPoint request");
          435  +    }
          436  +    return 0;
   411    437   }
   412    438   
   413    439   
   414    440   - (NSAttributedString *)attributedSubstringFromRange: (NSRange)theRange
   415    441   {
   416         -  static NSAttributedString *str = nil;
   417         -  if (str == nil) str = [NSAttributedString new];
   418         -  if (NS_KEYLOG)
   419         -    TKLog (@"attributedSubstringFromRange request");
   420         -  return str;
          442  +    static NSAttributedString *str = nil;
          443  +    if (str == nil) {
          444  +	str = [NSAttributedString new];
          445  +    }
          446  +    if (NS_KEYLOG) {
          447  +	TKLog(@"attributedSubstringFromRange request");
          448  +    }
          449  +    return str;
   421    450   }
   422    451   /* End <NSTextInput> impl. */
   423    452   @end
   424    453   
   425    454   
   426    455   @implementation TKContentView(TKKeyEvent)
   427    456   /* delete display of composing characters [not in <NSTextInput>] */
   428    457   - (void)deleteWorkingText
   429    458   {
   430         -  if (privateWorkingText == nil)
   431         -    return;
   432         -  if (NS_KEYLOG)
   433         -    TKLog(@"deleteWorkingText len = %lu\n",
   434         -	    (unsigned long)[privateWorkingText length]);
   435         -  [privateWorkingText release];
   436         -  privateWorkingText = nil;
   437         -  processingCompose = NO;
          459  +    if (privateWorkingText == nil) {
          460  +	return;
          461  +    }
          462  +    if (NS_KEYLOG) {
          463  +	TKLog(@"deleteWorkingText len = %lu\n",
          464  +	      (unsigned long)[privateWorkingText length]);
          465  +    }
          466  +    [privateWorkingText release];
          467  +    privateWorkingText = nil;
          468  +    processingCompose = NO;
   438    469   
   439         -  //PENDING: delete working text
          470  +    //PENDING: delete working text
   440    471   }
   441    472   @end
   442    473   
   443         -
   444         -
   445    474   /*
   446         - *  Set up basic fields in xevent for keyboard input.
          475  + * Set up basic fields in xevent for keyboard input.
   447    476    */
   448    477   static void
   449    478   setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state)
   450    479   {
   451    480       TkWindow *winPtr = TkMacOSXGetTkWindow(w);
   452    481       Tk_Window tkwin = (Tk_Window) winPtr;
          482  +
   453    483       if (!winPtr) {
   454    484   	return;
   455    485       }
   456    486   
   457    487       memset(xEvent, 0, sizeof(XEvent));
   458    488       xEvent->xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin));
   459    489       xEvent->xany.send_event = false;
................................................................................
   493    523       Window grab_window,
   494    524       Bool owner_events,
   495    525       int pointer_mode,
   496    526       int keyboard_mode,
   497    527       Time time)
   498    528   {
   499    529       keyboardGrabWinPtr = Tk_IdToWindow(display, grab_window);
   500         -    TkWindow *captureWinPtr = (TkWindow *)TkMacOSXGetCapture(); 
          530  +    TkWindow *captureWinPtr = (TkWindow *) TkMacOSXGetCapture();
          531  +
   501    532       if (keyboardGrabWinPtr && captureWinPtr) {
   502    533   	NSWindow *w = TkMacOSXDrawableWindow(grab_window);
   503    534   	MacDrawable *macWin = (MacDrawable *) grab_window;
   504    535   
   505         -	if (w && macWin->toplevel->winPtr == (TkWindow*) captureWinPtr) {
          536  +	if (w && macWin->toplevel->winPtr == (TkWindow *) captureWinPtr) {
   506    537   	    if (modalSession) {
   507    538   		Tcl_Panic("XGrabKeyboard: already grabbed");
   508    539   	    }
   509    540   	    keyboardGrabNSWindow = w;
   510    541   	    [w retain];
   511    542   	    modalSession = [NSApp beginModalSessionForWindow:w];
   512    543   	}
................................................................................
   617    648   	y += Tk_Y(tkwin);
   618    649   	tkwin = Tk_Parent(tkwin);
   619    650   	if (tkwin == NULL) {
   620    651   	    return;
   621    652   	}
   622    653       }
   623    654   
   624         -    /* But adjust for fact that NS uses flipped view. */
          655  +    /*
          656  +     * But adjust for fact that NS uses flipped view.
          657  +     */
          658  +
   625    659       y = Tk_Height(tkwin) - y;
   626    660   
   627    661       caret_x = x;
   628    662       caret_y = y;
   629    663       caret_height = height;
   630    664   }
   631    665   
   632    666   
   633    667   static unsigned convert_ns_to_X_keysym[] =
   634    668   {
   635         -  NSHomeFunctionKey,            0x50,
   636         -  NSLeftArrowFunctionKey,       0x51,
   637         -  NSUpArrowFunctionKey,         0x52,
   638         -  NSRightArrowFunctionKey,      0x53,
   639         -  NSDownArrowFunctionKey,       0x54,
   640         -  NSPageUpFunctionKey,          0x55,
   641         -  NSPageDownFunctionKey,        0x56,
   642         -  NSEndFunctionKey,             0x57,
   643         -  NSBeginFunctionKey,           0x58,
   644         -  NSSelectFunctionKey,          0x60,
   645         -  NSPrintFunctionKey,           0x61,
   646         -  NSExecuteFunctionKey,         0x62,
   647         -  NSInsertFunctionKey,          0x63,
   648         -  NSUndoFunctionKey,            0x65,
   649         -  NSRedoFunctionKey,            0x66,
   650         -  NSMenuFunctionKey,            0x67,
   651         -  NSFindFunctionKey,            0x68,
   652         -  NSHelpFunctionKey,            0x6A,
   653         -  NSBreakFunctionKey,           0x6B,
          669  +    NSHomeFunctionKey,          0x50,
          670  +    NSLeftArrowFunctionKey,     0x51,
          671  +    NSUpArrowFunctionKey,       0x52,
          672  +    NSRightArrowFunctionKey,    0x53,
          673  +    NSDownArrowFunctionKey,     0x54,
          674  +    NSPageUpFunctionKey,        0x55,
          675  +    NSPageDownFunctionKey,      0x56,
          676  +    NSEndFunctionKey,           0x57,
          677  +    NSBeginFunctionKey,         0x58,
          678  +    NSSelectFunctionKey,        0x60,
          679  +    NSPrintFunctionKey,         0x61,
          680  +    NSExecuteFunctionKey,       0x62,
          681  +    NSInsertFunctionKey,        0x63,
          682  +    NSUndoFunctionKey,          0x65,
          683  +    NSRedoFunctionKey,          0x66,
          684  +    NSMenuFunctionKey,          0x67,
          685  +    NSFindFunctionKey,          0x68,
          686  +    NSHelpFunctionKey,          0x6A,
          687  +    NSBreakFunctionKey,         0x6B,
          688  +
          689  +    NSF1FunctionKey,            0xBE,
          690  +    NSF2FunctionKey,            0xBF,
          691  +    NSF3FunctionKey,            0xC0,
          692  +    NSF4FunctionKey,            0xC1,
          693  +    NSF5FunctionKey,            0xC2,
          694  +    NSF6FunctionKey,            0xC3,
          695  +    NSF7FunctionKey,            0xC4,
          696  +    NSF8FunctionKey,            0xC5,
          697  +    NSF9FunctionKey,            0xC6,
          698  +    NSF10FunctionKey,           0xC7,
          699  +    NSF11FunctionKey,           0xC8,
          700  +    NSF12FunctionKey,           0xC9,
          701  +    NSF13FunctionKey,           0xCA,
          702  +    NSF14FunctionKey,           0xCB,
          703  +    NSF15FunctionKey,           0xCC,
          704  +    NSF16FunctionKey,           0xCD,
          705  +    NSF17FunctionKey,           0xCE,
          706  +    NSF18FunctionKey,           0xCF,
          707  +    NSF19FunctionKey,           0xD0,
          708  +    NSF20FunctionKey,           0xD1,
          709  +    NSF21FunctionKey,           0xD2,
          710  +    NSF22FunctionKey,           0xD3,
          711  +    NSF23FunctionKey,           0xD4,
          712  +    NSF24FunctionKey,           0xD5,
          713  +
          714  +    NSBackspaceCharacter,       0x08,  /* 8: Not on some KBs. */
          715  +    NSDeleteCharacter,          0xFF,  /* 127: Big 'delete' key upper right. */
          716  +    NSDeleteFunctionKey,        0x9F,  /* 63272: Del forw key off main array. */
   654    717   
   655         -  NSF1FunctionKey,              0xBE,
   656         -  NSF2FunctionKey,              0xBF,
   657         -  NSF3FunctionKey,              0xC0,
   658         -  NSF4FunctionKey,              0xC1,
   659         -  NSF5FunctionKey,              0xC2,
   660         -  NSF6FunctionKey,              0xC3,
   661         -  NSF7FunctionKey,              0xC4,
   662         -  NSF8FunctionKey,              0xC5,
   663         -  NSF9FunctionKey,              0xC6,
   664         -  NSF10FunctionKey,             0xC7,
   665         -  NSF11FunctionKey,             0xC8,
   666         -  NSF12FunctionKey,             0xC9,
   667         -  NSF13FunctionKey,             0xCA,
   668         -  NSF14FunctionKey,             0xCB,
   669         -  NSF15FunctionKey,             0xCC,
   670         -  NSF16FunctionKey,             0xCD,
   671         -  NSF17FunctionKey,             0xCE,
   672         -  NSF18FunctionKey,             0xCF,
   673         -  NSF19FunctionKey,             0xD0,
   674         -  NSF20FunctionKey,             0xD1,
   675         -  NSF21FunctionKey,             0xD2,
   676         -  NSF22FunctionKey,             0xD3,
   677         -  NSF23FunctionKey,             0xD4,
   678         -  NSF24FunctionKey,             0xD5,
          718  +    NSTabCharacter,		0x09,
          719  +    0x19,			0x09,  /* left tab->regular since pass shift */
          720  +    NSCarriageReturnCharacter,	0x0D,
          721  +    NSNewlineCharacter,		0x0D,
          722  +    NSEnterCharacter,		0x8D,
   679    723   
   680         -  NSBackspaceCharacter,         0x08,  /* 8: Not on some KBs. */
   681         -  NSDeleteCharacter,            0xFF,  /* 127: Big 'delete' key upper right. */
   682         -  NSDeleteFunctionKey,          0x9F,  /* 63272: Del forw key off main array. */
   683         -
   684         -  NSTabCharacter,		0x09,
   685         -  0x19,				0x09,  /* left tab->regular since pass shift */
   686         -  NSCarriageReturnCharacter,	0x0D,
   687         -  NSNewlineCharacter,		0x0D,
   688         -  NSEnterCharacter,		0x8D,
   689         -
   690         -  0x1B,				0x1B   /* escape */
          724  +    0x1B,			0x1B   /* escape */
   691    725   };
   692    726   
   693    727   
   694         -static unsigned isFunctionKey(unsigned code)
          728  +static unsigned
          729  +isFunctionKey(
          730  +    unsigned code)
   695    731   {
   696    732       const unsigned last_keysym = (sizeof (convert_ns_to_X_keysym)
   697    733                                   / sizeof (convert_ns_to_X_keysym[0]));
   698         -  unsigned keysym;
   699         -  for (keysym = 0; keysym < last_keysym; keysym += 2)
   700         -    if (code == convert_ns_to_X_keysym[keysym])
   701         -      return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
   702         -  return 0;
   703         - }
          734  +    unsigned keysym;
          735  +    for (keysym = 0; keysym < last_keysym; keysym += 2) {
          736  +	if (code == convert_ns_to_X_keysym[keysym]) {
          737  +	    return 0xFF00 | convert_ns_to_X_keysym[keysym+1];
          738  +	}
          739  +    }
          740  +    return 0;
          741  +}
   704    742   
   705    743   /*
   706    744    * Local Variables:
   707    745    * mode: objc
   708    746    * c-basic-offset: 4
   709    747    * fill-column: 79
   710    748    * coding: utf-8
   711    749    * End:
   712    750    */

Changes to macosx/tkMacOSXMenu.c.

   189    189       [super insertItem:newItem atIndex:index + _tkOffset];
   190    190       _tkItemCount++;
   191    191   }
   192    192   
   193    193   - (void) insertItem: (NSMenuItem *) newItem atIndex: (NSInteger) index
   194    194   {
   195    195       if (_tkMenu && index >= 0) {
   196         -	if ((NSUInteger)index <= _tkOffset) {
          196  +	if ((NSUInteger) index <= _tkOffset) {
   197    197   	    _tkOffset++;
   198    198   	} else {
   199         -	    NSAssert((NSUInteger)index >= _tkItemCount + _tkOffset,
          199  +	    NSAssert((NSUInteger) index >= _tkItemCount + _tkOffset,
   200    200   		    @"Cannot insert in the middle of Tk menu");
   201    201   	}
   202    202       }
   203    203       [super insertItem:newItem atIndex:index];
   204    204   }
   205    205   
   206    206   - (void) removeItemAtIndex: (NSInteger) index
   207    207   {
   208    208       if (_tkMenu && index >= 0) {
   209         -	if ((NSUInteger)index < _tkOffset) {
          209  +	if ((NSUInteger) index < _tkOffset) {
   210    210   	    _tkOffset--;
   211         -	} else if ((NSUInteger)index < _tkItemCount + _tkOffset) {
          211  +	} else if ((NSUInteger) index < _tkItemCount + _tkOffset) {
   212    212   	    _tkItemCount--;
   213    213   	}
   214    214       }
   215    215       [super removeItemAtIndex:index];
   216    216   }
   217    217   
   218    218   - (NSMenuItem *) newTkMenuItem: (TkMenuEntry *) mePtr
   219    219   {
   220    220       NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@""
   221    221   	    action:@selector(tkMenuItemInvoke:) keyEquivalent:@""];
   222    222   
   223    223       [menuItem setTarget:self];
   224         -    [menuItem setTag:(NSInteger)mePtr];
          224  +    [menuItem setTag:(NSInteger) mePtr];
   225    225       return menuItem;
   226    226   }
   227    227   @end
   228    228   
   229    229   @implementation TKMenu(TKMenuActions)
   230    230   
   231    231   - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
................................................................................
   248    248        * With the delegate matching key equivalents, when a menu action is sent
   249    249        * in response to a key equivalent, the sender is the whole menu and not the
   250    250        * specific menu item.  We use this to ignore key equivalents for Tk
   251    251        * menus (as Tk handles them directly via bindings).
   252    252        */
   253    253   
   254    254       if ([sender isKindOfClass:[NSMenuItem class]]) {
   255         -	NSMenuItem *menuItem = (NSMenuItem *)sender;
   256         -	TkMenu *menuPtr = (TkMenu *)_tkMenu;
   257         -	TkMenuEntry *mePtr = (TkMenuEntry *)[menuItem tag];
          255  +	NSMenuItem *menuItem = (NSMenuItem *) sender;
          256  +	TkMenu *menuPtr = (TkMenu *) _tkMenu;
          257  +	TkMenuEntry *mePtr = (TkMenuEntry *) [menuItem tag];
   258    258   
   259    259   	if (menuPtr && mePtr) {
   260    260   	    Tcl_Interp *interp = menuPtr->interp;
   261    261   
   262         -	    /*Add time for errors to fire if necessary. This is sub-optimal
   263         -	     *but avoids issues with Tcl/Cocoa event loop integration.
          262  +	    /*
          263  +	     * Add time for errors to fire if necessary. This is sub-optimal
          264  +	     * but avoids issues with Tcl/Cocoa event loop integration.
   264    265   	     */
   265    266   
   266    267   	    //Tcl_Sleep(100);
   267    268   	    Tcl_Preserve(interp);
   268    269   	    Tcl_Preserve(menuPtr);
   269    270   
   270    271   	    int result = TkInvokeMenu(interp, menuPtr, mePtr->index);
................................................................................
   301    302   	 * Command-Shift-? has not been allowed as a keyboard equivalent since
   302    303   	 * the first aqua port, for some mysterious reason.
   303    304   	 */
   304    305   
   305    306   	return NO;
   306    307       } else if (modifiers == (NSControlKeyMask | NSShiftKeyMask) &&
   307    308   	    [event keyCode] == 48) {
   308         -
   309         -	/* Starting with OSX 10.12 Control-Tab and Control-Shift-Tab are used
          309  +	/*
          310  +	 * Starting with OSX 10.12 Control-Tab and Control-Shift-Tab are used
   310    311   	 * to select window tabs.  But for some even more mysterious reason the
   311    312   	 * Control-Shift-Tab event has character 0x19 = NSBackTabCharacter
   312    313   	 * rather than 0x09 = NSTabCharacter.  At the same time, the
   313    314   	 * keyEquivalent must be \0x09 in order for it to be displayed
   314    315   	 * correctly in the menu. This makes it impossible for the standard
   315    316   	 * "Select Previous Tab" to work correctly, unless we intervene.
   316    317   	 */
   317    318   
   318    319   	key = @"\t";
   319    320       } else if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) {
   320         -
   321    321   	/*
   322    322   	 * If the command modifier is set, use the full character string so
   323    323   	 * things like the dvorak / qwerty layout will work.
   324    324   	 */
   325    325   
   326    326   	key = [event characters];
   327    327       }
................................................................................
   646    646   	attributes = TkMacOSXNSFontAttributesForFont(Tk_GetFontFromObj(
   647    647   		mePtr->menuPtr->tkwin, fontPtr));
   648    648   	if (gc->foreground != defaultFg || gc->background != defaultBg) {
   649    649   	    NSColor *color = TkMacOSXGetNSColor(gc,
   650    650   		    gc->foreground!=defaultFg? gc->foreground:gc->background);
   651    651   
   652    652   	    attributes = [[attributes mutableCopy] autorelease];
   653         -	    [(NSMutableDictionary *)attributes setObject:color
          653  +	    [(NSMutableDictionary *) attributes setObject:color
   654    654   		    forKey:NSForegroundColorAttributeName];
   655    655   	}
   656    656   	if (attributes) {
   657    657   	    attributedTitle = [[[NSAttributedString alloc]
   658    658   		    initWithString:title attributes:attributes] autorelease];
   659    659   	}
   660    660       }
................................................................................
   686    686   		 */
   687    687   
   688    688   		submenu = nil;
   689    689   	    } else {
   690    690   		[submenu setTitle:title];
   691    691   
   692    692       		if ([menuItem isEnabled]) {
   693         -		  /* This menuItem might have been previously disabled (XXX:
   694         -		     track this), which would have disabled entries; we must
   695         -		     re-enable the entries here. */
   696         -		  int i = 0;
   697         -		  NSArray *itemArray = [submenu itemArray];
   698         -		  for (NSMenuItem *item in itemArray) {
   699         -		    TkMenuEntry *submePtr = menuRefPtr->menuPtr->entries[i];
   700         -		    /* Work around an apparent bug where itemArray can have
   701         -                      more items than the menu's entries[] array. */
   702         -                    if (i >= menuRefPtr->menuPtr->numEntries) break;
   703         -		    [item setEnabled: !(submePtr->state == ENTRY_DISABLED)];
   704         -		    i++;
   705         -		  }
          693  +		    
          694  +		    /* This menuItem might have been previously disabled (XXX:
          695  +		     * track this), which would have disabled entries; we must
          696  +		     * re-enable the entries here.
          697  +		     */
          698  +
          699  +		    int i = 0;
          700  +		    NSArray *itemArray = [submenu itemArray];
          701  +		    for (NSMenuItem *item in itemArray) {
          702  +			TkMenuEntry *submePtr = menuRefPtr->menuPtr->entries[i];
          703  +
          704  +			/* Work around an apparent bug where itemArray can have
          705  +			 * more items than the menu's entries[] array.
          706  +			 */
          707  +
          708  +			if (i >= menuRefPtr->menuPtr->numEntries) break;
          709  +			[item setEnabled: !(submePtr->state == ENTRY_DISABLED)];
          710  +			i++;
          711  +		    }
   706    712   		}
   707         -
   708    713   	    }
   709    714   	}
   710    715       }
   711    716       [menuItem setSubmenu:submenu];
   712    717   
   713    718       return TCL_OK;
   714    719   }
................................................................................
   751    756   }
   752    757   
   753    758   /*
   754    759    *----------------------------------------------------------------------
   755    760    *
   756    761    * TkpPostMenu --
   757    762    *
   758         - *	Posts a menu on the screen. If entry is < 0 then the menu is
   759         - *      drawn so its top left corner is located at the point with
   760         - *      screen coordinates (x, y).  Otherwise the top left corner of
   761         - *      the specified entry is located at that point.
          763  + *	Posts a menu on the screen. If entry is < 0 then the menu is drawn so
          764  + *      its top left corner is located at the point with screen coordinates
          765  + *      (x,y).  Otherwise the top left corner of the specified entry is located
          766  + *      at that point.
   762    767    *
   763    768    * Results:
   764    769    *	Returns a standard Tcl result.
   765    770    *
   766    771    * Side effects:
   767    772    *	The menu is posted and handled.
   768    773    *
................................................................................
   824    829   }
   825    830   
   826    831   /*
   827    832    *----------------------------------------------------------------------
   828    833    *
   829    834    * TkpPostTearoffMenu --
   830    835    *
   831         - *	Tearoff menus are not supported on the Mac.  This placeholder
   832         - *      function, which is simply a copy of the unix function, posts a
   833         - *      completely useless window with a black background on the screen. If
   834         - *      entry is < 0 then the window is positioned so that its top left corner
   835         - *      is located at the point with screen coordinates (x, y).  Otherwise the
   836         - *      window position is offset so that top left corner of the specified
   837         - *      entry would be located at that point, if there actually were a menu.
          836  + *	Tearoff menus are not supported on the Mac.  This placeholder function,
          837  + *      which is simply a copy of the unix function, posts a completely useless
          838  + *      window with a black background on the screen. If entry is < 0 then the
          839  + *      window is positioned so that its top left corner is located at the
          840  + *      point with screen coordinates (x, y).  Otherwise the window position is
          841  + *      offset so that top left corner of the specified entry would be located
          842  + *      at that point, if there actually were a menu.
   838    843    *
   839    844    *      Mac menus steal all mouse or keyboard input from the application until
   840    845    *      the menu is dismissed, with or without a selection, by a mouse or key
   841    846    *      event.  Posting a Mac menu in a regression test will cause the test to
   842    847    *      halt waiting for user input.  This is why the TkpPostMenu function is
   843    848    *      not being used as the placeholder.
   844    849    *
................................................................................
   858    863       int x, int y, int index)	/* The screen coordinates where the top left
   859    864   				 * corner of the menu, or of the specified
   860    865   				 * entry, will be located. */
   861    866   {
   862    867       int vRootX, vRootY, vRootWidth, vRootHeight;
   863    868       int result;
   864    869   
   865         -    if (index >= menuPtr->numEntries) {
          870  +    if (index >= (int) menuPtr->numEntries) {
   866    871   	index = menuPtr->numEntries - 1;
   867    872       }
   868    873       if (index >= 0) {
   869    874   	y -= menuPtr->entries[index]->y;
   870    875       }
   871    876   
   872    877       TkActivateMenuEntry(menuPtr, -1);
................................................................................
   956    961   }
   957    962   
   958    963   /*
   959    964    *----------------------------------------------------------------------
   960    965    *
   961    966    * TkpSetMainMenubar --
   962    967    *
   963         - *	Puts the menu associated with a window into the menubar. Should only
   964         - *	be called when the window is in front.
          968  + *	Puts the menu associated with a window into the menubar. Should only be
          969  + *	called when the window is in front.
   965    970    *
   966    971    *      This is a no-op on all other platforms.  On OS X it is a no-op when
   967         - *      passed a NULL menuName or a nonexistent menuName, with an exception
   968         - *      for the first call in a new interpreter.  In that special case, passing a
          972  + *      passed a NULL menuName or a nonexistent menuName, with an exception for
          973  + *      the first call in a new interpreter.  In that special case, passing a
   969    974    *      NULL menuName installs the default menu.
   970    975    *
   971    976    * Results:
   972    977    *	None.
   973    978    *
   974    979    * Side effects:
   975    980    *	The menubar may be changed.
................................................................................
   989    994   
   990    995       /*
   991    996        * We will be called when an embedded window receives an ActivationNotify
   992    997        * event, but we should not change the menubar in that case.
   993    998        */
   994    999   
   995   1000       if (Tk_IsEmbedded(winPtr)) {
   996         -	    return;
   997         -	}
         1001  +	return;
         1002  +    }
   998   1003   
   999   1004       if (menuName) {
  1000   1005   	Tk_Window menubar = NULL;
         1006  +
  1001   1007   	if (winPtr->wmInfoPtr &&
  1002   1008   	    winPtr->wmInfoPtr->menuPtr &&
  1003   1009   	    winPtr->wmInfoPtr->menuPtr->masterMenuPtr) {
  1004   1010   	    menubar = winPtr->wmInfoPtr->menuPtr->masterMenuPtr->tkwin;
  1005   1011   	}
  1006   1012   
  1007   1013   	/*
  1008         -	 * Attempt to find the NSMenu directly.  If that fails, ask Tk to find it.
         1014  +	 * Attempt to find the NSMenu directly.  If that fails, ask Tk to find
         1015  +	 * it.
  1009   1016   	 */
  1010   1017   
  1011   1018   	if (menubar != NULL && strcmp(menuName, Tk_PathName(menubar)) == 0) {
  1012   1019   	    menu = (TKMenu *) winPtr->wmInfoPtr->menuPtr->platformData;
  1013   1020   	} else {
  1014   1021   	    TkMenuReferences *menuRefPtr = TkFindMenuReferences(interp,
  1015   1022   		    menuName);
         1023  +
  1016   1024   	    if (menuRefPtr && menuRefPtr->menuPtr &&
  1017   1025   		    menuRefPtr->menuPtr->platformData) {
  1018   1026   		menu = (TKMenu *) menuRefPtr->menuPtr->platformData;
  1019   1027   	    }
  1020   1028   	}
  1021   1029       }
  1022   1030   
  1023   1031       /*
  1024         -     * If we couldn't find a menu, do nothing unless the window belongs
  1025         -     * to a different application.  In that case, install the default
  1026         -     * menubar.
         1032  +     * If we couldn't find a menu, do nothing unless the window belongs to a
         1033  +     * different application.  In that case, install the default menubar.
  1027   1034        */
  1028   1035       
  1029   1036       if (menu || interp != currentInterp) {
  1030   1037   	[NSApp tkSetMainMenu:menu];
  1031   1038       }
  1032   1039       currentInterp = interp;
  1033   1040   }
................................................................................
  1034   1041   
  1035   1042   /*
  1036   1043    *----------------------------------------------------------------------
  1037   1044    *
  1038   1045    * CheckForSpecialMenu --
  1039   1046    *
  1040   1047    *	Given a menu, check to see whether or not it is a cascade in a menubar
  1041         - *	with one of the special names ".apple", ".help" or ".window".  If it
  1042         - *	is, the entry that points to this menu will be marked.
         1048  + *	with one of the special names ".apple", ".help" or ".window". If it is,
         1049  + *	the entry that points to this menu will be marked.
  1043   1050    *
  1044   1051    * Results:
  1045   1052    *	None.
  1046   1053    *
  1047   1054    * Side effects:
  1048   1055    *	Will set entryFlags appropriately.
  1049   1056    *
................................................................................
  1226   1233       int entryWidth, maxIndicatorSpace, borderWidth, activeBorderWidth;
  1227   1234       TkMenuEntry *mePtr;
  1228   1235       int haveAccel = 0;
  1229   1236   
  1230   1237       /*
  1231   1238        * Do nothing if this menu is a clone.
  1232   1239        */
         1240  +
  1233   1241       if (menuPtr->tkwin == NULL || menuPtr->masterMenuPtr != menuPtr) {
  1234   1242   	return;
  1235   1243       }
  1236   1244       
  1237         -    menuSize = [(NSMenu *)menuPtr->platformData size];
         1245  +    menuSize = [(NSMenu *) menuPtr->platformData size];
  1238   1246       Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
  1239   1247   	    &borderWidth);
  1240   1248       Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr,
  1241   1249   	    &activeBorderWidth);
  1242   1250       x = y = borderWidth;
  1243   1251       windowHeight = maxWidth = 0;
  1244   1252       maxIndicatorSpace = 0;
  1245   1253   
  1246   1254       /*
  1247   1255        * On the Mac especially, getting font metrics can be quite slow, so we
  1248   1256        * want to do it intelligently. We are going to precalculate them and pass
  1249   1257        * them down to all of the measuring and drawing routines. We will measure
  1250   1258        * the font metrics of the menu once. If an entry does not have its own
  1251         -     * font set, then we give the geometry/drawing routines the menu's font
  1252         -     * and metrics. If an entry has its own font, we will measure that font
  1253         -     * and give all of the geometry/drawing the entry's font and metrics.
         1259  +     * font set, then we give the geometry/drawing routines the menu's font and
         1260  +     * metrics. If an entry has its own font, we will measure that font and
         1261  +     * give all of the geometry/drawing the entry's font and metrics.
  1254   1262        */
  1255   1263   
  1256   1264       menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr);
  1257   1265       Tk_GetFontMetrics(menuFont, &menuMetrics);
  1258   1266       menuModifierCharWidth = ModifierCharWidth(menuFont);
  1259   1267   
  1260         -    for (i = 0; i < menuPtr->numEntries; i++) {
         1268  +    for (i = 0; i < (int) menuPtr->numEntries; i++) {
  1261   1269   	mePtr = menuPtr->entries[i];
  1262   1270   	if (mePtr->type == CASCADE_ENTRY || mePtr->accelLength > 0) {
  1263   1271   	    haveAccel = 1;
  1264   1272   	    break;
  1265   1273   	}
  1266   1274       }
  1267   1275   
  1268         -    for (i = 0; i < menuPtr->numEntries; i++) {
         1276  +    for (i = 0; i < (int) menuPtr->numEntries; i++) {
  1269   1277   	mePtr = menuPtr->entries[i];
  1270   1278   	if (mePtr->type == TEAROFF_ENTRY) {
  1271   1279   	    continue;
  1272   1280   	}
  1273   1281   	if (mePtr->fontPtr == NULL) {
  1274   1282   	    tkfont = menuFont;
  1275   1283   	    fmPtr = &menuMetrics;
................................................................................
  1291   1299   	     * (if any), and the width of the accelerator to be displayed to
  1292   1300   	     * the right of the label (if any). These sizes depend, of course,
  1293   1301   	     * on the type of the entry.
  1294   1302   	     */
  1295   1303   
  1296   1304   	    NSMenuItem *menuItem = (NSMenuItem *) mePtr->platformEntryData;
  1297   1305   	    int haveImage = 0, width = 0, height = 0;
         1306  +
  1298   1307   	    if (mePtr->image) {
  1299   1308   		Tk_SizeOfImage(mePtr->image, &width, &height);
  1300   1309   		haveImage = 1;
  1301   1310   		height += 2; /* tweak */
  1302   1311   	    } else if (mePtr->bitmapPtr) {
  1303   1312   		Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin,
  1304   1313   			mePtr->bitmapPtr);
         1314  +
  1305   1315   		Tk_SizeOfBitmap(menuPtr->display, bitmap, &width, &height);
  1306   1316   		haveImage = 1;
  1307   1317   		height += 2; /* tweak */
  1308   1318   	    }
  1309   1319   	    if (!haveImage || (mePtr->compound != COMPOUND_NONE)) {
  1310   1320   		NSAttributedString *attrTitle = [menuItem attributedTitle];
  1311   1321   		NSSize size;
................................................................................
  1409   1419       NSMenuItem *menuItem)
  1410   1420   {
  1411   1421       TkMenu *menuPtr = [menu tkMenu];
  1412   1422   
  1413   1423       if (menuPtr) {
  1414   1424   	int index = [menu tkIndexOfItem:menuItem];
  1415   1425   
  1416         -	if (index < 0 || index >= menuPtr->numEntries ||
         1426  +	if (index < 0 || index >= (int) menuPtr->numEntries ||
  1417   1427   		(menuPtr->entries[index])->state == ENTRY_DISABLED) {
  1418   1428   	    TkActivateMenuEntry(menuPtr, -1);
  1419   1429   	} else {
  1420   1430   	    TkActivateMenuEntry(menuPtr, index);
  1421   1431   	    MenuSelectEvent(menuPtr);
  1422   1432   	    return true;
  1423   1433   	}
................................................................................
  1488   1498   void
  1489   1499   RecursivelyClearActiveMenu(
  1490   1500       TkMenu *menuPtr)		/* The menu to reset. */
  1491   1501   {
  1492   1502       int i;
  1493   1503   
  1494   1504       TkActivateMenuEntry(menuPtr, -1);
  1495         -    for (i = 0; i < menuPtr->numEntries; i++) {
         1505  +    for (i = 0; i < (int) menuPtr->numEntries; i++) {
  1496   1506   	TkMenuEntry *mePtr = menuPtr->entries[i];
  1497   1507   
  1498   1508   	if (mePtr->type == CASCADE_ENTRY
  1499   1509   		&& (mePtr->childMenuRefPtr != NULL)
  1500   1510   		&& (mePtr->childMenuRefPtr->menuPtr != NULL)) {
  1501   1511   	    RecursivelyClearActiveMenu(mePtr->childMenuRefPtr->menuPtr);
  1502   1512   	}
................................................................................
  1777   1787   
  1778   1788   /*
  1779   1789    *----------------------------------------------------------------------
  1780   1790    *
  1781   1791    * TkMacOSXUseID --
  1782   1792    *
  1783   1793    *	Take the ID out of the available list for new menus. Used by the
  1784         - *	default menu bar's menus so that they do not get created at the tk
         1794  + *	default menu bar's menus so that they do not get created at the Tk
  1785   1795    *	level. See TkMacOSXGetNewMenuID for more information.
  1786   1796    *
  1787   1797    * Results:
  1788   1798    *	Returns TCL_OK if the id was not in use. Returns TCL_ERROR if the id
  1789   1799    *	was in use.
  1790   1800    *
  1791   1801    * Side effects:
................................................................................
  1802   1812   }
  1803   1813   
  1804   1814   /*
  1805   1815    *----------------------------------------------------------------------
  1806   1816    *
  1807   1817    * TkMacOSXDispatchMenuEvent --
  1808   1818    *
  1809         - *	Given a menu id and an item, dispatches the command associated with
  1810         - *	it.
         1819  + *	Given a menu id and an item, dispatches the command associated with it.
  1811   1820    *
  1812   1821    * Results:
  1813   1822    *	None.
  1814   1823    *
  1815   1824    * Side effects:
  1816   1825    *	Commands for the event are scheduled for execution at idle time.
  1817   1826    *
................................................................................
  1853   1862   }
  1854   1863   
  1855   1864   /*
  1856   1865    *----------------------------------------------------------------------
  1857   1866    *
  1858   1867    * TkMacOSXSetHelpMenuItemCount --
  1859   1868    *
  1860         - *	Has to be called after the first call to InsertMenu. Sets up the
  1861         - *	global variable for the number of items in the unmodified help menu.
  1862         - *	NB. Nobody uses this any more, since you can get the number of system
         1869  + *	Has to be called after the first call to InsertMenu. Sets up the global
         1870  + *	variable for the number of items in the unmodified help menu.
         1871  + *
         1872  + *	NB: Nobody uses this any more, since you can get the number of system
  1863   1873    *	help items from HMGetHelpMenu trivially. But it is in the stubs
  1864   1874    *	table...
  1865   1875    *
  1866   1876    * Results:
  1867   1877    *	None.
  1868   1878    *
  1869   1879    * Side effects:

Changes to macosx/tkMacOSXMenubutton.c.

     1      1   /*
     2      2    * tkMacOSXMenubutton.c --
     3      3    *
     4         - *	This file implements the Macintosh specific portion of the
     5         - *	menubutton widget.
            4  + *	This file implements the Macintosh specific portion of the menubutton
            5  + *	widget.
     6      6    *
     7      7    * Copyright (c) 1996 by Sun Microsystems, Inc.
     8      8    * Copyright 2001, Apple Computer, Inc.
     9      9    * Copyright (c) 2006-2007 Daniel A. Steffen <[email protected]>
    10     10    * Copyright 2007 Revar Desmera.
    11     11    * Copyright 2015 Kevin Walzer/WordTech Communications LLC.
    12     12    *
................................................................................
    28     28   typedef struct {
    29     29       Tk_3DBorder border;
    30     30       int relief;
    31     31       GC gc;
    32     32       int hasImageOrBitmap;
    33     33   } DrawParams;
    34     34   
    35         -
    36     35   /*
    37     36    * Declaration of Mac specific button structure.
    38     37    */
    39     38   
    40     39   typedef struct MacMenuButton {
    41     40       TkMenuButton info;		/* Generic button info. */
    42     41       int flags;
................................................................................
    46     45       DrawParams drawParams;
    47     46   } MacMenuButton;
    48     47   
    49     48   /*
    50     49    * Forward declarations for static functions defined later in this file:
    51     50    */
    52     51   
    53         -static void MenuButtonEventProc(ClientData clientData, XEvent *eventPtr);
    54         -static void MenuButtonBackgroundDrawCB (MacMenuButton *ptr, SInt16 depth,
    55         -					Boolean isColorDev);
    56         -static void MenuButtonContentDrawCB (ThemeButtonKind kind,
    57         -				     const HIThemeButtonDrawInfo * info,
    58         -				     MacMenuButton *ptr, SInt16 depth,
    59         -				     Boolean isColorDev);
    60         -static void MenuButtonEventProc ( ClientData clientData, XEvent *eventPtr);
    61         -static void TkMacOSXComputeMenuButtonParams (TkMenuButton * butPtr,
    62         -					     ThemeButtonKind* btnkind,
    63         -					     HIThemeButtonDrawInfo* drawinfo);
    64         -static void TkMacOSXComputeMenuButtonDrawParams (TkMenuButton * butPtr,
    65         -						 DrawParams * dpPtr);
    66         -static void TkMacOSXDrawMenuButton (MacMenuButton *butPtr, GC gc, Pixmap pixmap);
    67         -static void DrawMenuButtonImageAndText(TkMenuButton* butPtr);
           52  +static void		MenuButtonEventProc(ClientData clientData,
           53  +			    XEvent *eventPtr);
           54  +static void		MenuButtonBackgroundDrawCB(MacMenuButton *ptr,
           55  +			    SInt16 depth, Boolean isColorDev);
           56  +static void		MenuButtonContentDrawCB(ThemeButtonKind kind,
           57  +			    const HIThemeButtonDrawInfo *info,
           58  +			    MacMenuButton *ptr, SInt16 depth,
           59  +			    Boolean isColorDev);
           60  +static void		MenuButtonEventProc(ClientData clientData,
           61  +			    XEvent *eventPtr);
           62  +static void		TkMacOSXComputeMenuButtonParams(TkMenuButton *butPtr,
           63  +			    ThemeButtonKind *btnkind,
           64  +			    HIThemeButtonDrawInfo *drawinfo);
           65  +static void		TkMacOSXComputeMenuButtonDrawParams(
           66  +			    TkMenuButton *butPtr, DrawParams *dpPtr);
           67  +static void		TkMacOSXDrawMenuButton(MacMenuButton *butPtr, GC gc,
           68  +			    Pixmap pixmap);
           69  +static void		DrawMenuButtonImageAndText(TkMenuButton *butPtr);
    68     70   
    69     71   /*
    70     72    * The structure below defines menubutton class behavior by means of
    71     73    * procedures that can be invoked from generic window code.
    72     74    */
    73     75   
    74     76   Tk_ClassProcs tkpMenubuttonClass = {
................................................................................
   129    131   
   130    132   TkMenuButton *
   131    133   TkpCreateMenuButton(
   132    134       Tk_Window tkwin)
   133    135   {
   134    136       MacMenuButton *mbPtr = (MacMenuButton *) ckalloc(sizeof(MacMenuButton));
   135    137   
   136         -    Tk_CreateEventHandler(tkwin, ActivateMask, MenuButtonEventProc,
   137         -			  (ClientData) mbPtr);
          138  +    Tk_CreateEventHandler(tkwin, ActivateMask, MenuButtonEventProc, mbPtr);
   138    139       mbPtr->flags = FIRST_DRAW;
   139    140       mbPtr->btnkind = kThemePopupButton;
   140    141       bzero(&mbPtr->drawinfo, sizeof(mbPtr->drawinfo));
   141    142       bzero(&mbPtr->lastdrawinfo, sizeof(mbPtr->lastdrawinfo));
   142    143       return (TkMenuButton *) mbPtr;
   143    144   }
   144    145   
................................................................................
   149    150    *
   150    151    *	This procedure is invoked to display a menubutton widget.
   151    152    *
   152    153    * Results:
   153    154    *	None.
   154    155    *
   155    156    * Side effects:
   156         - *	Commands are output to X to display the menubutton in its
   157         - *	current mode.
          157  + *	Commands are output to X to display the menubutton in its current mode.
   158    158    *
   159    159    *----------------------------------------------------------------------
   160    160    */
   161    161   
   162    162   void
   163    163   TkpDisplayMenuButton(
   164    164       ClientData clientData)	/* Information about widget. */
   165    165   {
   166         -    MacMenuButton *mbPtr    = (MacMenuButton *)clientData;
   167         -    TkMenuButton  *butPtr   = (TkMenuButton *) clientData;
   168         -    Tk_Window tkwin         = butPtr->tkwin;
          166  +    MacMenuButton *mbPtr = clientData;
          167  +    TkMenuButton *butPtr = clientData;
          168  +    Tk_Window tkwin = butPtr->tkwin;
   169    169       Pixmap pixmap;
   170         -    DrawParams* dpPtr = &mbPtr->drawParams;
          170  +    DrawParams *dpPtr = &mbPtr->drawParams;
   171    171   
   172    172       butPtr->flags &= ~REDRAW_PENDING;
   173    173       if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
   174    174           return;
   175    175       }
   176    176   
   177    177       pixmap = (Pixmap) Tk_WindowId(tkwin);
   178    178   
   179    179       TkMacOSXComputeMenuButtonDrawParams(butPtr, dpPtr);
   180    180   
   181    181       /*
   182         -     * set up clipping region.  Make sure the we are using the port
   183         -     * for this button, or we will set the wrong window's clip.
          182  +     * Set up clipping region.  Make sure the we are using the port for this
          183  +     * button, or we will set the wrong window's clip.
   184    184        */
   185    185   
   186    186       TkMacOSXSetUpClippingRgn(pixmap);
   187    187   
   188         -    /* Draw the native portion of the buttons. */
          188  +    /*
          189  +     * Draw the native portion of the buttons.
          190  +     */
          191  +
   189    192       TkMacOSXDrawMenuButton(mbPtr,  dpPtr->gc, pixmap);
   190    193   
   191         -    /* Draw highlight border, if needed. */
   192         -    if (butPtr->highlightWidth < 3) {
   193         -        if ((butPtr->flags & GOT_FOCUS)) {
   194         -            Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
          194  +    /*
          195  +     * Draw highlight border, if needed.
          196  +     */
          197  +
          198  +    if ((butPtr->highlightWidth < 3) && (butPtr->flags & GOT_FOCUS)) {
          199  +	Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
   195    200                   Tk_Width(tkwin), Tk_Height(tkwin),
   196    201                   butPtr->highlightWidth, TK_RELIEF_SOLID);
   197         -        }
   198    202       }
   199    203   }
   200    204   
   201    205   /*
   202    206    *----------------------------------------------------------------------
   203    207    *
   204    208    * TkpDestroyMenuButton --
   205    209    *
   206         - *	Free data structures associated with the menubutton control.
   207         - *      This is a no-op on the Mac.
          210  + *	Free data structures associated with the menubutton control. This is a
          211  + *      no-op on the Mac.
   208    212    *
   209    213    * Results:
   210    214    *	None.
   211    215    *
   212    216    * Side effects:
   213    217    *	None.
   214    218    *
................................................................................
   275    279           txtWidth = butPtr->textWidth;
   276    280           txtHeight = butPtr->textHeight;
   277    281           avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
   278    282           Tk_GetFontMetrics(butPtr->tkfont, &fm);
   279    283       }
   280    284   
   281    285       /*
   282         -     * If the button is compound (ie, it shows both an image and text),
   283         -     * the new geometry is a combination of the image and text geometry.
   284         -     * We only honor the compound bit if the button has both text and an
   285         -     * image, because otherwise it is not really a compound button.
          286  +     * If the button is compound (ie, it shows both an image and text), the new
          287  +     * geometry is a combination of the image and text geometry. We only honor
          288  +     * the compound bit if the button has both text and an image, because
          289  +     * otherwise it is not really a compound button.
   286    290        */
   287    291   
   288    292       if (haveImage && haveText) {
   289    293           switch ((enum compound) butPtr->compound) {
   290         -            case COMPOUND_TOP:
   291         -            case COMPOUND_BOTTOM: {
   292         -                /*
   293         -                 * Image is above or below text
   294         -                 */
   295         -
   296         -                height += txtHeight + butPtr->padY;
   297         -                width = (width > txtWidth ? width : txtWidth);
   298         -                break;
   299         -            }
   300         -            case COMPOUND_LEFT:
   301         -            case COMPOUND_RIGHT: {
   302         -                /*
   303         -                 * Image is left or right of text
   304         -                 */
   305         -
   306         -                width += txtWidth + butPtr->padX;
   307         -                height = (height > txtHeight ? height : txtHeight);
   308         -                break;
   309         -            }
   310         -            case COMPOUND_CENTER: {
   311         -                /*
   312         -                 * Image and text are superimposed
   313         -                 */
   314         -
   315         -                width = (width > txtWidth ? width : txtWidth);
   316         -                height = (height > txtHeight ? height : txtHeight);
   317         -                break;
   318         -            }
   319         -            case COMPOUND_NONE: {break;}
          294  +	case COMPOUND_TOP:
          295  +	case COMPOUND_BOTTOM:
          296  +	    /*
          297  +	     * Image is above or below text
          298  +	     */
          299  +
          300  +	    height += txtHeight + butPtr->padY;
          301  +	    width = (width > txtWidth ? width : txtWidth);
          302  +	    break;
          303  +	case COMPOUND_LEFT:
          304  +	case COMPOUND_RIGHT:
          305  +	    /*
          306  +	     * Image is left or right of text
          307  +	     */
          308  +
          309  +	    width += txtWidth + butPtr->padX;
          310  +	    height = (height > txtHeight ? height : txtHeight);
          311  +	    break;
          312  +	case COMPOUND_CENTER:
          313  +	    /*
          314  +	     * Image and text are superimposed
          315  +	     */
          316  +
          317  +	    width = (width > txtWidth ? width : txtWidth);
          318  +	    height = (height > txtHeight ? height : txtHeight);
          319  +	    break;
          320  +	case COMPOUND_NONE:
          321  +	    break;
   320    322           }
   321    323   
   322    324           if (butPtr->width > 0) {
   323    325               width = butPtr->width;
   324    326           }
   325    327           if (butPtr->height > 0) {
   326    328               height = butPtr->height;
................................................................................
   367    369    * Side effects:
   368    370    *        The image and text are drawn.
   369    371    *
   370    372    *----------------------------------------------------------------------
   371    373    */
   372    374   void
   373    375   DrawMenuButtonImageAndText(
   374         -    TkMenuButton* butPtr)
          376  +    TkMenuButton *butPtr)
   375    377   {
   376         -    MacMenuButton *mbPtr = (MacMenuButton*)butPtr;
   377         -    Tk_Window  tkwin  = butPtr->tkwin;
   378         -    Pixmap     pixmap;
   379         -    int        haveImage = 0;
   380         -    int        haveText = 0;
   381         -    int        imageWidth = 0;
   382         -    int        imageHeight = 0;
   383         -    int        imageXOffset = 0;
   384         -    int        imageYOffset = 0;
   385         -    int        textXOffset = 0;
   386         -    int        textYOffset = 0;
   387         -    int        width = 0;
   388         -    int        height = 0;
   389         -    int        fullWidth = 0;
   390         -    int        fullHeight = 0;
   391         -    int        pressed;
          378  +    MacMenuButton *mbPtr = (MacMenuButton *) butPtr;
          379  +    Tk_Window tkwin  = butPtr->tkwin;
          380  +    Pixmap pixmap;
          381  +    int haveImage = 0, haveText = 0;
          382  +    int imageWidth = 0, imageHeight = 0;
          383  +    int imageXOffset = 0, imageYOffset = 0;
          384  +    int textXOffset = 0, textYOffset = 0;
          385  +    int width = 0, height = 0;
          386  +    int fullWidth = 0, fullHeight = 0;
   392    387   
   393    388       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   394    389           return;
   395    390       }
   396    391   
   397         -    DrawParams* dpPtr = &mbPtr->drawParams;
   398         -    pixmap = (Pixmap)Tk_WindowId(tkwin);
   399         -
          392  +    DrawParams *dpPtr = &mbPtr->drawParams;
          393  +    pixmap = (Pixmap) Tk_WindowId(tkwin);
   400    394   
   401    395       if (butPtr->image != None) {
   402    396           Tk_SizeOfImage(butPtr->image, &width, &height);
   403    397           haveImage = 1;
   404    398       } else if (butPtr->bitmap != None) {
   405    399           Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
   406    400           haveImage = 1;
   407    401       }
   408    402   
   409         -    imageWidth  = width;
          403  +    imageWidth = width;
   410    404       imageHeight = height;
   411    405   
   412         -    if (mbPtr->drawinfo.state == kThemeStatePressed) {
   413         -        /* Offset bitmaps by a bit when the button is pressed. */
   414         -        pressed = 1;
   415         -    }
   416         -
   417    406       haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
   418    407       if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
   419         -        int x = 0;
   420         -        int y = 0;
          408  +        int x = 0, y = 0;
          409  +
   421    410           textXOffset = 0;
   422    411           textYOffset = 0;
   423    412           fullWidth = 0;
   424    413           fullHeight = 0;
   425    414   
   426    415           switch ((enum compound) butPtr->compound) {
   427         -            case COMPOUND_TOP:
   428         -            case COMPOUND_BOTTOM: {
   429         -                /* Image is above or below text */
   430         -                if (butPtr->compound == COMPOUND_TOP) {
   431         -                    textYOffset = height + butPtr->padY;
   432         -                } else {
   433         -                    imageYOffset = butPtr->textHeight + butPtr->padY;
   434         -                }
   435         -                fullHeight = height + butPtr->textHeight + butPtr->padY;
   436         -                fullWidth = (width > butPtr->textWidth ?
   437         -			     width : butPtr->textWidth);
   438         -                textXOffset = (fullWidth - butPtr->textWidth)/2;
   439         -                imageXOffset = (fullWidth - width)/2;
   440         -                break;
   441         -            }
   442         -            case COMPOUND_LEFT:
   443         -            case COMPOUND_RIGHT: {
   444         -                /*
   445         -                 * Image is left or right of text
   446         -                 */
   447         -
   448         -                if (butPtr->compound == COMPOUND_LEFT) {
   449         -                    textXOffset = width + butPtr->padX - 2;
   450         -                } else {
   451         -                    imageXOffset = butPtr->textWidth + butPtr->padX;
   452         -                }
   453         -                fullWidth = butPtr->textWidth + butPtr->padX + width;
   454         -                fullHeight = (height > butPtr->textHeight ? height :
   455         -                        butPtr->textHeight);
   456         -                textYOffset = (fullHeight - butPtr->textHeight)/2;
   457         -                imageYOffset = (fullHeight - height)/2;
   458         -                break;
   459         -            }
   460         -            case COMPOUND_CENTER: {
   461         -                /*
   462         -                 * Image and text are superimposed
   463         -                 */
   464         -
   465         -                fullWidth = (width > butPtr->textWidth ? width :
   466         -                        butPtr->textWidth);
   467         -                fullHeight = (height > butPtr->textHeight ? height :
   468         -                        butPtr->textHeight);
   469         -                textXOffset = (fullWidth - butPtr->textWidth)/2;
   470         -                imageXOffset = (fullWidth - width)/2;
   471         -                textYOffset = (fullHeight - butPtr->textHeight)/2;
   472         -                imageYOffset = (fullHeight - height)/2;
   473         -                break;
   474         -            }
   475         -            case COMPOUND_NONE: {break;}
          416  +	case COMPOUND_TOP:
          417  +	case COMPOUND_BOTTOM:
          418  +	    /*
          419  +	     * Image is above or below text.
          420  +	     */
          421  +
          422  +	    if (butPtr->compound == COMPOUND_TOP) {
          423  +		textYOffset = height + butPtr->padY;
          424  +	    } else {
          425  +		imageYOffset = butPtr->textHeight + butPtr->padY;
          426  +	    }
          427  +	    fullHeight = height + butPtr->textHeight + butPtr->padY;
          428  +	    fullWidth = (width > butPtr->textWidth ?
          429  +		     width : butPtr->textWidth);
          430  +	    textXOffset = (fullWidth - butPtr->textWidth)/2;
          431  +	    imageXOffset = (fullWidth - width)/2;
          432  +	    break;
          433  +	case COMPOUND_LEFT:
          434  +	case COMPOUND_RIGHT:
          435  +	    /*
          436  +	     * Image is left or right of text
          437  +	     */
          438  +
          439  +	    if (butPtr->compound == COMPOUND_LEFT) {
          440  +		textXOffset = width + butPtr->padX - 2;
          441  +	    } else {
          442  +		imageXOffset = butPtr->textWidth + butPtr->padX;
          443  +	    }
          444  +	    fullWidth = butPtr->textWidth + butPtr->padX + width;
          445  +	    fullHeight = (height > butPtr->textHeight ? height :
          446  +                    butPtr->textHeight);
          447  +	    textYOffset = (fullHeight - butPtr->textHeight)/2;
          448  +	    imageYOffset = (fullHeight - height)/2;
          449  +	    break;
          450  +	case COMPOUND_CENTER:
          451  +	    /*
          452  +	     * Image and text are superimposed
          453  +	     */
          454  +
          455  +	    fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth);
          456  +	    fullHeight = (height > butPtr->textHeight ? height :
          457  +                    butPtr->textHeight);
          458  +	    textXOffset = (fullWidth - butPtr->textWidth) / 2;
          459  +	    imageXOffset = (fullWidth - width) / 2;
          460  +	    textYOffset = (fullHeight - butPtr->textHeight) / 2;
          461  +	    imageYOffset = (fullHeight - height) / 2;
          462  +	    break;
          463  +	case COMPOUND_NONE:
          464  +	    break;
   476    465   	}
   477    466   
   478    467           TkComputeAnchor(butPtr->anchor, tkwin,
   479         -                butPtr->padX + butPtr->inset,
   480         -                butPtr->padY + butPtr->inset,
          468  +                butPtr->padX + butPtr->inset, butPtr->padY + butPtr->inset,
   481    469                   fullWidth, fullHeight, &x, &y);
   482    470           imageXOffset = LEFT_INSET;
   483    471           imageYOffset += y;
   484    472           textYOffset -= 1;
   485    473   
   486    474           if (butPtr->image != NULL) {
   487         -                Tk_RedrawImage(butPtr->image, 0, 0, width,
   488         -                        height, pixmap, imageXOffset, imageYOffset);
          475  +	    Tk_RedrawImage(butPtr->image, 0, 0, width,
          476  +                    height, pixmap, imageXOffset, imageYOffset);
   489    477           } else {
   490    478               XSetClipOrigin(butPtr->display, dpPtr->gc,
   491    479                       imageXOffset, imageYOffset);
   492    480               XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc,
   493    481                       0, 0, (unsigned int) width, (unsigned int) height,
   494    482                       imageXOffset, imageYOffset, 1);
   495    483               XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
   496    484           }
   497    485   
   498    486           Tk_DrawTextLayout(butPtr->display, pixmap,
   499    487                   dpPtr->gc, butPtr->textLayout,
   500    488                   x + textXOffset, y + textYOffset, 0, -1);
   501    489           Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc,
   502         -                butPtr->textLayout,
   503         -                x + textXOffset, y + textYOffset,
          490  +                butPtr->textLayout, x + textXOffset, y + textYOffset,
   504    491                   butPtr->underline);
   505    492       } else {
          493  +	int x, y;
          494  +
   506    495           if (haveImage) {
   507         -            int x, y;
   508    496               TkComputeAnchor(butPtr->anchor, tkwin,
   509    497                       butPtr->padX + butPtr->borderWidth,
   510    498                       butPtr->padY + butPtr->borderWidth,
   511    499                       width, height, &x, &y);
   512    500   	    imageXOffset = LEFT_INSET;
   513    501   	    imageYOffset += y;
   514    502   	    if (butPtr->image != NULL) {
................................................................................
   520    508   			   pixmap, dpPtr->gc,
   521    509   			   0, 0, (unsigned int) width,
   522    510   			   (unsigned int) height,
   523    511   			   imageXOffset, imageYOffset, 1);
   524    512                   XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0);
   525    513               }
   526    514           } else {
   527         -	    int x, y;
   528    515   	    textXOffset = LEFT_INSET;
   529    516   	    TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY,
   530         -			    butPtr->textWidth, butPtr->textHeight, &x, &y);
          517  +		    butPtr->textWidth, butPtr->textHeight, &x, &y);
   531    518   	    Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc,
   532         -			      butPtr->textLayout, textXOffset, y, 0, -1);
          519  +		    butPtr->textLayout, textXOffset, y, 0, -1);
   533    520   	    y += butPtr->textHeight/2;
   534         -	  }
          521  +	}
   535    522      }
   536    523   }
   537         -
   538         -
   539         -
          524  +
   540    525   /*
   541    526    *--------------------------------------------------------------
   542    527    *
   543    528    * TkMacOSXDrawMenuButton --
   544    529    *
   545         - *        This function draws the tk menubutton using Mac controls
   546         - *        In addition, this code may apply custom colors passed
   547         - *        in the TkMenubutton.
          530  + *        This function draws the tk menubutton using Mac controls. In
          531  + *        addition, this code may apply custom colors passed in the
          532  + *        TkMenubutton.
   548    533    *
   549    534    * Results:
   550    535    *        None.
   551    536    *
   552    537    * Side effects:
   553    538    *        None.
   554    539    *
   555    540    *--------------------------------------------------------------
   556    541    */
          542  +
   557    543   static void
   558    544   TkMacOSXDrawMenuButton(
   559    545       MacMenuButton *mbPtr, /* Mac menubutton. */
   560         -    GC gc,                /* The GC we are drawing into - needed for
   561         -                           * the bevel button */
   562         -    Pixmap pixmap)        /* The pixmap we are drawing into - needed
   563         -                           * for the bevel button */
          546  +    GC gc,                /* The GC we are drawing into - needed for the bevel
          547  +                           * button */
          548  +    Pixmap pixmap)        /* The pixmap we are drawing into - needed for the
          549  +                           * bevel button */
   564    550   {
   565         -    TkMenuButton * butPtr = ( TkMenuButton *)mbPtr;
   566         -    TkWindow * winPtr;
   567         -    HIRect       cntrRect;
          551  +    TkMenuButton *butPtr = (TkMenuButton *) mbPtr;
          552  +    TkWindow *winPtr = (TkWindow *) butPtr->tkwin;
          553  +    HIRect cntrRect;
   568    554       TkMacOSXDrawingContext dc;
   569         -    DrawParams* dpPtr = &mbPtr->drawParams;
          555  +    DrawParams *dpPtr = &mbPtr->drawParams;
   570    556       int useNewerHITools = 1;
   571    557   
   572         -    winPtr = (TkWindow *)butPtr->tkwin;
   573         -
   574    558       TkMacOSXComputeMenuButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo);
   575    559   
   576    560       cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff,
   577         -			  Tk_Width(butPtr->tkwin),
   578         -			  Tk_Height(butPtr->tkwin));
          561  +	    Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin));
   579    562   
   580    563       if (useNewerHITools == 1) {
   581    564           HIRect contHIRec;
   582    565           static HIThemeButtonDrawInfo hiinfo;
   583    566   
   584         -        MenuButtonBackgroundDrawCB((MacMenuButton*) mbPtr, 32, true);
   585         -
          567  +        MenuButtonBackgroundDrawCB(mbPtr, 32, true);
   586    568   	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
   587    569   	    return;
   588    570   	}
   589    571   
   590         -
   591    572           hiinfo.version = 0;
   592    573           hiinfo.state = mbPtr->drawinfo.state;
   593         -        hiinfo.kind  = mbPtr->btnkind;
          574  +        hiinfo.kind = mbPtr->btnkind;
   594    575           hiinfo.value = mbPtr->drawinfo.value;
   595    576           hiinfo.adornment = mbPtr->drawinfo.adornment;
   596    577           hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
   597    578           if (hiinfo.animation.time.start == 0) {
   598    579               hiinfo.animation.time.start = hiinfo.animation.time.current;
   599    580           }
   600    581   
   601    582           HIThemeDrawButton(&cntrRect, &hiinfo, dc.context,
   602         -			  kHIThemeOrientationNormal, &contHIRec);
          583  +		kHIThemeOrientationNormal, &contHIRec);
   603    584   	TkMacOSXRestoreDrawingContext(&dc);
   604         -        MenuButtonContentDrawCB( mbPtr->btnkind, &mbPtr->drawinfo,
   605         -				 (MacMenuButton *)mbPtr, 32, true);
          585  +        MenuButtonContentDrawCB(mbPtr->btnkind, &mbPtr->drawinfo,
          586  +		mbPtr, 32, true);
   606    587       } else {
   607    588   	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
   608    589   	    return;
   609    590   	}
   610    591   	TkMacOSXRestoreDrawingContext(&dc);
   611    592       }
   612    593       mbPtr->lastdrawinfo = mbPtr->drawinfo;
................................................................................
   613    594   }
   614    595   
   615    596   /*
   616    597    *--------------------------------------------------------------
   617    598    *
   618    599    * MenuButtonBackgroundDrawCB --
   619    600    *
   620         - *        This function draws the background that
   621         - *        lies under checkboxes and radiobuttons.
          601  + *      This function draws the background that lies under checkboxes and
          602  + *      radiobuttons.
   622    603    *
   623    604    * Results:
   624         - *        None.
          605  + *      None.
   625    606    *
   626    607    * Side effects:
   627         - *        The background gets updated to the current color.
          608  + *      The background gets updated to the current color.
   628    609    *
   629    610    *--------------------------------------------------------------
   630    611    */
          612  +
   631    613   static void
   632    614   MenuButtonBackgroundDrawCB (
   633    615       MacMenuButton *ptr,
   634    616       SInt16 depth,
   635    617       Boolean isColorDev)
   636    618   {
   637         -    TkMenuButton* butPtr = (TkMenuButton*)ptr;
   638         -    Tk_Window tkwin  = butPtr->tkwin;
          619  +    TkMenuButton* butPtr = (TkMenuButton *) ptr;
          620  +    Tk_Window tkwin = butPtr->tkwin;
   639    621       Pixmap pixmap;
          622  +
   640    623       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   641    624           return;
   642    625       }
   643         -    pixmap = (Pixmap)Tk_WindowId(tkwin);
   644         -
          626  +    pixmap = (Pixmap) Tk_WindowId(tkwin);
   645    627       Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0,
   646         -        Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
          628  +            Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
   647    629   }
   648    630   
   649    631   /*
   650    632    *--------------------------------------------------------------
   651    633    *
   652    634    * MenuButtonContentDrawCB --
   653    635    *
   654         - *        This function draws the label and image for the button.
          636  + *      This function draws the label and image for the button.
   655    637    *
   656    638    * Results:
   657         - *        None.
          639  + *      None.
   658    640    *
   659    641    * Side effects:
   660         - *        The content of the button gets updated.
          642  + *      The content of the button gets updated.
   661    643    *
   662    644    *--------------------------------------------------------------
   663    645    */
          646  +
   664    647   static void
   665    648   MenuButtonContentDrawCB (
   666    649       ThemeButtonKind kind,
   667    650       const HIThemeButtonDrawInfo *drawinfo,
   668    651       MacMenuButton *ptr,
   669    652       SInt16 depth,
   670    653       Boolean isColorDev)
   671    654   {
   672         -    TkMenuButton  *butPtr = (TkMenuButton *)ptr;
   673         -    Tk_Window  tkwin  = butPtr->tkwin;
          655  +    TkMenuButton *butPtr = (TkMenuButton *) ptr;
          656  +    Tk_Window tkwin = butPtr->tkwin;
   674    657   
   675    658       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   676    659           return;
   677    660       }
   678    661       DrawMenuButtonImageAndText(butPtr);
   679    662   }
   680    663   
   681    664   /*
   682    665    *--------------------------------------------------------------
   683    666    *
   684    667    * MenuButtonEventProc --
   685    668    *
   686         - *	This procedure is invoked by the Tk dispatcher for various
   687         - *	events on buttons.
          669  + *	This procedure is invoked by the Tk dispatcher for various events on
          670  + *	buttons.
   688    671    *
   689    672    * Results:
   690    673    *	None.
   691    674    *
   692    675    * Side effects:
   693    676    *	When it gets exposed, it is redisplayed.
   694    677    *
................................................................................
   696    679    */
   697    680   
   698    681   static void
   699    682   MenuButtonEventProc(
   700    683       ClientData clientData,	/* Information about window. */
   701    684       XEvent *eventPtr)		/* Information about event. */
   702    685   {
   703         -    TkMenuButton *buttonPtr = (TkMenuButton *) clientData;
   704         -    MacMenuButton *mbPtr = (MacMenuButton *) clientData;
          686  +    TkMenuButton *buttonPtr = clientData;
          687  +    MacMenuButton *mbPtr = clientData;
   705    688   
   706    689       if (eventPtr->type == ActivateNotify
   707    690   	    || eventPtr->type == DeactivateNotify) {
   708    691   	if ((buttonPtr->tkwin == NULL) || (!Tk_IsMapped(buttonPtr->tkwin))) {
   709    692   	    return;
   710    693   	}
   711    694   	if (eventPtr->type == ActivateNotify) {
................................................................................
   721    704   }
   722    705   
   723    706   /*
   724    707    *----------------------------------------------------------------------
   725    708    *
   726    709    * TkMacOSXComputeMenuButtonParams --
   727    710    *
   728         - *      This procedure computes the various parameters used
   729         - *        when creating a Carbon Appearance control.
   730         - *      These are determined by the various tk button parameters
          711  + *      This procedure computes the various parameters used when creating a
          712  + *      Carbon Appearance control. These are determined by the various Tk
          713  + *      button parameters
   731    714    *
   732    715    * Results:
   733    716    *        None.
   734    717    *
   735    718    * Side effects:
   736    719    *        Sets the btnkind and drawinfo parameters
   737    720    *
   738    721    *----------------------------------------------------------------------
   739    722    */
   740    723   
   741    724   static void
   742    725   TkMacOSXComputeMenuButtonParams(
   743         -    TkMenuButton * butPtr,
   744         -    ThemeButtonKind* btnkind,
          726  +    TkMenuButton *butPtr,
          727  +    ThemeButtonKind *btnkind,
   745    728       HIThemeButtonDrawInfo *drawinfo)
   746    729   {
   747         -    MacMenuButton *mbPtr = (MacMenuButton *)butPtr;
          730  +    MacMenuButton *mbPtr = (MacMenuButton *) butPtr;
   748    731   
   749    732       if (butPtr->image || butPtr->bitmap || butPtr->text) {
   750    733   	/* TODO: allow for Small and Mini menubuttons. */
   751    734   	*btnkind = kThemePopupButton;
   752    735       } else { /* This should never happen. */
   753    736   	*btnkind = kThemeArrowButton;
   754    737       }
................................................................................
   785    768   }
   786    769   
   787    770   /*
   788    771    *----------------------------------------------------------------------
   789    772    *
   790    773    * TkMacOSXComputeMenuButtonDrawParams --
   791    774    *
   792         - *        This procedure selects an appropriate drawing context for
   793         - *        drawing a menubutton.
          775  + *      This procedure selects an appropriate drawing context for drawing a
          776  + *      menubutton.
   794    777    *
   795    778    * Results:
   796         - *        None.
          779  + *      None.
   797    780    *
   798    781    * Side effects:
   799         - *        Sets the button draw parameters.
          782  + *      Sets the button draw parameters.
   800    783    *
   801    784    *----------------------------------------------------------------------
   802    785    */
   803    786   
   804    787   static void
   805    788   TkMacOSXComputeMenuButtonDrawParams(
   806         -    TkMenuButton * butPtr,
   807         -    DrawParams * dpPtr)
          789  +    TkMenuButton *butPtr,
          790  +    DrawParams *dpPtr)
   808    791   {
   809         -    dpPtr->hasImageOrBitmap = ((butPtr->image != NULL) ||
   810         -			       (butPtr->bitmap != None));
          792  +    dpPtr->hasImageOrBitmap =
          793  +	    ((butPtr->image != NULL) || (butPtr->bitmap != None));
   811    794       dpPtr->border = butPtr->normalBorder;
   812    795       if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
   813    796           dpPtr->gc = butPtr->disabledGC;
   814    797       } else if (butPtr->state == STATE_ACTIVE) {
   815    798           dpPtr->gc = butPtr->activeTextGC;
   816    799           dpPtr->border = butPtr->activeBorder;
   817    800       } else {
   818    801           dpPtr->gc = butPtr->normalTextGC;
   819    802       }
   820    803   }
   821         -
          804  +
   822    805   /*
   823    806    * Local Variables:
   824    807    * mode: objc
   825    808    * c-basic-offset: 4
   826    809    * fill-column: 79
   827    810    * coding: utf-8
   828    811    * End:
   829    812    */

Changes to macosx/tkMacOSXMenus.c.

   173    173   }
   174    174   
   175    175   - (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>) anItem
   176    176   {
   177    177       SEL action = [anItem action];
   178    178   
   179    179       if (sel_isEqual(action, @selector(preferences:))) {
   180         -
   181    180   	return (_eventInterp && Tcl_FindCommand(_eventInterp,
   182    181   		"::tk::mac::ShowPreferences", NULL, 0));
   183    182       } else if (sel_isEqual(action, @selector(tkDemo:))) {
   184    183   	BOOL haveDemo = NO;
   185    184   
   186    185   	if (_eventInterp) {
   187    186   	    Tcl_Obj *path = GetWidgetDemoPath(_eventInterp);

Changes to macosx/tkMacOSXNotify.c.

    29     29   	Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData))
    30     30   
    31     31   static void TkMacOSXNotifyExitHandler(ClientData clientData);
    32     32   static void TkMacOSXEventsSetupProc(ClientData clientData, int flags);
    33     33   static void TkMacOSXEventsCheckProc(ClientData clientData, int flags);
    34     34   
    35     35   #ifdef TK_MAC_DEBUG_EVENTS
    36         -static char* Tk_EventName[39] = {
           36  +static const char *Tk_EventName[39] = {
    37     37       "",
    38     38       "",
    39     39       "KeyPress",		/*2*/
    40     40       "KeyRelease",      	/*3*/
    41     41       "ButtonPress",     	/*4*/
    42     42       "ButtonRelease",	/*5*/
    43     43       "MotionNotify",    	/*6*/
................................................................................
   132    132    * no longer, and perhaps never did need to set autoDisplay to NO, nor call
   133    133    * displayIfNeeded on our windows.  We can just leave all of that to the window
   134    134    * manager.
   135    135    */
   136    136   
   137    137   /*
   138    138    * Since the contentView is the first responder for a Tk Window, it is
   139         - * responsible for sending events up the responder chain.  We also check
   140         - * the pasteboard here.
          139  + * responsible for sending events up the responder chain.  We also check the
          140  + * pasteboard here.
   141    141    */
   142    142   - (void) sendEvent: (NSEvent *) theEvent
   143    143   {
   144    144       [super sendEvent:theEvent];
   145    145       [NSApp tkCheckPasteboard];
   146    146   #ifdef TK_MAC_DEBUG_EVENTS
   147    147       fprintf(stderr, "Sending event of type %d\n", (int)[theEvent type]);
................................................................................
   186    186   }
   187    187   
   188    188   /*
   189    189    *----------------------------------------------------------------------
   190    190    *
   191    191    * Tk_MacOSXSetupTkNotifier --
   192    192    *
   193         - *	This procedure is called during Tk initialization to create
   194         - *	the event source for TkAqua events.
          193  + *	This procedure is called during Tk initialization to create the event
          194  + *	source for TkAqua events.
   195    195    *
   196    196    * Results:
   197    197    *	None.
   198    198    *
   199    199    * Side effects:
   200    200    *	A new event source is created.
   201    201    *
................................................................................
   220    220   		 * Panic if main runloop is not on the main application thread.
   221    221   		 */
   222    222   
   223    223   		Tcl_Panic("Tk_MacOSXSetupTkNotifier: %s",
   224    224   		    "first [load] of TkAqua has to occur in the main thread!");
   225    225   	    }
   226    226   	    Tcl_CreateEventSource(TkMacOSXEventsSetupProc,
   227         -				  TkMacOSXEventsCheckProc,
   228         -				  NULL);
          227  +		    TkMacOSXEventsCheckProc, NULL);
   229    228   	    TkCreateExitHandler(TkMacOSXNotifyExitHandler, NULL);
   230    229   	    Tcl_SetServiceMode(TCL_SERVICE_ALL);
   231    230   	    TclMacOSXNotifierAddRunLoopMode(NSEventTrackingRunLoopMode);
   232    231   	    TclMacOSXNotifierAddRunLoopMode(NSModalPanelRunLoopMode);
   233    232   	}
   234    233       }
   235    234   }
................................................................................
   254    253   static void
   255    254   TkMacOSXNotifyExitHandler(
   256    255       ClientData clientData)	/* Not used. */
   257    256   {
   258    257       TSD_INIT();
   259    258   
   260    259       Tcl_DeleteEventSource(TkMacOSXEventsSetupProc,
   261         -			  TkMacOSXEventsCheckProc,
   262         -			  NULL);
          260  +	    TkMacOSXEventsCheckProc, NULL);
   263    261       tsdPtr->initialized = 0;
   264    262   }
   265    263   
   266    264   /*
   267    265    *----------------------------------------------------------------------
   268    266    *
   269    267    * TkMacOSXEventsSetupProc --
   270    268    *
   271         - *	This procedure implements the setup part of the MacOSX event
   272         - *	source. It is invoked by Tcl_DoOneEvent before calling
   273         - *      TkMacOSXEventsProc to process all queued NSEvents.  In our
   274         - *      case, all we need to do is to set the Tcl MaxBlockTime to
   275         - *      0 before starting the loop to process all queued NSEvents.
          269  + *	This procedure implements the setup part of the MacOSX event source. It
          270  + *	is invoked by Tcl_DoOneEvent before calling TkMacOSXEventsProc to
          271  + *	process all queued NSEvents.  In our case, all we need to do is to set
          272  + *	the Tcl MaxBlockTime to 0 before starting the loop to process all
          273  + *	queued NSEvents.
   276    274    *
   277    275    * Results:
   278    276    *	None.
   279    277    *
   280    278    * Side effects:
   281    279    *
   282         - *	If NSEvents are queued, then the maximum block time will be set
   283         - *	to 0 to ensure that control returns immediately to Tcl.
          280  + *	If NSEvents are queued, then the maximum block time will be set to 0 to
          281  + *	ensure that control returns immediately to Tcl.
   284    282    *
   285    283    *----------------------------------------------------------------------
   286    284    */
   287    285   
   288    286   static void
   289    287   TkMacOSXEventsSetupProc(
   290    288       ClientData clientData,
   291    289       int flags)
   292    290   {
   293    291       NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode];
   294         -    /* runloopMode will be nil if we are in a Tcl event loop. */
          292  +
          293  +    /*
          294  +     * runloopMode will be nil if we are in a Tcl event loop.
          295  +     */
          296  +
   295    297       if (flags & TCL_WINDOW_EVENTS && !runloopMode) {
   296    298   	static const Tcl_Time zeroBlockTime = { 0, 0 };
   297    299   	[NSApp _resetAutoreleasePool];
   298         -	/* Call this with dequeue=NO -- just checking if the queue is empty. */
   299         -	NSEvent *currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
   300         -				       untilDate:[NSDate distantPast]
   301         -				       inMode:GetRunLoopMode(TkMacOSXGetModalSession())
   302         -				       dequeue:NO];
          300  +
          301  +	/*
          302  +	 * Call this with dequeue=NO -- just checking if the queue is empty.
          303  +	 */
          304  +
          305  +	NSEvent *currentEvent =
          306  +	        [NSApp nextEventMatchingMask:NSAnyEventMask
          307  +			untilDate:[NSDate distantPast]
          308  +			inMode:GetRunLoopMode(TkMacOSXGetModalSession())
          309  +			dequeue:NO];
   303    310   	if (currentEvent) {
   304    311   	    if (currentEvent.type > 0) {
   305    312   		Tcl_SetMaxBlockTime(&zeroBlockTime);
   306    313   	    }
   307    314   	}
   308    315       }
   309    316   }
   310    317   
   311    318   /*
   312    319    *----------------------------------------------------------------------
   313    320    *
   314    321    * TkMacOSXEventsCheckProc --
   315    322    *
   316         - *	This procedure loops through all NSEvents waiting in the
   317         - *      TKApplication event queue, generating X events from them.
          323  + *	This procedure loops through all NSEvents waiting in the TKApplication
          324  + *      event queue, generating X events from them.
   318    325    *
   319    326    * Results:
   320    327    *	None.
   321    328    *
   322    329    * Side effects:
   323         - *	NSevents are used to generate X events, which are added to the
   324         - *      Tcl event queue.
          330  + *	NSevents are used to generate X events, which are added to the Tcl
          331  + *      event queue.
   325    332    *
   326    333    *----------------------------------------------------------------------
   327    334    */
   328    335   static void
   329    336   TkMacOSXEventsCheckProc(
   330    337       ClientData clientData,
   331    338       int flags)
   332    339   {
   333    340       NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode];
   334         -    /* runloopMode will be nil if we are in a Tcl event loop. */
          341  +
          342  +    /*
          343  +     * runloopMode will be nil if we are in a Tcl event loop.
          344  +     */
          345  +
   335    346       if (flags & TCL_WINDOW_EVENTS && !runloopMode) {
   336    347   	NSEvent *currentEvent = nil;
   337    348   	NSEvent *testEvent = nil;
   338    349   	NSModalSession modalSession;
   339         -	/* It is possible for the SetupProc to be called before this function
          350  +
          351  +	/*
          352  +	 * It is possible for the SetupProc to be called before this function
   340    353   	 * returns.  This happens, for example, when we process an event which
   341    354   	 * opens a modal window.  To prevent premature release of our
   342    355   	 * application-wide autorelease pool by a nested call to the SetupProc,
   343    356   	 * we must lock it here.
   344    357   	 */
          358  +
   345    359   	[NSApp _lockAutoreleasePool];
   346    360   	do {
   347    361   	    modalSession = TkMacOSXGetModalSession();
   348         -	    	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
   349         -					      untilDate:[NSDate distantPast]
   350         -						 inMode:GetRunLoopMode(modalSession)
   351         -						dequeue:NO];
   352         -	    /* We must not steal any events during LiveResize. */
          362  +	    testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
          363  +		    untilDate:[NSDate distantPast]
          364  +		    inMode:GetRunLoopMode(modalSession)
          365  +		    dequeue:NO];
          366  +
          367  +	    /*
          368  +	     * We must not steal any events during LiveResize.
          369  +	     */
          370  +
   353    371   	    if (testEvent && [[testEvent window] inLiveResize]) {
   354    372   		break;
   355    373   	    }
   356    374   	    currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
   357         -					      untilDate:[NSDate distantPast]
   358         -						 inMode:GetRunLoopMode(modalSession)
   359         -						dequeue:YES];
          375  +		    untilDate:[NSDate distantPast]
          376  +		    inMode:GetRunLoopMode(modalSession)
          377  +		    dequeue:YES];
   360    378   	    if (currentEvent) {
   361         -		/* Generate Xevents. */
          379  +		/*
          380  +		 * Generate Xevents.
          381  +		 */
          382  +
   362    383   		int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
   363    384   		NSEvent *processedEvent = [NSApp tkProcessEvent:currentEvent];
   364    385   		Tcl_SetServiceMode(oldServiceMode);
   365    386   		if (processedEvent) {
   366    387   #ifdef TK_MAC_DEBUG_EVENTS
   367    388   		    TKLog(@"   event: %@", currentEvent);
   368    389   #endif
   369    390   		    if (modalSession) {
   370    391   			[NSApp _modalSession:modalSession sendEvent:currentEvent];
   371    392   		    } else {
   372    393   			[NSApp sendEvent:currentEvent];
   373    394   		    }
   374    395   		}
   375         -
   376    396   	    } else {
   377    397   		break;
   378    398   	    }
   379    399   	} while (1);
   380         -	/* Now we can unlock the pool. */
          400  +
          401  +	/*
          402  +	 * Now we can unlock the pool.
          403  +	 */
          404  +
   381    405   	[NSApp _unlockAutoreleasePool];
   382    406       }
   383    407   }
   384         -
   385    408   
   386    409   /*
   387    410    * Local Variables:
   388    411    * mode: objc
   389    412    * c-basic-offset: 4
   390    413    * fill-column: 79
   391    414    * coding: utf-8
   392    415    * End:
   393    416    */

Changes to macosx/tkMacOSXRegion.c.

   183    183    *
   184    184    * TkRectInRegion --
   185    185    *
   186    186    *	Implements the equivelent of the X window function XRectInRegion. See
   187    187    *	Xwindow documentation for more details.
   188    188    *
   189    189    * Results:
   190         - *	Returns RectanglePart or RectangleOut. Note that this is not a
   191         - *	complete implementation since it doesn't test for RectangleIn.
          190  + *	Returns RectanglePart or RectangleOut. Note that this is not a complete
          191  + *	implementation since it doesn't test for RectangleIn.
   192    192    *
   193    193    * Side effects:
   194    194    *	None.
   195    195    *
   196    196    *----------------------------------------------------------------------
   197    197    */
   198    198   
................................................................................
   200    200   TkRectInRegion(
   201    201       TkRegion region,
   202    202       int x,
   203    203       int y,
   204    204       unsigned int width,
   205    205       unsigned int height)
   206    206   {
   207         -    if ( TkMacOSXIsEmptyRegion(region) ) {
   208         -	    return RectangleOut;
   209         -	}
   210         -    else {
          207  +    if (TkMacOSXIsEmptyRegion(region)) {
          208  +	return RectangleOut;
          209  +    } else {
   211    210   	const CGRect r = CGRectMake(x, y, width, height);
          211  +
   212    212   	return HIShapeIntersectsRect((HIShapeRef) region, &r) ?
   213         -	    RectanglePart : RectangleOut;
          213  +		RectanglePart : RectangleOut;
   214    214       }
   215    215   }
   216    216   
   217    217   /*
   218    218    *----------------------------------------------------------------------
   219    219    *
   220    220    * TkClipBox --
................................................................................
   230    230    *
   231    231    *----------------------------------------------------------------------
   232    232    */
   233    233   
   234    234   void
   235    235   TkClipBox(
   236    236       TkRegion r,
   237         -    XRectangle* rect_return)
          237  +    XRectangle *rect_return)
   238    238   {
   239    239       CGRect rect;
   240    240   
   241    241       HIShapeGetBounds((HIShapeRef) r, &rect);
   242    242       rect_return->x = rect.origin.x;
   243    243       rect_return->y = rect.origin.y;
   244    244       rect_return->width = rect.size.width;

Changes to macosx/tkMacOSXScale.c.

    47     47    */
    48     48   static ControlActionUPP scaleActionProc = NULL; /* Pointer to func. */
    49     49   
    50     50   /*
    51     51    * Forward declarations for procedures defined later in this file:
    52     52    */
    53     53   
    54         -static void MacScaleEventProc(ClientData clientData, XEvent *eventPtr);
    55         -static pascal void ScaleActionProc(ControlRef theControl,
    56         -	ControlPartCode partCode);
    57         -
           54  +static void		MacScaleEventProc(ClientData clientData,
           55  +			    XEvent *eventPtr);
           56  +static pascal void	ScaleActionProc(ControlRef theControl,
           57  +			    ControlPartCode partCode);
    58     58   
    59     59   /*
    60     60    *----------------------------------------------------------------------
    61     61    *
    62     62    * TkpCreateScale --
    63     63    *
    64     64    *	Allocate a new TkScale structure.
................................................................................
    80     80   
    81     81       macScalePtr->scaleHandle = NULL;
    82     82       if (scaleActionProc == NULL) {
    83     83   	scaleActionProc = NewControlActionUPP(ScaleActionProc);
    84     84       }
    85     85   
    86     86       Tk_CreateEventHandler(tkwin, ButtonPressMask,
    87         -	    MacScaleEventProc, (ClientData) macScalePtr);
           87  +	    MacScaleEventProc, macScalePtr);
    88     88   
    89     89       return (TkScale *) macScalePtr;
    90     90   }
    91     91   
    92     92   /*
    93     93    *----------------------------------------------------------------------
    94     94    *
................................................................................
   121    121   }
   122    122   
   123    123   /*
   124    124    *----------------------------------------------------------------------
   125    125    *
   126    126    * TkpDisplayScale --
   127    127    *
   128         - *	This procedure is invoked as an idle handler to redisplay
   129         - *	the contents of a scale widget.
          128  + *	This procedure is invoked as an idle handler to redisplay the contents
          129  + *	of a scale widget.
   130    130    *
   131    131    * Results:
   132    132    *	None.
   133    133    *
   134    134    * Side effects:
   135    135    *	The scale gets redisplayed.
   136    136    *
................................................................................
   137    137    *----------------------------------------------------------------------
   138    138    */
   139    139   
   140    140   void
   141    141   TkpDisplayScale(
   142    142       ClientData clientData)	/* Widget record for scale. */
   143    143   {
   144         -    TkScale *scalePtr = (TkScale *) clientData;
          144  +    TkScale *scalePtr = clientData;
   145    145       Tk_Window tkwin = scalePtr->tkwin;
   146    146       Tcl_Interp *interp = scalePtr->interp;
   147    147       int result;
   148    148       char string[TCL_DOUBLE_SPACE];
   149         -    MacScale *macScalePtr = (MacScale *) clientData;
          149  +    MacScale *macScalePtr = clientData;
   150    150       Rect r;
   151    151       WindowRef windowRef;
   152    152       CGrafPtr destPort, savePort;
   153    153       Boolean portChanged;
   154    154       MacDrawable *macDraw;
   155    155       SInt32 initialValue, minValue, maxValue;
   156    156       UInt16 numTicks;
................................................................................
   164    164   	goto done;
   165    165       }
   166    166   
   167    167       /*
   168    168        * Invoke the scale's command if needed.
   169    169        */
   170    170   
   171         -    Tcl_Preserve((ClientData) scalePtr);
          171  +    Tcl_Preserve(scalePtr);
   172    172       if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) {
   173         -	Tcl_Preserve((ClientData) interp);
          173  +	Tcl_Preserve(interp);
   174    174           if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format,
   175    175                   scalePtr->value) < 0) {
   176    176               string[TCL_DOUBLE_SPACE - 1] = '\0';
   177    177           }
   178    178   	Tcl_DStringInit(&buf);
   179    179   	Tcl_DStringAppend(&buf, scalePtr->command, -1);
   180    180   	Tcl_DStringAppend(&buf, " ", -1);
................................................................................
   181    181   	Tcl_DStringAppend(&buf, string, -1);
   182    182   	result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0);
   183    183   	Tcl_DStringFree(&buf);
   184    184   	if (result != TCL_OK) {
   185    185   	    Tcl_AddErrorInfo(interp, "\n    (command executed by scale)");
   186    186   	    Tcl_BackgroundException(interp, result);
   187    187   	}
   188         -	Tcl_Release((ClientData) interp);
          188  +	Tcl_Release(interp);
   189    189       }
   190    190       scalePtr->flags &= ~INVOKE_COMMAND;
   191    191       if (scalePtr->flags & SCALE_DELETED) {
   192         -	Tcl_Release((ClientData) scalePtr);
          192  +	Tcl_Release(scalePtr);
   193    193   	return;
   194    194       }
   195         -    Tcl_Release((ClientData) scalePtr);
          195  +    Tcl_Release(scalePtr);
   196    196   
   197    197       /*
   198         -     * Now handle the part of redisplay that is the same for
   199         -     * horizontal and vertical scales: border and traversal
   200         -     * highlight.
          198  +     * Now handle the part of redisplay that is the same for horizontal and
          199  +     * vertical scales: border and traversal highlight.
   201    200        */
   202    201   
   203    202       if (scalePtr->highlightWidth != 0) {
   204    203   	GC gc = Tk_GCForColor(scalePtr->highlightColorPtr, Tk_WindowId(tkwin));
   205    204   
   206    205   	Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth,
   207    206   		Tk_WindowId(tkwin));
................................................................................
   225    224       /*
   226    225        * Create Macintosh control.
   227    226        */
   228    227   
   229    228   #define MAC_OSX_SCROLL_WIDTH 10
   230    229   
   231    230       if (scalePtr->orient == ORIENT_HORIZONTAL) {
   232         -	int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;
          231  +	int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH) / 2;
   233    232   
   234    233   	if (offset < 0) {
   235    234   	    offset = 0;
   236    235   	}
   237    236   
   238    237   	r.left = macDraw->xOff + scalePtr->inset;
   239    238   	r.top = macDraw->yOff + offset;
   240    239   	r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset;
   241    240   	r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2;
   242    241       } else {
   243         -	int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2;
          242  +	int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH) / 2;
   244    243   
   245    244   	if (offset < 0) {
   246    245   	    offset = 0;
   247    246   	}
   248    247   
   249    248   	r.left = macDraw->xOff + offset;
   250    249   	r.top = macDraw->yOff + scalePtr->inset;
   251    250   	r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2;
   252         -	r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset;
          251  +	r.bottom = macDraw->yOff + Tk_Height(tkwin) - scalePtr->inset;
   253    252       }
   254    253   
   255    254       if (macScalePtr->scaleHandle == NULL) {
   256    255   #ifdef TK_MAC_DEBUG_SCALE
   257    256   	TkMacOSXDbgMsg("Initialising scale");
   258    257   #endif
   259    258   	initialValue = scalePtr->value;
................................................................................
   269    268   	    numTicks = 0;
   270    269   	} else {
   271    270   	    numTicks = (maxValue - minValue)/scalePtr->tickInterval;
   272    271   	}
   273    272   
   274    273   	CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue,
   275    274   		kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc,
   276         -		&(macScalePtr->scaleHandle));
          275  +		&macScalePtr->scaleHandle);
   277    276   	SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr);
   278    277   
   279    278   	if (IsWindowActive(windowRef)) {
   280    279   	    macScalePtr->flags |= ACTIVE;
   281    280   	}
   282    281       } else {
   283    282   	SetControlBounds(macScalePtr->scaleHandle, &r);
................................................................................
   286    285   	SetControl32BitMaximum(macScalePtr->scaleHandle, scalePtr->toValue);
   287    286       }
   288    287   
   289    288       /*
   290    289        * Finally draw the control.
   291    290        */
   292    291   
   293         -    SetControlVisibility(macScalePtr->scaleHandle,true,true);
   294         -    HiliteControl(macScalePtr->scaleHandle,0);
          292  +    SetControlVisibility(macScalePtr->scaleHandle, true, true);
          293  +    HiliteControl(macScalePtr->scaleHandle, 0);
   295    294       Draw1Control(macScalePtr->scaleHandle);
   296    295   
   297    296       if (portChanged) {
   298    297   	QDSwapPort(savePort, NULL);
   299    298       }
   300    299   done:
   301    300       scalePtr->flags &= ~REDRAW_ALL;
................................................................................
   302    301   }
   303    302   
   304    303   /*
   305    304    *----------------------------------------------------------------------
   306    305    *
   307    306    * TkpScaleElement --
   308    307    *
   309         - *	Determine which part of a scale widget lies under a given
   310         - *	point.
          308  + *	Determine which part of a scale widget lies under a given point.
   311    309    *
   312    310    * Results:
   313         - *	The return value is either TROUGH1, SLIDER, TROUGH2, or
   314         - *	OTHER, depending on which of the scale's active elements
   315         - *	(if any) is under the point at (x,y).
          311  + *	The return value is either TROUGH1, SLIDER, TROUGH2, or OTHER,
          312  + *	depending on which of the scale's active elements (if any) is under the
          313  + *	point at (x,y).
   316    314    *
   317    315    * Side effects:
   318    316    *	None.
   319    317    *
   320    318    *----------------------------------------------------------------------
   321    319    */
   322    320   
................................................................................
   353    351       }
   354    352   
   355    353   #ifdef TK_MAC_DEBUG_SCALE
   356    354       fprintf (stderr,"ScalePart %d, pos ( %d %d )\n", part, where.h, where.v );
   357    355   #endif
   358    356   
   359    357       switch (part) {
   360         -	case inSlider:
   361         -	    return SLIDER;
   362         -	case inInc:
   363         -	    if (scalePtr->orient == ORIENT_VERTICAL) {
   364         -		return TROUGH1;
   365         -	    } else {
   366         -		return TROUGH2;
   367         -	    }
   368         -	case inDecr:
   369         -	    if (scalePtr->orient == ORIENT_VERTICAL) {
   370         -		return TROUGH2;
   371         -	    } else {
   372         -		return TROUGH1;
   373         -	    }
   374         -	default:
   375         -	    return OTHER;
          358  +    case inSlider:
          359  +	return SLIDER;
          360  +    case inInc:
          361  +	if (scalePtr->orient == ORIENT_VERTICAL) {
          362  +	    return TROUGH1;
          363  +	} else {
          364  +	    return TROUGH2;
          365  +	}
          366  +    case inDecr:
          367  +	if (scalePtr->orient == ORIENT_VERTICAL) {
          368  +	    return TROUGH2;
          369  +	} else {
          370  +	    return TROUGH1;
          371  +	}
          372  +    default:
          373  +	return OTHER;
   376    374       }
   377    375   }
   378    376   
   379    377   /*
   380    378    *--------------------------------------------------------------
   381    379    *
   382    380    * MacScaleEventProc --
   383    381    *
   384         - *	This procedure is invoked by the Tk dispatcher for
   385         - *	ButtonPress events on scales.
          382  + *	This procedure is invoked by the Tk dispatcher for ButtonPress events
          383  + *	on scales.
   386    384    *
   387    385    * Results:
   388    386    *	None.
   389    387    *
   390    388    * Side effects:
   391         - *	When the window gets deleted, internal structures get
   392         - *	cleaned up. When it gets exposed, it is redisplayed.
          389  + *	When the window gets deleted, internal structures get cleaned up. When
          390  + *	it gets exposed, it is redisplayed.
   393    391    *
   394    392    *--------------------------------------------------------------
   395    393    */
   396    394   
   397    395   static void
   398    396   MacScaleEventProc(
   399    397       ClientData clientData,	/* Information about window. */
................................................................................
   407    405       Boolean portChanged;
   408    406   
   409    407   #ifdef TK_MAC_DEBUG_SCALE
   410    408       fprintf(stderr,"MacScaleEventProc\n" );
   411    409   #endif
   412    410   
   413    411       /*
   414         -     * To call Macintosh control routines we must have the port
   415         -     * set to the window containing the control. We will then test
   416         -     * which part of the control was hit and act accordingly.
          412  +     * To call Macintosh control routines we must have the port set to the
          413  +     * window containing the control. We will then test which part of the
          414  +     * control was hit and act accordingly.
   417    415        */
   418    416   
   419    417       destPort = TkMacOSXGetDrawablePort(Tk_WindowId(macScalePtr->info.tkwin));
   420    418       portChanged = QDSwapPort(destPort, &savePort);
   421    419       TkMacOSXSetUpClippingRgn(Tk_WindowId(macScalePtr->info.tkwin));
   422    420   
   423    421       TkMacOSXWinBounds((TkWindow *) macScalePtr->info.tkwin, &bounds);
................................................................................
   457    455   
   458    456   /*
   459    457    *--------------------------------------------------------------
   460    458    *
   461    459    * ScaleActionProc --
   462    460    *
   463    461    *	Callback procedure used by the Macintosh toolbox call
   464         - *	HandleControlClick. This call will update the display
   465         - *	while the scrollbar is being manipulated by the user.
          462  + *	HandleControlClick. This call will update the display while the
          463  + *	scrollbar is being manipulated by the user.
   466    464    *
   467    465    * Results:
   468    466    *	None.
   469    467    *
   470    468    * Side effects:
   471    469    *	May change the display.
   472    470    *
................................................................................
   482    480       TkScale *scalePtr = (TkScale *) GetControlReference(theControl);
   483    481   
   484    482   #ifdef TK_MAC_DEBUG_SCALE
   485    483       TkMacOSXDbgMsg("ScaleActionProc");
   486    484   #endif
   487    485       value = GetControlValue(theControl);
   488    486       TkScaleSetValue(scalePtr, value, 1, 1);
   489         -    Tcl_Preserve((ClientData) scalePtr);
          487  +    Tcl_Preserve(scalePtr);
   490    488       TkMacOSXRunTclEventLoop();
   491         -    Tcl_Release((ClientData) scalePtr);
          489  +    Tcl_Release(scalePtr);
   492    490   }
   493    491   #endif
   494    492   
   495    493   /*
   496    494    * Local Variables:
   497    495    * mode: objc
   498    496    * c-basic-offset: 4
   499    497    * fill-column: 79
   500    498    * coding: utf-8
   501    499    * End:
   502    500    */

Changes to macosx/tkMacOSXScrlbr.c.

     5      5    *	widget.
     6      6    *
     7      7    * Copyright (c) 1996 by Sun Microsystems, Inc.
     8      8    * Copyright 2001-2009, Apple Inc.
     9      9    * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
    10     10    * Copyright (c) 2015 Kevin Walzer/WordTech Commununications LLC.
    11     11    * Copyright (c) 2018 Marc Culler
           12  + *
    12     13    * See the file "license.terms" for information on usage and redistribution
    13     14    * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    14     15    */
    15     16   
    16     17   #include "tkInt.h"
    17     18   #include "tkScrollbar.h"
    18     19   #include "tkMacOSXPrivate.h"
    19         -
    20     20   
    21     21   #define MIN_SCROLLBAR_VALUE		0
    22     22   
    23     23   /*
    24     24    * Minimum slider length, in pixels (designed to make sure that the slider is
    25     25    * always easy to grab with the mouse).
    26     26    */
    27     27   
    28     28   #define MIN_SLIDER_LENGTH	5
    29     29   
    30         -/*Borrowed from ttkMacOSXTheme.c to provide appropriate scaling.*/
           30  +/*
           31  + * Borrowed from ttkMacOSXTheme.c to provide appropriate scaling.
           32  + */
           33  +
    31     34   #ifdef __LP64__
    32         -#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum))
           35  +#define RangeToFactor(maximum)	(((double) (INT_MAX >> 1)) / (maximum))
    33     36   #else
    34         -#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum))
           37  +#define RangeToFactor(maximum)	(((double) (LONG_MAX >> 1)) / (maximum))
    35     38   #endif /* __LP64__ */
    36     39   
    37     40   /*
    38     41    * Apple reversed the scroll direction with the release of OSX 10.7 Lion.
    39     42    */
    40     43   
    41         -#define SNOW_LEOPARD_STYLE (NSAppKitVersionNumber < 1138)
           44  +#define SNOW_LEOPARD_STYLE	(NSAppKitVersionNumber < 1138)
    42     45   
    43     46   /*
    44     47    * Declaration of an extended scrollbar structure with Mac specific additions.
    45     48    */
    46     49   
    47     50   typedef struct MacScrollbar {
    48     51       TkScrollbar information;	/* Generic scrollbar info. */
    49     52       GC troughGC;		/* For drawing trough. */
    50     53       GC copyGC;			/* Used for copying from pixmap onto screen. */
    51     54       Bool buttonDown;            /* Is the mouse button down? */
    52     55       Bool mouseOver;             /* Is the pointer over the scrollbar. */
    53         -    HIThemeTrackDrawInfo info;  /* Controls how the scrollbar is drawn. */
           56  +    HIThemeTrackDrawInfo info;	/* Controls how the scrollbar is drawn. */
    54     57   } MacScrollbar;
    55     58   
    56     59   /* Used to initialize a MacScrollbar's info field. */
    57     60   HIThemeTrackDrawInfo defaultInfo = {
    58     61       .version = 0,
    59     62       .min = 0.0,
    60     63       .max = 100.0,
................................................................................
    65     68    * The class procedure table for the scrollbar widget. All fields except size
    66     69    * are left initialized to NULL, which should happen automatically since the
    67     70    * variable is declared at this scope.
    68     71    */
    69     72   
    70     73   const Tk_ClassProcs tkpScrollbarProcs = {
    71     74       sizeof(Tk_ClassProcs),	/* size */
    72         -    NULL,					/* worldChangedProc */
    73         -    NULL,					/* createProc */
    74         -    NULL					/* modalProc */
           75  +    NULL,			/* worldChangedProc */
           76  +    NULL,			/* createProc */
           77  +    NULL			/* modalProc */
    75     78   };
    76     79   
           80  +/*
           81  + * Information on scrollbar layout, metrics, and draw info.
           82  + */
    77     83   
    78         -/* Information on scrollbar layout, metrics, and draw info.*/
    79     84   typedef struct ScrollbarMetrics {
    80     85       SInt32 width, minThumbHeight;
    81     86       int minHeight, topArrowHeight, bottomArrowHeight;
    82     87       NSControlSize controlSize;
    83     88   } ScrollbarMetrics;
    84     89   
    85         -
    86     90   static ScrollbarMetrics metrics = {
    87         -  15, 54, 26, 14, 14, kControlSizeNormal /* kThemeScrollBarMedium */
           91  +    15, 54, 26, 14, 14, kControlSizeNormal /* kThemeScrollBarMedium */
    88     92   };
    89         -
    90     93   
    91     94   /*
    92     95    * Declarations of static functions defined later in this file:
    93     96    */
    94     97   
    95         -static void ScrollbarEventProc(ClientData clientData, XEvent *eventPtr);
    96         -static int ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr);
    97         -static void UpdateControlValues(TkScrollbar  *scrollPtr);
    98         -
           98  +static void		ScrollbarEventProc(ClientData clientData,
           99  +			    XEvent *eventPtr);
          100  +static int		ScrollbarEvent(TkScrollbar *scrollPtr,
          101  +			    XEvent *eventPtr);
          102  +static void		UpdateControlValues(TkScrollbar *scrollPtr);
          103  +
    99    104   /*
   100    105    *----------------------------------------------------------------------
   101    106    *
   102    107    * TkpCreateScrollbar --
   103    108    *
   104    109    *	Allocate a new TkScrollbar structure.
   105    110    *
................................................................................
   110    115    *	Registers an event handler for the widget.
   111    116    *
   112    117    *----------------------------------------------------------------------
   113    118    */
   114    119   
   115    120   TkScrollbar *
   116    121   TkpCreateScrollbar(
   117         -		   Tk_Window tkwin)
          122  +    Tk_Window tkwin)
   118    123   {
   119         -
   120         -    MacScrollbar *scrollPtr = (MacScrollbar *)ckalloc(sizeof(MacScrollbar));
          124  +    MacScrollbar *scrollPtr = ckalloc(sizeof(MacScrollbar));
   121    125   
   122    126       scrollPtr->troughGC = NULL;
   123    127       scrollPtr->copyGC = NULL;
   124    128       scrollPtr->info = defaultInfo;
   125    129       scrollPtr->buttonDown = false;
   126    130   
   127    131       Tk_CreateEventHandler(tkwin,
   128         -			  ExposureMask        |
   129         -			  StructureNotifyMask |
   130         -			  FocusChangeMask     |
   131         -			  ButtonPressMask     |
   132         -			  ButtonReleaseMask   |
   133         -			  EnterWindowMask     |
   134         -			  LeaveWindowMask     |
   135         -			  VisibilityChangeMask,
   136         -			  ScrollbarEventProc, scrollPtr);
          132  +	    ExposureMask        |
          133  +	    StructureNotifyMask |
          134  +	    FocusChangeMask     |
          135  +	    ButtonPressMask     |
          136  +	    ButtonReleaseMask   |
          137  +	    EnterWindowMask     |
          138  +	    LeaveWindowMask     |
          139  +	    VisibilityChangeMask,
          140  +	    ScrollbarEventProc, scrollPtr);
   137    141   
   138    142       return (TkScrollbar *) scrollPtr;
   139    143   }
   140    144   
   141    145   /*
   142    146    *--------------------------------------------------------------
   143    147    *
   144    148    * TkpDisplayScrollbar --
   145    149    *
   146    150    *	This procedure redraws the contents of a scrollbar window. It is
   147         - *	invoked as a do-when-idle handler, so it only runs when there's
   148         - *	nothing else for the application to do.
          151  + *	invoked as a do-when-idle handler, so it only runs when there's nothing
          152  + *	else for the application to do.
   149    153    *
   150    154    * Results:
   151    155    *	None.
   152    156    *
   153    157    * Side effects:
   154    158    *	Draws a scrollbar on the screen.
   155    159    *
   156    160    *--------------------------------------------------------------
   157    161    */
   158    162   
   159    163   void
   160    164   TkpDisplayScrollbar(
   161         -		    ClientData clientData)	/* Information about window. */
          165  +    ClientData clientData)	/* Information about window. */
   162    166   {
   163         -    register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
          167  +    register TkScrollbar *scrollPtr = clientData;
   164    168       MacScrollbar *msPtr = (MacScrollbar *) scrollPtr;
   165    169       register Tk_Window tkwin = scrollPtr->tkwin;
   166    170       TkWindow *winPtr = (TkWindow *) tkwin;
   167    171       TkMacOSXDrawingContext dc;
   168    172   
   169    173       scrollPtr->flags &= ~REDRAW_PENDING;
   170    174   
   171    175       if (tkwin == NULL || !Tk_IsMapped(tkwin)) {
   172         -  	return;
          176  +	return;
   173    177       }
   174    178   
   175         -    MacDrawable *macWin =  (MacDrawable *) winPtr->window;
          179  +    MacDrawable *macWin = (MacDrawable *) winPtr->window;
   176    180       NSView *view = TkMacOSXDrawableView(macWin);
   177         -    if (!view ||
   178         -	macWin->flags & TK_DO_NOT_DRAW ||
   179         -	!TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
   180         -      return;
          181  +
          182  +    if ((view == NULL)
          183  +	    || (macWin->flags & TK_DO_NOT_DRAW)
          184  +	    || !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) {
          185  +	return;
   181    186       }
   182    187   
   183    188       CGFloat viewHeight = [view bounds].size.height;
   184         -    CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
   185         -			    .ty = viewHeight};
          189  +    CGAffineTransform t = {
          190  +	.a = 1, .b = 0,
          191  +	.c = 0, .d = -1,
          192  +	.tx = 0, .ty = viewHeight
          193  +    };
          194  +
   186    195       CGContextConcatCTM(dc.context, t);
   187    196   
   188         -    /*Draw a 3D rectangle to provide a base for the native scrollbar.*/
          197  +    /*
          198  +     * Draw a 3D rectangle to provide a base for the native scrollbar.
          199  +     */
          200  +
   189    201       if (scrollPtr->highlightWidth != 0) {
   190    202       	GC fgGC, bgGC;
   191    203   
   192    204       	bgGC = Tk_GCForColor(scrollPtr->highlightBgColorPtr, (Pixmap) macWin);
   193    205       	if (scrollPtr->flags & GOT_FOCUS) {
   194    206       	    fgGC = Tk_GCForColor(scrollPtr->highlightColorPtr, (Pixmap) macWin);
   195    207       	} else {
   196    208       	    fgGC = bgGC;
   197    209       	}
   198    210       	TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth,
   199         -    			       (Pixmap) macWin);
          211  +    		(Pixmap) macWin);
   200    212       }
   201    213   
   202    214       Tk_Draw3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder,
   203         -    		       scrollPtr->highlightWidth, scrollPtr->highlightWidth,
   204         -    		       Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
   205         -    		       Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
   206         -    		       scrollPtr->borderWidth, scrollPtr->relief);
          215  +	    scrollPtr->highlightWidth, scrollPtr->highlightWidth,
          216  +	    Tk_Width(tkwin) - 2*scrollPtr->highlightWidth,
          217  +	    Tk_Height(tkwin) - 2*scrollPtr->highlightWidth,
          218  +	    scrollPtr->borderWidth, scrollPtr->relief);
   207    219       Tk_Fill3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder,
   208         -    		       scrollPtr->inset, scrollPtr->inset,
   209         -    		       Tk_Width(tkwin) - 2*scrollPtr->inset,
   210         -    		       Tk_Height(tkwin) - 2*scrollPtr->inset, 0, TK_RELIEF_FLAT);
          220  +	    scrollPtr->inset, scrollPtr->inset,
          221  +	    Tk_Width(tkwin) - 2*scrollPtr->inset,
          222  +	    Tk_Height(tkwin) - 2*scrollPtr->inset, 0, TK_RELIEF_FLAT);
   211    223   
   212         -    /* Update values and then draw the native scrollbar over the rectangle.*/
          224  +    /*
          225  +     * Update values and then draw the native scrollbar over the rectangle.
          226  +     */
          227  +
   213    228       UpdateControlValues(scrollPtr);
   214    229   
   215    230       if (SNOW_LEOPARD_STYLE) {
   216         -	HIThemeDrawTrack (&(msPtr->info), 0, dc.context, kHIThemeOrientationInverted);
          231  +	HIThemeDrawTrack(&msPtr->info, 0, dc.context,
          232  +		kHIThemeOrientationInverted);
   217    233       } else {
   218         -	HIThemeDrawTrack (&(msPtr->info), 0, dc.context, kHIThemeOrientationNormal);
          234  +	HIThemeDrawTrack(&msPtr->info, 0, dc.context,
          235  +		kHIThemeOrientationNormal);
   219    236       }
   220    237       TkMacOSXRestoreDrawingContext(&dc);
   221    238   
   222    239       scrollPtr->flags &= ~REDRAW_PENDING;
   223    240   }
   224         -
          241  +
   225    242   /*
   226    243    *----------------------------------------------------------------------
   227    244    *
   228    245    * TkpComputeScrollbarGeometry --
   229    246    *
   230    247    *	After changes in a scrollbar's size or configuration, this procedure
   231    248    *	recomputes various geometry information used in displaying the
................................................................................
   236    253    *
   237    254    * Side effects:
   238    255    *	The scrollbar will be displayed differently.
   239    256    *
   240    257    *----------------------------------------------------------------------
   241    258    */
   242    259   
   243         -
   244         -
   245    260   extern void
   246    261   TkpComputeScrollbarGeometry(
   247    262       register TkScrollbar *scrollPtr)
   248         -                           /* Scrollbar whose geometry may have
   249         -                           * changed. */
          263  +				/* Scrollbar whose geometry may have
          264  +				 * changed. */
   250    265   {
   251         -
   252         -   /*
   253         -    * The code below is borrowed from tkUnixScrlbr.c but has been adjusted to
   254         -    * account for some differences between macOS and X11. The Unix scrollbar
   255         -    * has an arrow button on each end.  On macOS 10.6 (Snow Leopard) the
   256         -    * scrollbars by default have both arrow buttons at the bottom or right.
   257         -    * (There is a preferences setting to use the Unix layout, but we are not
   258         -    * supporting that!)  On more recent versions of macOS there are no arrow
   259         -    * buttons at all. The case of no arrow buttons can be handled as a special
   260         -    * case of having both buttons at the end, but where scrollPtr->arrowLength
   261         -    * happens to be zero.  To adjust for having both arrows at the same end we
   262         -    * shift the scrollbar up by the arrowLength.
   263         -    */
          266  +    /*
          267  +     * The code below is borrowed from tkUnixScrlbr.c but has been adjusted to
          268  +     * account for some differences between macOS and X11. The Unix scrollbar
          269  +     * has an arrow button on each end.  On macOS 10.6 (Snow Leopard) the
          270  +     * scrollbars by default have both arrow buttons at the bottom or right.
          271  +     * (There is a preferences setting to use the Unix layout, but we are not
          272  +     * supporting that!)  On more recent versions of macOS there are no arrow
          273  +     * buttons at all. The case of no arrow buttons can be handled as a special
          274  +     * case of having both buttons at the end, but where scrollPtr->arrowLength
          275  +     * happens to be zero.  To adjust for having both arrows at the same end we
          276  +     * shift the scrollbar up by the arrowLength.
          277  +     */
   264    278   
   265    279       int fieldLength;
   266    280   
   267    281       if (scrollPtr->highlightWidth < 0) {
   268         -       scrollPtr->highlightWidth = 0;
          282  +	scrollPtr->highlightWidth = 0;
   269    283       }
   270    284       scrollPtr->inset = scrollPtr->highlightWidth + scrollPtr->borderWidth;
   271    285       if ([NSApp macMinorVersion] == 6) {
   272         -      scrollPtr->arrowLength = scrollPtr->width;
          286  +	scrollPtr->arrowLength = scrollPtr->width;
   273    287       } else {
   274         -      scrollPtr->arrowLength = 0;
          288  +	scrollPtr->arrowLength = 0;
   275    289       }
   276    290       fieldLength = (scrollPtr->vertical ? Tk_Height(scrollPtr->tkwin)
   277         -           : Tk_Width(scrollPtr->tkwin))
   278         -           - 2*(scrollPtr->arrowLength + scrollPtr->inset);
          291  +	    : Tk_Width(scrollPtr->tkwin))
          292  +	    - 2*(scrollPtr->arrowLength + scrollPtr->inset);
   279    293       if (fieldLength < 0) {
   280         -       fieldLength = 0;
          294  +	fieldLength = 0;
   281    295       }
   282    296       scrollPtr->sliderFirst = fieldLength*scrollPtr->firstFraction;
   283    297       scrollPtr->sliderLast = fieldLength*scrollPtr->lastFraction;
   284    298   
   285    299       /*
   286    300        * Adjust the slider so that some piece of it is always displayed in the
   287    301        * scrollbar and so that it has at least a minimal width (so it can be
   288    302        * grabbed with the mouse).
   289    303        */
   290    304   
   291    305       if (scrollPtr->sliderFirst > fieldLength - MIN_SLIDER_LENGTH) {
   292         -       scrollPtr->sliderFirst = fieldLength - MIN_SLIDER_LENGTH;
          306  +	scrollPtr->sliderFirst = fieldLength - MIN_SLIDER_LENGTH;
   293    307       }
   294    308       if (scrollPtr->sliderFirst < 0) {
   295         -       scrollPtr->sliderFirst = 0;
          309  +	scrollPtr->sliderFirst = 0;
   296    310       }
   297    311       if (scrollPtr->sliderLast < scrollPtr->sliderFirst + MIN_SLIDER_LENGTH) {
   298         -       scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH;
          312  +	scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH;
   299    313       }
   300    314       if (scrollPtr->sliderLast > fieldLength) {
   301         -       scrollPtr->sliderLast = fieldLength;
          315  +	scrollPtr->sliderLast = fieldLength;
   302    316       }
   303    317       scrollPtr->sliderFirst += -scrollPtr->arrowLength + scrollPtr->inset;
   304    318       scrollPtr->sliderLast += scrollPtr->inset;
   305    319   
   306    320       /*
   307    321        * Register the desired geometry for the window. Leave enough space for the
   308    322        * two arrows, if there are any arrows, plus a minimum-size slider, plus
   309    323        * border around the whole window, if any. Then arrange for the window to
   310    324        * be redisplayed.
   311    325        */
   312    326   
   313         -      if (scrollPtr->vertical) {
   314         -       Tk_GeometryRequest(scrollPtr->tkwin,
   315         -              scrollPtr->width + 2*scrollPtr->inset,
   316         -              2*(scrollPtr->arrowLength + scrollPtr->borderWidth
   317         -              + scrollPtr->inset) + metrics.minThumbHeight);
          327  +    if (scrollPtr->vertical) {
          328  +	Tk_GeometryRequest(scrollPtr->tkwin,
          329  +		scrollPtr->width + 2*scrollPtr->inset,
          330  +		2*(scrollPtr->arrowLength + scrollPtr->borderWidth
          331  +		+ scrollPtr->inset) + metrics.minThumbHeight);
   318    332       } else {
   319         -       Tk_GeometryRequest(scrollPtr->tkwin,
   320         -              2*(scrollPtr->arrowLength + scrollPtr->borderWidth
   321         -              + scrollPtr->inset) + metrics.minThumbHeight,
   322         -              scrollPtr->width + 2*scrollPtr->inset);
          333  +	Tk_GeometryRequest(scrollPtr->tkwin,
          334  +		2*(scrollPtr->arrowLength + scrollPtr->borderWidth
          335  +		+ scrollPtr->inset) + metrics.minThumbHeight,
          336  +		scrollPtr->width + 2*scrollPtr->inset);
   323    337       }
   324    338       Tk_SetInternalBorder(scrollPtr->tkwin, scrollPtr->inset);
   325    339   }
   326         -
          340  +
   327    341   /*
   328    342    *----------------------------------------------------------------------
   329    343    *
   330    344    * TkpDestroyScrollbar --
   331    345    *
   332    346    *	Free data structures associated with the scrollbar control.
   333    347    *
................................................................................
   338    352    *	Frees the GCs associated with the scrollbar.
   339    353    *
   340    354    *----------------------------------------------------------------------
   341    355    */
   342    356   
   343    357   void
   344    358   TkpDestroyScrollbar(
   345         -		    TkScrollbar *scrollPtr)
          359  +    TkScrollbar *scrollPtr)
   346    360   {
   347         -    MacScrollbar *macScrollPtr = (MacScrollbar *)scrollPtr;
          361  +    MacScrollbar *macScrollPtr = (MacScrollbar *) scrollPtr;
   348    362   
   349    363       if (macScrollPtr->troughGC != None) {
   350    364   	Tk_FreeGC(scrollPtr->display, macScrollPtr->troughGC);
   351    365       }
   352    366       if (macScrollPtr->copyGC != None) {
   353    367   	Tk_FreeGC(scrollPtr->display, macScrollPtr->copyGC);
   354    368       }
   355    369   }
   356         -
          370  +
   357    371   /*
   358    372    *----------------------------------------------------------------------
   359    373    *
   360    374    * TkpConfigureScrollbar --
   361    375    *
   362         - *	This procedure is called after the generic code has finished
   363         - *	processing configuration options, in order to configure platform
   364         - *	specific options.  There are no such option on the Mac, however.
          376  + *	This procedure is called after the generic code has finished processing
          377  + *	configuration options, in order to configure platform specific options.
          378  + *	There are no such option on the Mac, however.
   365    379    *
   366    380    * Results:
   367    381    *	None.
   368    382    *
   369    383    * Side effects:
   370    384    *	Currently, none.
   371    385    *
   372    386    *----------------------------------------------------------------------
   373    387    */
   374    388   
   375    389   void
   376    390   TkpConfigureScrollbar(
   377         -		      register TkScrollbar *scrollPtr)
          391  +    register TkScrollbar *scrollPtr)
   378    392   {
   379         -
          393  +    /* empty */
   380    394   }
   381         -
          395  +
   382    396   /*
   383    397    *--------------------------------------------------------------
   384    398    *
   385    399    * TkpScrollbarPosition --
   386    400    *
   387    401    *	Determine the scrollbar element corresponding to a given position.
   388    402    *
................................................................................
   399    413   
   400    414   int
   401    415   TkpScrollbarPosition(
   402    416       register TkScrollbar *scrollPtr,
   403    417   				/* Scrollbar widget record. */
   404    418       int x, int y)		/* Coordinates within scrollPtr's window. */
   405    419   {
   406         -
   407         -   /*
   408         -   * The code below is borrowed from tkUnixScrlbr.c and needs no adjustment
   409         -   * since it does not involve the arrow buttons.
   410         -   */
          420  +    /*
          421  +     * The code below is borrowed from tkUnixScrlbr.c and needs no adjustment
          422  +     * since it does not involve the arrow buttons.
          423  +     */
   411    424   
   412    425       int length, width, tmp;
   413    426       register const int inset = scrollPtr->inset;
   414    427   
   415    428       if (scrollPtr->vertical) {
   416         -  	length = Tk_Height(scrollPtr->tkwin);
   417         -  	width = Tk_Width(scrollPtr->tkwin);
          429  +	length = Tk_Height(scrollPtr->tkwin);
          430  +	width = Tk_Width(scrollPtr->tkwin);
   418    431       } else {
   419         -  	tmp = x;
   420         -  	x = y;
   421         -  	y = tmp;
   422         -  	length = Tk_Width(scrollPtr->tkwin);
   423         -  	width = Tk_Height(scrollPtr->tkwin);
          432  +	tmp = x;
          433  +	x = y;
          434  +	y = tmp;
          435  +	length = Tk_Width(scrollPtr->tkwin);
          436  +	width = Tk_Height(scrollPtr->tkwin);
   424    437       }
   425    438   
   426    439       if (x < inset || x >= width - inset ||
   427         -	y < inset || y >= length - inset) {
   428         -  	return OUTSIDE;
          440  +	    y < inset || y >= length - inset) {
          441  +	return OUTSIDE;
   429    442       }
   430    443   
   431    444       /*
   432    445        * Here we assume that the scrollbar is layed out with both arrow buttons
   433    446        * at the bottom (or right).  Except on 10.6, however, the arrows do not
   434    447        * actually exist, i.e. the arrowLength is 0.  These are the same
   435    448        * assumptions which are being made in TkpComputeScrollbarGeometry.
   436    449        */
   437    450   
   438    451       if (y < scrollPtr->sliderFirst + scrollPtr->arrowLength) {
   439         -  	return TOP_GAP;
   440         -      }
   441         -      if (y < scrollPtr->sliderLast) {
   442         -  	return SLIDER;
   443         -      }
   444         -      if (y < length - (2*scrollPtr->arrowLength + inset)) {
   445         -  	return BOTTOM_GAP;
   446         -      }
   447         -      /* On systems newer than 10.6 we have already returned. */
   448         -      if (y < length - (scrollPtr->arrowLength + inset)) {
   449         -  	return TOP_ARROW;
   450         -      }
   451         -      return BOTTOM_ARROW;
          452  +	return TOP_GAP;
          453  +    }
          454  +    if (y < scrollPtr->sliderLast) {
          455  +	return SLIDER;
          456  +    }
          457  +    if (y < length - (2*scrollPtr->arrowLength + inset)) {
          458  +	return BOTTOM_GAP;
          459  +    }
          460  +
          461  +    /*
          462  +     * On systems newer than 10.6 we have already returned.
          463  +     */
          464  +
          465  +    if (y < length - (scrollPtr->arrowLength + inset)) {
          466  +	return TOP_ARROW;
          467  +    }
          468  +    return BOTTOM_ARROW;
   452    469   }
   453         -
          470  +
   454    471   /*
   455    472    *--------------------------------------------------------------
   456    473    *
   457    474    * UpdateControlValues --
   458    475    *
   459         - *	This procedure updates the Macintosh scrollbar control to
   460         - *	display the values defined by the Tk scrollbar. This is the
   461         - *	key interface to the Mac-native  scrollbar; the Unix bindings
   462         - *	drive scrolling in the Tk window and all the Mac scrollbar has
   463         - *	to do is redraw itself.
          476  + *	This procedure updates the Macintosh scrollbar control to display the
          477  + *	values defined by the Tk scrollbar. This is the key interface to the
          478  + *	Mac-native scrollbar; the Unix bindings drive scrolling in the Tk
          479  + *	window and all the Mac scrollbar has to do is redraw itself.
   464    480    *
   465    481    * Results:
   466    482    *	None.
   467    483    *
   468    484    * Side effects:
   469    485    *	The Macintosh control is updated.
   470    486    *
   471    487    *--------------------------------------------------------------
   472    488    */
   473    489   
   474    490   static void
   475    491   UpdateControlValues(
   476         -		    TkScrollbar *scrollPtr)		/* Scrollbar data struct. */
          492  +    TkScrollbar *scrollPtr)		/* Scrollbar data struct. */
   477    493   {
   478         -    MacScrollbar *msPtr = (MacScrollbar *)scrollPtr;
          494  +    MacScrollbar *msPtr = (MacScrollbar *) scrollPtr;
   479    495       Tk_Window tkwin = scrollPtr->tkwin;
   480    496       MacDrawable *macWin = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin);
   481    497       double dViewSize;
   482         -    HIRect  contrlRect;
          498  +    HIRect contrlRect;
   483    499       short width, height;
   484    500   
   485    501       NSView *view = TkMacOSXDrawableView(macWin);
   486    502       CGFloat viewHeight = [view bounds].size.height;
   487    503       NSRect frame;
          504  +
   488    505       frame = NSMakeRect(macWin->xOff, macWin->yOff, Tk_Width(tkwin),
   489         -		       Tk_Height(tkwin));
          506  +	    Tk_Height(tkwin));
   490    507       frame = NSInsetRect(frame, scrollPtr->inset, scrollPtr->inset);
   491    508       frame.origin.y = viewHeight - (frame.origin.y + frame.size.height);
   492    509   
   493    510       contrlRect = NSRectToCGRect(frame);
   494    511       msPtr->info.bounds = contrlRect;
   495    512   
   496    513       width = contrlRect.size.width;
................................................................................
   499    516       /*
   500    517        * Ensure we set scrollbar control bounds only once all size adjustments
   501    518        * have been computed.
   502    519        */
   503    520   
   504    521       msPtr->info.bounds = contrlRect;
   505    522       if (scrollPtr->vertical) {
   506         -      msPtr->info.attributes &= ~kThemeTrackHorizontal;
          523  +	msPtr->info.attributes &= ~kThemeTrackHorizontal;
   507    524       } else {
   508         -      msPtr->info.attributes |= kThemeTrackHorizontal;
          525  +	msPtr->info.attributes |= kThemeTrackHorizontal;
   509    526       }
   510    527   
   511    528       /*
   512    529        * Given the Tk parameters for the fractions of the start and end of the
   513    530        * thumb, the following calculation determines the location for the
   514    531        * Macintosh thumb. The Aqua scroll control works as follows. The
   515    532        * scrollbar's value is the position of the left (or top) side of the view
   516    533        * area in the content area being scrolled. The maximum value of the
   517    534        * control is therefore the dimension of the content area less the size of
   518    535        * the view area.
   519    536        */
   520    537   
   521         -    double maximum = 100,  factor;
   522         -    factor = RangeToFactor(maximum);
   523         -    dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction)
   524         -	* factor;
   525         -    msPtr->info.max =  MIN_SCROLLBAR_VALUE +
   526         -	factor - dViewSize;
          538  +    double maximum = 100, factor = RangeToFactor(maximum);
          539  +
          540  +    dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction) * factor;
          541  +    msPtr->info.max = MIN_SCROLLBAR_VALUE + factor - dViewSize;
   527    542       msPtr->info.trackInfo.scrollbar.viewsize = dViewSize;
   528    543       if (scrollPtr->vertical) {
   529         -      if (SNOW_LEOPARD_STYLE) {
   530         -	msPtr->info.value = factor * scrollPtr->firstFraction;
   531         -      } else {
   532         -	msPtr->info.value = msPtr->info.max - factor * scrollPtr->firstFraction;
   533         -      }
          544  +	if (SNOW_LEOPARD_STYLE) {
          545  +	    msPtr->info.value = factor * scrollPtr->firstFraction;
          546  +	} else {
          547  +	    msPtr->info.value = msPtr->info.max -
          548  +		    factor * scrollPtr->firstFraction;
          549  +	}
   534    550       } else {
   535         -	 msPtr->info.value =  MIN_SCROLLBAR_VALUE + factor * scrollPtr->firstFraction;
          551  +	msPtr->info.value = MIN_SCROLLBAR_VALUE +
          552  +		factor * scrollPtr->firstFraction;
   536    553       }
   537    554   
   538         -    if((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0)
   539         -       || height <= metrics.minHeight) {
          555  +    if ((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0)
          556  +	    || height <= metrics.minHeight) {
   540    557       	msPtr->info.enableState = kThemeTrackHideTrack;
   541    558       } else {
   542    559           msPtr->info.enableState = kThemeTrackActive;
   543         -    	msPtr->info.attributes = kThemeTrackShowThumb |  kThemeTrackThumbRgnIsNotGhost;
          560  +    	msPtr->info.attributes =
          561  +		kThemeTrackShowThumb | kThemeTrackThumbRgnIsNotGhost;
   544    562       }
   545         -
   546    563   }
   547         -
          564  +
   548    565   /*
   549    566    *--------------------------------------------------------------
   550    567    *
   551    568    * ScrollbarEvent --
   552    569    *
   553         - *	This procedure is invoked in response to <ButtonPress>, <ButtonRelease>,
   554         - *      <EnterNotify>, and <LeaveNotify> events. The Scrollbar appearance is
   555         - *      modified for each event.
          570  + *	This procedure is invoked in response to <ButtonPress>,
          571  + *      <ButtonRelease>, <EnterNotify>, and <LeaveNotify> events.  The
          572  + *      Scrollbar appearance is modified for each event.
   556    573    *
   557    574    *--------------------------------------------------------------
   558    575    */
   559    576   
   560    577   static int
   561         -ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr)
          578  +ScrollbarEvent(
          579  +    TkScrollbar *scrollPtr,
          580  +    XEvent *eventPtr)
   562    581   {
   563         -    MacScrollbar *msPtr = (MacScrollbar *)scrollPtr;
          582  +    MacScrollbar *msPtr = (MacScrollbar *) scrollPtr;
   564    583   
   565         -    /* The pressState does not indicate whether the moused button was
   566         -     * pressed at some location in the Scrollbar.  Rather, it indicates
   567         -     * that the scrollbar should appear as if it were pressed in that
   568         -     * location. The standard Mac behavior is that once the button is
   569         -     * pressed inside the Scrollbar the appearance should not change until
   570         -     * the button is released, even if the mouse moves outside of the
   571         -     * scrollbar.  However, if the mouse lies over the scrollbar but the
   572         -     * button is not pressed then the appearance should be the same as if
   573         -     * the button had been pressed on the slider, i.e. kThemeThumbPressed.
   574         -     * See the file Appearance.r, or HIToolbox.bridgesupport on 10.14.
          584  +    /*
          585  +     * The pressState does not indicate whether the moused button was pressed
          586  +     * at some location in the Scrollbar.  Rather, it indicates that the
          587  +     * scrollbar should appear as if it were pressed in that location. The
          588  +     * standard Mac behavior is that once the button is pressed inside the
          589  +     * Scrollbar the appearance should not change until the button is released,
          590  +     * even if the mouse moves outside of the scrollbar.  However, if the mouse
          591  +     * lies over the scrollbar but the button is not pressed then the
          592  +     * appearance should be the same as if the button had been pressed on the
          593  +     * slider, i.e. kThemeThumbPressed.  See the file Appearance.r, or
          594  +     * HIToolbox.bridgesupport on 10.14.
   575    595        */
   576    596   
   577    597       if (eventPtr->type == ButtonPress) {
   578    598   	msPtr->buttonDown = true;
   579    599   	UpdateControlValues(scrollPtr);
          600  +
   580    601   	int where = TkpScrollbarPosition(scrollPtr,
   581         -					 eventPtr->xbutton.x,
   582         -					 eventPtr->xbutton.y);
   583         -	switch(where) {
          602  +		eventPtr->xbutton.x, eventPtr->xbutton.y);
          603  +
          604  +	switch (where) {
   584    605   	case OUTSIDE:
   585    606   	    msPtr->info.trackInfo.scrollbar.pressState = 0;
   586    607   	    break;
   587    608   	case TOP_GAP:
   588    609   	    msPtr->info.trackInfo.scrollbar.pressState = kThemeTopTrackPressed;
   589    610   	    break;
   590    611   	case SLIDER:
   591    612   	    msPtr->info.trackInfo.scrollbar.pressState = kThemeThumbPressed;
   592    613   	    break;
   593    614   	case BOTTOM_GAP:
   594         -	    msPtr->info.trackInfo.scrollbar.pressState = kThemeBottomTrackPressed;
          615  +	    msPtr->info.trackInfo.scrollbar.pressState =
          616  +		    kThemeBottomTrackPressed;
   595    617   	    break;
   596    618   	case TOP_ARROW:
   597         -	    /* This looks wrong and the docs say it is wrong but it works. */
   598         -	    msPtr->info.trackInfo.scrollbar.pressState = kThemeTopInsideArrowPressed;
          619  +	    /*
          620  +	     * This looks wrong and the docs say it is wrong but it works.
          621  +	     */
          622  +
          623  +	    msPtr->info.trackInfo.scrollbar.pressState =
          624  +		    kThemeTopInsideArrowPressed;
   599    625   	    break;
   600    626   	case BOTTOM_ARROW:
   601         -	    msPtr->info.trackInfo.scrollbar.pressState = kThemeBottomOutsideArrowPressed;
          627  +	    msPtr->info.trackInfo.scrollbar.pressState =
          628  +		    kThemeBottomOutsideArrowPressed;
   602    629   	    break;
   603    630   	}
   604    631       }
   605    632       if (eventPtr->type == ButtonRelease) {
   606    633   	msPtr->buttonDown = false;
   607    634   	if (!msPtr->mouseOver) {
   608    635   	    msPtr->info.trackInfo.scrollbar.pressState = 0;
................................................................................
   618    645   	msPtr->mouseOver = false;
   619    646   	if (!msPtr->buttonDown) {
   620    647   	    msPtr->info.trackInfo.scrollbar.pressState = 0;
   621    648   	}
   622    649       }
   623    650       return TCL_OK;
   624    651   }
   625         -
   626         -
   627         -
          652  +
   628    653   /*
   629    654    *--------------------------------------------------------------
   630    655    *
   631    656    * ScrollbarEventProc --
   632    657    *
   633    658    *	This procedure is invoked by the Tk dispatcher for various events on
   634    659    *	scrollbars.
................................................................................
   641    666    *	it gets exposed, it is redisplayed.
   642    667    *
   643    668    *--------------------------------------------------------------
   644    669    */
   645    670   
   646    671   static void
   647    672   ScrollbarEventProc(
   648         -		   ClientData clientData,	/* Information about window. */
   649         -		   XEvent *eventPtr)		/* Information about event. */
          673  +    ClientData clientData,	/* Information about window. */
          674  +    XEvent *eventPtr)		/* Information about event. */
   650    675   {
   651    676       TkScrollbar *scrollPtr = clientData;
   652    677   
   653    678       switch (eventPtr->type) {
   654    679       case UnmapNotify:
   655    680   	TkMacOSXSetScrollbarGrow((TkWindow *) scrollPtr->tkwin, false);
   656    681   	break;
................................................................................
   664    689       case LeaveNotify:
   665    690       	ScrollbarEvent(clientData, eventPtr);
   666    691   	break;
   667    692       default:
   668    693   	TkScrollbarEventProc(clientData, eventPtr);
   669    694       }
   670    695   }
   671         -
          696  +
   672    697   /*
   673    698    * Local Variables:
   674    699    * mode: objc
   675    700    * c-basic-offset: 4
   676    701    * fill-column: 79
   677    702    * coding: utf-8
   678    703    * End:
   679    704    */

Changes to macosx/tkMacOSXSend.c.

    47     47   				 * list. */
    48     48   } RegisteredInterp;
    49     49   
    50     50   /*
    51     51    * A registry of all interpreters for a display is kept in a property
    52     52    * "InterpRegistry" on the root window of the display. It is organized as a
    53     53    * series of zero or more concatenated strings (in no particular order), each
    54         - * of the form
           54  + * of the form:
    55     55    *	window space name '\0'
    56     56    * where "window" is the hex id of the comm. window to use to talk to an
    57     57    * interpreter named "name".
    58     58    *
    59     59    * When the registry is being manipulated by an application (e.g. to add or
    60     60    * remove an entry), it is loaded into memory using a structure of the
    61     61    * following type:
................................................................................
    74     74   				 * none. See format description above; this is
    75     75   				 * *not* terminated by the first null
    76     76   				 * character. Dynamically allocated. */
    77     77       int allocedByX;		/* Non-zero means must free property with
    78     78   				 * XFree; zero means use ckfree. */
    79     79   } NameRegistry;
    80     80   
    81         -static int initialized = 0; /* A flag to denote if we have initialized
           81  +static int initialized = 0;	/* A flag to denote if we have initialized
    82     82   				 * yet. */
    83     83   
    84     84   static RegisteredInterp *interpListPtr = NULL;
    85     85   				/* List of all interpreters registered by this
    86     86   				 * process. */
    87     87   
    88     88   /*

Changes to macosx/tkMacOSXSubwindows.c.

    61     61        * deleting is being tracked by the grab code.
    62     62        */
    63     63   
    64     64       TkPointerDeadWindow(macWin->winPtr);
    65     65       TkMacOSXSelDeadWindow(macWin->winPtr);
    66     66       macWin->toplevel->referenceCount--;
    67     67   
    68         -    if (!Tk_IsTopLevel(macWin->winPtr) ) {
           68  +    if (!Tk_IsTopLevel(macWin->winPtr)) {
    69     69   	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
    70     70   	if (macWin->winPtr->parentPtr != NULL) {
    71     71   	    TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
    72     72   	}
    73     73   	if (macWin->visRgn) {
    74     74   	    CFRelease(macWin->visRgn);
    75     75   	}
................................................................................
   147    147       display->request++;
   148    148       macWin->winPtr->flags |= TK_MAPPED;
   149    149       if (Tk_IsTopLevel(macWin->winPtr)) {
   150    150   	if (!Tk_IsEmbedded(macWin->winPtr)) {
   151    151   	    NSWindow *win = TkMacOSXDrawableWindow(window);
   152    152   
   153    153   	    /*
   154         -	     * We want to activate Tk when a toplevel is mapped
   155         -	     * but we must not supply YES here.  This is because
   156         -	     * during Tk initialization the root window is mapped
   157         -	     * before applicationDidFinishLaunching returns. Forcing
   158         -	     * the app to activate too early can make the menu bar
   159         -	     * unresponsive.
          154  +	     * We want to activate Tk when a toplevel is mapped but we must not
          155  +	     * supply YES here.  This is because during Tk initialization the
          156  +	     * root window is mapped before applicationDidFinishLaunching
          157  +	     * returns. Forcing the app to activate too early can make the menu
          158  +	     * bar unresponsive.
   160    159   	     */
   161    160   
   162    161   	    TkMacOSXApplyWindowAttributes(macWin->winPtr, win);
   163    162   	    [win setExcludedFromWindowsMenu:NO];
   164    163   	    [NSApp activateIgnoringOtherApps:NO];
   165    164   	    [[win contentView] setNeedsDisplay:YES];
   166         -	    if ( [win canBecomeKeyWindow] ) {
          165  +	    if ([win canBecomeKeyWindow]) {
   167    166   		[win makeKeyAndOrderFront:NSApp];
   168    167   	    } else {
   169    168   		[win orderFrontRegardless];
   170    169   	    }
   171    170   	    
   172    171   	    /*
   173    172   	     * In some cases the toplevel will not be drawn unless we process
................................................................................
   181    180   
   182    181   	    /*
   183    182   	     * Rebuild the container's clipping region and display
   184    183   	     * the window.
   185    184   	     */
   186    185   
   187    186   	    TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr);
   188         -	    TkMacOSXInvalClipRgns((Tk_Window)contWinPtr);
          187  +
          188  +	    TkMacOSXInvalClipRgns((Tk_Window) contWinPtr);
   189    189   	    TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
   190    190   	}
   191    191   	TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr);
   192    192   
   193    193   	/*
   194    194   	 * We only need to send the MapNotify event for toplevel windows.
   195    195   	 */
................................................................................
   199    199   	event.xany.display = display;
   200    200   
   201    201   	event.xmap.window = window;
   202    202   	event.xmap.type = MapNotify;
   203    203   	event.xmap.event = window;
   204    204   	event.xmap.override_redirect = macWin->winPtr->atts.override_redirect;
   205    205   	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
   206         -
   207    206       } else {
   208         -
   209    207   	/*
   210    208   	 * Rebuild the parent's clipping region and display the window.
   211         -	 *
   212    209   	 */
   213    210   
   214    211   	TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr);
   215    212   	TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW);
   216    213       }
   217    214   
   218    215       /*
................................................................................
   294    291       XEvent event;
   295    292   
   296    293       display->request++;
   297    294       if (Tk_IsTopLevel(winPtr)) {
   298    295   	if (!Tk_IsEmbedded(winPtr) &&
   299    296   		winPtr->wmInfoPtr->hints.initial_state!=IconicState) {
   300    297   	    NSWindow *win = TkMacOSXDrawableWindow(window);
          298  +
   301    299   	    [win orderOut:nil];
   302    300   	}
   303    301   	TkMacOSXInvalClipRgns((Tk_Window) winPtr);
   304    302   
   305    303   	/*
   306    304   	 * We only need to send the UnmapNotify event for toplevel windows.
   307    305   	 */
................................................................................
   312    310   
   313    311   	event.xunmap.type = UnmapNotify;
   314    312   	event.xunmap.window = window;
   315    313   	event.xunmap.event = window;
   316    314   	event.xunmap.from_configure = false;
   317    315   	Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
   318    316       } else {
   319         -
   320    317   	/*
   321    318   	 * Rebuild the visRgn clip region for the parent so it will be allowed
   322    319   	 * to draw in the space from which this subwindow was removed.
   323    320   	 */
   324    321   
   325    322   	if (parentPtr && parentPtr->privatePtr->visRgn) {
   326         -	    TkMacOSXInvalidateViewRegion(TkMacOSXDrawableView(parentPtr->privatePtr),
   327         -					 parentPtr->privatePtr->visRgn);
          323  +	    TkMacOSXInvalidateViewRegion(
          324  +		    TkMacOSXDrawableView(parentPtr->privatePtr),
          325  +		    parentPtr->privatePtr->visRgn);
   328    326   	}
   329    327   	TkMacOSXInvalClipRgns((Tk_Window) parentPtr);
   330    328   	TkMacOSXUpdateClipRgn(parentPtr);
   331    329       }
   332    330       winPtr->flags &= ~TK_MAPPED;
   333    331   }
   334    332   
................................................................................
   353    351   XResizeWindow(
   354    352       Display *display,		/* Display. */
   355    353       Window window,		/* Window. */
   356    354       unsigned int width,
   357    355       unsigned int height)
   358    356   {
   359    357       MacDrawable *macWin = (MacDrawable *) window;
          358  +
   360    359       display->request++;
   361    360       if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
   362    361   	NSWindow *w = macWin->winPtr->wmInfoPtr->window;
          362  +
   363    363   	if (w) {
   364    364   	    NSRect r = [w contentRectForFrameRect:[w frame]];
          365  +
   365    366   	    r.origin.y += r.size.height - height;
   366    367   	    r.size.width = width;
   367    368   	    r.size.height = height;
   368    369   	    [w setFrame:[w frameRectForContentRect:r] display:YES];
   369    370   	}
   370    371       } else {
   371    372   	MoveResizeWindow(macWin);
................................................................................
   373    374   }
   374    375   
   375    376   /*
   376    377    *----------------------------------------------------------------------
   377    378    *
   378    379    * XMoveResizeWindow --
   379    380    *
   380         - *	Move or resize a given X window. See X windows documentation
   381         - *	for further details.
          381  + *	Move or resize a given X window. See X windows documentation for
          382  + *	further details.
   382    383    *
   383    384    * Results:
   384    385    *	None.
   385    386    *
   386    387    * Side effects:
   387    388    *	None.
   388    389    *
................................................................................
   398    399       unsigned int height)
   399    400   {
   400    401       MacDrawable *macWin = (MacDrawable *) window;
   401    402   
   402    403       display->request++;
   403    404       if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
   404    405   	NSWindow *w = macWin->winPtr->wmInfoPtr->window;
          406  +
   405    407   	if (w) {
   406         -
   407         -	    /* We explicitly convert everything to doubles so we don't get
          408  +	    /*
          409  +	     * We explicitly convert everything to doubles so we don't get
   408    410   	     * surprised (again) by what happens when you do arithmetic with
   409    411   	     * unsigned ints.
   410    412   	     */
   411    413   
   412         -	    CGFloat X = (CGFloat)x;
   413         -	    CGFloat Y = (CGFloat)y;
   414         -	    CGFloat Width = (CGFloat)width;
   415         -	    CGFloat Height = (CGFloat)height;
   416         -	    CGFloat XOff = (CGFloat)macWin->winPtr->wmInfoPtr->xInParent;
   417         -	    CGFloat YOff = (CGFloat)macWin->winPtr->wmInfoPtr->yInParent;
   418         -	    NSRect r = NSMakeRect(X + XOff,
   419         -	    			  tkMacOSXZeroScreenHeight - Y - YOff - Height,
   420         -	    			  Width, Height);
          414  +	    CGFloat X = (CGFloat) x;
          415  +	    CGFloat Y = (CGFloat) y;
          416  +	    CGFloat Width = (CGFloat) width;
          417  +	    CGFloat Height = (CGFloat) height;
          418  +	    CGFloat XOff = (CGFloat) macWin->winPtr->wmInfoPtr->xInParent;
          419  +	    CGFloat YOff = (CGFloat) macWin->winPtr->wmInfoPtr->yInParent;
          420  +	    NSRect r = NSMakeRect(
          421  +		    X + XOff, tkMacOSXZeroScreenHeight - Y - YOff - Height,
          422  +	    	    Width, Height);
          423  +
   421    424   	    [w setFrame:[w frameRectForContentRect:r] display:YES];
   422    425   	}
   423    426       } else {
   424    427   	MoveResizeWindow(macWin);
   425    428       }
   426    429   }
   427    430   
   428    431   /*
   429    432    *----------------------------------------------------------------------
   430    433    *
   431    434    * XMoveWindow --
   432    435    *
   433         - *	Move a given X window. See X windows documentation for further
   434         - *	details.
          436  + *	Move a given X window. See X windows documentation for further details.
   435    437    *
   436    438    * Results:
   437    439    *	None.
   438    440    *
   439    441    * Side effects:
   440    442    *	None.
   441    443    *
................................................................................
   449    451       int x, int y)
   450    452   {
   451    453       MacDrawable *macWin = (MacDrawable *) window;
   452    454   
   453    455       display->request++;
   454    456       if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
   455    457   	NSWindow *w = macWin->winPtr->wmInfoPtr->window;
          458  +
   456    459   	if (w) {
   457         -	    [w setFrameTopLeftPoint:NSMakePoint(x, tkMacOSXZeroScreenHeight - y)];
          460  +	    [w setFrameTopLeftPoint: NSMakePoint(
          461  +		    x, tkMacOSXZeroScreenHeight - y)];
   458    462   	}
   459    463       } else {
   460    464   	MoveResizeWindow(macWin);
   461    465       }
   462    466   }
   463    467   
   464    468   /*
................................................................................
   491    495   
   492    496       if (Tk_IsEmbedded(macWin->winPtr)) {
   493    497   	TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr);
   494    498   
   495    499   	if (contWinPtr) {
   496    500   	    macParent = contWinPtr->privatePtr;
   497    501   	} else {
   498         -
   499    502   	    /*
   500    503   	     * Here we should handle out of process embedding. At this point,
   501    504   	     * we are assuming that the changes.x,y is not maintained, if you
   502    505   	     * need the info get it from Tk_GetRootCoords, and that the
   503    506   	     * toplevel sits at 0,0 when it is drawn.
   504    507   	     */
   505    508   	}
   506    509       } else {
   507         -
   508    510   	/*
   509    511   	 * TODO: update all xOff & yOffs
   510    512   	 */
   511    513   
   512    514   	macParent = macWin->winPtr->parentPtr->privatePtr;
   513    515   	parentBorderwidth = macWin->winPtr->parentPtr->changes.border_width;
   514    516       }
................................................................................
   592    594   {
   593    595       MacDrawable *macWin = (MacDrawable *) window;
   594    596   
   595    597       display->request++;
   596    598       if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
   597    599   	TkWmRestackToplevel(macWin->winPtr, Above, NULL);
   598    600       } else {
   599         -
   600    601   	/*
   601    602   	 * TODO: this should generate damage
   602    603   	 */
   603    604       }
   604    605   }
   605    606   
   606    607   #if 0
................................................................................
   627    628   {
   628    629       MacDrawable *macWin = (MacDrawable *) window;
   629    630   
   630    631       display->request++;
   631    632       if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) {
   632    633   	TkWmRestackToplevel(macWin->winPtr, Below, NULL);
   633    634       } else {
   634         -
   635    635           /*
   636    636   	 * TODO: this should generate damage
   637    637   	 */
   638    638       }
   639    639   }
   640    640   #endif
   641    641   
................................................................................
   690    690   	Rect bounds;
   691    691   	NSRect r;
   692    692   
   693    693   	if (view) {
   694    694   	    TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr);
   695    695   	    TkMacOSXWinBounds(winPtr, &bounds);
   696    696   	    r = NSMakeRect(bounds.left,
   697         -		[view bounds].size.height - bounds.bottom,
   698         -		bounds.right - bounds.left, bounds.bottom - bounds.top);
          697  +		    [view bounds].size.height - bounds.bottom,
          698  +		    bounds.right - bounds.left, bounds.bottom - bounds.top);
   699    699   	    [view setNeedsDisplayInRect:r];
   700    700   	}
   701    701       }
   702    702   
   703         -    /* TkGenWMMoveRequestEvent(macWin->winPtr,
   704         -	    macWin->winPtr->changes.x, macWin->winPtr->changes.y); */
          703  +#if 0
          704  +    TkGenWMMoveRequestEvent(macWin->winPtr,
          705  +	    macWin->winPtr->changes.x, macWin->winPtr->changes.y);
          706  +#endif
   705    707   }
   706    708   
   707    709   /*
   708    710    *----------------------------------------------------------------------
   709    711    *
   710    712    * TkMacOSXSetDrawingEnabled --
   711    713    *
................................................................................
   719    721    *	The clipping regions for the window and its children are cleared.
   720    722    *
   721    723    *----------------------------------------------------------------------
   722    724    */
   723    725   
   724    726   void
   725    727   TkMacOSXSetDrawingEnabled(
   726         -	TkWindow *winPtr,
   727         -	int flag)
          728  +    TkWindow *winPtr,
          729  +    int flag)
   728    730   {
   729    731       TkWindow *childPtr;
   730    732       MacDrawable *macWin = winPtr->privatePtr;
   731    733   
   732    734       if (macWin) {
   733         -	if (flag ) {
          735  +	if (flag) {
   734    736   	    macWin->flags &= ~TK_DO_NOT_DRAW;
   735    737   	} else {
   736    738   	    macWin->flags |= TK_DO_NOT_DRAW;
   737    739   	}
   738    740       }
   739    741   
   740    742       /*
   741         -     * Set the flag for all children & their descendants, excluding
   742         -     * Toplevels. (??? Do we need to exclude Toplevels?)
          743  +     * Set the flag for all children & their descendants, excluding Toplevels.
          744  +     * (??? Do we need to exclude Toplevels?)
   743    745        */
   744    746   
   745    747       childPtr = winPtr->childList;
   746    748       while (childPtr) {
   747    749   	if (!Tk_IsTopLevel(childPtr)) {
   748    750   	    TkMacOSXSetDrawingEnabled(childPtr, flag);
   749    751   	}
................................................................................
   899    901   		if (!HIShapeIsEmpty(diffRgn)) {
   900    902   		    macWin->visRgn = HIShapeCreateCopy(rgn);
   901    903   		}
   902    904   		CFRelease(diffRgn);
   903    905   	    }
   904    906   	    CFRelease(rgn);
   905    907   	} else {
   906         -
   907    908   	    /*
   908    909   	     * An unmapped window has empty clip regions to prevent any
   909    910   	     * (erroneous) drawing into it or its children from becoming
   910    911   	     * visible. [Bug 940117]
   911    912   	     */
   912    913   
   913    914   	    if (!Tk_IsTopLevel(winPtr)) {
................................................................................
   929    930   
   930    931   /*
   931    932    *----------------------------------------------------------------------
   932    933    *
   933    934    * TkMacOSXVisableClipRgn --
   934    935    *
   935    936    *	This function returns the Macintosh clipping region for the given
   936         - *	window. The caller is responsible for disposing of the returned
   937         - *	region via TkDestroyRegion().
          937  + *	window. The caller is responsible for disposing of the returned region
          938  + *	via TkDestroyRegion().
   938    939    *
   939    940    * Results:
   940    941    *	The region.
   941    942    *
   942    943    * Side effects:
   943    944    *	None.
   944    945    *
................................................................................
   948    949   TkRegion
   949    950   TkMacOSXVisableClipRgn(
   950    951       TkWindow *winPtr)
   951    952   {
   952    953       if (winPtr->privatePtr->flags & TK_CLIP_INVALID) {
   953    954   	TkMacOSXUpdateClipRgn(winPtr);
   954    955       }
   955         -    return (TkRegion)HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn);
          956  +    return (TkRegion) HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn);
   956    957   }
   957    958   
   958    959   /*
   959    960    *----------------------------------------------------------------------
   960    961    *
   961    962    * TkMacOSXInvalidateViewRegion --
   962    963    *
................................................................................
   968    969    * Side effects:
   969    970    *	Damage is created.
   970    971    *
   971    972    *----------------------------------------------------------------------
   972    973    */
   973    974   
   974    975   static OSStatus
   975         -InvalViewRect(int msg, HIShapeRef rgn, const CGRect *rect, void *ref) {
          976  +InvalViewRect(
          977  +    int msg,
          978  +    HIShapeRef rgn,
          979  +    const CGRect *rect,
          980  +    void *ref)
          981  +{
   976    982       static CGAffineTransform t;
   977    983       NSView *view = ref;
   978    984   
   979    985       if (!view) {
   980    986   	return paramErr;
   981    987       }
   982    988       switch (msg) {
................................................................................
  1048   1054    *
  1049   1055    * Side effects:
  1050   1056    *	None.
  1051   1057    *
  1052   1058    *----------------------------------------------------------------------
  1053   1059    */
  1054   1060   
  1055         -NSWindow*
         1061  +NSWindow *
  1056   1062   TkMacOSXDrawableWindow(
  1057   1063       Drawable drawable)
  1058   1064   {
  1059   1065       MacDrawable *macWin = (MacDrawable *) drawable;
  1060   1066       NSWindow *result = nil;
  1061   1067   
  1062   1068       if (!macWin || macWin->flags & TK_IS_PIXMAP) {
................................................................................
  1066   1072   	    macWin->toplevel->winPtr->wmInfoPtr->window) {
  1067   1073   	result = macWin->toplevel->winPtr->wmInfoPtr->window;
  1068   1074       } else if (macWin->winPtr && macWin->winPtr->wmInfoPtr &&
  1069   1075   	    macWin->winPtr->wmInfoPtr->window) {
  1070   1076   	result = macWin->winPtr->wmInfoPtr->window;
  1071   1077       } else if (macWin->toplevel && (macWin->toplevel->flags & TK_EMBEDDED)) {
  1072   1078   	TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
         1079  +
  1073   1080   	if (contWinPtr) {
  1074   1081   	    result = TkMacOSXDrawableWindow((Drawable) contWinPtr->privatePtr);
  1075   1082   	}
  1076   1083       }
  1077   1084       return result;
  1078   1085   }
  1079   1086   
................................................................................
  1119   1126    *
  1120   1127    * Side effects:
  1121   1128    *	None.
  1122   1129    *
  1123   1130    *----------------------------------------------------------------------
  1124   1131    */
  1125   1132   
  1126         -NSView*
         1133  +NSView *
  1127   1134   TkMacOSXDrawableView(
  1128   1135       MacDrawable *macWin)
  1129   1136   {
  1130   1137       NSView *result = nil;
  1131   1138   
  1132   1139       if (!macWin) {
  1133   1140   	result = nil;
  1134   1141       } else if (!macWin->toplevel) {
  1135   1142   	result = macWin->view;
  1136   1143       } else if (!(macWin->toplevel->flags & TK_EMBEDDED)) {
  1137   1144   	result = macWin->toplevel->view;
  1138   1145       } else {
  1139   1146   	TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr);
         1147  +
  1140   1148   	if (contWinPtr) {
  1141   1149   	    result = TkMacOSXDrawableView(contWinPtr->privatePtr);
  1142   1150   	}
  1143   1151       }
  1144   1152       return result;
  1145   1153   }
  1146   1154   
................................................................................
  1160   1168    *----------------------------------------------------------------------
  1161   1169    */
  1162   1170   
  1163   1171   void *
  1164   1172   TkMacOSXGetRootControl(
  1165   1173       Drawable drawable)
  1166   1174   {
  1167         -
  1168   1175       /*
  1169   1176        * will probably need to fix this up for embedding
  1170   1177        */
  1171   1178   
  1172   1179       return TkMacOSXDrawableView((MacDrawable *) drawable);
  1173   1180   }
  1174   1181   
................................................................................
  1277   1284    */
  1278   1285   
  1279   1286   void
  1280   1287   TkMacOSXWinBounds(
  1281   1288       TkWindow *winPtr,
  1282   1289       void *bounds)
  1283   1290   {
  1284         -    Rect *b = (Rect *)bounds;
         1291  +    Rect *b = (Rect *) bounds;
         1292  +
  1285   1293       b->left = winPtr->privatePtr->xOff;
  1286   1294       b->top = winPtr->privatePtr->yOff;
  1287   1295       b->right = b->left + winPtr->changes.width;
  1288   1296       b->bottom = b->top + winPtr->changes.height;
  1289   1297   }
  1290   1298   
  1291   1299   /*
................................................................................
  1341   1349       TkWindow *winPtr,
  1342   1350       int deltaX,
  1343   1351       int deltaY)
  1344   1352   {
  1345   1353       TkWindow *childPtr;
  1346   1354   
  1347   1355       if (winPtr->privatePtr == NULL) {
  1348         -
  1349   1356   	/*
  1350   1357   	 * We haven't called Tk_MakeWindowExist for this window yet. The offset
  1351   1358   	 * information will be postponed and calulated at that time. (This will
  1352   1359   	 * usually only happen when a mapped parent is being moved but has
  1353   1360   	 * child windows that have yet to be mapped.)
  1354   1361   	 */
  1355   1362   

Changes to macosx/tkMacOSXWindowEvent.c.

    64     64   
    65     65   - (void) windowBoundsChanged: (NSNotification *) notification
    66     66   {
    67     67   #ifdef TK_MAC_DEBUG_NOTIFICATIONS
    68     68       TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
    69     69   #endif
    70     70       BOOL movedOnly = [[notification name]
    71         -			 isEqualToString:NSWindowDidMoveNotification];
           71  +	    isEqualToString:NSWindowDidMoveNotification];
    72     72       NSWindow *w = [notification object];
    73     73       TkWindow *winPtr = TkMacOSXGetTkWindow(w);
    74     74   
    75     75       if (winPtr) {
    76     76   	WmInfo *wmPtr = winPtr->wmInfoPtr;
    77     77   	NSRect bounds = [w frame];
    78     78   	int x, y, width = -1, height = -1, flags = 0;
................................................................................
    87     87   	if (!movedOnly && (winPtr->changes.width != bounds.size.width ||
    88     88   		winPtr->changes.height !=  bounds.size.height)) {
    89     89   	    width = bounds.size.width - wmPtr->xInParent;
    90     90   	    height = bounds.size.height - wmPtr->yInParent;
    91     91   	    flags |= TK_SIZE_CHANGED;
    92     92   	}
    93     93   	if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) {
    94         -
    95     94   	    /*
    96     95   	     * Propagate geometry changes immediately.
    97     96   	     */
    98     97   
    99     98   	    flags |= TK_MACOSX_HANDLE_EVENT_IMMEDIATELY;
   100     99   	}
   101    100   
................................................................................
   136    135   	}
   137    136       }
   138    137   }
   139    138   
   140    139   - (NSRect)windowWillUseStandardFrame:(NSWindow *)window
   141    140                           defaultFrame:(NSRect)newFrame
   142    141   {
   143         -
   144    142       /*
   145         -     * This method needs to be implemented in order for [NSWindow isZoomed]
   146         -     * to give the correct answer.  But it suffices to always validate
   147         -     * every request.
          143  +     * This method needs to be implemented in order for [NSWindow isZoomed] to
          144  +     * give the correct answer. But it suffices to always validate every
          145  +     * request.
   148    146        */
   149    147   
   150    148       return newFrame;
   151    149   }
   152    150   
   153    151   - (NSSize)window:(NSWindow *)window
   154    152     willUseFullScreenContentSize:(NSSize)proposedSize
   155    153   {
          154  +    /*
          155  +     * We don't need to change the proposed size, but we do need to implement
          156  +     * this method.  Otherwise the full screen window will be sized to the
          157  +     * screen's visibleFrame, leaving black bands at the top and bottom.
          158  +     */
   156    159   
   157         -    /*
   158         -     * We don't need to change the proposed size, but we do need to
   159         -     * implement this method.  Otherwise the full screen window will
   160         -     * be sized to the screen's visibleFrame, leaving black bands at
   161         -     * the top and bottom.
   162         -     */
   163    160       return proposedSize;
   164    161   }
   165    162   
   166    163   - (void) windowEnteredFullScreen: (NSNotification *) notification
   167    164   {
   168    165   #ifdef TK_MAC_DEBUG_NOTIFICATIONS
   169    166       TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
................................................................................
   204    201   	if (_windowWithMouse == w) {
   205    202   	    _windowWithMouse = nil;
   206    203   	    [w release];
   207    204   	}
   208    205       }
   209    206   
   210    207       /*
   211         -     * If necessary, TkGenWMDestroyEvent() handles [close]ing the window,
   212         -     * so can always return NO from -windowShouldClose: for a Tk window.
          208  +     * If necessary, TkGenWMDestroyEvent() handles [close]ing the window, so
          209  +     * can always return NO from -windowShouldClose: for a Tk window.
   213    210        */
   214    211   
   215    212       return (winPtr ? NO : YES);
   216    213   }
   217         -
   218    214   
   219    215   #ifdef TK_MAC_DEBUG_NOTIFICATIONS
   220    216   
   221    217   - (void) windowDragStart: (NSNotification *) notification
   222    218   {
   223    219       TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification);
   224    220   }
................................................................................
   251    247       NSWindow *w = [notification object];
   252    248       TkWindow *winPtr = TkMacOSXGetTkWindow(w);
   253    249   
   254    250       if (winPtr) {
   255    251   	//Tk_UnmapWindow((Tk_Window) winPtr);
   256    252       }
   257    253   }
   258         -
   259    254   
   260    255   #endif /* TK_MAC_DEBUG_NOTIFICATIONS */
   261    256   
   262    257   - (void) _setupWindowNotifications
   263    258   {
   264    259       NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
   265    260   
................................................................................
   359    354   #pragma mark -
   360    355   
   361    356   /*
   362    357    *----------------------------------------------------------------------
   363    358    *
   364    359    * TkpAppIsDrawing --
   365    360    *
   366         - *      A widget display procedure can call this to determine whether it
   367         - *      is being run inside of the drawRect method.  This is needed for
   368         - *      some tests, especially of the Text widget, which record data in
   369         - *      a global Tcl variable and assume that display procedures will be
   370         - *      run in a predictable sequence as Tcl idle tasks.
          361  + *      A widget display procedure can call this to determine whether it is
          362  + *      being run inside of the drawRect method. This is needed for some tests,
          363  + *      especially of the Text widget, which record data in a global Tcl
          364  + *      variable and assume that display procedures will be run in a
          365  + *      predictable sequence as Tcl idle tasks.
   371    366    *
   372    367    * Results:
   373    368    *	True only while running the drawRect method of a TKContentView;
   374    369    *
   375    370    * Side effects:
   376    371    *	None
   377    372    *
   378    373    *----------------------------------------------------------------------
   379    374    */
          375  +
   380    376   MODULE_SCOPE Bool
   381    377   TkpAppIsDrawing(void) {
   382    378       return [NSApp isDrawing];
   383    379   }
   384         -
   385    380   
   386    381   /*
   387    382    *----------------------------------------------------------------------
   388    383    *
   389    384    * GenerateUpdates --
   390    385    *
   391    386    *	Given a Macintosh update region and a Tk window this function geneates
................................................................................
   666    661   	if (flags & TK_LOCATION_CHANGED) {
   667    662   	    wmPtr->x = x;
   668    663   	    wmPtr->y = y;
   669    664   	}
   670    665   	if ((flags & TK_SIZE_CHANGED) && !(wmPtr->flags & WM_SYNC_PENDING) &&
   671    666   		((width != Tk_Width(tkwin)) || (height != Tk_Height(tkwin)))) {
   672    667   	    if ((wmPtr->width == -1) && (width == winPtr->reqWidth)) {
   673         -
   674    668   		/*
   675    669   		 * Don't set external width, since the user didn't change it
   676    670   		 * from what the widgets asked for.
   677    671   		 */
   678         -
   679    672   	    } else if (wmPtr->gridWin != NULL) {
   680    673   		wmPtr->width = wmPtr->reqGridWidth
   681    674   			+ (width - winPtr->reqWidth)/wmPtr->widthInc;
   682    675   		if (wmPtr->width < 0) {
   683    676   		    wmPtr->width = 0;
   684    677   		}
   685    678   	    } else {
   686    679   		wmPtr->width = width;
   687    680   	    }
   688    681   
   689    682   	    if ((wmPtr->height == -1) && (height == winPtr->reqHeight)) {
   690         -
   691    683   		/*
   692    684   		 * Don't set external height, since the user didn't change it
   693    685   		 * from what the widgets asked for.
   694    686   		 */
   695         -
   696    687   	    } else if (wmPtr->gridWin != NULL) {
   697    688   		wmPtr->height = wmPtr->reqGridHeight
   698    689   			+ (height - winPtr->reqHeight)/wmPtr->heightInc;
   699    690   		if (wmPtr->height < 0) {
   700    691   		    wmPtr->height = 0;
   701    692   		}
   702    693   	    } else {
................................................................................
   703    694   		wmPtr->height = height;
   704    695   	    }
   705    696   
   706    697   	    wmPtr->configWidth = width;
   707    698   	    wmPtr->configHeight = height;
   708    699   	}
   709    700       }
   710         -
   711    701   
   712    702       /*
   713    703        * Now set up the changes structure. Under X we wait for the
   714    704        * ConfigureNotify to set these values. On the Mac we know imediatly that
   715    705        * this is what we want - so we just set them. However, we need to make
   716    706        * sure the windows clipping region is marked invalid so the change is
   717    707        * visible to the subwindow.
................................................................................
   895    885   #ifdef TK_MAC_DEBUG_DRAWING
   896    886       TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
   897    887       if (winPtr) fprintf(stderr, "drawRect: drawing %s\n",
   898    888   			Tk_PathName(winPtr));
   899    889   #endif
   900    890   
   901    891       /*
   902         -     * We do not allow recursive calls to drawRect, but we only log
   903         -     * them on OSX > 10.13, where they should never happen.
          892  +     * We do not allow recursive calls to drawRect, but we only log them on OSX
          893  +     * > 10.13, where they should never happen.
   904    894        */
   905    895   
   906    896       if ([NSApp isDrawing]) {
   907    897   	if ([NSApp macMinorVersion] > 13) {
   908    898   	    TKLog(@"WARNING: a recursive call to drawRect was aborted.");
   909    899   	}
   910    900   	return;
................................................................................
   951    941       if (winPtr) {
   952    942   	unsigned int width = (unsigned int)newsize.width;
   953    943   	unsigned int height=(unsigned int)newsize.height;
   954    944   	ClientData oldArg;
   955    945       	Tk_RestrictProc *oldProc;
   956    946   
   957    947   	/*
   958         -	 * This can be called from outside the Tk event loop.
   959         -	 * Since it calls Tcl_DoOneEvent, we need to make sure we
   960         -	 * don't clobber the AutoreleasePool set up by the caller.
          948  +	 * This can be called from outside the Tk event loop.  Since it calls
          949  +	 * Tcl_DoOneEvent, we need to make sure we don't clobber the
          950  +	 * AutoreleasePool set up by the caller.
   961    951   	 */
   962    952   
   963    953   	[NSApp _lockAutoreleasePool];
   964    954   
   965    955   	/*
   966    956   	 * Disable Tk drawing until the window has been completely configured.
   967    957   	 */
................................................................................
   969    959   	TkMacOSXSetDrawingEnabled(winPtr, 0);
   970    960   
   971    961   	 /*
   972    962   	  * Generate and handle a ConfigureNotify event for the new size.
   973    963   	  */
   974    964   
   975    965   	TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height,
   976         -			      TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
          966  +		TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY);
   977    967       	oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg);
   978    968       	Tk_RestrictEvents(oldProc, oldArg, &oldArg);
   979    969   
   980    970   	/*
   981    971   	 * Now that Tk has configured all subwindows, create the clip regions.
   982    972   	 */
   983    973   
................................................................................
  1057   1047   	 * were created when the expose events were processed.
  1058   1048   	 */
  1059   1049   	while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {}
  1060   1050       }
  1061   1051   }
  1062   1052   
  1063   1053   /*
  1064         - * This method is called when a user changes between light and dark mode.
  1065         - * The implementation here generates a Tk virtual event which can be bound
  1066         - * to a function that redraws the window in an appropriate style.
         1054  + * This method is called when a user changes between light and dark mode. The
         1055  + * implementation here generates a Tk virtual event which can be bound to a
         1056  + * function that redraws the window in an appropriate style.
  1067   1057    */
  1068   1058   
  1069   1059   - (void) viewDidChangeEffectiveAppearance
  1070   1060   {
  1071   1061       XVirtualEvent event;
  1072   1062       int x, y;
  1073   1063       NSWindow *w = [self window];
................................................................................
  1095   1085       } else {
  1096   1086           event.name = Tk_GetUid("LightAqua");
  1097   1087       }
  1098   1088       Tk_QueueWindowEvent((XEvent *) &event, TCL_QUEUE_TAIL);
  1099   1089   }
  1100   1090   
  1101   1091   /*
  1102         - * This is no-op on 10.7 and up because Apple has removed this widget,
  1103         - * but we are leaving it here for backwards compatibility.
         1092  + * This is no-op on 10.7 and up because Apple has removed this widget, but we
         1093  + * are leaving it here for backwards compatibility.
  1104   1094    */
  1105   1095   
  1106   1096   - (void) tkToolbarButton: (id) sender
  1107   1097   {
  1108   1098   #ifdef TK_MAC_DEBUG_EVENTS
  1109   1099       TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd);
  1110   1100   #endif

Changes to macosx/tkMacOSXWm.c.

     1      1   /*
     2      2    * tkMacOSXWm.c --
     3      3    *
     4      4    *	This module takes care of the interactions between a Tk-based
     5      5    *	application and the window manager. Among other things, it implements
     6         - *	the "wm" command and passes geometry information to the window
     7         - *	manager.
            6  + *	the "wm" command and passes geometry information to the window manager.
     8      7    *
     9      8    * Copyright (c) 1994-1997 Sun Microsystems, Inc.
    10      9    * Copyright 2001-2009, Apple Inc.
    11     10    * Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
    12     11    * Copyright (c) 2010 Kevin Walzer/WordTech Communications LLC.
    13     12    * Copyright (c) 2017-2019 Marc Culler.
    14     13    *
................................................................................
   388    387   	/*
   389    388   	 * This avoids including the title bar for full screen windows
   390    389   	 * but does include it for normal windows.
   391    390   	 */
   392    391   
   393    392   	if ([self styleMask] & NSFullScreenWindowMask) {
   394    393    	    frameRect = [NSWindow frameRectForContentRect:NSZeroRect
   395         -				  styleMask:[self styleMask]];
          394  +		    styleMask:[self styleMask]];
   396    395   	} else {
   397    396   	    frameRect = [self frameRectForContentRect:NSZeroRect];
   398    397   	}
   399    398   
   400    399   	WmInfo *wmPtr = winPtr->wmInfoPtr;
   401    400   
   402    401   	wmPtr->xInParent = -frameRect.origin.x;
................................................................................
   450    449   - (id) retain
   451    450   {
   452    451       id result = [super retain];
   453    452       const char *title = [[self title] UTF8String];
   454    453       if (title == nil) {
   455    454   	title = "unnamed window";
   456    455       }
   457         -    if (DEBUG_ZOMBIES > 1){
          456  +    if (DEBUG_ZOMBIES > 1) {
   458    457   	fprintf(stderr, "Retained <%s>. Count is: %lu\n",
   459    458   		title, [self retainCount]);
   460    459       }
   461    460       return result;
   462    461   }
   463    462   
   464    463   - (id) autorelease
   465    464   {
   466    465       id result = [super autorelease];
   467    466       const char *title = [[self title] UTF8String];
   468    467       if (title == nil) {
   469    468   	title = "unnamed window";
   470    469       }
   471         -    if (DEBUG_ZOMBIES > 1){
          470  +    if (DEBUG_ZOMBIES > 1) {
   472    471   	fprintf(stderr, "Autoreleased <%s>. Count is %lu\n",
   473    472   		title, [self retainCount]);
   474    473       }
   475    474       return result;
   476    475   }
   477    476   
   478    477   - (oneway void) release {
   479    478       const char *title = [[self title] UTF8String];
   480    479       if (title == nil) {
   481    480   	title = "unnamed window";
   482    481       }
   483         -    if (DEBUG_ZOMBIES > 1){
          482  +    if (DEBUG_ZOMBIES > 1) {
   484    483   	fprintf(stderr, "Releasing <%s>. Count is %lu\n",
   485    484   		title, [self retainCount]);
   486    485       }
   487    486       [super release];
   488    487   }
   489    488   
   490    489   - (void) dealloc {
   491    490       const char *title = [[self title] UTF8String];
   492    491       if (title == nil) {
   493    492   	title = "unnamed window";
   494    493       }
   495         -    if (DEBUG_ZOMBIES > 0){
          494  +    if (DEBUG_ZOMBIES > 0) {
   496    495   	fprintf(stderr, ">>>> Freeing <%s>. Count is %lu\n",
   497    496   		title, [self retainCount]);
   498    497       }
   499    498       [super dealloc];
   500    499   }
   501    500   
   502    501   #endif
................................................................................
   994    993   	/* Activate the highest window left on the screen. */
   995    994   	NSArray *windows = [NSApp orderedWindows];
   996    995   	for (id nswindow in windows) {
   997    996   	    TkWindow *winPtr2 = TkMacOSXGetTkWindow(nswindow);
   998    997   
   999    998   	    if (winPtr2 && nswindow != window) {
  1000    999   		WmInfo *wmPtr = winPtr2->wmInfoPtr;
  1001         -		BOOL minimized = (wmPtr->hints.initial_state == IconicState ||
  1002         -				  wmPtr->hints.initial_state == WithdrawnState);
         1000  +		BOOL minimized = (wmPtr->hints.initial_state == IconicState
         1001  +			|| wmPtr->hints.initial_state == WithdrawnState);
         1002  +
  1003   1003   		/*
  1004   1004   		 * If no windows are left on the screen and the next window is
  1005   1005   		 * iconified or withdrawn, we don't want to make it be the
  1006   1006   		 * KeyWindow because that would cause it to be displayed on the
  1007   1007   		 * screen.
  1008   1008   		 */
         1009  +
  1009   1010   		if ([nswindow canBecomeKeyWindow] && !minimized) {
  1010   1011   		    [nswindow makeKeyAndOrderFront:NSApp];
  1011   1012   		    break;
  1012   1013   		}
  1013   1014   	    }
  1014   1015   	}
         1016  +
  1015   1017   	/*
  1016   1018   	 * Process all window events immediately to force the closed window to
  1017   1019   	 * be deallocated.  But don't do this for the root window as that is
  1018   1020   	 * unnecessary and can lead to segfaults.
  1019   1021   	 */
         1022  +
  1020   1023   	if (winPtr->parentPtr) {
  1021   1024   	    while (Tk_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {}
  1022   1025   	}
  1023   1026   	[NSApp _resetAutoreleasePool];
  1024   1027   #if DEBUG_ZOMBIES > 0
  1025   1028   	fprintf(stderr, "================= Pool dump ===================\n");
  1026   1029   	[NSAutoreleasePool showPools];
................................................................................
  2620   2623   	return TCL_OK;
  2621   2624       }
  2622   2625   
  2623   2626       if (*Tcl_GetString(objv[3]) == '\0') {
  2624   2627   	wmPtr->hints.flags &= ~IconPositionHint;
  2625   2628       } else {
  2626   2629   	if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
  2627         -	    || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)){
         2630  +		|| (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) {
  2628   2631   	    return TCL_ERROR;
  2629   2632   	}
  2630   2633   	wmPtr->hints.icon_x = x;
  2631   2634   	wmPtr->hints.icon_y = y;
  2632   2635   	wmPtr->hints.flags |= IconPositionHint;
  2633   2636       }
  2634   2637       return TCL_OK;
................................................................................
  3449   3452   	}
  3450   3453   
  3451   3454   	if (Tcl_GetIndexFromObjStruct(interp, objv[3], optionStrings,
  3452   3455   		sizeof(char *), "argument", 0, &index) != TCL_OK) {
  3453   3456   	    return TCL_ERROR;
  3454   3457   	}
  3455   3458   
  3456         -	if (index == OPT_NORMAL) {
         3459  +	switch (index) {
         3460  +	case OPT_NORMAL:
  3457   3461   	    TkpWmSetState(winPtr, NormalState);
  3458   3462   
  3459   3463   	    /*
  3460   3464   	     * This varies from 'wm deiconify' because it does not force the
  3461   3465   	     * window to be raised and receive focus
  3462   3466   	     */
  3463         -	} else if (index == OPT_ICONIC) {
         3467  +
         3468  +	    break;
         3469  +	case OPT_ICONIC:
  3464   3470   	    if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) {
  3465   3471   		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  3466   3472   			"can't iconify \"%s\": override-redirect flag is set",
  3467   3473   			winPtr->pathName));
  3468   3474   		Tcl_SetErrorCode(interp, "TK", "WM", "STATE",
  3469   3475   			"OVERRIDE_REDIRECT", NULL);
  3470   3476   		return TCL_ERROR;
................................................................................
  3474   3480   			"can't iconify \"%s\": it is a transient",
  3475   3481   			winPtr->pathName));
  3476   3482   		Tcl_SetErrorCode(interp, "TK", "WM", "STATE", "TRANSIENT",
  3477   3483   			NULL);
  3478   3484   		return TCL_ERROR;
  3479   3485   	    }
  3480   3486   	    TkpWmSetState(winPtr, IconicState);
  3481         -	} else if (index == OPT_WITHDRAWN) {
         3487  +	    break;
         3488  +	case OPT_WITHDRAWN:
  3482   3489   	    TkpWmSetState(winPtr, WithdrawnState);
  3483         -	} else { /* OPT_ZOOMED */
         3490  +	    break;
         3491  +	default: /* OPT_ZOOMED */
  3484   3492   	    TkpWmSetState(winPtr, ZoomState);
         3493  +	    break;
  3485   3494   	}
  3486   3495       } else if (wmPtr->iconFor != NULL) {
  3487   3496   	Tcl_SetObjResult(interp, Tcl_NewStringObj("icon", -1));
  3488   3497       } else {
  3489   3498   	if (wmPtr->hints.initial_state == NormalState ||
  3490   3499   		wmPtr->hints.initial_state == ZoomState) {
  3491   3500   	    wmPtr->hints.initial_state = (TkMacOSXIsWindowZoomed(winPtr) ?
................................................................................
  3597   3606   	    Tcl_SetObjResult(interp,
  3598   3607   		Tcl_NewStringObj(Tk_PathName(wmPtr->master), -1));
  3599   3608   	}
  3600   3609   	return TCL_OK;
  3601   3610       }
  3602   3611       if (Tcl_GetString(objv[3])[0] == '\0') {
  3603   3612   	RemoveTransient(winPtr);
  3604         -
  3605   3613       } else {
  3606   3614   	if (TkGetWindowFromObj(interp, tkwin, objv[3], &master) != TCL_OK) {
  3607   3615   	    return TCL_ERROR;
  3608   3616   	}
  3609   3617   	masterPtr = (TkWindow*) master;
  3610   3618   	while (!Tk_TopWinHierarchy(masterPtr)) {
  3611         -
  3612   3619               /*
  3613   3620                * Ensure that the master window is actually a Tk toplevel.
  3614   3621                */
  3615   3622   
  3616   3623               masterPtr = masterPtr->parentPtr;
  3617   3624           }
  3618   3625   	Tk_MakeWindowExist((Tk_Window)masterPtr);
................................................................................
  3622   3629   		    "can't make \"%s\" a transient: it is an icon for %s",
  3623   3630   		    Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor)));
  3624   3631   	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
  3625   3632   	    return TCL_ERROR;
  3626   3633   	}
  3627   3634   
  3628   3635   	wmPtr2 = masterPtr->wmInfoPtr;
  3629         -	/* Under some circumstances, wmPtr2 is NULL here. */
         3636  +
         3637  +	/*
         3638  +	 * Under some circumstances, wmPtr2 is NULL here.
         3639  +	 */
         3640  +
  3630   3641   	if (wmPtr2 != NULL && wmPtr2->iconFor != NULL) {
  3631   3642   	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  3632   3643   		    "can't make \"%s\" a master: it is an icon for %s",
  3633   3644   		    Tcl_GetString(objv[3]), Tk_PathName(wmPtr2->iconFor)));
  3634   3645   	    Tcl_SetErrorCode(interp, "TK", "WM", "TRANSIENT", "ICON", NULL);
  3635   3646   	    return TCL_ERROR;
  3636   3647   	}
................................................................................
  3673   3684   	}
  3674   3685   
  3675   3686   	wmPtr->master = (Tk_Window) masterPtr;
  3676   3687       }
  3677   3688       ApplyMasterOverrideChanges(winPtr, NULL);
  3678   3689       return TCL_OK;
  3679   3690   }
  3680         -
         3691  +
  3681   3692   /*
  3682   3693    *----------------------------------------------------------------------
  3683   3694    *
  3684   3695    * RemoveTransient --
  3685   3696    *
  3686   3697    *      Clears the transient's master record and removes the transient from the
  3687   3698    *      master's list.
................................................................................
  3780   3791       NSWindow *win = TkMacOSXDrawableWindow(winPtr->window);
  3781   3792       [win orderOut:nil];
  3782   3793       [win setExcludedFromWindowsMenu:YES];
  3783   3794   
  3784   3795       /*
  3785   3796        * If this window has a transient, the transient must also be withdrawn.
  3786   3797        */
         3798  +
  3787   3799       for (Transient *transientPtr = wmPtr->transientPtr;
  3788   3800   	    transientPtr != NULL; transientPtr = transientPtr->nextPtr) {
  3789   3801   	TkWindow *winPtr2 = transientPtr->winPtr;
  3790   3802   	TkWindow *masterPtr = (TkWindow *) TkGetTransientMaster(winPtr2);
  3791   3803   
  3792   3804       	if (masterPtr == winPtr &&
  3793   3805   		winPtr2->wmInfoPtr->hints.initial_state != WithdrawnState) {
................................................................................
  3794   3806   	    TkpWmSetState(winPtr2, WithdrawnState);
  3795   3807   	    transientPtr->flags |= WITHDRAWN_BY_MASTER;
  3796   3808   	}
  3797   3809       }
  3798   3810   
  3799   3811       return TCL_OK;
  3800   3812   }
  3801         -
         3813  +
  3802   3814   /*
  3803         - * Invoked by those wm subcommands that affect geometry.
  3804         - * Schedules a geometry update.
         3815  + * Invoked by those wm subcommands that affect geometry.  Schedules a geometry
         3816  + * update.
  3805   3817    */
  3806   3818   
  3807   3819   static void
  3808   3820   WmUpdateGeom(
  3809   3821       WmInfo *wmPtr,
  3810   3822       TkWindow *winPtr)
  3811   3823   {
................................................................................
  4411   4423        */
  4412   4424   
  4413   4425       wmPtr->width = width;
  4414   4426       wmPtr->height = height;
  4415   4427       if (flags & WM_NEGATIVE_X) {
  4416   4428   	int borderwidth = wmPtr->parentWidth - winPtr->changes.width;
  4417   4429   	int newWidth = width == -1 ? winPtr->changes.width : width;
         4430  +
  4418   4431   	x = (x == -1) ?
  4419         -	    wmPtr->x + winPtr->changes.width - newWidth :
  4420         -	    wmPtr->vRootWidth - x - newWidth - borderwidth;
         4432  +		wmPtr->x + winPtr->changes.width - newWidth :
         4433  +		wmPtr->vRootWidth - x - newWidth - borderwidth;
  4421   4434       }
  4422   4435       if (x == -1) {
  4423   4436   	x = wmPtr->x;
  4424   4437       }
  4425   4438       if (flags & WM_NEGATIVE_Y) {
  4426   4439   	int borderheight = wmPtr->parentHeight - winPtr->changes.height;
  4427   4440   	int newHeight = height == -1 ? winPtr->changes.height : height;
         4441  +
  4428   4442   	y = (y == -1) ?
  4429         -	    wmPtr->y + winPtr->changes.height - newHeight :
  4430         -	    wmPtr->vRootHeight - y - newHeight - borderheight;
         4443  +		wmPtr->y + winPtr->changes.height - newHeight :
         4444  +		wmPtr->vRootHeight - y - newHeight - borderheight;
  4431   4445       }
  4432   4446       if (y == -1) {
  4433   4447   	y = wmPtr->y;
  4434   4448       }
  4435   4449       if (wmPtr->flags & WM_FULLSCREEN) {
  4436   4450   	wmPtr->configX = x;
  4437   4451   	wmPtr->configY = y;
................................................................................
  4550   4564    *	This is a Macintosh specific implementation of this function. Given
  4551   4565    *	the root coordinates of a point, this procedure returns the token for
  4552   4566    *	the top-most window covering that point, if there exists such a window
  4553   4567    *	in this application.
  4554   4568    *
  4555   4569    * Results:
  4556   4570    *	The return result is either a token for the window corresponding to
  4557         - *	rootX and rootY, or else NULL to indicate that there is no such
  4558         - *	window.
         4571  + *	rootX and rootY, or else NULL to indicate that there is no such window.
  4559   4572    *
  4560   4573    * Side effects:
  4561   4574    *	None.
  4562   4575    *
  4563   4576    *----------------------------------------------------------------------
  4564   4577    */
  4565   4578   
................................................................................
  6140   6153   }
  6141   6154   
  6142   6155   /*
  6143   6156    *----------------------------------------------------------------------
  6144   6157    *
  6145   6158    * TkpDisplayWindow --
  6146   6159    *
  6147         - *      Mark the contentView of this window as needing display so the
  6148         - *      window will be drawn by the window manager.  If this is called
  6149         - *      within the drawRect method, do nothing.
         6160  + *      Mark the contentView of this window as needing display so the window
         6161  + *      will be drawn by the window manager.  If this is called within the
         6162  + *      drawRect method, do nothing.
  6150   6163    *
  6151   6164    * Results:
  6152   6165    *      None.
  6153   6166    *
  6154   6167    * Side effects:
  6155   6168    *      The window's contentView is marked as needing display.
  6156   6169    *
  6157   6170    *----------------------------------------------------------------------
  6158   6171    */
  6159   6172   
  6160   6173   MODULE_SCOPE void
  6161   6174   TkpDisplayWindow(Tk_Window tkwin) {
  6162   6175       if (![NSApp isDrawing]) {
  6163         -    	TkWindow *winPtr = (TkWindow*)tkwin;
         6176  +    	TkWindow *winPtr = (TkWindow *) tkwin;
  6164   6177       	NSWindow *w = TkMacOSXDrawableWindow(winPtr->window);
  6165   6178   
  6166   6179       	[[w contentView] setNeedsDisplay: YES];
  6167   6180       }
  6168   6181   }
  6169   6182   
  6170   6183   /*
  6171   6184    *----------------------------------------------------------------------
  6172   6185    *
  6173   6186    * TkMacOSXRegisterOffScreenWindow --
  6174   6187    *
  6175         - *	This function adds the passed in Off Screen Port to the hash table
  6176         - *	that maps Mac windows to root X windows.
         6188  + *	This function adds the passed in Off Screen Port to the hash table that
         6189  + *	maps Mac windows to root X windows.
  6177   6190    *
  6178   6191    * Results:
  6179   6192    *	None.
  6180   6193    *
  6181   6194    * Side effects:
  6182   6195    *	An entry is added to the windowTable hash table.
  6183   6196    *
................................................................................
  6977   6990   		        NSResizableWindowMask;
  6978   6991   	} else {
  6979   6992   	    styleMask |= NSTitledWindowMask;
  6980   6993   	}
  6981   6994       }
  6982   6995       if (macWindow) {
  6983   6996   	structureRect = [NSWindow frameRectForContentRect:NSZeroRect
  6984         -				  styleMask:styleMask];
         6997  +		styleMask:styleMask];
  6985   6998   
  6986   6999   	/*
  6987   7000   	 * Synchronize the wmInfoPtr to match the new window configuration
  6988   7001   	 * so windowBoundsChanged won't corrupt the window manager info.
  6989   7002   	 */
  6990   7003   
  6991   7004   	wmPtr->xInParent = -structureRect.origin.x;
................................................................................
  7232   7245   
  7233   7246   static void
  7234   7247   RemapWindows(
  7235   7248       TkWindow *winPtr,
  7236   7249       MacDrawable *parentWin)
  7237   7250   {
  7238   7251       TkWindow *childPtr;
         7252  +
  7239   7253       /*
  7240   7254        * Remove the OS specific window. It will get rebuilt when the window gets
  7241   7255        * Mapped.
  7242   7256        */
  7243   7257   
  7244   7258       if (winPtr->window != None) {
  7245   7259   	MacDrawable *macWin = (MacDrawable *) winPtr->window;

Changes to macosx/ttkMacOSXTheme.c.

    56     56   
    57     57   /*----------------------------------------------------------------------
    58     58    * +++ Utilities.
    59     59    */
    60     60   
    61     61   /*
    62     62    * BoxToRect --
    63         - *    Convert a Ttk_Box in Tk coordinates relative to the given Drawable
    64         - *    to a native Rect relative to the containing port.
           63  + *    Convert a Ttk_Box in Tk coordinates relative to the given Drawable to a
           64  + *    native Rect relative to the containing port.
    65     65    */
    66         -static inline CGRect BoxToRect(Drawable d, Ttk_Box b)
           66  +
           67  +static inline CGRect
           68  +BoxToRect(
           69  +    Drawable d,
           70  +    Ttk_Box b)
    67     71   {
    68     72       MacDrawable *md = (MacDrawable*)d;
    69     73       CGRect rect;
    70     74   
    71     75       rect.origin.y	= b.y + md->yOff;
    72     76       rect.origin.x	= b.x + md->xOff;
    73     77       rect.size.height	= b.height;
................................................................................
    98    102   };
    99    103   
   100    104   /*
   101    105    * NormalizeButtonBounds --
   102    106    *
   103    107    * Apple's Human Interface Guidelines only allow three specific heights for
   104    108    * most buttons: Regular, small and mini. We always use the regular size.
   105         - * However, Ttk may provide an arbitrary bounding rectangle.  We always draw
   106         - * the button centered vertically on the rectangle, and having the same width
   107         - * as the rectangle.  This function returns the actual bounding rectangle that
   108         - * will be used in drawing the button.
          109  + * However, Ttk may provide an arbitrary bounding rectangle. We always draw the
          110  + * button centered vertically on the rectangle, and having the same width as
          111  + * the rectangle. This function returns the actual bounding rectangle that will
          112  + * be used in drawing the button.
   109    113    *
   110    114    * The BevelButton is allowed to have arbitrary size, and also has external
   111    115    * padding.  This is handled separately here.
   112    116    */
   113    117   
   114    118   static CGRect NormalizeButtonBounds(
   115    119       SInt32 heightMetric,
   116    120       CGRect bounds)
   117    121   {
   118         -    SInt32 height;
   119         -    if (heightMetric != NoThemeMetric) {
          122  +    if (heightMetric != (SInt32) NoThemeMetric) {
          123  +	SInt32 height;
          124  +
   120    125   	ChkErr(GetThemeMetric, heightMetric, &height);
   121    126   	bounds.origin.y += (bounds.size.height - height)/2;
   122    127   	bounds.size.height = height;
   123    128       }
   124    129       return bounds;
   125    130   }
   126    131   
................................................................................
   145    150   /*----------------------------------------------------------------------
   146    151    * GetBackgroundColor --
   147    152    *
   148    153    *	Fills the array rgba with the color coordinates for a background color.
   149    154    *	Start with the background color of a window's geometry master, or the
   150    155    *	standard ttk window background if not. If the contrast parameter is
   151    156    *	nonzero modify this color to be darker, for the aqua appearance, or
   152         - *	lighter for the DarkAqua appearance.  This is primarily used by the
   153         - *	Fill and Background elements.
          157  + *	lighter for the DarkAqua appearance. This is primarily used by the Fill
          158  + *	and Background elements.
   154    159    */
   155    160   
   156    161   static void GetBackgroundColor(
   157    162       CGContextRef context,
   158    163       Tk_Window tkwin,
   159    164       int contrast,
   160    165       CGFloat *rgba)
   161    166   {
   162    167       TkWindow *winPtr = (TkWindow *) tkwin;
   163    168       TkWindow *masterPtr = (TkWindow *) TkGetGeomMaster(tkwin);
          169  +
   164    170       while (masterPtr != NULL) {
   165    171   	if (masterPtr->privatePtr->flags & TTK_HAS_CONTRASTING_BG) {
   166    172   	    break;
   167    173   	}
   168         -	masterPtr = (TkWindow *)TkGetGeomMaster(masterPtr);
          174  +	masterPtr = (TkWindow *) TkGetGeomMaster(masterPtr);
   169    175       }
   170    176       if (masterPtr) {
   171    177   	for (int i = 0; i < 4; i++) {
   172    178   	    rgba[i] = masterPtr->privatePtr->fillRGBA[i];
   173    179   	}
   174    180       } else {
   175    181   	if ([NSApp macMinorVersion] > 13) {
   176    182   	    NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   177    183   	    NSColor *windowColor = [[NSColor windowBackgroundColor]
   178    184   				       colorUsingColorSpace: deviceRGB];
          185  +
   179    186   	    [windowColor getComponents: rgba];
   180    187   	} else {
   181    188   	    for (int i = 0; i < 4; i++) {
   182    189   		rgba[i] = windowBackground[i];
   183    190   	    }
   184    191   	}
   185    192       }
................................................................................
   215    222       Tk_Window tkwin)
   216    223   {
   217    224       CGPathRef path;
   218    225       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   219    226       NSColor *borderColor, *bgColor;
   220    227       static CGFloat border[4] = {1.0, 1.0, 1.0, 0.25};
   221    228       CGFloat fill[4];
          229  +
   222    230       GetBackgroundColor(context, tkwin, 1, fill);
   223    231       bgColor = [NSColor colorWithColorSpace: deviceRGB components: fill
   224    232   				     count: 4];
   225    233       CGContextSetFillColorSpace(context, deviceRGB.CGColorSpace);
   226    234       CGContextSetFillColorWithColor(context, bgColor.CGColor);
   227    235       path = CGPathCreateWithRoundedRect(bounds, 4, 4, NULL);
   228    236       CGContextClipToRect(context, bounds);
................................................................................
   251    259   static void SolidFillRoundedRectangle(
   252    260       CGContextRef context,
   253    261       CGRect bounds,
   254    262       CGFloat radius,
   255    263       NSColor *color)
   256    264   {
   257    265       CGPathRef path;
          266  +
   258    267       CGContextSetFillColorWithColor(context, color.CGColor);
   259    268       path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
   260    269       CGContextBeginPath(context);
   261    270       CGContextAddPath(context, path);
   262    271       CGContextFillPath(context);
   263    272       CFRelease(path);
   264    273   }
................................................................................
   267    276       CGContextRef context,
   268    277       CGRect bounds,
   269    278       CGFloat inset,
   270    279       CGFloat size,
   271    280       CGFloat *rgba)
   272    281   {
   273    282       CGFloat x, y;
          283  +
   274    284       CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
   275    285       CGContextSetLineWidth(context, 1.5);
   276    286       x = bounds.origin.x + inset;
   277    287       y = bounds.origin.y + trunc(bounds.size.height/2);
   278         -    CGContextBeginPath(context);
          288  +
   279    289       CGPoint arrow[3] = {
   280    290   	{x, y-size/4}, {x+size/2, y+size/4}, {x+size, y-size/4}
   281    291       };
          292  +
          293  +    CGContextBeginPath(context);
   282    294       CGContextAddLines(context, arrow, 3);
   283    295       CGContextStrokePath(context);
   284    296   }
   285    297   
   286    298   static void DrawUpArrow(
   287    299       CGContextRef context,
   288    300       CGRect bounds,
   289    301       CGFloat inset,
   290    302       CGFloat size,
   291    303       CGFloat *rgba)
   292    304   {
   293    305       CGFloat x, y;
          306  +
   294    307       CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
   295    308       CGContextSetLineWidth(context, 1.5);
   296    309       x = bounds.origin.x + inset;
   297    310       y = bounds.origin.y + trunc(bounds.size.height/2);
   298         -    CGContextBeginPath(context);
          311  +
   299    312       CGPoint arrow[3] = {
   300    313   	{x, y+size/4}, {x+size/2, y-size/4}, {x+size, y+size/4}
   301    314       };
          315  +
          316  +    CGContextBeginPath(context);
   302    317       CGContextAddLines(context, arrow, 3);
   303    318       CGContextStrokePath(context);
   304    319   }
   305    320   
   306    321   /*----------------------------------------------------------------------
   307    322    * DrawListHeader --
   308    323    *
................................................................................
   364    379       CGContextStrokePath(context);
   365    380       CGContextAddLines(context, bottom, 2);
   366    381       CGContextStrokePath(context);
   367    382       CGContextRestoreGState(context);
   368    383   
   369    384       if (state & TTK_TREEVIEW_STATE_SORTARROW) {
   370    385   	CGRect arrowBounds = bounds;
          386  +
   371    387   	arrowBounds.origin.x = bounds.origin.x + bounds.size.width - 16;
   372    388   	arrowBounds.size.width = 16;
   373    389   	if (state & TTK_STATE_ALTERNATE) {
   374    390   	    DrawUpArrow(context, arrowBounds, 3, 8, blackRGBA);
   375    391   	} else if (state & TTK_STATE_SELECTED) {
   376    392   	    DrawDownArrow(context, arrowBounds, 3, 8, blackRGBA);
   377    393   	}
................................................................................
   409    425   static CGFloat darkBackgroundGradient[8] = {0.0, 0.0, 0.0, 0.1,
   410    426   					    0.0, 0.0, 0.0, 0.25};
   411    427   static CGFloat darkInactiveGradient[8] = {89.0/255, 90.0/255, 93.0/255, 1.0,
   412    428   				       119.0/255, 120.0/255, 122.0/255, 1.0};
   413    429   static CGFloat darkSelectedGradient[8] = {23.0/255, 111.0/255, 232.0/255, 1.0,
   414    430   					  20.0/255, 94.0/255,  206.0/255, 1.0};
   415    431   
   416         - 
   417    432   /*----------------------------------------------------------------------
   418    433    * GradientFillRoundedRectangle --
   419    434    *
   420    435    *	Fill a rounded rectangle with a specified gradient.
   421    436    */
   422    437   
   423    438   static void GradientFillRoundedRectangle(
   424    439       CGContextRef context,
   425    440       CGRect bounds,
   426    441       CGFloat radius,
   427         -    CGFloat* colors,
          442  +    CGFloat *colors,
   428    443       int numColors)
   429    444   {
   430    445       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   431    446       CGPathRef path;
   432    447       CGPoint end = {
   433    448   	bounds.origin.x,
   434    449   	bounds.origin.y + bounds.size.height
   435    450       };
   436    451       CGGradientRef gradient = CGGradientCreateWithColorComponents(
   437    452   	    deviceRGB.CGColorSpace, colors, NULL, numColors);
          453  +
   438    454       path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
   439    455       CGContextBeginPath(context);
   440    456       CGContextAddPath(context, path);
   441    457       CGContextClip(context);
   442    458       CGContextDrawLinearGradient(context, gradient, bounds.origin, end, 0);
   443    459       CFRelease(path);
   444    460       CFRelease(gradient);
................................................................................
   448    464       CGContextRef context,
   449    465       CGRect bounds,
   450    466       CGFloat inset,
   451    467       CGFloat size,
   452    468       CGFloat *rgba)
   453    469   {
   454    470       CGFloat x, y;
          471  +
   455    472       CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]);
   456    473       CGContextSetLineWidth(context, 1.5);
   457    474       x = bounds.origin.x + inset;
   458    475       y = bounds.origin.y + trunc(bounds.size.height/2);
   459    476       CGContextBeginPath(context);
          477  +
   460    478       CGPoint bottomArrow[3] = {{x, y+2}, {x+size/2, y+2+size/2}, {x+size, y+2}};
   461         -    CGContextAddLines(context, bottomArrow, 3);
   462    479       CGPoint topArrow[3] = {{x, y-2}, {x+size/2, y-2-size/2}, {x+size, y-2}};
          480  +
          481  +    CGContextAddLines(context, bottomArrow, 3);
   463    482       CGContextAddLines(context, topArrow, 3);
   464    483       CGContextStrokePath(context);
   465    484   }
   466    485   
   467    486   /*----------------------------------------------------------------------
   468    487    * FillButtonBackground --
   469    488    *
................................................................................
   479    498       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   480    499       CGGradientRef backgroundGradient = CGGradientCreateWithColorComponents(
   481    500   	    deviceRGB.CGColorSpace, darkBackgroundGradient, NULL, 2);
   482    501       CGPoint backgroundEnd = {
   483    502   	bounds.origin.x,
   484    503   	bounds.origin.y + bounds.size.height
   485    504       };
          505  +
   486    506       CGContextBeginPath(context);
   487    507       path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL);
   488    508       CGContextAddPath(context, path);
   489    509       CGContextClip(context);
   490    510       CGContextDrawLinearGradient(context, backgroundGradient,
   491    511   	    bounds.origin, backgroundEnd, 0);
   492    512       CFRelease(path);
................................................................................
   504    524       CGContextRef context,
   505    525       CGRect bounds)
   506    526   {
   507    527       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   508    528       CGPoint topEnd = {bounds.origin.x, bounds.origin.y + 3};
   509    529       CGGradientRef topGradient = CGGradientCreateWithColorComponents(
   510    530   	    deviceRGB.CGColorSpace, darkTopGradient, NULL, 2);
          531  +
   511    532       CGContextSaveGState(context);
   512    533       CGContextBeginPath(context);
   513    534       CGContextAddArc(context, bounds.origin.x + 4, bounds.origin.y + 4,
   514    535   	    4, PI, 3*PI/2, 0);
   515    536       CGContextAddArc(context, bounds.origin.x + bounds.size.width - 4,
   516    537   	    bounds.origin.y + 4, 4, 3*PI/2, 0, 0);
   517    538       CGContextReplacePathWithStrokedPath(context);
................................................................................
   572    593   
   573    594       /*
   574    595        * If this is a popup, draw the arrow button.
   575    596        */
   576    597   
   577    598       if (kind == kThemePopupButton | kind == kThemeComboBox) {
   578    599   	CGRect arrowBounds = bounds;
          600  +
   579    601   	arrowBounds.size.width = 16;
   580    602   	arrowBounds.origin.x += bounds.size.width - 16;
   581    603   
   582    604   	/*
   583    605   	 * If the toplevel is front, paint the button blue.
   584    606   	 */
   585    607   
   586    608   	if (!(state & TTK_STATE_BACKGROUND) &&
   587         -	    !(state & TTK_STATE_DISABLED)) {
          609  +		!(state & TTK_STATE_DISABLED)) {
   588    610   	    GradientFillRoundedRectangle(context, arrowBounds, 4,
   589         -				   darkSelectedGradient, 2);
          611  +		    darkSelectedGradient, 2);
   590    612   	}
   591    613   	if (kind == kThemePopupButton) {
   592    614   	    DrawUpDownArrows(context, arrowBounds, 3, 7, whiteRGBA);
   593    615   	} else {
   594    616   	    DrawDownArrow(context, arrowBounds, 4, 8, whiteRGBA);
   595    617   	}
   596    618       }
................................................................................
   597    619   
   598    620       HighlightButtonBorder(context, bounds);
   599    621   }
   600    622   
   601    623   /*----------------------------------------------------------------------
   602    624    * DrawDarkIncDecButton --
   603    625    *
   604         - *	This is a standalone drawing procedure which draws an IncDecButton
   605         - *	(as used in a Spinbox) in the Dark Mode style.
          626  + *	This is a standalone drawing procedure which draws an IncDecButton (as
          627  + *	used in a Spinbox) in the Dark Mode style.
   606    628    */
   607    629   
   608    630   static void DrawDarkIncDecButton(
   609    631       CGRect bounds,
   610    632       ThemeDrawState drawState,
   611    633       Ttk_State state,
   612    634       CGContextRef context)
................................................................................
   636    658   
   637    659       /*
   638    660        * If pressed, paint the appropriate half blue.
   639    661        */
   640    662       
   641    663       if (state & TTK_STATE_PRESSED) {
   642    664   	CGRect clip = bounds;
          665  +
   643    666   	clip.size.height /= 2;
   644    667   	CGContextSaveGState(context);
   645    668   	if (drawState == kThemeStatePressedDown) {
   646    669   	    clip.origin.y += clip.size.height;
   647    670   	}
   648    671   	CGContextClipToRect(context, clip);
   649    672   	GradientFillRoundedRectangle(context, bounds, 5,
   650         -				   darkSelectedGradient, 2);
          673  +		darkSelectedGradient, 2);
   651    674   	CGContextRestoreGState(context);
   652    675       }
   653    676       DrawUpDownArrows(context, bounds, 3, 5, whiteRGBA);
   654    677       HighlightButtonBorder(context, bounds);
   655    678   }
   656    679   
   657    680   /*----------------------------------------------------------------------
................................................................................
   710    733       Ttk_State state,
   711    734       CGContextRef context)
   712    735   {
   713    736       CGRect checkbounds = {{0, bounds.size.height/2 - 8},{16, 16}};
   714    737       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   715    738       NSColor *stroke;
   716    739       CGFloat x, y;
          740  +
   717    741       bounds = CGRectOffset(checkbounds, bounds.origin.x, bounds.origin.y);
   718    742       x = bounds.origin.x;
   719    743       y = bounds.origin.y;
   720    744   
   721    745       CGContextClipToRect(context, bounds);
   722    746       FillButtonBackground(context, bounds, 4);
   723    747       bounds = CGRectInset(bounds, 1, 1);
................................................................................
   737    761   	    stroke = [NSColor disabledControlTextColor];
   738    762   	} else {
   739    763   	    stroke = [NSColor controlTextColor];
   740    764   	}
   741    765   	CGContextSetStrokeColorWithColor(context, stroke.CGColor);
   742    766       }
   743    767       if (state & TTK_STATE_SELECTED) {
          768  +	CGPoint check[3] = {{x+4, y+8}, {x+7, y+11}, {x+11, y+4}};
          769  +
   744    770   	CGContextSetLineWidth(context, 1.5);
   745    771   	CGContextBeginPath(context);
   746         -	CGPoint check[3] = {{x+4, y+8}, {x+7, y+11}, {x+11, y+4}};
   747    772   	CGContextAddLines(context, check, 3);
   748    773   	CGContextStrokePath(context);
   749    774       } else if (state & TTK_STATE_ALTERNATE) {
          775  +	CGPoint bar[2] = {{x+4, y+8}, {x+12, y+8}};
          776  +
   750    777   	CGContextSetLineWidth(context, 2.0);
   751    778   	CGContextBeginPath(context);
   752         -	CGPoint bar[2] = {{x+4, y+8}, {x+12, y+8}};
   753    779   	CGContextAddLines(context, bar, 2);
   754    780   	CGContextStrokePath(context);
   755    781       }
   756    782   }
   757    783   
   758    784   /*----------------------------------------------------------------------
   759    785    * DrawDarkRadioButton --
   760    786    *
   761         - *    This is a standalone drawing procedure which draws RadioButtons
   762         - *    in the Dark Mode style.
          787  + *    This is a standalone drawing procedure which draws RadioButtons in the
          788  + *    Dark Mode style.
   763    789    */
   764    790   
   765    791   static void DrawDarkRadioButton(
   766    792       CGRect bounds,
   767    793       Ttk_State state,
   768    794       CGContextRef context)
   769    795   {
   770    796       CGRect checkbounds = {{0, bounds.size.height/2 - 9},{18, 18}};
   771    797       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   772    798       NSColor *fill;
   773    799       CGFloat x, y;
          800  +
   774    801       bounds = CGRectOffset(checkbounds, bounds.origin.x, bounds.origin.y);
   775    802       x = bounds.origin.x;
   776    803       y = bounds.origin.y;
   777    804   
   778    805       CGContextClipToRect(context, bounds);
   779    806       FillButtonBackground(context, bounds, 9);
   780    807       bounds = CGRectInset(bounds, 1, 1);
................................................................................
   794    821   	    fill = [NSColor disabledControlTextColor];
   795    822   	} else {
   796    823   	    fill = [NSColor controlTextColor];
   797    824   	}
   798    825   	CGContextSetFillColorWithColor(context, fill.CGColor);
   799    826       }
   800    827       if (state & TTK_STATE_SELECTED) {
   801         -	CGContextBeginPath(context);
   802    828   	CGRect dot = {{x + 6, y + 6}, {6, 6}};
          829  +
          830  +	CGContextBeginPath(context);
   803    831   	CGContextAddEllipseInRect(context, dot);
   804    832   	CGContextFillPath(context);
   805    833       } else if (state & TTK_STATE_ALTERNATE) {
   806    834   	CGRect bar = {{x + 5, y + 8}, {8, 2}};
          835  +
   807    836   	CGContextFillRect(context, bar);
   808    837       }
   809    838   }
   810    839   
   811    840   /*----------------------------------------------------------------------
   812    841    * DrawDarkTab --
   813    842    *
................................................................................
   869    898   	    CGContextSetShouldAntialias(context, false);
   870    899   	    stroke = [NSColor colorWithColorSpace: deviceRGB
   871    900   				       components: darkTabSeparator
   872    901   					    count: 4];
   873    902   	    CGContextSetStrokeColorWithColor(context, stroke.CGColor);
   874    903   	    CGContextBeginPath(context);
   875    904   	    CGContextMoveToPoint(context, originalBounds.origin.x,
   876         -	        originalBounds.origin.y + 1);
          905  +		    originalBounds.origin.y + 1);
   877    906   	    CGContextAddLineToPoint(context, originalBounds.origin.x,
   878         -	        originalBounds.origin.y + originalBounds.size.height - 1);
          907  +		    originalBounds.origin.y + originalBounds.size.height - 1);
   879    908   	    CGContextStrokePath(context);
   880    909   	    CGContextRestoreGState(context);
   881    910   	}
   882    911       } else {
   883    912   	/*
   884    913   	 * This is the selected tab; paint it blue.  If it is first, cover up
   885    914   	 * the separator line drawn by the second one.  (The selected tab is
................................................................................
   887    916   	 */
   888    917   
   889    918   	if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) {
   890    919   	    bounds.size.width += 1;
   891    920   	}
   892    921   	if (!(state & TTK_STATE_BACKGROUND)) {
   893    922   	    GradientFillRoundedRectangle(context, bounds, 4,
   894         -					 darkSelectedGradient, 2);
          923  +		    darkSelectedGradient, 2);
   895    924   	} else {
   896    925   	    faceColor = [NSColor colorWithColorSpace: deviceRGB
   897    926   				     components: darkInactiveSelectedTab
   898    927   					  count: 4];
   899    928   	    SolidFillRoundedRectangle(context, bounds, 4, faceColor);
   900    929   	}
   901    930   	HighlightButtonBorder(context, bounds);
   902    931       }
   903    932   }
   904         -
          933  +
   905    934   /*----------------------------------------------------------------------
   906    935    * DrawDarkSeparator --
   907    936    *
   908         - *    This is a standalone drawing procedure which draws a separator widget
   909         - *    in Dark Mode.
          937  + *    This is a standalone drawing procedure which draws a separator widget in
          938  + *    Dark Mode.
   910    939    */
   911    940   
   912    941   static void DrawDarkSeparator(
   913    942       CGRect bounds,
   914    943       CGContextRef context,
   915    944       Tk_Window tkwin)
   916    945   {
   917    946       static CGFloat fill[4] = {1.0, 1.0, 1.0, 0.3};
   918    947       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   919    948       NSColor *fillColor = [NSColor colorWithColorSpace: deviceRGB
   920    949   					   components: fill
   921    950   						count:4];
          951  +
   922    952       CGContextSetFillColorWithColor(context, fillColor.CGColor);
   923    953       CGContextFillRect(context, bounds);
   924    954   }
   925         -
          955  +
   926    956   /*----------------------------------------------------------------------
   927    957    * DrawDarkFrame --
   928    958    *
   929         - *    This is a standalone drawing procedure which draws various
   930         - *    types of borders in Dark Mode.
          959  + *    This is a standalone drawing procedure which draws various types of
          960  + *    borders in Dark Mode.
   931    961    */
   932    962   
   933    963   static void DrawDarkFrame(
   934    964       CGRect bounds,
   935    965       CGContextRef context,
   936    966       HIThemeFrameKind kind)
   937    967   {
   938    968       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   939    969       NSColor *stroke;
   940         -    CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
   941    970       CGFloat x = bounds.origin.x, y = bounds.origin.y;
   942    971       CGFloat w = bounds.size.width, h = bounds.size.height;
   943    972       CGPoint topPart[4] = {
   944    973   	{x, y + h - 1}, {x, y}, {x + w, y}, {x + w, y + h - 1}
   945    974       };
   946    975       CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}}; 
   947    976       CGPoint accent[2] = {{x, y + 1}, {x + w, y + 1}};
   948         -    switch(kind) {
          977  +
          978  +    CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
          979  +    switch (kind) {
   949    980       case kHIThemeFrameTextFieldSquare:
   950    981   	CGContextSaveGState(context);
   951    982   	CGContextSetShouldAntialias(context, false);
   952    983   	CGContextBeginPath(context);
   953    984   	stroke = [NSColor colorWithColorSpace: deviceRGB
   954    985   				       components: darkFrameTop
   955    986   					    count: 4];
................................................................................
   974   1005   	break;
   975   1006       }
   976   1007   }
   977   1008   
   978   1009   /*----------------------------------------------------------------------
   979   1010    * DrawListHeader --
   980   1011    *
   981         - *    This is a standalone drawing procedure which draws column
   982         - *    headers for a Treeview in the Dark Mode.
         1012  + *	This is a standalone drawing procedure which draws column headers for a
         1013  + *	Treeview in the Dark Mode.
   983   1014    */
   984   1015   
   985   1016   static void DrawDarkListHeader(
   986   1017       CGRect bounds,
   987   1018       CGContextRef context,
   988   1019       Tk_Window tkwin,
   989   1020       int state)
   990   1021   {
   991   1022       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
   992   1023       NSColor *stroke;
   993         -    CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
   994   1024       CGFloat x = bounds.origin.x, y = bounds.origin.y;
   995   1025       CGFloat w = bounds.size.width, h = bounds.size.height;
   996   1026       CGPoint top[2] = {{x, y}, {x + w, y}};
   997   1027       CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}}; 
   998   1028       CGPoint separator[2] = {{x + w, y + 3}, {x + w, y + h - 3}};
   999   1029   
         1030  +    CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace);
  1000   1031       CGContextSaveGState(context);
  1001   1032       CGContextSetShouldAntialias(context, false);
  1002   1033       stroke = [NSColor colorWithColorSpace: deviceRGB
  1003   1034   			       components: darkFrameBottom
  1004   1035   				    count: 4];
  1005   1036       CGContextSetStrokeColorWithColor(context, stroke.CGColor);
  1006   1037       CGContextBeginPath(context);
................................................................................
  1028   1059   #endif /* MAC_OS_X_VERSION_MIN_REQUIRED >101300 */
  1029   1060   
  1030   1061   /*----------------------------------------------------------------------
  1031   1062    * +++ Button element: Used for elements drawn with DrawThemeButton.
  1032   1063    */
  1033   1064   
  1034   1065   /*
  1035         - * When Ttk draws the various types of buttons, a pointer to one of these
  1036         - * is passed as the clientData.
         1066  + * When Ttk draws the various types of buttons, a pointer to one of these is
         1067  + * passed as the clientData.
  1037   1068    */
  1038   1069   
  1039   1070   typedef struct {
  1040   1071       ThemeButtonKind kind;
  1041   1072       ThemeMetric heightMetric;
  1042   1073   } ThemeButtonParams;
  1043   1074   
................................................................................
  1078   1109   {
  1079   1110       /*
  1080   1111        * See ButtonElementDraw for the explanation of why we always draw
  1081   1112        * PushButtons in the active state.
  1082   1113        */
  1083   1114   
  1084   1115       SInt32 HIThemeState;
         1116  +
  1085   1117       switch (params->kind) {
  1086   1118       case kThemePushButton:
  1087   1119   	HIThemeState = kThemeStateActive;
  1088   1120   	break;
  1089   1121       default:
  1090   1122   	HIThemeState = Ttk_StateTableLookup(ThemeStateTable, state);
  1091   1123   	break;
................................................................................
  1097   1129   	.kind = params ? params->kind : 0,
  1098   1130   	.value = Ttk_StateTableLookup(ButtonValueTable, state),
  1099   1131   	.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state),
  1100   1132       };
  1101   1133       return info;
  1102   1134   }
  1103   1135   
  1104         -static void ButtonElementMinSize(
  1105         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1106         -    int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
         1136  +static void
         1137  +ButtonElementMinSize(
         1138  +    void *clientData,
         1139  +    void *elementRecord,
         1140  +    Tk_Window tkwin,
         1141  +    int *minWidth, int *minHeight,
         1142  +    Ttk_Padding *paddingPtr)
  1107   1143   {
  1108   1144       ThemeButtonParams *params = clientData;
  1109   1145   
  1110   1146       if (params->heightMetric != NoThemeMetric) {
  1111   1147   	ChkErr(GetThemeMetric, params->heightMetric, minHeight);
  1112   1148   
  1113   1149   	/*
  1114         -	 * The theme height does not include the 1-pixel border around
  1115         -	 * the button, although it does include the 1-pixel shadow at
  1116         -	 * the bottom.
         1150  +	 * The theme height does not include the 1-pixel border around the
         1151  +	 * button, although it does include the 1-pixel shadow at the bottom.
  1117   1152   	 */
  1118   1153   
  1119   1154   	*minHeight += 2;
  1120   1155   
  1121   1156   	/*
  1122   1157   	 * The minwidth must be 0 to force the generic ttk code to compute the
  1123   1158   	 * correct text layout.  For example, a non-zero value will cause the
................................................................................
  1125   1160   	 * the style.
  1126   1161   	 */
  1127   1162   
  1128   1163   	*minWidth = 0;
  1129   1164       }
  1130   1165   }
  1131   1166   
  1132         -static void ButtonElementSize(
  1133         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1134         -    int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
         1167  +static void
         1168  +ButtonElementSize(
         1169  +    void *clientData,
         1170  +    void *elementRecord,
         1171  +    Tk_Window tkwin,
         1172  +    int *minWidth, int *minHeight,
         1173  +    Ttk_Padding *paddingPtr)
  1135   1174   {
  1136   1175       ThemeButtonParams *params = clientData;
  1137   1176       const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin);
  1138   1177       static const CGRect scratchBounds = {{0, 0}, {100, 100}};
  1139   1178       CGRect contentBounds, backgroundBounds;
  1140   1179       int verticalPad;
  1141   1180   
................................................................................
  1149   1188        * enough to contain the image of the button in any state, which might
  1150   1189        * include highlight borders, shadows, etc.  The content rectangle is not
  1151   1190        * centered vertically within the background rectangle, presumably because
  1152   1191        * shadows only appear on the bottom.  Nonetheless, when HITools is asked
  1153   1192        * to draw a button with a certain bounding rectangle it draws the button
  1154   1193        * centered within the rectangle.
  1155   1194        *
  1156         -     * To compute the effective padding around a button we request the
  1157         -     * content and bounding rectangles for a 100x100 button and use the
  1158         -     * padding between those.  However, we symmetrize the padding on the
  1159         -     * top and bottom, because that is how the button will be drawn.
         1195  +     * To compute the effective padding around a button we request the content
         1196  +     * and bounding rectangles for a 100x100 button and use the padding between
         1197  +     * those. However, we symmetrize the padding on the top and bottom, because
         1198  +     * that is how the button will be drawn.
  1160   1199        */
  1161   1200   
  1162   1201       ChkErr(HIThemeGetButtonContentBounds,
  1163   1202   	    &scratchBounds, &info, &contentBounds);
  1164   1203       ChkErr(HIThemeGetButtonBackgroundBounds,
  1165   1204   	    &scratchBounds, &info, &backgroundBounds);
  1166   1205       paddingPtr->left = contentBounds.origin.x - backgroundBounds.origin.x;
  1167   1206       paddingPtr->right =
  1168   1207   	    CGRectGetMaxX(backgroundBounds) - CGRectGetMaxX(contentBounds);
  1169   1208       verticalPad = backgroundBounds.size.height - contentBounds.size.height;
  1170   1209       paddingPtr->top = paddingPtr->bottom = verticalPad / 2;
  1171   1210   }
  1172   1211   
  1173         -static void ButtonElementDraw(
  1174         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1175         -    Drawable d, Ttk_Box b, Ttk_State state)
         1212  +static void
         1213  +ButtonElementDraw(
         1214  +    void *clientData,
         1215  +    void *elementRecord,
         1216  +    Tk_Window tkwin,
         1217  +    Drawable d,
         1218  +    Ttk_Box b,
         1219  +    Ttk_State state)
  1176   1220   {
  1177   1221       ThemeButtonParams *params = clientData;
  1178   1222       CGRect bounds = BoxToRect(d, b);
  1179   1223       HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state, tkwin);
  1180   1224       bounds = NormalizeButtonBounds(params->heightMetric, bounds);
  1181   1225       
  1182         -    BEGIN_DRAWING(d)
         1226  +    BEGIN_DRAWING(d);
  1183   1227       if (TkMacOSXInDarkMode(tkwin)) {
  1184   1228   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1185   1229   	switch (info.kind) {
  1186   1230   	case kThemePushButton:
  1187   1231   	case kThemePopupButton:
  1188   1232   	    DrawDarkButton(bounds, info.kind, state, dc.context);
  1189   1233   	    break;
................................................................................
  1231   1275   	    info.value == kThemeButtonMixed) {
  1232   1276   	    info.value = kThemeButtonOff;
  1233   1277   	    info.state = kThemeStateInactive;
  1234   1278   	}
  1235   1279   	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
  1236   1280   		NULL);
  1237   1281       }
  1238         -    END_DRAWING
         1282  +    END_DRAWING;
  1239   1283   }
  1240   1284   
  1241   1285   static Ttk_ElementSpec ButtonElementSpec = {
  1242   1286       TK_STYLE_VERSION_2,
  1243   1287       sizeof(NullElement),
  1244   1288       TtkNullElementOptions,
  1245   1289       ButtonElementSize,
................................................................................
  1311   1355    * between the content in the tab view and the tab-view edges.
  1312   1356    *
  1313   1357    * <URL: http://developer.apple.com/documentation/userexperience/Conceptual/
  1314   1358    *       AppleHIGuidelines/XHIGControls/XHIGControls.html#//apple_ref/doc/uid/
  1315   1359    *       TP30000359-TPXREF116>
  1316   1360    */
  1317   1361   
  1318         -static void TabElementSize(
  1319         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1320         -    int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
         1362  +static void
         1363  +TabElementSize(
         1364  +    void *clientData,
         1365  +    void *elementRecord,
         1366  +    Tk_Window tkwin,
         1367  +    int *minWidth, int *minHeight,
         1368  +    Ttk_Padding *paddingPtr)
  1321   1369   {
  1322         -    GetThemeMetric(kThemeMetricLargeTabHeight, (SInt32 *)minHeight);
         1370  +    GetThemeMetric(kThemeMetricLargeTabHeight, (SInt32 *) minHeight);
  1323   1371       *paddingPtr = Ttk_MakePadding(0, 0, 0, 2);
  1324         -
  1325   1372   }
  1326   1373   
  1327         -static void TabElementDraw(
  1328         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1329         -    Drawable d, Ttk_Box b, Ttk_State state)
         1374  +static void
         1375  +TabElementDraw(
         1376  +    void *clientData,
         1377  +    void *elementRecord,
         1378  +    Tk_Window tkwin,
         1379  +    Drawable d,
         1380  +    Ttk_Box b,
         1381  +    Ttk_State state)
  1330   1382   {
  1331   1383       CGRect bounds = BoxToRect(d, b);
  1332   1384       HIThemeTabDrawInfo info = {
  1333   1385   	.version = 1,
  1334   1386   	.style = Ttk_StateTableLookup(TabStyleTable, state),
  1335   1387   	.direction = kThemeTabNorth,
  1336   1388   	.size = kHIThemeTabSizeNormal,
  1337   1389   	.adornment = Ttk_StateTableLookup(TabAdornmentTable, state),
  1338   1390   	.kind = kHIThemeTabKindNormal,
  1339   1391   	.position = Ttk_StateTableLookup(TabPositionTable, state),
  1340   1392       };
  1341         -    BEGIN_DRAWING(d)
         1393  +
         1394  +    BEGIN_DRAWING(d);
  1342   1395   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1343   1396       if (TkMacOSXInDarkMode(tkwin)) {
  1344   1397   	DrawDarkTab(bounds, state, dc.context);
  1345   1398       } else {
  1346   1399   	ChkErr(HIThemeDrawTab, &bounds, &info, dc.context, HIOrientation, NULL);
  1347   1400       }
  1348   1401   #else
  1349   1402       ChkErr(HIThemeDrawTab, &bounds, &info, dc.context, HIOrientation, NULL);
  1350   1403   #endif
  1351         -    END_DRAWING
         1404  +    END_DRAWING;
  1352   1405   }
  1353   1406   
  1354   1407   static Ttk_ElementSpec TabElementSpec = {
  1355   1408       TK_STYLE_VERSION_2,
  1356   1409       sizeof(NullElement),
  1357   1410       TtkNullElementOptions,
  1358   1411       TabElementSize,
................................................................................
  1371   1424   }
  1372   1425   
  1373   1426   static void PaneElementDraw(
  1374   1427       void *clientData, void *elementRecord, Tk_Window tkwin,
  1375   1428       Drawable d, Ttk_Box b, Ttk_State state)
  1376   1429   {
  1377   1430       CGRect bounds = BoxToRect(d, b);
         1431  +
  1378   1432       bounds.origin.y -= kThemeMetricTabFrameOverlap;
  1379   1433       bounds.size.height += kThemeMetricTabFrameOverlap;
  1380         -    BEGIN_DRAWING(d)
         1434  +    BEGIN_DRAWING(d);
  1381   1435       if ([NSApp macMinorVersion] > 9) {
  1382   1436   #if MAC_OS_X_VERSION_MAX_ALLOWED > 1080
  1383         -    DrawGroupBox(bounds, dc.context, tkwin);
         1437  +	DrawGroupBox(bounds, dc.context, tkwin);
  1384   1438   #endif
  1385   1439       } else { 
  1386         -    HIThemeTabPaneDrawInfo info = {
  1387         -	.version = 1,
  1388         -	.state = Ttk_StateTableLookup(ThemeStateTable, state),
  1389         -	.direction = kThemeTabNorth,
  1390         -	.size = kHIThemeTabSizeNormal,
  1391         -	.kind = kHIThemeTabKindNormal,
  1392         -	.adornment = kHIThemeTabPaneAdornmentNormal,
  1393         -    };
  1394         -    bounds.origin.y -= kThemeMetricTabFrameOverlap;
  1395         -    bounds.size.height += kThemeMetricTabFrameOverlap;
  1396         -    ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation);
         1440  +	HIThemeTabPaneDrawInfo info = {
         1441  +	    .version = 1,
         1442  +	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
         1443  +	    .direction = kThemeTabNorth,
         1444  +	    .size = kHIThemeTabSizeNormal,
         1445  +	    .kind = kHIThemeTabKindNormal,
         1446  +	    .adornment = kHIThemeTabPaneAdornmentNormal,
         1447  +	};
         1448  +	bounds.origin.y -= kThemeMetricTabFrameOverlap;
         1449  +	bounds.size.height += kThemeMetricTabFrameOverlap;
         1450  +	ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation);
  1397   1451       }
  1398         -    END_DRAWING
         1452  +    END_DRAWING;
  1399   1453   }
  1400   1454   
  1401   1455   static Ttk_ElementSpec PaneElementSpec = {
  1402   1456       TK_STYLE_VERSION_2,
  1403   1457       sizeof(NullElement),
  1404   1458       TtkNullElementOptions,
  1405   1459       PaneElementSize,
................................................................................
  1414   1468    * a maximum of 2 pixels thick."
  1415   1469    *
  1416   1470    * "Maximum of 2 pixels thick" is apparently a lie; looks more like 4 to me
  1417   1471    * with shading.
  1418   1472    */
  1419   1473   
  1420   1474   static void GroupElementSize(
  1421         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1422         -    int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
         1475  +    void *clientData,
         1476  +    void *elementRecord,
         1477  +    Tk_Window tkwin,
         1478  +    int *minWidth, int *minHeight,
         1479  +    Ttk_Padding *paddingPtr)
  1423   1480   {
  1424   1481       *paddingPtr = Ttk_UniformPadding(4);
  1425   1482   }
  1426   1483   
  1427   1484   static void GroupElementDraw(
  1428         -    void *clientData, void *elementRecord, Tk_Window tkwin,
  1429         -    Drawable d, Ttk_Box b, Ttk_State state)
         1485  +    void *clientData,
         1486  +    void *elementRecord,
         1487  +    Tk_Window tkwin,
         1488  +    Drawable d,
         1489  +    Ttk_Box b,
         1490  +    Ttk_State state)
  1430   1491   {
  1431   1492       CGRect bounds = BoxToRect(d, b);
  1432   1493   
  1433         -    BEGIN_DRAWING(d)
         1494  +    BEGIN_DRAWING(d);
  1434   1495       if ([NSApp macMinorVersion] > 9) {
  1435   1496   #if MAC_OS_X_VERSION_MAX_ALLOWED > 1080
  1436         -    DrawGroupBox(bounds, dc.context, tkwin);
         1497  +	DrawGroupBox(bounds, dc.context, tkwin);
  1437   1498   #endif
  1438   1499       } else { 
  1439         -    const HIThemeGroupBoxDrawInfo info = {
  1440         -	.version = 0,
  1441         -	.state = Ttk_StateTableLookup(ThemeStateTable, state),
  1442         -	.kind = kHIThemeGroupBoxKindPrimaryOpaque,
  1443         -    };
  1444         -    ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation);
         1500  +	const HIThemeGroupBoxDrawInfo info = {
         1501  +	    .version = 0,
         1502  +	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
         1503  +	    .kind = kHIThemeGroupBoxKindPrimaryOpaque,
         1504  +	};
         1505  +	ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation);
  1445   1506       }
  1446         -    END_DRAWING
         1507  +    END_DRAWING;
  1447   1508   }
  1448   1509   
  1449   1510   static Ttk_ElementSpec GroupElementSpec = {
  1450   1511       TK_STYLE_VERSION_2,
  1451   1512       sizeof(NullElement),
  1452   1513       TtkNullElementOptions,
  1453   1514       GroupElementSize,
................................................................................
  1465   1526       Tcl_Obj	*fieldbackgroundObj;
  1466   1527   } EntryElement;
  1467   1528   
  1468   1529   #define ENTRY_DEFAULT_BACKGROUND "systemTextBackgroundColor"
  1469   1530   
  1470   1531   static Ttk_ElementOptionSpec EntryElementOptions[] = {
  1471   1532       { "-background", TK_OPTION_BORDER,
  1472         -      Tk_Offset(EntryElement,backgroundObj), ENTRY_DEFAULT_BACKGROUND },
         1533  +	Tk_Offset(EntryElement,backgroundObj), ENTRY_DEFAULT_BACKGROUND },
  1473   1534       { "-fieldbackground", TK_OPTION_BORDER,
  1474         -      Tk_Offset(EntryElement,fieldbackgroundObj), ENTRY_DEFAULT_BACKGROUND },
         1535  +	Tk_Offset(EntryElement,fieldbackgroundObj), ENTRY_DEFAULT_BACKGROUND },
  1475   1536       {0}
  1476   1537   };
  1477   1538   
  1478   1539   static void EntryElementSize(
  1479   1540       void *clientData, void *elementRecord, Tk_Window tkwin,
  1480   1541       int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
  1481   1542   {
................................................................................
  1491   1552       CGRect bounds = BoxToRect(d, inner);
  1492   1553       NSColor *background;
  1493   1554       Tk_3DBorder backgroundPtr = NULL;
  1494   1555       static const char *defaultBG = ENTRY_DEFAULT_BACKGROUND;
  1495   1556   
  1496   1557       if (TkMacOSXInDarkMode(tkwin)) {
  1497   1558   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1498         -	BEGIN_DRAWING(d)
         1559  +	BEGIN_DRAWING(d);
  1499   1560   	NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
  1500   1561   	CGFloat fill[4];
         1562  +
  1501   1563   	GetBackgroundColor(dc.context, tkwin, 1, fill);
  1502   1564   	background = [NSColor colorWithColorSpace: deviceRGB
  1503   1565   				       components: fill
  1504   1566   					    count: 4];
  1505   1567   	CGContextSetFillColorWithColor(dc.context, background.CGColor);
  1506   1568   	CGContextFillRect(dc.context, bounds);
  1507   1569   	DrawDarkFrame(bounds, dc.context, kHIThemeFrameTextFieldSquare);
  1508         -	END_DRAWING
         1570  +	END_DRAWING;
  1509   1571   #endif
  1510   1572       } else {
  1511   1573   	const HIThemeFrameDrawInfo info = {
  1512   1574   	    .version = 0,
  1513   1575   	    .kind = kHIThemeFrameTextFieldSquare,
  1514   1576   	    .state = Ttk_StateTableLookup(ThemeStateTable, state),
  1515   1577   	    .isFocused = state & TTK_STATE_FOCUS,
................................................................................
  1530   1592   	    backgroundPtr = Tk_Get3DBorderFromObj(tkwin,e->backgroundObj);
  1531   1593   	}
  1532   1594   	if (backgroundPtr != NULL) {
  1533   1595   	    XFillRectangle(Tk_Display(tkwin), d,
  1534   1596   		    Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC),
  1535   1597   		    inner.x, inner.y, inner.width, inner.height);
  1536   1598   	}
  1537         -	BEGIN_DRAWING(d)
         1599  +	BEGIN_DRAWING(d);
  1538   1600   	if (backgroundPtr == NULL) {
  1539   1601   	    background = [NSColor textBackgroundColor];
  1540   1602   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
  1541   1603   	    CGContextSetFillColorWithColor(dc.context, background.CGColor);
  1542   1604   #else
  1543   1605   	    CGContextSetRGBFillColor(dc.context, 1.0, 1.0, 1.0, 1.0);
  1544   1606   #endif
  1545   1607   	    CGContextFillRect(dc.context, bounds);
  1546   1608   	}
  1547   1609   	ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation);
  1548         -	END_DRAWING
         1610  +	END_DRAWING;
  1549   1611       }
  1550   1612       /*if (state & TTK_STATE_FOCUS) {
  1551   1613   	ChkErr(DrawThemeFocusRect, &bounds, 1);
  1552   1614       }*/
  1553   1615   }
  1554   1616   
  1555   1617   static Ttk_ElementSpec EntryElementSpec = {
................................................................................
  1600   1662   	.version = 0,
  1601   1663   	.state = Ttk_StateTableLookup(ThemeStateTable, state),
  1602   1664   	.kind = kThemeComboBox,
  1603   1665   	.value = Ttk_StateTableLookup(ButtonValueTable, state),
  1604   1666   	.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state),
  1605   1667       };
  1606   1668   
  1607         -    BEGIN_DRAWING(d)
         1669  +    BEGIN_DRAWING(d);
  1608   1670       bounds.origin.y += 1;
  1609   1671       if (TkMacOSXInDarkMode(tkwin)) {
  1610   1672   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1611   1673   	bounds.size.height += 1;
  1612   1674   	DrawDarkButton(bounds, info.kind, state, dc.context);
  1613   1675   #endif
  1614         -    } else
  1615         -	{
         1676  +    } else {
  1616   1677   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
  1617   1678   	if ((state & TTK_STATE_BACKGROUND) &&
  1618         -	    !(state & TTK_STATE_DISABLED)) {
         1679  +		!(state & TTK_STATE_DISABLED)) {
  1619   1680   	    NSColor *background = [NSColor textBackgroundColor];
  1620   1681   	    CGRect innerBounds = CGRectInset(bounds, 1, 2);
         1682  +
  1621   1683   	    SolidFillRoundedRectangle(dc.context, innerBounds, 4, background);
  1622   1684   	}
  1623   1685   #endif
  1624   1686   	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
  1625   1687       }
  1626         -    END_DRAWING
         1688  +    END_DRAWING;
  1627   1689   }
  1628   1690   
  1629   1691   static Ttk_ElementSpec ComboboxElementSpec = {
  1630   1692       TK_STYLE_VERSION_2,
  1631   1693       sizeof(NullElement),
  1632   1694       TtkNullElementOptions,
  1633   1695       ComboboxElementSize,
................................................................................
  1670   1732   
  1671   1733   static void SpinButtonUpElementDraw(
  1672   1734       void *clientData, void *elementRecord, Tk_Window tkwin,
  1673   1735       Drawable d, Ttk_Box b, Ttk_State state)
  1674   1736   {
  1675   1737       CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins));
  1676   1738       int infoState;
         1739  +
  1677   1740       bounds.size.height *= 2;
  1678   1741       if (state & TTK_STATE_PRESSED) {
  1679   1742   	infoState = kThemeStatePressedUp;
  1680   1743       } else {
  1681   1744   	infoState = Ttk_StateTableLookup(ThemeStateTable, state);
  1682   1745       }
         1746  +
  1683   1747       const HIThemeButtonDrawInfo info = {
  1684   1748   	.version = 0,
  1685   1749   	.state = infoState,
  1686   1750   	.kind = kThemeIncDecButton,
  1687   1751   	.value = Ttk_StateTableLookup(ButtonValueTable, state),
  1688   1752   	.adornment = kThemeAdornmentNone,
  1689   1753       };
  1690         -    BEGIN_DRAWING(d)
         1754  +
         1755  +    BEGIN_DRAWING(d);
  1691   1756   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1692   1757       if (TkMacOSXInDarkMode(tkwin)) {
  1693   1758   	DrawDarkIncDecButton(bounds, infoState, state, dc.context);
  1694   1759       } else
  1695   1760   #endif
  1696   1761       {
  1697   1762   	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
  1698   1763       }
  1699         -    END_DRAWING
         1764  +    END_DRAWING;
  1700   1765   }
  1701   1766   
  1702   1767   static Ttk_ElementSpec SpinButtonUpElementSpec = {
  1703   1768       TK_STYLE_VERSION_2,
  1704   1769       sizeof(NullElement),
  1705   1770       TtkNullElementOptions,
  1706   1771       SpinButtonUpElementSize,
................................................................................
  1721   1786   
  1722   1787   static void SpinButtonDownElementDraw(
  1723   1788       void *clientData, void *elementRecord, Tk_Window tkwin,
  1724   1789       Drawable d, Ttk_Box b, Ttk_State state)
  1725   1790   {
  1726   1791       CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins));
  1727   1792       int infoState = 0;
         1793  +
  1728   1794       bounds.origin.y -= bounds.size.height;
  1729   1795       bounds.size.height *= 2;
  1730   1796       if (state & TTK_STATE_PRESSED) {
  1731   1797   	infoState = kThemeStatePressedDown;
  1732   1798       } else {
  1733         -	return;
         1799  +	return;		// ???
  1734   1800       }
  1735   1801       const HIThemeButtonDrawInfo info = {
  1736   1802   	.version = 0,
  1737   1803   	.state = infoState,
  1738   1804   	.kind = kThemeIncDecButton,
  1739   1805   	.value = Ttk_StateTableLookup(ButtonValueTable, state),
  1740   1806   	.adornment = kThemeAdornmentNone,
  1741   1807       };
  1742   1808   
  1743         -    BEGIN_DRAWING(d)
         1809  +    BEGIN_DRAWING(d);
  1744   1810   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1745   1811       if (TkMacOSXInDarkMode(tkwin)) {
  1746   1812   	DrawDarkIncDecButton(bounds, infoState, state, dc.context);
  1747   1813       } else
  1748   1814   #endif
  1749   1815       {
  1750         -	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
         1816  +	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation,
         1817  +		NULL);
  1751   1818       }
  1752         -    END_DRAWING
         1819  +    END_DRAWING;
  1753   1820   }
  1754   1821   
  1755   1822   static Ttk_ElementSpec SpinButtonDownElementSpec = {
  1756   1823       TK_STYLE_VERSION_2,
  1757   1824       sizeof(NullElement),
  1758   1825       TtkNullElementOptions,
  1759   1826       SpinButtonDownElementSize,
................................................................................
  1846   1913   		kThemeThumbPressed : 0;
  1847   1914   	if (state & TTK_STATE_ALTERNATE) {
  1848   1915   	    info.trackInfo.slider.thumbDir = kThemeThumbDownward;
  1849   1916   	} else {
  1850   1917   	    info.trackInfo.slider.thumbDir = kThemeThumbPlain;
  1851   1918   	}
  1852   1919       }
  1853         -    BEGIN_DRAWING(d)
         1920  +    BEGIN_DRAWING(d);
  1854   1921   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1855   1922       if (TkMacOSXInDarkMode(tkwin)) {
  1856   1923   	CGRect bounds = BoxToRect(d, b);
  1857   1924   	NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
  1858   1925   	NSColor *trackColor = [NSColor colorWithColorSpace: deviceRGB
  1859   1926   	 					components: darkTrack
  1860   1927   	 					     count: 4];
         1928  +
  1861   1929   	if (orientation == TTK_ORIENT_HORIZONTAL) {
  1862   1930   	    bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 2);
  1863   1931   	} else {
  1864   1932   	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 2);
  1865   1933   	}
  1866   1934   	SolidFillRoundedRectangle(dc.context, bounds, 2, trackColor);
  1867   1935       }
  1868   1936   #endif
  1869   1937       ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
  1870         -    END_DRAWING
         1938  +    END_DRAWING;
  1871   1939   }
  1872   1940   
  1873   1941   static Ttk_ElementSpec TrackElementSpec = {
  1874   1942       TK_STYLE_VERSION_2,
  1875   1943       sizeof(TrackElement),
  1876   1944       TrackElementOptions,
  1877   1945       TrackElementSize,
................................................................................
  1883   1951    * Has geometry only. The Scale widget adjusts the position of this element,
  1884   1952    * and uses it for hit detection. In the Aqua theme, the slider is actually
  1885   1953    * drawn as part of the trough element.
  1886   1954    *
  1887   1955    * Also buggy: The geometry here is a Wild-Assed-Guess; I can't figure out how
  1888   1956    * to get the Appearance Manager to tell me the slider size.
  1889   1957    */
         1958  +
  1890   1959   static void SliderElementSize(
  1891   1960       void *clientData, void *elementRecord, Tk_Window tkwin,
  1892   1961       int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
  1893   1962   {
  1894   1963       *minWidth = *minHeight = 24;
  1895   1964   }
  1896   1965   
................................................................................
  1967   2036   	.attributes = kThemeTrackShowThumb |
  1968   2037   		(orientation == TTK_ORIENT_HORIZONTAL ?
  1969   2038   		kThemeTrackHorizontal : 0),
  1970   2039   	.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state),
  1971   2040   	.trackInfo.progress.phase = phase,
  1972   2041       };
  1973   2042   
  1974         -    BEGIN_DRAWING(d)
         2043  +    BEGIN_DRAWING(d);
  1975   2044   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  1976   2045       if (TkMacOSXInDarkMode(tkwin)) {
  1977   2046   	CGRect bounds = BoxToRect(d, b);
  1978   2047   	NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
  1979   2048   	NSColor *trackColor = [NSColor colorWithColorSpace: deviceRGB
  1980   2049   	 					components: darkTrack
  1981   2050   	 					     count: 4];
................................................................................
  1984   2053   	} else {
  1985   2054   	    bounds = CGRectInset(bounds, bounds.size.width/2 - 3, 1);
  1986   2055   	}
  1987   2056   	SolidFillRoundedRectangle(dc.context, bounds, 3, trackColor);
  1988   2057       }
  1989   2058   #endif
  1990   2059       ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation);
  1991         -    END_DRAWING
         2060  +    END_DRAWING;
  1992   2061   }
  1993   2062   
  1994   2063   static Ttk_ElementSpec PbarElementSpec = {
  1995   2064       TK_STYLE_VERSION_2,
  1996   2065       sizeof(PbarElement),
  1997   2066       PbarElementOptions,
  1998   2067       PbarElementSize,
................................................................................
  2050   2119   {
  2051   2120       ScrollbarElement *scrollbar = elementRecord;
  2052   2121       int orientation = TTK_ORIENT_HORIZONTAL;
  2053   2122       CGRect bounds = BoxToRect(d, b);
  2054   2123       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
  2055   2124       NSColor *troughColor;
  2056   2125       CGFloat *rgba = TkMacOSXInDarkMode(tkwin) ? darkTrough : lightTrough;
         2126  +
  2057   2127       Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation);
  2058   2128       if (orientation == TTK_ORIENT_HORIZONTAL) {
  2059   2129   	bounds = CGRectInset(bounds, 0, 1);
  2060   2130       } else {
  2061   2131   	bounds = CGRectInset(bounds, 1, 0);
  2062   2132       }
  2063   2133       troughColor = [NSColor colorWithColorSpace: deviceRGB
  2064   2134   				    components: rgba
  2065   2135   					 count: 4];
  2066         -    BEGIN_DRAWING(d)
         2136  +    BEGIN_DRAWING(d);
  2067   2137       if ([NSApp macMinorVersion] > 8) {
  2068   2138   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
  2069   2139   	CGContextSetFillColorWithColor(dc.context, troughColor.CGColor);
  2070   2140   #endif
  2071   2141       } else {
  2072   2142   	ChkErr(HIThemeSetFill, kThemeBrushDocumentWindowBackground, NULL,
  2073   2143   	       dc.context, HIOrientation);
  2074   2144       }
  2075   2145       CGContextFillRect(dc.context, bounds);
  2076         -    END_DRAWING
         2146  +    END_DRAWING;
  2077   2147   }
  2078   2148   
  2079   2149   static Ttk_ElementSpec TroughElementSpec = {
  2080   2150       TK_STYLE_VERSION_2,
  2081   2151       sizeof(ScrollbarElement),
  2082   2152       ScrollbarElementOptions,
  2083   2153       TroughElementSize,
................................................................................
  2101   2171   
  2102   2172   static void ThumbElementDraw(
  2103   2173       void *clientData, void *elementRecord, Tk_Window tkwin,
  2104   2174       Drawable d, Ttk_Box b, Ttk_State state)
  2105   2175   {
  2106   2176       ScrollbarElement *scrollbar = elementRecord;
  2107   2177       int orientation = TTK_ORIENT_HORIZONTAL;
         2178  +
  2108   2179       Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation);
  2109   2180   
  2110   2181       /*
  2111   2182        * In order to make ttk scrollbars work correctly it is necessary to be
  2112   2183        * able to display the thumb element at the size and location which the ttk
  2113   2184        * scrollbar widget requests.  The algorithm that HIToolbox uses to
  2114   2185        * determine the thumb geometry from the input values of min, max, value
................................................................................
  2125   2196   
  2126   2197       if ([NSApp macMinorVersion] > 8) {
  2127   2198   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
  2128   2199   	CGRect thumbBounds = BoxToRect(d, b);
  2129   2200   	NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
  2130   2201   	NSColor *thumbColor;
  2131   2202   	CGFloat *rgba;
  2132         -	if ((orientation == TTK_ORIENT_HORIZONTAL &&
  2133         -	     thumbBounds.size.width >= Tk_Width(tkwin) - 8) ||
  2134         -	    (orientation == TTK_ORIENT_VERTICAL &&
  2135         -	     thumbBounds.size.height >= Tk_Height(tkwin) - 8)) {
         2203  +
         2204  +	if ((orientation == TTK_ORIENT_HORIZONTAL
         2205  +		&& thumbBounds.size.width >= Tk_Width(tkwin) - 8)
         2206  +		|| (orientation == TTK_ORIENT_VERTICAL
         2207  +		&& thumbBounds.size.height >= Tk_Height(tkwin) - 8)) {
  2136   2208   	    return;
  2137   2209   	}
         2210  +
  2138   2211   	int isDark = TkMacOSXInDarkMode(tkwin);
         2212  +
  2139   2213   	if ((state & TTK_STATE_PRESSED) ||
  2140         -	    (state & TTK_STATE_HOVER) ) {
         2214  +		(state & TTK_STATE_HOVER)) {
  2141   2215   	    rgba = isDark ? darkActiveThumb : lightActiveThumb;
  2142   2216   	} else {
  2143   2217   	    rgba = isDark ? darkInactiveThumb : lightInactiveThumb;
  2144   2218   	}
  2145   2219   	thumbColor = [NSColor colorWithColorSpace: deviceRGB
  2146   2220   				       components: rgba
  2147   2221   					    count: 4];
  2148         -	BEGIN_DRAWING(d)
  2149         -	    SolidFillRoundedRectangle(dc.context, thumbBounds, 4, thumbColor);
  2150         -	END_DRAWING
         2222  +	BEGIN_DRAWING(d);
         2223  +	SolidFillRoundedRectangle(dc.context, thumbBounds, 4, thumbColor);
         2224  +	END_DRAWING;
  2151   2225   #endif
  2152   2226       } else {
  2153   2227   	double thumbSize, trackSize, visibleSize, viewSize;
  2154   2228   	MacDrawable *macWin = (MacDrawable *) Tk_WindowId(tkwin);
  2155   2229   	CGRect troughBounds = {{macWin->xOff, macWin->yOff},
  2156   2230   			       {Tk_Width(tkwin), Tk_Height(tkwin)}};
  2157   2231   
................................................................................
  2160   2234   	 * floats in the drawing routine.  All of values provided in the info
  2161   2235   	 * struct, namely min, max, value, and viewSize are only defined up to
  2162   2236   	 * an arbitrary scale factor.  To avoid roundoff error we scale so that
  2163   2237   	 * the viewSize is a large float which is smaller than the largest int.
  2164   2238   	 */
  2165   2239       
  2166   2240   	viewSize = RangeToFactor(100.0);
         2241  +
  2167   2242   	HIThemeTrackDrawInfo info = {
  2168   2243   	    .version = 0,
  2169   2244   	    .bounds = troughBounds,
  2170   2245   	    .min = 0,
  2171   2246   	    .attributes = kThemeTrackShowThumb | kThemeTrackThumbRgnIsNotGhost,
  2172   2247   	    .enableState = kThemeTrackActive
  2173   2248   	};
         2249  +
  2174   2250   	info.trackInfo.scrollbar.viewsize = viewSize*.8; 
  2175   2251   	if (orientation == TTK_ORIENT_HORIZONTAL) {
  2176   2252   	    trackSize = troughBounds.size.width;
  2177   2253   	    thumbSize = b.width;
  2178   2254   	    visibleSize = (thumbSize / trackSize) * viewSize;
  2179   2255   	    info.max = viewSize - visibleSize;
  2180   2256   	    info.value = info.max * (b.x / (trackSize - thumbSize)); 
................................................................................
  2182   2258   	    thumbSize = b.height;
  2183   2259   	    trackSize = troughBounds.size.height;
  2184   2260   	    visibleSize = (thumbSize / trackSize) * viewSize;
  2185   2261   	    info.max = viewSize - visibleSize;
  2186   2262   	    info.value = info.max * (b.y / (trackSize - thumbSize)); 
  2187   2263   	}
  2188   2264   	if ((state & TTK_STATE_PRESSED) ||
  2189         -	    (state & TTK_STATE_HOVER) ) {
         2265  +		(state & TTK_STATE_HOVER)) {
  2190   2266   	    info.trackInfo.scrollbar.pressState = kThemeThumbPressed;
  2191   2267   	} else {
  2192   2268   	    info.trackInfo.scrollbar.pressState = 0;
  2193   2269   	}
  2194   2270   	if (orientation == TTK_ORIENT_HORIZONTAL) {
  2195   2271   	    info.attributes |= kThemeTrackHorizontal;
  2196   2272   	} else {
  2197   2273   	    info.attributes &= ~kThemeTrackHorizontal;
  2198   2274   	}
  2199         -	BEGIN_DRAWING(d)
  2200         -	    HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationNormal);
  2201         -	END_DRAWING
  2202         -	    }
         2275  +	BEGIN_DRAWING(d);
         2276  +	HIThemeDrawTrack(&info, 0, dc.context, kHIThemeOrientationNormal);
         2277  +	END_DRAWING;
         2278  +    }
  2203   2279   }
  2204   2280   
  2205   2281   static Ttk_ElementSpec ThumbElementSpec = {
  2206   2282       TK_STYLE_VERSION_2,
  2207   2283       sizeof(ScrollbarElement),
  2208   2284       ScrollbarElementOptions,
  2209   2285       ThumbElementSize,
................................................................................
  2251   2327       CGRect bounds = BoxToRect(d, b);
  2252   2328       const HIThemeSeparatorDrawInfo info = {
  2253   2329   	.version = 0,
  2254   2330   	/* Separator only supports kThemeStateActive, kThemeStateInactive */
  2255   2331   	.state = Ttk_StateTableLookup(ThemeStateTable, state & TTK_STATE_BACKGROUND),
  2256   2332       };
  2257   2333   
  2258         -    BEGIN_DRAWING(d)
         2334  +    BEGIN_DRAWING(d);
  2259   2335   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  2260   2336       if (TkMacOSXInDarkMode(tkwin)) {
  2261   2337   	DrawDarkSeparator(bounds, dc.context, tkwin);
  2262   2338       } else {
  2263   2339   	ChkErr(HIThemeDrawSeparator, &bounds, &info, dc.context, HIOrientation);
  2264   2340       }
  2265   2341   #else
  2266   2342       ChkErr(HIThemeDrawSeparator, &bounds, &info, dc.context, HIOrientation);
  2267   2343   #endif
  2268         -    END_DRAWING
         2344  +    END_DRAWING;
  2269   2345   }
  2270   2346   
  2271   2347   static Ttk_ElementSpec SeparatorElementSpec = {
  2272   2348       TK_STYLE_VERSION_2,
  2273   2349       sizeof(NullElement),
  2274   2350       TtkNullElementOptions,
  2275   2351       SeparatorElementSize,
................................................................................
  2312   2388   	.state = Ttk_StateTableLookup(ThemeStateTable,
  2313   2389   		state & TTK_STATE_BACKGROUND),
  2314   2390   	.kind = kHIThemeGrowBoxKindNormal,
  2315   2391   	.direction = sizegripGrowDirection,
  2316   2392   	.size = kHIThemeGrowBoxSizeNormal,
  2317   2393       };
  2318   2394   
  2319         -    BEGIN_DRAWING(d)
         2395  +    BEGIN_DRAWING(d);
  2320   2396       ChkErr(HIThemeDrawGrowBox, &bounds.origin, &info, dc.context, HIOrientation);
  2321         -    END_DRAWING
         2397  +    END_DRAWING;
  2322   2398   }
  2323   2399   
  2324   2400   static Ttk_ElementSpec SizegripElementSpec = {
  2325   2401       TK_STYLE_VERSION_2,
  2326   2402       sizeof(NullElement),
  2327   2403       TtkNullElementOptions,
  2328   2404       SizegripElementSize,
................................................................................
  2377   2453       Drawable d, Ttk_Box b, Ttk_State state)
  2378   2454   {
  2379   2455       CGRect bounds = BoxToRect(d, b);
  2380   2456   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
  2381   2457       NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace];
  2382   2458       NSColor *bgColor;
  2383   2459       CGFloat fill[4];
  2384         -    BEGIN_DRAWING(d)
         2460  +
         2461  +    BEGIN_DRAWING(d);
  2385   2462       GetBackgroundColor(dc.context, tkwin, 0, fill);
  2386   2463       bgColor = [NSColor colorWithColorSpace: deviceRGB components: fill
  2387   2464   				     count: 4];
  2388   2465       CGContextSetFillColorSpace(dc.context, deviceRGB.CGColorSpace);
  2389   2466       CGContextSetFillColorWithColor(dc.context, bgColor.CGColor);
  2390   2467       CGContextFillRect(dc.context, bounds);
  2391         -    END_DRAWING
         2468  +    END_DRAWING;
  2392   2469   #else
  2393   2470       ThemeBrush brush = (state & TTK_STATE_BACKGROUND)
  2394   2471   	    ? kThemeBrushModelessDialogBackgroundInactive
  2395   2472   	    : kThemeBrushModelessDialogBackgroundActive;
  2396         -    BEGIN_DRAWING(d)
         2473  +
         2474  +    BEGIN_DRAWING(d);
  2397   2475       ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation);
  2398   2476       //QDSetPatternOrigin(PatternOrigin(tkwin, d));
  2399   2477       CGContextFillRect(dc.context, bounds);
  2400         -    END_DRAWING
         2478  +    END_DRAWING;
  2401   2479   #endif
  2402   2480   }
  2403   2481   
  2404   2482   static void BackgroundElementDraw(
  2405   2483       void *clientData, void *elementRecord, Tk_Window tkwin,
  2406   2484       Drawable d, Ttk_Box b, unsigned int state)
  2407   2485   {
  2408   2486       FillElementDraw(clientData, elementRecord, tkwin, d, Ttk_WinBox(tkwin),
  2409         -    		    state);
         2487  +	    state);
  2410   2488   }
  2411   2489   
  2412   2490   static Ttk_ElementSpec FillElementSpec = {
  2413   2491       TK_STYLE_VERSION_2,
  2414   2492       sizeof(NullElement),
  2415   2493       TtkNullElementOptions,
  2416   2494       TtkNullElementSize,
................................................................................
  2425   2503       BackgroundElementDraw
  2426   2504   };
  2427   2505   
  2428   2506   /*----------------------------------------------------------------------
  2429   2507    * +++ ToolbarBackground element -- toolbar style for frames.
  2430   2508    *
  2431   2509    *    This is very similar to the normal background element, but uses a
  2432         - *    different ThemeBrush in order to get the lighter pinstripe effect
  2433         - *    used in toolbars. We use SetThemeBackground() rather than
  2434         - *    ApplyThemeBackground() in order to get the right style.
         2510  + *    different ThemeBrush in order to get the lighter pinstripe effect used in
         2511  + *    toolbars. We use SetThemeBackground() rather than ApplyThemeBackground()
         2512  + *    in order to get the right style.
  2435   2513    *
  2436   2514    * <URL: http://developer.apple.com/documentation/Carbon/Reference/
  2437   2515    *    Appearance_Manager/appearance_manager/constant_7.html#/
  2438   2516    *    /apple_ref/doc/uid/TP30000243/C005321>
  2439   2517    *
  2440   2518    */
  2441   2519   
................................................................................
  2442   2520   static void ToolbarBackgroundElementDraw(
  2443   2521       void *clientData, void *elementRecord, Tk_Window tkwin,
  2444   2522       Drawable d, Ttk_Box b, Ttk_State state)
  2445   2523   {
  2446   2524       ThemeBrush brush = kThemeBrushToolbarBackground;
  2447   2525       CGRect bounds = BoxToRect(d, Ttk_WinBox(tkwin));
  2448   2526   
  2449         -    BEGIN_DRAWING(d)
         2527  +    BEGIN_DRAWING(d);
  2450   2528       ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation);
  2451   2529       //QDSetPatternOrigin(PatternOrigin(tkwin, d));
  2452   2530       CGContextFillRect(dc.context, bounds);
  2453         -    END_DRAWING
         2531  +    END_DRAWING;
  2454   2532   }
  2455   2533   
  2456   2534   static Ttk_ElementSpec ToolbarBackgroundElementSpec = {
  2457   2535       TK_STYLE_VERSION_2,
  2458   2536       sizeof(NullElement),
  2459   2537       TtkNullElementOptions,
  2460   2538       TtkNullElementSize,
................................................................................
  2513   2591   	    TTK_STATE_SELECTED|TTK_TREEVIEW_STATE_SORTARROW},
  2514   2592       { kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_ALTERNATE},
  2515   2593       { kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_SELECTED},
  2516   2594       { kThemeAdornmentFocus, TTK_STATE_FOCUS},
  2517   2595       { kThemeAdornmentNone, 0}
  2518   2596   };
  2519   2597   
  2520         -static void TreeAreaElementSize (
         2598  +static void TreeAreaElementSize(
  2521   2599       void *clientData, void *elementRecord, Tk_Window tkwin,
  2522   2600       int *minWidth, int *minHeight, Ttk_Padding *paddingPtr)
  2523   2601   { 
  2524   2602       /*
  2525   2603        * Padding is needed to get the heading text to align correctly, since the
  2526   2604        * widget expects the heading to be the same height as a row.
  2527   2605        */
................................................................................
  2561   2639   	.version = 0,
  2562   2640   	.state = Ttk_StateTableLookup(ThemeStateTable, state),
  2563   2641   	.kind = params->kind,
  2564   2642   	.value = Ttk_StateTableLookup(TreeHeaderValueTable, state),
  2565   2643   	.adornment = Ttk_StateTableLookup(TreeHeaderAdornmentTable, state),
  2566   2644       };
  2567   2645   
  2568         -    BEGIN_DRAWING(d)
         2646  +    BEGIN_DRAWING(d);
  2569   2647       if ([NSApp macMinorVersion] > 8) {
  2570   2648   #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080
  2571         -
  2572   2649   	/*
  2573         -	 * Compensate for the padding added in TreeHeaderElementSize, so
  2574         -	 * the larger heading will be drawn at the top of the widget.
         2650  +	 * Compensate for the padding added in TreeHeaderElementSize, so the
         2651  +	 * larger heading will be drawn at the top of the widget.
  2575   2652   	 */
  2576   2653   	
  2577   2654   	bounds.origin.y -= 4;
  2578   2655   	if (TkMacOSXInDarkMode(tkwin)) {
  2579   2656   #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300
  2580   2657   	    DrawDarkListHeader(bounds, dc.context, tkwin, state);
  2581   2658   #endif
................................................................................
  2582   2659   	} else {
  2583   2660   	    DrawListHeader(bounds, dc.context, tkwin, state);
  2584   2661   	}
  2585   2662   #endif /* MAC_OS_X_VERSION_MIN_REQUIRED > 1080 */
  2586   2663       } else {
  2587   2664   	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
  2588   2665       }
  2589         -    END_DRAWING
         2666  +    END_DRAWING;
  2590   2667   }
  2591   2668   
  2592   2669   static Ttk_ElementSpec TreeHeaderElementSpec = {
  2593   2670       TK_STYLE_VERSION_2,
  2594   2671       sizeof(NullElement),
  2595   2672       TtkNullElementOptions,
  2596   2673       TreeHeaderElementSize,
................................................................................
  2632   2709   	    .version = 0,
  2633   2710   	    .state = triangleState,
  2634   2711   	    .kind = kThemeDisclosureTriangle,
  2635   2712   	    .value = Ttk_StateTableLookup(DisclosureValueTable, state),
  2636   2713   	    .adornment = kThemeAdornmentDrawIndicatorOnly,
  2637   2714   	};
  2638   2715   
  2639         -	BEGIN_DRAWING(d)
         2716  +	BEGIN_DRAWING(d);
  2640   2717   	ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL);
  2641         -	END_DRAWING
         2718  +	END_DRAWING;
  2642   2719       }
  2643   2720   }
  2644   2721   
  2645   2722   static Ttk_ElementSpec DisclosureElementSpec = {
  2646   2723       TK_STYLE_VERSION_2,
  2647   2724       sizeof(NullElement),
  2648   2725       TtkNullElementOptions,
................................................................................
  2731   2808   
  2732   2809   TTK_LAYOUT("Horizontal.TScrollbar",
  2733   2810       TTK_GROUP("Horizontal.Scrollbar.trough", TTK_FILL_X,
  2734   2811   	TTK_NODE("Horizontal.Scrollbar.thumb", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_BOTH)
  2735   2812   	TTK_NODE("Horizontal.Scrollbar.rightarrow", TTK_PACK_RIGHT)
  2736   2813   	TTK_NODE("Horizontal.Scrollbar.leftarrow", TTK_PACK_RIGHT)))
  2737   2814   
  2738         -TTK_END_LAYOUT_TABLE
         2815  +TTK_END_LAYOUT_TABLE;
  2739   2816   
  2740   2817   /*----------------------------------------------------------------------
  2741   2818    * +++ Initialization.
  2742   2819    */
  2743   2820   
  2744         -static int AquaTheme_Init(Tcl_Interp *interp)
         2821  +static int
         2822  +AquaTheme_Init(
         2823  +    Tcl_Interp *interp)
  2745   282