From b6a8a33706e8b40d3b7dc7560f48db43202d1078 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 16 Jan 2024 21:28:16 +0000 Subject: (partial) fix for [026e2bb685]: text tag sets bad relief, gets error, but bad relief is saved anyway. -relief and -justify is working now, but other options hstill have the same problem --- generic/tkTextTag.c | 18 ++++++++++++++++-- tests/textTag.test | 17 ++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/generic/tkTextTag.c b/generic/tkTextTag.c index 4126a49..2cd0d55 100644 --- a/generic/tkTextTag.c +++ b/generic/tkTextTag.c @@ -394,16 +394,30 @@ TkTextTagCmd( &tagPtr->relief) != TCL_OK) { ckfree(tagPtr->reliefString); tagPtr->reliefString = NULL; + if ((unsigned)tagPtr->relief <= TK_RELIEF_SUNKEN) { + const char *reliefString = Tk_NameOfRelief(tagPtr->relief); + tagPtr->reliefString = ckalloc(strlen(reliefString)+1); + strcpy(tagPtr->reliefString, reliefString); + } return TCL_ERROR; } + } else { + tagPtr->relief = TK_RELIEF_NULL; } if (tagPtr->justifyString != NULL) { if (Tk_GetJustify(interp, tagPtr->justifyString, &tagPtr->justify) != TCL_OK) { ckfree(tagPtr->justifyString); tagPtr->justifyString = NULL; + if ((unsigned)tagPtr->justify <= (unsigned)TK_JUSTIFY_CENTER) { + const char *justifyString = Tk_NameOfJustify(tagPtr->justify); + tagPtr->justifyString = ckalloc(strlen(justifyString)+1); + strcpy(tagPtr->justifyString, justifyString); + } return TCL_ERROR; } + } else { + tagPtr->justify = (Tk_Justify)-1; } if (tagPtr->lMargin1String != NULL) { if (Tk_GetPixels(interp, textPtr->tkwin, @@ -1036,13 +1050,13 @@ TkTextCreateTag( tagPtr->borderWidth = 0; tagPtr->borderWidthPtr = NULL; tagPtr->reliefString = NULL; - tagPtr->relief = TK_RELIEF_FLAT; + tagPtr->relief = TK_RELIEF_NULL; tagPtr->bgStipple = None; tagPtr->fgColor = NULL; tagPtr->tkfont = NULL; tagPtr->fgStipple = None; tagPtr->justifyString = NULL; - tagPtr->justify = TK_JUSTIFY_LEFT; + tagPtr->justify = (Tk_Justify)-1; tagPtr->lMargin1String = NULL; tagPtr->lMargin1 = 0; tagPtr->lMargin2String = NULL; diff --git a/tests/textTag.test b/tests/textTag.test index 1de80bc..cf3794b 100644 --- a/tests/textTag.test +++ b/tests/textTag.test @@ -3,7 +3,7 @@ # # Copyright (c) 1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. -# Copyright (c) 1998-1999 by Scriptics Corporation. +# Copyright (c) 1998-1999 Scriptics Corporation. # All rights reserved. package require tcltest 2.2 @@ -113,11 +113,13 @@ 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 { - .t tag configure x -justify middle +test textTag-1.13 {configuration options, bug [026e2bb685]} -body { + .t tag configure x -justify right + catch {.t tag configure x -justify middle} msg + list $msg [.t tag configure x -justify] } -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} +} -result {{bad justification "middle": must be left, right, or center} {-justify {} {} {} right}} test textTag-1.14 {tag configuration options} -body { .t tag configure x -lmargin1 10 .t tag cget x -lmargin1 @@ -538,12 +540,13 @@ 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, bug [026e2bb685]} -body { .t tag delete x - .t tag configure x -justify bogus + catch {.t tag configure x -justify bogus} msg + list $msg [.t tag configure x -justify] } -cleanup { .t tag delete x -} -returnCodes error -result {bad justification "bogus": must be left, right, or center} +} -result {{bad justification "bogus": must be left, right, or center} {-justify {} {} {} {}}} test textTag-5.10 {TkTextTagCmd - "configure" option} -body { .t tag delete x .t tag configure x -justify fill -- cgit v0.12