From 2bc6576988e60413ca7873f9c9899f9f1f012564 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 10 Jun 2024 20:10:22 +0000 Subject: Better solution for [4d0a6f32b7], which doesn't cache padX/padY/borderWidth/hightlightWidth any more: If scaling changes, it needs to be re-calculated, which wasn't taken into account. Done for 'button' and 'message' --- generic/tkButton.c | 22 +++ generic/tkMessage.c | 28 +++- macosx/tkMacOSXButton.c | 354 +++++++++++++++++++++++++----------------------- unix/tkUnixButton.c | 36 +++-- win/tkWinButton.c | 22 ++- 5 files changed, 270 insertions(+), 192 deletions(-) diff --git a/generic/tkButton.c b/generic/tkButton.c index cbbe880..2ec939e 100644 --- a/generic/tkButton.c +++ b/generic/tkButton.c @@ -1099,15 +1099,35 @@ ConfigureButton( } if (butPtr->borderWidth < 0) { butPtr->borderWidth = 0; + if (butPtr->borderWidthPtr) { + Tcl_DecrRefCount(butPtr->borderWidthPtr); + } + butPtr->borderWidthPtr = Tcl_NewIntObj(0); + Tcl_IncrRefCount(butPtr->borderWidthPtr); } if (butPtr->highlightWidth < 0) { butPtr->highlightWidth = 0; + if (butPtr->highlightWidthPtr) { + Tcl_DecrRefCount(butPtr->highlightWidthPtr); + } + butPtr->highlightWidthPtr = Tcl_NewIntObj(0); + Tcl_IncrRefCount(butPtr->highlightWidthPtr); } if (butPtr->padX < 0) { butPtr->padX = 0; + if (butPtr->padXPtr) { + Tcl_DecrRefCount(butPtr->padXPtr); + } + butPtr->padXPtr = Tcl_NewIntObj(0); + Tcl_IncrRefCount(butPtr->padXPtr); } if (butPtr->padY < 0) { butPtr->padY = 0; + if (butPtr->padYPtr) { + Tcl_DecrRefCount(butPtr->padYPtr); + } + butPtr->padYPtr = Tcl_NewIntObj(0); + Tcl_IncrRefCount(butPtr->padYPtr); } if (butPtr->type >= TYPE_CHECK_BUTTON) { @@ -1463,6 +1483,7 @@ ButtonEventProc( } else if (eventPtr->type == FocusIn) { if (eventPtr->xfocus.detail != NotifyInferior) { butPtr->flags |= GOT_FOCUS; + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); if (butPtr->highlightWidth > 0) { goto redraw; } @@ -1470,6 +1491,7 @@ ButtonEventProc( } else if (eventPtr->type == FocusOut) { if (eventPtr->xfocus.detail != NotifyInferior) { butPtr->flags &= ~GOT_FOCUS; + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); if (butPtr->highlightWidth > 0) { goto redraw; } diff --git a/generic/tkMessage.c b/generic/tkMessage.c index 07dad51..05c0c66 100644 --- a/generic/tkMessage.c +++ b/generic/tkMessage.c @@ -505,6 +505,11 @@ ConfigureMessage( if (msgPtr->highlightWidth < 0) { msgPtr->highlightWidth = 0; + if (msgPtr->highlightWidth) { + Tcl_DecrRefCount(msgPtr->highlightWidthObj); + } + msgPtr->highlightWidthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(msgPtr->highlightWidthObj); } Tk_FreeSavedOptions(&savedOptions); @@ -552,10 +557,22 @@ MessageWorldChanged( msgPtr->textGC = gc; Tk_GetFontMetrics(msgPtr->tkfont, &fm); + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXPtr, &msgPtr->padX); if (msgPtr->padX < 0) { + if (strcmp(Tcl_GetString(msgPtr->padXPtr), "-1")) { + Tcl_DecrRefCount(msgPtr->padXPtr); + msgPtr->padXPtr = Tcl_NewIntObj(-1); + Tcl_IncrRefCount(msgPtr->padXPtr); + } msgPtr->padX = fm.ascent / 2; } + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYPtr, &msgPtr->padY); if (msgPtr->padY < 0) { + if (strcmp(Tcl_GetString(msgPtr->padYPtr), "-1")) { + Tcl_DecrRefCount(msgPtr->padYPtr); + msgPtr->padYPtr = Tcl_NewIntObj(-1); + Tcl_IncrRefCount(msgPtr->padYPtr); + } msgPtr->padY = fm.ascent / 4; } @@ -600,6 +617,9 @@ ComputeMessageGeometry( Tk_FreeTextLayout(msgPtr->textLayout); + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &msgPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &msgPtr->highlightWidth); + inset = msgPtr->borderWidth + msgPtr->highlightWidth; /* @@ -679,8 +699,12 @@ DisplayMessage( Message *msgPtr = (Message *)clientData; Tk_Window tkwin = msgPtr->tkwin; int x, y; - int borderWidth = msgPtr->highlightWidth; + int borderWidth; + + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &msgPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &msgPtr->highlightWidth); + borderWidth = msgPtr->highlightWidth; msgPtr->flags &= ~REDRAW_PENDING; if ((msgPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; @@ -762,6 +786,7 @@ MessageEventProc( } else if (eventPtr->type == FocusIn) { if (eventPtr->xfocus.detail != NotifyInferior) { msgPtr->flags |= GOT_FOCUS; + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &msgPtr->highlightWidth); if (msgPtr->highlightWidth > 0) { goto redraw; } @@ -769,6 +794,7 @@ MessageEventProc( } else if (eventPtr->type == FocusOut) { if (eventPtr->xfocus.detail != NotifyInferior) { msgPtr->flags &= ~GOT_FOCUS; + Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &msgPtr->highlightWidth); if (msgPtr->highlightWidth > 0) { goto redraw; } diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 26d0c33..7d231a6 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -194,6 +194,8 @@ TkpDisplayButton( } pixmap = (Pixmap) Tk_WindowId(tkwin); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + if (TkMacOSXComputeButtonDrawParams(butPtr, dpPtr)) { macButtonPtr->useTkText = 0; } else { @@ -208,26 +210,26 @@ TkpDisplayButton( Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); } - /* + /* * 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. */ - TkMacOSXDrawButton(macButtonPtr, dpPtr->gc, pixmap); + TkMacOSXDrawButton(macButtonPtr, dpPtr->gc, pixmap); - /* + /* * Ask for the highlight border, if needed. */ - if (butPtr->highlightWidth < 3) { - needhighlight = 1; - } + if (butPtr->highlightWidth < 3) { + needhighlight = 1; + } } /* @@ -236,7 +238,7 @@ TkpDisplayButton( if (needhighlight) { GC gc = NULL; - if ((butPtr->flags & GOT_FOCUS) && butPtr->highlightColorPtr) { + if ((butPtr->flags & GOT_FOCUS) && butPtr->highlightColorPtr) { gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap); } else if (butPtr->type == TYPE_LABEL) { gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder), pixmap); @@ -313,14 +315,17 @@ TkpComputeButtonGeometry( haveImage = 1; } + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXPtr, &butPtr->padX); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYPtr, &butPtr->padY); + if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) { Tk_FreeTextLayout(butPtr->textLayout); butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont, text, TCL_INDEX_NONE, butPtr->wrapLength, butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight); - txtWidth = butPtr->textWidth + 2*butPtr->padX; - txtHeight = butPtr->textHeight + 2*butPtr->padY; + txtWidth = butPtr->textWidth + 2 * butPtr->padX; + txtHeight = butPtr->textHeight + 2 * butPtr->padY; haveText = 1; } @@ -342,7 +347,7 @@ TkpComputeButtonGeometry( * Image is left or right of text. */ - width += txtWidth + 2*butPtr->padX; + width += txtWidth + 2 * butPtr->padX; height = (height > txtHeight ? height : txtHeight); break; case COMPOUND_CENTER: @@ -368,15 +373,15 @@ TkpComputeButtonGeometry( height += 2; } } else { /* Text only */ - width = txtWidth + butPtr->indicatorSpace; + width = txtWidth + butPtr->indicatorSpace; height = txtHeight; if (butPtr->width > 0) { charWidth = Tk_TextWidth(butPtr->tkfont, "0", 1); - width = butPtr->width * charWidth + 2*butPtr->padX; + width = butPtr->width * charWidth + 2 * butPtr->padX; } if (butPtr->height > 0) { Tk_GetFontMetrics(butPtr->tkfont, &fm); - height = butPtr->height * fm.linespace + 2*butPtr->padY; + height = butPtr->height * fm.linespace + 2 * butPtr->padY; } } @@ -384,19 +389,18 @@ TkpComputeButtonGeometry( * Now figure out the size of the border decorations for the button. */ - if (butPtr->highlightWidth < 0) { - butPtr->highlightWidth = 0; - } + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); butPtr->inset = butPtr->borderWidth + butPtr->highlightWidth; - width += butPtr->inset*2; - height += butPtr->inset*2; + width += butPtr->inset * 2; + height += butPtr->inset * 2; if ([NSApp macOSVersion] == 100600) { width += 12; } if (mbPtr->btnkind == kThemePushButton) { - HIRect tmpRect; + HIRect tmpRect; HIRect contBounds; /* @@ -406,16 +410,16 @@ TkpComputeButtonGeometry( * standard padding. */ - tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY); - HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds); - if (height < contBounds.size.height) { + tmpRect = CGRectMake(0, 0, width + 2 * HI_PADX, height + 2 * HI_PADY); + HIThemeGetButtonContentBounds(&tmpRect, &mbPtr->drawinfo, &contBounds); + if (height < contBounds.size.height) { height = (int)contBounds.size.height; - } - if (width < contBounds.size.width) { + } + if (width < contBounds.size.width) { width = (int)contBounds.size.width; - } - height += 2*HI_PADY; - width += 2*HI_PADX; + } + height += 2 * HI_PADY; + width += 2 * HI_PADX; } Tk_GeometryRequest(butPtr->tkwin, width, height); Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset); @@ -453,31 +457,36 @@ DrawButtonImageAndText( DrawParams *dpPtr = &mbPtr->drawParams; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { - return; + return; } pixmap = (Pixmap) Tk_WindowId(tkwin); if (butPtr->image != NULL) { - Tk_SizeOfImage(butPtr->image, &width, &height); - haveImage = 1; + Tk_SizeOfImage(butPtr->image, &width, &height); + haveImage = 1; } else if (butPtr->bitmap != None) { - Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); - haveImage = 1; + Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); + haveImage = 1; } imageWidth = width; imageHeight = height; if (mbPtr->drawinfo.state == kThemeStatePressed) { - pressed = 1; + pressed = 1; } + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->padXPtr, &butPtr->padX); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->padYPtr, &butPtr->padY); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { /* Image and Text */ - int x, y; + int x, y; - switch ((enum compound) butPtr->compound) { + switch ((enum compound) butPtr->compound) { case COMPOUND_TOP: case COMPOUND_BOTTOM: /* Image is above or below text */ @@ -526,27 +535,27 @@ DrawButtonImageAndText( break; } - TkComputeAnchor(butPtr->anchor, tkwin, - butPtr->padX + butPtr->borderWidth, - butPtr->padY + butPtr->borderWidth, - fullWidth + butPtr->indicatorSpace, fullHeight, &x, &y); + TkComputeAnchor(butPtr->anchor, tkwin, + butPtr->padX + butPtr->borderWidth, + butPtr->padY + butPtr->borderWidth, + fullWidth + butPtr->indicatorSpace, fullHeight, &x, &y); x += butPtr->indicatorSpace; - if (dpPtr->relief == TK_RELIEF_SUNKEN) { - x += dpPtr->offset; - y += dpPtr->offset; - } else if (dpPtr->relief == TK_RELIEF_RAISED) { - x -= dpPtr->offset; - y -= dpPtr->offset; - } - if (pressed) { - x += dpPtr->offset; - y += dpPtr->offset; - } - imageXOffset += x; - imageYOffset += y; - - if (butPtr->image != NULL) { + if (dpPtr->relief == TK_RELIEF_SUNKEN) { + x += dpPtr->offset; + y += dpPtr->offset; + } else if (dpPtr->relief == TK_RELIEF_RAISED) { + x -= dpPtr->offset; + y -= dpPtr->offset; + } + if (pressed) { + 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, @@ -559,29 +568,29 @@ DrawButtonImageAndText( Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, imageXOffset, imageYOffset); } - } else { + } 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); - } + } y += 1; /* Tweak to match native buttons. */ - Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, + Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); - Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc, - butPtr->textLayout, - x + textXOffset, y + textYOffset, - butPtr->underline); + Tk_UnderlineTextLayout(butPtr->display, pixmap, dpPtr->gc, + butPtr->textLayout, + x + textXOffset, y + textYOffset, + butPtr->underline); } else if (haveImage) { /* Image only */ - int x = 0, y; + int x = 0, y; TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX + butPtr->borderWidth, butPtr->padY + butPtr->borderWidth, width + butPtr->indicatorSpace, height, &x, &y); - x += butPtr->indicatorSpace; + x += butPtr->indicatorSpace; if (pressed) { x += dpPtr->offset; y += dpPtr->offset; @@ -610,7 +619,7 @@ DrawButtonImageAndText( XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); } } else { /* Text only */ - int x, y; + int x, y; TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, butPtr->textWidth + butPtr->indicatorSpace, @@ -629,46 +638,46 @@ DrawButtonImageAndText( */ if (mbPtr->useTkText) { - if ((butPtr->state == STATE_DISABLED) - && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) { - if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn - && (butPtr->selectBorder != NULL)) { - XSetForeground(butPtr->display, butPtr->stippleGC, - Tk_3DBorderColor(butPtr->selectBorder)->pixel); - } - /* - * Stipple the whole button if no disabledFg was specified, - * otherwise restrict stippling only to displayed image - */ - if (butPtr->disabledFg == NULL) { - XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, - 0, 0, (unsigned) Tk_Width(tkwin), - (unsigned) Tk_Height(tkwin)); - } else { - XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, - imageXOffset, imageYOffset, - (unsigned) imageWidth, (unsigned) imageHeight); - } - if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn - && (butPtr->selectBorder != NULL) - ) { - XSetForeground(butPtr->display, butPtr->stippleGC, - Tk_3DBorderColor(butPtr->normalBorder)->pixel); - } - } - - /* - * Draw the border and traversal highlight last. This way, if the - * button's contents overflow they'll be covered up by the border. - */ - - if (dpPtr->relief != TK_RELIEF_FLAT) { + if ((butPtr->state == STATE_DISABLED) + && ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) { + if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn + && (butPtr->selectBorder != NULL)) { + XSetForeground(butPtr->display, butPtr->stippleGC, + Tk_3DBorderColor(butPtr->selectBorder)->pixel); + } + /* + * Stipple the whole button if no disabledFg was specified, + * otherwise restrict stippling only to displayed image + */ + if (butPtr->disabledFg == NULL) { + XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, + 0, 0, (unsigned) Tk_Width(tkwin), + (unsigned) Tk_Height(tkwin)); + } else { + XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, + imageXOffset, imageYOffset, + (unsigned) imageWidth, (unsigned) imageHeight); + } + if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn + && (butPtr->selectBorder != NULL) + ) { + XSetForeground(butPtr->display, butPtr->stippleGC, + Tk_3DBorderColor(butPtr->normalBorder)->pixel); + } + } + + /* + * Draw the border and traversal highlight last. This way, if the + * button's contents overflow they'll be covered up by the border. + */ + + 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, + Tk_Width(tkwin) - 2 * inset, Tk_Height(tkwin) - 2 * inset, butPtr->borderWidth, dpPtr->relief); - } + } } } @@ -695,7 +704,7 @@ TkpDestroyButton( MacButton *mbPtr = (MacButton *) butPtr; /* Mac button. */ if (mbPtr->defaultPulseHandler) { - Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler); + Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler); } } @@ -704,11 +713,11 @@ 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. + * None. * * Side effects: * The control is created, or reinitialised as needed @@ -720,9 +729,9 @@ static void TkMacOSXDrawButton( MacButton *mbPtr, /* Mac button. */ TCL_UNUSED(GC), /* The GC we are drawing into - needed for - * the bevel button */ + * the bevel button */ Pixmap pixmap) /* The pixmap we are drawing into - needed - * for the bevel button */ + * for the bevel button */ { TkButton *butPtr = (TkButton *) mbPtr; TkWindow *winPtr = (TkWindow *) butPtr->tkwin; @@ -739,24 +748,24 @@ TkMacOSXDrawButton( cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset); if (useNewerHITools == 1) { - HIRect contHIRec; - static HIThemeButtonDrawInfo hiinfo; + HIRect contHIRec; + static HIThemeButtonDrawInfo hiinfo; - ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true); + ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true); if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, &dc)) { return; } - hiinfo.version = 0; - hiinfo.state = mbPtr->drawinfo.state; - hiinfo.kind = mbPtr->btnkind; - hiinfo.value = mbPtr->drawinfo.value; - hiinfo.adornment = mbPtr->drawinfo.adornment; - hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent(); - if (hiinfo.animation.time.start == 0) { - hiinfo.animation.time.start = hiinfo.animation.time.current; - } + hiinfo.version = 0; + hiinfo.state = mbPtr->drawinfo.state; + hiinfo.kind = mbPtr->btnkind; + hiinfo.value = mbPtr->drawinfo.value; + hiinfo.adornment = mbPtr->drawinfo.adornment; + hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent(); + if (hiinfo.animation.time.start == 0) { + hiinfo.animation.time.start = hiinfo.animation.time.current; + } /* * To avoid buttons with white text on a white background, we set the @@ -776,7 +785,7 @@ TkMacOSXDrawButton( kHIThemeOrientationNormal, &contHIRec); TkMacOSXRestoreDrawingContext(&dc); - ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo, + ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo, (MacButton *) mbPtr, 32, true); } else { if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, &dc)) { @@ -793,14 +802,14 @@ 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. + * None. * * Side effects: - * The background gets updated to the current color. + * The background gets updated to the current color. * *-------------------------------------------------------------- */ @@ -819,26 +828,26 @@ ButtonBackgroundDrawCB( int usehlborder = 0; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { - return; + return; } pixmap = (Pixmap) Tk_WindowId(tkwin); if (butPtr->type != TYPE_LABEL) { - switch (mbPtr->btnkind) { + switch (mbPtr->btnkind) { case kThemeSmallBevelButton: case kThemeBevelButton: case kThemeRoundedBevelButton: case kThemePushButton: usehlborder = 1; break; - } + } } if (usehlborder) { - Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0, - Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); + Tk_Fill3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, 0, + Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); } else { - Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, - Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); + Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, 0, 0, + Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); } } @@ -847,13 +856,13 @@ ButtonBackgroundDrawCB( * * ButtonContentDrawCB -- * - * 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. * *-------------------------------------------------------------- */ @@ -870,7 +879,7 @@ ButtonContentDrawCB ( Tk_Window tkwin = butPtr->tkwin; if (tkwin == NULL || !Tk_IsMapped(tkwin)) { - return; + return; } /* @@ -936,7 +945,7 @@ ButtonEventProc( * None. * * Side effects: - * Sets the btnkind and drawinfo parameters + * Sets the btnkind and drawinfo parameters * *---------------------------------------------------------------------- */ @@ -949,18 +958,21 @@ TkMacOSXComputeButtonParams( { MacButton *mbPtr = (MacButton *) butPtr; + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + if (butPtr->borderWidth <= 2) { - *btnkind = kThemeSmallBevelButton; + *btnkind = kThemeSmallBevelButton; } else if (butPtr->borderWidth == 3) { - *btnkind = kThemeBevelButton; + *btnkind = kThemeBevelButton; } else if (butPtr->borderWidth == 4) { - *btnkind = kThemeRoundedBevelButton; + *btnkind = kThemeRoundedBevelButton; } else { - *btnkind = kThemePushButton; + *btnkind = kThemePushButton; } if ((butPtr->image == NULL) && (butPtr->bitmap == None)) { - switch (butPtr->type) { + switch (butPtr->type) { case TYPE_BUTTON: *btnkind = kThemePushButton; break; @@ -982,7 +994,7 @@ TkMacOSXComputeButtonParams( } if (butPtr->indicatorOn) { - switch (butPtr->type) { + switch (butPtr->type) { case TYPE_RADIO_BUTTON: if (butPtr->borderWidth <= 1) { *btnkind = kThemeSmallRadioButton; @@ -997,22 +1009,22 @@ TkMacOSXComputeButtonParams( *btnkind = kThemeCheckBox; } break; - } + } } else { - if (butPtr->type == TYPE_RADIO_BUTTON || + if (butPtr->type == TYPE_RADIO_BUTTON || butPtr->type == TYPE_CHECK_BUTTON) { if (*btnkind == kThemePushButton) { *btnkind = kThemeBevelButton; } - } + } } if (butPtr->flags & SELECTED) { - drawinfo->value = kThemeButtonOn; + drawinfo->value = kThemeButtonOn; } else if (butPtr->flags & TRISTATED) { - drawinfo->value = kThemeButtonMixed; + drawinfo->value = kThemeButtonMixed; } else { - drawinfo->value = kThemeButtonOff; + drawinfo->value = kThemeButtonOff; } if ((mbPtr->flags & FIRST_DRAW) != 0) { @@ -1024,17 +1036,17 @@ TkMacOSXComputeButtonParams( drawinfo->state = kThemeStateInactive; if ((mbPtr->flags & ACTIVE) == 0) { - if (butPtr->state == STATE_DISABLED) { - drawinfo->state = kThemeStateUnavailableInactive; - } else { - drawinfo->state = kThemeStateInactive; - } + if (butPtr->state == STATE_DISABLED) { + drawinfo->state = kThemeStateUnavailableInactive; + } else { + drawinfo->state = kThemeStateInactive; + } } else if (butPtr->state == STATE_DISABLED) { - drawinfo->state = kThemeStateUnavailable; + drawinfo->state = kThemeStateUnavailable; } else if (butPtr->state == STATE_ACTIVE) { - drawinfo->state = kThemeStatePressed; + drawinfo->state = kThemeStatePressed; } else { - drawinfo->state = kThemeStateActive; + drawinfo->state = kThemeStateActive; } drawinfo->adornment = kThemeAdornmentNone; @@ -1049,17 +1061,17 @@ TkMacOSXComputeButtonParams( * the button periodically. */ - if (!mbPtr->defaultPulseHandler && ([NSApp macOSVersion] <= 100900)) { - mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler( - PULSE_TIMER_MSECS, PulseDefaultButtonProc, butPtr); - } + if (!mbPtr->defaultPulseHandler && ([NSApp macOSVersion] <= 100900)) { + mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler( + PULSE_TIMER_MSECS, PulseDefaultButtonProc, butPtr); + } } else if (mbPtr->defaultPulseHandler) { - Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler); + Tcl_DeleteTimerHandler(mbPtr->defaultPulseHandler); } if (butPtr->highlightWidth >= 3) { - if ((butPtr->flags & GOT_FOCUS)) { - drawinfo->adornment |= kThemeAdornmentFocus; - } + if ((butPtr->flags & GOT_FOCUS)) { + drawinfo->adornment |= kThemeAdornmentFocus; + } } } @@ -1091,17 +1103,17 @@ TkMacOSXComputeButtonDrawParams( || (butPtr->bitmap != None)); if (butPtr->type != TYPE_LABEL) { - dpPtr->offset = 0; - if (dpPtr->hasImageOrBitmap) { - switch (mbPtr->btnkind) { + dpPtr->offset = 0; + if (dpPtr->hasImageOrBitmap) { + switch (mbPtr->btnkind) { case kThemeSmallBevelButton: case kThemeBevelButton: case kThemeRoundedBevelButton: case kThemePushButton: dpPtr->offset = 1; break; - } - } + } + } } dpPtr->border = butPtr->normalBorder; @@ -1187,7 +1199,7 @@ PulseDefaultButtonProc(void *clientData) */ Tcl_CancelIdleCall(TkpDisplayButton, clientData); mbPtr->defaultPulseHandler = Tcl_CreateTimerHandler( - PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData); + PULSE_TIMER_MSECS, PulseDefaultButtonProc, clientData); } /* diff --git a/unix/tkUnixButton.c b/unix/tkUnixButton.c index 8e4ed96..8ba2df3 100644 --- a/unix/tkUnixButton.c +++ b/unix/tkUnixButton.c @@ -533,6 +533,11 @@ TkpDisplayButton( imageWidth = width; imageHeight = height; + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->padXPtr, &butPtr->padX); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->padYPtr, &butPtr->padY); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { @@ -725,7 +730,7 @@ TkpDisplayButton( if ((butPtr->type == TYPE_CHECK_BUTTON || butPtr->type == TYPE_RADIO_BUTTON) && butPtr->indicatorOn - && butPtr->indicatorDiameter > 2*butPtr->borderWidth) { + && butPtr->indicatorDiameter > 2 * butPtr->borderWidth) { TkBorder *selBorder = (TkBorder *) butPtr->selectBorder; XColor *selColor = NULL; int btype = (butPtr->type == TYPE_CHECK_BUTTON ? @@ -799,16 +804,16 @@ TkpDisplayButton( */ Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset, - inset, Tk_Width(tkwin) - 2*inset, - Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT); + inset, Tk_Width(tkwin) - 2 * inset, + Tk_Height(tkwin) - 2 * inset, 2, TK_RELIEF_FLAT); inset += 2; Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset, - inset, Tk_Width(tkwin) - 2*inset, - Tk_Height(tkwin) - 2*inset, 1, TK_RELIEF_SUNKEN); + inset, Tk_Width(tkwin) - 2 * inset, + Tk_Height(tkwin) - 2 * inset, 1, TK_RELIEF_SUNKEN); inset++; Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset, - inset, Tk_Width(tkwin) - 2*inset, - Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT); + inset, Tk_Width(tkwin) - 2 * inset, + Tk_Height(tkwin) - 2 * inset, 2, TK_RELIEF_FLAT); inset += 2; } else if (butPtr->defaultState == DEFAULT_NORMAL) { @@ -827,7 +832,7 @@ TkpDisplayButton( */ Tk_Draw3DRectangle(tkwin, pixmap, border, inset, inset, - Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset, + Tk_Width(tkwin) - 2 * inset, Tk_Height(tkwin) - 2 * inset, butPtr->borderWidth, relief); } if (butPtr->highlightWidth > 0) { @@ -888,6 +893,11 @@ TkpComputeButtonGeometry( int haveImage = 0, haveText = 0; Tk_FontMetrics fm; + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXPtr, &butPtr->padX); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYPtr, &butPtr->padY); + butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth; /* @@ -981,8 +991,8 @@ TkpComputeButtonGeometry( } } - width += 2*butPtr->padX; - height += 2*butPtr->padY; + width += 2 * butPtr->padX; + height += 2 * butPtr->padY; } else { if (haveImage) { if (butPtr->width > 0) { @@ -1025,15 +1035,15 @@ TkpComputeButtonGeometry( */ if ((butPtr->image == NULL) && (butPtr->bitmap == None)) { - width += 2*butPtr->padX; - height += 2*butPtr->padY; + width += 2 * butPtr->padX; + height += 2 * butPtr->padY; } if ((butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin)) { width += 2; height += 2; } Tk_GeometryRequest(butPtr->tkwin, (int) (width + butPtr->indicatorSpace - + 2*butPtr->inset), (int) (height + 2*butPtr->inset)); + + 2 * butPtr->inset), (int) (height + 2 * butPtr->inset)); Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset); } diff --git a/win/tkWinButton.c b/win/tkWinButton.c index a60fec2..88b98c6 100644 --- a/win/tkWinButton.c +++ b/win/tkWinButton.c @@ -565,6 +565,11 @@ TkpDisplayButton( return; } + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->padXPtr, &butPtr->padX); + Tk_GetPixelsFromObj(NULL, tkwin, butPtr->padYPtr, &butPtr->padY); + border = butPtr->normalBorder; if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) { gc = butPtr->disabledGC; @@ -924,8 +929,8 @@ TkpDisplayButton( if (relief != TK_RELIEF_FLAT) { Tk_Draw3DRectangle(tkwin, pixmap, border, defaultWidth, defaultWidth, - Tk_Width(tkwin) - 2*defaultWidth, - Tk_Height(tkwin) - 2*defaultWidth, + Tk_Width(tkwin) - 2 * defaultWidth, + Tk_Height(tkwin) - 2 * defaultWidth, butPtr->borderWidth, relief); } if (defaultWidth != 0) { @@ -1000,9 +1005,9 @@ TkpComputeButtonGeometry( ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - if (butPtr->highlightWidth < 0) { - butPtr->highlightWidth = 0; - } + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->highlightWidthPtr, &butPtr->highlightWidth); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->borderWidthPtr, &butPtr->borderWidth); + butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth; butPtr->indicatorSpace = 0; @@ -1195,6 +1200,9 @@ TkpComputeButtonGeometry( * because otherwise it is not really a compound button. */ + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padXPtr, &butPtr->padX); + Tk_GetPixelsFromObj(NULL, butPtr->tkwin, butPtr->padYPtr, &butPtr->padY); + if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { switch ((enum compound) butPtr->compound) { case COMPOUND_TOP: @@ -1265,8 +1273,8 @@ TkpComputeButtonGeometry( height = butPtr->height; } - width += 2*butPtr->padX; - height += 2*butPtr->padY; + width += 2 * butPtr->padX; + height += 2 * butPtr->padY; } else if (haveImage) { if (butPtr->width > 0) { width = butPtr->width; -- cgit v0.12