diff options
author | treectrl <treectrl> | 2002-12-21 21:58:12 (GMT) |
---|---|---|
committer | treectrl <treectrl> | 2002-12-21 21:58:12 (GMT) |
commit | 38c497adc6727ac79dcaec378c67f795f9e808f2 (patch) | |
tree | e55e868ee3fac01007e85f792ec63fbefcf83cbf /generic | |
parent | 898d0d64d9265fae448403558a7df6804cd6999a (diff) | |
download | tktreectrl-38c497adc6727ac79dcaec378c67f795f9e808f2.zip tktreectrl-38c497adc6727ac79dcaec378c67f795f9e808f2.tar.gz tktreectrl-38c497adc6727ac79dcaec378c67f795f9e808f2.tar.bz2 |
Text layout fixes.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkTreeElem.c | 29 | ||||
-rw-r--r-- | generic/tkTreeElem.h | 1 | ||||
-rw-r--r-- | generic/tkTreeStyle.c | 63 | ||||
-rw-r--r-- | generic/tkTreeUtils.c | 6 |
4 files changed, 57 insertions, 42 deletions
diff --git a/generic/tkTreeElem.c b/generic/tkTreeElem.c index e3c94e0..7079620 100644 --- a/generic/tkTreeElem.c +++ b/generic/tkTreeElem.c @@ -2857,8 +2857,8 @@ static void TextUpdateLayout(ElementArgs *args) if (elemX->layout != NULL) { -/*if (tree->debug.enable && tree->debug.display) - dbwin("TextUpdateLayout %s: free %p (%s)\n", Tk_PathName(tree->tkwin), elemX, masterX ? "instance" : "master");*/ +if (1 && tree->debug.enable && tree->debug.display) + dbwin("TextUpdateLayout %s: free %p (%s)\n", Tk_PathName(tree->tkwin), elemX, masterX ? "instance" : "master"); TextLayout_Free(elemX->layout); elemX->layout = NULL; } @@ -2896,7 +2896,9 @@ static void TextUpdateLayout(ElementArgs *args) width = elemX->width; else if ((masterX != NULL) && (masterX->widthObj != NULL)) width = masterX->width; - +if (0 && tree->debug.enable) +dbwin("lines %d multiLine %d width %d squeeze %d\n", +lines, multiLine, width, args->layout.squeeze); if ((lines == 1) || (!multiLine && (width == 0))) return; @@ -2926,8 +2928,8 @@ static void TextUpdateLayout(ElementArgs *args) elemX->layout = TextLayout_Compute(tkfont, text, Tcl_NumUtfChars(text, textLen), width, justify, lines, flags); -/*if (tree->debug.enable && tree->debug.display) - dbwin("TextUpdateLayout %s: alloc %p (%s)\n", Tk_PathName(tree->tkwin), elemX, masterX ? "instance" : "master");*/ +if (1 && tree->debug.enable && tree->debug.display) + dbwin("TextUpdateLayout %s: alloc %p (%s)\n", Tk_PathName(tree->tkwin), elemX, masterX ? "instance" : "master"); } static void DeleteText(ElementArgs *args) @@ -3098,9 +3100,6 @@ static void DisplayText(ElementArgs *args) if (elemX->layout != NULL) layout = elemX->layout; - else if ((elemX->text == NULL) && (masterX != NULL) && - (masterX->layout != NULL)) - layout = masterX->layout; if (layout != NULL) { @@ -3175,15 +3174,6 @@ static void LayoutText(ElementArgs *args) } #endif - if ((masterX != NULL) /* && (elemX != masterX) */ && - (masterX->layoutInvalid || (masterX->layoutWidth != args->layout.width))) - { - args->elem = (Element *) masterX; - TextUpdateLayout(args); - args->elem = elem; - masterX->layoutInvalid = FALSE; - masterX->layoutWidth = args->layout.width; - } if (elemX->layoutInvalid || (elemX->layoutWidth != args->layout.width)) { TextUpdateLayout(args); @@ -3193,9 +3183,6 @@ static void LayoutText(ElementArgs *args) if (elemX->layout != NULL) layout = elemX->layout; - else if ((elemX->text == NULL) && (masterX != NULL) && - (masterX->layout != NULL)) - layout = masterX->layout; if (layout != NULL) { @@ -3240,7 +3227,7 @@ static void LayoutText(ElementArgs *args) width = elemX->width; else if ((masterX != NULL) && (masterX->widthObj != NULL)) width = masterX->width; - if (width && (width < args->layout.width)) + if ((width > 0) && (width < args->layout.width)) args->layout.width = width; Tk_GetFontMetrics(tkfont, &fm); args->layout.height = fm.linespace; /* TODO: multi-line strings */ diff --git a/generic/tkTreeElem.h b/generic/tkTreeElem.h index 524e4f6..11e57d1 100644 --- a/generic/tkTreeElem.h +++ b/generic/tkTreeElem.h @@ -27,6 +27,7 @@ struct ElementArgs Drawable drawable; } display; struct { + int squeeze; int width; int height; } layout; diff --git a/generic/tkTreeStyle.c b/generic/tkTreeStyle.c index 15b06c8..c1a550e 100644 --- a/generic/tkTreeStyle.c +++ b/generic/tkTreeStyle.c @@ -1167,21 +1167,32 @@ static void Style_DoLayout2(StyleDrawArgs *drawArgs, struct Layout layouts[20]) layout->useHeight = eLink->neededHeight; + /* If a Text Element is given less width than it needs (due to + * -squeeze x layout), then it may wrap lines. This means + * the height can vary depending on the width. */ if (eLink->elem->typePtr == &elemTypeText) { - if (layout->iWidth != eLink->layoutWidth) + ElementArgs args; + + if (layout->iWidth == eLink->layoutWidth) { - ElementArgs args; + layout->useHeight = eLink->layoutHeight; + continue; + } - args.tree = tree; - args.state = state; - args.elem = eLink->elem; - args.layout.width = layout->iWidth; - (*args.elem->typePtr->layoutProc)(&args); + if ((eLink->layoutWidth == -1) && + (layout->iWidth >= eLink->neededWidth)) + continue; - eLink->layoutWidth = layout->iWidth; - eLink->layoutHeight = args.layout.height; - } + args.tree = tree; + args.state = state; + args.elem = eLink->elem; + args.layout.squeeze = layout->iWidth < eLink->neededWidth; + args.layout.width = layout->iWidth; + (*args.elem->typePtr->layoutProc)(&args); + + eLink->layoutWidth = layout->iWidth; + eLink->layoutHeight = args.layout.height; layout->useHeight = eLink->layoutHeight; } } @@ -1209,21 +1220,32 @@ static void Style_DoLayout(StyleDrawArgs *drawArgs, struct Layout layouts[20], c layout->useHeight = eLink->neededHeight; + /* If a Text Element is given less width than it needs (due to + * -squeeze x layout), then it may wrap lines. This means + * the height can vary depending on the width. */ if (eLink->elem->typePtr == &elemTypeText) { - if (layout->iWidth != eLink->layoutWidth) + ElementArgs args; + + if (layout->iWidth == eLink->layoutWidth) { - ElementArgs args; + layout->useHeight = eLink->layoutHeight; + continue; + } - args.tree = tree; - args.state = state; - args.elem = eLink->elem; - args.layout.width = layout->iWidth; - (*args.elem->typePtr->layoutProc)(&args); + if ((eLink->layoutWidth == -1) && + (layout->iWidth >= eLink->neededWidth)) + continue; - eLink->layoutWidth = layout->iWidth; - eLink->layoutHeight = args.layout.height; - } + args.tree = tree; + args.state = state; + args.elem = eLink->elem; + args.layout.squeeze = layout->iWidth < eLink->neededWidth; + args.layout.width = layout->iWidth; + (*args.elem->typePtr->layoutProc)(&args); + + eLink->layoutWidth = layout->iWidth; + eLink->layoutHeight = args.layout.height; layout->useHeight = eLink->layoutHeight; } } @@ -1311,6 +1333,7 @@ static void Style_NeededSize(TreeCtrl *tree, Style *style, int state, int *width args.tree = tree; args.state = state; args.elem = eLink2->elem; + args.layout.squeeze = 0; args.layout.width = -1; (*args.elem->typePtr->layoutProc)(&args); eLink2->neededWidth = args.layout.width; diff --git a/generic/tkTreeUtils.c b/generic/tkTreeUtils.c index 9c8b482..f03de2d 100644 --- a/generic/tkTreeUtils.c +++ b/generic/tkTreeUtils.c @@ -641,8 +641,9 @@ wrapLine: curX = 0; baseline += height; + layoutPtr->numLines++; - if ((maxLines > 0) && (++layoutPtr->numLines >= maxLines)) + if ((maxLines > 0) && (layoutPtr->numLines >= maxLines)) break; } @@ -780,6 +781,9 @@ finish: Tcl_DStringFree(&lineBuffer); + if (layoutPtr->numLines == 1) + dbwin("WARNING: single-line TextLayout created\n"); + return (TextLayout) layoutPtr; } |