Skip to content

Commit

Permalink
Fix [026e2bb685]: text tag sets bad relief, gets error, but bad relie…
Browse files Browse the repository at this point in the history
…f is saved anyway
  • Loading branch information
jan.nijtmans committed Jan 14, 2024
3 parents 9cc0c1a + 9c779e7 + 667a7fc commit 3141307
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 40 deletions.
7 changes: 2 additions & 5 deletions generic/tkText.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,6 @@ CreateWidget(
*/

textPtr->selTagPtr = TkTextCreateTag(textPtr, "sel", NULL);
textPtr->selTagPtr->reliefString = (char *)
ckalloc(sizeof(DEF_TEXT_SELECT_RELIEF));
strcpy(textPtr->selTagPtr->reliefString, DEF_TEXT_SELECT_RELIEF);
Tk_GetRelief(interp, DEF_TEXT_SELECT_RELIEF, &textPtr->selTagPtr->relief);
textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &startIndex);
textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &startIndex);
Expand Down Expand Up @@ -2271,7 +2268,7 @@ ConfigureText(
textPtr->selTagPtr->affectsDisplayGeometry = 0;
if ((textPtr->selTagPtr->elide >= 0)
|| (textPtr->selTagPtr->tkfont != NULL)
|| (textPtr->selTagPtr->justifyString != NULL)
|| (textPtr->selTagPtr->justify != TK_JUSTIFY_NULL)
|| (textPtr->selTagPtr->lMargin1String != NULL)
|| (textPtr->selTagPtr->lMargin2String != NULL)
|| (textPtr->selTagPtr->offsetString != NULL)
Expand All @@ -2290,7 +2287,7 @@ ConfigureText(
}
if ((textPtr->selTagPtr->border != NULL)
|| (textPtr->selTagPtr->selBorder != NULL)
|| (textPtr->selTagPtr->reliefString != NULL)
|| (textPtr->selTagPtr->relief != TK_RELIEF_NULL)
|| (textPtr->selTagPtr->bgStipple != None)
|| (textPtr->selTagPtr->fgColor != NULL)
|| (textPtr->selTagPtr->selFgColor != NULL)
Expand Down
13 changes: 7 additions & 6 deletions generic/tkText.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ typedef struct TkTextTag {
* value specified here. */
int borderWidth; /* Width of 3-D border for background. */
Tcl_Obj *borderWidthPtr; /* Width of 3-D border for background. */
char *reliefString; /* -relief option string (malloc-ed). NULL
* means option not specified. */
#if TCL_MAJOR_VERSION < 9
char *reliefString; /* Not used any more */
#endif
int relief; /* 3-D relief for background. */
Pixmap bgStipple; /* Stipple bitmap for background. None means
* no value specified here. */
Expand All @@ -334,11 +335,11 @@ typedef struct TkTextTag {
Pixmap fgStipple; /* Stipple bitmap for text and other
* foreground stuff. None means no value
* specified here.*/
char *justifyString; /* -justify option string (malloc-ed). NULL
* means option not specified. */
#if TCL_MAJOR_VERSION < 9
char *justifyString; /* Not used any more */
#endif
Tk_Justify justify; /* How to justify text: TK_JUSTIFY_LEFT,
* TK_JUSTIFY_RIGHT, TK_JUSTIFY_CENTER, or TK_JUSTIFY_NULL.
* Only valid if justifyString is non-NULL. */
* TK_JUSTIFY_RIGHT, TK_JUSTIFY_CENTER, or TK_JUSTIFY_NULL. */
char *lMargin1String; /* -lmargin1 option string (malloc-ed). NULL
* means option not specified. */
int lMargin1; /* Left margin for first display line of each
Expand Down
4 changes: 2 additions & 2 deletions generic/tkTextDisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ GetStyle(
styleValues.borderWidth = tagPtr->borderWidth;
borderWidthPrio = tagPtr->priority;
}
if ((tagPtr->reliefString != NULL)
if ((tagPtr->relief != TK_RELIEF_NULL)
&& (tagPtr->priority > reliefPrio)) {
if (styleValues.border == NULL) {
styleValues.border = textPtr->border;
Expand All @@ -898,7 +898,7 @@ GetStyle(
styleValues.fgStipple = tagPtr->fgStipple;
fgStipplePrio = tagPtr->priority;
}
if ((tagPtr->justifyString != NULL)
if ((tagPtr->justify != TK_JUSTIFY_NULL)
&& (tagPtr->priority > justifyPrio)) {
styleValues.justify = tagPtr->justify;
justifyPrio = tagPtr->priority;
Expand Down
30 changes: 11 additions & 19 deletions generic/tkTextTag.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static const Tk_OptionSpec tagOptionSpecs[] = {
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, tkfont), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_COLOR, "-foreground", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, fgColor), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-justify", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, justifyString), TK_OPTION_NULL_OK, 0,0},
{TK_OPTION_JUSTIFY, "-justify", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, justify), TK_OPTION_NULL_OK, 0,0},
{TK_OPTION_STRING, "-lmargin1", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, lMargin1String), TK_OPTION_NULL_OK,0,0},
{TK_OPTION_STRING, "-lmargin2", NULL, NULL,
Expand All @@ -49,8 +49,8 @@ static const Tk_OptionSpec tagOptionSpecs[] = {
{TK_OPTION_COLOR, "-overstrikefg", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, overstrikeColor),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-relief", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, reliefString), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_RELIEF, "-relief", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, relief), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-rmargin", NULL, NULL,
NULL, TCL_INDEX_NONE, offsetof(TkTextTag, rMarginString), TK_OPTION_NULL_OK, 0,0},
{TK_OPTION_BORDER, "-rmargincolor", NULL, NULL,
Expand Down Expand Up @@ -368,18 +368,6 @@ TkTextTagCmd(
if (tagPtr->borderWidth < 0) {
tagPtr->borderWidth = 0;
}
if (tagPtr->reliefString != NULL) {
if (Tk_GetRelief(interp, tagPtr->reliefString,
&tagPtr->relief) != TCL_OK) {
return TCL_ERROR;
}
}
if (tagPtr->justifyString != NULL) {
if (Tk_GetJustify(interp, tagPtr->justifyString,
&tagPtr->justify) != TCL_OK) {
return TCL_ERROR;
}
}
if (tagPtr->lMargin1String != NULL) {
if (Tk_GetPixels(interp, textPtr->tkwin,
tagPtr->lMargin1String, &tagPtr->lMargin1) != TCL_OK) {
Expand Down Expand Up @@ -479,7 +467,7 @@ TkTextTagCmd(
tagPtr->affectsDisplayGeometry = 0;
if ((tagPtr->elide >= 0)
|| (tagPtr->tkfont != NULL)
|| (tagPtr->justifyString != NULL)
|| (tagPtr->justify != TK_JUSTIFY_NULL)
|| (tagPtr->lMargin1String != NULL)
|| (tagPtr->lMargin2String != NULL)
|| (tagPtr->offsetString != NULL)
Expand All @@ -498,7 +486,7 @@ TkTextTagCmd(
}
if ((tagPtr->border != NULL)
|| (tagPtr->selBorder != NULL)
|| (tagPtr->reliefString != NULL)
|| (tagPtr->relief != TK_RELIEF_NULL)
|| (tagPtr->bgStipple != None)
|| (tagPtr->fgColor != NULL)
|| (tagPtr->selFgColor != NULL)
Expand Down Expand Up @@ -993,13 +981,17 @@ TkTextCreateTag(
tagPtr->border = NULL;
tagPtr->borderWidth = 0;
tagPtr->borderWidthPtr = NULL;
#if TCL_MAJOR_VERSION < 9
tagPtr->reliefString = NULL;
tagPtr->relief = TK_RELIEF_FLAT;
#endif
tagPtr->relief = TK_RELIEF_NULL;
tagPtr->bgStipple = None;
tagPtr->fgColor = NULL;
tagPtr->tkfont = NULL;
tagPtr->fgStipple = None;
#if TCL_MAJOR_VERSION < 9
tagPtr->justifyString = NULL;
#endif
tagPtr->justify = TK_JUSTIFY_NULL;
tagPtr->lMargin1String = NULL;
tagPtr->lMargin1 = 0;
Expand Down
16 changes: 8 additions & 8 deletions tests/textTag.test
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ test textTag-1.12 {tag configuration options} -body {
} -cleanup {
.t tag configure x -justify [lindex [.t tag configure x -justify] 3]
} -result {left}
test textTag-1.13 {configuration options} -body {
test textTag-1.13 {configuration options} -constraint needsTcl87 -body {
.t tag configure x -justify middle
} -cleanup {
.t tag configure x -justify [lindex [.t tag configure x -justify] 3]
} -returnCodes error -result {bad justification "middle": must be left, right, or center}
} -returnCodes error -result {bad justification "middle": must be left, right, center, or ""}
test textTag-1.14 {tag configuration options} -body {
.t tag configure x -lmargin1 10
.t tag cget x -lmargin1
Expand Down Expand Up @@ -190,11 +190,11 @@ test textTag-1.22 {tag configuration options} -body {
} -cleanup {
.t tag configure x -relief [lindex [.t tag configure x -relief] 3]
} -result {raised}
test textTag-1.23 {configuration options} -body {
test textTag-1.23 {configuration options} -constraint needsTcl87 -body {
.t tag configure x -relief stupid
} -cleanup {
.t tag configure x -relief [lindex [.t tag configure x -relief] 3]
} -returnCodes error -result {bad relief "stupid": must be flat, groove, raised, ridge, solid, or sunken}
} -returnCodes error -result {bad relief "stupid": must be flat, groove, raised, ridge, solid, sunken, or ""}
test textTag-1.24 {tag configuration options} -body {
.t tag configure x -rmargin 10
.t tag cget x -rmargin
Expand Down Expand Up @@ -538,18 +538,18 @@ test textTag-5.8 {TkTextTagCmd - "configure" option} -body {
} -cleanup {
.t tag delete x
} -result {-justify {} {} {} left}
test textTag-5.9 {TkTextTagCmd - "configure" option} -body {
test textTag-5.9 {TkTextTagCmd - "configure" option} -constraint needsTcl87 -body {
.t tag delete x
.t tag configure x -justify bogus
} -cleanup {
.t tag delete x
} -returnCodes error -result {bad justification "bogus": must be left, right, or center}
test textTag-5.10 {TkTextTagCmd - "configure" option} -body {
} -returnCodes error -result {bad justification "bogus": must be left, right, center, or ""}
test textTag-5.10 {TkTextTagCmd - "configure" option} -constraint needsTcl87 -body {
.t tag delete x
.t tag configure x -justify fill
} -cleanup {
.t tag delete x
} -returnCodes error -result {bad justification "fill": must be left, right, or center}
} -returnCodes error -result {bad justification "fill": must be left, right, center, or ""}
test textTag-5.11 {TkTextTagCmd - "configure" option} -body {
.t tag delete x
.t tag configure x -offset 2
Expand Down

0 comments on commit 3141307

Please sign in to comment.