summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-14 20:20:39 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-14 20:20:39 (GMT)
commitb990e1db176a541b5095f23d0fec999c992afb58 (patch)
treec99403db7657941c9b8d9da39fec2e833b6d5371
parent83514ebcf9336a0ee9330bdfa93a39de39ac6b54 (diff)
parent8a2f66101bb61555e247c13cd0e6717121c07c49 (diff)
downloadtk-b990e1db176a541b5095f23d0fec999c992afb58.zip
tk-b990e1db176a541b5095f23d0fec999c992afb58.tar.gz
tk-b990e1db176a541b5095f23d0fec999c992afb58.tar.bz2
Better fix for [4d0a6f32b7]: Unique behavior of some options in the message widget in 8.7/9.0. No longer cache PIXEL values in button's and message. With testcases
-rw-r--r--generic/tkButton.c30
-rw-r--r--generic/tkMessage.c194
-rw-r--r--macosx/tkMacOSXButton.c62
-rw-r--r--tests/button.test11
-rw-r--r--tests/message.test10
-rw-r--r--unix/tkUnixButton.c36
-rw-r--r--win/tkWinButton.c22
7 files changed, 254 insertions, 111 deletions
diff --git a/generic/tkButton.c b/generic/tkButton.c
index d129bca..9d033e4 100644
--- a/generic/tkButton.c
+++ b/generic/tkButton.c
@@ -1097,17 +1097,45 @@ ConfigureButton(
} else {
Tk_SetBackgroundFromBorder(butPtr->tkwin, butPtr->normalBorder);
}
+ if (butPtr->wrapLength < 0) {
+ butPtr->wrapLength = 0;
+ if (butPtr->wrapLengthPtr) {
+ Tcl_DecrRefCount(butPtr->wrapLengthPtr);
+ }
+ butPtr->wrapLengthPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->wrapLengthPtr);
+ }
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 +1491,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 +1499,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 64531b6..0dc912c 100644
--- a/generic/tkMessage.c
+++ b/generic/tkMessage.c
@@ -54,21 +54,20 @@ typedef struct {
Tk_3DBorder border; /* Structure used to draw 3-D border and
* background. NULL means a border hasn't been
* created yet. */
- int borderWidth; /* Width of border. */
+ Tcl_Obj *borderWidthObj; /* Width of border. */
int relief; /* 3-D effect: TK_RELIEF_RAISED, etc. */
- int highlightWidth; /* Width in pixels of highlight to draw
+ Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw
* around widget when it has the focus.
- * <= 0 means don't draw a highlight. */
+ * 0 means don't draw a highlight. */
XColor *highlightBgColorPtr;
/* Color for drawing traversal highlight
* area when highlight is off. */
XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
Tk_Font tkfont; /* Information about text font, or NULL. */
XColor *fgColorPtr; /* Foreground color in normal mode. */
- Tcl_Obj *padXPtr, *padYPtr; /* Tcl_Obj rep's of padX, padY values. */
- int padX, padY; /* User-requested extra space around text. */
- int width; /* User-requested width, in pixels. 0 means
- * compute width using aspect ratio below. */
+ Tcl_Obj *padXObj, *padYObj; /* Tcl_Obj rep's of padX, padY values. */
+ Tcl_Obj *widthObj; /* User-requested width, in pixels. 0 means
+ * compute width using aspect ratio. */
int aspect; /* Desired aspect ratio for window
* (100*width/height). */
int msgWidth; /* Width in pixels needed to display
@@ -93,11 +92,6 @@ typedef struct {
* scripts. Malloc'ed, but may be NULL. */
int flags; /* Various flags; see below for
* definitions. */
- Tcl_Obj *borderWidthObj; /* Width of border. */
- Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw
- * around widget when it has the focus. <= 0 means don't draw a highlight. */
- Tcl_Obj *widthObj; /* User-requested width, in pixels. 0 means
- * compute width using aspect ratio. */
} Message;
/*
@@ -121,45 +115,45 @@ typedef struct {
static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", DEF_MESSAGE_ANCHOR,
- TCL_INDEX_NONE, offsetof(Message, anchor), TK_OPTION_ENUM_VAR, 0, 0},
+ TCL_INDEX_NONE, offsetof(Message, anchor), TK_OPTION_ENUM_VAR, 0, 0},
{TK_OPTION_INT, "-aspect", "aspect", "Aspect", DEF_MESSAGE_ASPECT,
- TCL_INDEX_NONE, offsetof(Message, aspect), 0, 0, 0},
+ TCL_INDEX_NONE, offsetof(Message, aspect), 0, 0, 0},
{TK_OPTION_BORDER, "-background", "background", "Background",
- DEF_MESSAGE_BG_COLOR, TCL_INDEX_NONE, offsetof(Message, border), 0,
- DEF_MESSAGE_BG_MONO, 0},
+ DEF_MESSAGE_BG_COLOR, TCL_INDEX_NONE, offsetof(Message, border), 0,
+ DEF_MESSAGE_BG_MONO, 0},
{TK_OPTION_SYNONYM, "-bd", NULL, NULL, NULL,
- 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
+ 0, TCL_INDEX_NONE, 0, "-borderwidth", 0},
{TK_OPTION_SYNONYM, "-bg", NULL, NULL, NULL,
- 0, TCL_INDEX_NONE, 0, "-background", 0},
+ 0, TCL_INDEX_NONE, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
- DEF_MESSAGE_BORDER_WIDTH, offsetof(Message, borderWidthObj),
- offsetof(Message, borderWidth), 0, 0, 0},
+ DEF_MESSAGE_BORDER_WIDTH, offsetof(Message, borderWidthObj),
+ TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
- DEF_MESSAGE_CURSOR, TCL_INDEX_NONE, offsetof(Message, cursor),
- TK_OPTION_NULL_OK, 0, 0},
+ DEF_MESSAGE_CURSOR, TCL_INDEX_NONE, offsetof(Message, cursor),
+ TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-fg", NULL, NULL, NULL,
- 0, TCL_INDEX_NONE, 0, "-foreground", 0},
+ 0, TCL_INDEX_NONE, 0, "-foreground", 0},
{TK_OPTION_FONT, "-font", "font", "Font",
DEF_MESSAGE_FONT, TCL_INDEX_NONE, offsetof(Message, tkfont), 0, 0, 0},
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
DEF_MESSAGE_FG, TCL_INDEX_NONE, offsetof(Message, fgColorPtr), 0, 0, 0},
{TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
- "HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, TCL_INDEX_NONE,
- offsetof(Message, highlightBgColorPtr), 0, 0, 0},
+ "HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, TCL_INDEX_NONE,
+ offsetof(Message, highlightBgColorPtr), 0, 0, 0},
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
- DEF_MESSAGE_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Message, highlightColorPtr),
- 0, 0, 0},
+ DEF_MESSAGE_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Message, highlightColorPtr),
+ 0, 0, 0},
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness", DEF_MESSAGE_HIGHLIGHT_WIDTH, offsetof(Message, highlightWidthObj),
- offsetof(Message, highlightWidth), 0, 0, 0},
+ TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
DEF_MESSAGE_JUSTIFY, TCL_INDEX_NONE, offsetof(Message, justify), TK_OPTION_ENUM_VAR, 0, 0},
{TK_OPTION_PIXELS, "-padx", "padX", "Pad",
- DEF_MESSAGE_PADX, offsetof(Message, padXPtr),
- offsetof(Message, padX), TK_OPTION_NULL_OK, 0, 0},
+ DEF_MESSAGE_PADX, offsetof(Message, padXObj),
+ TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-pady", "padY", "Pad",
- DEF_MESSAGE_PADY, offsetof(Message, padYPtr),
- offsetof(Message, padY), TK_OPTION_NULL_OK, 0, 0},
+ DEF_MESSAGE_PADY, offsetof(Message, padYObj),
+ TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
DEF_MESSAGE_RELIEF, TCL_INDEX_NONE, offsetof(Message, relief), 0, 0, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
@@ -171,7 +165,7 @@ static const Tk_OptionSpec optionSpecs[] = {
DEF_MESSAGE_TEXT_VARIABLE, TCL_INDEX_NONE, offsetof(Message, textVarName),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-width", "width", "Width",
- DEF_MESSAGE_WIDTH, offsetof(Message, widthObj), offsetof(Message, width), 0, 0 ,0},
+ DEF_MESSAGE_WIDTH, offsetof(Message, widthObj), TCL_INDEX_NONE, 0, 0 ,0},
{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0}
};
@@ -454,6 +448,7 @@ ConfigureMessage(
TCL_UNUSED(int)) /* Flags to pass to Tk_ConfigureWidget. */
{
Tk_SavedOptions savedOptions;
+ int width, borderWidth, highlightWidth, padX, padY;
/*
* Eliminate any existing trace on a variable monitored by the message.
@@ -503,8 +498,53 @@ ConfigureMessage(
msgPtr->numChars = TkNumUtfChars(msgPtr->string, TCL_INDEX_NONE);
- if (msgPtr->highlightWidth < 0) {
- msgPtr->highlightWidth = 0;
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->widthObj, &width);
+ if (width < 0) {
+ if (msgPtr->widthObj) {
+ Tcl_DecrRefCount(msgPtr->widthObj);
+ }
+ msgPtr->widthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->widthObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ if (borderWidth < 0) {
+ if (msgPtr->borderWidthObj) {
+ Tcl_DecrRefCount(msgPtr->borderWidthObj);
+ }
+ msgPtr->borderWidthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->borderWidthObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth < 0) {
+ if (msgPtr->highlightWidthObj) {
+ Tcl_DecrRefCount(msgPtr->highlightWidthObj);
+ }
+ msgPtr->highlightWidthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->highlightWidthObj);
+ }
+ if (!msgPtr->padXObj) {
+ msgPtr->padXObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padXObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ if (padX < 0) {
+ if (strcmp(Tcl_GetString(msgPtr->padXObj), "-1")) {
+ Tcl_DecrRefCount(msgPtr->padXObj);
+ msgPtr->padXObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padXObj);
+ }
+ }
+ if (!msgPtr->padYObj) {
+ msgPtr->padYObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padYObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ if (padY < 0) {
+ if (strcmp(Tcl_GetString(msgPtr->padYObj), "-1")) {
+ Tcl_DecrRefCount(msgPtr->padYObj);
+ msgPtr->padYObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padYObj);
+ }
}
Tk_FreeSavedOptions(&savedOptions);
@@ -536,7 +576,6 @@ MessageWorldChanged(
{
XGCValues gcValues;
GC gc = NULL;
- Tk_FontMetrics fm;
Message *msgPtr = (Message *)instanceData;
if (msgPtr->border != NULL) {
@@ -551,14 +590,6 @@ MessageWorldChanged(
}
msgPtr->textGC = gc;
- Tk_GetFontMetrics(msgPtr->tkfont, &fm);
- if (msgPtr->padX < 0) {
- msgPtr->padX = fm.ascent / 2;
- }
- if (msgPtr->padY < 0) {
- msgPtr->padY = fm.ascent / 4;
- }
-
/*
* Recompute the desired geometry for the window, and arrange for the
* window to be redisplayed.
@@ -597,10 +628,24 @@ ComputeMessageGeometry(
int width, inc, height;
int thisWidth, thisHeight, maxWidth;
int aspect, lowerBound, upperBound, inset;
+ int borderWidth, highlightWidth, padX, padY;
+ Tk_FontMetrics fm;
Tk_FreeTextLayout(msgPtr->textLayout);
- inset = msgPtr->borderWidth + msgPtr->highlightWidth;
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ Tk_GetFontMetrics(msgPtr->tkfont, &fm);
+ if (padX < 0) {
+ padX = fm.ascent / 2;
+ }
+ if (padY < 0) {
+ padY = fm.ascent / 4;
+ }
+
+ inset = borderWidth + highlightWidth;
/*
* Compute acceptable bounds for the final aspect ratio.
@@ -621,8 +666,8 @@ ComputeMessageGeometry(
* explicit width then just use that.
*/
- if (msgPtr->width > 0) {
- width = msgPtr->width;
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->widthObj, &width);
+ if (width > 0) {
inc = 0;
} else {
width = WidthOfScreen(Tk_Screen(msgPtr->tkwin))/2;
@@ -633,8 +678,8 @@ ComputeMessageGeometry(
msgPtr->textLayout = Tk_ComputeTextLayout(msgPtr->tkfont,
msgPtr->string, msgPtr->numChars, width, msgPtr->justify,
0, &thisWidth, &thisHeight);
- maxWidth = thisWidth + 2 * (inset + msgPtr->padX);
- height = thisHeight + 2 * (inset + msgPtr->padY);
+ maxWidth = thisWidth + 2 * (inset + padX);
+ height = thisHeight + 2 * (inset + padY);
if (inc <= 2) {
break;
@@ -679,22 +724,36 @@ DisplayMessage(
Message *msgPtr = (Message *)clientData;
Tk_Window tkwin = msgPtr->tkwin;
int x, y;
- int borderWidth = msgPtr->highlightWidth;
+ int width, borderWidth, highlightWidth, padX, padY;
+ Tk_FontMetrics fm;
+
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ Tk_GetFontMetrics(msgPtr->tkfont, &fm);
+ if (padX < 0) {
+ padX = fm.ascent / 2;
+ }
+ if (padY < 0) {
+ padY = fm.ascent / 4;
+ }
+ width = highlightWidth;
msgPtr->flags &= ~REDRAW_PENDING;
if ((msgPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
return;
}
if (msgPtr->border != NULL) {
- borderWidth += msgPtr->borderWidth;
+ width += borderWidth;
}
if (msgPtr->relief == TK_RELIEF_FLAT) {
- borderWidth = msgPtr->highlightWidth;
+ width = highlightWidth;
}
Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), msgPtr->border,
- borderWidth, borderWidth,
- Tk_Width(tkwin) - 2 * borderWidth,
- Tk_Height(tkwin) - 2 * borderWidth,
+ width, width,
+ Tk_Width(tkwin) - 2 * width,
+ Tk_Height(tkwin) - 2 * width,
0, TK_RELIEF_FLAT);
/*
@@ -702,28 +761,28 @@ DisplayMessage(
* anchor option.
*/
- TkComputeAnchor(msgPtr->anchor, tkwin, msgPtr->padX, msgPtr->padY,
+ TkComputeAnchor(msgPtr->anchor, tkwin, padX, padY,
msgPtr->msgWidth, msgPtr->msgHeight, &x, &y);
Tk_DrawTextLayout(Tk_Display(tkwin), Tk_WindowId(tkwin), msgPtr->textGC,
msgPtr->textLayout, x, y, 0, -1);
- if (borderWidth > msgPtr->highlightWidth) {
+ if (width > highlightWidth) {
Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), msgPtr->border,
- msgPtr->highlightWidth, msgPtr->highlightWidth,
- Tk_Width(tkwin) - 2*msgPtr->highlightWidth,
- Tk_Height(tkwin) - 2*msgPtr->highlightWidth,
- msgPtr->borderWidth, msgPtr->relief);
+ highlightWidth, highlightWidth,
+ Tk_Width(tkwin) - 2 * highlightWidth,
+ Tk_Height(tkwin) - 2 * highlightWidth,
+ borderWidth, msgPtr->relief);
}
- if (msgPtr->highlightWidth != 0) {
+ if (highlightWidth > 0) {
GC fgGC, bgGC;
bgGC = Tk_GCForColor(msgPtr->highlightBgColorPtr, Tk_WindowId(tkwin));
if (msgPtr->flags & GOT_FOCUS) {
fgGC = Tk_GCForColor(msgPtr->highlightColorPtr,Tk_WindowId(tkwin));
- Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, msgPtr->highlightWidth,
+ Tk_DrawHighlightBorder(tkwin, fgGC, bgGC, highlightWidth,
Tk_WindowId(tkwin));
} else {
- Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, msgPtr->highlightWidth,
+ Tk_DrawHighlightBorder(tkwin, bgGC, bgGC, highlightWidth,
Tk_WindowId(tkwin));
}
}
@@ -753,6 +812,7 @@ MessageEventProc(
XEvent *eventPtr) /* Information about event. */
{
Message *msgPtr = (Message *)clientData;
+ int highlightWidth;
if (((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0))
|| (eventPtr->type == ConfigureNotify)) {
@@ -762,14 +822,16 @@ MessageEventProc(
} else if (eventPtr->type == FocusIn) {
if (eventPtr->xfocus.detail != NotifyInferior) {
msgPtr->flags |= GOT_FOCUS;
- if (msgPtr->highlightWidth > 0) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth > 0) {
goto redraw;
}
}
} else if (eventPtr->type == FocusOut) {
if (eventPtr->xfocus.detail != NotifyInferior) {
msgPtr->flags &= ~GOT_FOCUS;
- if (msgPtr->highlightWidth > 0) {
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth > 0) {
goto redraw;
}
}
diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c
index 797fe4e..c825920 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 {
@@ -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:
@@ -372,11 +377,11 @@ TkpComputeButtonGeometry(
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,14 +389,13 @@ 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;
}
@@ -406,7 +410,7 @@ TkpComputeButtonGeometry(
* standard padding.
*/
- tmpRect = CGRectMake(0, 0, width + 2*HI_PADX, height + 2*HI_PADY);
+ 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;
@@ -414,8 +418,8 @@ TkpComputeButtonGeometry(
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);
@@ -473,6 +477,11 @@ DrawButtonImageAndText(
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;
@@ -666,7 +675,7 @@ DrawButtonImageAndText(
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);
}
}
@@ -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
@@ -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.
*
*--------------------------------------------------------------
*/
@@ -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.
*
*--------------------------------------------------------------
*/
@@ -936,7 +945,7 @@ ButtonEventProc(
* None.
*
* Side effects:
- * Sets the btnkind and drawinfo parameters
+ * Sets the btnkind and drawinfo parameters
*
*----------------------------------------------------------------------
*/
@@ -949,6 +958,9 @@ 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;
} else if (butPtr->borderWidth == 3) {
diff --git a/tests/button.test b/tests/button.test
index fb1e5f3..91fcf49 100644
--- a/tests/button.test
+++ b/tests/button.test
@@ -2668,6 +2668,17 @@ test button-1.270 {configuration options} -body {
destroy .c
} -result {}
+test button-1.271 {configuration options: fallback to default} -setup {
+ checkbutton .c -borderwidth -2 -highlightthickness -2 -font {Helvetica -12 bold}
+ pack .c
+ update
+} -body {
+ .c configure -padx -2 -pady -2 -wraplength -2
+ list [.c cget -padx] [.c cget -pady] [.c cget -borderwidth] [.c cget -highlightthickness] [.c cget -wraplength]
+} -cleanup {
+ destroy .c
+} -result {0 0 0 0 0}
+
# ex-tests 3.*
test button-2.1 {ButtonCreate - not enough arguments} -body {
button
diff --git a/tests/message.test b/tests/message.test
index 61a9e99..f5c0d82 100644
--- a/tests/message.test
+++ b/tests/message.test
@@ -393,6 +393,16 @@ test message-1.38 {configuration option: "width"} -setup {
} -cleanup {
destroy .m
} -returnCodes {error} -result {expected screen distance but got "badValue"}
+test message-1.39 {configuration options, fallback to default} -setup {
+ message .m -borderwidth -2 -highlightthickness -2 -font {Helvetica -12 bold}
+ pack .m
+ update
+} -body {
+ .m configure -padx -2 -pady -2 -width -2
+ list [.m cget -padx] [.m cget -pady] [.m cget -borderwidth] [.m cget -highlightthickness] [.m cget -width]
+} -cleanup {
+ destroy .m
+} -result {-1 -1 0 0 0}
test message-2.1 {Tk_MessageObjCmd procedure} -body {
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 31789e1..e0998b5 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;