Skip to content

Commit

Permalink
Fix [f91aa24bbe] for allmost all remaining widgets. Canvtext is the o…
Browse files Browse the repository at this point in the history
…nly one which is not complete yet
  • Loading branch information
jan.nijtmans committed Oct 23, 2024
2 parents c9f9159 + 282f2b4 commit 1320b8a
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 84 deletions.
14 changes: 7 additions & 7 deletions generic/tkEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
{TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand",
NULL, offsetof(Entry, validateCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-values", "values", "Values",
DEF_SPINBOX_VALUES, TCL_INDEX_NONE, offsetof(Spinbox, valueStr),
DEF_SPINBOX_VALUES, offsetof(Spinbox, valueObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-vcmd", NULL, NULL,
NULL, 0, TCL_INDEX_NONE, 0, "-validatecommand", 0},
Expand Down Expand Up @@ -1115,7 +1115,7 @@ ConfigureEntry(
Spinbox *sbPtr = (Spinbox *) entryPtr;
/* Only used when this widget is of type
* TK_SPINBOX */
char *oldValues = NULL;
Tcl_Obj *oldValues = NULL;
Tcl_Obj *oldFormat = NULL;
int error;
int oldExport = 0;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ ConfigureEntry(

oldExport = (entryPtr->exportSelection) && (!Tcl_IsSafe(entryPtr->interp));
if (entryPtr->type == TK_SPINBOX) {
oldValues = sbPtr->valueStr;
oldValues = sbPtr->valueObj;
oldFormat = sbPtr->reqFormatObj;
oldFrom = sbPtr->fromValue;
oldTo = sbPtr->toValue;
Expand Down Expand Up @@ -1286,16 +1286,16 @@ ConfigureEntry(
* See if we have to rearrange our listObj data.
*/

if (oldValues != sbPtr->valueStr) {
if (oldValues != sbPtr->valueObj) {
if (sbPtr->listObj != NULL) {
Tcl_DecrRefCount(sbPtr->listObj);
}
sbPtr->listObj = NULL;
if (sbPtr->valueStr != NULL) {
if (sbPtr->valueObj != NULL) {
Tcl_Obj *newObjPtr;
Tcl_Size nelems;

newObjPtr = Tcl_NewStringObj(sbPtr->valueStr, TCL_INDEX_NONE);
newObjPtr = sbPtr->valueObj;
if (Tcl_ListObjLength(interp, newObjPtr, &nelems)
!= TCL_OK) {
valuesChanged = -1;
Expand Down Expand Up @@ -1398,7 +1398,7 @@ ConfigureEntry(
*/

EntryValueChanged(entryPtr, Tcl_GetString(objPtr));
} else if ((sbPtr->valueStr == NULL)
} else if ((sbPtr->valueObj == NULL)
&& !DOUBLES_EQ(sbPtr->fromValue, sbPtr->toValue)
&& (!DOUBLES_EQ(sbPtr->fromValue, oldFrom)
|| !DOUBLES_EQ(sbPtr->toValue, oldTo))) {
Expand Down
22 changes: 21 additions & 1 deletion generic/tkEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ typedef struct {
Tk_3DBorder readonlyBorder; /* Used for drawing border around whole window
* in readonly state, plus used for
* background. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *borderWidthObj; /* Width of 3-D border around window. */
#else
int borderWidth;
#endif
Tk_Cursor cursor; /* Current cursor for window, or NULL. */
int exportSelection; /* Non-zero means tie internal entry selection
* to X selection. */
Expand All @@ -91,23 +95,39 @@ typedef struct {
XColor *highlightBgColorPtr;/* Color for drawing traversal highlight area
* when highlight is off. */
XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around
* widget when it has the focus. <= 0 means
* don't draw a highlight. */
#else
int highlightWidth;
#endif
Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion
* cursor. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *insertBorderWidthObj; /* Width of 3-D border around insert cursor. */
#else
int insertBorderWidth;
#endif
int insertOffTime; /* Number of milliseconds cursor should spend
* in "off" state for each blink. */
int insertOnTime; /* Number of milliseconds cursor should spend
* in "on" state for each blink. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *insertWidthObj; /* Total width of insert cursor. */
#else
int insertWidth;
#endif
Tk_Justify justify; /* Justification to use for text within
* window. */
int relief; /* 3-D effect: TK_RELIEF_RAISED, etc. */
Tk_3DBorder selBorder; /* Border and background for selected
* characters. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *selBorderWidthObj; /* Width of border around selection. */
#else
int selBorderWidth;
#endif
XColor *selFgColorPtr; /* Foreground color for selected text. */
int state; /* Normal or disabled. Entry is read-only when
* disabled. */
Expand Down Expand Up @@ -235,7 +255,7 @@ typedef struct {
* digits and other information; used for the
* value. */

char *valueStr; /* Values List. Malloc'ed. */
Tcl_Obj *valueObj; /* Values List. */
Tcl_Obj *listObj; /* Pointer to the list object being used */
int eIndex; /* Holds the current index into elements */
int nElements; /* Holds the current count of elements */
Expand Down
22 changes: 10 additions & 12 deletions generic/tkScale.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static const Tk_OptionSpec optionSpecs[] = {
DEF_SCALE_BORDER_WIDTH, offsetof(TkScale, borderWidthObj), TCL_INDEX_NONE,
0, 0, 0},
{TK_OPTION_STRING, "-command", "command", "Command",
DEF_SCALE_COMMAND, TCL_INDEX_NONE, offsetof(TkScale, command),
DEF_SCALE_COMMAND, offsetof(TkScale, commandObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
DEF_SCALE_CURSOR, TCL_INDEX_NONE, offsetof(TkScale, cursor),
Expand Down Expand Up @@ -80,7 +80,7 @@ static const Tk_OptionSpec optionSpecs[] = {
"HighlightThickness", DEF_SCALE_HIGHLIGHT_WIDTH, offsetof(TkScale, highlightWidthObj),
TCL_INDEX_NONE, 0, 0, 0},
{TK_OPTION_STRING, "-label", "label", "Label",
DEF_SCALE_LABEL, TCL_INDEX_NONE, offsetof(TkScale, label),
DEF_SCALE_LABEL, offsetof(TkScale, labelObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_PIXELS, "-length", "length", "Length",
DEF_SCALE_LENGTH, offsetof(TkScale, lengthObj), TCL_INDEX_NONE, 0, 0, 0},
Expand Down Expand Up @@ -291,11 +291,10 @@ Tk_ScaleObjCmd(
scalePtr->resolution = 1.0;
scalePtr->digits = 0;
scalePtr->bigIncrement = 0.0;
scalePtr->command = NULL;
scalePtr->commandObj = NULL;
scalePtr->repeatDelay = 0;
scalePtr->repeatInterval = 0;
scalePtr->label = NULL;
scalePtr->labelLength = 0;
scalePtr->labelObj = NULL;
scalePtr->state = STATE_NORMAL;
scalePtr->borderWidthObj = NULL;
scalePtr->bgBorder = NULL;
Expand Down Expand Up @@ -673,8 +672,6 @@ ConfigureScale(
ComputeFormat(scalePtr, 0);
ComputeFormat(scalePtr, 1);

scalePtr->labelLength = scalePtr->label ? strlen(scalePtr->label) : 0;

Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder);

Tk_GetPixelsFromObj(NULL, scalePtr->tkwin, scalePtr->highlightWidthObj, &highlightWidth);
Expand Down Expand Up @@ -1041,7 +1038,7 @@ ComputeScaleGeometry(
if (scalePtr->orient == ORIENT_HORIZONTAL) {
y = scalePtr->inset;
extraSpace = 0;
if (scalePtr->labelLength != 0) {
if (scalePtr->labelObj != NULL) {
scalePtr->horizLabelY = y + SPACING;
y += scalePtr->fontHeight;
extraSpace = SPACING;
Expand Down Expand Up @@ -1136,13 +1133,14 @@ ComputeScaleGeometry(
Tk_GetPixelsFromObj(NULL, scalePtr->tkwin, scalePtr->borderWidthObj, &borderWidth);
Tk_GetPixelsFromObj(NULL, scalePtr->tkwin, scalePtr->widthObj, &width);
x += 2 * borderWidth + width;
if (scalePtr->labelLength == 0) {
if (scalePtr->labelObj == NULL) {
scalePtr->vertLabelX = 0;
} else {
Tcl_Size labelLength;
const char *label= Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength);
scalePtr->vertLabelX = x + fm.ascent/2;
x = scalePtr->vertLabelX + fm.ascent/2
+ Tk_TextWidth(scalePtr->tkfont, scalePtr->label,
scalePtr->labelLength);
+ Tk_TextWidth(scalePtr->tkfont, label, labelLength);
}
Tk_GetPixelsFromObj(NULL, scalePtr->tkwin, scalePtr->lengthObj, &length);
Tk_GeometryRequest(scalePtr->tkwin, x + scalePtr->inset,
Expand Down Expand Up @@ -1483,7 +1481,7 @@ TkScaleSetValue(
* configuring the widget -command option even if the value did not change.
*/

if ((invokeCommand) && (scalePtr->command != NULL)) {
if ((invokeCommand) && (scalePtr->commandObj != NULL)) {
scalePtr->flags |= INVOKE_COMMAND;
}
TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER);
Expand Down
21 changes: 18 additions & 3 deletions generic/tkScale.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ typedef struct TkScale {
* available for this widget. */
enum orient orient; /* Orientation for window (vertical or
* horizontal). */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *widthObj; /* Desired narrow dimension of scale, in
* pixels. */
Tcl_Obj *lengthObj; /* Desired long dimension of scale, in
* pixels. */
#else
int width, length;
#endif
double value; /* Current value of scale. */
Tcl_Obj *varNamePtr; /* Name of variable or NULL. If non-NULL,
* scale's value tracks the contents of this
Expand All @@ -79,15 +83,14 @@ typedef struct TkScale {
* tick interval. */
double bigIncrement; /* Amount to use for large increments to scale
* value. (0 means we pick a value). */
char *command; /* Command prefix to use when invoking Tcl
Tcl_Obj *commandObj; /* Command prefix to use when invoking Tcl
* commands because the scale value changed.
* NULL means don't invoke commands. */
int repeatDelay; /* How long to wait before auto-repeating on
* scrolling actions (in ms). */
int repeatInterval; /* Interval between autorepeats (in ms). */
char *label; /* Label to display above or to right of
Tcl_Obj *labelObj; /* Label to display above or to right of
* scale; NULL means don't display a label. */
Tcl_Size labelLength; /* Number of non-NULL chars. in label. */
enum state state; /* Values are active, normal, or disabled.
* Value of scale cannot be changed when
* disabled. */
Expand All @@ -96,7 +99,11 @@ typedef struct TkScale {
* Information used when displaying widget:
*/

#if TK_MAJOR_VERSION > 8
Tcl_Obj *borderWidthObj; /* Width of 3-D border around window. */
#else
int borderWidth; /* Width of 3-D border around window. */
#endif
Tk_3DBorder bgBorder; /* Used for drawing slider and other
* background areas. */
Tk_3DBorder activeBorder; /* For drawing the slider when active. */
Expand All @@ -110,9 +117,13 @@ typedef struct TkScale {
GC textGC; /* GC for drawing text in normal mode. */
int relief; /* Indicates whether window as a whole is
* raised, sunken, or flat. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *highlightWidthObj; /* Width in pixels of highlight to draw around
* widget when it has the focus. <= 0 means
* don't draw a highlight. */
#else
int highlightWidth;
#endif
Tk_3DBorder highlightBorder;/* Value of -highlightbackground option:
* specifies background with which to draw 3-D
* default ring and focus highlight area when
Expand All @@ -123,8 +134,12 @@ typedef struct TkScale {
* Indicates how much interior stuff must be
* offset from outside edges to leave room for
* borders. */
#if TK_MAJOR_VERSION > 8
Tcl_Obj *sliderLengthObj; /* Length of slider, measured in pixels along
* long dimension of scale. */
#else
int sliderLength;
#endif
int showValue; /* Non-zero means to display the scale value
* below or to the left of the slider; zero
* means don't display the value. */
Expand Down
30 changes: 15 additions & 15 deletions generic/ttk/ttkEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ typedef struct {
int exportSelection; /* Tie internal selection to X selection? */

VMODE validate; /* Validation mode */
char *validateCmd; /* Validation script template */
char *invalidCmd; /* Invalid callback script template */
Tcl_Obj *validateCmdObj; /* Validation script template */
Tcl_Obj *invalidCmdObj; /* Invalid callback script template */

char *showChar; /* Used to derive displayString */
Tcl_Obj *showCharObj; /* Used to derive displayString */

Tcl_Obj *fontObj; /* Text font to use */
Tcl_Obj *widthObj; /* Desired width of window (in avgchars) */
Expand Down Expand Up @@ -166,7 +166,7 @@ static const Tk_OptionSpec EntryOptionSpecs[] = {
DEF_ENTRY_FONT, offsetof(Entry, entry.fontObj),TCL_INDEX_NONE,
0,0,GEOMETRY_CHANGED},
{TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand",
NULL, TCL_INDEX_NONE, offsetof(Entry, entry.invalidCmd),
NULL, offsetof(Entry, entry.invalidCmdObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
"left", TCL_INDEX_NONE, offsetof(Entry, entry.justify),
Expand All @@ -175,7 +175,7 @@ static const Tk_OptionSpec EntryOptionSpecs[] = {
NULL, offsetof(Entry, entry.placeholderObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-show", "show", "Show",
NULL, TCL_INDEX_NONE, offsetof(Entry, entry.showChar),
NULL, offsetof(Entry, entry.showCharObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-state", "state", "State",
"normal", offsetof(Entry, entry.stateObj), TCL_INDEX_NONE,
Expand All @@ -187,13 +187,13 @@ static const Tk_OptionSpec EntryOptionSpecs[] = {
"none", TCL_INDEX_NONE, offsetof(Entry, entry.validate),
TK_OPTION_ENUM_VAR, validateStrings, 0},
{TK_OPTION_STRING, "-validatecommand", "validateCommand", "ValidateCommand",
NULL, TCL_INDEX_NONE, offsetof(Entry, entry.validateCmd),
NULL, offsetof(Entry, entry.validateCmdObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_INT, "-width", "width", "Width",
DEF_ENTRY_WIDTH, offsetof(Entry, entry.widthObj), TCL_INDEX_NONE,
0,0,GEOMETRY_CHANGED},
{TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
NULL, TCL_INDEX_NONE, offsetof(Entry, entry.xscroll.scrollCmd),
NULL, offsetof(Entry, entry.xscroll.scrollCmdObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED},

/* EntryStyleData options:
Expand Down Expand Up @@ -604,7 +604,7 @@ EntryValidateChange(
VMODE vmode = entryPtr->entry.validate;
int code, change_ok;

if ((entryPtr->entry.validateCmd == NULL)
if ((entryPtr->entry.validateCmdObj == NULL)
|| (entryPtr->core.flags & VALIDATING)
|| !EntryNeedsValidation(vmode, reason))
{
Expand All @@ -616,7 +616,7 @@ EntryValidateChange(
/* Run -validatecommand and check return value:
*/
code = RunValidationScript(interp, entryPtr,
entryPtr->entry.validateCmd, "-validatecommand",
Tcl_GetString(entryPtr->entry.validateCmdObj), "-validatecommand",
newValue, index, count, reason);
if (code != TCL_OK) {
goto done;
Expand All @@ -632,9 +632,9 @@ EntryValidateChange(

/* Run the -invalidcommand if validation failed:
*/
if (!change_ok && entryPtr->entry.invalidCmd != NULL) {
if (!change_ok && entryPtr->entry.invalidCmdObj != NULL) {
code = RunValidationScript(interp, entryPtr,
entryPtr->entry.invalidCmd, "-invalidcommand",
Tcl_GetString(entryPtr->entry.invalidCmdObj), "-invalidcommand",
newValue, index, count, reason);
if (code != TCL_OK) {
goto done;
Expand Down Expand Up @@ -764,8 +764,8 @@ EntryStoreValue(Entry *entryPtr, const char *value)
entryPtr->entry.numChars = numChars;

entryPtr->entry.displayString
= entryPtr->entry.showChar
? EntryDisplayString(entryPtr->entry.showChar, numChars)
= entryPtr->entry.showCharObj
? EntryDisplayString(Tcl_GetString(entryPtr->entry.showCharObj), numChars)
: entryPtr->entry.string
;

Expand Down Expand Up @@ -1059,8 +1059,8 @@ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask)
ckfree(entryPtr->entry.displayString);

entryPtr->entry.displayString
= entryPtr->entry.showChar
? EntryDisplayString(entryPtr->entry.showChar, entryPtr->entry.numChars)
= entryPtr->entry.showCharObj
? EntryDisplayString(Tcl_GetString(entryPtr->entry.showCharObj), entryPtr->entry.numChars)
: entryPtr->entry.string
;

Expand Down
4 changes: 2 additions & 2 deletions generic/ttk/ttkScroll.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ static int UpdateScrollbar(Tcl_Interp *interp, ScrollHandle h)

h->flags &= ~SCROLL_UPDATE_REQUIRED;

if (s->scrollCmd == NULL) {
if (s->scrollCmdObj == NULL) {
return TCL_OK;
}

arg1[0] = arg2[0] = ' ';
Tcl_PrintDouble(interp, (double)s->first / s->total, arg1+1);
Tcl_PrintDouble(interp, (double)s->last / s->total, arg2+1);
Tcl_DStringInit(&buf);
Tcl_DStringAppend(&buf, s->scrollCmd, TCL_INDEX_NONE);
Tcl_DStringAppend(&buf, Tcl_GetString(s->scrollCmdObj), TCL_INDEX_NONE);
Tcl_DStringAppend(&buf, arg1, TCL_INDEX_NONE);
Tcl_DStringAppend(&buf, arg2, TCL_INDEX_NONE);

Expand Down
4 changes: 2 additions & 2 deletions generic/ttk/ttkTreeview.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,10 @@ static const Tk_OptionSpec TreeviewOptionSpecs[] = {
0, 0, GEOMETRY_CHANGED},

{TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.xscroll.scrollCmd),
NULL, offsetof(Treeview, tree.xscroll.scrollCmdObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED},
{TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.yscroll.scrollCmd),
NULL, offsetof(Treeview, tree.yscroll.scrollCmdObj), TCL_INDEX_NONE,
TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED},

WIDGET_TAKEFOCUS_TRUE,
Expand Down
Loading

0 comments on commit 1320b8a

Please sign in to comment.