diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXButton.c | 685 | ||||
-rw-r--r-- | macosx/tkMacOSXClipboard.c | 8 | ||||
-rw-r--r-- | macosx/tkMacOSXCursor.c | 18 | ||||
-rw-r--r-- | macosx/tkMacOSXDialog.c | 408 | ||||
-rw-r--r-- | macosx/tkMacOSXDraw.c | 465 | ||||
-rw-r--r-- | macosx/tkMacOSXEmbed.c | 58 | ||||
-rw-r--r-- | macosx/tkMacOSXFont.c | 193 | ||||
-rw-r--r-- | macosx/tkMacOSXImage.c | 145 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 19 | ||||
-rw-r--r-- | macosx/tkMacOSXKeyEvent.c | 567 | ||||
-rw-r--r-- | macosx/tkMacOSXMenu.c | 150 | ||||
-rw-r--r-- | macosx/tkMacOSXMenubutton.c | 415 | ||||
-rw-r--r-- | macosx/tkMacOSXMenus.c | 1 | ||||
-rw-r--r-- | macosx/tkMacOSXNotify.c | 103 | ||||
-rw-r--r-- | macosx/tkMacOSXRegion.c | 16 | ||||
-rw-r--r-- | macosx/tkMacOSXScale.c | 108 | ||||
-rw-r--r-- | macosx/tkMacOSXScrlbr.c | 395 | ||||
-rw-r--r-- | macosx/tkMacOSXSend.c | 4 | ||||
-rw-r--r-- | macosx/tkMacOSXSubwindows.c | 115 | ||||
-rw-r--r-- | macosx/tkMacOSXWindowEvent.c | 64 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 82 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 450 |
22 files changed, 2436 insertions, 2033 deletions
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index ad963e1..1c4ad25 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -1,8 +1,8 @@ /* * tkMacOSXButton.c -- * - * This file implements the Macintosh specific portion of the - * button widgets. + * This file implements the Macintosh specific portion of the button + * widgets. * * Copyright (c) 1996-1997 by Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. @@ -70,20 +70,23 @@ typedef struct { * Forward declarations for procedures defined later in this file: */ - -static void ButtonBackgroundDrawCB (const HIRect *btnbounds, MacButton *ptr, - SInt16 depth, Boolean isColorDev); -static void ButtonContentDrawCB (const HIRect *bounds, ThemeButtonKind kind, - const HIThemeButtonDrawInfo *info, MacButton *ptr, SInt16 depth, - Boolean isColorDev); -static void ButtonEventProc(ClientData clientData, XEvent *eventPtr); -static void TkMacOSXComputeButtonParams (TkButton * butPtr, ThemeButtonKind* btnkind, - HIThemeButtonDrawInfo* drawinfo); -static int TkMacOSXComputeButtonDrawParams (TkButton * butPtr, DrawParams * dpPtr); -static void TkMacOSXDrawButton (MacButton *butPtr, GC gc, Pixmap pixmap); -static void DrawButtonImageAndText(TkButton* butPtr); -static void PulseDefaultButtonProc(ClientData clientData); - +static void ButtonBackgroundDrawCB(const HIRect *btnbounds, + MacButton *ptr, SInt16 depth, Boolean isColorDev); +static void ButtonContentDrawCB(const HIRect *bounds, + ThemeButtonKind kind, + const HIThemeButtonDrawInfo *info, MacButton *ptr, + SInt16 depth, Boolean isColorDev); +static void ButtonEventProc(ClientData clientData, + XEvent *eventPtr); +static void TkMacOSXComputeButtonParams(TkButton *butPtr, + ThemeButtonKind *btnkind, + HIThemeButtonDrawInfo *drawinfo); +static int TkMacOSXComputeButtonDrawParams(TkButton *butPtr, + DrawParams * dpPtr); +static void TkMacOSXDrawButton(MacButton *butPtr, GC gc, + Pixmap pixmap); +static void DrawButtonImageAndText(TkButton *butPtr); +static void PulseDefaultButtonProc(ClientData clientData); /* * The class procedure table for the button widgets. @@ -95,15 +98,15 @@ const Tk_ClassProcs tkpButtonProcs = { }; static int bCount; - + /* *---------------------------------------------------------------------- * * TkpButtonSetDefaults -- * - * This procedure is invoked before option tables are created for - * buttons. It modifies some of the default values to match the current - * values defined for this platform. + * This procedure is invoked before option tables are created for buttons. + * It modifies some of the default values to match the current values + * defined for this platform. * * Results: * Some of the default values in *specPtr are modified. @@ -117,9 +120,8 @@ static int bCount; void TkpButtonSetDefaults() { -/*No-op.*/ + /*No-op.*/ } - /* *---------------------------------------------------------------------- @@ -141,10 +143,10 @@ TkButton * TkpCreateButton( Tk_Window tkwin) { - MacButton *macButtonPtr = (MacButton *) ckalloc(sizeof(MacButton)); + MacButton *macButtonPtr = ckalloc(sizeof(MacButton)); Tk_CreateEventHandler(tkwin, ActivateMask, - ButtonEventProc, (ClientData) macButtonPtr); + ButtonEventProc, macButtonPtr); macButtonPtr->id = bCount++; macButtonPtr->flags = FIRST_DRAW; macButtonPtr->btnkind = kThemePushButton; @@ -152,7 +154,7 @@ TkpCreateButton( bzero(&macButtonPtr->drawinfo, sizeof(macButtonPtr->drawinfo)); bzero(&macButtonPtr->lastdrawinfo, sizeof(macButtonPtr->lastdrawinfo)); - return (TkButton *)macButtonPtr; + return (TkButton *) macButtonPtr; } /* @@ -160,15 +162,15 @@ TkpCreateButton( * * TkpDisplayButton -- * - * This procedure is invoked to display a button widget. It is - * normally invoked as an idle handler. + * This procedure is invoked to display a button widget. It is normally + * invoked as an idle handler. * * Results: * None. * * Side effects: - * Commands are output to X to display the button in its - * current mode. The REDRAW_PENDING flag is cleared. + * Commands are output to X to display the button in its current mode. The + * REDRAW_PENDING flag is cleared. * *---------------------------------------------------------------------- */ @@ -177,8 +179,8 @@ void TkpDisplayButton( ClientData clientData) /* Information about widget. */ { - MacButton *macButtonPtr = (MacButton *) clientData; - TkButton *butPtr = (TkButton *) clientData; + MacButton *macButtonPtr = clientData; + TkButton *butPtr = clientData; Tk_Window tkwin = butPtr->tkwin; Pixmap pixmap; DrawParams* dpPtr = &macButtonPtr->drawParams; @@ -191,16 +193,15 @@ TkpDisplayButton( pixmap = (Pixmap) Tk_WindowId(tkwin); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); - if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr) ) { + if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr)) { macButtonPtr->useTkText = 0; } else { macButtonPtr->useTkText = 1; } - /* - * Set up clipping region. Make sure the we are using the port - * for this button, or we will set the wrong window's clip. + * Set up clipping region. Make sure the we are using the port for this + * button, or we will set the wrong window's clip. */ if (macButtonPtr->useTkText) { @@ -212,26 +213,36 @@ TkpDisplayButton( Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); } - /* Display image or bitmap or text for labels or custom controls. */ + /* + * Display image or bitmap or text for labels or custom controls. + */ + DrawButtonImageAndText(butPtr); - needhighlight = 1; + needhighlight = 1; } else { - /* Draw the native portion of the buttons. */ + /* + * Draw the native portion of the buttons. + */ + TkMacOSXDrawButton(macButtonPtr, dpPtr->gc, pixmap); - /* Draw highlight border, if needed. */ + /* + * Ask for the highlight border, if needed. + */ + if (butPtr->highlightWidth < 3) { needhighlight = 1; } } - /* Draw highlight border, if needed. */ - if (needhighlight) { - if ((butPtr->flags & GOT_FOCUS)) { - Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, + /* + * Draw highlight border. + */ + + if (needhighlight && (butPtr->flags & GOT_FOCUS)) { + Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), butPtr->highlightWidth, TK_RELIEF_SOLID); - } } } @@ -240,9 +251,9 @@ TkpDisplayButton( * * TkpComputeButtonGeometry -- * - * After changes in a button's text or bitmap, this procedure - * recomputes the button's geometry and passes this information - * along to the geometry manager for the window. + * After changes in a button's text or bitmap, this procedure recomputes + * the button's geometry and passes this information along to the geometry + * manager for the window. * * Results: * None. @@ -259,7 +270,7 @@ TkpComputeButtonGeometry( { int width = 0, height = 0, charWidth = 1, haveImage = 0, haveText = 0; int txtWidth = 0, txtHeight = 0; - MacButton *mbPtr = (MacButton*)butPtr; + MacButton *mbPtr = (MacButton *) butPtr; Tk_FontMetrics fm; char *text = Tcl_GetString(butPtr->textPtr); @@ -270,21 +281,27 @@ TkpComputeButtonGeometry( */ if (butPtr->indicatorOn) { - switch (butPtr->type) { - case TYPE_RADIO_BUTTON: - GetThemeMetric(kThemeMetricRadioButtonWidth, (SInt32 *)&butPtr->indicatorDiameter); - break; - case TYPE_CHECK_BUTTON: - GetThemeMetric(kThemeMetricCheckBoxWidth, (SInt32 *)&butPtr->indicatorDiameter); - break; - default: - break; - } - /* Allow 2px extra space next to the indicator. */ - butPtr->indicatorSpace = butPtr->indicatorDiameter + 2; + switch (butPtr->type) { + case TYPE_RADIO_BUTTON: + GetThemeMetric(kThemeMetricRadioButtonWidth, + (SInt32 *) &butPtr->indicatorDiameter); + break; + case TYPE_CHECK_BUTTON: + GetThemeMetric(kThemeMetricCheckBoxWidth, + (SInt32 *) &butPtr->indicatorDiameter); + break; + default: + break; + } + + /* + * Allow 2px extra space next to the indicator. + */ + + butPtr->indicatorSpace = butPtr->indicatorDiameter + 2; } else { - butPtr->indicatorSpace = 0; - butPtr->indicatorDiameter = 0; + butPtr->indicatorSpace = 0; + butPtr->indicatorDiameter = 0; } if (butPtr->image != NULL) { @@ -308,44 +325,43 @@ TkpComputeButtonGeometry( if (haveImage && haveText) { /* Image and Text */ switch ((enum compound) butPtr->compound) { - case COMPOUND_TOP: - case COMPOUND_BOTTOM: - - /* - * Image is above or below text. - */ - - height += txtHeight + butPtr->padY; - width = (width > txtWidth ? width : txtWidth); - break; - case COMPOUND_LEFT: - case COMPOUND_RIGHT: - - /* - * Image is left or right of text. - */ - - width += txtWidth + 2*butPtr->padX; - height = (height > txtHeight ? height : txtHeight); - break; - case COMPOUND_CENTER: - - /* - * Image and text are superimposed. - */ - - width = (width > txtWidth ? width : txtWidth); - height = (height > txtHeight ? height : txtHeight); - break; - default: - break; + case COMPOUND_TOP: + case COMPOUND_BOTTOM: + /* + * Image is above or below text. + */ + + height += txtHeight + butPtr->padY; + width = (width > txtWidth ? width : txtWidth); + break; + case COMPOUND_LEFT: + case COMPOUND_RIGHT: + /* + * Image is left or right of text. + */ + + width += txtWidth + 2*butPtr->padX; + height = (height > txtHeight ? height : txtHeight); + break; + case COMPOUND_CENTER: + /* + * Image and text are superimposed. + */ + + width = (width > txtWidth ? width : txtWidth); + height = (height > txtHeight ? height : txtHeight); + break; + default: + break; } width += butPtr->indicatorSpace; } else if (haveImage) { /* Image only */ width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace; height = butPtr->height > 0 ? butPtr->height : height; if (butPtr->type == TYPE_BUTTON) { - /* Allow room to shift the image. */ + /* + * Allow room to shift the image. + */ width += 2; height += 2; } @@ -375,17 +391,17 @@ TkpComputeButtonGeometry( width += butPtr->inset*2; height += butPtr->inset*2; if ([NSApp macMinorVersion] == 6) { - width += 12; + width += 12; } if (mbPtr->btnkind == kThemePushButton) { HIRect tmpRect; HIRect contBounds; /* - * A PushButton has a minimum size. We make sure that we - * are not underestimating the size by requesting the content - * size of a Pushbutton whose overall size is our content size - * expanded by the standard padding. + * A PushButton has a minimum size. We make sure that we are not + * underestimating the size by requesting the content size of a + * Pushbutton whose overall size is our content size expanded by the + * standard padding. */ tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY); @@ -402,51 +418,43 @@ TkpComputeButtonGeometry( Tk_GeometryRequest(butPtr->tkwin, width, height); Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset); } - + /* *---------------------------------------------------------------------- * * DrawButtonImageAndText -- * - * Draws the image and text associated with a button or label. + * Draws the image and text associated with a button or label. * * Results: - * None. + * None. * * Side effects: - * The image and text are drawn. + * The image and text are drawn. * *---------------------------------------------------------------------- */ static void DrawButtonImageAndText( - TkButton* butPtr) + TkButton *butPtr) { - MacButton *mbPtr = (MacButton*)butPtr; - Tk_Window tkwin = butPtr->tkwin; - Pixmap pixmap; - int haveImage = 0; - int haveText = 0; - int imageWidth = 0; - int imageHeight = 0; - int imageXOffset = 0; - int imageYOffset = 0; - int textXOffset = 0; - int textYOffset = 0; - int width = 0; - int height = 0; - int fullWidth = 0; - int fullHeight = 0; - int pressed = 0; - + MacButton *mbPtr = (MacButton *) butPtr; + Tk_Window tkwin = butPtr->tkwin; + Pixmap pixmap; + int haveImage = 0, haveText = 0, pressed = 0; + int imageWidth = 0, imageHeight = 0; + int imageXOffset = 0, imageYOffset = 0; + int textXOffset = 0, textYOffset = 0; + int width = 0, height = 0; + int fullWidth = 0, fullHeight = 0; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; } - DrawParams* dpPtr = &mbPtr->drawParams; - pixmap = (Pixmap)Tk_WindowId(tkwin); + DrawParams *dpPtr = &mbPtr->drawParams; + pixmap = (Pixmap) Tk_WindowId(tkwin); if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); @@ -456,74 +464,68 @@ DrawButtonImageAndText( haveImage = 1; } - imageWidth = width; + imageWidth = width; imageHeight = height; if (mbPtr->drawinfo.state == kThemeStatePressed) { - /* Offset bitmaps by a bit when the button is pressed. */ + /* + * Offset bitmaps by a bit when the button is pressed. + */ + pressed = 1; } haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); if (haveImage && haveText) { /* Image and Text */ - int x; - int y; - textXOffset = 0; - textYOffset = 0; - fullWidth = 0; - fullHeight = 0; + int x, y; switch ((enum compound) butPtr->compound) { case COMPOUND_TOP: - case COMPOUND_BOTTOM: { - /* Image is above or below text */ - if (butPtr->compound == COMPOUND_TOP) { - textYOffset = height + butPtr->padY; - } else { - imageYOffset = butPtr->textHeight + butPtr->padY; - } - fullHeight = height + butPtr->textHeight + butPtr->padY; - fullWidth = (width > butPtr->textWidth ? width : - butPtr->textWidth); - textXOffset = (fullWidth - butPtr->textWidth)/2; - imageXOffset = (fullWidth - width)/2; - break; - } + case COMPOUND_BOTTOM: + /* Image is above or below text */ + if (butPtr->compound == COMPOUND_TOP) { + textYOffset = height + butPtr->padY; + } else { + imageYOffset = butPtr->textHeight + butPtr->padY; + } + fullHeight = height + butPtr->textHeight + butPtr->padY; + fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth); + textXOffset = (fullWidth - butPtr->textWidth)/2; + imageXOffset = (fullWidth - width)/2; + break; case COMPOUND_LEFT: - case COMPOUND_RIGHT: { - /* - * Image is left or right of text - */ - - if (butPtr->compound == COMPOUND_LEFT) { - textXOffset = width + butPtr->padX; - } else { - imageXOffset = butPtr->textWidth + butPtr->padX; - } - fullWidth = butPtr->textWidth + butPtr->padX + width; - fullHeight = (height > butPtr->textHeight ? height : - butPtr->textHeight); - textYOffset = (fullHeight - butPtr->textHeight)/2; - imageYOffset = (fullHeight - height)/2; - break; - } - case COMPOUND_CENTER: { - /* - * Image and text are superimposed - */ - - fullWidth = (width > butPtr->textWidth ? width : - butPtr->textWidth); - fullHeight = (height > butPtr->textHeight ? height : - butPtr->textHeight); - textXOffset = (fullWidth - butPtr->textWidth)/2; - imageXOffset = (fullWidth - width)/2; - textYOffset = (fullHeight - butPtr->textHeight)/2; - imageYOffset = (fullHeight - height)/2; - break; - } + case COMPOUND_RIGHT: + /* + * Image is left or right of text + */ + + if (butPtr->compound == COMPOUND_LEFT) { + textXOffset = width + butPtr->padX; + } else { + imageXOffset = butPtr->textWidth + butPtr->padX; + } + fullWidth = butPtr->textWidth + butPtr->padX + width; + fullHeight = (height > butPtr->textHeight ? height : + butPtr->textHeight); + textYOffset = (fullHeight - butPtr->textHeight)/2; + imageYOffset = (fullHeight - height)/2; + break; + case COMPOUND_CENTER: + /* + * Image and text are superimposed + */ + + fullWidth = (width > butPtr->textWidth ? width : + butPtr->textWidth); + fullHeight = (height > butPtr->textHeight ? height : + butPtr->textHeight); + textXOffset = (fullWidth - butPtr->textWidth)/2; + imageXOffset = (fullWidth - width)/2; + textYOffset = (fullHeight - butPtr->textHeight)/2; + imageYOffset = (fullHeight - height)/2; + break; default: - break; + break; } TkComputeAnchor(butPtr->anchor, tkwin, @@ -547,25 +549,25 @@ DrawButtonImageAndText( imageYOffset += y; if (butPtr->image != NULL) { - if ((butPtr->selectImage != NULL) && - (butPtr->flags & SELECTED)) { - Tk_RedrawImage(butPtr->selectImage, 0, 0, - width, height, pixmap, imageXOffset, imageYOffset); - } else if ((butPtr->tristateImage != NULL) && - (butPtr->flags & TRISTATED)) { - Tk_RedrawImage(butPtr->tristateImage, 0, 0, - width, height, pixmap, imageXOffset, imageYOffset); - } else { - Tk_RedrawImage(butPtr->image, 0, 0, width, - height, pixmap, imageXOffset, imageYOffset); - } + if ((butPtr->selectImage != NULL) && + (butPtr->flags & SELECTED)) { + Tk_RedrawImage(butPtr->selectImage, 0, 0, + width, height, pixmap, imageXOffset, imageYOffset); + } else if ((butPtr->tristateImage != NULL) && + (butPtr->flags & TRISTATED)) { + Tk_RedrawImage(butPtr->tristateImage, 0, 0, + width, height, pixmap, imageXOffset, imageYOffset); + } else { + Tk_RedrawImage(butPtr->image, 0, 0, width, + height, pixmap, imageXOffset, imageYOffset); + } } else { - XSetClipOrigin(butPtr->display, dpPtr->gc, - imageXOffset, imageYOffset); - XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc, - 0, 0, (unsigned int) width, (unsigned int) height, - imageXOffset, imageYOffset, 1); - XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); + XSetClipOrigin(butPtr->display, dpPtr->gc, + imageXOffset, imageYOffset); + XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc, + 0, 0, (unsigned int) width, (unsigned int) height, + imageXOffset, imageYOffset, 1); + XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); } y += 1; /* Tweak to match native buttons. */ @@ -577,60 +579,57 @@ DrawButtonImageAndText( x + textXOffset, y + textYOffset, butPtr->underline); } else if (haveImage) { /* Image only */ - int x = 0; - int y; + int x = 0, y; + TkComputeAnchor(butPtr->anchor, tkwin, - butPtr->padX + butPtr->borderWidth, - butPtr->padY + butPtr->borderWidth, - width + butPtr->indicatorSpace, - height, &x, &y); + butPtr->padX + butPtr->borderWidth, + butPtr->padY + butPtr->borderWidth, + width + butPtr->indicatorSpace, height, &x, &y); x += butPtr->indicatorSpace; if (pressed) { - x += dpPtr->offset; - y += dpPtr->offset; + x += dpPtr->offset; + y += dpPtr->offset; } imageXOffset += x; imageYOffset += y; if (butPtr->image != NULL) { - - if ((butPtr->selectImage != NULL) && - (butPtr->flags & SELECTED)) { - Tk_RedrawImage(butPtr->selectImage, 0, 0, width, - height, pixmap, imageXOffset, imageYOffset); - } else if ((butPtr->tristateImage != NULL) && - (butPtr->flags & TRISTATED)) { - Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, - height, pixmap, imageXOffset, imageYOffset); - } else { - Tk_RedrawImage(butPtr->image, 0, 0, width, height, - pixmap, imageXOffset, imageYOffset); - } + if ((butPtr->selectImage != NULL) && + (butPtr->flags & SELECTED)) { + Tk_RedrawImage(butPtr->selectImage, 0, 0, width, + height, pixmap, imageXOffset, imageYOffset); + } else if ((butPtr->tristateImage != NULL) && + (butPtr->flags & TRISTATED)) { + Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, + height, pixmap, imageXOffset, imageYOffset); + } else { + Tk_RedrawImage(butPtr->image, 0, 0, width, height, + pixmap, imageXOffset, imageYOffset); + } } else { - XSetClipOrigin(butPtr->display, dpPtr->gc, x, y); - XCopyPlane(butPtr->display, butPtr->bitmap, - pixmap, dpPtr->gc, - 0, 0, (unsigned int) width, - (unsigned int) height, - imageXOffset, imageYOffset, 1); - XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); + XSetClipOrigin(butPtr->display, dpPtr->gc, x, y); + XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, dpPtr->gc, + 0, 0, (unsigned int) width, (unsigned int) height, + imageXOffset, imageYOffset, 1); + XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); } } else { /* Text only */ int x, y; + TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, - butPtr->textWidth + butPtr->indicatorSpace, - butPtr->textHeight, &x, &y); + butPtr->textWidth + butPtr->indicatorSpace, + butPtr->textHeight, &x, &y); x += butPtr->indicatorSpace; y += 1; /* Tweak to match native buttons */ - Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, - x, y, 0, -1); + Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, + butPtr->textLayout, x, y, 0, -1); } /* * If the button is disabled with a stipple rather than a special - * foreground color, generate the stippled effect. If the widget - * is selected and we use a different background color when selected, - * must temporarily modify the GC so the stippling is the right color. + * foreground color, generate the stippled effect. If the widget is + * selected and we use a different background color when selected, must + * temporarily modify the GC so the stippling is the right color. */ if (mbPtr->useTkText) { @@ -668,18 +667,15 @@ DrawButtonImageAndText( */ if (dpPtr->relief != TK_RELIEF_FLAT) { - int inset = butPtr->highlightWidth; - Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset, - Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset, - butPtr->borderWidth, dpPtr->relief); + int inset = butPtr->highlightWidth; + + Tk_Draw3DRectangle(tkwin, pixmap, dpPtr->border, inset, inset, + Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset, + butPtr->borderWidth, dpPtr->relief); } } - - } - - - - +} + /* *---------------------------------------------------------------------- * @@ -701,6 +697,7 @@ TkpDestroyButton( TkButton *butPtr) { MacButton *mbPtr = (MacButton *) butPtr; /* Mac button. */ + if (mbPtr->defaultPulseHandler) { Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler); } @@ -711,9 +708,8 @@ TkpDestroyButton( * * TkMacOSXDrawButton -- * - * This function draws the tk button using Mac controls - * In addition, this code may apply custom colors passed - * in the TkButton. + * This function draws the tk button using Mac controls. In addition, + * this code may apply custom colors passed in the TkButton. * * Results: * None. @@ -732,23 +728,19 @@ TkMacOSXDrawButton( Pixmap pixmap) /* The pixmap we are drawing into - needed * for the bevel button */ { - TkButton * butPtr = ( TkButton *)mbPtr; - TkWindow * winPtr; - HIRect cntrRect; + TkButton *butPtr = (TkButton *) mbPtr; + TkWindow *winPtr = (TkWindow *) butPtr->tkwin; + HIRect cntrRect; TkMacOSXDrawingContext dc; - DrawParams* dpPtr = &mbPtr->drawParams; + DrawParams *dpPtr = &mbPtr->drawParams; int useNewerHITools = 1; - winPtr = (TkWindow *)butPtr->tkwin; - TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo); - cntrRect = CGRectMake(winPtr->privatePtr->xOff, - winPtr->privatePtr->yOff, - Tk_Width(butPtr->tkwin), - Tk_Height(butPtr->tkwin)); + cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff, + Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin)); - cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset); + cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset); if (useNewerHITools == 1) { HIRect contHIRec; @@ -762,7 +754,7 @@ TkMacOSXDrawButton( hiinfo.version = 0; hiinfo.state = mbPtr->drawinfo.state; - hiinfo.kind = mbPtr->btnkind; + hiinfo.kind = mbPtr->btnkind; hiinfo.value = mbPtr->drawinfo.value; hiinfo.adornment = mbPtr->drawinfo.adornment; hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent(); @@ -772,21 +764,19 @@ TkMacOSXDrawButton( /* * To avoid buttons with white text on a white background, we always - * set the state to inactive in Dark Mode. It isn't perfect but - * it is usable. Using a ttk::button would be a better choice, - * however. + * set the state to inactive in Dark Mode. It isn't perfect but it is + * usable. Using a ttk::button would be a better choice, however. */ if (TkMacOSXInDarkMode(butPtr->tkwin)) { hiinfo.state = kThemeStateInactive; } - HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal, - &contHIRec); + HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, + kHIThemeOrientationNormal, &contHIRec); TkMacOSXRestoreDrawingContext(&dc); ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo, - (MacButton *)mbPtr, 32, true); - + (MacButton *) mbPtr, 32, true); } else { if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) { return; @@ -802,8 +792,8 @@ TkMacOSXDrawButton( * * ButtonBackgroundDrawCB -- * - * This function draws the background that - * lies under checkboxes and radiobuttons. + * This function draws the background that lies under checkboxes and + * radiobuttons. * * Results: * None. @@ -813,32 +803,33 @@ TkMacOSXDrawButton( * *-------------------------------------------------------------- */ + static void -ButtonBackgroundDrawCB ( - const HIRect * btnbounds, +ButtonBackgroundDrawCB( + const HIRect *btnbounds, MacButton *ptr, SInt16 depth, Boolean isColorDev) { - MacButton* mbPtr = (MacButton*)ptr; - TkButton* butPtr = (TkButton*)mbPtr; - Tk_Window tkwin = butPtr->tkwin; + MacButton *mbPtr = (MacButton *) ptr; + TkButton *butPtr = (TkButton *) mbPtr; + Tk_Window tkwin = butPtr->tkwin; Pixmap pixmap; int usehlborder = 0; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; } - pixmap = (Pixmap)Tk_WindowId(tkwin); + pixmap = (Pixmap) Tk_WindowId(tkwin); if (butPtr->type != TYPE_LABEL) { switch (mbPtr->btnkind) { - case kThemeSmallBevelButton: - case kThemeBevelButton: - case kThemeRoundedBevelButton: - case kThemePushButton: - usehlborder = 1; - break; + case kThemeSmallBevelButton: + case kThemeBevelButton: + case kThemeRoundedBevelButton: + case kThemePushButton: + usehlborder = 1; + break; } } if (usehlborder) { @@ -874,17 +865,18 @@ ButtonContentDrawCB ( SInt16 depth, Boolean isColorDev) { - TkButton *butPtr = (TkButton *)ptr; - Tk_Window tkwin = butPtr->tkwin; + TkButton *butPtr = (TkButton *) ptr; + Tk_Window tkwin = butPtr->tkwin; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; } /* - * Overlay Tk elements over button native region: drawing elements - * within button boundaries/native region causes unpredictable metrics. + * Overlay Tk elements over button native region: drawing elements within + * button boundaries/native region causes unpredictable metrics. */ + DrawButtonImageAndText( butPtr); } @@ -893,8 +885,8 @@ ButtonContentDrawCB ( * * ButtonEventProc -- * - * This procedure is invoked by the Tk dispatcher for various - * events on buttons. + * This procedure is invoked by the Tk dispatcher for various events on + * buttons. * * Results: * None. @@ -910,8 +902,8 @@ ButtonEventProc( ClientData clientData, /* Information about window. */ XEvent *eventPtr) /* Information about event. */ { - TkButton *buttonPtr = (TkButton *) clientData; - MacButton *mbPtr = (MacButton *) clientData; + TkButton *buttonPtr = clientData; + MacButton *mbPtr = clientData; if (eventPtr->type == ActivateNotify || eventPtr->type == DeactivateNotify) { @@ -924,7 +916,7 @@ ButtonEventProc( mbPtr->flags &= ~ACTIVE; } if ((buttonPtr->flags & REDRAW_PENDING) == 0) { - Tcl_DoWhenIdle(TkpDisplayButton, (ClientData) buttonPtr); + Tcl_DoWhenIdle(TkpDisplayButton, buttonPtr); buttonPtr->flags |= REDRAW_PENDING; } } @@ -935,9 +927,9 @@ ButtonEventProc( * * TkMacOSXComputeButtonParams -- * - * This procedure computes the various parameters used - * when creating a Carbon Appearance control. - * These are determined by the various tk button parameters + * This procedure computes the various parameters used when creating a + * Carbon Appearance control. These are determined by the various tk + * button parameters * * Results: * None. @@ -950,11 +942,11 @@ ButtonEventProc( static void TkMacOSXComputeButtonParams( - TkButton * butPtr, - ThemeButtonKind* btnkind, - HIThemeButtonDrawInfo *drawinfo) + TkButton *butPtr, + ThemeButtonKind *btnkind, + HIThemeButtonDrawInfo *drawinfo) { - MacButton *mbPtr = (MacButton *)butPtr; + MacButton *mbPtr = (MacButton *) butPtr; if (butPtr->borderWidth <= 2) { *btnkind = kThemeSmallBevelButton; @@ -968,47 +960,46 @@ TkMacOSXComputeButtonParams( if ((butPtr->image == None) && (butPtr->bitmap == None)) { switch (butPtr->type) { - case TYPE_BUTTON: - *btnkind = kThemePushButton; - break; - case TYPE_RADIO_BUTTON: - if (butPtr->borderWidth <= 1) { - *btnkind = kThemeSmallRadioButton; - } else { - *btnkind = kThemeRadioButton; - } - break; - case TYPE_CHECK_BUTTON: - if (butPtr->borderWidth <= 1) { - *btnkind = kThemeSmallCheckBox; - } else { - *btnkind = kThemeCheckBox; - } - break; + case TYPE_BUTTON: + *btnkind = kThemePushButton; + break; + case TYPE_RADIO_BUTTON: + if (butPtr->borderWidth <= 1) { + *btnkind = kThemeSmallRadioButton; + } else { + *btnkind = kThemeRadioButton; + } + break; + case TYPE_CHECK_BUTTON: + if (butPtr->borderWidth <= 1) { + *btnkind = kThemeSmallCheckBox; + } else { + *btnkind = kThemeCheckBox; + } + break; } } if (butPtr->indicatorOn) { switch (butPtr->type) { - case TYPE_RADIO_BUTTON: - if (butPtr->borderWidth <= 1) { - *btnkind = kThemeSmallRadioButton; - } else { - *btnkind = kThemeRadioButton; - } - break; - case TYPE_CHECK_BUTTON: - if (butPtr->borderWidth <= 1) { - *btnkind = kThemeSmallCheckBox; - } else { - *btnkind = kThemeCheckBox; - } - break; + case TYPE_RADIO_BUTTON: + if (butPtr->borderWidth <= 1) { + *btnkind = kThemeSmallRadioButton; + } else { + *btnkind = kThemeRadioButton; + } + break; + case TYPE_CHECK_BUTTON: + if (butPtr->borderWidth <= 1) { + *btnkind = kThemeSmallCheckBox; + } else { + *btnkind = kThemeCheckBox; + } + break; } } else { if (butPtr->type == TYPE_RADIO_BUTTON || - butPtr->type == TYPE_CHECK_BUTTON - ) { + butPtr->type == TYPE_CHECK_BUTTON) { if (*btnkind == kThemePushButton) { *btnkind = kThemeBevelButton; } @@ -1050,8 +1041,7 @@ TkMacOSXComputeButtonParams( drawinfo->adornment |= kThemeAdornmentDefault; if (!mbPtr->defaultPulseHandler) { mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler( - PULSE_TIMER_MSECS, PulseDefaultButtonProc, - (ClientData) butPtr); + PULSE_TIMER_MSECS, PulseDefaultButtonProc, butPtr); } } else if (mbPtr->defaultPulseHandler) { Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler); @@ -1068,9 +1058,8 @@ TkMacOSXComputeButtonParams( * * TkMacOSXComputeButtonDrawParams -- * - * This procedure computes the various parameters used - * when drawing a button - * These are determined by the various tk button parameters + * This procedure computes the various parameters used when drawing a + * button. These are determined by the various tk button parameters * * Results: * 1 if control will be used, 0 otherwise. @@ -1086,7 +1075,7 @@ TkMacOSXComputeButtonDrawParams( TkButton *butPtr, DrawParams *dpPtr) { - MacButton *mbPtr = (MacButton *)butPtr; + MacButton *mbPtr = (MacButton *) butPtr; dpPtr->hasImageOrBitmap = ((butPtr->image != NULL) || (butPtr->bitmap != None)); @@ -1095,12 +1084,12 @@ TkMacOSXComputeButtonDrawParams( dpPtr->offset = 0; if (dpPtr->hasImageOrBitmap) { switch (mbPtr->btnkind) { - case kThemeSmallBevelButton: - case kThemeBevelButton: - case kThemeRoundedBevelButton: - case kThemePushButton: - dpPtr->offset = 1; - break; + case kThemeSmallBevelButton: + case kThemeBevelButton: + case kThemeRoundedBevelButton: + case kThemePushButton: + dpPtr->offset = 1; + break; } } } @@ -1121,8 +1110,8 @@ TkMacOSXComputeButtonDrawParams( } /* - * Override the relief specified for the button if this is a - * checkbutton or radiobutton and there's no indicator. + * Override the relief specified for the button if this is a checkbutton or + * radiobutton and there's no indicator. */ dpPtr->relief = butPtr->relief; @@ -1134,18 +1123,14 @@ TkMacOSXComputeButtonDrawParams( } } - if (butPtr->type != TYPE_LABEL && - (butPtr->type == TYPE_BUTTON || - butPtr->indicatorOn || - dpPtr->hasImageOrBitmap)) { - + if (butPtr->type != TYPE_LABEL && (butPtr->type == TYPE_BUTTON || + butPtr->indicatorOn || dpPtr->hasImageOrBitmap)) { /* * Draw this widget as a native control. */ - + return 1; } else { - /* * Draw this widget from scratch. */ @@ -1170,15 +1155,17 @@ TkMacOSXComputeButtonDrawParams( * *-------------------------------------------------------------- */ + static void PulseDefaultButtonProc(ClientData clientData) { - MacButton *mbPtr = (MacButton *)clientData; + MacButton *mbPtr = clientData; + TkpDisplayButton(clientData); mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler( PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData); } - + /* * Local Variables: * mode: objc diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c index efd3c69..6cbcdf6 100644 --- a/macosx/tkMacOSXClipboard.c +++ b/macosx/tkMacOSXClipboard.c @@ -123,8 +123,9 @@ TkSelGetSelection( { int result = TCL_ERROR; TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; + int haveExternalClip = + ([[NSPasteboard generalPasteboard] changeCount] != changeCount); - int haveExternalClip = ([[NSPasteboard generalPasteboard] changeCount] != changeCount); if (dispPtr && (haveExternalClip || dispPtr->clipboardActive) && selection == dispPtr->clipboardAtom && (target == XA_STRING || target == dispPtr->utf8Atom)) { @@ -177,6 +178,7 @@ XSetSelectionOwner( clipboardOwner = owner ? Tk_IdToWindow(display, owner) : NULL; if (!dispPtr->clipboardActive) { NSPasteboard *pb = [NSPasteboard generalPasteboard]; + changeCount = [pb declareTypes:[NSArray array] owner:NSApp]; } } @@ -188,8 +190,8 @@ XSetSelectionOwner( * * TkMacOSXSelDeadWindow -- * - * This function is invoked just before a TkWindow is deleted. It - * performs selection-related cleanup. + * This function is invoked just before a TkWindow is deleted. It performs + * selection-related cleanup. * * Results: * None. diff --git a/macosx/tkMacOSXCursor.c b/macosx/tkMacOSXCursor.c index b6394b7..03d13dd 100644 --- a/macosx/tkMacOSXCursor.c +++ b/macosx/tkMacOSXCursor.c @@ -185,7 +185,7 @@ static const struct CursorName cursorNames[] = { * Declarations of static variables used in this file. */ -static TkMacOSXCursor * gCurrentCursor = NULL; +static TkMacOSXCursor *gCurrentCursor = NULL; /* A pointer to the current cursor. */ static int gResizeOverride = false; /* A boolean indicating whether we should use @@ -194,7 +194,7 @@ static int gTkOwnsCursor = true;/* A boolean indicating whether Tk owns the * cursor. If not (for instance, in the case * where a Tk window is embedded in another * app's window, and the cursor is out of the - * tk window, we will not attempt to adjust + * Tk window, we will not attempt to adjust * the cursor. */ /* @@ -278,6 +278,7 @@ FindCursorByName( kCGColorSpaceGenericGray); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, pix*pix/8, NULL); + if (provider) { img = CGImageCreate(pix, pix, 1, 1, pix/8, colorspace, kCGBitmapByteOrderDefault, provider, decodeWB, 0, @@ -299,14 +300,21 @@ FindCursorByName( initWithCGImage:maskedImg]; CFRelease(maskedImg); } - if (mask) { CFRelease(mask); } - if (img) { CFRelease(img); } - if (colorspace) { CFRelease(colorspace); } + if (mask) { + CFRelease(mask); + } + if (img) { + CFRelease(img); + } + if (colorspace) { + CFRelease(colorspace); + } if (bitmapImageRep) { image = [[NSImage alloc] initWithSize:NSMakeSize(pix, pix)]; [image addRepresentation:bitmapImageRep]; [bitmapImageRep release]; } + uint16_t *hotSpotData = (uint16_t*)(bitmap + 2*pix*pix/8); hotSpot.y = CFSwapInt16BigToHost(*hotSpotData++); hotSpot.x = CFSwapInt16BigToHost(*hotSpotData); diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index a7e10b4..c96d294 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -22,31 +22,39 @@ #else #define modalOK NSModalResponseOK #define modalCancel NSModalResponseCancel -#endif +#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090 #define modalOther -1 #define modalError -2 -/*Vars for filtering in "open file" and "save file" dialogs.*/ -typedef struct { - bool doFileTypes; // show the accessory view which displays the filter menu - bool preselectFilter; // a filter was selected by the typevariable - bool userHasSelectedFilter; // The user has changed the filter in the accessory view - - NSMutableArray *fileTypeNames; // array of names, e.g. "Text document" - NSMutableArray *fileTypeExtensions; // array of allowed extensions per name, e.g. "txt", "doc" - NSMutableArray *fileTypeLabels; // displayed string, e.g. "Text document (.txt, .doc)" - NSMutableArray *fileTypeAllowsAll; // boolean if the all pattern (*.*) is included - - NSMutableArray *allowedExtensions; // set of all allowed extensions - bool allowedExtensionsAllowAll; // set of all allowed extensions includes *.* +/* + * Vars for filtering in "open file" and "save file" dialogs. + */ - NSUInteger fileTypeIndex; // index of currently selected filter +typedef struct { + bool doFileTypes; /* Show the accessory view which + * displays the filter menu */ + bool preselectFilter; /* A filter was selected by the + * typevariable. */ + bool userHasSelectedFilter; /* The user has changed the filter in + * the accessory view. */ + NSMutableArray *fileTypeNames; /* Array of names, e.g. "Text + * document". */ + NSMutableArray *fileTypeExtensions; /* Array of allowed extensions per + * name, e.g. "txt", "doc". */ + NSMutableArray *fileTypeLabels; /* Displayed string, e.g. "Text + * document (.txt, .doc)". */ + NSMutableArray *fileTypeAllowsAll; /* Boolean if the all pattern (*.*) is + * included. */ + NSMutableArray *allowedExtensions; /* Set of all allowed extensions. */ + bool allowedExtensionsAllowAll; /* Set of all allowed extensions + * includes *.* */ + NSUInteger fileTypeIndex; /* Index of currently selected + * filter. */ } filepanelFilterInfo; -filepanelFilterInfo filterInfo; - -NSOpenPanel *openpanel; -NSSavePanel *savepanel; +static filepanelFilterInfo filterInfo; +static NSOpenPanel *openpanel; +static NSSavePanel *savepanel; static const char *const colorOptionStrings[] = { "-initialcolor", "-parent", "-title", NULL @@ -166,10 +174,15 @@ static const short alertNativeButtonIndexAndTypeToButtonIndex[][3] = { }; /* - * Construct a file URL from directory and filename. Either may - * be nil. If both are nil, returns nil. + * Construct a file URL from directory and filename. Either may be nil. If both + * are nil, returns nil. */ -static NSURL *getFileURL(NSString *directory, NSString *filename) { + +static NSURL * +getFileURL( + NSString *directory, + NSString *filename) +{ NSURL *url = nil; if (directory) { url = [NSURL fileURLWithPath:directory isDirectory:YES]; @@ -229,7 +242,6 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) { } } - - (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo { @@ -272,12 +284,18 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) { if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) { [openpanel setAllowsOtherFileTypes:YES]; - /* setAllowsOtherFileTypes might have no effect; it's inherited from the - * NSSavePanel, where it has the effect that it does not append an extension - * Setting the allowed file types to nil allows selecting any file */ + + /* + * setAllowsOtherFileTypes might have no effect; it's inherited from + * the NSSavePanel, where it has the effect that it does not append an + * extension. Setting the allowed file types to nil allows selecting + * any file. + */ + [openpanel setAllowedFileTypes:nil]; } else { - NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; + NSMutableArray *allowedtypes = + [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; [openpanel setAllowedFileTypes:allowedtypes]; [openpanel setAllowsOtherFileTypes:NO]; } @@ -293,7 +311,8 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) { [savepanel setAllowsOtherFileTypes:YES]; [savepanel setAllowedFileTypes:nil]; } else { - NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; + NSMutableArray *allowedtypes = + [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; [savepanel setAllowedFileTypes:allowedtypes]; [savepanel setAllowsOtherFileTypes:NO]; } @@ -384,6 +403,7 @@ Tk_ChooseColorObjCmd( [colorPanel _setUseModalAppearance:YES]; if (title) { NSString *s = [[NSString alloc] initWithUTF8String:title]; + [colorPanel setTitle:s]; [s release]; } @@ -415,9 +435,17 @@ end: return result; } -/* dissect the -filetype nested lists and store the information - * in the filterInfo structure */ -int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVariablePtr) { +/* + * Dissect the -filetype nested lists and store the information in the + * filterInfo structure. + */ + +static int +parseFileFilters( + Tcl_Interp *interp, + Tcl_Obj *fileTypesPtr, + Tcl_Obj *typeVariablePtr) +{ if (!fileTypesPtr) { filterInfo.doFileTypes = false; @@ -425,6 +453,7 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar } FileFilterList fl; + TkInitFileFilters(&fl); if (TkGetFileFilters(interp, &fl, fileTypesPtr, 0) != TCL_OK) { TkFreeFileFilters(&fl); @@ -445,11 +474,12 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar if (filterInfo.doFileTypes) { for (FileFilter *filterPtr = fl.filters; filterPtr; filterPtr = filterPtr->next) { - NSString * name = [[NSString alloc] initWithUTF8String: filterPtr -> name]; + NSString *name = [[NSString alloc] initWithUTF8String: filterPtr->name]; + [filterInfo.fileTypeNames addObject:name]; [name release]; - NSMutableArray * clauseextensions = [NSMutableArray array]; - NSMutableArray * displayextensions = [NSMutableArray array]; + NSMutableArray *clauseextensions = [NSMutableArray array]; + NSMutableArray *displayextensions = [NSMutableArray array]; bool allowsAll = NO; for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr; @@ -460,7 +490,7 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar const char *str = globPtr->pattern; while (*str && (*str == '*' || *str == '.')) { str++; - } + } if (*str) { NSString *extension = [[NSString alloc] initWithUTF8String:str]; if (![filterInfo.allowedExtensions containsObject:extension]) { @@ -472,7 +502,10 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar [extension release]; } else { - // it is the all pattern (*, .* or *.*) + /* + * It is the all pattern (*, .* or *.*) + */ + allowsAll = YES; filterInfo.allowedExtensionsAllowAll = YES; [displayextensions addObject:@"*"]; @@ -482,27 +515,39 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar [filterInfo.fileTypeExtensions addObject:clauseextensions]; [filterInfo.fileTypeAllowsAll addObject:[NSNumber numberWithBool:allowsAll]]; - NSMutableString * label = [[NSMutableString alloc] initWithString:name]; + NSMutableString *label = [[NSMutableString alloc] initWithString:name]; [label appendString:@" ("]; [label appendString:[displayextensions componentsJoinedByString:@", "]]; [label appendString:@")"]; [filterInfo.fileTypeLabels addObject:label]; [label release]; - } - /* Check if the typevariable exists and matches one of the names */ + /* + * Check if the typevariable exists and matches one of the names. + */ + filterInfo.preselectFilter = false; filterInfo.userHasSelectedFilter = false; if (typeVariablePtr) { - /* extract the variable content as a NSString */ - Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp, typeVariablePtr, NULL, TCL_GLOBAL_ONLY); + /* + * Extract the variable content as a NSString. + */ + + Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp, + typeVariablePtr, NULL, TCL_GLOBAL_ONLY); + + /* + * Check that the typevariable exists. + */ - /* check that the typevariable exists */ if (selectedFileTypeObj != NULL) { - const char *selectedFileType = Tcl_GetString(selectedFileTypeObj); - NSString *selectedFileTypeStr = [[NSString alloc] initWithUTF8String:selectedFileType]; - NSUInteger index = [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr]; + const char *selectedFileType = + Tcl_GetString(selectedFileTypeObj); + NSString *selectedFileTypeStr = + [[NSString alloc] initWithUTF8String:selectedFileType]; + NSUInteger index = + [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr]; if (index != NSNotFound) { filterInfo.fileTypeIndex = index; @@ -517,17 +562,24 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar return TCL_OK; } -bool filterCompatible(NSString *extension, int filterIndex) { - NSMutableArray *allowedExtensions = [filterInfo.fileTypeExtensions objectAtIndex: filterIndex]; +static bool +filterCompatible( + NSString *extension, + int filterIndex) +{ + NSMutableArray *allowedExtensions = + [filterInfo.fileTypeExtensions objectAtIndex: filterIndex]; + + /* + * If this contains the all pattern, accept any extension. + */ - /* If this contains the all pattern, accept any extension */ if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterIndex] boolValue]) { return true; } return [allowedExtensions containsObject: extension]; } - /* *---------------------------------------------------------------------- @@ -631,13 +683,16 @@ Tk_GetOpenFileObjCmd( if (title) { [openpanel setTitle:title]; - /* From OSX 10.11, the title string is silently ignored in the open panel. - * Prepend the title to the message in this case - * NOTE should be conditional on OSX version, but - * -mmacosx-version-min does not revert this behaviour*/ + /* + * From OSX 10.11, the title string is silently ignored in the open + * panel. Prepend the title to the message in this case. NOTE should + * be conditional on OSX version, but -mmacosx-version-min does not + * revert this behaviour + */ if (message) { - NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message]; + NSString *fullmessage = + [[NSString alloc] initWithFormat:@"%@\n%@", title, message]; [message release]; [title release]; message = fullmessage; @@ -658,15 +713,20 @@ Tk_GetOpenFileObjCmd( } if (filterInfo.doFileTypes) { - NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)]; - NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)]; + NSView *accessoryView = [[NSView alloc] + initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)]; + NSTextField *label = [[NSTextField alloc] + initWithFrame:NSMakeRect(0, 0, 60, 22)]; + [label setEditable:NO]; [label setStringValue:@"Filter:"]; [label setBordered:NO]; [label setBezeled:NO]; [label setDrawsBackground:NO]; - NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO]; + NSPopUpButton *popupButton = [[NSPopUpButton alloc] + initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO]; + [popupButton addItemsWithTitles:filterInfo.fileTypeLabels]; [popupButton setAction:@selector(selectFormat:)]; @@ -674,10 +734,16 @@ Tk_GetOpenFileObjCmd( [accessoryView addSubview:popupButton]; if (filterInfo.preselectFilter) { - /* A specific filter was selected from the typevariable. Select it and - * open the accessory view */ + /* + * A specific filter was selected from the typevariable. Select it + * and open the accessory view. + */ + [popupButton selectItemAtIndex:filterInfo.fileTypeIndex]; - /* on OSX > 10.11, the optons are not visible by default. Ergo allow all file types + + /* + * On OSX > 10.11, the options are not visible by default. Ergo + * allow all file types [openpanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]]; */ [openpanel setAllowedFileTypes:filterInfo.allowedExtensions]; @@ -693,7 +759,10 @@ Tk_GetOpenFileObjCmd( [openpanel setAccessoryView:accessoryView]; } else { - /* No filters are given. Allow picking all files */ + /* + * No filters are given. Allow picking all files. + */ + [openpanel setAllowsOtherFileTypes:YES]; } @@ -711,20 +780,24 @@ Tk_GetOpenFileObjCmd( parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window); if (haveParentOption && parent && ![parent attachedSheet]) { parentIsKey = [parent isKeyWindow]; - if (directory || filename ) { - NSURL * fileURL = getFileURL(directory, filename); + if (directory || filename) { + NSURL *fileURL = getFileURL(directory, filename); + [openpanel setDirectoryURL:fileURL]; } [openpanel beginSheetModalForWindow:parent - completionHandler:^(NSInteger returnCode) - { [NSApp tkFilePanelDidEnd:openpanel + completionHandler:^(NSInteger returnCode) { + [NSApp tkFilePanelDidEnd:openpanel returnCode:returnCode - contextInfo:callbackInfo ]; } ]; - modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:openpanel]; + contextInfo:callbackInfo ]; + }]; + modalReturnCode = cmdObj ? modalOther : + [NSApp runModalForWindow:openpanel]; } else { - if (directory || filename ) { - NSURL * fileURL = getFileURL(directory, filename); + if (directory || filename) { + NSURL *fileURL = getFileURL(directory, filename); + [openpanel setDirectoryURL:fileURL]; } @@ -737,38 +810,50 @@ Tk_GetOpenFileObjCmd( [parent makeKeyWindow]; } - if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && - filterInfo.doFileTypes) { + if ((typeVariablePtr && (modalReturnCode == NSOKButton)) + && filterInfo.doFileTypes) { /* - * The -typevariable must be set to the selected file type, if the dialog was not cancelled + * The -typevariable must be set to the selected file type, if the + * dialog was not cancelled. */ + NSUInteger selectedFilterIndex = filterInfo.fileTypeIndex; NSString *selectedFilter = NULL; + if (filterInfo.userHasSelectedFilter) { selectedFilterIndex = filterInfo.fileTypeIndex; selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex]; } else { - /* Difficult case: the user has not touched the filter settings, but we must - * return something in the typevariable. First check if the preselected type is compatible - * with the selected file, otherwise choose the first compatible type from the list, - * finally fall back to the empty string */ + /* + * Difficult case: the user has not touched the filter settings, + * but we must return something in the typevariable. First check if + * the preselected type is compatible with the selected file, + * otherwise choose the first compatible type from the list, + * finally fall back to the empty string. + */ + NSURL *selectedFile; + if (multiple) { - // Use the first file in the case of multiple selection - // Anyway it is not overly useful here + /* + * Use the first file in the case of multiple selection. + * Anyway it is not overly useful here. + */ selectedFile = [[openpanel URLs] objectAtIndex:0]; } else { selectedFile = [openpanel URL]; } NSString *extension = [selectedFile pathExtension]; + if (filterInfo.preselectFilter && - filterCompatible(extension, filterInfo.fileTypeIndex)) { + filterCompatible(extension, filterInfo.fileTypeIndex)) { selectedFilterIndex = filterInfo.fileTypeIndex; // The preselection from the typevariable selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex]; } else { // scan the list NSUInteger i; + for (i = 0; i < [filterInfo.fileTypeNames count]; i++) { if (filterCompatible(extension, i)) { selectedFilterIndex = i; @@ -780,19 +865,17 @@ Tk_GetOpenFileObjCmd( } else { selectedFilter = @""; } - } } Tcl_ObjSetVar2(interp, typeVariablePtr, NULL, - Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY); + Tcl_NewStringObj([selectedFilter UTF8String], -1), + TCL_GLOBAL_ONLY); } - end: return result; } - /* *---------------------------------------------------------------------- @@ -807,6 +890,7 @@ Tk_GetOpenFileObjCmd( * * Side effects: * See user documentation. + * *---------------------------------------------------------------------- */ @@ -828,7 +912,7 @@ Tk_GetSaveFileObjCmd( NSString *directory = nil, *filename = nil, *defaultType = nil; NSString *message = nil, *title = nil; NSWindow *parent; - savepanel = [NSSavePanel savePanel]; + savepanel = [NSSavePanel savePanel]; NSInteger modalReturnCode = modalError; BOOL parentIsKey = NO; @@ -906,13 +990,17 @@ Tk_GetSaveFileObjCmd( if (title) { [savepanel setTitle:title]; - /* From OSX 10.11, the title string is silently ignored, if the save panel is a sheet. - * Prepend the title to the message in this case - * NOTE should be conditional on OSX version, but - * -mmacosx-version-min does not revert this behaviour*/ + /* + * From OSX 10.11, the title string is silently ignored, if the save + * panel is a sheet. Prepend the title to the message in this case. + * NOTE: should be conditional on OSX version, but -mmacosx-version-min + * does not revert this behaviour. + */ + if (haveParentOption) { if (message) { - NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message]; + NSString *fullmessage = + [[NSString alloc] initWithFormat:@"%@\n%@",title,message]; [message release]; [title release]; message = fullmessage; @@ -932,15 +1020,20 @@ Tk_GetSaveFileObjCmd( } if (filterInfo.doFileTypes) { - NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)]; - NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)]; + NSView *accessoryView = [[NSView alloc] + initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)]; + NSTextField *label = [[NSTextField alloc] + initWithFrame:NSMakeRect(0, 0, 60, 22)]; + [label setEditable:NO]; [label setStringValue:NSLocalizedString(@"Format:", nil)]; [label setBordered:NO]; [label setBezeled:NO]; [label setDrawsBackground:NO]; - NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO]; + NSPopUpButton *popupButton = [[NSPopUpButton alloc] + initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO]; + [popupButton addItemsWithTitles:filterInfo.fileTypeLabels]; [popupButton selectItemAtIndex:filterInfo.fileTypeIndex]; [popupButton setAction:@selector(saveFormat:)]; @@ -953,10 +1046,14 @@ Tk_GetSaveFileObjCmd( [savepanel setAllowedFileTypes:[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]]; [savepanel setAllowsOtherFileTypes:filterInfo.allowedExtensionsAllowAll]; } else if (defaultType) { - /* If no filetypes are given, defaultextension is an alternative way - * to specify the attached extension. Just propose this extension, - * but don't display an accessory view */ + /* + * If no filetypes are given, defaultextension is an alternative way to + * specify the attached extension. Just propose this extension, but + * don't display an accessory view. + */ + NSMutableArray *AllowedFileTypes = [NSMutableArray array]; + [AllowedFileTypes addObject:defaultType]; [savepanel setAllowedFileTypes:AllowedFileTypes]; [savepanel setAllowsOtherFileTypes:YES]; @@ -978,27 +1075,39 @@ Tk_GetSaveFileObjCmd( parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window); if (haveParentOption && parent && ![parent attachedSheet]) { - parentIsKey = [parent isKeyWindow]; - if (directory) { + parentIsKey = [parent isKeyWindow]; + if (directory) { [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } - /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ + + /* + * Check for file name, otherwise set to empty string; crashes with + * uncaught exception if set to nil. + */ + if (filename) { [savepanel setNameFieldStringValue:filename]; } else { [savepanel setNameFieldStringValue:@""]; } [savepanel beginSheetModalForWindow:parent - completionHandler:^(NSInteger returnCode) - { [NSApp tkFilePanelDidEnd:savepanel + completionHandler:^(NSInteger returnCode) { + [NSApp tkFilePanelDidEnd:savepanel returnCode:returnCode - contextInfo:callbackInfo ]; } ]; - modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel]; + contextInfo:callbackInfo]; + }]; + modalReturnCode = cmdObj ? modalOther : + [NSApp runModalForWindow:savepanel]; } else { if (directory) { [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } - /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ + + /* + * Check for file name, otherwise set to empty string; crashes with + * uncaught exception if set to nil. + */ + if (filename) { [savepanel setNameFieldStringValue:filename]; } else { @@ -1013,16 +1122,20 @@ Tk_GetSaveFileObjCmd( [parent makeKeyWindow]; } - if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && filterInfo.doFileTypes) { + if (typeVariablePtr && (modalReturnCode == NSOKButton) + && filterInfo.doFileTypes) { /* - * The -typevariable must be set to the selected file type, if the dialog was not cancelled + * The -typevariable must be set to the selected file type, if the + * dialog was not cancelled. */ - NSString * selectedFilter = [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex]; + + NSString *selectedFilter = + [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex]; Tcl_ObjSetVar2(interp, typeVariablePtr, NULL, - Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY); + Tcl_NewStringObj([selectedFilter UTF8String], -1), + TCL_GLOBAL_ONLY); } - end: return result; } @@ -1130,7 +1243,12 @@ Tk_ChooseDirectoryObjCmd( callbackInfo->cmdObj = cmdObj; callbackInfo->interp = interp; callbackInfo->multiple = 0; - /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/ + + /* + * Check for directory value, set to root if not specified; otherwise + * crashes with exception because of nil string parameter. + */ + if (!directory) { directory = @"/"; } @@ -1139,10 +1257,11 @@ Tk_ChooseDirectoryObjCmd( parentIsKey = [parent isKeyWindow]; [panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; [panel beginSheetModalForWindow:parent - completionHandler:^(NSInteger returnCode) - { [NSApp tkFilePanelDidEnd:panel - returnCode:returnCode - contextInfo:callbackInfo ]; } ]; + completionHandler:^(NSInteger returnCode) { + [NSApp tkFilePanelDidEnd:panel + returnCode:returnCode + contextInfo:callbackInfo]; + }]; modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel]; } else { [panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; @@ -1201,11 +1320,12 @@ TkAboutDlg(void) */ NSString *version = @"Tcl " TCL_PATCH_LEVEL " & Tk " TCL_PATCH_LEVEL; - NSString *url = @"www.tcl-lang.org"; + NSString *url = @"www.tcl-lang.org"; NSTextView *credits = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,300,300)]; NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]]; NSDictionary *textAttributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; + [credits insertText: [[NSAttributedString alloc] initWithString:[NSString stringWithFormat: @"\n" "Tcl and Tk are distributed under a modified BSD license: " @@ -1219,11 +1339,13 @@ TkAboutDlg(void) "%1$C 1998-2000 Jim Ingham & Ray Johnson\n\n" "%1$C 1998-2000 Scriptics Inc.\n\n" "%1$C 1996-1997 Sun Microsystems Inc.", 0xA9, year] - attributes:textAttributes] - replacementRange:NSMakeRange(0,0)]; + attributes:textAttributes] + replacementRange:NSMakeRange(0,0)]; [credits setDrawsBackground:NO]; [credits setEditable:NO]; - NSAlert *about = [[NSAlert alloc] init]; + + NSAlert *about = [[NSAlert alloc] init]; + [[about window] setTitle:@"About Tcl & Tk"]; [about setMessageText: version]; [about setInformativeText:url]; @@ -1378,7 +1500,8 @@ Tk_MessageBoxObjCmd( */ if (Tcl_GetIndexFromObjStruct(interp, objv[indexDefaultOption + 1], - alertButtonStrings, sizeof(char *), "-default value", TCL_EXACT, &index) != TCL_OK) { + alertButtonStrings, sizeof(char *), "-default value", + TCL_EXACT, &index) != TCL_OK) { goto end; } @@ -1399,7 +1522,7 @@ Tk_MessageBoxObjCmd( [alert setAlertStyle:alertStyles[iconIndex]]; i = 0; while (i < 3 && alertButtonNames[typeIndex][i]) { - [alert addButtonWithTitle:(NSString*)alertButtonNames[typeIndex][i++]]; + [alert addButtonWithTitle:(NSString*) alertButtonNames[typeIndex][i++]]; } buttons = [alert buttons]; for (NSButton *b in buttons) { @@ -1428,10 +1551,11 @@ Tk_MessageBoxObjCmd( parentIsKey = [parent isKeyWindow]; #if MAC_OS_X_VERSION_MIN_REQUIRED > 1090 [alert beginSheetModalForWindow:parent - completionHandler:^(NSModalResponse returnCode) - { [NSApp tkAlertDidEnd:alert - returnCode:returnCode - contextInfo:callbackInfo ]; } ]; + completionHandler:^(NSModalResponse returnCode) { + [NSApp tkAlertDidEnd:alert + returnCode:returnCode + contextInfo:callbackInfo]; + }]; #else [alert beginSheetModalForWindow:parent modalDelegate:NSApp @@ -1471,7 +1595,10 @@ typedef struct FontchooserData { Tk_Window parent; } FontchooserData; -enum FontchooserEvent { FontchooserClosed, FontchooserSelection }; +enum FontchooserEvent { + FontchooserClosed, + FontchooserSelection +}; static void FontchooserEvent(int kind); static Tcl_Obj * FontchooserCget(FontchooserData *fcdPtr, @@ -1563,8 +1690,8 @@ enum FontchooserOption { * * FontchooserEvent -- * - * This processes events generated by user interaction with the - * font panel. + * This processes events generated by user interaction with the font + * panel. * * Results: * None. @@ -1623,9 +1750,8 @@ FontchooserEvent( * * FontchooserCget -- * - * Helper for the FontchooserConfigure command to return the - * current value of any of the options (which may be NULL in - * the structure) + * Helper for the FontchooserConfigure command to return the current value + * of any of the options (which may be NULL in the structure). * * Results: * Tcl object of option value. @@ -1688,8 +1814,8 @@ FontchooserCget( * * FontchooserConfigureCmd -- * - * Implementation of the 'tk fontchooser configure' ensemble command. - * See the user documentation for what it does. + * Implementation of the 'tk fontchooser configure' ensemble command. See + * the user documentation for what it does. * * Results: * See the user documentation. @@ -1822,7 +1948,8 @@ FontchooserConfigureCmd( [fm setSelectedAttributes:fontPanelFontAttributes isMultiple:NO]; if ([fp isVisible]) { - TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL); + TkSendVirtualEvent(fcdPtr->parent, + "TkFontchooserFontChanged", NULL); } break; case FontchooserCmd: @@ -1850,9 +1977,9 @@ FontchooserConfigureCmd( * * FontchooserShowCmd -- * - * Implements the 'tk fontchooser show' ensemble command. The - * per-interp configuration data for the dialog is held in an interp - * associated structure. + * Implements the 'tk fontchooser show' ensemble command. The per-interp + * configuration data for the dialog is held in an interp associated + * structure. * * Results: * See the user documentation. @@ -1878,8 +2005,10 @@ FontchooserShowCmd( Tk_CreateEventHandler(fcdPtr->parent, StructureNotifyMask, FontchooserParentEventHandler, fcdPtr); } + NSFontManager *fm = [NSFontManager sharedFontManager]; NSFontPanel *fp = [fm fontPanel:YES]; + if ([fp delegate] != NSApp) { [fp setDelegate:NSApp]; } @@ -1897,8 +2026,8 @@ FontchooserShowCmd( * * FontchooserHideCmd -- * - * Implementation of the 'tk fontchooser hide' ensemble. See the - * user documentation for details. + * Implementation of the 'tk fontchooser hide' ensemble. See the user + * documentation for details. * * Results: * See the user documentation. @@ -1917,6 +2046,7 @@ FontchooserHideCmd( Tcl_Obj *const objv[]) { NSFontPanel *fp = [[NSFontManager sharedFontManager] fontPanel:NO]; + if ([fp isVisible]) { [fp orderOut:NSApp]; } @@ -1997,8 +2127,8 @@ DeleteFontchooserData( * * TkInitFontchooser -- * - * Associate the font chooser configuration data with the Tcl - * interpreter. There is one font chooser per interp. + * Associate the font chooser configuration data with the Tcl interpreter. + * There is one font chooser per interp. * * Results: * None. diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index faad137..dceb3a6 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -1,9 +1,8 @@ /* * tkMacOSXDraw.c -- * - * This file contains functions that perform drawing to - * Xlib windows. Most of the functions simple emulate - * Xlib functions. + * This file contains functions that perform drawing to Xlib windows. Most + * of the functions simple emulate Xlib functions. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001-2009, Apple Inc. @@ -31,7 +30,7 @@ #endif */ -#define radians(d) ((d) * (M_PI/180.0)) +#define radians(d) ((d) * (M_PI/180.0)) /* * Non-antialiased CG drawing looks better and more like X11 drawing when using @@ -40,7 +39,7 @@ #define NON_AA_CG_OFFSET .999 static int cgAntiAliasLimit = 0; -#define notAA(w) ((w) < cgAntiAliasLimit) +#define notAA(w) ((w) < cgAntiAliasLimit) static int useThemedToplevel = 0; static int useThemedFrame = 0; @@ -119,24 +118,24 @@ TkMacOSXInitCGDrawing( * replacement is [NSView cacheDisplayInRect: toBitmapImageRep:] and that * is what is being used here. However, that method only works when the * view has a valid CGContext, and a view is only guaranteed to have a - * valid context during a call to [NSView drawRect]. To further - * complicate matters, cacheDisplayInRect calls [NSView drawRect]. - * Essentially it is asking the view to draw a subrectangle of itself into - * a special graphics context which is linked to the BitmapImageRep. But - * our implementation of [NSView drawRect] does not allow recursive calls. - * If called recursively it returns immediately without doing any drawing. + * valid context during a call to [NSView drawRect]. To further complicate + * matters, cacheDisplayInRect calls [NSView drawRect]. Essentially it is + * asking the view to draw a subrectangle of itself into a special + * graphics context which is linked to the BitmapImageRep. But our + * implementation of [NSView drawRect] does not allow recursive calls. If + * called recursively it returns immediately without doing any drawing. * So the bottom line is that this function either returns a NULL pointer - * or a black image. To make it useful would require a significant amount - * of rewriting of the drawRect method. Perhaps the next release of OSX + * or a black image. To make it useful would require a significant amount + * of rewriting of the drawRect method. Perhaps the next release of OSX * will include some more helpful ways of doing this. * * Results: - * Returns an NSBitmapRep representing the image of the given - * rectangle of the given drawable. This object is retained. - * The caller is responsible for releasing it. + * Returns an NSBitmapRep representing the image of the given rectangle of + * the given drawable. This object is retained. The caller is responsible + * for releasing it. * - * NOTE: The x,y coordinates should be relative to a coordinate system with - * origin at the top left, as used by XImage and CGImage, not bottom + * NOTE: The x,y coordinates should be relative to a coordinate system + * with origin at the top left, as used by XImage and CGImage, not bottom * left as used by NSView. * * Side effects: @@ -144,46 +143,46 @@ TkMacOSXInitCGDrawing( * *---------------------------------------------------------------------- */ -NSBitmapImageRep* + +NSBitmapImageRep * TkMacOSXBitmapRepFromDrawableRect( - Drawable drawable, - int x, - int y, - unsigned int width, - unsigned int height) + Drawable drawable, + int x, + int y, + unsigned int width, + unsigned int height) { MacDrawable *mac_drawable = (MacDrawable *) drawable; CGContextRef cg_context = NULL; - CGImageRef cg_image=NULL, sub_cg_image = NULL; + CGImageRef cg_image = NULL, sub_cg_image = NULL; NSBitmapImageRep *bitmap_rep = NULL; - NSView *view=NULL; - if ( mac_drawable->flags & TK_IS_PIXMAP ) { - + NSView *view = NULL; + if (mac_drawable->flags & TK_IS_PIXMAP) { /* * This MacDrawable is a bitmap, so its view is NULL. */ - cg_context = TkMacOSXGetCGContextForDrawable(drawable); CGRect image_rect = CGRectMake(x, y, width, height); - cg_image = CGBitmapContextCreateImage( (CGContextRef) cg_context); + + cg_context = TkMacOSXGetCGContextForDrawable(drawable); + cg_image = CGBitmapContextCreateImage((CGContextRef) cg_context); sub_cg_image = CGImageCreateWithImageInRect(cg_image, image_rect); - if ( sub_cg_image ) { + if (sub_cg_image) { bitmap_rep = [NSBitmapImageRep alloc]; [bitmap_rep initWithCGImage:sub_cg_image]; } - if ( cg_image ) { + if (cg_image) { CGImageRelease(cg_image); } - } else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) { - + } else if ((view = TkMacOSXDrawableView(mac_drawable)) != NULL) { /* * Convert Tk top-left to NSView bottom-left coordinates. */ int view_height = [view bounds].size.height; NSRect view_rect = NSMakeRect(x + mac_drawable->xOff, - view_height - height - y - mac_drawable->yOff, - width, height); + view_height - height - y - mac_drawable->yOff, + width, height); /* * Attempt to copy from the view to a bitmapImageRep. If the view does @@ -218,8 +217,7 @@ TkMacOSXBitmapRepFromDrawableRect( * None. * * Side effects: - * Data is moved from a window or bitmap to a second window or - * bitmap. + * Data is moved from a window or bitmap to a second window or bitmap. * *---------------------------------------------------------------------- */ @@ -229,10 +227,10 @@ XCopyArea( Display *display, /* Display. */ Drawable src, /* Source drawable. */ Drawable dst, /* Destination drawable. */ - GC gc, /* GC to use. */ + GC gc, /* GC to use. */ int src_x, /* X & Y, width & height */ int src_y, /* define the source rectangle */ - unsigned int width, /* that will be copied. */ + unsigned int width, /* that will be copied. */ unsigned int height, int dest_x, /* Dest X & Y on dest rect. */ int dest_y) @@ -249,37 +247,36 @@ XCopyArea( } if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) { - return; TkMacOSXDbgMsg("Failed to setup drawing context."); + return; } - if ( dc.context ) { - if (srcDraw->flags & TK_IS_PIXMAP) { - img = TkMacOSXCreateCGImageWithDrawable(src); - }else if (TkMacOSXDrawableWindow(src)) { - bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src, - src_x, src_y, width, height); - if ( bitmap_rep ) { - img = [bitmap_rep CGImage]; - } - } else { - TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap."); - } + if (!dc.context) { + TkMacOSXDbgMsg("Invalid destination drawable - no context."); + return; + } - if (img) { - bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height); - srcRect = CGRectMake(src_x, src_y, width, height); - dstRect = CGRectMake(dest_x, dest_y, width, height); - TkMacOSXDrawCGImage(dst, gc, dc.context, img, - gc->foreground, gc->background, bounds, srcRect, dstRect); - CFRelease(img); - } else { - TkMacOSXDbgMsg("Failed to construct CGImage."); + if (srcDraw->flags & TK_IS_PIXMAP) { + img = TkMacOSXCreateCGImageWithDrawable(src); + } else if (TkMacOSXDrawableWindow(src)) { + bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src, + src_x, src_y, width, height); + if (bitmap_rep) { + img = [bitmap_rep CGImage]; } + } else { + TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap."); + } + if (img) { + bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height); + srcRect = CGRectMake(src_x, src_y, width, height); + dstRect = CGRectMake(dest_x, dest_y, width, height); + TkMacOSXDrawCGImage(dst, gc, dc.context, img, + gc->foreground, gc->background, bounds, srcRect, dstRect); + CFRelease(img); } else { - TkMacOSXDbgMsg("Invalid destination drawable - no context."); - return; + TkMacOSXDbgMsg("Failed to construct CGImage."); } TkMacOSXRestoreDrawingContext(&dc); @@ -290,10 +287,9 @@ XCopyArea( * * XCopyPlane -- * - * Copies a bitmap from a source drawable to a destination - * drawable. The plane argument specifies which bit plane of - * the source contains the bitmap. Note that this implementation - * ignores the gc->function. + * Copies a bitmap from a source drawable to a destination drawable. The + * plane argument specifies which bit plane of the source contains the + * bitmap. Note that this implementation ignores the gc->function. * * Results: * None. @@ -334,29 +330,50 @@ XCopyPlane( if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) { return; } + CGContextRef context = dc.context; + if (context) { CGImageRef img = TkMacOSXCreateCGImageWithDrawable(src); + if (img) { TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask; unsigned long imageBackground = gc->background; - if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP){ + + if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP) { srcRect = CGRectMake(src_x, src_y, width, height); - CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(clipPtr->value.pixmap); - CGImageRef submask = CGImageCreateWithImageInRect(img, srcRect); + CGImageRef mask = TkMacOSXCreateCGImageWithDrawable( + clipPtr->value.pixmap); + CGImageRef submask = CGImageCreateWithImageInRect( + img, srcRect); CGRect rect = CGRectMake(dest_x, dest_y, width, height); + rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff); CGContextSaveGState(context); - /* Move the origin of the destination to top left. */ - CGContextTranslateCTM(context, 0, rect.origin.y + CGRectGetMaxY(rect)); + + /* + * Move the origin of the destination to top left. + */ + + CGContextTranslateCTM(context, + 0, rect.origin.y + CGRectGetMaxY(rect)); CGContextScaleCTM(context, 1, -1); - /* Fill with the background color, clipping to the mask. */ + + /* + * Fill with the background color, clipping to the mask. + */ + CGContextClipToMask(context, rect, submask); TkMacOSXSetColorInContext(gc, gc->background, dc.context); CGContextFillRect(context, rect); - /* Fill with the foreground color, clipping to the - intersection of img and mask. */ - CGImageRef subimage = CGImageCreateWithImageInRect(img, srcRect); + + /* + * Fill with the foreground color, clipping to the + * intersection of img and mask. + */ + + CGImageRef subimage = CGImageCreateWithImageInRect( + img, srcRect); CGContextClipToMask(context, rect, subimage); TkMacOSXSetColorInContext(gc, gc->foreground, context); CGContextFillRect(context, rect); @@ -366,22 +383,31 @@ XCopyPlane( CGImageRelease(submask); CGImageRelease(subimage); } else { - bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height); + bounds = CGRectMake(0, 0, + srcDraw->size.width, srcDraw->size.height); srcRect = CGRectMake(src_x, src_y, width, height); dstRect = CGRectMake(dest_x, dest_y, width, height); - TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground, - imageBackground, bounds, srcRect, dstRect); + TkMacOSXDrawCGImage(dst, gc, dc.context, img, + gc->foreground, imageBackground, bounds, + srcRect, dstRect); CGImageRelease(img); } - } else { /* no image */ + } else { + /* no image */ TkMacOSXDbgMsg("Invalid source drawable"); } } else { - TkMacOSXDbgMsg("Invalid destination drawable - could not get a bitmap context."); + TkMacOSXDbgMsg("Invalid destination drawable - " + "could not get a bitmap context."); } TkMacOSXRestoreDrawingContext(&dc); - } else { /* source drawable is a window, not a Pixmap */ - XCopyArea(display, src, dst, gc, src_x, src_y, width, height, dest_x, dest_y); + } else { + /* + * Source drawable is a Window, not a Pixmap. + */ + + XCopyArea(display, src, dst, gc, src_x, src_y, width, height, + dest_x, dest_y); } } @@ -430,7 +456,7 @@ TkMacOSXCreateCGImageWithDrawable( *---------------------------------------------------------------------- */ -static NSImage* +static NSImage * CreateNSImageWithPixmap( Pixmap pixmap, int width, @@ -466,7 +492,7 @@ CreateNSImageWithPixmap( *---------------------------------------------------------------------- */ -NSImage* +NSImage * TkMacOSXGetNSImageWithTkImage( Display *display, Tk_Image image, @@ -499,7 +525,7 @@ TkMacOSXGetNSImageWithTkImage( *---------------------------------------------------------------------- */ -NSImage* +NSImage * TkMacOSXGetNSImageWithBitmap( Display *display, Pixmap bitmap, @@ -550,23 +576,24 @@ TkMacOSXGetCGContextForDrawable( CGColorSpaceRef colorspace = NULL; CGBitmapInfo bitmapInfo = #ifdef __LITTLE_ENDIAN__ - kCGBitmapByteOrder32Host; + kCGBitmapByteOrder32Host; #else - kCGBitmapByteOrderDefault; + kCGBitmapByteOrderDefault; #endif char *data; - CGRect bounds = CGRectMake(0, 0, macDraw->size.width, macDraw->size.height); + CGRect bounds = CGRectMake(0, 0, + macDraw->size.width, macDraw->size.height); if (macDraw->flags & TK_IS_BW_PIXMAP) { bitsPerPixel = 8; - bitmapInfo = (CGBitmapInfo)kCGImageAlphaOnly; + bitmapInfo = (CGBitmapInfo) kCGImageAlphaOnly; } else { colorspace = CGColorSpaceCreateDeviceRGB(); bitsPerPixel = 32; bitmapInfo |= kCGImageAlphaPremultipliedFirst; } - bytesPerRow = ((size_t) macDraw->size.width * bitsPerPixel + 127) >> 3 - & ~15; + bytesPerRow = ((size_t) + macDraw->size.width * bitsPerPixel + 127) >> 3 & ~15; len = macDraw->size.height * bytesPerRow; data = ckalloc(len); bzero(data, len); @@ -630,8 +657,8 @@ TkMacOSXDrawCGImage( dstBounds = CGRectOffset(dstBounds, macDraw->xOff, macDraw->yOff); if (CGImageIsMask(image)) { if (macDraw->flags & TK_IS_BW_PIXMAP) { - - /* Set fill color to black; background comes from the context, + /* + * Set fill color to black; background comes from the context, * or is transparent. */ @@ -655,11 +682,13 @@ TkMacOSXDrawCGImage( CGContextSetRGBFillColor(context, 0, 1, 0, 0.1); CGContextFillRect(context, dstBounds); CGContextStrokeRect(context, dstBounds); + CGPoint p[4] = {dstBounds.origin, CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMaxY(dstBounds)), CGPointMake(CGRectGetMinX(dstBounds), CGRectGetMaxY(dstBounds)), CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMinY(dstBounds)) }; + CGContextStrokeLineSegments(context, p, 4); CGContextRestoreGState(context); TkMacOSXDbgMsg("Drawing CGImage at (x=%f, y=%f), (w=%f, h=%f)", @@ -736,12 +765,13 @@ XDrawLines( CGContextAddLineToPoint(dc.context, prevx, prevy); } } + /* - * In the case of closed polylines, the first and last points - * are the same. We want miter or bevel join be rendered also - * at this point, this needs telling CoreGraphics that the - * path is closed. + * In the case of closed polylines, the first and last points are the + * same. We want miter or bevel join be rendered also at this point, + * this needs telling CoreGraphics that the path is closed. */ + if ((points[0].x == points[npoints-1].x) && (points[0].y == points[npoints-1].y)) { CGContextClosePath(dc.context); @@ -820,10 +850,10 @@ XDrawSegments( void XFillPolygon( - Display* display, /* Display. */ + Display *display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ - XPoint* points, /* Array of points. */ + XPoint *points, /* Array of points. */ int npoints, /* Number of points. */ int shape, /* Shape to draw. */ int mode) /* Drawing mode. */ @@ -902,8 +932,7 @@ XDrawRectangle( double o = (lw % 2) ? .5 : 0; rect = CGRectMake( - macWin->xOff + x + o, - macWin->yOff + y + o, + macWin->xOff + x + o, macWin->yOff + y + o, width, height); CGContextStrokeRect(dc.context, rect); } @@ -916,17 +945,15 @@ XDrawRectangle( * * XDrawRectangles -- * - * Draws the outlines of the specified rectangles as if a - * five-point PolyLine protocol request were specified for each - * rectangle: + * Draws the outlines of the specified rectangles as if a five-point + * PolyLine protocol request were specified for each rectangle: * * [x,y] [x+width,y] [x+width,y+height] [x,y+height] [x,y] * - * For the specified rectangles, these functions do not draw a - * pixel more than once. XDrawRectangles draws the rectangles in - * the order listed in the array. If rectangles intersect, the - * intersecting pixels are drawn multiple times. Draws a - * rectangle. + * For the specified rectangles, these functions do not draw a pixel more + * than once. XDrawRectangles draws the rectangles in the order listed in + * the array. If rectangles intersect, the intersecting pixels are drawn + * multiple times. Draws a rectangle. * * Results: * None. @@ -991,7 +1018,7 @@ XDrawRectangles( int XFillRectangles( - Display* display, /* Display. */ + Display *display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ XRectangle *rectangles, /* Rectangle array. */ @@ -1042,7 +1069,7 @@ XFillRectangles( void XDrawArc( - Display* display, /* Display. */ + Display *display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ int x, int y, /* Upper left of bounding rect. */ @@ -1099,14 +1126,13 @@ XDrawArc( * * XDrawArcs -- * - * Draws multiple circular or elliptical arcs. Each arc is - * specified by a rectangle and two angles. The center of the - * circle or ellipse is the center of the rect- angle, and the - * major and minor axes are specified by the width and height. - * Positive angles indicate counterclock- wise motion, and - * negative angles indicate clockwise motion. If the magnitude - * of angle2 is greater than 360 degrees, XDrawArcs truncates it - * to 360 degrees. + * Draws multiple circular or elliptical arcs. Each arc is specified by a + * rectangle and two angles. The center of the circle or ellipse is the + * center of the rect- angle, and the major and minor axes are specified + * by the width and height. Positive angles indicate counterclock- wise + * motion, and negative angles indicate clockwise motion. If the magnitude + * of angle2 is greater than 360 degrees, XDrawArcs truncates it to 360 + * degrees. * * Results: * None. @@ -1125,7 +1151,6 @@ XDrawArcs( XArc *arcArr, int nArcs) { - MacDrawable *macWin = (MacDrawable *) d; TkMacOSXDrawingContext dc; XArc *arcPtr; @@ -1195,7 +1220,7 @@ XDrawArcs( void XFillArc( - Display* display, /* Display. */ + Display *display, /* Display. */ Drawable d, /* Draw on this. */ GC gc, /* Use this GC. */ int x, int y, /* Upper left of bounding rect. */ @@ -1360,13 +1385,12 @@ XMaxRequestSize( * * TkScrollWindow -- * - * Scroll a rectangle of the specified window and accumulate - * a damage region. + * Scroll a rectangle of the specified window and accumulate a damage + * region. * * Results: - * Returns 0 if the scroll generated no additional damage. - * Otherwise, sets the region that needs to be repainted after - * scrolling and returns 1. + * Returns 0 if the scroll generated no additional damage. Otherwise, sets + * the region that needs to be repainted after scrolling and returns 1. * * Side effects: * Scrolls the bits in the window. @@ -1385,47 +1409,63 @@ TkScrollWindow( { Drawable drawable = Tk_WindowId(tkwin); MacDrawable *macDraw = (MacDrawable *) drawable; - TKContentView *view = (TKContentView *)TkMacOSXDrawableView(macDraw); + TKContentView *view = (TKContentView *) TkMacOSXDrawableView(macDraw); CGRect srcRect, dstRect; HIShapeRef dmgRgn = NULL, extraRgn = NULL; NSRect bounds, visRect, scrollSrc, scrollDst; int result = 0; - if ( view ) { - /* Get the scroll area in NSView coordinates (origin at bottom left). */ + if (view) { + /* + * Get the scroll area in NSView coordinates (origin at bottom left). + */ + bounds = [view bounds]; scrollSrc = NSMakeRect(macDraw->xOff + x, - bounds.size.height - height - (macDraw->yOff + y), - width, height); + bounds.size.height - height - (macDraw->yOff + y), + width, height); scrollDst = NSOffsetRect(scrollSrc, dx, -dy); - /* Limit scrolling to the window content area. */ + /* + * Limit scrolling to the window content area. + */ + visRect = [view visibleRect]; scrollSrc = NSIntersectionRect(scrollSrc, visRect); scrollDst = NSIntersectionRect(scrollDst, visRect); - if ( !NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst) ) { + if (!NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst)) { /* * Mark the difference between source and destination as damaged. - * This region is described in NSView coordinates (y=0 at the bottom) - * and converted to Tk coordinates later. + * This region is described in NSView coordinates (y=0 at the + * bottom) and converted to Tk coordinates later. */ srcRect = CGRectMake(x, y, width, height); dstRect = CGRectOffset(srcRect, dx, dy); - /* Compute the damage. */ + /* + * Compute the damage. + */ + dmgRgn = HIShapeCreateMutableWithRect(&srcRect); extraRgn = HIShapeCreateWithRect(&dstRect); - ChkErr(HIShapeDifference, dmgRgn, extraRgn, (HIMutableShapeRef) dmgRgn); + ChkErr(HIShapeDifference, dmgRgn, extraRgn, + (HIMutableShapeRef) dmgRgn); result = HIShapeIsEmpty(dmgRgn) ? 0 : 1; - /* Convert to Tk coordinates, offset by the window origin. */ + /* + * Convert to Tk coordinates, offset by the window origin. + */ + TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn); if (extraRgn) { CFRelease(extraRgn); } - /* Scroll the rectangle. */ + /* + * Scroll the rectangle. + */ + [view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)]; } } else { @@ -1472,8 +1512,8 @@ TkMacOSXSetUpGraphicsPort( * Set up a drawing context for the given drawable and GC. * * Results: - * Boolean indicating whether it is ok to draw; if false, drawing - * context was not setup, so do not attempt to draw and do not call + * Boolean indicating whether it is ok to draw; if false, drawing context + * was not setup, so do not attempt to draw and do not call * TkMacOSXRestoreDrawingContext(). * * Side effects: @@ -1486,18 +1526,18 @@ Bool TkMacOSXSetupDrawingContext( Drawable d, GC gc, - int useCG, /* advisory only ! */ + int useCG, /* advisory only ! */ TkMacOSXDrawingContext *dcPtr) { - MacDrawable *macDraw = ((MacDrawable*)d); + MacDrawable *macDraw = (MacDrawable *) d; Bool canDraw = true; NSWindow *win = NULL; TkMacOSXDrawingContext dc = {}; CGRect clipBounds; /* - * If the drawable is not a pixmap and it has an associated - * NSWindow then we know we are drawing to a window. + * If the drawable is not a pixmap and it has an associated NSWindow then + * we know we are drawing to a window. */ if (!(macDraw->flags & TK_IS_PIXMAP)) { @@ -1516,9 +1556,8 @@ TkMacOSXSetupDrawingContext( } /* - * If we already have a CGContext, use it. Otherwise, if we - * are drawing to a window then we can get one from the - * window. + * If we already have a CGContext, use it. Otherwise, if we are drawing to + * a window then we can get one from the window. */ dc.context = TkMacOSXGetCGContextForDrawable(d); @@ -1526,35 +1565,34 @@ TkMacOSXSetupDrawingContext( dc.portBounds = clipBounds = CGContextGetClipBoundingBox(dc.context); } else if (win) { NSView *view = TkMacOSXDrawableView(macDraw); - if (view) { - - /* - * We can only draw into the view when the current CGContext is - * valid and belongs to the view. Validity can only be guaranteed - * inside of a view's drawRect or setFrame methods. The isDrawing - * attribute tells us whether we are being called from one of those - * methods. - * - * If the CGContext is not valid, or belongs to a different View, - * then we mark our view as needing display and return failure. - * It should get drawn in a later call to drawRect. - */ - if (view != [NSView focusView]) { - [view setNeedsDisplay:YES]; - canDraw = false; - goto end; - } - dc.view = view; - dc.context = GET_CGCONTEXT; - dc.portBounds = NSRectToCGRect([view bounds]); - if (dc.clipRgn) { - clipBounds = CGContextGetClipBoundingBox(dc.context); - } - } else { + if (!view) { Tcl_Panic("TkMacOSXSetupDrawingContext(): " "no NSView to draw into !"); } + + /* + * We can only draw into the view when the current CGContext is valid + * and belongs to the view. Validity can only be guaranteed inside of + * a view's drawRect or setFrame methods. The isDrawing attribute + * tells us whether we are being called from one of those methods. + * + * If the CGContext is not valid, or belongs to a different View, then + * we mark our view as needing display and return failure. It should + * get drawn in a later call to drawRect. + */ + + if (view != [NSView focusView]) { + [view setNeedsDisplay:YES]; + canDraw = false; + goto end; + } + dc.view = view; + dc.context = GET_CGCONTEXT; + dc.portBounds = NSRectToCGRect([view bounds]); + if (dc.clipRgn) { + clipBounds = CGContextGetClipBoundingBox(dc.context); + } } else { Tcl_Panic("TkMacOSXSetupDrawingContext(): " "no context to draw into !"); @@ -1565,8 +1603,13 @@ TkMacOSXSetupDrawingContext( */ if (dc.context) { - CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0, - .ty = dc.portBounds.size.height}; + CGAffineTransform t = { + .a = 1, .b = 0, + .c = 0, .d = -1, + .tx = 0, + .ty = dc.portBounds.size.height + }; + dc.portBounds.origin.x += macDraw->xOff; dc.portBounds.origin.y += macDraw->yOff; CGContextSaveGState(dc.context); @@ -1581,6 +1624,7 @@ TkMacOSXSetupDrawingContext( CGContextRestoreGState(dc.context); #endif /* TK_MAC_DEBUG_DRAWING */ CGRect r; + if (!HIShapeIsRectangular(dc.clipRgn) || !CGRectContainsRect( *HIShapeGetBounds(dc.clipRgn, &r), CGRectApplyAffineTransform(clipBounds, t))) { @@ -1608,21 +1652,28 @@ TkMacOSXSetupDrawingContext( CGContextSetPatternPhase(dc.context, CGSizeMake( dc.portBounds.size.width, dc.portBounds.size.height)); } - if(gc->function != GXcopy) { + if (gc->function != GXcopy) { TkMacOSXDbgMsg("Logical functions other than GXcopy are " "not supported for CG drawing!"); } - /* When should we antialias? */ + + /* + * When should we antialias? + */ + shouldAntialias = !notAA(gc->line_width); if (!shouldAntialias) { - /* Make non-antialiased CG drawing look more like X11 */ + /* + * Make non-antialiased CG drawing look more like X11. + */ + w -= (gc->line_width ? NON_AA_CG_OFFSET : 0); } CGContextSetShouldAntialias(dc.context, shouldAntialias); CGContextSetLineWidth(dc.context, w); if (gc->line_style != LineSolid) { int num = 0; - char *p = &(gc->dashes); + char *p = &gc->dashes; CGFloat dashOffset = gc->dash_offset; CGFloat lengths[10]; @@ -1632,13 +1683,13 @@ TkMacOSXSetupDrawingContext( } CGContextSetLineDash(dc.context, dashOffset, lengths, num); } - if ((unsigned)gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) { + if ((unsigned) gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) { CGContextSetLineCap(dc.context, - cgCap[(unsigned)gc->cap_style]); + cgCap[(unsigned) gc->cap_style]); } if ((unsigned)gc->join_style < sizeof(cgJoin)/sizeof(CGLineJoin)) { CGContextSetLineJoin(dc.context, - cgJoin[(unsigned)gc->join_style]); + cgJoin[(unsigned) gc->join_style]); } } } @@ -1647,8 +1698,11 @@ end: #ifdef TK_MAC_DEBUG_DRAWING if (!canDraw && win != NULL) { TkWindow *winPtr = TkMacOSXGetTkWindow(win); - if (winPtr) fprintf(stderr, "Cannot draw in %s - postponing.\n", - Tk_PathName(winPtr)); + + if (winPtr) { + fprintf(stderr, "Cannot draw in %s - postponing.\n", + Tk_PathName(winPtr)); + } } #endif if (!canDraw && dc.clipRgn) { @@ -1719,7 +1773,9 @@ TkMacOSXGetClipRgn( TkMacOSXUpdateClipRgn(macDraw->winPtr); #ifdef TK_MAC_DEBUG_DRAWING TkMacOSXDbgMsg("%s", macDraw->winPtr->pathName); + NSView *view = TkMacOSXDrawableView(macDraw); + CGContextSaveGState(context); CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, [view bounds].size.height)); @@ -1743,8 +1799,8 @@ TkMacOSXGetClipRgn( * * TkMacOSXSetUpClippingRgn -- * - * Set up the clipping region so that drawing only occurs on the - * specified X subwindow. + * Set up the clipping region so that drawing only occurs on the specified + * X subwindow. * * Results: * None. @@ -1766,8 +1822,8 @@ TkMacOSXSetUpClippingRgn( * * TkpClipDrawableToRect -- * - * Clip all drawing into the drawable d to the given rectangle. - * If width or height are negative, reset to no clipping. + * Clip all drawing into the drawable d to the given rectangle. If width + * or height are negative, reset to no clipping. * * Results: * None. @@ -1832,8 +1888,8 @@ ClipToGC( HIShapeRef *clipRgnPtr) /* must point to initialized variable */ { if (gc && gc->clip_mask && - ((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) { - TkRegion gcClip = ((TkpClipMask*)gc->clip_mask)->value.region; + ((TkpClipMask *) gc->clip_mask)->type == TKP_CLIP_REGION) { + TkRegion gcClip = ((TkpClipMask *) gc->clip_mask)->value.region; int xOffset = ((MacDrawable *) d)->xOff + gc->clip_x_origin; int yOffset = ((MacDrawable *) d)->yOff + gc->clip_y_origin; HIShapeRef clipRgn = *clipRgnPtr, gcClipRgn; @@ -1856,10 +1912,9 @@ ClipToGC( * * TkMacOSXMakeStippleMap -- * - * Given a drawable and a stipple pattern this function draws the - * pattern repeatedly over the drawable. The drawable can then - * be used as a mask for bit-bliting a stipple pattern over an - * object. + * Given a drawable and a stipple pattern this function draws the pattern + * repeatedly over the drawable. The drawable can then be used as a mask + * for bit-bliting a stipple pattern over an object. * * Results: * A BitMap data structure. @@ -1883,12 +1938,12 @@ TkMacOSXMakeStippleMap( * * TkpDrawHighlightBorder -- * - * This procedure draws a rectangular ring around the outside of - * a widget to indicate that it has received the input focus. + * This procedure draws a rectangular ring around the outside of a widget + * to indicate that it has received the input focus. * - * On the Macintosh, this puts a 1 pixel border in the bgGC color - * between the widget and the focus ring, except in the case where - * highlightWidth is 1, in which case the border is left out. + * On the Macintosh, this puts a 1 pixel border in the bgGC color between + * the widget and the focus ring, except in the case where highlightWidth + * is 1, in which case the border is left out. * * For proper Mac L&F, use highlightWidth of 3. * @@ -1896,8 +1951,8 @@ TkMacOSXMakeStippleMap( * None. * * Side effects: - * A rectangle "width" pixels wide is drawn in "drawable", - * corresponding to the outer area of "tkwin". + * A rectangle "width" pixels wide is drawn in "drawable", corresponding + * to the outer area of "tkwin". * *---------------------------------------------------------------------- */ @@ -1926,8 +1981,8 @@ TkpDrawHighlightBorder ( * * TkpDrawFrame -- * - * This procedure draws the rectangular frame area. If the user - * has requested themeing, it draws with the background theme. + * This procedure draws the rectangular frame area. If the user has + * requested themeing, it draws with the background theme. * * Results: * None. diff --git a/macosx/tkMacOSXEmbed.c b/macosx/tkMacOSXEmbed.c index b23f33b..4f67f13 100644 --- a/macosx/tkMacOSXEmbed.c +++ b/macosx/tkMacOSXEmbed.c @@ -334,15 +334,15 @@ TkpUseWindow( macWin->flags |= TK_EMBEDDED; macWin->xOff = parent->winPtr->privatePtr->xOff + - parent->winPtr->changes.border_width + - winPtr->changes.x; + parent->winPtr->changes.border_width + + winPtr->changes.x; macWin->yOff = parent->winPtr->privatePtr->yOff + - parent->winPtr->changes.border_width + - winPtr->changes.y; + parent->winPtr->changes.border_width + + winPtr->changes.y; /* - * Finish filling up the container structure with the embedded - * window's information. + * Finish filling up the container structure with the embedded window's + * information. */ containerPtr->embedded = (Window) macWin; @@ -353,8 +353,8 @@ TkpUseWindow( * tkwin is eventually deleted. */ - Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc, - winPtr); + Tk_CreateEventHandler(tkwin, StructureNotifyMask, + EmbeddedEventProc, winPtr); return TCL_OK; } @@ -588,16 +588,25 @@ TkpTestembedCmd( continue; } Tcl_DStringStartSublist(&dString); - /* Parent id */ + + /* + * Parent id + */ + if (containerPtr->parent == None) { Tcl_DStringAppendElement(&dString, ""); } else if (all) { - sprintf(buffer, "0x%" TCL_Z_MODIFIER "x", (size_t) containerPtr->parent); + sprintf(buffer, "0x%" TCL_Z_MODIFIER "x", + (size_t) containerPtr->parent); Tcl_DStringAppendElement(&dString, buffer); } else { Tcl_DStringAppendElement(&dString, "XXX"); } - /* Parent pathName */ + + /* + * Parent pathName + */ + if (containerPtr->parentPtr == NULL || parentInterp != interp) { Tcl_DStringAppendElement(&dString, ""); @@ -605,11 +614,17 @@ TkpTestembedCmd( Tcl_DStringAppendElement(&dString, containerPtr->parentPtr->pathName); } + /* * On X11 embedded is a wrapper, which does not exist on macOS. */ + Tcl_DStringAppendElement(&dString, ""); - /* Embedded window pathName */ + + /* + * Embedded window pathName + */ + if (containerPtr->embeddedPtr == NULL || embeddedInterp != interp) { Tcl_DStringAppendElement(&dString, ""); @@ -768,6 +783,7 @@ ContainerEventProc( /* * When the interpreter is being dismantled this can be nil. */ + return; } @@ -920,6 +936,7 @@ EmbedActivateProc( XEvent *eventPtr) /* ResizeRequest event. */ { Container *containerPtr = clientData; + if (containerPtr->embeddedPtr != NULL) { if (eventPtr->type == ActivateNotify) { TkGenerateActivateEvents(containerPtr->embeddedPtr,1); @@ -1024,11 +1041,10 @@ EmbedGeometryRequest( /* * Forward the requested size into our geometry management hierarchy via * the container window. We need to send a Configure event back to the - * embedded application if we decide not to honor its request; to make - * this happen, process all idle event handlers synchronously here (so - * that the geometry managers have had a chance to do whatever they want - * to do), and if the window's size didn't change then generate a - * configure event. + * embedded application if we decide not to honor its request; to make this + * happen, process all idle event handlers synchronously here (so that the + * geometry managers have had a chance to do whatever they want to do), and + * if the window's size didn't change then generate a configure event. */ Tk_GeometryRequest((Tk_Window) winPtr, width, height); @@ -1050,8 +1066,8 @@ EmbedGeometryRequest( * application of its current size and location. This procedure is called * when the embedded application made a geometry request that we did not * grant, so that the embedded application knows that its geometry didn't - * change after all. It is a response to ConfigureRequest events, which - * we do not currently synthesize on the Mac + * change after all. It is a response to ConfigureRequest events, which we + * do not currently synthesize on the Mac * * Results: * None. @@ -1111,8 +1127,8 @@ EmbedWindowDeleted( containerPtr->parentPtr->flags & TK_BOTH_HALVES) { XEvent event; - event.xany.serial = - LastKnownRequestProcessed(Tk_Display(containerPtr->parentPtr)); + event.xany.serial = LastKnownRequestProcessed( + Tk_Display(containerPtr->parentPtr)); event.xany.send_event = False; event.xany.display = Tk_Display(containerPtr->parentPtr); diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index deaab20..7f1cc72 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -1,8 +1,8 @@ /* * tkMacOSXFont.c -- * - * Contains the Macintosh implementation of the platform-independant - * font package interface. + * Contains the Macintosh implementation of the platform-independant font + * package interface. * * Copyright 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> @@ -32,9 +32,8 @@ */ typedef struct { - TkFont font; /* Stuff used by generic font package. Must - * be first in structure. */ - + TkFont font; /* Stuff used by generic font package. Must be + * first in structure. */ NSFont *nsFont; NSDictionary *nsAttributes; } MacFont; @@ -83,17 +82,21 @@ static int antialiasedTextEnabled = -1; static NSCharacterSet *whitespaceCharacterSet = nil; static NSCharacterSet *lineendingCharacterSet = nil; -static void GetTkFontAttributesForNSFont(NSFont *nsFont, - TkFontAttributes *faPtr); -static NSFont *FindNSFont(const char *familyName, NSFontTraitMask traits, - NSInteger weight, CGFloat size, int fallbackToDefault); -static void InitFont(NSFont *nsFont, const TkFontAttributes *reqFaPtr, - MacFont * fontPtr); -static int CreateNamedSystemFont(Tcl_Interp *interp, Tk_Window tkwin, - const char* name, TkFontAttributes *faPtr); -static void DrawCharsInContext(Display *display, Drawable drawable, GC gc, - Tk_Font tkfont, const char *source, int numBytes, int rangeStart, - int rangeLength, int x, int y, double angle); +static void GetTkFontAttributesForNSFont(NSFont *nsFont, + TkFontAttributes *faPtr); +static NSFont * FindNSFont(const char *familyName, + NSFontTraitMask traits, NSInteger weight, + CGFloat size, int fallbackToDefault); +static void InitFont(NSFont *nsFont, + const TkFontAttributes *reqFaPtr, + MacFont *fontPtr); +static int CreateNamedSystemFont(Tcl_Interp *interp, + Tk_Window tkwin, const char *name, + TkFontAttributes *faPtr); +static void DrawCharsInContext(Display *display, Drawable drawable, + GC gc, Tk_Font tkfont, const char *source, + int numBytes, int rangeStart, int rangeLength, + int x, int y, double angle); #pragma mark - #pragma mark Font Helpers: @@ -232,7 +235,7 @@ InitFont( int ascent, descent/*, dontAA*/; static const UniChar ch[] = {'.', 'W', ' ', 0xc4, 0xc1, 0xc2, 0xc3, 0xc7}; /* ., W, Space, Auml, Aacute, Acirc, Atilde, Ccedilla */ - #define nCh (sizeof(ch) / sizeof(UniChar)) +#define nCh (sizeof(ch) / sizeof(UniChar)) CGGlyph glyphs[nCh]; CGRect boundingRects[nCh]; @@ -244,7 +247,11 @@ InitFont( TkInitFontAttributes(faPtr); } fontPtr->nsFont = nsFont; - // some don't like antialiasing on fixed-width even if bigger than limit + + /* + * Some don't like antialiasing on fixed-width even if bigger than limit + */ + // dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10; if (antialiasedTextEnabled >= 0/* || dontAA*/) { renderingMode = (antialiasedTextEnabled == 0/* || dontAA*/) ? @@ -294,7 +301,7 @@ InitFont( NSLigatureAttributeName, [NSNumber numberWithDouble:kern], NSKernAttributeName, nil]; fontPtr->nsAttributes = [nsAttributes retain]; - #undef nCh +#undef nCh } /* @@ -358,10 +365,14 @@ TkpFontPkgInit( NSFont *nsFont; TkFontAttributes fa; NSMutableCharacterSet *cs; - /* Since we called before TkpInit, we need our own autorelease pool. */ + /* + * Since we called before TkpInit, we need our own autorelease pool. + */ NSAutoreleasePool *pool = [NSAutoreleasePool new]; - /* force this for now */ + /* + * Force this for now. + */ if (!mainPtr->winPtr->mainPtr) { mainPtr->winPtr->mainPtr = mainPtr; } @@ -413,17 +424,17 @@ TkpFontPkgInit( * Map a platform-specific native font name to a TkFont. * * Results: - * The return value is a pointer to a TkFont that represents the - * native font. If a native font by the given name could not be - * found, the return value is NULL. + * The return value is a pointer to a TkFont that represents the native + * font. If a native font by the given name could not be found, the return + * value is NULL. * - * Every call to this procedure returns a new TkFont structure, even - * if the name has already been seen before. The caller should call + * Every call to this procedure returns a new TkFont structure, even if + * the name has already been seen before. The caller should call * TkpDeleteFont() when the font is no longer needed. * - * The caller is responsible for initializing the memory associated - * with the generic TkFont when this function returns and releasing - * the contents of the generics TkFont before calling TkpDeleteFont(). + * The caller is responsible for initializing the memory associated with + * the generic TkFont when this function returns and releasing the + * contents of the generics TkFont before calling TkpDeleteFont(). * * Side effects: * None. @@ -449,8 +460,8 @@ TkpGetNativeFont( } else { return NULL; } - ctFont = CTFontCreateUIFontForLanguage(HIThemeGetUIFontType( - themeFontId), 0, NULL); + ctFont = CTFontCreateUIFontForLanguage( + HIThemeGetUIFontType(themeFontId), 0, NULL); if (ctFont) { fontPtr = ckalloc(sizeof(MacFont)); InitFont((NSFont*) ctFont, NULL, fontPtr); @@ -468,19 +479,18 @@ TkpGetNativeFont( * closest matching attributes. * * Results: - * The return value is a pointer to a TkFont that represents the font - * with the desired attributes. If a font with the desired attributes - * could not be constructed, some other font will be substituted - * automatically. + * The return value is a pointer to a TkFont that represents the font with + * the desired attributes. If a font with the desired attributes could not + * be constructed, some other font will be substituted automatically. * - * Every call to this procedure returns a new TkFont structure, even - * if the specified attributes have already been seen before. The - * caller should call TkpDeleteFont() to free the platform- specific - * data when the font is no longer needed. + * Every call to this procedure returns a new TkFont structure, even if + * the specified attributes have already been seen before. The caller + * should call TkpDeleteFont() to free the platform- specific data when + * the font is no longer needed. * - * The caller is responsible for initializing the memory associated - * with the generic TkFont when this function returns and releasing - * the contents of the generic TkFont before calling TkpDeleteFont(). + * The caller is responsible for initializing the memory associated with + * the generic TkFont when this function returns and releasing the + * contents of the generic TkFont before calling TkpDeleteFont(). * * Side effects: * None. @@ -492,16 +502,16 @@ TkFont * TkpGetFontFromAttributes( TkFont *tkFontPtr, /* If non-NULL, store the information in this * existing TkFont structure, rather than - * allocating a new structure to hold the - * font; the existing contents of the font - * will be released. If NULL, a new TkFont - * structure is allocated. */ + * allocating a new structure to hold the font; + * the existing contents of the font will be + * released. If NULL, a new TkFont structure is + * allocated. */ Tk_Window tkwin, /* For display where font will be used. */ const TkFontAttributes *faPtr) /* Set of attributes to match. */ { MacFont *fontPtr; - int points = (int)(TkFontGetPoints(tkwin, faPtr->size) + 0.5); + int points = (int) (TkFontGetPoints(tkwin, faPtr->size) + 0.5); NSFontTraitMask traits = GetNSFontTraitsFromTkFontAttributes(faPtr); NSInteger weight = (faPtr->weight == TK_FW_BOLD ? 9 : 5); NSFont *nsFont; @@ -538,9 +548,9 @@ TkpGetFontFromAttributes( * TkpDeleteFont -- * * Called to release a font allocated by TkpGetNativeFont() or - * TkpGetFontFromAttributes(). The caller should have already - * released the fields of the TkFont that are used exclusively by the - * generic TkFont code. + * TkpGetFontFromAttributes(). The caller should have already released the + * fields of the TkFont that are used exclusively by the generic TkFont + * code. * * Results: * TkFont is deallocated. @@ -567,8 +577,8 @@ TkpDeleteFont( * * TkpGetFontFamilies -- * - * Return information about the font families that are available on - * the display of the given window. + * Return information about the font families that are available on the + * display of the given window. * * Results: * Modifies interp's result object to hold a list of all the available @@ -600,12 +610,12 @@ TkpGetFontFamilies( * * TkpGetSubFonts -- * - * A function used by the testing package for querying the actual - * screen fonts that make up a font object. + * A function used by the testing package for querying the actual screen + * fonts that make up a font object. * * Results: - * Modifies interp's result object to hold a list containing the names - * of the screen fonts that make up the given font object. + * Modifies interp's result object to hold a list containing the names of + * the screen fonts that make up the given font object. * * Side effects: * None. @@ -642,8 +652,8 @@ TkpGetSubFonts( * * TkpGetFontAttrsForChar -- * - * Retrieve the font attributes of the actual font used to render a - * given character. + * Retrieve the font attributes of the actual font used to render a given + * character. * * Results: * None. @@ -745,10 +755,9 @@ Tk_MeasureChars( * all the characters on the line for context. * * Results: - * The return value is the number of bytes from source that - * fit into the span that extends from 0 to maxLength. *lengthPtr is - * filled with the x-coordinate of the right edge of the last - * character that did fit. + * The return value is the number of bytes from source that fit into the + * span that extends from 0 to maxLength. *lengthPtr is filled with the + * x-coordinate of the right edge of the last character that did fit. * * Side effects: * None. @@ -774,11 +783,11 @@ TkpMeasureCharsInContext( * TK_PARTIAL_OK means include the last char * which only partially fits on this line. * TK_WHOLE_WORDS means stop on a word - * boundary, if possible. TK_AT_LEAST_ONE - * means return at least one character even - * if no characters fit. If TK_WHOLE_WORDS - * and TK_AT_LEAST_ONE are set and the first - * word doesn't fit, we return at least one + * boundary, if possible. TK_AT_LEAST_ONE means + * return at least one character even if no + * characters fit. If TK_WHOLE_WORDS and + * TK_AT_LEAST_ONE are set and the first word + * doesn't fit, we return at least one * character or whatever characters fit into * maxLength. TK_ISOLATE_END means that the * last character should not be considered in @@ -864,14 +873,13 @@ TkpMeasureCharsInContext( } /* - * If there is no line breakpoint in the source string between - * its start and the index position that fits in maxWidth, then + * If there is no line breakpoint in the source string between its + * start and the index position that fits in maxWidth, then * CTTypesetterSuggestLineBreak() returns that very last index. - * However if the TK_WHOLE_WORDS flag is set, we want to break - * at a word boundary. In this situation, unless TK_AT_LEAST_ONE - * is set, we must report that zero chars actually fit (in other - * words the smallest word of the source string is still larger - * than maxWidth). + * However if the TK_WHOLE_WORDS flag is set, we want to break at a + * word boundary. In this situation, unless TK_AT_LEAST_ONE is set, we + * must report that zero chars actually fit (in other words the + * smallest word of the source string is still larger than maxWidth). */ if ((index >= start) && (index < len) && @@ -903,9 +911,12 @@ TkpMeasureCharsInContext( CFRelease(line); } - /* The call to CTTypesetterSuggestClusterBreak above will always - return at least one character regardless of whether it exceeded - it or not. Clean that up now. */ + /* + * The call to CTTypesetterSuggestClusterBreak above will always return + * at least one character regardless of whether it exceeded it or not. + * Clean that up now. + */ + while (width > maxWidth && !(flags & TK_PARTIAL_OK) && index > start+(flags & TK_AT_LEAST_ONE)) { range.length = --index; @@ -946,7 +957,7 @@ done: * actual implementation in TkpDrawCharsInContext(). * * Results: - * None. + * None. * * Side effects: * Information gets drawn on the screen. @@ -964,8 +975,8 @@ Tk_DrawChars( const char *source, /* UTF-8 string to be displayed. Need not be * '\0' terminated. All Tk meta-characters * (tabs, control characters, and newlines) - * should be stripped out of the string that - * is passed to this function. If they are not + * should be stripped out of the string that is + * passed to this function. If they are not * stripped out, they will be displayed as * regular printing characters. */ int numBytes, /* Number of bytes in string. */ @@ -986,8 +997,8 @@ TkDrawAngledChars( const char *source, /* UTF-8 string to be displayed. Need not be * '\0' terminated. All Tk meta-characters * (tabs, control characters, and newlines) - * should be stripped out of the string that - * is passed to this function. If they are not + * should be stripped out of the string that is + * passed to this function. If they are not * stripped out, they will be displayed as * regular printing characters. */ int numBytes, /* Number of bytes in string. */ @@ -1029,8 +1040,8 @@ TkpDrawCharsInContext( const char * source, /* UTF-8 string to be displayed. Need not be * '\0' terminated. All Tk meta-characters * (tabs, control characters, and newlines) - * should be stripped out of the string that - * is passed to this function. If they are not + * should be stripped out of the string that is + * passed to this function. If they are not * stripped out, they will be displayed as * regular printing characters. */ int numBytes, /* Number of bytes in string. */ @@ -1054,8 +1065,8 @@ DrawCharsInContext( const char * source, /* UTF-8 string to be displayed. Need not be * '\0' terminated. All Tk meta-characters * (tabs, control characters, and newlines) - * should be stripped out of the string that - * is passed to this function. If they are not + * should be stripped out of the string that is + * passed to this function. If they are not * stripped out, they will be displayed as * regular printing characters. */ int numBytes, /* Number of bytes in string. */ @@ -1091,6 +1102,7 @@ DrawCharsInContext( if (!string) { return; } + context = drawingContext.context; fg = TkMacOSXCreateCGColor(gc, gc->foreground); attributes = [fontPtr->nsAttributes mutableCopy]; @@ -1119,6 +1131,7 @@ DrawCharsInContext( len = Tcl_NumUtfChars(source, rangeStart + rangeLength); if (start > 0) { CGRect clipRect = CGRectInfinite, startBounds; + line = CTTypesetterCreateLine(typesetter, CFRangeMake(0, start)); startBounds = CTLineGetImageBounds(line, context); CFRelease(line); @@ -1241,9 +1254,10 @@ TkMacOSXFontDescriptionForNSFontAndNSFontAttributes( NSUnderlineStyleAttributeName]; id strikethrough = [nsAttributes objectForKey: NSStrikethroughStyleAttributeName]; + objv[i++] = Tcl_NewStringObj(familyName, -1); objv[i++] = Tcl_NewWideIntObj([nsFont pointSize]); -#define S(s) Tcl_NewStringObj(STRINGIFY(s),(int)(sizeof(STRINGIFY(s))-1)) +#define S(s) Tcl_NewStringObj(STRINGIFY(s), (int)(sizeof(STRINGIFY(s))-1)) objv[i++] = (traits & NSBoldFontMask) ? S(bold) : S(normal); objv[i++] = (traits & NSItalicFontMask) ? S(italic) : S(roman); if ([underline respondsToSelector:@selector(intValue)] && @@ -1267,8 +1281,9 @@ TkMacOSXFontDescriptionForNSFontAndNSFontAttributes( * TkMacOSXUseAntialiasedText -- * * Enables or disables application-wide use of antialiased text (where - * available). Sets up a linked Tcl global variable to allow - * disabling of antialiased text from tcl. + * available). Sets up a linked Tcl global variable to allow disabling of + * antialiased text from Tcl. + * * The possible values for this variable are: * * -1 - Use system default as configurable in "System Prefs" -> "General". diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 38f4a70..36f1fc6 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -23,7 +23,7 @@ _XInitImageFuncPtrs( { return 0; } - + /* *---------------------------------------------------------------------- * @@ -81,14 +81,15 @@ TkMacOSXCreateCGImageWithXImage( data = memcpy(ckalloc(len), image->data + image->xoffset, len); } if (data) { - provider = CGDataProviderCreateWithData(data, data, len, releaseData); + provider = CGDataProviderCreateWithData(data, data, len, + releaseData); } if (provider) { - img = CGImageMaskCreate(image->width, image->height, bitsPerComponent, - bitsPerPixel, image->bytes_per_line, provider, decode, 0); + img = CGImageMaskCreate(image->width, image->height, + bitsPerComponent, bitsPerPixel, image->bytes_per_line, + provider, decode, 0); } - } else if (image->format == ZPixmap && image->bits_per_pixel == 32) { - + } else if ((image->format == ZPixmap) && (image->bits_per_pixel == 32)) { /* * Color image */ @@ -96,7 +97,6 @@ TkMacOSXCreateCGImageWithXImage( CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); if (image->width == 0 && image->height == 0) { - /* * CGCreateImage complains on early macOS releases. */ @@ -106,11 +106,12 @@ TkMacOSXCreateCGImageWithXImage( bitsPerComponent = 8; bitsPerPixel = 32; bitmapInfo = (image->byte_order == MSBFirst ? - kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big); + kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big); bitmapInfo |= kCGImageAlphaLast; data = memcpy(ckalloc(len), image->data + image->xoffset, len); if (data) { - provider = CGDataProviderCreateWithData(data, data, len, releaseData); + provider = CGDataProviderCreateWithData(data, data, len, + releaseData); } if (provider) { img = CGImageCreate(image->width, image->height, bitsPerComponent, @@ -127,7 +128,6 @@ TkMacOSXCreateCGImageWithXImage( return img; } - /* *---------------------------------------------------------------------- * @@ -179,15 +179,14 @@ XGetImage( if (win && has_retina == unknown) { #ifdef __clang__ - has_retina = [win respondsToSelector:@selector(backingScaleFactor)]? - yes : no; + has_retina = [win respondsToSelector:@selector(backingScaleFactor)] ? + yes : no; #else has_retina = no; #endif } if (has_retina == yes) { - /* * We only allow scale factors 1 or 2, as Apple currently does. */ @@ -205,7 +204,7 @@ XGetImage( } bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(drawable, - x, y, width, height); + x, y, width, height); if (!bitmap_rep) { TkMacOSXDbgMsg("XGetImage: Failed to construct NSBitmapRep"); return NULL; @@ -214,12 +213,12 @@ XGetImage( size = [bitmap_rep bytesPerPlane]; bytes_per_row = [bitmap_rep bytesPerRow]; bitmap = ckalloc(size); - if (!bitmap || - (bitmap_fmt != 0 && bitmap_fmt != 1) || - [bitmap_rep samplesPerPixel] != 4 || - [bitmap_rep isPlanar] != 0 || - bytes_per_row < 4 * scaled_width || - size != bytes_per_row*scaled_height ) { + if (!bitmap + || (bitmap_fmt != 0 && bitmap_fmt != 1) + || [bitmap_rep samplesPerPixel] != 4 + || [bitmap_rep isPlanar] != 0 + || bytes_per_row < 4 * scaled_width + || size != bytes_per_row * scaled_height) { TkMacOSXDbgMsg("XGetImage: Unrecognized bitmap format"); CFRelease(bitmap_rep); return NULL; @@ -228,8 +227,8 @@ XGetImage( CFRelease(bitmap_rep); /* - * When Apple extracts a bitmap from an NSView, it may be in - * either BGRA or ABGR format. For an XImage we need RGBA. + * When Apple extracts a bitmap from an NSView, it may be in either + * BGRA or ABGR format. For an XImage we need RGBA. */ struct pixel_fmt pixel = bitmap_fmt == 0 ? bgra : abgr; @@ -248,16 +247,16 @@ XGetImage( } } imagePtr = XCreateImage(display, NULL, depth, format, offset, - (char*)bitmap, scaled_width, scaled_height, - bitmap_pad, bytes_per_row); + (char*) bitmap, scaled_width, scaled_height, + bitmap_pad, bytes_per_row); if (scalefactor == 2) { imagePtr->pixelpower = 1; } } else { /* - * There are some calls to XGetImage in the generic Tk - * code which pass an XYPixmap rather than a ZPixmap. - * XYPixmaps should be handled here. + * There are some calls to XGetImage in the generic Tk code which pass + * an XYPixmap rather than a ZPixmap. XYPixmaps should be handled + * here. */ TkMacOSXDbgMsg("XGetImage does not handle XYPixmaps at the moment."); } @@ -323,40 +322,40 @@ ImageGetPixel( + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); switch (image->bits_per_pixel) { - case 32: { - r = (*((unsigned int*) srcPtr) >> 16) & 0xff; - g = (*((unsigned int*) srcPtr) >> 8) & 0xff; - b = (*((unsigned int*) srcPtr) ) & 0xff; - /*if (image->byte_order == LSBFirst) { - r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0]; - } else { - r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; - }*/ - break; - } - case 16: - r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; - g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; - b = (*((unsigned short*) srcPtr) << 3) & 0xf8; - break; - case 8: - r = (*srcPtr << 2) & 0xc0; - g = (*srcPtr << 4) & 0xc0; - b = (*srcPtr << 6) & 0xc0; - r |= r >> 2 | r >> 4 | r >> 6; - g |= g >> 2 | g >> 4 | g >> 6; - b |= b >> 2 | b >> 4 | b >> 6; - break; - case 4: { - unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); - r = (c & 0x04) ? 0xff : 0; - g = (c & 0x02) ? 0xff : 0; - b = (c & 0x01) ? 0xff : 0; - break; - } - case 1: - r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; - break; + case 32: + r = (*((unsigned int*) srcPtr) >> 16) & 0xff; + g = (*((unsigned int*) srcPtr) >> 8) & 0xff; + b = (*((unsigned int*) srcPtr) ) & 0xff; + /*if (image->byte_order == LSBFirst) { + r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0]; + } else { + r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; + }*/ + break; + case 16: + r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; + g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; + b = (*((unsigned short*) srcPtr) << 3) & 0xf8; + break; + case 8: + r = (*srcPtr << 2) & 0xc0; + g = (*srcPtr << 4) & 0xc0; + b = (*srcPtr << 6) & 0xc0; + r |= r >> 2 | r >> 4 | r >> 6; + g |= g >> 2 | g >> 4 | g >> 6; + b |= b >> 2 | b >> 4 | b >> 6; + break; + case 4: { + unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); + + r = (c & 0x04) ? 0xff : 0; + g = (c & 0x02) ? 0xff : 0; + b = (c & 0x01) ? 0xff : 0; + break; + } + case 1: + r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; + break; } } return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b; @@ -389,6 +388,7 @@ ImagePutPixel( unsigned char *dstPtr = ((unsigned char*) image->data) + (y * image->bytes_per_line) + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); + if (image->bits_per_pixel == 32) { *((unsigned int*) dstPtr) = pixel; } else { @@ -420,7 +420,7 @@ ImagePutPixel( } return 0; } - + /* *---------------------------------------------------------------------- * @@ -451,6 +451,7 @@ XCreateImage( int bytes_per_line) { XImage *ximage; + display->request++; ximage = ckalloc(sizeof(XImage)); @@ -461,9 +462,12 @@ XCreateImage( ximage->format = format; ximage->data = data; ximage->obdata = NULL; - /* The default pixelpower is 0. This must be explicitly set to 1 in the + + /* + * The default pixelpower is 0. This must be explicitly set to 1 in the * case of an XImage extracted from a Retina display. */ + ximage->pixelpower = 0; if (format == ZPixmap) { @@ -476,7 +480,10 @@ XCreateImage( if (bitmap_pad) { ximage->bitmap_pad = bitmap_pad; } else { - /* Use 16 byte alignment for best Quartz perfomance */ + /* + * Use 16 byte alignment for best Quartz perfomance. + */ + ximage->bitmap_pad = 128; } if (bytes_per_line) { @@ -511,9 +518,9 @@ XCreateImage( * * TkPutImage -- * - * Copies a rectangular subimage of an XImage into a drawable. - * Currently this is only called by TkImgPhotoDisplay, using - * a Window as the drawable. + * Copies a rectangular subimage of an XImage into a drawable. Currently + * this is only called by TkImgPhotoDisplay, using a Window as the + * drawable. * * Results: * None. @@ -559,13 +566,15 @@ TkPutImage( } if (img) { - /* If the XImage has big pixels, the source is rescaled to reflect + /* + * If the XImage has big pixels, the source is rescaled to reflect * the actual pixel dimensions. This is not currently used, but * could arise if the image were copied from a retina monitor and * redrawn on an ordinary monitor. */ int pp = image->pixelpower; + bounds = CGRectMake(0, 0, image->width, image->height); srcRect = CGRectMake(src_x<<pp, src_y<<pp, width<<pp, height<<pp); dstRect = CGRectMake(dest_x, dest_y, width, height); diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 3c02d92..2e92c0b 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -45,7 +45,7 @@ static char scriptPath[PATH_MAX + 1] = ""; @implementation TKApplication(TKInit) - (void) _resetAutoreleasePool { - if([self poolLock] == 0) { + if ([self poolLock] == 0) { [_mainPool drain]; _mainPool = [NSAutoreleasePool new]; } else { @@ -117,16 +117,15 @@ static char scriptPath[PATH_MAX + 1] = ""; -(void)applicationDidFinishLaunching:(NSNotification *)notification { /* - * It is not safe to force activation of the NSApp until this - * method is called. Activating too early can cause the menu - * bar to be unresponsive. + * It is not safe to force activation of the NSApp until this method is + * called. Activating too early can cause the menu bar to be unresponsive. */ [NSApp activateIgnoringOtherApps: YES]; /* - * Process events to ensure that the root window is fully - * initialized. See ticket 56a1823c73. + * Process events to ensure that the root window is fully initialized. See + * ticket 56a1823c73. */ [NSApp _lockAutoreleasePool]; @@ -310,8 +309,8 @@ TkpInit( } /* - * Instantiate our NSApplication object. This needs to be - * done before we check whether to open a console window. + * Instantiate our NSApplication object. This needs to be done before + * we check whether to open a console window. */ NSAutoreleasePool *pool = [NSAutoreleasePool new]; @@ -342,8 +341,8 @@ TkpInit( Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR)); /* - * Only show the console if we don't have a startup script - * and tcl_interactive hasn't been set already. + * Only show the console if we don't have a startup script and + * tcl_interactive hasn't been set already. */ if (Tcl_GetStartupScript(NULL) == NULL) { diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c index 543e7ab..f2470de 100644 --- a/macosx/tkMacOSXKeyEvent.c +++ b/macosx/tkMacOSXKeyEvent.c @@ -27,16 +27,16 @@ static Tk_Window keyboardGrabWinPtr = NULL; /* Current keyboard grab window. */ static NSWindow *keyboardGrabNSWindow = nil; - /* NSWindow for the current keyboard grab window. */ + /* NSWindow for the current keyboard grab + * window. */ static NSModalSession modalSession = nil; - static BOOL processingCompose = NO; static BOOL finishedCompose = NO; - static int caret_x = 0, caret_y = 0, caret_height = 0; -static void setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state); -static unsigned isFunctionKey(unsigned int code); +static void setupXEvent(XEvent *xEvent, NSWindow *w, + unsigned int state); +static unsigned isFunctionKey(unsigned int code); unsigned short releaseCode; @@ -50,22 +50,21 @@ unsigned short releaseCode; #ifdef TK_MAC_DEBUG_EVENTS TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); #endif - NSWindow* w; - NSEventType type = [theEvent type]; + NSWindow *w; + NSEventType type = [theEvent type]; NSUInteger modifiers = ([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask); - NSUInteger len = 0; - BOOL repeat = NO; - unsigned short keyCode = [theEvent keyCode]; - NSString *characters = nil, *charactersIgnoringModifiers = nil; + NSUInteger len = 0; + BOOL repeat = NO; + unsigned short keyCode = [theEvent keyCode]; + NSString *characters = nil, *charactersIgnoringModifiers = nil; static NSUInteger savedModifiers = 0; static NSMutableArray *nsEvArray; - if (nsEvArray == nil) - { + if (nsEvArray == nil) { nsEvArray = [[NSMutableArray alloc] initWithCapacity: 1]; processingCompose = NO; - } + } w = [theEvent window]; TkWindow *winPtr = TkMacOSXGetTkWindow(w); @@ -109,37 +108,39 @@ unsigned short releaseCode; return theEvent; /* Unrecognized key event. */ } - /* Create an Xevent to add to the Tk queue. */ + /* + * Create an Xevent to add to the Tk queue. + */ + if (!processingCompose) { unsigned int state = 0; if (modifiers & NSAlphaShiftKeyMask) { - state |= LockMask; + state |= LockMask; } if (modifiers & NSShiftKeyMask) { - state |= ShiftMask; + state |= ShiftMask; } if (modifiers & NSControlKeyMask) { - state |= ControlMask; + state |= ControlMask; } if (modifiers & NSCommandKeyMask) { - state |= Mod1Mask; /* command key */ + state |= Mod1Mask; /* command key */ } if (modifiers & NSAlternateKeyMask) { - state |= Mod2Mask; /* option key */ + state |= Mod2Mask; /* option key */ } if (modifiers & NSNumericPadKeyMask) { - state |= Mod3Mask; + state |= Mod3Mask; } if (modifiers & NSFunctionKeyMask) { - state |= Mod4Mask; + state |= Mod4Mask; } /* - * Events are only received for the front Window on the Macintosh. - * So to build an XEvent we look up the Tk window associated to the - * Front window. If a different window has a local grab we ignore - * the event. + * Events are only received for the front Window on the Macintosh. So + * to build an XEvent we look up the Tk window associated to the Front + * window. If a different window has a local grab we ignore the event. */ TkWindow *winPtr = TkMacOSXGetTkWindow(w); @@ -147,110 +148,112 @@ unsigned short releaseCode; if (tkwin) { TkWindow *grabWinPtr = winPtr->dispPtr->grabWinPtr; - if (grabWinPtr && - grabWinPtr != winPtr && - !winPtr->dispPtr->grabFlags && /* this means the grab is local. */ - grabWinPtr->mainPtr == winPtr->mainPtr) { + + if (grabWinPtr + && grabWinPtr != winPtr + && !winPtr->dispPtr->grabFlags /* this means the grab is local. */ + && grabWinPtr->mainPtr == winPtr->mainPtr) { return theEvent; } } else { tkwin = (Tk_Window) winPtr->dispPtr->focusPtr; } if (!tkwin) { - TkMacOSXDbgMsg("tkwin == NULL"); - return theEvent; /* Give up. No window for this event. */ + TkMacOSXDbgMsg("tkwin == NULL"); + return theEvent; /* Give up. No window for this event. */ } /* - * If it's a function key, or we have modifiers other than Shift or Alt, - * pass it straight to Tk. Otherwise we'll send for input processing. + * If it's a function key, or we have modifiers other than Shift or + * Alt, pass it straight to Tk. Otherwise we'll send for input + * processing. */ - int code = (len == 0) ? - 0 : [charactersIgnoringModifiers characterAtIndex: 0]; + int code = (len == 0) ? 0 : + [charactersIgnoringModifiers characterAtIndex: 0]; if (type != NSKeyDown || isFunctionKey(code) - || (len > 0 && state & (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask))) { - + || (len > 0 && state & (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask))) { XEvent xEvent; - setupXEvent(&xEvent, w, state); + setupXEvent(&xEvent, w, state); if (type == NSFlagsChanged) { - if (savedModifiers > modifiers) { - xEvent.xany.type = KeyRelease; - } else { - xEvent.xany.type = KeyPress; - } + if (savedModifiers > modifiers) { + xEvent.xany.type = KeyRelease; + } else { + xEvent.xany.type = KeyPress; + } - /* - * Use special '-1' to signify a special keycode to our platform - * specific code in tkMacOSXKeyboard.c. This is rather like what - * happens on Windows. - */ + /* + * Use special '-1' to signify a special keycode to our + * platform specific code in tkMacOSXKeyboard.c. This is rather + * like what happens on Windows. + */ - xEvent.xany.send_event = -1; + xEvent.xany.send_event = -1; - /* - * Set keycode (which was zero) to the changed modifier - */ + /* + * Set keycode (which was zero) to the changed modifier + */ - xEvent.xkey.keycode = (modifiers ^ savedModifiers); + xEvent.xkey.keycode = (modifiers ^ savedModifiers); } else { - if (type == NSKeyUp || repeat) { - xEvent.xany.type = KeyRelease; - } else { - xEvent.xany.type = KeyPress; - } - - /* For command key, take input manager's word so things - like dvorak / qwerty layout work. */ - if ((modifiers & NSCommandKeyMask) == NSCommandKeyMask - && (modifiers & NSAlternateKeyMask) != NSAlternateKeyMask - && len > 0 && !isFunctionKey(code)) { - // head off keycode-based translation in tkMacOSXKeyboard.c - xEvent.xkey.nbytes = [characters length]; //len - } - - if ([characters length] > 0) { - xEvent.xkey.keycode = - (keyCode << 16) | (UInt16) [characters characterAtIndex:0]; - if (![characters getCString:xEvent.xkey.trans_chars - maxLength:XMaxTransChars encoding:NSUTF8StringEncoding]) { - /* prevent SF bug 2907388 (crash on some composite chars) */ - //PENDING: we might not need this anymore - TkMacOSXDbgMsg("characters too long"); - return theEvent; - } - } - - if (repeat) { - Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); - xEvent.xany.type = KeyPress; - xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin)); - } + if (type == NSKeyUp || repeat) { + xEvent.xany.type = KeyRelease; + } else { + xEvent.xany.type = KeyPress; + } + + /* + * For command key, take input manager's word so things like + * dvorak / qwerty layout work. + */ + + if ((modifiers & NSCommandKeyMask) == NSCommandKeyMask + && (modifiers & NSAlternateKeyMask) != NSAlternateKeyMask + && len > 0 && !isFunctionKey(code)) { + // head off keycode-based translation in tkMacOSXKeyboard.c + xEvent.xkey.nbytes = [characters length]; //len + } + + if ([characters length] > 0) { + xEvent.xkey.keycode = (keyCode << 16) | + (UInt16) [characters characterAtIndex:0]; + if (![characters getCString:xEvent.xkey.trans_chars + maxLength:XMaxTransChars encoding:NSUTF8StringEncoding]) { + /* prevent SF bug 2907388 (crash on some composite chars) */ + //PENDING: we might not need this anymore + TkMacOSXDbgMsg("characters too long"); + return theEvent; + } + } + + if (repeat) { + Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); + xEvent.xany.type = KeyPress; + xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin)); + } } Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); savedModifiers = modifiers; return theEvent; - } /* if send straight to TK */ - - } /* if not processing compose */ + } /* if send straight to TK */ + } /* if not processing compose */ if (type == NSKeyDown) { - if (NS_KEYLOG) - fprintf (stderr, "keyDown: %s compose sequence.\n", - processingCompose == YES ? "Continue" : "Begin"); + if (NS_KEYLOG) { + TKLog(@"keyDown: %s compose sequence.\n", + processingCompose == YES ? "Continue" : "Begin"); + } processingCompose = YES; [nsEvArray addObject: theEvent]; [[w contentView] interpretKeyEvents: nsEvArray]; [nsEvArray removeObject: theEvent]; - } + } savedModifiers = modifiers; - return theEvent; } @end - @implementation TKContentView @@ -261,163 +264,189 @@ unsigned short releaseCode; by doCommandBySelector: deleteBackward: */ - (void)insertText: (id)aString { - int i, len = [(NSString *)aString length]; - XEvent xEvent; + int i, len = [(NSString *) aString length]; + XEvent xEvent; - if (NS_KEYLOG) - TKLog (@"insertText '%@'\tlen = %d", aString, len); - processingCompose = NO; - finishedCompose = YES; + if (NS_KEYLOG) { + TKLog(@"insertText '%@'\tlen = %d", aString, len); + } + processingCompose = NO; + finishedCompose = YES; - /* first, clear any working text */ - if (privateWorkingText != nil) - [self deleteWorkingText]; + /* + * First, clear any working text. + */ + + if (privateWorkingText != nil) { + [self deleteWorkingText]; + } - /* now insert the string as keystrokes */ - setupXEvent(&xEvent, [self window], 0); - xEvent.xany.type = KeyPress; + /* + * Now insert the string as keystrokes. + */ - for (i =0; i<len; i++) - { - xEvent.xkey.keycode = (UInt16) [aString characterAtIndex: i]; - [[aString substringWithRange: NSMakeRange(i,1)] + setupXEvent(&xEvent, [self window], 0); + xEvent.xany.type = KeyPress; + + for (i =0; i<len; i++) { + xEvent.xkey.keycode = (UInt16) [aString characterAtIndex: i]; + [[aString substringWithRange: NSMakeRange(i,1)] getCString: xEvent.xkey.trans_chars maxLength: XMaxTransChars encoding: NSUTF8StringEncoding]; - xEvent.xkey.nbytes = strlen(xEvent.xkey.trans_chars); - xEvent.xany.type = KeyPress; - releaseCode = (UInt16) [aString characterAtIndex: 0]; - Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); - } - releaseCode = (UInt16) [aString characterAtIndex: 0]; + xEvent.xkey.nbytes = strlen(xEvent.xkey.trans_chars); + xEvent.xany.type = KeyPress; + releaseCode = (UInt16) [aString characterAtIndex: 0]; + Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); + } + releaseCode = (UInt16) [aString characterAtIndex: 0]; } /* <NSTextInput>: inserts display of composing characters */ - (void)setMarkedText: (id)aString selectedRange: (NSRange)selRange { - NSString *str = [aString respondsToSelector: @selector (string)] ? - [aString string] : aString; - if (NS_KEYLOG) - TKLog (@"setMarkedText '%@' len =%lu range %lu from %lu", str, - (unsigned long) [str length], (unsigned long) selRange.length, - (unsigned long) selRange.location); - - if (privateWorkingText != nil) - [self deleteWorkingText]; - if ([str length] == 0) - return; + NSString *str = [aString respondsToSelector: @selector (string)] ? + [aString string] : aString; + if (NS_KEYLOG) { + TKLog(@"setMarkedText '%@' len =%lu range %lu from %lu", str, + (unsigned long) [str length], (unsigned long) selRange.length, + (unsigned long) selRange.location); + } + + if (privateWorkingText != nil) { + [self deleteWorkingText]; + } + if ([str length] == 0) { + return; + } - processingCompose = YES; - privateWorkingText = [str copy]; + processingCompose = YES; + privateWorkingText = [str copy]; - //PENDING: insert workingText underlined + //PENDING: insert workingText underlined } - (BOOL)hasMarkedText { - return privateWorkingText != nil; + return privateWorkingText != nil; } - (NSRange)markedRange { - NSRange rng = privateWorkingText != nil - ? NSMakeRange (0, [privateWorkingText length]) : NSMakeRange (NSNotFound, 0); - if (NS_KEYLOG) - TKLog (@"markedRange request"); - return rng; + NSRange rng = privateWorkingText != nil + ? NSMakeRange(0, [privateWorkingText length]) + : NSMakeRange(NSNotFound, 0); + + if (NS_KEYLOG) { + TKLog(@"markedRange request"); + } + return rng; } - (void)unmarkText { - if (NS_KEYLOG) - TKLog (@"unmark (accept) text"); - [self deleteWorkingText]; - processingCompose = NO; + if (NS_KEYLOG) { + TKLog(@"unmark (accept) text"); + } + [self deleteWorkingText]; + processingCompose = NO; } /* used to position char selection windows, etc. */ - (NSRect)firstRectForCharacterRange: (NSRange)theRange { - NSRect rect; - NSPoint pt; + NSRect rect; + NSPoint pt; - pt.x = caret_x; - pt.y = caret_y; + pt.x = caret_x; + pt.y = caret_y; - pt = [self convertPoint: pt toView: nil]; - pt = [[self window] tkConvertPointToScreen: pt]; - pt.y -= caret_height; + pt = [self convertPoint: pt toView: nil]; + pt = [[self window] tkConvertPointToScreen: pt]; + pt.y -= caret_height; - rect.origin = pt; - rect.size.width = caret_height; - rect.size.height = caret_height; - return rect; + rect.origin = pt; + rect.size.width = caret_height; + rect.size.height = caret_height; + return rect; } - (NSInteger)conversationIdentifier { - return (NSInteger)self; + return (NSInteger) self; } - (void)doCommandBySelector: (SEL)aSelector { - if (NS_KEYLOG) - TKLog (@"doCommandBySelector: %@", NSStringFromSelector (aSelector)); - processingCompose = NO; - if (aSelector == @selector (deleteBackward:)) - { - /* happens when user backspaces over an ongoing composition: - throw a 'delete' into the event queue */ - XEvent xEvent; - setupXEvent(&xEvent, [self window], 0); - xEvent.xany.type = KeyPress; - xEvent.xkey.nbytes = 1; - xEvent.xkey.keycode = (0x33 << 16) | 0x7F; - xEvent.xkey.trans_chars[0] = 0x7F; - xEvent.xkey.trans_chars[1] = 0x0; - Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); + if (NS_KEYLOG) { + TKLog(@"doCommandBySelector: %@", NSStringFromSelector(aSelector)); + } + processingCompose = NO; + if (aSelector == @selector (deleteBackward:)) { + /* + * Happens when user backspaces over an ongoing composition: + * throw a 'delete' into the event queue. + */ + + XEvent xEvent; + + setupXEvent(&xEvent, [self window], 0); + xEvent.xany.type = KeyPress; + xEvent.xkey.nbytes = 1; + xEvent.xkey.keycode = (0x33 << 16) | 0x7F; + xEvent.xkey.trans_chars[0] = 0x7F; + xEvent.xkey.trans_chars[1] = 0x0; + Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); } } - (NSArray *)validAttributesForMarkedText { - static NSArray *arr = nil; - if (arr == nil) arr = [NSArray new]; - /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */ - return arr; + static NSArray *arr = nil; + + if (arr == nil) { + arr = [NSArray new]; + } + /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */ + return arr; } - (NSRange)selectedRange { - if (NS_KEYLOG) - TKLog (@"selectedRange request"); - return NSMakeRange (NSNotFound, 0); + if (NS_KEYLOG) { + TKLog(@"selectedRange request"); + } + return NSMakeRange(NSNotFound, 0); } - (NSUInteger)characterIndexForPoint: (NSPoint)thePoint { - if (NS_KEYLOG) - TKLog (@"characterIndexForPoint request"); - return 0; + if (NS_KEYLOG) { + TKLog(@"characterIndexForPoint request"); + } + return 0; } - (NSAttributedString *)attributedSubstringFromRange: (NSRange)theRange { - static NSAttributedString *str = nil; - if (str == nil) str = [NSAttributedString new]; - if (NS_KEYLOG) - TKLog (@"attributedSubstringFromRange request"); - return str; + static NSAttributedString *str = nil; + if (str == nil) { + str = [NSAttributedString new]; + } + if (NS_KEYLOG) { + TKLog(@"attributedSubstringFromRange request"); + } + return str; } /* End <NSTextInput> impl. */ @end @@ -427,29 +456,30 @@ unsigned short releaseCode; /* delete display of composing characters [not in <NSTextInput>] */ - (void)deleteWorkingText { - if (privateWorkingText == nil) - return; - if (NS_KEYLOG) - TKLog(@"deleteWorkingText len = %lu\n", - (unsigned long)[privateWorkingText length]); - [privateWorkingText release]; - privateWorkingText = nil; - processingCompose = NO; - - //PENDING: delete working text + if (privateWorkingText == nil) { + return; + } + if (NS_KEYLOG) { + TKLog(@"deleteWorkingText len = %lu\n", + (unsigned long)[privateWorkingText length]); + } + [privateWorkingText release]; + privateWorkingText = nil; + processingCompose = NO; + + //PENDING: delete working text } @end - - /* - * Set up basic fields in xevent for keyboard input. + * Set up basic fields in xevent for keyboard input. */ static void setupXEvent(XEvent *xEvent, NSWindow *w, unsigned int state) { TkWindow *winPtr = TkMacOSXGetTkWindow(w); Tk_Window tkwin = (Tk_Window) winPtr; + if (!winPtr) { return; } @@ -497,12 +527,13 @@ XGrabKeyboard( Time time) { keyboardGrabWinPtr = Tk_IdToWindow(display, grab_window); - TkWindow *captureWinPtr = (TkWindow *)TkMacOSXGetCapture(); + TkWindow *captureWinPtr = (TkWindow *) TkMacOSXGetCapture(); + if (keyboardGrabWinPtr && captureWinPtr) { NSWindow *w = TkMacOSXDrawableWindow(grab_window); MacDrawable *macWin = (MacDrawable *) grab_window; - if (w && macWin->toplevel->winPtr == (TkWindow*) captureWinPtr) { + if (w && macWin->toplevel->winPtr == (TkWindow *) captureWinPtr) { if (modalSession) { Tcl_Panic("XGrabKeyboard: already grabbed"); } @@ -621,7 +652,10 @@ Tk_SetCaretPos( } } - /* But adjust for fact that NS uses flipped view. */ + /* + * But adjust for fact that NS uses flipped view. + */ + y = Tk_Height(tkwin) - y; caret_x = x; @@ -632,75 +666,80 @@ Tk_SetCaretPos( static unsigned convert_ns_to_X_keysym[] = { - NSHomeFunctionKey, 0x50, - NSLeftArrowFunctionKey, 0x51, - NSUpArrowFunctionKey, 0x52, - NSRightArrowFunctionKey, 0x53, - NSDownArrowFunctionKey, 0x54, - NSPageUpFunctionKey, 0x55, - NSPageDownFunctionKey, 0x56, - NSEndFunctionKey, 0x57, - NSBeginFunctionKey, 0x58, - NSSelectFunctionKey, 0x60, - NSPrintFunctionKey, 0x61, - NSExecuteFunctionKey, 0x62, - NSInsertFunctionKey, 0x63, - NSUndoFunctionKey, 0x65, - NSRedoFunctionKey, 0x66, - NSMenuFunctionKey, 0x67, - NSFindFunctionKey, 0x68, - NSHelpFunctionKey, 0x6A, - NSBreakFunctionKey, 0x6B, - - NSF1FunctionKey, 0xBE, - NSF2FunctionKey, 0xBF, - NSF3FunctionKey, 0xC0, - NSF4FunctionKey, 0xC1, - NSF5FunctionKey, 0xC2, - NSF6FunctionKey, 0xC3, - NSF7FunctionKey, 0xC4, - NSF8FunctionKey, 0xC5, - NSF9FunctionKey, 0xC6, - NSF10FunctionKey, 0xC7, - NSF11FunctionKey, 0xC8, - NSF12FunctionKey, 0xC9, - NSF13FunctionKey, 0xCA, - NSF14FunctionKey, 0xCB, - NSF15FunctionKey, 0xCC, - NSF16FunctionKey, 0xCD, - NSF17FunctionKey, 0xCE, - NSF18FunctionKey, 0xCF, - NSF19FunctionKey, 0xD0, - NSF20FunctionKey, 0xD1, - NSF21FunctionKey, 0xD2, - NSF22FunctionKey, 0xD3, - NSF23FunctionKey, 0xD4, - NSF24FunctionKey, 0xD5, - - NSBackspaceCharacter, 0x08, /* 8: Not on some KBs. */ - NSDeleteCharacter, 0xFF, /* 127: Big 'delete' key upper right. */ - NSDeleteFunctionKey, 0x9F, /* 63272: Del forw key off main array. */ - - NSTabCharacter, 0x09, - 0x19, 0x09, /* left tab->regular since pass shift */ - NSCarriageReturnCharacter, 0x0D, - NSNewlineCharacter, 0x0D, - NSEnterCharacter, 0x8D, - - 0x1B, 0x1B /* escape */ + NSHomeFunctionKey, 0x50, + NSLeftArrowFunctionKey, 0x51, + NSUpArrowFunctionKey, 0x52, + NSRightArrowFunctionKey, 0x53, + NSDownArrowFunctionKey, 0x54, + NSPageUpFunctionKey, 0x55, + NSPageDownFunctionKey, 0x56, + NSEndFunctionKey, 0x57, + NSBeginFunctionKey, 0x58, + NSSelectFunctionKey, 0x60, + NSPrintFunctionKey, 0x61, + NSExecuteFunctionKey, 0x62, + NSInsertFunctionKey, 0x63, + NSUndoFunctionKey, 0x65, + NSRedoFunctionKey, 0x66, + NSMenuFunctionKey, 0x67, + NSFindFunctionKey, 0x68, + NSHelpFunctionKey, 0x6A, + NSBreakFunctionKey, 0x6B, + + NSF1FunctionKey, 0xBE, + NSF2FunctionKey, 0xBF, + NSF3FunctionKey, 0xC0, + NSF4FunctionKey, 0xC1, + NSF5FunctionKey, 0xC2, + NSF6FunctionKey, 0xC3, + NSF7FunctionKey, 0xC4, + NSF8FunctionKey, 0xC5, + NSF9FunctionKey, 0xC6, + NSF10FunctionKey, 0xC7, + NSF11FunctionKey, 0xC8, + NSF12FunctionKey, 0xC9, + NSF13FunctionKey, 0xCA, + NSF14FunctionKey, 0xCB, + NSF15FunctionKey, 0xCC, + NSF16FunctionKey, 0xCD, + NSF17FunctionKey, 0xCE, + NSF18FunctionKey, 0xCF, + NSF19FunctionKey, 0xD0, + NSF20FunctionKey, 0xD1, + NSF21FunctionKey, 0xD2, + NSF22FunctionKey, 0xD3, + NSF23FunctionKey, 0xD4, + NSF24FunctionKey, 0xD5, + + NSBackspaceCharacter, 0x08, /* 8: Not on some KBs. */ + NSDeleteCharacter, 0xFF, /* 127: Big 'delete' key upper right. */ + NSDeleteFunctionKey, 0x9F, /* 63272: Del forw key off main array. */ + + NSTabCharacter, 0x09, + 0x19, 0x09, /* left tab->regular since pass shift */ + NSCarriageReturnCharacter, 0x0D, + NSNewlineCharacter, 0x0D, + NSEnterCharacter, 0x8D, + + 0x1B, 0x1B /* escape */ }; -static unsigned isFunctionKey(unsigned code) +static unsigned +isFunctionKey( + unsigned code) { - const unsigned last_keysym = (sizeof (convert_ns_to_X_keysym) - / sizeof (convert_ns_to_X_keysym[0])); - unsigned keysym; - for (keysym = 0; keysym < last_keysym; keysym += 2) - if (code == convert_ns_to_X_keysym[keysym]) - return 0xFF00 | convert_ns_to_X_keysym[keysym+1]; - return 0; - } + const unsigned last_keysym = (sizeof(convert_ns_to_X_keysym) + / sizeof(convert_ns_to_X_keysym[0])); + unsigned keysym; + + for (keysym = 0; keysym < last_keysym; keysym += 2) { + if (code == convert_ns_to_X_keysym[keysym]) { + return 0xFF00 | convert_ns_to_X_keysym[keysym + 1]; + } + } + return 0; +} /* * Local Variables: diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index 3d7cdaf..2292ede 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -193,10 +193,10 @@ static int ModifierCharWidth(Tk_Font tkfont); - (void) insertItem: (NSMenuItem *) newItem atIndex: (NSInteger) index { if (_tkMenu && index >= 0) { - if ((NSUInteger)index <= _tkOffset) { + if ((NSUInteger) index <= _tkOffset) { _tkOffset++; } else { - NSAssert((NSUInteger)index >= _tkItemCount + _tkOffset, + NSAssert((NSUInteger) index >= _tkItemCount + _tkOffset, @"Cannot insert in the middle of Tk menu"); } } @@ -206,9 +206,9 @@ static int ModifierCharWidth(Tk_Font tkfont); - (void) removeItemAtIndex: (NSInteger) index { if (_tkMenu && index >= 0) { - if ((NSUInteger)index < _tkOffset) { + if ((NSUInteger) index < _tkOffset) { _tkOffset--; - } else if ((NSUInteger)index < _tkItemCount + _tkOffset) { + } else if ((NSUInteger) index < _tkItemCount + _tkOffset) { _tkItemCount--; } } @@ -221,7 +221,7 @@ static int ModifierCharWidth(Tk_Font tkfont); action:@selector(tkMenuItemInvoke:) keyEquivalent:@""]; [menuItem setTarget:self]; - [menuItem setTag:(NSInteger)mePtr]; + [menuItem setTag:(NSInteger) mePtr]; return menuItem; } @end @@ -252,15 +252,16 @@ static int ModifierCharWidth(Tk_Font tkfont); */ if ([sender isKindOfClass:[NSMenuItem class]]) { - NSMenuItem *menuItem = (NSMenuItem *)sender; - TkMenu *menuPtr = (TkMenu *)_tkMenu; - TkMenuEntry *mePtr = (TkMenuEntry *)[menuItem tag]; + NSMenuItem *menuItem = (NSMenuItem *) sender; + TkMenu *menuPtr = (TkMenu *) _tkMenu; + TkMenuEntry *mePtr = (TkMenuEntry *) [menuItem tag]; if (menuPtr && mePtr) { Tcl_Interp *interp = menuPtr->interp; - /*Add time for errors to fire if necessary. This is sub-optimal - *but avoids issues with Tcl/Cocoa event loop integration. + /* + * Add time for errors to fire if necessary. This is sub-optimal + * but avoids issues with Tcl/Cocoa event loop integration. */ //Tcl_Sleep(100); @@ -305,8 +306,8 @@ static int ModifierCharWidth(Tk_Font tkfont); return NO; } else if (modifiers == (NSControlKeyMask | NSShiftKeyMask) && [event keyCode] == 48) { - - /* Starting with OSX 10.12 Control-Tab and Control-Shift-Tab are used + /* + * Starting with OSX 10.12 Control-Tab and Control-Shift-Tab are used * to select window tabs. But for some even more mysterious reason the * Control-Shift-Tab event has character 0x19 = NSBackTabCharacter * rather than 0x09 = NSTabCharacter. At the same time, the @@ -317,7 +318,6 @@ static int ModifierCharWidth(Tk_Font tkfont); key = @"\t"; } else if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) { - /* * If the command modifier is set, use the full character string so * things like the dvorak / qwerty layout will work. @@ -650,7 +650,7 @@ TkpConfigureMenuEntry( gc->foreground!=defaultFg? gc->foreground:gc->background); attributes = [[attributes mutableCopy] autorelease]; - [(NSMutableDictionary *)attributes setObject:color + [(NSMutableDictionary *) attributes setObject:color forKey:NSForegroundColorAttributeName]; } if (attributes) { @@ -690,21 +690,30 @@ TkpConfigureMenuEntry( [submenu setTitle:title]; if ([menuItem isEnabled]) { - /* This menuItem might have been previously disabled (XXX: - track this), which would have disabled entries; we must - re-enable the entries here. */ - int i = 0; - NSArray *itemArray = [submenu itemArray]; - for (NSMenuItem *item in itemArray) { - TkMenuEntry *submePtr = menuRefPtr->menuPtr->entries[i]; - /* Work around an apparent bug where itemArray can have - more items than the menu's entries[] array. */ - if (i >= (int)menuRefPtr->menuPtr->numEntries) break; - [item setEnabled: !(submePtr->state == ENTRY_DISABLED)]; - i++; - } + /* + * This menuItem might have been previously disabled (XXX: + * track this), which would have disabled entries; we must + * re-enable the entries here. + */ + + int i = 0; + NSArray *itemArray = [submenu itemArray]; + + for (NSMenuItem *item in itemArray) { + TkMenuEntry *submePtr = menuRefPtr->menuPtr->entries[i]; + + /* + * Work around an apparent bug where itemArray can have + * more items than the menu's entries[] array. + */ + + if (i >= (int) menuRefPtr->menuPtr->numEntries) { + break; + } + [item setEnabled: !(submePtr->state == ENTRY_DISABLED)]; + i++; + } } - } } } @@ -755,10 +764,10 @@ TkpDestroyMenuEntry( * * TkpPostMenu -- * - * Posts a menu on the screen. If entry is < 0 then the menu is - * drawn so its top left corner is located at the point with - * screen coordinates (x, y). Otherwise the top left corner of - * the specified entry is located at that point. + * Posts a menu on the screen. If entry is < 0 then the menu is drawn so + * its top left corner is located at the point with screen coordinates + * (x,y). Otherwise the top left corner of the specified entry is located + * at that point. * * Results: * Returns a standard Tcl result. @@ -828,13 +837,13 @@ TkpPostMenu( * * TkpPostTearoffMenu -- * - * Tearoff menus are not supported on the Mac. This placeholder - * function, which is simply a copy of the unix function, posts a - * completely useless window with a black background on the screen. If - * entry is < 0 then the window is positioned so that its top left corner - * is located at the point with screen coordinates (x, y). Otherwise the - * window position is offset so that top left corner of the specified - * entry would be located at that point, if there actually were a menu. + * Tearoff menus are not supported on the Mac. This placeholder function, + * which is simply a copy of the unix function, posts a completely useless + * window with a black background on the screen. If entry is < 0 then the + * window is positioned so that its top left corner is located at the + * point with screen coordinates (x, y). Otherwise the window position is + * offset so that top left corner of the specified entry would be located + * at that point, if there actually were a menu. * * Mac menus steal all mouse or keyboard input from the application until * the menu is dismissed, with or without a selection, by a mouse or key @@ -862,7 +871,7 @@ TkpPostTearoffMenu( int vRootX, vRootY, vRootWidth, vRootHeight; int result; - if (index >= (int)menuPtr->numEntries) { + if (index >= (int) menuPtr->numEntries) { index = menuPtr->numEntries - 1; } if (index >= 0) { @@ -960,12 +969,12 @@ TkpSetWindowMenuBar( * * TkpSetMainMenubar -- * - * Puts the menu associated with a window into the menubar. Should only - * be called when the window is in front. + * Puts the menu associated with a window into the menubar. Should only be + * called when the window is in front. * * This is a no-op on all other platforms. On OS X it is a no-op when - * passed a NULL menuName or a nonexistent menuName, with an exception - * for the first call in a new interpreter. In that special case, passing a + * passed a NULL menuName or a nonexistent menuName, with an exception for + * the first call in a new interpreter. In that special case, passing a * NULL menuName installs the default menu. * * Results: @@ -993,19 +1002,21 @@ TkpSetMainMenubar( */ if (Tk_IsEmbedded(winPtr)) { - return; - } + return; + } if (menuName) { Tk_Window menubar = NULL; + if (winPtr->wmInfoPtr && - winPtr->wmInfoPtr->menuPtr && - winPtr->wmInfoPtr->menuPtr->masterMenuPtr) { + winPtr->wmInfoPtr->menuPtr && + winPtr->wmInfoPtr->menuPtr->masterMenuPtr) { menubar = winPtr->wmInfoPtr->menuPtr->masterMenuPtr->tkwin; } /* - * Attempt to find the NSMenu directly. If that fails, ask Tk to find it. + * Attempt to find the NSMenu directly. If that fails, ask Tk to find + * it. */ if (menubar != NULL && strcmp(menuName, Tk_PathName(menubar)) == 0) { @@ -1013,6 +1024,7 @@ TkpSetMainMenubar( } else { TkMenuReferences *menuRefPtr = TkFindMenuReferences(interp, menuName); + if (menuRefPtr && menuRefPtr->menuPtr && menuRefPtr->menuPtr->platformData) { menu = (TKMenu *) menuRefPtr->menuPtr->platformData; @@ -1021,9 +1033,8 @@ TkpSetMainMenubar( } /* - * If we couldn't find a menu, do nothing unless the window belongs - * to a different application. In that case, install the default - * menubar. + * If we couldn't find a menu, do nothing unless the window belongs to a + * different application. In that case, install the default menubar. */ if (menu || interp != currentInterp) { @@ -1038,8 +1049,8 @@ TkpSetMainMenubar( * CheckForSpecialMenu -- * * Given a menu, check to see whether or not it is a cascade in a menubar - * with one of the special names ".apple", ".help" or ".window". If it - * is, the entry that points to this menu will be marked. + * with one of the special names ".apple", ".help" or ".window". If it is, + * the entry that points to this menu will be marked. * * Results: * None. @@ -1230,11 +1241,12 @@ TkpComputeStandardMenuGeometry( /* * Do nothing if this menu is a clone. */ + if (menuPtr->tkwin == NULL || menuPtr->masterMenuPtr != menuPtr) { return; } - menuSize = [(NSMenu *)menuPtr->platformData size]; + menuSize = [(NSMenu *) menuPtr->platformData size]; Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr, &borderWidth); Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->activeBorderWidthPtr, @@ -1248,16 +1260,16 @@ TkpComputeStandardMenuGeometry( * want to do it intelligently. We are going to precalculate them and pass * them down to all of the measuring and drawing routines. We will measure * the font metrics of the menu once. If an entry does not have its own - * font set, then we give the geometry/drawing routines the menu's font - * and metrics. If an entry has its own font, we will measure that font - * and give all of the geometry/drawing the entry's font and metrics. + * font set, then we give the geometry/drawing routines the menu's font and + * metrics. If an entry has its own font, we will measure that font and + * give all of the geometry/drawing the entry's font and metrics. */ menuFont = Tk_GetFontFromObj(menuPtr->tkwin, menuPtr->fontPtr); Tk_GetFontMetrics(menuFont, &menuMetrics); menuModifierCharWidth = ModifierCharWidth(menuFont); - for (i = 0; i < (int)menuPtr->numEntries; i++) { + for (i = 0; i < (int) menuPtr->numEntries; i++) { mePtr = menuPtr->entries[i]; if (mePtr->type == CASCADE_ENTRY || mePtr->accelLength > 0) { haveAccel = 1; @@ -1265,7 +1277,7 @@ TkpComputeStandardMenuGeometry( } } - for (i = 0; i < (int)menuPtr->numEntries; i++) { + for (i = 0; i < (int) menuPtr->numEntries; i++) { mePtr = menuPtr->entries[i]; if (mePtr->type == TEAROFF_ENTRY) { continue; @@ -1295,6 +1307,7 @@ TkpComputeStandardMenuGeometry( NSMenuItem *menuItem = (NSMenuItem *) mePtr->platformEntryData; int haveImage = 0, width = 0, height = 0; + if (mePtr->image) { Tk_SizeOfImage(mePtr->image, &width, &height); haveImage = 1; @@ -1302,6 +1315,7 @@ TkpComputeStandardMenuGeometry( } else if (mePtr->bitmapPtr) { Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr); + Tk_SizeOfBitmap(menuPtr->display, bitmap, &width, &height); haveImage = 1; height += 2; /* tweak */ @@ -1413,7 +1427,7 @@ GenerateMenuSelectEvent( if (menuPtr) { int index = [menu tkIndexOfItem:menuItem]; - if (index < 0 || index >= (int)menuPtr->numEntries || + if (index < 0 || index >= (int) menuPtr->numEntries || (menuPtr->entries[index])->state == ENTRY_DISABLED) { TkActivateMenuEntry(menuPtr, -1); } else { @@ -1492,7 +1506,7 @@ RecursivelyClearActiveMenu( int i; TkActivateMenuEntry(menuPtr, -1); - for (i = 0; i < (int)menuPtr->numEntries; i++) { + for (i = 0; i < (int) menuPtr->numEntries; i++) { TkMenuEntry *mePtr = menuPtr->entries[i]; if (mePtr->type == CASCADE_ENTRY @@ -1781,7 +1795,7 @@ TkMacOSXPreprocessMenu(void) * TkMacOSXUseID -- * * Take the ID out of the available list for new menus. Used by the - * default menu bar's menus so that they do not get created at the tk + * default menu bar's menus so that they do not get created at the Tk * level. See TkMacOSXGetNewMenuID for more information. * * Results: @@ -1806,8 +1820,7 @@ TkMacOSXUseMenuID( * * TkMacOSXDispatchMenuEvent -- * - * Given a menu id and an item, dispatches the command associated with - * it. + * Given a menu id and an item, dispatches the command associated with it. * * Results: * None. @@ -1857,9 +1870,10 @@ TkMacOSXHandleTearoffMenu(void) * * TkMacOSXSetHelpMenuItemCount -- * - * Has to be called after the first call to InsertMenu. Sets up the - * global variable for the number of items in the unmodified help menu. - * NB. Nobody uses this any more, since you can get the number of system + * Has to be called after the first call to InsertMenu. Sets up the global + * variable for the number of items in the unmodified help menu. + * + * NB: Nobody uses this any more, since you can get the number of system * help items from HMGetHelpMenu trivially. But it is in the stubs * table... * diff --git a/macosx/tkMacOSXMenubutton.c b/macosx/tkMacOSXMenubutton.c index b2b4b76..33ae213 100644 --- a/macosx/tkMacOSXMenubutton.c +++ b/macosx/tkMacOSXMenubutton.c @@ -1,8 +1,8 @@ /* * tkMacOSXMenubutton.c -- * - * This file implements the Macintosh specific portion of the - * menubutton widget. + * This file implements the Macintosh specific portion of the menubutton + * widget. * * Copyright (c) 1996 by Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. @@ -32,7 +32,6 @@ typedef struct { int hasImageOrBitmap; } DrawParams; - /* * Declaration of Mac specific button structure. */ @@ -50,21 +49,24 @@ typedef struct MacMenuButton { * Forward declarations for static functions defined later in this file: */ -static void MenuButtonEventProc(ClientData clientData, XEvent *eventPtr); -static void MenuButtonBackgroundDrawCB (MacMenuButton *ptr, SInt16 depth, - Boolean isColorDev); -static void MenuButtonContentDrawCB (ThemeButtonKind kind, - const HIThemeButtonDrawInfo * info, - MacMenuButton *ptr, SInt16 depth, - Boolean isColorDev); -static void MenuButtonEventProc ( ClientData clientData, XEvent *eventPtr); -static void TkMacOSXComputeMenuButtonParams (TkMenuButton * butPtr, - ThemeButtonKind* btnkind, - HIThemeButtonDrawInfo* drawinfo); -static void TkMacOSXComputeMenuButtonDrawParams (TkMenuButton * butPtr, - DrawParams * dpPtr); -static void TkMacOSXDrawMenuButton (MacMenuButton *butPtr, GC gc, Pixmap pixmap); -static void DrawMenuButtonImageAndText(TkMenuButton* butPtr); +static void MenuButtonEventProc(ClientData clientData, + XEvent *eventPtr); +static void MenuButtonBackgroundDrawCB(MacMenuButton *ptr, + SInt16 depth, Boolean isColorDev); +static void MenuButtonContentDrawCB(ThemeButtonKind kind, + const HIThemeButtonDrawInfo *info, + MacMenuButton *ptr, SInt16 depth, + Boolean isColorDev); +static void MenuButtonEventProc(ClientData clientData, + XEvent *eventPtr); +static void TkMacOSXComputeMenuButtonParams(TkMenuButton *butPtr, + ThemeButtonKind *btnkind, + HIThemeButtonDrawInfo *drawinfo); +static void TkMacOSXComputeMenuButtonDrawParams( + TkMenuButton *butPtr, DrawParams *dpPtr); +static void TkMacOSXDrawMenuButton(MacMenuButton *butPtr, GC gc, + Pixmap pixmap); +static void DrawMenuButtonImageAndText(TkMenuButton *butPtr); /* * The structure below defines menubutton class behavior by means of @@ -133,8 +135,7 @@ TkpCreateMenuButton( { MacMenuButton *mbPtr = (MacMenuButton *) ckalloc(sizeof(MacMenuButton)); - Tk_CreateEventHandler(tkwin, ActivateMask, MenuButtonEventProc, - (ClientData) mbPtr); + Tk_CreateEventHandler(tkwin, ActivateMask, MenuButtonEventProc, mbPtr); mbPtr->flags = FIRST_DRAW; mbPtr->btnkind = kThemePopupButton; bzero(&mbPtr->drawinfo, sizeof(mbPtr->drawinfo)); @@ -153,8 +154,7 @@ TkpCreateMenuButton( * None. * * Side effects: - * Commands are output to X to display the menubutton in its - * current mode. + * Commands are output to X to display the menubutton in its current mode. * *---------------------------------------------------------------------- */ @@ -163,11 +163,11 @@ void TkpDisplayMenuButton( ClientData clientData) /* Information about widget. */ { - MacMenuButton *mbPtr = (MacMenuButton *)clientData; - TkMenuButton *butPtr = (TkMenuButton *) clientData; - Tk_Window tkwin = butPtr->tkwin; + MacMenuButton *mbPtr = clientData; + TkMenuButton *butPtr = clientData; + Tk_Window tkwin = butPtr->tkwin; Pixmap pixmap; - DrawParams* dpPtr = &mbPtr->drawParams; + DrawParams *dpPtr = &mbPtr->drawParams; butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { @@ -179,22 +179,26 @@ TkpDisplayMenuButton( TkMacOSXComputeMenuButtonDrawParams(butPtr, dpPtr); /* - * set up clipping region. Make sure the we are using the port - * for this button, or we will set the wrong window's clip. + * Set up clipping region. Make sure the we are using the port for this + * button, or we will set the wrong window's clip. */ TkMacOSXSetUpClippingRgn(pixmap); - /* Draw the native portion of the buttons. */ + /* + * Draw the native portion of the buttons. + */ + TkMacOSXDrawMenuButton(mbPtr, dpPtr->gc, pixmap); - /* Draw highlight border, if needed. */ - if (butPtr->highlightWidth < 3) { - if ((butPtr->flags & GOT_FOCUS)) { - Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, + /* + * Draw highlight border, if needed. + */ + + if ((butPtr->highlightWidth < 3) && (butPtr->flags & GOT_FOCUS)) { + Tk_Draw3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), butPtr->highlightWidth, TK_RELIEF_SOLID); - } } } @@ -203,8 +207,8 @@ TkpDisplayMenuButton( * * TkpDestroyMenuButton -- * - * Free data structures associated with the menubutton control. - * This is a no-op on the Mac. + * Free data structures associated with the menubutton control. This is a + * no-op on the Mac. * * Results: * None. @@ -279,44 +283,42 @@ TkpComputeMenuButtonGeometry(butPtr) } /* - * If the button is compound (ie, it shows both an image and text), - * the new geometry is a combination of the image and text geometry. - * We only honor the compound bit if the button has both text and an - * image, because otherwise it is not really a compound button. + * If the button is compound (ie, it shows both an image and text), the new + * geometry is a combination of the image and text geometry. We only honor + * the compound bit if the button has both text and an image, because + * otherwise it is not really a compound button. */ if (haveImage && haveText) { switch ((enum compound) butPtr->compound) { - case COMPOUND_TOP: - case COMPOUND_BOTTOM: { - /* - * Image is above or below text - */ - - height += txtHeight + butPtr->padY; - width = (width > txtWidth ? width : txtWidth); - break; - } - case COMPOUND_LEFT: - case COMPOUND_RIGHT: { - /* - * Image is left or right of text - */ - - width += txtWidth + butPtr->padX; - height = (height > txtHeight ? height : txtHeight); - break; - } - case COMPOUND_CENTER: { - /* - * Image and text are superimposed - */ - - width = (width > txtWidth ? width : txtWidth); - height = (height > txtHeight ? height : txtHeight); - break; - } - case COMPOUND_NONE: {break;} + case COMPOUND_TOP: + case COMPOUND_BOTTOM: + /* + * Image is above or below text + */ + + height += txtHeight + butPtr->padY; + width = (width > txtWidth ? width : txtWidth); + break; + case COMPOUND_LEFT: + case COMPOUND_RIGHT: + /* + * Image is left or right of text + */ + + width += txtWidth + butPtr->padX; + height = (height > txtHeight ? height : txtHeight); + break; + case COMPOUND_CENTER: + /* + * Image and text are superimposed + */ + + width = (width > txtWidth ? width : txtWidth); + height = (height > txtHeight ? height : txtHeight); + break; + case COMPOUND_NONE: + break; } if (butPtr->width > 0) { @@ -371,32 +373,24 @@ TkpComputeMenuButtonGeometry(butPtr) */ void DrawMenuButtonImageAndText( - TkMenuButton* butPtr) + TkMenuButton *butPtr) { - MacMenuButton *mbPtr = (MacMenuButton*)butPtr; - Tk_Window tkwin = butPtr->tkwin; - Pixmap pixmap; - int haveImage = 0; - int haveText = 0; - int imageWidth = 0; - int imageHeight = 0; - int imageXOffset = 0; - int imageYOffset = 0; - int textXOffset = 0; - int textYOffset = 0; - int width = 0; - int height = 0; - int fullWidth = 0; - int fullHeight = 0; - int pressed; + MacMenuButton *mbPtr = (MacMenuButton *) butPtr; + Tk_Window tkwin = butPtr->tkwin; + Pixmap pixmap; + int haveImage = 0, haveText = 0; + int imageWidth = 0, imageHeight = 0; + int imageXOffset = 0, imageYOffset = 0; + int textXOffset = 0, textYOffset = 0; + int width = 0, height = 0; + int fullWidth = 0, fullHeight = 0; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; } - DrawParams* dpPtr = &mbPtr->drawParams; - pixmap = (Pixmap)Tk_WindowId(tkwin); - + DrawParams *dpPtr = &mbPtr->drawParams; + pixmap = (Pixmap) Tk_WindowId(tkwin); if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); @@ -406,86 +400,80 @@ DrawMenuButtonImageAndText( haveImage = 1; } - imageWidth = width; + imageWidth = width; imageHeight = height; - if (mbPtr->drawinfo.state == kThemeStatePressed) { - /* Offset bitmaps by a bit when the button is pressed. */ - pressed = 1; - } - haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { - int x = 0; - int y = 0; + int x = 0, y = 0; + textXOffset = 0; textYOffset = 0; fullWidth = 0; fullHeight = 0; switch ((enum compound) butPtr->compound) { - case COMPOUND_TOP: - case COMPOUND_BOTTOM: { - /* Image is above or below text */ - if (butPtr->compound == COMPOUND_TOP) { - textYOffset = height + butPtr->padY; - } else { - imageYOffset = butPtr->textHeight + butPtr->padY; - } - fullHeight = height + butPtr->textHeight + butPtr->padY; - fullWidth = (width > butPtr->textWidth ? - width : butPtr->textWidth); - textXOffset = (fullWidth - butPtr->textWidth)/2; - imageXOffset = (fullWidth - width)/2; - break; - } - case COMPOUND_LEFT: - case COMPOUND_RIGHT: { - /* - * Image is left or right of text - */ - - if (butPtr->compound == COMPOUND_LEFT) { - textXOffset = width + butPtr->padX - 2; - } else { - imageXOffset = butPtr->textWidth + butPtr->padX; - } - fullWidth = butPtr->textWidth + butPtr->padX + width; - fullHeight = (height > butPtr->textHeight ? height : - butPtr->textHeight); - textYOffset = (fullHeight - butPtr->textHeight)/2; - imageYOffset = (fullHeight - height)/2; - break; - } - case COMPOUND_CENTER: { - /* - * Image and text are superimposed - */ - - fullWidth = (width > butPtr->textWidth ? width : - butPtr->textWidth); - fullHeight = (height > butPtr->textHeight ? height : - butPtr->textHeight); - textXOffset = (fullWidth - butPtr->textWidth)/2; - imageXOffset = (fullWidth - width)/2; - textYOffset = (fullHeight - butPtr->textHeight)/2; - imageYOffset = (fullHeight - height)/2; - break; - } - case COMPOUND_NONE: {break;} + case COMPOUND_TOP: + case COMPOUND_BOTTOM: + /* + * Image is above or below text. + */ + + if (butPtr->compound == COMPOUND_TOP) { + textYOffset = height + butPtr->padY; + } else { + imageYOffset = butPtr->textHeight + butPtr->padY; + } + fullHeight = height + butPtr->textHeight + butPtr->padY; + fullWidth = (width > butPtr->textWidth ? + width : butPtr->textWidth); + textXOffset = (fullWidth - butPtr->textWidth)/2; + imageXOffset = (fullWidth - width)/2; + break; + case COMPOUND_LEFT: + case COMPOUND_RIGHT: + /* + * Image is left or right of text + */ + + if (butPtr->compound == COMPOUND_LEFT) { + textXOffset = width + butPtr->padX - 2; + } else { + imageXOffset = butPtr->textWidth + butPtr->padX; + } + fullWidth = butPtr->textWidth + butPtr->padX + width; + fullHeight = (height > butPtr->textHeight ? height : + butPtr->textHeight); + textYOffset = (fullHeight - butPtr->textHeight)/2; + imageYOffset = (fullHeight - height)/2; + break; + case COMPOUND_CENTER: + /* + * Image and text are superimposed + */ + + fullWidth = (width > butPtr->textWidth ? width : butPtr->textWidth); + fullHeight = (height > butPtr->textHeight ? height : + butPtr->textHeight); + textXOffset = (fullWidth - butPtr->textWidth) / 2; + imageXOffset = (fullWidth - width) / 2; + textYOffset = (fullHeight - butPtr->textHeight) / 2; + imageYOffset = (fullHeight - height) / 2; + break; + case COMPOUND_NONE: + break; } TkComputeAnchor(butPtr->anchor, tkwin, - butPtr->padX + butPtr->inset, - butPtr->padY + butPtr->inset, + butPtr->padX + butPtr->inset, butPtr->padY + butPtr->inset, fullWidth, fullHeight, &x, &y); imageXOffset = LEFT_INSET; imageYOffset += y; textYOffset -= 1; if (butPtr->image != NULL) { - Tk_RedrawImage(butPtr->image, 0, 0, width, - height, pixmap, imageXOffset, imageYOffset); + Tk_RedrawImage(butPtr->image, 0, 0, width, + height, pixmap, imageXOffset, imageYOffset); } else { XSetClipOrigin(butPtr->display, dpPtr->gc, imageXOffset, imageYOffset); @@ -499,12 +487,12 @@ DrawMenuButtonImageAndText( dpPtr->gc, butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc, - butPtr->textLayout, - x + textXOffset, y + textYOffset, + butPtr->textLayout, x + textXOffset, y + textYOffset, butPtr->underline); } else { + int x, y; + if (haveImage) { - int x, y; TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX + butPtr->borderWidth, butPtr->padY + butPtr->borderWidth, @@ -524,27 +512,24 @@ DrawMenuButtonImageAndText( XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); } } else { - int x, y; textXOffset = LEFT_INSET; TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, - butPtr->textWidth, butPtr->textHeight, &x, &y); + butPtr->textWidth, butPtr->textHeight, &x, &y); Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, - butPtr->textLayout, textXOffset, y, 0, -1); + butPtr->textLayout, textXOffset, y, 0, -1); y += butPtr->textHeight/2; - } + } } } - - - + /* *-------------------------------------------------------------- * * TkMacOSXDrawMenuButton -- * - * This function draws the tk menubutton using Mac controls - * In addition, this code may apply custom colors passed - * in the TkMenubutton. + * This function draws the tk menubutton using Mac controls. In + * addition, this code may apply custom colors passed in the + * TkMenubutton. * * Results: * None. @@ -554,43 +539,39 @@ DrawMenuButtonImageAndText( * *-------------------------------------------------------------- */ + static void TkMacOSXDrawMenuButton( MacMenuButton *mbPtr, /* Mac menubutton. */ - GC gc, /* The GC we are drawing into - needed for - * the bevel button */ - Pixmap pixmap) /* The pixmap we are drawing into - needed - * for the bevel button */ + GC gc, /* The GC we are drawing into - needed for the bevel + * button */ + Pixmap pixmap) /* The pixmap we are drawing into - needed for the + * bevel button */ { - TkMenuButton * butPtr = ( TkMenuButton *)mbPtr; - TkWindow * winPtr; - HIRect cntrRect; + TkMenuButton *butPtr = (TkMenuButton *) mbPtr; + TkWindow *winPtr = (TkWindow *) butPtr->tkwin; + HIRect cntrRect; TkMacOSXDrawingContext dc; - DrawParams* dpPtr = &mbPtr->drawParams; + DrawParams *dpPtr = &mbPtr->drawParams; int useNewerHITools = 1; - winPtr = (TkWindow *)butPtr->tkwin; - TkMacOSXComputeMenuButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo); cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff, - Tk_Width(butPtr->tkwin), - Tk_Height(butPtr->tkwin)); + Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin)); if (useNewerHITools == 1) { HIRect contHIRec; static HIThemeButtonDrawInfo hiinfo; - MenuButtonBackgroundDrawCB((MacMenuButton*) mbPtr, 32, true); - + MenuButtonBackgroundDrawCB(mbPtr, 32, true); if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) { return; } - hiinfo.version = 0; hiinfo.state = mbPtr->drawinfo.state; - hiinfo.kind = mbPtr->btnkind; + hiinfo.kind = mbPtr->btnkind; hiinfo.value = mbPtr->drawinfo.value; hiinfo.adornment = mbPtr->drawinfo.adornment; hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent(); @@ -599,10 +580,10 @@ TkMacOSXDrawMenuButton( } HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, - kHIThemeOrientationNormal, &contHIRec); + kHIThemeOrientationNormal, &contHIRec); TkMacOSXRestoreDrawingContext(&dc); - MenuButtonContentDrawCB( mbPtr->btnkind, &mbPtr->drawinfo, - (MacMenuButton *)mbPtr, 32, true); + MenuButtonContentDrawCB(mbPtr->btnkind, &mbPtr->drawinfo, + mbPtr, 32, true); } else { if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) { return; @@ -617,33 +598,34 @@ TkMacOSXDrawMenuButton( * * MenuButtonBackgroundDrawCB -- * - * This function draws the background that - * lies under checkboxes and radiobuttons. + * This function draws the background that lies under checkboxes and + * radiobuttons. * * Results: - * None. + * None. * * Side effects: - * The background gets updated to the current color. + * The background gets updated to the current color. * *-------------------------------------------------------------- */ + static void MenuButtonBackgroundDrawCB ( MacMenuButton *ptr, SInt16 depth, Boolean isColorDev) { - TkMenuButton* butPtr = (TkMenuButton*)ptr; - Tk_Window tkwin = butPtr->tkwin; + TkMenuButton* butPtr = (TkMenuButton *) ptr; + Tk_Window tkwin = butPtr->tkwin; Pixmap pixmap; + if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; } - pixmap = (Pixmap)Tk_WindowId(tkwin); - + pixmap = (Pixmap) Tk_WindowId(tkwin); Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, - Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); + Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); } /* @@ -651,16 +633,17 @@ MenuButtonBackgroundDrawCB ( * * MenuButtonContentDrawCB -- * - * This function draws the label and image for the button. + * This function draws the label and image for the button. * * Results: - * None. + * None. * * Side effects: - * The content of the button gets updated. + * The content of the button gets updated. * *-------------------------------------------------------------- */ + static void MenuButtonContentDrawCB ( ThemeButtonKind kind, @@ -669,8 +652,8 @@ MenuButtonContentDrawCB ( SInt16 depth, Boolean isColorDev) { - TkMenuButton *butPtr = (TkMenuButton *)ptr; - Tk_Window tkwin = butPtr->tkwin; + TkMenuButton *butPtr = (TkMenuButton *) ptr; + Tk_Window tkwin = butPtr->tkwin; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { return; @@ -683,8 +666,8 @@ MenuButtonContentDrawCB ( * * MenuButtonEventProc -- * - * This procedure is invoked by the Tk dispatcher for various - * events on buttons. + * This procedure is invoked by the Tk dispatcher for various events on + * buttons. * * Results: * None. @@ -700,8 +683,8 @@ MenuButtonEventProc( ClientData clientData, /* Information about window. */ XEvent *eventPtr) /* Information about event. */ { - TkMenuButton *buttonPtr = (TkMenuButton *) clientData; - MacMenuButton *mbPtr = (MacMenuButton *) clientData; + TkMenuButton *buttonPtr = clientData; + MacMenuButton *mbPtr = clientData; if (eventPtr->type == ActivateNotify || eventPtr->type == DeactivateNotify) { @@ -725,9 +708,9 @@ MenuButtonEventProc( * * TkMacOSXComputeMenuButtonParams -- * - * This procedure computes the various parameters used - * when creating a Carbon Appearance control. - * These are determined by the various tk button parameters + * This procedure computes the various parameters used when creating a + * Carbon Appearance control. These are determined by the various Tk + * button parameters * * Results: * None. @@ -740,11 +723,11 @@ MenuButtonEventProc( static void TkMacOSXComputeMenuButtonParams( - TkMenuButton * butPtr, - ThemeButtonKind* btnkind, + TkMenuButton *butPtr, + ThemeButtonKind *btnkind, HIThemeButtonDrawInfo *drawinfo) { - MacMenuButton *mbPtr = (MacMenuButton *)butPtr; + MacMenuButton *mbPtr = (MacMenuButton *) butPtr; if (butPtr->image || butPtr->bitmap || butPtr->text) { /* TODO: allow for Small and Mini menubuttons. */ @@ -789,25 +772,25 @@ TkMacOSXComputeMenuButtonParams( * * TkMacOSXComputeMenuButtonDrawParams -- * - * This procedure selects an appropriate drawing context for - * drawing a menubutton. + * This procedure selects an appropriate drawing context for drawing a + * menubutton. * * Results: - * None. + * None. * * Side effects: - * Sets the button draw parameters. + * Sets the button draw parameters. * *---------------------------------------------------------------------- */ static void TkMacOSXComputeMenuButtonDrawParams( - TkMenuButton * butPtr, - DrawParams * dpPtr) + TkMenuButton *butPtr, + DrawParams *dpPtr) { - dpPtr->hasImageOrBitmap = ((butPtr->image != NULL) || - (butPtr->bitmap != None)); + dpPtr->hasImageOrBitmap = + ((butPtr->image != NULL) || (butPtr->bitmap != None)); dpPtr->border = butPtr->normalBorder; if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) { dpPtr->gc = butPtr->disabledGC; @@ -818,7 +801,7 @@ TkMacOSXComputeMenuButtonDrawParams( dpPtr->gc = butPtr->normalTextGC; } } - + /* * Local Variables: * mode: objc diff --git a/macosx/tkMacOSXMenus.c b/macosx/tkMacOSXMenus.c index 32d807e..bc66a10 100644 --- a/macosx/tkMacOSXMenus.c +++ b/macosx/tkMacOSXMenus.c @@ -177,7 +177,6 @@ static Tcl_Obj * GetWidgetDemoPath(Tcl_Interp *interp); SEL action = [anItem action]; if (sel_isEqual(action, @selector(preferences:))) { - return (_eventInterp && Tcl_FindCommand(_eventInterp, "::tk::mac::ShowPreferences", NULL, 0)); } else if (sel_isEqual(action, @selector(tkDemo:))) { diff --git a/macosx/tkMacOSXNotify.c b/macosx/tkMacOSXNotify.c index 3a32527..7267b00 100644 --- a/macosx/tkMacOSXNotify.c +++ b/macosx/tkMacOSXNotify.c @@ -33,7 +33,7 @@ static void TkMacOSXEventsSetupProc(ClientData clientData, int flags); static void TkMacOSXEventsCheckProc(ClientData clientData, int flags); #ifdef TK_MAC_DEBUG_EVENTS -static char* Tk_EventName[39] = { +static const char *Tk_EventName[39] = { "", "", "KeyPress", /*2*/ @@ -136,8 +136,8 @@ void DebugPrintQueue(void) /* * Since the contentView is the first responder for a Tk Window, it is - * responsible for sending events up the responder chain. We also check - * the pasteboard here. + * responsible for sending events up the responder chain. We also check the + * pasteboard here. */ - (void) sendEvent: (NSEvent *) theEvent { @@ -190,8 +190,8 @@ GetRunLoopMode(NSModalSession modalSession) * * Tk_MacOSXSetupTkNotifier -- * - * This procedure is called during Tk initialization to create - * the event source for TkAqua events. + * This procedure is called during Tk initialization to create the event + * source for TkAqua events. * * Results: * None. @@ -224,8 +224,7 @@ Tk_MacOSXSetupTkNotifier(void) "first [load] of TkAqua has to occur in the main thread!"); } Tcl_CreateEventSource(TkMacOSXEventsSetupProc, - TkMacOSXEventsCheckProc, - NULL); + TkMacOSXEventsCheckProc, NULL); TkCreateExitHandler(TkMacOSXNotifyExitHandler, NULL); Tcl_SetServiceMode(TCL_SERVICE_ALL); TclMacOSXNotifierAddRunLoopMode(NSEventTrackingRunLoopMode); @@ -258,8 +257,7 @@ TkMacOSXNotifyExitHandler( TSD_INIT(); Tcl_DeleteEventSource(TkMacOSXEventsSetupProc, - TkMacOSXEventsCheckProc, - NULL); + TkMacOSXEventsCheckProc, NULL); tsdPtr->initialized = 0; } @@ -268,19 +266,19 @@ TkMacOSXNotifyExitHandler( * * TkMacOSXEventsSetupProc -- * - * This procedure implements the setup part of the MacOSX event - * source. It is invoked by Tcl_DoOneEvent before calling - * TkMacOSXEventsProc to process all queued NSEvents. In our - * case, all we need to do is to set the Tcl MaxBlockTime to - * 0 before starting the loop to process all queued NSEvents. + * This procedure implements the setup part of the MacOSX event source. It + * is invoked by Tcl_DoOneEvent before calling TkMacOSXEventsProc to + * process all queued NSEvents. In our case, all we need to do is to set + * the Tcl MaxBlockTime to 0 before starting the loop to process all + * queued NSEvents. * * Results: * None. * * Side effects: * - * If NSEvents are queued, then the maximum block time will be set - * to 0 to ensure that control returns immediately to Tcl. + * If NSEvents are queued, then the maximum block time will be set to 0 to + * ensure that control returns immediately to Tcl. * *---------------------------------------------------------------------- */ @@ -291,15 +289,24 @@ TkMacOSXEventsSetupProc( int flags) { NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode]; - /* runloopMode will be nil if we are in a Tcl event loop. */ + + /* + * runloopMode will be nil if we are in a Tcl event loop. + */ + if (flags & TCL_WINDOW_EVENTS && !runloopMode) { static const Tcl_Time zeroBlockTime = { 0, 0 }; [NSApp _resetAutoreleasePool]; - /* Call this with dequeue=NO -- just checking if the queue is empty. */ - NSEvent *currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:GetRunLoopMode(TkMacOSXGetModalSession()) - dequeue:NO]; + + /* + * Call this with dequeue=NO -- just checking if the queue is empty. + */ + + NSEvent *currentEvent = + [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] + inMode:GetRunLoopMode(TkMacOSXGetModalSession()) + dequeue:NO]; if (currentEvent) { if (currentEvent.type > 0) { Tcl_SetMaxBlockTime(&zeroBlockTime); @@ -313,15 +320,15 @@ TkMacOSXEventsSetupProc( * * TkMacOSXEventsCheckProc -- * - * This procedure loops through all NSEvents waiting in the - * TKApplication event queue, generating X events from them. + * This procedure loops through all NSEvents waiting in the TKApplication + * event queue, generating X events from them. * * Results: * None. * * Side effects: - * NSevents are used to generate X events, which are added to the - * Tcl event queue. + * NSevents are used to generate X events, which are added to the Tcl + * event queue. * *---------------------------------------------------------------------- */ @@ -331,34 +338,48 @@ TkMacOSXEventsCheckProc( int flags) { NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode]; - /* runloopMode will be nil if we are in a Tcl event loop. */ + + /* + * runloopMode will be nil if we are in a Tcl event loop. + */ + if (flags & TCL_WINDOW_EVENTS && !runloopMode) { NSEvent *currentEvent = nil; NSEvent *testEvent = nil; NSModalSession modalSession; - /* It is possible for the SetupProc to be called before this function + + /* + * It is possible for the SetupProc to be called before this function * returns. This happens, for example, when we process an event which * opens a modal window. To prevent premature release of our * application-wide autorelease pool by a nested call to the SetupProc, * we must lock it here. */ + [NSApp _lockAutoreleasePool]; do { modalSession = TkMacOSXGetModalSession(); - testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:GetRunLoopMode(modalSession) - dequeue:NO]; - /* We must not steal any events during LiveResize. */ + testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] + inMode:GetRunLoopMode(modalSession) + dequeue:NO]; + + /* + * We must not steal any events during LiveResize. + */ + if (testEvent && [[testEvent window] inLiveResize]) { break; } currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:GetRunLoopMode(modalSession) - dequeue:YES]; + untilDate:[NSDate distantPast] + inMode:GetRunLoopMode(modalSession) + dequeue:YES]; if (currentEvent) { - /* Generate Xevents. */ + /* + * Generate Xevents. + */ + int oldServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); NSEvent *processedEvent = [NSApp tkProcessEvent:currentEvent]; Tcl_SetServiceMode(oldServiceMode); @@ -372,16 +393,18 @@ TkMacOSXEventsCheckProc( [NSApp sendEvent:currentEvent]; } } - } else { break; } } while (1); - /* Now we can unlock the pool. */ + + /* + * Now we can unlock the pool. + */ + [NSApp _unlockAutoreleasePool]; } } - /* * Local Variables: diff --git a/macosx/tkMacOSXRegion.c b/macosx/tkMacOSXRegion.c index 0f2a74a..323318c 100644 --- a/macosx/tkMacOSXRegion.c +++ b/macosx/tkMacOSXRegion.c @@ -187,8 +187,8 @@ TkMacOSXIsEmptyRegion( * Xwindow documentation for more details. * * Results: - * Returns RectanglePart or RectangleOut. Note that this is not a - * complete implementation since it doesn't test for RectangleIn. + * Returns RectanglePart or RectangleOut. Note that this is not a complete + * implementation since it doesn't test for RectangleIn. * * Side effects: * None. @@ -204,13 +204,13 @@ TkRectInRegion( unsigned int width, unsigned int height) { - if ( TkMacOSXIsEmptyRegion(region) ) { - return RectangleOut; - } - else { + if (TkMacOSXIsEmptyRegion(region)) { + return RectangleOut; + } else { const CGRect r = CGRectMake(x, y, width, height); + return HIShapeIntersectsRect((HIShapeRef) region, &r) ? - RectanglePart : RectangleOut; + RectanglePart : RectangleOut; } } @@ -234,7 +234,7 @@ TkRectInRegion( void TkClipBox( TkRegion r, - XRectangle* rect_return) + XRectangle *rect_return) { CGRect rect; diff --git a/macosx/tkMacOSXScale.c b/macosx/tkMacOSXScale.c index 8a6a96b..0195ffb 100644 --- a/macosx/tkMacOSXScale.c +++ b/macosx/tkMacOSXScale.c @@ -51,10 +51,10 @@ static ControlActionUPP scaleActionProc = NULL; /* Pointer to func. */ * Forward declarations for procedures defined later in this file: */ -static void MacScaleEventProc(ClientData clientData, XEvent *eventPtr); -static pascal void ScaleActionProc(ControlRef theControl, - ControlPartCode partCode); - +static void MacScaleEventProc(ClientData clientData, + XEvent *eventPtr); +static pascal void ScaleActionProc(ControlRef theControl, + ControlPartCode partCode); /* *---------------------------------------------------------------------- @@ -84,7 +84,7 @@ TkpCreateScale( } Tk_CreateEventHandler(tkwin, ButtonPressMask, - MacScaleEventProc, (ClientData) macScalePtr); + MacScaleEventProc, macScalePtr); return (TkScale *) macScalePtr; } @@ -125,8 +125,8 @@ TkpDestroyScale( * * TkpDisplayScale -- * - * This procedure is invoked as an idle handler to redisplay - * the contents of a scale widget. + * This procedure is invoked as an idle handler to redisplay the contents + * of a scale widget. * * Results: * None. @@ -141,12 +141,12 @@ void TkpDisplayScale( ClientData clientData) /* Widget record for scale. */ { - TkScale *scalePtr = (TkScale *) clientData; + TkScale *scalePtr = clientData; Tk_Window tkwin = scalePtr->tkwin; Tcl_Interp *interp = scalePtr->interp; int result; char string[TCL_DOUBLE_SPACE]; - MacScale *macScalePtr = (MacScale *) clientData; + MacScale *macScalePtr = clientData; Rect r; WindowRef windowRef; CGrafPtr destPort, savePort; @@ -168,9 +168,9 @@ TkpDisplayScale( * Invoke the scale's command if needed. */ - Tcl_Preserve((ClientData) scalePtr); + Tcl_Preserve(scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { - Tcl_Preserve((ClientData) interp); + Tcl_Preserve(interp); if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format, scalePtr->value) < 0) { string[TCL_DOUBLE_SPACE - 1] = '\0'; @@ -185,19 +185,18 @@ TkpDisplayScale( Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); Tcl_BackgroundException(interp, result); } - Tcl_Release((ClientData) interp); + Tcl_Release(interp); } scalePtr->flags &= ~INVOKE_COMMAND; if (scalePtr->flags & SCALE_DELETED) { - Tcl_Release((ClientData) scalePtr); + Tcl_Release(scalePtr); return; } - Tcl_Release((ClientData) scalePtr); + Tcl_Release(scalePtr); /* - * Now handle the part of redisplay that is the same for - * horizontal and vertical scales: border and traversal - * highlight. + * Now handle the part of redisplay that is the same for horizontal and + * vertical scales: border and traversal highlight. */ if (scalePtr->highlightWidth != 0) { @@ -229,7 +228,7 @@ TkpDisplayScale( #define MAC_OSX_SCROLL_WIDTH 10 if (scalePtr->orient == ORIENT_HORIZONTAL) { - int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; + int offset = (Tk_Height(tkwin) - MAC_OSX_SCROLL_WIDTH) / 2; if (offset < 0) { offset = 0; @@ -240,7 +239,7 @@ TkpDisplayScale( r.right = macDraw->xOff+Tk_Width(tkwin) - scalePtr->inset; r.bottom = macDraw->yOff + offset + MAC_OSX_SCROLL_WIDTH/2; } else { - int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH)/2; + int offset = (Tk_Width(tkwin) - MAC_OSX_SCROLL_WIDTH) / 2; if (offset < 0) { offset = 0; @@ -249,7 +248,7 @@ TkpDisplayScale( r.left = macDraw->xOff + offset; r.top = macDraw->yOff + scalePtr->inset; r.right = macDraw->xOff + offset + MAC_OSX_SCROLL_WIDTH/2; - r.bottom = macDraw->yOff+Tk_Height(tkwin) - scalePtr->inset; + r.bottom = macDraw->yOff + Tk_Height(tkwin) - scalePtr->inset; } if (macScalePtr->scaleHandle == NULL) { @@ -273,7 +272,7 @@ TkpDisplayScale( CreateSliderControl(windowRef, &r, initialValue, minValue, maxValue, kControlSliderPointsDownOrRight, numTicks, 1, scaleActionProc, - &(macScalePtr->scaleHandle)); + &macScalePtr->scaleHandle); SetControlReference(macScalePtr->scaleHandle, (UInt32) scalePtr); if (IsWindowActive(windowRef)) { @@ -290,8 +289,8 @@ TkpDisplayScale( * Finally draw the control. */ - SetControlVisibility(macScalePtr->scaleHandle,true,true); - HiliteControl(macScalePtr->scaleHandle,0); + SetControlVisibility(macScalePtr->scaleHandle, true, true); + HiliteControl(macScalePtr->scaleHandle, 0); Draw1Control(macScalePtr->scaleHandle); if (portChanged) { @@ -306,13 +305,12 @@ done: * * TkpScaleElement -- * - * Determine which part of a scale widget lies under a given - * point. + * Determine which part of a scale widget lies under a given point. * * Results: - * The return value is either TROUGH1, SLIDER, TROUGH2, or - * OTHER, depending on which of the scale's active elements - * (if any) is under the point at (x,y). + * The return value is either TROUGH1, SLIDER, TROUGH2, or OTHER, + * depending on which of the scale's active elements (if any) is under the + * point at (x,y). * * Side effects: * None. @@ -357,22 +355,22 @@ TkpScaleElement( #endif switch (part) { - case inSlider: - return SLIDER; - case inInc: - if (scalePtr->orient == ORIENT_VERTICAL) { - return TROUGH1; - } else { - return TROUGH2; - } - case inDecr: - if (scalePtr->orient == ORIENT_VERTICAL) { - return TROUGH2; - } else { - return TROUGH1; - } - default: - return OTHER; + case inSlider: + return SLIDER; + case inInc: + if (scalePtr->orient == ORIENT_VERTICAL) { + return TROUGH1; + } else { + return TROUGH2; + } + case inDecr: + if (scalePtr->orient == ORIENT_VERTICAL) { + return TROUGH2; + } else { + return TROUGH1; + } + default: + return OTHER; } } @@ -381,15 +379,15 @@ TkpScaleElement( * * MacScaleEventProc -- * - * This procedure is invoked by the Tk dispatcher for - * ButtonPress events on scales. + * This procedure is invoked by the Tk dispatcher for ButtonPress events + * on scales. * * Results: * None. * * Side effects: - * When the window gets deleted, internal structures get - * cleaned up. When it gets exposed, it is redisplayed. + * When the window gets deleted, internal structures get cleaned up. When + * it gets exposed, it is redisplayed. * *-------------------------------------------------------------- */ @@ -411,9 +409,9 @@ MacScaleEventProc( #endif /* - * To call Macintosh control routines we must have the port - * set to the window containing the control. We will then test - * which part of the control was hit and act accordingly. + * To call Macintosh control routines we must have the port set to the + * window containing the control. We will then test which part of the + * control was hit and act accordingly. */ destPort = TkMacOSXGetDrawablePort(Tk_WindowId(macScalePtr->info.tkwin)); @@ -461,8 +459,8 @@ MacScaleEventProc( * ScaleActionProc -- * * Callback procedure used by the Macintosh toolbox call - * HandleControlClick. This call will update the display - * while the scrollbar is being manipulated by the user. + * HandleControlClick. This call will update the display while the + * scrollbar is being manipulated by the user. * * Results: * None. @@ -486,9 +484,9 @@ ScaleActionProc( #endif value = GetControlValue(theControl); TkScaleSetValue(scalePtr, value, 1, 1); - Tcl_Preserve((ClientData) scalePtr); + Tcl_Preserve(scalePtr); TkMacOSXRunTclEventLoop(); - Tcl_Release((ClientData) scalePtr); + Tcl_Release(scalePtr); } #endif diff --git a/macosx/tkMacOSXScrlbr.c b/macosx/tkMacOSXScrlbr.c index 4a108db..06e0a64 100644 --- a/macosx/tkMacOSXScrlbr.c +++ b/macosx/tkMacOSXScrlbr.c @@ -9,6 +9,7 @@ * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2015 Kevin Walzer/WordTech Commununications LLC. * Copyright (c) 2018 Marc Culler + * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ @@ -17,7 +18,6 @@ #include "tkScrollbar.h" #include "tkMacOSXPrivate.h" - #define MIN_SCROLLBAR_VALUE 0 /* @@ -27,18 +27,21 @@ #define MIN_SLIDER_LENGTH 5 -/*Borrowed from ttkMacOSXTheme.c to provide appropriate scaling.*/ +/* + * Borrowed from ttkMacOSXTheme.c to provide appropriate scaling. + */ + #ifdef __LP64__ -#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum)) +#define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum)) #else -#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum)) +#define RangeToFactor(maximum) (((double) (LONG_MAX >> 1)) / (maximum)) #endif /* __LP64__ */ /* * Apple reversed the scroll direction with the release of OSX 10.7 Lion. */ -#define SNOW_LEOPARD_STYLE (NSAppKitVersionNumber < 1138) +#define SNOW_LEOPARD_STYLE (NSAppKitVersionNumber < 1138) /* * Declaration of an extended scrollbar structure with Mac specific additions. @@ -50,7 +53,7 @@ typedef struct MacScrollbar { GC copyGC; /* Used for copying from pixmap onto screen. */ Bool buttonDown; /* Is the mouse button down? */ Bool mouseOver; /* Is the pointer over the scrollbar. */ - HIThemeTrackDrawInfo info; /* Controls how the scrollbar is drawn. */ + HIThemeTrackDrawInfo info; /* Controls how the scrollbar is drawn. */ } MacScrollbar; /* Used to initialize a MacScrollbar's info field. */ @@ -69,33 +72,35 @@ HIThemeTrackDrawInfo defaultInfo = { const Tk_ClassProcs tkpScrollbarProcs = { sizeof(Tk_ClassProcs), /* size */ - NULL, /* worldChangedProc */ - NULL, /* createProc */ - NULL /* modalProc */ + NULL, /* worldChangedProc */ + NULL, /* createProc */ + NULL /* modalProc */ }; +/* + * Information on scrollbar layout, metrics, and draw info. + */ -/* Information on scrollbar layout, metrics, and draw info.*/ typedef struct ScrollbarMetrics { SInt32 width, minThumbHeight; int minHeight, topArrowHeight, bottomArrowHeight; NSControlSize controlSize; } ScrollbarMetrics; - static ScrollbarMetrics metrics = { - 15, 54, 26, 14, 14, kControlSizeNormal /* kThemeScrollBarMedium */ + 15, 54, 26, 14, 14, kControlSizeNormal /* kThemeScrollBarMedium */ }; - /* * Declarations of static functions defined later in this file: */ -static void ScrollbarEventProc(ClientData clientData, XEvent *eventPtr); -static int ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr); -static void UpdateControlValues(TkScrollbar *scrollPtr); - +static void ScrollbarEventProc(ClientData clientData, + XEvent *eventPtr); +static int ScrollbarEvent(TkScrollbar *scrollPtr, + XEvent *eventPtr); +static void UpdateControlValues(TkScrollbar *scrollPtr); + /* *---------------------------------------------------------------------- * @@ -114,10 +119,9 @@ static void UpdateControlValues(TkScrollbar *scrollPtr); TkScrollbar * TkpCreateScrollbar( - Tk_Window tkwin) + Tk_Window tkwin) { - - MacScrollbar *scrollPtr = (MacScrollbar *)ckalloc(sizeof(MacScrollbar)); + MacScrollbar *scrollPtr = ckalloc(sizeof(MacScrollbar)); scrollPtr->troughGC = NULL; scrollPtr->copyGC = NULL; @@ -125,15 +129,15 @@ TkpCreateScrollbar( scrollPtr->buttonDown = false; Tk_CreateEventHandler(tkwin, - ExposureMask | - StructureNotifyMask | - FocusChangeMask | - ButtonPressMask | - ButtonReleaseMask | - EnterWindowMask | - LeaveWindowMask | - VisibilityChangeMask, - ScrollbarEventProc, scrollPtr); + ExposureMask | + StructureNotifyMask | + FocusChangeMask | + ButtonPressMask | + ButtonReleaseMask | + EnterWindowMask | + LeaveWindowMask | + VisibilityChangeMask, + ScrollbarEventProc, scrollPtr); return (TkScrollbar *) scrollPtr; } @@ -144,8 +148,8 @@ TkpCreateScrollbar( * TkpDisplayScrollbar -- * * This procedure redraws the contents of a scrollbar window. It is - * invoked as a do-when-idle handler, so it only runs when there's - * nothing else for the application to do. + * invoked as a do-when-idle handler, so it only runs when there's nothing + * else for the application to do. * * Results: * None. @@ -158,9 +162,9 @@ TkpCreateScrollbar( void TkpDisplayScrollbar( - ClientData clientData) /* Information about window. */ + ClientData clientData) /* Information about window. */ { - register TkScrollbar *scrollPtr = (TkScrollbar *) clientData; + register TkScrollbar *scrollPtr = clientData; MacScrollbar *msPtr = (MacScrollbar *) scrollPtr; register Tk_Window tkwin = scrollPtr->tkwin; TkWindow *winPtr = (TkWindow *) tkwin; @@ -169,23 +173,31 @@ TkpDisplayScrollbar( scrollPtr->flags &= ~REDRAW_PENDING; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { - return; + return; } - MacDrawable *macWin = (MacDrawable *) winPtr->window; + MacDrawable *macWin = (MacDrawable *) winPtr->window; NSView *view = TkMacOSXDrawableView(macWin); - if (!view || - macWin->flags & TK_DO_NOT_DRAW || - !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) { - return; + + if ((view == NULL) + || (macWin->flags & TK_DO_NOT_DRAW) + || !TkMacOSXSetupDrawingContext((Drawable) macWin, NULL, 1, &dc)) { + return; } CGFloat viewHeight = [view bounds].size.height; - CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0, - .ty = viewHeight}; + CGAffineTransform t = { + .a = 1, .b = 0, + .c = 0, .d = -1, + .tx = 0, .ty = viewHeight + }; + CGContextConcatCTM(dc.context, t); - /*Draw a 3D rectangle to provide a base for the native scrollbar.*/ + /* + * Draw a 3D rectangle to provide a base for the native scrollbar. + */ + if (scrollPtr->highlightWidth != 0) { GC fgGC, bgGC; @@ -196,32 +208,37 @@ TkpDisplayScrollbar( fgGC = bgGC; } TkpDrawHighlightBorder(tkwin, fgGC, bgGC, scrollPtr->highlightWidth, - (Pixmap) macWin); + (Pixmap) macWin); } Tk_Draw3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder, - scrollPtr->highlightWidth, scrollPtr->highlightWidth, - Tk_Width(tkwin) - 2*scrollPtr->highlightWidth, - Tk_Height(tkwin) - 2*scrollPtr->highlightWidth, - scrollPtr->borderWidth, scrollPtr->relief); + scrollPtr->highlightWidth, scrollPtr->highlightWidth, + Tk_Width(tkwin) - 2*scrollPtr->highlightWidth, + Tk_Height(tkwin) - 2*scrollPtr->highlightWidth, + scrollPtr->borderWidth, scrollPtr->relief); Tk_Fill3DRectangle(tkwin, (Pixmap) macWin, scrollPtr->bgBorder, - scrollPtr->inset, scrollPtr->inset, - Tk_Width(tkwin) - 2*scrollPtr->inset, - Tk_Height(tkwin) - 2*scrollPtr->inset, 0, TK_RELIEF_FLAT); + scrollPtr->inset, scrollPtr->inset, + Tk_Width(tkwin) - 2*scrollPtr->inset, + Tk_Height(tkwin) - 2*scrollPtr->inset, 0, TK_RELIEF_FLAT); + + /* + * Update values and then draw the native scrollbar over the rectangle. + */ - /* Update values and then draw the native scrollbar over the rectangle.*/ UpdateControlValues(scrollPtr); if (SNOW_LEOPARD_STYLE) { - HIThemeDrawTrack (&(msPtr->info), 0, dc.context, kHIThemeOrientationInverted); + HIThemeDrawTrack(&msPtr->info, 0, dc.context, + kHIThemeOrientationInverted); } else { - HIThemeDrawTrack (&(msPtr->info), 0, dc.context, kHIThemeOrientationNormal); + HIThemeDrawTrack(&msPtr->info, 0, dc.context, + kHIThemeOrientationNormal); } TkMacOSXRestoreDrawingContext(&dc); scrollPtr->flags &= ~REDRAW_PENDING; } - + /* *---------------------------------------------------------------------- * @@ -240,44 +257,41 @@ TkpDisplayScrollbar( *---------------------------------------------------------------------- */ - - extern void TkpComputeScrollbarGeometry( register TkScrollbar *scrollPtr) - /* Scrollbar whose geometry may have - * changed. */ + /* Scrollbar whose geometry may have + * changed. */ { - - /* - * The code below is borrowed from tkUnixScrlbr.c but has been adjusted to - * account for some differences between macOS and X11. The Unix scrollbar - * has an arrow button on each end. On macOS 10.6 (Snow Leopard) the - * scrollbars by default have both arrow buttons at the bottom or right. - * (There is a preferences setting to use the Unix layout, but we are not - * supporting that!) On more recent versions of macOS there are no arrow - * buttons at all. The case of no arrow buttons can be handled as a special - * case of having both buttons at the end, but where scrollPtr->arrowLength - * happens to be zero. To adjust for having both arrows at the same end we - * shift the scrollbar up by the arrowLength. - */ + /* + * The code below is borrowed from tkUnixScrlbr.c but has been adjusted to + * account for some differences between macOS and X11. The Unix scrollbar + * has an arrow button on each end. On macOS 10.6 (Snow Leopard) the + * scrollbars by default have both arrow buttons at the bottom or right. + * (There is a preferences setting to use the Unix layout, but we are not + * supporting that!) On more recent versions of macOS there are no arrow + * buttons at all. The case of no arrow buttons can be handled as a special + * case of having both buttons at the end, but where scrollPtr->arrowLength + * happens to be zero. To adjust for having both arrows at the same end we + * shift the scrollbar up by the arrowLength. + */ int fieldLength; if (scrollPtr->highlightWidth < 0) { - scrollPtr->highlightWidth = 0; + scrollPtr->highlightWidth = 0; } scrollPtr->inset = scrollPtr->highlightWidth + scrollPtr->borderWidth; if ([NSApp macMinorVersion] == 6) { - scrollPtr->arrowLength = scrollPtr->width; + scrollPtr->arrowLength = scrollPtr->width; } else { - scrollPtr->arrowLength = 0; + scrollPtr->arrowLength = 0; } fieldLength = (scrollPtr->vertical ? Tk_Height(scrollPtr->tkwin) - : Tk_Width(scrollPtr->tkwin)) - - 2*(scrollPtr->arrowLength + scrollPtr->inset); + : Tk_Width(scrollPtr->tkwin)) + - 2*(scrollPtr->arrowLength + scrollPtr->inset); if (fieldLength < 0) { - fieldLength = 0; + fieldLength = 0; } scrollPtr->sliderFirst = fieldLength*scrollPtr->firstFraction; scrollPtr->sliderLast = fieldLength*scrollPtr->lastFraction; @@ -289,16 +303,16 @@ TkpComputeScrollbarGeometry( */ if (scrollPtr->sliderFirst > fieldLength - MIN_SLIDER_LENGTH) { - scrollPtr->sliderFirst = fieldLength - MIN_SLIDER_LENGTH; + scrollPtr->sliderFirst = fieldLength - MIN_SLIDER_LENGTH; } if (scrollPtr->sliderFirst < 0) { - scrollPtr->sliderFirst = 0; + scrollPtr->sliderFirst = 0; } if (scrollPtr->sliderLast < scrollPtr->sliderFirst + MIN_SLIDER_LENGTH) { - scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH; + scrollPtr->sliderLast = scrollPtr->sliderFirst + MIN_SLIDER_LENGTH; } if (scrollPtr->sliderLast > fieldLength) { - scrollPtr->sliderLast = fieldLength; + scrollPtr->sliderLast = fieldLength; } scrollPtr->sliderFirst += -scrollPtr->arrowLength + scrollPtr->inset; scrollPtr->sliderLast += scrollPtr->inset; @@ -310,20 +324,20 @@ TkpComputeScrollbarGeometry( * be redisplayed. */ - if (scrollPtr->vertical) { - Tk_GeometryRequest(scrollPtr->tkwin, - scrollPtr->width + 2*scrollPtr->inset, - 2*(scrollPtr->arrowLength + scrollPtr->borderWidth - + scrollPtr->inset) + metrics.minThumbHeight); + if (scrollPtr->vertical) { + Tk_GeometryRequest(scrollPtr->tkwin, + scrollPtr->width + 2*scrollPtr->inset, + 2*(scrollPtr->arrowLength + scrollPtr->borderWidth + + scrollPtr->inset) + metrics.minThumbHeight); } else { - Tk_GeometryRequest(scrollPtr->tkwin, - 2*(scrollPtr->arrowLength + scrollPtr->borderWidth - + scrollPtr->inset) + metrics.minThumbHeight, - scrollPtr->width + 2*scrollPtr->inset); + Tk_GeometryRequest(scrollPtr->tkwin, + 2*(scrollPtr->arrowLength + scrollPtr->borderWidth + + scrollPtr->inset) + metrics.minThumbHeight, + scrollPtr->width + 2*scrollPtr->inset); } Tk_SetInternalBorder(scrollPtr->tkwin, scrollPtr->inset); } - + /* *---------------------------------------------------------------------- * @@ -342,9 +356,9 @@ TkpComputeScrollbarGeometry( void TkpDestroyScrollbar( - TkScrollbar *scrollPtr) + TkScrollbar *scrollPtr) { - MacScrollbar *macScrollPtr = (MacScrollbar *)scrollPtr; + MacScrollbar *macScrollPtr = (MacScrollbar *) scrollPtr; if (macScrollPtr->troughGC != None) { Tk_FreeGC(scrollPtr->display, macScrollPtr->troughGC); @@ -353,15 +367,15 @@ TkpDestroyScrollbar( Tk_FreeGC(scrollPtr->display, macScrollPtr->copyGC); } } - + /* *---------------------------------------------------------------------- * * TkpConfigureScrollbar -- * - * This procedure is called after the generic code has finished - * processing configuration options, in order to configure platform - * specific options. There are no such option on the Mac, however. + * This procedure is called after the generic code has finished processing + * configuration options, in order to configure platform specific options. + * There are no such option on the Mac, however. * * Results: * None. @@ -374,11 +388,11 @@ TkpDestroyScrollbar( void TkpConfigureScrollbar( - register TkScrollbar *scrollPtr) + register TkScrollbar *scrollPtr) { - + /* empty */ } - + /* *-------------------------------------------------------------- * @@ -403,29 +417,28 @@ TkpScrollbarPosition( /* Scrollbar widget record. */ int x, int y) /* Coordinates within scrollPtr's window. */ { - - /* - * The code below is borrowed from tkUnixScrlbr.c and needs no adjustment - * since it does not involve the arrow buttons. - */ + /* + * The code below is borrowed from tkUnixScrlbr.c and needs no adjustment + * since it does not involve the arrow buttons. + */ int length, width, tmp; register const int inset = scrollPtr->inset; if (scrollPtr->vertical) { - length = Tk_Height(scrollPtr->tkwin); - width = Tk_Width(scrollPtr->tkwin); + length = Tk_Height(scrollPtr->tkwin); + width = Tk_Width(scrollPtr->tkwin); } else { - tmp = x; - x = y; - y = tmp; - length = Tk_Width(scrollPtr->tkwin); - width = Tk_Height(scrollPtr->tkwin); + tmp = x; + x = y; + y = tmp; + length = Tk_Width(scrollPtr->tkwin); + width = Tk_Height(scrollPtr->tkwin); } if (x < inset || x >= width - inset || - y < inset || y >= length - inset) { - return OUTSIDE; + y < inset || y >= length - inset) { + return OUTSIDE; } /* @@ -436,31 +449,34 @@ TkpScrollbarPosition( */ if (y < scrollPtr->sliderFirst + scrollPtr->arrowLength) { - return TOP_GAP; - } - if (y < scrollPtr->sliderLast) { - return SLIDER; - } - if (y < length - (2*scrollPtr->arrowLength + inset)) { - return BOTTOM_GAP; - } - /* On systems newer than 10.6 we have already returned. */ - if (y < length - (scrollPtr->arrowLength + inset)) { - return TOP_ARROW; - } - return BOTTOM_ARROW; -} + return TOP_GAP; + } + if (y < scrollPtr->sliderLast) { + return SLIDER; + } + if (y < length - (2*scrollPtr->arrowLength + inset)) { + return BOTTOM_GAP; + } + /* + * On systems newer than 10.6 we have already returned. + */ + + if (y < length - (scrollPtr->arrowLength + inset)) { + return TOP_ARROW; + } + return BOTTOM_ARROW; +} + /* *-------------------------------------------------------------- * * UpdateControlValues -- * - * This procedure updates the Macintosh scrollbar control to - * display the values defined by the Tk scrollbar. This is the - * key interface to the Mac-native scrollbar; the Unix bindings - * drive scrolling in the Tk window and all the Mac scrollbar has - * to do is redraw itself. + * This procedure updates the Macintosh scrollbar control to display the + * values defined by the Tk scrollbar. This is the key interface to the + * Mac-native scrollbar; the Unix bindings drive scrolling in the Tk + * window and all the Mac scrollbar has to do is redraw itself. * * Results: * None. @@ -473,20 +489,21 @@ TkpScrollbarPosition( static void UpdateControlValues( - TkScrollbar *scrollPtr) /* Scrollbar data struct. */ + TkScrollbar *scrollPtr) /* Scrollbar data struct. */ { - MacScrollbar *msPtr = (MacScrollbar *)scrollPtr; + MacScrollbar *msPtr = (MacScrollbar *) scrollPtr; Tk_Window tkwin = scrollPtr->tkwin; MacDrawable *macWin = (MacDrawable *) Tk_WindowId(scrollPtr->tkwin); double dViewSize; - HIRect contrlRect; + HIRect contrlRect; short width, height; NSView *view = TkMacOSXDrawableView(macWin); CGFloat viewHeight = [view bounds].size.height; NSRect frame; + frame = NSMakeRect(macWin->xOff, macWin->yOff, Tk_Width(tkwin), - Tk_Height(tkwin)); + Tk_Height(tkwin)); frame = NSInsetRect(frame, scrollPtr->inset, scrollPtr->inset); frame.origin.y = viewHeight - (frame.origin.y + frame.size.height); @@ -503,9 +520,9 @@ UpdateControlValues( msPtr->info.bounds = contrlRect; if (scrollPtr->vertical) { - msPtr->info.attributes &= ~kThemeTrackHorizontal; + msPtr->info.attributes &= ~kThemeTrackHorizontal; } else { - msPtr->info.attributes |= kThemeTrackHorizontal; + msPtr->info.attributes |= kThemeTrackHorizontal; } /* @@ -518,69 +535,73 @@ UpdateControlValues( * the view area. */ - double maximum = 100, factor; - factor = RangeToFactor(maximum); - dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction) - * factor; - msPtr->info.max = MIN_SCROLLBAR_VALUE + - factor - dViewSize; + double maximum = 100, factor = RangeToFactor(maximum); + + dViewSize = (scrollPtr->lastFraction - scrollPtr->firstFraction) * factor; + msPtr->info.max = MIN_SCROLLBAR_VALUE + factor - dViewSize; msPtr->info.trackInfo.scrollbar.viewsize = dViewSize; if (scrollPtr->vertical) { - if (SNOW_LEOPARD_STYLE) { - msPtr->info.value = factor * scrollPtr->firstFraction; - } else { - msPtr->info.value = msPtr->info.max - factor * scrollPtr->firstFraction; - } + if (SNOW_LEOPARD_STYLE) { + msPtr->info.value = factor * scrollPtr->firstFraction; + } else { + msPtr->info.value = msPtr->info.max - + factor * scrollPtr->firstFraction; + } } else { - msPtr->info.value = MIN_SCROLLBAR_VALUE + factor * scrollPtr->firstFraction; + msPtr->info.value = MIN_SCROLLBAR_VALUE + + factor * scrollPtr->firstFraction; } - if((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0) - || height <= metrics.minHeight) { + if ((scrollPtr->firstFraction <= 0.0 && scrollPtr->lastFraction >= 1.0) + || height <= metrics.minHeight) { msPtr->info.enableState = kThemeTrackHideTrack; } else { msPtr->info.enableState = kThemeTrackActive; - msPtr->info.attributes = kThemeTrackShowThumb | kThemeTrackThumbRgnIsNotGhost; + msPtr->info.attributes = + kThemeTrackShowThumb | kThemeTrackThumbRgnIsNotGhost; } - } - + /* *-------------------------------------------------------------- * * ScrollbarEvent -- * - * This procedure is invoked in response to <ButtonPress>, <ButtonRelease>, - * <EnterNotify>, and <LeaveNotify> events. The Scrollbar appearance is - * modified for each event. + * This procedure is invoked in response to <ButtonPress>, + * <ButtonRelease>, <EnterNotify>, and <LeaveNotify> events. The + * Scrollbar appearance is modified for each event. * *-------------------------------------------------------------- */ static int -ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr) +ScrollbarEvent( + TkScrollbar *scrollPtr, + XEvent *eventPtr) { - MacScrollbar *msPtr = (MacScrollbar *)scrollPtr; - - /* The pressState does not indicate whether the moused button was - * pressed at some location in the Scrollbar. Rather, it indicates - * that the scrollbar should appear as if it were pressed in that - * location. The standard Mac behavior is that once the button is - * pressed inside the Scrollbar the appearance should not change until - * the button is released, even if the mouse moves outside of the - * scrollbar. However, if the mouse lies over the scrollbar but the - * button is not pressed then the appearance should be the same as if - * the button had been pressed on the slider, i.e. kThemeThumbPressed. - * See the file Appearance.r, or HIToolbox.bridgesupport on 10.14. + MacScrollbar *msPtr = (MacScrollbar *) scrollPtr; + + /* + * The pressState does not indicate whether the moused button was pressed + * at some location in the Scrollbar. Rather, it indicates that the + * scrollbar should appear as if it were pressed in that location. The + * standard Mac behavior is that once the button is pressed inside the + * Scrollbar the appearance should not change until the button is released, + * even if the mouse moves outside of the scrollbar. However, if the mouse + * lies over the scrollbar but the button is not pressed then the + * appearance should be the same as if the button had been pressed on the + * slider, i.e. kThemeThumbPressed. See the file Appearance.r, or + * HIToolbox.bridgesupport on 10.14. */ if (eventPtr->type == ButtonPress) { msPtr->buttonDown = true; UpdateControlValues(scrollPtr); + int where = TkpScrollbarPosition(scrollPtr, - eventPtr->xbutton.x, - eventPtr->xbutton.y); - switch(where) { + eventPtr->xbutton.x, eventPtr->xbutton.y); + + switch (where) { case OUTSIDE: msPtr->info.trackInfo.scrollbar.pressState = 0; break; @@ -591,14 +612,20 @@ ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr) msPtr->info.trackInfo.scrollbar.pressState = kThemeThumbPressed; break; case BOTTOM_GAP: - msPtr->info.trackInfo.scrollbar.pressState = kThemeBottomTrackPressed; + msPtr->info.trackInfo.scrollbar.pressState = + kThemeBottomTrackPressed; break; case TOP_ARROW: - /* This looks wrong and the docs say it is wrong but it works. */ - msPtr->info.trackInfo.scrollbar.pressState = kThemeTopInsideArrowPressed; + /* + * This looks wrong and the docs say it is wrong but it works. + */ + + msPtr->info.trackInfo.scrollbar.pressState = + kThemeTopInsideArrowPressed; break; case BOTTOM_ARROW: - msPtr->info.trackInfo.scrollbar.pressState = kThemeBottomOutsideArrowPressed; + msPtr->info.trackInfo.scrollbar.pressState = + kThemeBottomOutsideArrowPressed; break; } } @@ -622,9 +649,7 @@ ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr) } return TCL_OK; } - - - + /* *-------------------------------------------------------------- * @@ -645,8 +670,8 @@ ScrollbarEvent(TkScrollbar *scrollPtr, XEvent *eventPtr) static void ScrollbarEventProc( - ClientData clientData, /* Information about window. */ - XEvent *eventPtr) /* Information about event. */ + ClientData clientData, /* Information about window. */ + XEvent *eventPtr) /* Information about event. */ { TkScrollbar *scrollPtr = clientData; @@ -668,7 +693,7 @@ ScrollbarEventProc( TkScrollbarEventProc(clientData, eventPtr); } } - + /* * Local Variables: * mode: objc diff --git a/macosx/tkMacOSXSend.c b/macosx/tkMacOSXSend.c index 1fdf048..8b65532 100644 --- a/macosx/tkMacOSXSend.c +++ b/macosx/tkMacOSXSend.c @@ -51,7 +51,7 @@ typedef struct RegisteredInterp { * A registry of all interpreters for a display is kept in a property * "InterpRegistry" on the root window of the display. It is organized as a * series of zero or more concatenated strings (in no particular order), each - * of the form + * of the form: * window space name '\0' * where "window" is the hex id of the comm. window to use to talk to an * interpreter named "name". @@ -78,7 +78,7 @@ typedef struct NameRegistry { * XFree; zero means use ckfree. */ } NameRegistry; -static int initialized = 0; /* A flag to denote if we have initialized +static int initialized = 0; /* A flag to denote if we have initialized * yet. */ static RegisteredInterp *interpListPtr = NULL; diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 805d58f..06aaa9d 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -65,7 +65,7 @@ XDestroyWindow( TkMacOSXSelDeadWindow(macWin->winPtr); macWin->toplevel->referenceCount--; - if (!Tk_IsTopLevel(macWin->winPtr) ) { + if (!Tk_IsTopLevel(macWin->winPtr)) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); if (macWin->winPtr->parentPtr != NULL) { TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); @@ -151,19 +151,18 @@ XMapWindow( NSWindow *win = TkMacOSXDrawableWindow(window); /* - * We want to activate Tk when a toplevel is mapped - * but we must not supply YES here. This is because - * during Tk initialization the root window is mapped - * before applicationDidFinishLaunching returns. Forcing - * the app to activate too early can make the menu bar - * unresponsive. + * We want to activate Tk when a toplevel is mapped but we must not + * supply YES here. This is because during Tk initialization the + * root window is mapped before applicationDidFinishLaunching + * returns. Forcing the app to activate too early can make the menu + * bar unresponsive. */ TkMacOSXApplyWindowAttributes(macWin->winPtr, win); [win setExcludedFromWindowsMenu:NO]; [NSApp activateIgnoringOtherApps:NO]; [[win contentView] setNeedsDisplay:YES]; - if ( [win canBecomeKeyWindow] ) { + if ([win canBecomeKeyWindow]) { [win makeKeyAndOrderFront:NSApp]; } else { [win orderFrontRegardless]; @@ -185,7 +184,8 @@ XMapWindow( */ TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr); - TkMacOSXInvalClipRgns((Tk_Window)contWinPtr); + + TkMacOSXInvalClipRgns((Tk_Window) contWinPtr); TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); @@ -203,12 +203,9 @@ XMapWindow( event.xmap.event = window; event.xmap.override_redirect = macWin->winPtr->atts.override_redirect; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); - } else { - /* * Rebuild the parent's clipping region and display the window. - * */ TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); @@ -298,6 +295,7 @@ XUnmapWindow( if (!Tk_IsEmbedded(winPtr) && winPtr->wmInfoPtr->hints.initial_state!=IconicState) { NSWindow *win = TkMacOSXDrawableWindow(window); + [win orderOut:nil]; } TkMacOSXInvalClipRgns((Tk_Window) winPtr); @@ -316,15 +314,15 @@ XUnmapWindow( event.xunmap.from_configure = false; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); } else { - /* * Rebuild the visRgn clip region for the parent so it will be allowed * to draw in the space from which this subwindow was removed. */ if (parentPtr && parentPtr->privatePtr->visRgn) { - TkMacOSXInvalidateViewRegion(TkMacOSXDrawableView(parentPtr->privatePtr), - parentPtr->privatePtr->visRgn); + TkMacOSXInvalidateViewRegion( + TkMacOSXDrawableView(parentPtr->privatePtr), + parentPtr->privatePtr->visRgn); } TkMacOSXInvalClipRgns((Tk_Window) parentPtr); TkMacOSXUpdateClipRgn(parentPtr); @@ -357,11 +355,14 @@ XResizeWindow( unsigned int height) { MacDrawable *macWin = (MacDrawable *) window; + display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { NSWindow *w = macWin->winPtr->wmInfoPtr->window; + if (w) { NSRect r = [w contentRectForFrameRect:[w frame]]; + r.origin.y += r.size.height - height; r.size.width = width; r.size.height = height; @@ -377,8 +378,8 @@ XResizeWindow( * * XMoveResizeWindow -- * - * Move or resize a given X window. See X windows documentation - * for further details. + * Move or resize a given X window. See X windows documentation for + * further details. * * Results: * None. @@ -402,22 +403,24 @@ XMoveResizeWindow( display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { NSWindow *w = macWin->winPtr->wmInfoPtr->window; - if (w) { - /* We explicitly convert everything to doubles so we don't get + if (w) { + /* + * We explicitly convert everything to doubles so we don't get * surprised (again) by what happens when you do arithmetic with * unsigned ints. */ - CGFloat X = (CGFloat)x; - CGFloat Y = (CGFloat)y; - CGFloat Width = (CGFloat)width; - CGFloat Height = (CGFloat)height; - CGFloat XOff = (CGFloat)macWin->winPtr->wmInfoPtr->xInParent; - CGFloat YOff = (CGFloat)macWin->winPtr->wmInfoPtr->yInParent; - NSRect r = NSMakeRect(X + XOff, - tkMacOSXZeroScreenHeight - Y - YOff - Height, - Width, Height); + CGFloat X = (CGFloat) x; + CGFloat Y = (CGFloat) y; + CGFloat Width = (CGFloat) width; + CGFloat Height = (CGFloat) height; + CGFloat XOff = (CGFloat) macWin->winPtr->wmInfoPtr->xInParent; + CGFloat YOff = (CGFloat) macWin->winPtr->wmInfoPtr->yInParent; + NSRect r = NSMakeRect( + X + XOff, tkMacOSXZeroScreenHeight - Y - YOff - Height, + Width, Height); + [w setFrame:[w frameRectForContentRect:r] display:YES]; } } else { @@ -430,8 +433,7 @@ XMoveResizeWindow( * * XMoveWindow -- * - * Move a given X window. See X windows documentation for further - * details. + * Move a given X window. See X windows documentation for further details. * * Results: * None. @@ -453,8 +455,10 @@ XMoveWindow( display->request++; if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { NSWindow *w = macWin->winPtr->wmInfoPtr->window; + if (w) { - [w setFrameTopLeftPoint:NSMakePoint(x, tkMacOSXZeroScreenHeight - y)]; + [w setFrameTopLeftPoint: NSMakePoint( + x, tkMacOSXZeroScreenHeight - y)]; } } else { MoveResizeWindow(macWin); @@ -495,7 +499,6 @@ MoveResizeWindow( if (contWinPtr) { macParent = contWinPtr->privatePtr; } else { - /* * Here we should handle out of process embedding. At this point, * we are assuming that the changes.x,y is not maintained, if you @@ -504,7 +507,6 @@ MoveResizeWindow( */ } } else { - /* * TODO: update all xOff & yOffs */ @@ -596,7 +598,6 @@ XRaiseWindow( if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { TkWmRestackToplevel(macWin->winPtr, Above, NULL); } else { - /* * TODO: this should generate damage */ @@ -631,7 +632,6 @@ XLowerWindow( if (Tk_IsTopLevel(macWin->winPtr) && !Tk_IsEmbedded(macWin->winPtr)) { TkWmRestackToplevel(macWin->winPtr, Below, NULL); } else { - /* * TODO: this should generate damage */ @@ -694,14 +694,16 @@ XConfigureWindow( TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr); TkMacOSXWinBounds(winPtr, &bounds); r = NSMakeRect(bounds.left, - [view bounds].size.height - bounds.bottom, - bounds.right - bounds.left, bounds.bottom - bounds.top); + [view bounds].size.height - bounds.bottom, + bounds.right - bounds.left, bounds.bottom - bounds.top); [view setNeedsDisplayInRect:r]; } } - /* TkGenWMMoveRequestEvent(macWin->winPtr, - macWin->winPtr->changes.x, macWin->winPtr->changes.y); */ +#if 0 + TkGenWMMoveRequestEvent(macWin->winPtr, + macWin->winPtr->changes.x, macWin->winPtr->changes.y); +#endif } /* @@ -723,14 +725,14 @@ XConfigureWindow( void TkMacOSXSetDrawingEnabled( - TkWindow *winPtr, - int flag) + TkWindow *winPtr, + int flag) { TkWindow *childPtr; MacDrawable *macWin = winPtr->privatePtr; if (macWin) { - if (flag ) { + if (flag) { macWin->flags &= ~TK_DO_NOT_DRAW; } else { macWin->flags |= TK_DO_NOT_DRAW; @@ -738,8 +740,8 @@ TkMacOSXSetDrawingEnabled( } /* - * Set the flag for all children & their descendants, excluding - * Toplevels. (??? Do we need to exclude Toplevels?) + * Set the flag for all children & their descendants, excluding Toplevels. + * (??? Do we need to exclude Toplevels?) */ childPtr = winPtr->childList; @@ -903,7 +905,6 @@ TkMacOSXUpdateClipRgn( } CFRelease(rgn); } else { - /* * An unmapped window has empty clip regions to prevent any * (erroneous) drawing into it or its children from becoming @@ -933,8 +934,8 @@ TkMacOSXUpdateClipRgn( * TkMacOSXVisableClipRgn -- * * This function returns the Macintosh clipping region for the given - * window. The caller is responsible for disposing of the returned - * region via TkDestroyRegion(). + * window. The caller is responsible for disposing of the returned region + * via TkDestroyRegion(). * * Results: * The region. @@ -952,7 +953,7 @@ TkMacOSXVisableClipRgn( if (winPtr->privatePtr->flags & TK_CLIP_INVALID) { TkMacOSXUpdateClipRgn(winPtr); } - return (TkRegion)HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn); + return (TkRegion) HIShapeCreateMutableCopy(winPtr->privatePtr->visRgn); } /* @@ -972,7 +973,12 @@ TkMacOSXVisableClipRgn( */ static OSStatus -InvalViewRect(int msg, HIShapeRef rgn, const CGRect *rect, void *ref) { +InvalViewRect( + int msg, + HIShapeRef rgn, + const CGRect *rect, + void *ref) +{ static CGAffineTransform t; NSView *view = ref; @@ -1052,7 +1058,7 @@ TkMacOSXInvalidateWindow( *---------------------------------------------------------------------- */ -NSWindow* +NSWindow * TkMacOSXDrawableWindow( Drawable drawable) { @@ -1070,6 +1076,7 @@ TkMacOSXDrawableWindow( result = macWin->winPtr->wmInfoPtr->window; } else if (macWin->toplevel && (macWin->toplevel->flags & TK_EMBEDDED)) { TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); + if (contWinPtr) { result = TkMacOSXDrawableWindow((Drawable) contWinPtr->privatePtr); } @@ -1123,7 +1130,7 @@ TkMacOSXGetDrawablePort( *---------------------------------------------------------------------- */ -NSView* +NSView * TkMacOSXDrawableView( MacDrawable *macWin) { @@ -1137,6 +1144,7 @@ TkMacOSXDrawableView( result = macWin->toplevel->view; } else { TkWindow *contWinPtr = TkpGetOtherWindow(macWin->toplevel->winPtr); + if (contWinPtr) { result = TkMacOSXDrawableView(contWinPtr->privatePtr); } @@ -1164,7 +1172,6 @@ void * TkMacOSXGetRootControl( Drawable drawable) { - /* * will probably need to fix this up for embedding */ @@ -1281,7 +1288,8 @@ TkMacOSXWinBounds( TkWindow *winPtr, void *bounds) { - Rect *b = (Rect *)bounds; + Rect *b = (Rect *) bounds; + b->left = winPtr->privatePtr->xOff; b->top = winPtr->privatePtr->yOff; b->right = b->left + winPtr->changes.width; @@ -1345,7 +1353,6 @@ UpdateOffsets( TkWindow *childPtr; if (winPtr->privatePtr == NULL) { - /* * We haven't called Tk_MakeWindowExist for this window yet. The offset * information will be postponed and calulated at that time. (This will diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 54e1272..6b80761 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -68,7 +68,7 @@ extern NSString *NSWindowDidOrderOffScreenNotification; TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification); #endif BOOL movedOnly = [[notification name] - isEqualToString:NSWindowDidMoveNotification]; + isEqualToString:NSWindowDidMoveNotification]; NSWindow *w = [notification object]; TkWindow *winPtr = TkMacOSXGetTkWindow(w); @@ -91,7 +91,6 @@ extern NSString *NSWindowDidOrderOffScreenNotification; flags |= TK_SIZE_CHANGED; } if (Tcl_GetServiceMode() != TCL_SERVICE_NONE) { - /* * Propagate geometry changes immediately. */ @@ -140,11 +139,10 @@ extern NSString *NSWindowDidOrderOffScreenNotification; - (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame { - /* - * This method needs to be implemented in order for [NSWindow isZoomed] - * to give the correct answer. But it suffices to always validate - * every request. + * This method needs to be implemented in order for [NSWindow isZoomed] to + * give the correct answer. But it suffices to always validate every + * request. */ return newFrame; @@ -153,13 +151,12 @@ extern NSString *NSWindowDidOrderOffScreenNotification; - (NSSize)window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize { - /* - * We don't need to change the proposed size, but we do need to - * implement this method. Otherwise the full screen window will - * be sized to the screen's visibleFrame, leaving black bands at - * the top and bottom. + * We don't need to change the proposed size, but we do need to implement + * this method. Otherwise the full screen window will be sized to the + * screen's visibleFrame, leaving black bands at the top and bottom. */ + return proposedSize; } @@ -208,14 +205,13 @@ extern NSString *NSWindowDidOrderOffScreenNotification; } /* - * If necessary, TkGenWMDestroyEvent() handles [close]ing the window, - * so can always return NO from -windowShouldClose: for a Tk window. + * If necessary, TkGenWMDestroyEvent() handles [close]ing the window, so + * can always return NO from -windowShouldClose: for a Tk window. */ return (winPtr ? NO : YES); } - #ifdef TK_MAC_DEBUG_NOTIFICATIONS - (void) windowDragStart: (NSNotification *) notification @@ -256,7 +252,6 @@ extern NSString *NSWindowDidOrderOffScreenNotification; } } - #endif /* TK_MAC_DEBUG_NOTIFICATIONS */ - (void) _setupWindowNotifications @@ -363,11 +358,11 @@ extern NSString *NSWindowDidOrderOffScreenNotification; * * TkpAppIsDrawing -- * - * A widget display procedure can call this to determine whether it - * is being run inside of the drawRect method. This is needed for - * some tests, especially of the Text widget, which record data in - * a global Tcl variable and assume that display procedures will be - * run in a predictable sequence as Tcl idle tasks. + * A widget display procedure can call this to determine whether it is + * being run inside of the drawRect method. This is needed for some tests, + * especially of the Text widget, which record data in a global Tcl + * variable and assume that display procedures will be run in a + * predictable sequence as Tcl idle tasks. * * Results: * True only while running the drawRect method of a TKContentView; @@ -377,11 +372,11 @@ extern NSString *NSWindowDidOrderOffScreenNotification; * *---------------------------------------------------------------------- */ + MODULE_SCOPE Bool TkpAppIsDrawing(void) { return [NSApp isDrawing]; } - /* *---------------------------------------------------------------------- @@ -670,12 +665,10 @@ TkGenWMConfigureEvent( if ((flags & TK_SIZE_CHANGED) && !(wmPtr->flags & WM_SYNC_PENDING) && ((width != Tk_Width(tkwin)) || (height != Tk_Height(tkwin)))) { if ((wmPtr->width == -1) && (width == winPtr->reqWidth)) { - /* * Don't set external width, since the user didn't change it * from what the widgets asked for. */ - } else if (wmPtr->gridWin != NULL) { wmPtr->width = wmPtr->reqGridWidth + (width - winPtr->reqWidth)/wmPtr->widthInc; @@ -687,12 +680,10 @@ TkGenWMConfigureEvent( } if ((wmPtr->height == -1) && (height == winPtr->reqHeight)) { - /* * Don't set external height, since the user didn't change it * from what the widgets asked for. */ - } else if (wmPtr->gridWin != NULL) { wmPtr->height = wmPtr->reqGridHeight + (height - winPtr->reqHeight)/wmPtr->heightInc; @@ -708,7 +699,6 @@ TkGenWMConfigureEvent( } } - /* * Now set up the changes structure. Under X we wait for the * ConfigureNotify to set these values. On the Mac we know imediatly that @@ -899,8 +889,8 @@ ConfigureRestrictProc( #endif /* - * We do not allow recursive calls to drawRect, but we only log - * them on OSX > 10.13, where they should never happen. + * We do not allow recursive calls to drawRect, but we only log them on OSX + * > 10.13, where they should never happen. */ if ([NSApp isDrawing]) { @@ -955,9 +945,9 @@ ConfigureRestrictProc( Tk_RestrictProc *oldProc; /* - * This can be called from outside the Tk event loop. - * Since it calls Tcl_DoOneEvent, we need to make sure we - * don't clobber the AutoreleasePool set up by the caller. + * This can be called from outside the Tk event loop. Since it calls + * Tcl_DoOneEvent, we need to make sure we don't clobber the + * AutoreleasePool set up by the caller. */ [NSApp _lockAutoreleasePool]; @@ -973,7 +963,7 @@ ConfigureRestrictProc( */ TkGenWMConfigureEvent(tkwin, Tk_X(tkwin), Tk_Y(tkwin), width, height, - TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY); + TK_SIZE_CHANGED | TK_MACOSX_HANDLE_EVENT_IMMEDIATELY); oldProc = Tk_RestrictEvents(ConfigureRestrictProc, NULL, &oldArg); Tk_RestrictEvents(oldProc, oldArg, &oldArg); @@ -1061,9 +1051,9 @@ ConfigureRestrictProc( } /* - * This method is called when a user changes between light and dark mode. - * The implementation here generates a Tk virtual event which can be bound - * to a function that redraws the window in an appropriate style. + * This method is called when a user changes between light and dark mode. The + * implementation here generates a Tk virtual event which can be bound to a + * function that redraws the window in an appropriate style. */ - (void) viewDidChangeEffectiveAppearance @@ -1099,8 +1089,8 @@ ConfigureRestrictProc( } /* - * This is no-op on 10.7 and up because Apple has removed this widget, - * but we are leaving it here for backwards compatibility. + * This is no-op on 10.7 and up because Apple has removed this widget, but we + * are leaving it here for backwards compatibility. */ - (void) tkToolbarButton: (id) sender diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 60277d1..648cf66 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -3,8 +3,7 @@ * * This module takes care of the interactions between a Tk-based * application and the window manager. Among other things, it implements - * the "wm" command and passes geometry information to the window - * manager. + * the "wm" command and passes geometry information to the window manager. * * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright 2001-2009, Apple Inc. @@ -392,7 +391,7 @@ static void RemoveTransient(TkWindow *winPtr); if ([self styleMask] & NSFullScreenWindowMask) { frameRect = [NSWindow frameRectForContentRect:NSZeroRect - styleMask:[self styleMask]]; + styleMask:[self styleMask]]; } else { frameRect = [self frameRectForContentRect:NSZeroRect]; } @@ -454,7 +453,7 @@ static void RemoveTransient(TkWindow *winPtr); if (title == nil) { title = "unnamed window"; } - if (DEBUG_ZOMBIES > 1){ + if (DEBUG_ZOMBIES > 1) { fprintf(stderr, "Retained <%s>. Count is: %lu\n", title, [self retainCount]); } @@ -468,7 +467,7 @@ static void RemoveTransient(TkWindow *winPtr); if (title == nil) { title = "unnamed window"; } - if (DEBUG_ZOMBIES > 1){ + if (DEBUG_ZOMBIES > 1) { fprintf(stderr, "Autoreleased <%s>. Count is %lu\n", title, [self retainCount]); } @@ -480,7 +479,7 @@ static void RemoveTransient(TkWindow *winPtr); if (title == nil) { title = "unnamed window"; } - if (DEBUG_ZOMBIES > 1){ + if (DEBUG_ZOMBIES > 1) { fprintf(stderr, "Releasing <%s>. Count is %lu\n", title, [self retainCount]); } @@ -492,7 +491,7 @@ static void RemoveTransient(TkWindow *winPtr); if (title == nil) { title = "unnamed window"; } - if (DEBUG_ZOMBIES > 0){ + if (DEBUG_ZOMBIES > 0) { fprintf(stderr, ">>>> Freeing <%s>. Count is %lu\n", title, [self retainCount]); } @@ -998,25 +997,29 @@ TkWmDeadWindow( if (winPtr2 && nswindow != window) { WmInfo *wmPtr = winPtr2->wmInfoPtr; - BOOL minimized = (wmPtr->hints.initial_state == IconicState || - wmPtr->hints.initial_state == WithdrawnState); + BOOL minimized = (wmPtr->hints.initial_state == IconicState + || wmPtr->hints.initial_state == WithdrawnState); + /* * If no windows are left on the screen and the next window is * iconified or withdrawn, we don't want to make it be the * KeyWindow because that would cause it to be displayed on the * screen. */ + if ([nswindow canBecomeKeyWindow] && !minimized) { [nswindow makeKeyAndOrderFront:NSApp]; break; } } } + /* * Process all window events immediately to force the closed window to * be deallocated. But don't do this for the root window as that is * unnecessary and can lead to segfaults. */ + if (winPtr->parentPtr) { while (Tk_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {} } @@ -2624,7 +2627,7 @@ WmIconpositionCmd( wmPtr->hints.flags &= ~IconPositionHint; } else { if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK) - || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)){ + || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) { return TCL_ERROR; } wmPtr->hints.icon_x = x; @@ -3455,14 +3458,17 @@ WmStateCmd( return TCL_ERROR; } - if (index == OPT_NORMAL) { + switch (index) { + case OPT_NORMAL: TkpWmSetState(winPtr, NormalState); /* * This varies from 'wm deiconify' because it does not force the * window to be raised and receive focus */ - } else if (index == OPT_ICONIC) { + + break; + case OPT_ICONIC: if (Tk_Attributes((Tk_Window) winPtr)->override_redirect) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "can't iconify \"%s\": override-redirect flag is set", @@ -3480,10 +3486,13 @@ WmStateCmd( return TCL_ERROR; } TkpWmSetState(winPtr, IconicState); - } else if (index == OPT_WITHDRAWN) { + break; + case OPT_WITHDRAWN: TkpWmSetState(winPtr, WithdrawnState); - } else { /* OPT_ZOOMED */ + break; + default: /* OPT_ZOOMED */ TkpWmSetState(winPtr, ZoomState); + break; } } else if (wmPtr->iconFor != NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("icon", -1)); @@ -3603,14 +3612,12 @@ WmTransientCmd( } if (Tcl_GetString(objv[3])[0] == '\0') { RemoveTransient(winPtr); - } else { if (TkGetWindowFromObj(interp, tkwin, objv[3], &master) != TCL_OK) { return TCL_ERROR; } masterPtr = (TkWindow*) master; while (!Tk_TopWinHierarchy(masterPtr)) { - /* * Ensure that the master window is actually a Tk toplevel. */ @@ -3628,7 +3635,11 @@ WmTransientCmd( } wmPtr2 = masterPtr->wmInfoPtr; - /* Under some circumstances, wmPtr2 is NULL here. */ + + /* + * Under some circumstances, wmPtr2 is NULL here. + */ + if (wmPtr2 != NULL && wmPtr2->iconFor != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "can't make \"%s\" a master: it is an icon for %s", @@ -3679,7 +3690,7 @@ WmTransientCmd( ApplyMasterOverrideChanges(winPtr, NULL); return TCL_OK; } - + /* *---------------------------------------------------------------------- * @@ -3786,6 +3797,7 @@ WmWithdrawCmd( /* * If this window has a transient, the transient must also be withdrawn. */ + for (Transient *transientPtr = wmPtr->transientPtr; transientPtr != NULL; transientPtr = transientPtr->nextPtr) { TkWindow *winPtr2 = transientPtr->winPtr; @@ -3800,10 +3812,10 @@ WmWithdrawCmd( return TCL_OK; } - + /* - * Invoked by those wm subcommands that affect geometry. - * Schedules a geometry update. + * Invoked by those wm subcommands that affect geometry. Schedules a geometry + * update. */ static void @@ -4417,9 +4429,10 @@ ParseGeometry( if (flags & WM_NEGATIVE_X) { int borderwidth = wmPtr->parentWidth - winPtr->changes.width; int newWidth = width == -1 ? winPtr->changes.width : width; + x = (x == -1) ? - wmPtr->x + winPtr->changes.width - newWidth : - wmPtr->vRootWidth - x - newWidth - borderwidth; + wmPtr->x + winPtr->changes.width - newWidth : + wmPtr->vRootWidth - x - newWidth - borderwidth; } if (x == -1) { x = wmPtr->x; @@ -4427,9 +4440,10 @@ ParseGeometry( if (flags & WM_NEGATIVE_Y) { int borderheight = wmPtr->parentHeight - winPtr->changes.height; int newHeight = height == -1 ? winPtr->changes.height : height; + y = (y == -1) ? - wmPtr->y + winPtr->changes.height - newHeight : - wmPtr->vRootHeight - y - newHeight - borderheight; + wmPtr->y + winPtr->changes.height - newHeight : + wmPtr->vRootHeight - y - newHeight - borderheight; } if (y == -1) { y = wmPtr->y; @@ -4556,8 +4570,7 @@ Tk_GetRootCoords( * * Results: * The return result is either a token for the window corresponding to - * rootX and rootY, or else NULL to indicate that there is no such - * window. + * rootX and rootY, or else NULL to indicate that there is no such window. * * Side effects: * None. @@ -6146,9 +6159,9 @@ TkMacOSXMakeRealWindowExist( * * TkpDisplayWindow -- * - * Mark the contentView of this window as needing display so the - * window will be drawn by the window manager. If this is called - * within the drawRect method, do nothing. + * Mark the contentView of this window as needing display so the window + * will be drawn by the window manager. If this is called within the + * drawRect method, do nothing. * * Results: * None. @@ -6162,7 +6175,7 @@ TkMacOSXMakeRealWindowExist( MODULE_SCOPE void TkpDisplayWindow(Tk_Window tkwin) { if (![NSApp isDrawing]) { - TkWindow *winPtr = (TkWindow*)tkwin; + TkWindow *winPtr = (TkWindow *) tkwin; NSWindow *w = TkMacOSXDrawableWindow(winPtr->window); [[w contentView] setNeedsDisplay: YES]; @@ -6174,8 +6187,8 @@ TkpDisplayWindow(Tk_Window tkwin) { * * TkMacOSXRegisterOffScreenWindow -- * - * This function adds the passed in Off Screen Port to the hash table - * that maps Mac windows to root X windows. + * This function adds the passed in Off Screen Port to the hash table that + * maps Mac windows to root X windows. * * Results: * None. @@ -6983,7 +6996,7 @@ ApplyMasterOverrideChanges( } if (macWindow) { structureRect = [NSWindow frameRectForContentRect:NSZeroRect - styleMask:styleMask]; + styleMask:styleMask]; /* * Synchronize the wmInfoPtr to match the new window configuration @@ -7238,6 +7251,7 @@ RemapWindows( MacDrawable *parentWin) { TkWindow *childPtr; + /* * Remove the OS specific window. It will get rebuilt when the window gets * Mapped. diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index a890b63..0c474f0 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -60,10 +60,14 @@ /* * BoxToRect -- - * Convert a Ttk_Box in Tk coordinates relative to the given Drawable - * to a native Rect relative to the containing port. + * Convert a Ttk_Box in Tk coordinates relative to the given Drawable to a + * native Rect relative to the containing port. */ -static inline CGRect BoxToRect(Drawable d, Ttk_Box b) + +static inline CGRect +BoxToRect( + Drawable d, + Ttk_Box b) { MacDrawable *md = (MacDrawable*)d; CGRect rect; @@ -102,10 +106,10 @@ static Ttk_StateTable ThemeStateTable[] = { * * Apple's Human Interface Guidelines only allow three specific heights for * most buttons: Regular, small and mini. We always use the regular size. - * However, Ttk may provide an arbitrary bounding rectangle. We always draw - * the button centered vertically on the rectangle, and having the same width - * as the rectangle. This function returns the actual bounding rectangle that - * will be used in drawing the button. + * However, Ttk may provide an arbitrary bounding rectangle. We always draw the + * button centered vertically on the rectangle, and having the same width as + * the rectangle. This function returns the actual bounding rectangle that will + * be used in drawing the button. * * The BevelButton is allowed to have arbitrary size, and also has external * padding. This is handled separately here. @@ -115,8 +119,9 @@ static CGRect NormalizeButtonBounds( SInt32 heightMetric, CGRect bounds) { - SInt32 height; - if (heightMetric != NoThemeMetric) { + if (heightMetric != (SInt32) NoThemeMetric) { + SInt32 height; + ChkErr(GetThemeMetric, heightMetric, &height); bounds.origin.y += (bounds.size.height - height)/2; bounds.size.height = height; @@ -149,8 +154,8 @@ static CGFloat blackRGBA[4] = {0.0, 0.0, 0.0, 1.0}; * Start with the background color of a window's geometry master, or the * standard ttk window background if not. If the contrast parameter is * nonzero modify this color to be darker, for the aqua appearance, or - * lighter for the DarkAqua appearance. This is primarily used by the - * Fill and Background elements. + * lighter for the DarkAqua appearance. This is primarily used by the Fill + * and Background elements. */ static void GetBackgroundColor( @@ -161,11 +166,12 @@ static void GetBackgroundColor( { TkWindow *winPtr = (TkWindow *) tkwin; TkWindow *masterPtr = (TkWindow *) TkGetGeomMaster(tkwin); + while (masterPtr != NULL) { if (masterPtr->privatePtr->flags & TTK_HAS_CONTRASTING_BG) { break; } - masterPtr = (TkWindow *)TkGetGeomMaster(masterPtr); + masterPtr = (TkWindow *) TkGetGeomMaster(masterPtr); } if (masterPtr) { for (int i = 0; i < 4; i++) { @@ -176,6 +182,7 @@ static void GetBackgroundColor( NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *windowColor = [[NSColor windowBackgroundColor] colorUsingColorSpace: deviceRGB]; + [windowColor getComponents: rgba]; } else { for (int i = 0; i < 4; i++) { @@ -219,6 +226,7 @@ static void DrawGroupBox( NSColor *borderColor, *bgColor; static CGFloat border[4] = {1.0, 1.0, 1.0, 0.25}; CGFloat fill[4]; + GetBackgroundColor(context, tkwin, 1, fill); bgColor = [NSColor colorWithColorSpace: deviceRGB components: fill count: 4]; @@ -255,6 +263,7 @@ static void SolidFillRoundedRectangle( NSColor *color) { CGPathRef path; + CGContextSetFillColorWithColor(context, color.CGColor); path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); CGContextBeginPath(context); @@ -271,14 +280,17 @@ static void DrawDownArrow( CGFloat *rgba) { CGFloat x, y; + CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]); CGContextSetLineWidth(context, 1.5); x = bounds.origin.x + inset; y = bounds.origin.y + trunc(bounds.size.height/2); - CGContextBeginPath(context); + CGPoint arrow[3] = { {x, y-size/4}, {x+size/2, y+size/4}, {x+size, y-size/4} }; + + CGContextBeginPath(context); CGContextAddLines(context, arrow, 3); CGContextStrokePath(context); } @@ -291,14 +303,17 @@ static void DrawUpArrow( CGFloat *rgba) { CGFloat x, y; + CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]); CGContextSetLineWidth(context, 1.5); x = bounds.origin.x + inset; y = bounds.origin.y + trunc(bounds.size.height/2); - CGContextBeginPath(context); + CGPoint arrow[3] = { {x, y+size/4}, {x+size/2, y-size/4}, {x+size, y+size/4} }; + + CGContextBeginPath(context); CGContextAddLines(context, arrow, 3); CGContextStrokePath(context); } @@ -368,6 +383,7 @@ static void DrawListHeader( if (state & TTK_TREEVIEW_STATE_SORTARROW) { CGRect arrowBounds = bounds; + arrowBounds.origin.x = bounds.origin.x + bounds.size.width - 16; arrowBounds.size.width = 16; if (state & TTK_STATE_ALTERNATE) { @@ -413,7 +429,6 @@ static CGFloat darkInactiveGradient[8] = {89.0/255, 90.0/255, 93.0/255, 1.0, static CGFloat darkSelectedGradient[8] = {23.0/255, 111.0/255, 232.0/255, 1.0, 20.0/255, 94.0/255, 206.0/255, 1.0}; - /*---------------------------------------------------------------------- * GradientFillRoundedRectangle -- * @@ -424,7 +439,7 @@ static void GradientFillRoundedRectangle( CGContextRef context, CGRect bounds, CGFloat radius, - CGFloat* colors, + CGFloat *colors, int numColors) { NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; @@ -435,6 +450,7 @@ static void GradientFillRoundedRectangle( }; CGGradientRef gradient = CGGradientCreateWithColorComponents( deviceRGB.CGColorSpace, colors, NULL, numColors); + path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); CGContextBeginPath(context); CGContextAddPath(context, path); @@ -452,14 +468,17 @@ static void DrawUpDownArrows( CGFloat *rgba) { CGFloat x, y; + CGContextSetRGBStrokeColor(context, rgba[0], rgba[1], rgba[2], rgba[3]); CGContextSetLineWidth(context, 1.5); x = bounds.origin.x + inset; y = bounds.origin.y + trunc(bounds.size.height/2); CGContextBeginPath(context); + CGPoint bottomArrow[3] = {{x, y+2}, {x+size/2, y+2+size/2}, {x+size, y+2}}; - CGContextAddLines(context, bottomArrow, 3); CGPoint topArrow[3] = {{x, y-2}, {x+size/2, y-2-size/2}, {x+size, y-2}}; + + CGContextAddLines(context, bottomArrow, 3); CGContextAddLines(context, topArrow, 3); CGContextStrokePath(context); } @@ -483,6 +502,7 @@ static void FillButtonBackground( bounds.origin.x, bounds.origin.y + bounds.size.height }; + CGContextBeginPath(context); path = CGPathCreateWithRoundedRect(bounds, radius, radius, NULL); CGContextAddPath(context, path); @@ -508,6 +528,7 @@ static void HighlightButtonBorder( CGPoint topEnd = {bounds.origin.x, bounds.origin.y + 3}; CGGradientRef topGradient = CGGradientCreateWithColorComponents( deviceRGB.CGColorSpace, darkTopGradient, NULL, 2); + CGContextSaveGState(context); CGContextBeginPath(context); CGContextAddArc(context, bounds.origin.x + 4, bounds.origin.y + 4, @@ -576,6 +597,7 @@ static void DrawDarkButton( if (kind == kThemePopupButton | kind == kThemeComboBox) { CGRect arrowBounds = bounds; + arrowBounds.size.width = 16; arrowBounds.origin.x += bounds.size.width - 16; @@ -584,9 +606,9 @@ static void DrawDarkButton( */ if (!(state & TTK_STATE_BACKGROUND) && - !(state & TTK_STATE_DISABLED)) { + !(state & TTK_STATE_DISABLED)) { GradientFillRoundedRectangle(context, arrowBounds, 4, - darkSelectedGradient, 2); + darkSelectedGradient, 2); } if (kind == kThemePopupButton) { DrawUpDownArrows(context, arrowBounds, 3, 7, whiteRGBA); @@ -601,8 +623,8 @@ static void DrawDarkButton( /*---------------------------------------------------------------------- * DrawDarkIncDecButton -- * - * This is a standalone drawing procedure which draws an IncDecButton - * (as used in a Spinbox) in the Dark Mode style. + * This is a standalone drawing procedure which draws an IncDecButton (as + * used in a Spinbox) in the Dark Mode style. */ static void DrawDarkIncDecButton( @@ -640,6 +662,7 @@ static void DrawDarkIncDecButton( if (state & TTK_STATE_PRESSED) { CGRect clip = bounds; + clip.size.height /= 2; CGContextSaveGState(context); if (drawState == kThemeStatePressedDown) { @@ -647,7 +670,7 @@ static void DrawDarkIncDecButton( } CGContextClipToRect(context, clip); GradientFillRoundedRectangle(context, bounds, 5, - darkSelectedGradient, 2); + darkSelectedGradient, 2); CGContextRestoreGState(context); } DrawUpDownArrows(context, bounds, 3, 5, whiteRGBA); @@ -714,6 +737,7 @@ static void DrawDarkCheckBox( NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *stroke; CGFloat x, y; + bounds = CGRectOffset(checkbounds, bounds.origin.x, bounds.origin.y); x = bounds.origin.x; y = bounds.origin.y; @@ -741,15 +765,17 @@ static void DrawDarkCheckBox( CGContextSetStrokeColorWithColor(context, stroke.CGColor); } if (state & TTK_STATE_SELECTED) { + CGPoint check[3] = {{x+4, y+8}, {x+7, y+11}, {x+11, y+4}}; + CGContextSetLineWidth(context, 1.5); CGContextBeginPath(context); - CGPoint check[3] = {{x+4, y+8}, {x+7, y+11}, {x+11, y+4}}; CGContextAddLines(context, check, 3); CGContextStrokePath(context); } else if (state & TTK_STATE_ALTERNATE) { + CGPoint bar[2] = {{x+4, y+8}, {x+12, y+8}}; + CGContextSetLineWidth(context, 2.0); CGContextBeginPath(context); - CGPoint bar[2] = {{x+4, y+8}, {x+12, y+8}}; CGContextAddLines(context, bar, 2); CGContextStrokePath(context); } @@ -758,8 +784,8 @@ static void DrawDarkCheckBox( /*---------------------------------------------------------------------- * DrawDarkRadioButton -- * - * This is a standalone drawing procedure which draws RadioButtons - * in the Dark Mode style. + * This is a standalone drawing procedure which draws RadioButtons in the + * Dark Mode style. */ static void DrawDarkRadioButton( @@ -771,6 +797,7 @@ static void DrawDarkRadioButton( NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *fill; CGFloat x, y; + bounds = CGRectOffset(checkbounds, bounds.origin.x, bounds.origin.y); x = bounds.origin.x; y = bounds.origin.y; @@ -798,12 +825,14 @@ static void DrawDarkRadioButton( CGContextSetFillColorWithColor(context, fill.CGColor); } if (state & TTK_STATE_SELECTED) { - CGContextBeginPath(context); CGRect dot = {{x + 6, y + 6}, {6, 6}}; + + CGContextBeginPath(context); CGContextAddEllipseInRect(context, dot); CGContextFillPath(context); } else if (state & TTK_STATE_ALTERNATE) { CGRect bar = {{x + 5, y + 8}, {8, 2}}; + CGContextFillRect(context, bar); } } @@ -873,9 +902,9 @@ static void DrawDarkTab( CGContextSetStrokeColorWithColor(context, stroke.CGColor); CGContextBeginPath(context); CGContextMoveToPoint(context, originalBounds.origin.x, - originalBounds.origin.y + 1); + originalBounds.origin.y + 1); CGContextAddLineToPoint(context, originalBounds.origin.x, - originalBounds.origin.y + originalBounds.size.height - 1); + originalBounds.origin.y + originalBounds.size.height - 1); CGContextStrokePath(context); CGContextRestoreGState(context); } @@ -891,7 +920,7 @@ static void DrawDarkTab( } if (!(state & TTK_STATE_BACKGROUND)) { GradientFillRoundedRectangle(context, bounds, 4, - darkSelectedGradient, 2); + darkSelectedGradient, 2); } else { faceColor = [NSColor colorWithColorSpace: deviceRGB components: darkInactiveSelectedTab @@ -901,12 +930,12 @@ static void DrawDarkTab( HighlightButtonBorder(context, bounds); } } - + /*---------------------------------------------------------------------- * DrawDarkSeparator -- * - * This is a standalone drawing procedure which draws a separator widget - * in Dark Mode. + * This is a standalone drawing procedure which draws a separator widget in + * Dark Mode. */ static void DrawDarkSeparator( @@ -919,15 +948,16 @@ static void DrawDarkSeparator( NSColor *fillColor = [NSColor colorWithColorSpace: deviceRGB components: fill count:4]; + CGContextSetFillColorWithColor(context, fillColor.CGColor); CGContextFillRect(context, bounds); } - + /*---------------------------------------------------------------------- * DrawDarkFrame -- * - * This is a standalone drawing procedure which draws various - * types of borders in Dark Mode. + * This is a standalone drawing procedure which draws various types of + * borders in Dark Mode. */ static void DrawDarkFrame( @@ -937,7 +967,6 @@ static void DrawDarkFrame( { NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *stroke; - CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace); CGFloat x = bounds.origin.x, y = bounds.origin.y; CGFloat w = bounds.size.width, h = bounds.size.height; CGPoint topPart[4] = { @@ -945,7 +974,9 @@ static void DrawDarkFrame( }; CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}}; CGPoint accent[2] = {{x, y + 1}, {x + w, y + 1}}; - switch(kind) { + + CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace); + switch (kind) { case kHIThemeFrameTextFieldSquare: CGContextSaveGState(context); CGContextSetShouldAntialias(context, false); @@ -978,8 +1009,8 @@ static void DrawDarkFrame( /*---------------------------------------------------------------------- * DrawListHeader -- * - * This is a standalone drawing procedure which draws column - * headers for a Treeview in the Dark Mode. + * This is a standalone drawing procedure which draws column headers for a + * Treeview in the Dark Mode. */ static void DrawDarkListHeader( @@ -990,13 +1021,13 @@ static void DrawDarkListHeader( { NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *stroke; - CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace); CGFloat x = bounds.origin.x, y = bounds.origin.y; CGFloat w = bounds.size.width, h = bounds.size.height; CGPoint top[2] = {{x, y}, {x + w, y}}; CGPoint bottom[2] = {{x, y + h}, {x + w, y + h}}; CGPoint separator[2] = {{x + w, y + 3}, {x + w, y + h - 3}}; + CGContextSetStrokeColorSpace(context, deviceRGB.CGColorSpace); CGContextSaveGState(context); CGContextSetShouldAntialias(context, false); stroke = [NSColor colorWithColorSpace: deviceRGB @@ -1032,8 +1063,8 @@ static void DrawDarkListHeader( */ /* - * When Ttk draws the various types of buttons, a pointer to one of these - * is passed as the clientData. + * When Ttk draws the various types of buttons, a pointer to one of these is + * passed as the clientData. */ typedef struct { @@ -1082,6 +1113,7 @@ static inline HIThemeButtonDrawInfo computeButtonDrawInfo( */ SInt32 HIThemeState; + switch (params->kind) { case kThemePushButton: HIThemeState = kThemeStateActive; @@ -1101,9 +1133,13 @@ static inline HIThemeButtonDrawInfo computeButtonDrawInfo( return info; } -static void ButtonElementMinSize( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *minWidth, int *minHeight, Ttk_Padding *paddingPtr) +static void +ButtonElementMinSize( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *minWidth, int *minHeight, + Ttk_Padding *paddingPtr) { ThemeButtonParams *params = clientData; @@ -1111,9 +1147,8 @@ static void ButtonElementMinSize( ChkErr(GetThemeMetric, params->heightMetric, minHeight); /* - * The theme height does not include the 1-pixel border around - * the button, although it does include the 1-pixel shadow at - * the bottom. + * The theme height does not include the 1-pixel border around the + * button, although it does include the 1-pixel shadow at the bottom. */ *minHeight += 2; @@ -1129,9 +1164,13 @@ static void ButtonElementMinSize( } } -static void ButtonElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *minWidth, int *minHeight, Ttk_Padding *paddingPtr) +static void +ButtonElementSize( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *minWidth, int *minHeight, + Ttk_Padding *paddingPtr) { ThemeButtonParams *params = clientData; const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0, tkwin); @@ -1153,10 +1192,10 @@ static void ButtonElementSize( * to draw a button with a certain bounding rectangle it draws the button * centered within the rectangle. * - * To compute the effective padding around a button we request the - * content and bounding rectangles for a 100x100 button and use the - * padding between those. However, we symmetrize the padding on the - * top and bottom, because that is how the button will be drawn. + * To compute the effective padding around a button we request the content + * and bounding rectangles for a 100x100 button and use the padding between + * those. However, we symmetrize the padding on the top and bottom, because + * that is how the button will be drawn. */ ChkErr(HIThemeGetButtonContentBounds, @@ -1170,16 +1209,21 @@ static void ButtonElementSize( paddingPtr->top = paddingPtr->bottom = verticalPad / 2; } -static void ButtonElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, Ttk_State state) +static void +ButtonElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + Ttk_State state) { ThemeButtonParams *params = clientData; CGRect bounds = BoxToRect(d, b); HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state, tkwin); bounds = NormalizeButtonBounds(params->heightMetric, bounds); - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); if (TkMacOSXInDarkMode(tkwin)) { #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 switch (info.kind) { @@ -1235,7 +1279,7 @@ static void ButtonElementDraw( ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec ButtonElementSpec = { @@ -1315,18 +1359,26 @@ static Ttk_StateTable TabPositionTable[] = { * TP30000359-TPXREF116> */ -static void TabElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *minWidth, int *minHeight, Ttk_Padding *paddingPtr) +static void +TabElementSize( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *minWidth, int *minHeight, + Ttk_Padding *paddingPtr) { - GetThemeMetric(kThemeMetricLargeTabHeight, (SInt32 *)minHeight); + GetThemeMetric(kThemeMetricLargeTabHeight, (SInt32 *) minHeight); *paddingPtr = Ttk_MakePadding(0, 0, 0, 2); - } -static void TabElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, Ttk_State state) +static void +TabElementDraw( + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + Ttk_State state) { CGRect bounds = BoxToRect(d, b); HIThemeTabDrawInfo info = { @@ -1338,7 +1390,8 @@ static void TabElementDraw( .kind = kHIThemeTabKindNormal, .position = Ttk_StateTableLookup(TabPositionTable, state), }; - BEGIN_DRAWING(d) + + BEGIN_DRAWING(d); #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 if (TkMacOSXInDarkMode(tkwin)) { DrawDarkTab(bounds, state, dc.context); @@ -1348,7 +1401,7 @@ static void TabElementDraw( #else ChkErr(HIThemeDrawTab, &bounds, &info, dc.context, HIOrientation, NULL); #endif - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec TabElementSpec = { @@ -1375,27 +1428,28 @@ static void PaneElementDraw( Drawable d, Ttk_Box b, Ttk_State state) { CGRect bounds = BoxToRect(d, b); + bounds.origin.y -= kThemeMetricTabFrameOverlap; bounds.size.height += kThemeMetricTabFrameOverlap; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); if ([NSApp macMinorVersion] > 9) { #if MAC_OS_X_VERSION_MAX_ALLOWED > 1080 - DrawGroupBox(bounds, dc.context, tkwin); + DrawGroupBox(bounds, dc.context, tkwin); #endif } else { - HIThemeTabPaneDrawInfo info = { - .version = 1, - .state = Ttk_StateTableLookup(ThemeStateTable, state), - .direction = kThemeTabNorth, - .size = kHIThemeTabSizeNormal, - .kind = kHIThemeTabKindNormal, - .adornment = kHIThemeTabPaneAdornmentNormal, - }; - bounds.origin.y -= kThemeMetricTabFrameOverlap; - bounds.size.height += kThemeMetricTabFrameOverlap; - ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation); + HIThemeTabPaneDrawInfo info = { + .version = 1, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .direction = kThemeTabNorth, + .size = kHIThemeTabSizeNormal, + .kind = kHIThemeTabKindNormal, + .adornment = kHIThemeTabPaneAdornmentNormal, + }; + bounds.origin.y -= kThemeMetricTabFrameOverlap; + bounds.size.height += kThemeMetricTabFrameOverlap; + ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec PaneElementSpec = { @@ -1418,32 +1472,39 @@ static Ttk_ElementSpec PaneElementSpec = { */ static void GroupElementSize( - void *clientData, void *elementRecord, Tk_Window tkwin, - int *minWidth, int *minHeight, Ttk_Padding *paddingPtr) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + int *minWidth, int *minHeight, + Ttk_Padding *paddingPtr) { *paddingPtr = Ttk_UniformPadding(4); } static void GroupElementDraw( - void *clientData, void *elementRecord, Tk_Window tkwin, - Drawable d, Ttk_Box b, Ttk_State state) + void *clientData, + void *elementRecord, + Tk_Window tkwin, + Drawable d, + Ttk_Box b, + Ttk_State state) { CGRect bounds = BoxToRect(d, b); - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); if ([NSApp macMinorVersion] > 9) { #if MAC_OS_X_VERSION_MAX_ALLOWED > 1080 - DrawGroupBox(bounds, dc.context, tkwin); + DrawGroupBox(bounds, dc.context, tkwin); #endif } else { - const HIThemeGroupBoxDrawInfo info = { - .version = 0, - .state = Ttk_StateTableLookup(ThemeStateTable, state), - .kind = kHIThemeGroupBoxKindPrimaryOpaque, - }; - ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation); + const HIThemeGroupBoxDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .kind = kHIThemeGroupBoxKindPrimaryOpaque, + }; + ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec GroupElementSpec = { @@ -1469,9 +1530,9 @@ typedef struct { static Ttk_ElementOptionSpec EntryElementOptions[] = { { "-background", TK_OPTION_BORDER, - Tk_Offset(EntryElement,backgroundObj), ENTRY_DEFAULT_BACKGROUND }, + Tk_Offset(EntryElement,backgroundObj), ENTRY_DEFAULT_BACKGROUND }, { "-fieldbackground", TK_OPTION_BORDER, - Tk_Offset(EntryElement,fieldbackgroundObj), ENTRY_DEFAULT_BACKGROUND }, + Tk_Offset(EntryElement,fieldbackgroundObj), ENTRY_DEFAULT_BACKGROUND }, {0} }; @@ -1495,9 +1556,10 @@ static void EntryElementDraw( if (TkMacOSXInDarkMode(tkwin)) { #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; CGFloat fill[4]; + GetBackgroundColor(dc.context, tkwin, 1, fill); background = [NSColor colorWithColorSpace: deviceRGB components: fill @@ -1505,7 +1567,7 @@ static void EntryElementDraw( CGContextSetFillColorWithColor(dc.context, background.CGColor); CGContextFillRect(dc.context, bounds); DrawDarkFrame(bounds, dc.context, kHIThemeFrameTextFieldSquare); - END_DRAWING + END_DRAWING; #endif } else { const HIThemeFrameDrawInfo info = { @@ -1534,7 +1596,7 @@ static void EntryElementDraw( Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC), inner.x, inner.y, inner.width, inner.height); } - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); if (backgroundPtr == NULL) { background = [NSColor textBackgroundColor]; #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080 @@ -1545,7 +1607,7 @@ static void EntryElementDraw( CGContextFillRect(dc.context, bounds); } ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation); - END_DRAWING + END_DRAWING; } /*if (state & TTK_STATE_FOCUS) { ChkErr(DrawThemeFocusRect, &bounds, 1); @@ -1604,26 +1666,26 @@ static void ComboboxElementDraw( .adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state), }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); bounds.origin.y += 1; if (TkMacOSXInDarkMode(tkwin)) { #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 bounds.size.height += 1; DrawDarkButton(bounds, info.kind, state, dc.context); #endif - } else - { + } else { #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080 if ((state & TTK_STATE_BACKGROUND) && - !(state & TTK_STATE_DISABLED)) { + !(state & TTK_STATE_DISABLED)) { NSColor *background = [NSColor textBackgroundColor]; CGRect innerBounds = CGRectInset(bounds, 1, 2); + SolidFillRoundedRectangle(dc.context, innerBounds, 4, background); } #endif ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec ComboboxElementSpec = { @@ -1674,12 +1736,14 @@ static void SpinButtonUpElementDraw( { CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins)); int infoState; + bounds.size.height *= 2; if (state & TTK_STATE_PRESSED) { infoState = kThemeStatePressedUp; } else { infoState = Ttk_StateTableLookup(ThemeStateTable, state); } + const HIThemeButtonDrawInfo info = { .version = 0, .state = infoState, @@ -1687,7 +1751,8 @@ static void SpinButtonUpElementDraw( .value = Ttk_StateTableLookup(ButtonValueTable, state), .adornment = kThemeAdornmentNone, }; - BEGIN_DRAWING(d) + + BEGIN_DRAWING(d); #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 if (TkMacOSXInDarkMode(tkwin)) { DrawDarkIncDecButton(bounds, infoState, state, dc.context); @@ -1696,7 +1761,7 @@ static void SpinButtonUpElementDraw( { ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec SpinButtonUpElementSpec = { @@ -1725,12 +1790,13 @@ static void SpinButtonDownElementDraw( { CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins)); int infoState = 0; + bounds.origin.y -= bounds.size.height; bounds.size.height *= 2; if (state & TTK_STATE_PRESSED) { infoState = kThemeStatePressedDown; } else { - return; + return; // ??? } const HIThemeButtonDrawInfo info = { .version = 0, @@ -1740,16 +1806,17 @@ static void SpinButtonDownElementDraw( .adornment = kThemeAdornmentNone, }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 if (TkMacOSXInDarkMode(tkwin)) { DrawDarkIncDecButton(bounds, infoState, state, dc.context); } else #endif { - ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, + NULL); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec SpinButtonDownElementSpec = { @@ -1850,7 +1917,7 @@ static void TrackElementDraw( info.trackInfo.slider.thumbDir = kThemeThumbPlain; } } - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 if (TkMacOSXInDarkMode(tkwin)) { CGRect bounds = BoxToRect(d, b); @@ -1858,6 +1925,7 @@ static void TrackElementDraw( NSColor *trackColor = [NSColor colorWithColorSpace: deviceRGB components: darkTrack count: 4]; + if (orientation == TTK_ORIENT_HORIZONTAL) { bounds = CGRectInset(bounds, 1, bounds.size.height/2 - 2); } else { @@ -1867,7 +1935,7 @@ static void TrackElementDraw( } #endif ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation); - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec TrackElementSpec = { @@ -1887,6 +1955,7 @@ static Ttk_ElementSpec TrackElementSpec = { * Also buggy: The geometry here is a Wild-Assed-Guess; I can't figure out how * to get the Appearance Manager to tell me the slider size. */ + static void SliderElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *minWidth, int *minHeight, Ttk_Padding *paddingPtr) @@ -1971,7 +2040,7 @@ static void PbarElementDraw( .trackInfo.progress.phase = phase, }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 if (TkMacOSXInDarkMode(tkwin)) { CGRect bounds = BoxToRect(d, b); @@ -1988,7 +2057,7 @@ static void PbarElementDraw( } #endif ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation); - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec PbarElementSpec = { @@ -2054,6 +2123,7 @@ static void TroughElementDraw( NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *troughColor; CGFloat *rgba = TkMacOSXInDarkMode(tkwin) ? darkTrough : lightTrough; + Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation); if (orientation == TTK_ORIENT_HORIZONTAL) { bounds = CGRectInset(bounds, 0, 1); @@ -2063,7 +2133,7 @@ static void TroughElementDraw( troughColor = [NSColor colorWithColorSpace: deviceRGB components: rgba count: 4]; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); if ([NSApp macMinorVersion] > 8) { #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080 CGContextSetFillColorWithColor(dc.context, troughColor.CGColor); @@ -2073,7 +2143,7 @@ static void TroughElementDraw( dc.context, HIOrientation); } CGContextFillRect(dc.context, bounds); - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec TroughElementSpec = { @@ -2105,6 +2175,7 @@ static void ThumbElementDraw( { ScrollbarElement *scrollbar = elementRecord; int orientation = TTK_ORIENT_HORIZONTAL; + Ttk_GetOrientFromObj(NULL, scrollbar->orientObj, &orientation); /* @@ -2129,15 +2200,18 @@ static void ThumbElementDraw( NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *thumbColor; CGFloat *rgba; - if ((orientation == TTK_ORIENT_HORIZONTAL && - thumbBounds.size.width >= Tk_Width(tkwin) - 8) || - (orientation == TTK_ORIENT_VERTICAL && - thumbBounds.size.height >= Tk_Height(tkwin) - 8)) { + + if ((orientation == TTK_ORIENT_HORIZONTAL + && thumbBounds.size.width >= Tk_Width(tkwin) - 8) + || (orientation == TTK_ORIENT_VERTICAL + && thumbBounds.size.height >= Tk_Height(tkwin) - 8)) { return; } + int isDark = TkMacOSXInDarkMode(tkwin); + if ((state & TTK_STATE_PRESSED) || - (state & TTK_STATE_HOVER) ) { + (state & TTK_STATE_HOVER)) { rgba = isDark ? darkActiveThumb : lightActiveThumb; } else { rgba = isDark ? darkInactiveThumb : lightInactiveThumb; @@ -2145,9 +2219,9 @@ static void ThumbElementDraw( thumbColor = [NSColor colorWithColorSpace: deviceRGB components: rgba count: 4]; - BEGIN_DRAWING(d) - SolidFillRoundedRectangle(dc.context, thumbBounds, 4, thumbColor); - END_DRAWING + BEGIN_DRAWING(d); + SolidFillRoundedRectangle(dc.context, thumbBounds, 4, thumbColor); + END_DRAWING; #endif } else { double thumbSize, trackSize, visibleSize, viewSize; @@ -2164,6 +2238,7 @@ static void ThumbElementDraw( */ viewSize = RangeToFactor(100.0); + HIThemeTrackDrawInfo info = { .version = 0, .bounds = troughBounds, @@ -2171,6 +2246,7 @@ static void ThumbElementDraw( .attributes = kThemeTrackShowThumb | kThemeTrackThumbRgnIsNotGhost, .enableState = kThemeTrackActive }; + info.trackInfo.scrollbar.viewsize = viewSize*.8; if (orientation == TTK_ORIENT_HORIZONTAL) { trackSize = troughBounds.size.width; @@ -2186,7 +2262,7 @@ static void ThumbElementDraw( info.value = info.max * (b.y / (trackSize - thumbSize)); } if ((state & TTK_STATE_PRESSED) || - (state & TTK_STATE_HOVER) ) { + (state & TTK_STATE_HOVER)) { info.trackInfo.scrollbar.pressState = kThemeThumbPressed; } else { info.trackInfo.scrollbar.pressState = 0; @@ -2196,10 +2272,10 @@ static void ThumbElementDraw( } else { info.attributes &= ~kThemeTrackHorizontal; } - BEGIN_DRAWING(d) - HIThemeDrawTrack (&info, 0, dc.context, kHIThemeOrientationNormal); - END_DRAWING - } + BEGIN_DRAWING(d); + HIThemeDrawTrack(&info, 0, dc.context, kHIThemeOrientationNormal); + END_DRAWING; + } } static Ttk_ElementSpec ThumbElementSpec = { @@ -2255,7 +2331,7 @@ static void SeparatorElementDraw( .state = Ttk_StateTableLookup(ThemeStateTable, state & TTK_STATE_BACKGROUND), }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); #if MAC_OS_X_VERSION_MIN_REQUIRED > 101300 if (TkMacOSXInDarkMode(tkwin)) { DrawDarkSeparator(bounds, dc.context, tkwin); @@ -2265,7 +2341,7 @@ static void SeparatorElementDraw( #else ChkErr(HIThemeDrawSeparator, &bounds, &info, dc.context, HIOrientation); #endif - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec SeparatorElementSpec = { @@ -2316,9 +2392,9 @@ static void SizegripElementDraw( .size = kHIThemeGrowBoxSizeNormal, }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); ChkErr(HIThemeDrawGrowBox, &bounds.origin, &info, dc.context, HIOrientation); - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec SizegripElementSpec = { @@ -2381,23 +2457,25 @@ static void FillElementDraw( NSColorSpace *deviceRGB = [NSColorSpace deviceRGBColorSpace]; NSColor *bgColor; CGFloat fill[4]; - BEGIN_DRAWING(d) + + BEGIN_DRAWING(d); GetBackgroundColor(dc.context, tkwin, 0, fill); bgColor = [NSColor colorWithColorSpace: deviceRGB components: fill count: 4]; CGContextSetFillColorSpace(dc.context, deviceRGB.CGColorSpace); CGContextSetFillColorWithColor(dc.context, bgColor.CGColor); CGContextFillRect(dc.context, bounds); - END_DRAWING + END_DRAWING; #else ThemeBrush brush = (state & TTK_STATE_BACKGROUND) ? kThemeBrushModelessDialogBackgroundInactive : kThemeBrushModelessDialogBackgroundActive; - BEGIN_DRAWING(d) + + BEGIN_DRAWING(d); ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation); //QDSetPatternOrigin(PatternOrigin(tkwin, d)); CGContextFillRect(dc.context, bounds); - END_DRAWING + END_DRAWING; #endif } @@ -2406,7 +2484,7 @@ static void BackgroundElementDraw( Drawable d, Ttk_Box b, unsigned int state) { FillElementDraw(clientData, elementRecord, tkwin, d, Ttk_WinBox(tkwin), - state); + state); } static Ttk_ElementSpec FillElementSpec = { @@ -2429,9 +2507,9 @@ static Ttk_ElementSpec BackgroundElementSpec = { * +++ ToolbarBackground element -- toolbar style for frames. * * This is very similar to the normal background element, but uses a - * different ThemeBrush in order to get the lighter pinstripe effect - * used in toolbars. We use SetThemeBackground() rather than - * ApplyThemeBackground() in order to get the right style. + * different ThemeBrush in order to get the lighter pinstripe effect used in + * toolbars. We use SetThemeBackground() rather than ApplyThemeBackground() + * in order to get the right style. * * <URL: http://developer.apple.com/documentation/Carbon/Reference/ * Appearance_Manager/appearance_manager/constant_7.html#/ @@ -2446,11 +2524,11 @@ static void ToolbarBackgroundElementDraw( ThemeBrush brush = kThemeBrushToolbarBackground; CGRect bounds = BoxToRect(d, Ttk_WinBox(tkwin)); - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation); //QDSetPatternOrigin(PatternOrigin(tkwin, d)); CGContextFillRect(dc.context, bounds); - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec ToolbarBackgroundElementSpec = { @@ -2517,7 +2595,7 @@ static Ttk_StateTable TreeHeaderAdornmentTable[] = { { kThemeAdornmentNone, 0} }; -static void TreeAreaElementSize ( +static void TreeAreaElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *minWidth, int *minHeight, Ttk_Padding *paddingPtr) { @@ -2565,13 +2643,12 @@ static void TreeHeaderElementDraw( .adornment = Ttk_StateTableLookup(TreeHeaderAdornmentTable, state), }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); if ([NSApp macMinorVersion] > 8) { #if MAC_OS_X_VERSION_MIN_REQUIRED > 1080 - /* - * Compensate for the padding added in TreeHeaderElementSize, so - * the larger heading will be drawn at the top of the widget. + * Compensate for the padding added in TreeHeaderElementSize, so the + * larger heading will be drawn at the top of the widget. */ bounds.origin.y -= 4; @@ -2586,7 +2663,7 @@ static void TreeHeaderElementDraw( } else { ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); } - END_DRAWING + END_DRAWING; } static Ttk_ElementSpec TreeHeaderElementSpec = { @@ -2636,9 +2713,9 @@ static void DisclosureElementDraw( .adornment = kThemeAdornmentDrawIndicatorOnly, }; - BEGIN_DRAWING(d) + BEGIN_DRAWING(d); ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); - END_DRAWING + END_DRAWING; } } @@ -2735,13 +2812,15 @@ TTK_LAYOUT("Horizontal.TScrollbar", TTK_NODE("Horizontal.Scrollbar.rightarrow", TTK_PACK_RIGHT) TTK_NODE("Horizontal.Scrollbar.leftarrow", TTK_PACK_RIGHT))) -TTK_END_LAYOUT_TABLE +TTK_END_LAYOUT_TABLE; /*---------------------------------------------------------------------- * +++ Initialization. */ -static int AquaTheme_Init(Tcl_Interp *interp) +static int +AquaTheme_Init( + Tcl_Interp *interp) { Ttk_Theme themePtr = Ttk_CreateTheme(interp, "aqua", NULL); @@ -2752,38 +2831,41 @@ static int AquaTheme_Init(Tcl_Interp *interp) /* * Elements: */ + Ttk_RegisterElementSpec(themePtr, "background", &BackgroundElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "fill", &FillElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "field", &FieldElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Toolbar.background", - &ToolbarBackgroundElementSpec, 0); + &ToolbarBackgroundElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Button.button", - &ButtonElementSpec, &PushButtonParams); + &ButtonElementSpec, &PushButtonParams); Ttk_RegisterElementSpec(themePtr, "Checkbutton.button", - &ButtonElementSpec, &CheckBoxParams); + &ButtonElementSpec, &CheckBoxParams); Ttk_RegisterElementSpec(themePtr, "Radiobutton.button", - &ButtonElementSpec, &RadioButtonParams); + &ButtonElementSpec, &RadioButtonParams); Ttk_RegisterElementSpec(themePtr, "Toolbutton.border", - &ButtonElementSpec, &BevelButtonParams); + &ButtonElementSpec, &BevelButtonParams); Ttk_RegisterElementSpec(themePtr, "Menubutton.button", - &ButtonElementSpec, &PopupButtonParams); + &ButtonElementSpec, &PopupButtonParams); Ttk_RegisterElementSpec(themePtr, "Spinbox.uparrow", - &SpinButtonUpElementSpec, 0); + &SpinButtonUpElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Spinbox.downarrow", - &SpinButtonDownElementSpec, 0); + &SpinButtonDownElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Combobox.button", - &ComboboxElementSpec, 0); + &ComboboxElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Treeitem.indicator", - &DisclosureElementSpec, &DisclosureParams); + &DisclosureElementSpec, &DisclosureParams); Ttk_RegisterElementSpec(themePtr, "Treeheading.cell", - &TreeHeaderElementSpec, &ListHeaderParams); + &TreeHeaderElementSpec, &ListHeaderParams); - Ttk_RegisterElementSpec(themePtr, "Treeview.treearea", &TreeAreaElementSpec, 0); + Ttk_RegisterElementSpec(themePtr, "Treeview.treearea", + &TreeAreaElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Notebook.tab", &TabElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Notebook.client", &PaneElementSpec, 0); - Ttk_RegisterElementSpec(themePtr, "Labelframe.border", &GroupElementSpec, 0); + Ttk_RegisterElementSpec(themePtr, "Labelframe.border", + &GroupElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Entry.field", &EntryElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Spinbox.field", &EntryElementSpec, 0); @@ -2803,23 +2885,31 @@ static int AquaTheme_Init(Tcl_Interp *interp) Ttk_RegisterElementSpec(themePtr,"Progressbar.track", &PbarElementSpec, 0); Ttk_RegisterElementSpec(themePtr,"Scale.trough", &TrackElementSpec, - &ScaleData); + &ScaleData); Ttk_RegisterElementSpec(themePtr,"Scale.slider", &SliderElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.trough", &TroughElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.thumb", &ThumbElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.trough", &TroughElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.thumb", &ThumbElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.trough", + &TroughElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.thumb", + &ThumbElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.trough", + &TroughElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.thumb", + &ThumbElementSpec, 0); /* * If we are not in Snow Leopard or Lion the arrows won't actually be * displayed. */ - Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.uparrow", &ArrowElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.downarrow", &ArrowElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.leftarrow", &ArrowElementSpec, 0); - Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.rightarrow", &ArrowElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.uparrow", + &ArrowElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Vertical.Scrollbar.downarrow", + &ArrowElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.leftarrow", + &ArrowElementSpec, 0); + Ttk_RegisterElementSpec(themePtr,"Horizontal.Scrollbar.rightarrow", + &ArrowElementSpec, 0); /* * Layouts: |