Skip to content

Commit

Permalink
Backport part of [29ba539501]: many PIXEL options don't keep their co…
Browse files Browse the repository at this point in the history
…nfigured value.

Merge 8.6
  • Loading branch information
jan.nijtmans committed Aug 11, 2024
2 parents 1a91640 + 4384548 commit 3ad9d24
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 48 deletions.
20 changes: 5 additions & 15 deletions generic/tkButton.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,41 +1099,31 @@ ConfigureButton(
}
if (butPtr->wrapLength < 0) {
butPtr->wrapLength = 0;
if (butPtr->wrapLengthPtr) {
Tcl_DecrRefCount(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);
}
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);
}
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);
}
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);
}
Tcl_DecrRefCount(butPtr->padYPtr);
butPtr->padYPtr = Tcl_NewIntObj(0);
Tcl_IncrRefCount(butPtr->padYPtr);
}
Expand Down
49 changes: 35 additions & 14 deletions generic/tkEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static const Tk_OptionSpec entryOptSpec[] = {
{TK_OPTION_SYNONYM, "-bg", NULL, NULL,
NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
DEF_ENTRY_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Entry, borderWidth), 0, 0, 0},
DEF_ENTRY_BORDER_WIDTH, offsetof(Entry, borderWidthObj), offsetof(Entry, borderWidth), 0, 0, 0},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
DEF_ENTRY_CURSOR, TCL_INDEX_NONE, offsetof(Entry, cursor),
TK_OPTION_NULL_OK, 0, 0},
Expand All @@ -100,12 +100,12 @@ static const Tk_OptionSpec entryOptSpec[] = {
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
DEF_ENTRY_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Entry, highlightColorPtr), 0, 0, 0},
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, offsetof(Entry, highlightWidthObj),
offsetof(Entry, highlightWidth), 0, 0, 0},
{TK_OPTION_BORDER, "-insertbackground", "insertBackground", "Foreground",
DEF_ENTRY_INSERT_BG, TCL_INDEX_NONE, offsetof(Entry, insertBorder), 0, 0, 0},
{TK_OPTION_PIXELS, "-insertborderwidth", "insertBorderWidth",
"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, TCL_INDEX_NONE,
"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, offsetof(Entry, insertBorderWidthObj),
offsetof(Entry, insertBorderWidth), 0,
DEF_ENTRY_INSERT_BD_MONO, 0},
{TK_OPTION_INT, "-insertofftime", "insertOffTime", "OffTime",
Expand All @@ -114,7 +114,7 @@ static const Tk_OptionSpec entryOptSpec[] = {
{TK_OPTION_INT, "-insertontime", "insertOnTime", "OnTime",
DEF_ENTRY_INSERT_ON_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOnTime), 0, 0, 0},
{TK_OPTION_PIXELS, "-insertwidth", "insertWidth", "InsertWidth",
DEF_ENTRY_INSERT_WIDTH, TCL_INDEX_NONE, offsetof(Entry, insertWidth), 0, 0, 0},
DEF_ENTRY_INSERT_WIDTH, offsetof(Entry, insertWidthObj), offsetof(Entry, insertWidth), 0, 0, 0},
{TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand",
DEF_ENTRY_INVALIDCMD, TCL_INDEX_NONE, offsetof(Entry, invalidCmd),
TK_OPTION_NULL_OK, 0, 0},
Expand All @@ -138,7 +138,7 @@ static const Tk_OptionSpec entryOptSpec[] = {
DEF_ENTRY_SELECT_COLOR, TCL_INDEX_NONE, offsetof(Entry, selBorder),
0, DEF_ENTRY_SELECT_MONO, 0},
{TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, TCL_INDEX_NONE,
"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, offsetof(Entry, selBorderWidthObj),
offsetof(Entry, selBorderWidth),
0, DEF_ENTRY_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
Expand Down Expand Up @@ -200,7 +200,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
{TK_OPTION_SYNONYM, "-bg", NULL, NULL,
NULL, 0, TCL_INDEX_NONE, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
DEF_ENTRY_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(Entry, borderWidth), 0, 0, 0},
DEF_ENTRY_BORDER_WIDTH, offsetof(Entry, borderWidthObj), offsetof(Entry, borderWidth), 0, 0, 0},
{TK_OPTION_BORDER, "-buttonbackground", "buttonBackground", "Background",
DEF_BUTTON_BG_COLOR, TCL_INDEX_NONE, offsetof(Spinbox, buttonBorder),
0, DEF_BUTTON_BG_MONO, 0},
Expand Down Expand Up @@ -244,14 +244,14 @@ static const Tk_OptionSpec sbOptSpec[] = {
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
DEF_ENTRY_HIGHLIGHT, TCL_INDEX_NONE, offsetof(Entry, highlightColorPtr), 0, 0, 0},
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, TCL_INDEX_NONE,
"HighlightThickness", DEF_ENTRY_HIGHLIGHT_WIDTH, offsetof(Entry, highlightWidthObj),
offsetof(Entry, highlightWidth), 0, 0, 0},
{TK_OPTION_DOUBLE, "-increment", "increment", "Increment",
DEF_SPINBOX_INCREMENT, TCL_INDEX_NONE, offsetof(Spinbox, increment), 0, 0, 0},
{TK_OPTION_BORDER, "-insertbackground", "insertBackground", "Foreground",
DEF_ENTRY_INSERT_BG, TCL_INDEX_NONE, offsetof(Entry, insertBorder), 0, 0, 0},
{TK_OPTION_PIXELS, "-insertborderwidth", "insertBorderWidth",
"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, TCL_INDEX_NONE,
"BorderWidth", DEF_ENTRY_INSERT_BD_COLOR, offsetof(Entry, insertBorderWidthObj),
offsetof(Entry, insertBorderWidth), 0,
DEF_ENTRY_INSERT_BD_MONO, 0},
{TK_OPTION_INT, "-insertofftime", "insertOffTime", "OffTime",
Expand All @@ -260,7 +260,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
{TK_OPTION_INT, "-insertontime", "insertOnTime", "OnTime",
DEF_ENTRY_INSERT_ON_TIME, TCL_INDEX_NONE, offsetof(Entry, insertOnTime), 0, 0, 0},
{TK_OPTION_PIXELS, "-insertwidth", "insertWidth", "InsertWidth",
DEF_ENTRY_INSERT_WIDTH, TCL_INDEX_NONE, offsetof(Entry, insertWidth), 0, 0, 0},
DEF_ENTRY_INSERT_WIDTH, offsetof(Entry, insertWidthObj), offsetof(Entry, insertWidth), 0, 0, 0},
{TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand",
DEF_ENTRY_INVALIDCMD, TCL_INDEX_NONE, offsetof(Entry, invalidCmd),
TK_OPTION_NULL_OK, 0, 0},
Expand Down Expand Up @@ -290,7 +290,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
DEF_ENTRY_SELECT_COLOR, TCL_INDEX_NONE, offsetof(Entry, selBorder),
0, DEF_ENTRY_SELECT_MONO, 0},
{TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, TCL_INDEX_NONE,
"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, offsetof(Entry, selBorderWidthObj),
offsetof(Entry, selBorderWidth),
0, DEF_ENTRY_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
Expand Down Expand Up @@ -1190,14 +1190,35 @@ ConfigureEntry(
}
Tk_SetBackgroundFromBorder(entryPtr->tkwin, border);

if (entryPtr->insertWidth < 0) {
entryPtr->insertWidth = 0;
if (entryPtr->borderWidth < 0) {
entryPtr->borderWidth = 0;
Tcl_DecrRefCount(entryPtr->borderWidthObj);
entryPtr->borderWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(entryPtr->borderWidthObj);
}
if (entryPtr->highlightWidth < 0) {
entryPtr->highlightWidth = 0;
Tcl_DecrRefCount(entryPtr->highlightWidthObj);
entryPtr->highlightWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(entryPtr->highlightWidthObj);
}
if (entryPtr->insertBorderWidth < 0) {
entryPtr->insertBorderWidth = 0;
Tcl_DecrRefCount(entryPtr->insertBorderWidthObj);
entryPtr->insertBorderWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(entryPtr->insertBorderWidthObj);
}
if (entryPtr->highlightWidth < 0) {
entryPtr->highlightWidth = 0;
if (entryPtr->insertWidth < 0) {
entryPtr->insertWidth = 0;
Tcl_DecrRefCount(entryPtr->insertWidthObj);
entryPtr->insertWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(entryPtr->insertWidthObj);
}
if (entryPtr->selBorderWidth < 0) {
entryPtr->selBorderWidth = 0;
Tcl_DecrRefCount(entryPtr->selBorderWidthObj);
entryPtr->selBorderWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(entryPtr->selBorderWidthObj);
}

if (entryPtr->type == TK_SPINBOX) {
Expand Down
5 changes: 5 additions & 0 deletions generic/tkEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ typedef struct {
* commands. Malloc'ed. */
char *invalidCmd; /* Command called when a validation returns 0
* (successfully fails), defaults to {}. */
Tcl_Obj *borderWidthObj;
Tcl_Obj *highlightWidthObj;
Tcl_Obj *insertWidthObj;
Tcl_Obj *insertBorderWidthObj;
Tcl_Obj *selBorderWidthObj;
} Entry;

/*
Expand Down
20 changes: 10 additions & 10 deletions generic/tkTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ Tktest_Init(
Tcl_CreateObjCommand2(interp, "testtext", TkpTesttextCmd,
Tk_MainWindow(interp), NULL);
Tcl_CreateObjCommand(interp, "testphotostringmatch",
TestPhotoStringMatchCmd, Tk_MainWindow(interp),
NULL);
TestPhotoStringMatchCmd, Tk_MainWindow(interp),
NULL);

#if defined(_WIN32)
Tcl_CreateObjCommand(interp, "testmetrics", TestmetricsObjCmd,
Expand Down Expand Up @@ -1562,7 +1562,7 @@ ImageDisplay(
} else {

/*
* Drawing is not possible on the first call to DisplayImage.
* Drawing is not possible on the first call to DisplayImage.
* Save the message, but do not log it until the actual display.
*/

Expand Down Expand Up @@ -2138,16 +2138,16 @@ TestPhotoStringMatchCmd(
int width, height;

if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "imageData");
return TCL_ERROR;
Tcl_WrongNumArgs(interp, 1, objv, "imageData");
return TCL_ERROR;
}
if (TkDebugPhotoStringMatchDef(interp, objv[1], dummy, &width, &height)) {
resultObj[0] = Tcl_NewWideIntObj(width);
resultObj[1] = Tcl_NewWideIntObj(height);
Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObj));
return TCL_OK;
resultObj[0] = Tcl_NewWideIntObj(width);
resultObj[1] = Tcl_NewWideIntObj(height);
Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObj));
return TCL_OK;
} else {
return TCL_ERROR;
return TCL_ERROR;
}
}

