summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authortreectrl <treectrl>2006-12-04 20:11:18 (GMT)
committertreectrl <treectrl>2006-12-04 20:11:18 (GMT)
commit359b188d95c280ba5a80b0065a22b44db1f843b9 (patch)
tree776f0179df5718484b0f6d0d21183fc1d020899b /generic
parent65bace58a9abeb2eef787fd109d1698b1a8fafde (diff)
downloadtktreectrl-359b188d95c280ba5a80b0065a22b44db1f843b9.zip
tktreectrl-359b188d95c280ba5a80b0065a22b44db1f843b9.tar.gz
tktreectrl-359b188d95c280ba5a80b0065a22b44db1f843b9.tar.bz2
Fixed bug where text elements were requesting height when displaying an empty string. Stopped allocating a zero-length string.
Diffstat (limited to 'generic')
-rw-r--r--generic/tkTreeElem.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/generic/tkTreeElem.c b/generic/tkTreeElem.c
index b43b7ac..80b0cf5 100644
--- a/generic/tkTreeElem.c
+++ b/generic/tkTreeElem.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2002-2006 Tim Baker
*
- * RCS: @(#) $Id: tkTreeElem.c,v 1.54 2006/12/04 05:51:18 treectrl Exp $
+ * RCS: @(#) $Id: tkTreeElem.c,v 1.55 2006/12/04 20:11:18 treectrl Exp $
*/
#include "tkTreeCtrl.h"
@@ -2398,6 +2398,7 @@ static void TextUpdateStringRep(ElementArgs *args)
if ((elemX->textObj == NULL) && (elemX->text != NULL)) {
ckfree(elemX->text);
elemX->text = NULL;
+ elemX->textLen = 0;
}
/* If -text is specified, -data, -datatype and -format are ignored */
@@ -2416,14 +2417,17 @@ static void TextUpdateStringRep(ElementArgs *args)
varNameObj = etv ? etv->varNameObj : NULL;
if (varNameObj != NULL) {
- Tcl_Obj *valueObj = Tcl_ObjGetVar2(tree->interp, varNameObj, NULL, TCL_GLOBAL_ONLY);
+ Tcl_Obj *valueObj = Tcl_ObjGetVar2(tree->interp, varNameObj, NULL,
+ TCL_GLOBAL_ONLY);
if (valueObj == NULL) {
/* not possible I think */
} else {
char *string = Tcl_GetStringFromObj(valueObj, &elemX->textLen);
- elemX->text = ckalloc(elemX->textLen);
- memcpy(elemX->text, string, elemX->textLen);
+ if (elemX->textLen > 0) {
+ elemX->text = ckalloc(elemX->textLen);
+ memcpy(elemX->text, string, elemX->textLen);
+ }
}
return;
}
@@ -2553,8 +2557,10 @@ static void TextUpdateStringRep(ElementArgs *args)
if (resultObj != NULL) {
char *string = Tcl_GetStringFromObj(resultObj, &elemX->textLen);
- elemX->text = ckalloc(elemX->textLen);
- memcpy(elemX->text, string, elemX->textLen);
+ if (elemX->textLen > 0) {
+ elemX->text = ckalloc(elemX->textLen);
+ memcpy(elemX->text, string, elemX->textLen);
+ }
}
}
}
@@ -3171,7 +3177,7 @@ static void NeededProcText(ElementArgs *args)
text = masterX->text;
textLen = masterX->textLen;
}
- if (text != NULL) {
+ if (textLen > 0) {
int maxWidth = -1;
tkfont = DO_FontForState(tree, elem, 1004, state);
@@ -3204,6 +3210,7 @@ static void HeightProcText(ElementArgs *args)
int state = args->state;
int height = 0;
char *text = NULL;
+ int textLen = 0;
Tk_Font tkfont;
Tk_FontMetrics fm;
ElementTextLayout2 *etl2;
@@ -3215,10 +3222,12 @@ static void HeightProcText(ElementArgs *args)
} else {
if (elemX->text != NULL) {
text = elemX->text;
+ textLen = elemX->textLen;
} else if ((masterX != NULL) && (masterX->text != NULL)) {
text = masterX->text;
+ textLen = masterX->textLen;
}
- if (text != NULL) {
+ if (textLen > 0) {
tkfont = DO_FontForState(tree, elem, 1004, state);
if (tkfont == NULL)
tkfont = tree->tkfont;