Expand Down
4 changes: 2 additions & 2 deletions generic/ttk/ttkTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ typedef void (Ttk_CleanupProc)(void *clientData);
enum TTKStyleVersion2 { TK_STYLE_VERSION_2 = 2 };

typedef void (Ttk_ElementSizeProc)(void *clientData, void *elementRecord,
Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding*);
Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding*);
typedef void (Ttk_ElementDrawProc)(void *clientData, void *elementRecord,
Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state);
Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state);

typedef struct Ttk_ElementOptionSpec
{
Expand Down
6 changes: 3 additions & 3 deletions tests/entry.test
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test entry-1.7 {configuration option: "borderwidth" for entry} -setup {
.e cget -borderwidth
} -cleanup {
destroy .e
} -result 1
} -result 1.3
test entry-1.8 {configuration option: "borderwidth" for entry} -setup {
entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .e ; update idletasks
Expand Down Expand Up @@ -362,7 +362,7 @@ test entry-1.32 {configuration option: "insertborderwidth" for entry} -setup {
.e cget -insertborderwidth
} -cleanup {
destroy .e
} -result 1
} -result 1.3
test entry-1.33 {configuration option: "insertborderwidth" for entry} -setup {
entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .e ; update idletasks
Expand Down Expand Up @@ -515,7 +515,7 @@ test entry-1.47 {configuration option: "selectborderwidth" for entry} -setup {
.e cget -selectborderwidth
} -cleanup {
destroy .e
} -result 1
} -result 1.3
test entry-1.48 {configuration option: "selectborderwidth" for entry} -setup {
entry .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold}
pack .e ; update idletasks
Expand Down
6 changes: 3 additions & 3 deletions tests/spinbox.test
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ test spinbox-1.9 {configuration option: "borderwidth"} -setup {
.e cget -borderwidth
} -cleanup {
destroy .e
} -result 1
} -result 1.3
test spinbox-1.10 {configuration option: "borderwidth" for spinbox} -setup {
spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
-relief sunken
Expand Down Expand Up @@ -536,7 +536,7 @@ test spinbox-1.45 {configuration option: "insertborderwidth"} -setup {
.e cget -insertborderwidth
} -cleanup {
destroy .e
} -result 1
} -result 1.3
test spinbox-1.46 {configuration option: "insertborderwidth" for spinbox} -setup {
spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
-relief sunken
Expand Down Expand Up @@ -758,7 +758,7 @@ test spinbox-1.65 {configuration option: "selectborderwidth"} -setup {
.e cget -selectborderwidth
} -cleanup {
destroy .e
} -result 1
} -result 1.3
test spinbox-1.66 {configuration option: "selectborderwidth" for spinbox} -setup {
spinbox .e -borderwidth 2 -highlightthickness 2 -font {Helvetica -12} \
-relief sunken
Expand Down
3 changes: 2 additions & 1 deletion win/tkWinButton.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ TkpDisplayButton(
int dottedWidth = butPtr->borderWidth + 1 + defaultWidth;
TkWinDrawDottedRect(butPtr->display, pixmap, gc->foreground,
dottedWidth, dottedWidth,
Tk_Width(tkwin) - 2*dottedWidth, Tk_Height(tkwin) - 2*dottedWidth);
Tk_Width(tkwin) - 2*dottedWidth,
Tk_Height(tkwin) - 2*dottedWidth);
} else {
TkWinDrawDottedRect(butPtr->display, pixmap, gc->foreground,
x-1 + textXOffset, y-1 + textYOffset,
Expand Down

0 comments on commit 3ad9d24

Please sign in to comment.