summaryrefslogtreecommitdiffstats
path: root/generic/tkTextDisp.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkTextDisp.c')
-rw-r--r--generic/tkTextDisp.c859
1 files changed, 427 insertions, 432 deletions
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 905a4c6..185681f 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -24,8 +24,6 @@
#include "tkMacOSXInt.h"
#endif
-#define OK_TO_LOG (!TkpWillDrawWidget(textPtr->tkwin))
-
/*
* "Calculations of line pixel heights and the size of the vertical
* scrollbar."
@@ -142,7 +140,7 @@ typedef struct StyleValues {
int overstrike; /* Non-zero means draw overstrike through
* text. */
XColor *overstrikeColor; /* Foreground color for overstrike through
- * text. */
+ * text. */
int rMargin; /* Right margin, in pixels. */
Tk_3DBorder rMarginColor; /* Color of right margin. */
int spacing1; /* Spacing above first dline in text line. */
@@ -155,7 +153,7 @@ typedef struct StyleValues {
int underline; /* Non-zero means draw underline underneath
* text. */
XColor *underlineColor; /* Foreground color for underline underneath
- * text. */
+ * text. */
int elide; /* Zero means draw text, otherwise not. */
TkWrapMode wrapMode; /* How to handle wrap-around for this tag.
* One of TEXT_WRAPMODE_CHAR,
@@ -205,20 +203,13 @@ typedef struct TextStyle {
/*
* Macros to make debugging/testing logging a little easier.
- *
- * On OSX 10.14 Drawing procedures are sometimes run because the system has
- * decided to redraw the window. This can corrupt the data that a test is
- * trying to collect. So we don't write to the logging variables when the
- * drawing procedure is being run that way. Other systems can always log.
*/
#define LOG(toVar,what) \
- if (OK_TO_LOG) \
- Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \
- TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT)
+ Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \
+ TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT)
#define CLEAR(var) \
- if (OK_TO_LOG) \
- Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY)
+ Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY)
/*
* The following structure describes one line of the display, which may be
@@ -255,11 +246,11 @@ typedef struct DLine {
Tk_3DBorder lMarginColor; /* Background color of the area corresponding
* to the left margin of the display line. */
int lMarginWidth; /* Pixel width of the area corresponding to
- * the left margin. */
+ * the left margin. */
Tk_3DBorder rMarginColor; /* Background color of the area corresponding
* to the right margin of the display line. */
int rMarginWidth; /* Pixel width of the area corresponding to
- * the right margin. */
+ * the right margin. */
int length; /* Total length of line, in pixels. */
TkTextDispChunk *chunkPtr; /* Pointer to first chunk in list of all of
* those that are displayed on this line of
@@ -573,7 +564,7 @@ static void DisplayLineBackground(TkText *textPtr, DLine *dlPtr,
DLine *prevPtr, Pixmap pixmap);
static void DisplayText(void *clientData);
static DLine * FindDLine(TkText *textPtr, DLine *dlPtr,
- const TkTextIndex *indexPtr);
+ const TkTextIndex *indexPtr);
static void FreeDLines(TkText *textPtr, DLine *firstPtr,
DLine *lastPtr, int action);
static void FreeStyle(TkText *textPtr, TextStyle *stylePtr);
@@ -622,7 +613,7 @@ static void AsyncUpdateLineMetrics(void *clientData);
static void GenerateWidgetViewSyncEvent(TkText *textPtr, Bool InSync);
static void AsyncUpdateYScrollbar(void *clientData);
static int IsStartOfNotMergedLine(const TkText *textPtr,
- const TkTextIndex *indexPtr);
+ const TkTextIndex *indexPtr);
/*
* Result values returned by TextGetScrollInfoObj:
@@ -813,9 +804,9 @@ GetStyle(
styleValues.overstrikeColor = textPtr->fgColor;
styleValues.tkfont = textPtr->tkfont;
styleValues.justify = TK_JUSTIFY_LEFT;
- styleValues.spacing1 = textPtr->spacing1;
- styleValues.spacing2 = textPtr->spacing2;
- styleValues.spacing3 = textPtr->spacing3;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->spacing1Obj, &styleValues.spacing1);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->spacing2Obj, &styleValues.spacing2);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->spacing3Obj, &styleValues.spacing3);
styleValues.tabArrayPtr = textPtr->tabArrayPtr;
styleValues.tabStyle = textPtr->tabStyle;
styleValues.wrapMode = textPtr->wrapMode;
@@ -823,19 +814,19 @@ GetStyle(
isSelected = 0;
for (i = 0 ; i < numTags; i++) {
- if (textPtr->selTagPtr == tagPtrs[i]) {
- isSelected = 1;
- break;
- }
+ if (textPtr->selTagPtr == tagPtrs[i]) {
+ isSelected = 1;
+ break;
+ }
}
for (i = 0 ; i < numTags; i++) {
Tk_3DBorder border;
- XColor *fgColor;
+ XColor *fgColor;
tagPtr = tagPtrs[i];
border = tagPtr->border;
- fgColor = tagPtr->fgColor;
+ fgColor = tagPtr->fgColor;
/*
* If this is the selection tag, and inactiveSelBorder is NULL (the
@@ -855,22 +846,22 @@ GetStyle(
border = textPtr->inactiveSelBorder;
}
- if ((tagPtr->selBorder != NULL) && (isSelected)) {
- border = tagPtr->selBorder;
- }
+ if ((tagPtr->selBorder != NULL) && (isSelected)) {
+ border = tagPtr->selBorder;
+ }
- if ((tagPtr->selFgColor != NULL) && isSelected) {
- fgColor = tagPtr->selFgColor;
- }
+ if ((tagPtr->selFgColor != NULL) && isSelected) {
+ fgColor = tagPtr->selFgColor;
+ }
if ((border != NULL) && (tagPtr->priority > borderPrio)) {
styleValues.border = border;
borderPrio = tagPtr->priority;
}
- if ((tagPtr->borderWidthPtr != NULL)
- && (Tcl_GetString(tagPtr->borderWidthPtr)[0] != '\0')
+ if ((tagPtr->borderWidthObj != NULL)
+ && (Tcl_GetString(tagPtr->borderWidthObj)[0] != '\0')
&& (tagPtr->priority > borderWidthPrio)) {
- styleValues.borderWidth = tagPtr->borderWidth;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->borderWidthObj, &styleValues.borderWidth);
borderWidthPrio = tagPtr->priority;
}
if ((tagPtr->relief != TK_RELIEF_NULL)
@@ -904,14 +895,14 @@ GetStyle(
styleValues.justify = tagPtr->justify;
justifyPrio = tagPtr->priority;
}
- if ((tagPtr->lMargin1 != INT_MIN)
+ if ((tagPtr->lMargin1Obj != NULL)
&& (tagPtr->priority > lMargin1Prio)) {
- styleValues.lMargin1 = tagPtr->lMargin1;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->lMargin1Obj, &styleValues.lMargin1);
lMargin1Prio = tagPtr->priority;
}
- if ((tagPtr->lMargin2 != INT_MIN)
+ if ((tagPtr->lMargin2Obj != NULL)
&& (tagPtr->priority > lMargin2Prio)) {
- styleValues.lMargin2 = tagPtr->lMargin2;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->lMargin2Obj, &styleValues.lMargin2);
lMargin2Prio = tagPtr->priority;
}
if ((tagPtr->lMarginColor != NULL)
@@ -919,24 +910,24 @@ GetStyle(
styleValues.lMarginColor = tagPtr->lMarginColor;
lMarginColorPrio = tagPtr->priority;
}
- if ((tagPtr->offset != INT_MIN)
+ if ((tagPtr->offsetObj != NULL)
&& (tagPtr->priority > offsetPrio)) {
- styleValues.offset = tagPtr->offset;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->offsetObj, &styleValues.offset);
offsetPrio = tagPtr->priority;
}
if ((tagPtr->overstrike >= 0)
&& (tagPtr->priority > overstrikePrio)) {
styleValues.overstrike = tagPtr->overstrike > 0;
overstrikePrio = tagPtr->priority;
- if (tagPtr->overstrikeColor != NULL) {
- styleValues.overstrikeColor = tagPtr->overstrikeColor;
- } else if (fgColor != NULL) {
- styleValues.overstrikeColor = fgColor;
- }
+ if (tagPtr->overstrikeColor != NULL) {
+ styleValues.overstrikeColor = tagPtr->overstrikeColor;
+ } else if (fgColor != NULL) {
+ styleValues.overstrikeColor = fgColor;
+ }
}
- if ((tagPtr->rMargin != INT_MIN)
+ if ((tagPtr->rMarginObj != NULL)
&& (tagPtr->priority > rMarginPrio)) {
- styleValues.rMargin = tagPtr->rMargin;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->rMarginObj, &styleValues.rMargin);
rMarginPrio = tagPtr->priority;
}
if ((tagPtr->rMarginColor != NULL)
@@ -944,19 +935,19 @@ GetStyle(
styleValues.rMarginColor = tagPtr->rMarginColor;
rMarginColorPrio = tagPtr->priority;
}
- if ((tagPtr->spacing1 != INT_MIN)
+ if ((tagPtr->spacing1Obj != NULL)
&& (tagPtr->priority > spacing1Prio)) {
- styleValues.spacing1 = tagPtr->spacing1;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->spacing1Obj, &styleValues.spacing1);
spacing1Prio = tagPtr->priority;
}
- if ((tagPtr->spacing2 != INT_MIN)
+ if ((tagPtr->spacing2Obj != NULL)
&& (tagPtr->priority > spacing2Prio)) {
- styleValues.spacing2 = tagPtr->spacing2;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->spacing2Obj, &styleValues.spacing2);
spacing2Prio = tagPtr->priority;
}
- if ((tagPtr->spacing3 != INT_MIN)
+ if ((tagPtr->spacing3Obj != NULL)
&& (tagPtr->priority > spacing3Prio)) {
- styleValues.spacing3 = tagPtr->spacing3;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, tagPtr->spacing3Obj, &styleValues.spacing3);
spacing3Prio = tagPtr->priority;
}
if ((tagPtr->tabStringPtr != NULL)
@@ -974,19 +965,19 @@ GetStyle(
&& (tagPtr->priority > underlinePrio)) {
styleValues.underline = tagPtr->underline > 0;
underlinePrio = tagPtr->priority;
- if (tagPtr->underlineColor != NULL) {
- styleValues.underlineColor = tagPtr->underlineColor;
- } else if (fgColor != NULL) {
- styleValues.underlineColor = fgColor;
- }
+ if (tagPtr->underlineColor != NULL) {
+ styleValues.underlineColor = tagPtr->underlineColor;
+ } else if (fgColor != NULL) {
+ styleValues.underlineColor = fgColor;
+ }
}
if ((tagPtr->elide >= 0)
&& (tagPtr->priority > elidePrio)) {
styleValues.elide = tagPtr->elide > 0;
elidePrio = tagPtr->priority;
}
- if ((tagPtr->wrapMode != TEXT_WRAPMODE_NULL)
- && (tagPtr->priority > wrapPrio)) {
+ if (((tagPtr->wrapMode == TEXT_WRAPMODE_CHAR) || (tagPtr->wrapMode == TEXT_WRAPMODE_NONE)
+ || (tagPtr->wrapMode == TEXT_WRAPMODE_WORD)) && (tagPtr->priority > wrapPrio)) {
styleValues.wrapMode = tagPtr->wrapMode;
wrapPrio = tagPtr->priority;
}
@@ -1476,7 +1467,7 @@ LayoutDLine(
x = chunkPtr->stylePtr->sValuePtr->lMargin2;
}
- dlPtr->lMarginWidth = x;
+ dlPtr->lMarginWidth = x;
if (wrapMode == TEXT_WRAPMODE_NONE) {
maxX = -1;
} else {
@@ -1791,7 +1782,7 @@ LayoutDLine(
dlPtr->lMarginColor = sValuePtr->lMarginColor;
dlPtr->rMarginColor = sValuePtr->rMarginColor;
if (wrapMode != TEXT_WRAPMODE_NONE) {
- dlPtr->rMarginWidth = rMargin;
+ dlPtr->rMarginWidth = rMargin;
}
/*
@@ -2099,9 +2090,9 @@ UpdateDisplayInfo(
* widget.
*/
- lineNum = TkBTreeNumLines(textPtr->sharedTextPtr->tree,
- textPtr) - 1;
- bytesToCount = INT_MAX;
+ lineNum = TkBTreeNumLines(textPtr->sharedTextPtr->tree,
+ textPtr) - 1;
+ bytesToCount = INT_MAX;
} else {
lineNum = TkBTreeLinesTo(textPtr,
dInfoPtr->dLinePtr->index.linePtr);
@@ -2488,14 +2479,14 @@ DisplayDLine(
* Third, draw the background color of the left and right margins.
*/
if (dlPtr->lMarginColor != NULL) {
- Tk_Fill3DRectangle(textPtr->tkwin, pixmap, dlPtr->lMarginColor, 0, y,
- dlPtr->lMarginWidth + dInfoPtr->x - dInfoPtr->curXPixelOffset,
- dlPtr->height, 0, TK_RELIEF_FLAT);
+ Tk_Fill3DRectangle(textPtr->tkwin, pixmap, dlPtr->lMarginColor, 0, y,
+ dlPtr->lMarginWidth + dInfoPtr->x - dInfoPtr->curXPixelOffset,
+ dlPtr->height, 0, TK_RELIEF_FLAT);
}
if (dlPtr->rMarginColor != NULL) {
- Tk_Fill3DRectangle(textPtr->tkwin, pixmap, dlPtr->rMarginColor,
- dInfoPtr->maxX - dlPtr->rMarginWidth + dInfoPtr->curXPixelOffset,
- y, dlPtr->rMarginWidth, dlPtr->height, 0, TK_RELIEF_FLAT);
+ Tk_Fill3DRectangle(textPtr->tkwin, pixmap, dlPtr->rMarginColor,
+ dInfoPtr->maxX - dlPtr->rMarginWidth + dInfoPtr->curXPixelOffset,
+ y, dlPtr->rMarginWidth, dlPtr->height, 0, TK_RELIEF_FLAT);
}
/*
@@ -2720,15 +2711,15 @@ DisplayLineBackground(
rightX = leftX + 32767;
}
- /*
- * Prevent the borders from leaking on adjacent characters,
- * which would happen for too large border width.
- */
+ /*
+ * Prevent the borders from leaking on adjacent characters,
+ * which would happen for too large border width.
+ */
- bw = sValuePtr->borderWidth;
- if (leftX + sValuePtr->borderWidth > rightX) {
- bw = rightX - leftX;
- }
+ bw = sValuePtr->borderWidth;
+ if (leftX + sValuePtr->borderWidth > rightX) {
+ bw = rightX - leftX;
+ }
XFillRectangle(display, pixmap, chunkPtr->stylePtr->bgGC,
leftX + xOffset, y, (unsigned int) (rightX - leftX),
@@ -2835,23 +2826,23 @@ DisplayLineBackground(
matchRight = (nextPtr2 != NULL)
&& SAME_BACKGROUND(nextPtr2->stylePtr, chunkPtr->stylePtr);
if (matchLeft && !matchRight) {
- bw = sValuePtr->borderWidth;
- if (rightX2 - sValuePtr->borderWidth < leftX) {
- bw = rightX2 - leftX;
- }
+ bw = sValuePtr->borderWidth;
+ if (rightX2 - sValuePtr->borderWidth < leftX) {
+ bw = rightX2 - leftX;
+ }
if (sValuePtr->relief != TK_RELIEF_FLAT) {
Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border,
rightX2 - bw + xOffset, y, bw,
sValuePtr->borderWidth, 0, sValuePtr->relief);
}
- leftX = rightX2 - bw;
+ leftX = rightX2 - bw;
leftXIn = 0;
} else if (!matchLeft && matchRight
&& (sValuePtr->relief != TK_RELIEF_FLAT)) {
- bw = sValuePtr->borderWidth;
- if (rightX2 + sValuePtr->borderWidth > rightX) {
- bw = rightX - rightX2;
- }
+ bw = sValuePtr->borderWidth;
+ if (rightX2 + sValuePtr->borderWidth > rightX) {
+ bw = rightX - rightX2;
+ }
Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border,
rightX2 + xOffset, y, bw, sValuePtr->borderWidth,
1, sValuePtr->relief);
@@ -2945,10 +2936,10 @@ DisplayLineBackground(
matchRight = (nextPtr2 != NULL)
&& SAME_BACKGROUND(nextPtr2->stylePtr, chunkPtr->stylePtr);
if (matchLeft && !matchRight) {
- bw = sValuePtr->borderWidth;
- if (rightX2 - sValuePtr->borderWidth < leftX) {
- bw = rightX2 - leftX;
- }
+ bw = sValuePtr->borderWidth;
+ if (rightX2 - sValuePtr->borderWidth < leftX) {
+ bw = rightX2 - leftX;
+ }
if (sValuePtr->relief != TK_RELIEF_FLAT) {
Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border,
rightX2 - bw + xOffset,
@@ -2959,10 +2950,10 @@ DisplayLineBackground(
leftXIn = 1;
} else if (!matchLeft && matchRight
&& (sValuePtr->relief != TK_RELIEF_FLAT)) {
- bw = sValuePtr->borderWidth;
- if (rightX2 + sValuePtr->borderWidth > rightX) {
- bw = rightX - rightX2;
- }
+ bw = sValuePtr->borderWidth;
+ if (rightX2 + sValuePtr->borderWidth > rightX) {
+ bw = rightX - rightX2;
+ }
Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border,
rightX2 + xOffset,
y + dlPtr->height - sValuePtr->borderWidth, bw,
@@ -3022,7 +3013,7 @@ AsyncUpdateLineMetrics(
dInfoPtr->lineUpdateTimer = NULL;
if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)
- || !Tk_IsMapped(textPtr->tkwin)) {
+ || !Tk_IsMapped(textPtr->tkwin)) {
/*
* The widget has been deleted, or is not mapped. Don't do anything.
*/
@@ -3082,27 +3073,27 @@ AsyncUpdateLineMetrics(
* after the afterSyncCmd pointer had been set to NULL.
*/
- if (textPtr->afterSyncCmd) {
- int code;
+ if (textPtr->afterSyncCmd) {
+ int code;
Tcl_CancelIdleCall(TkTextRunAfterSyncCmd, textPtr);
- Tcl_Preserve(textPtr->interp);
- code = Tcl_EvalObjEx(textPtr->interp, textPtr->afterSyncCmd,
- TCL_EVAL_GLOBAL);
+ Tcl_Preserve(textPtr->interp);
+ code = Tcl_EvalObjEx(textPtr->interp, textPtr->afterSyncCmd,
+ TCL_EVAL_GLOBAL);
if (code == TCL_ERROR) {
- Tcl_AddErrorInfo(textPtr->interp, "\n (text sync)");
- Tcl_BackgroundException(textPtr->interp, TCL_ERROR);
+ Tcl_AddErrorInfo(textPtr->interp, "\n (text sync)");
+ Tcl_BackgroundException(textPtr->interp, TCL_ERROR);
}
- Tcl_Release(textPtr->interp);
- Tcl_DecrRefCount(textPtr->afterSyncCmd);
- textPtr->afterSyncCmd = NULL;
+ Tcl_Release(textPtr->interp);
+ Tcl_DecrRefCount(textPtr->afterSyncCmd);
+ textPtr->afterSyncCmd = NULL;
}
- /*
- * Fire the <<WidgetViewSync>> event since the widget view is in sync
- * with its internal data (actually it will be after the next trip
- * through the event loop, because the widget redraws at idle-time).
- */
- GenerateWidgetViewSyncEvent(textPtr, 1);
+ /*
+ * Fire the <<WidgetViewSync>> event since the widget view is in sync
+ * with its internal data (actually it will be after the next trip
+ * through the event loop, because the widget redraws at idle-time).
+ */
+ GenerateWidgetViewSyncEvent(textPtr, 1);
if (textPtr->refCount-- <= 1) {
ckfree(textPtr);
@@ -3218,8 +3209,8 @@ TkTextUpdateLineMetrics(
int count = 0;
int totalLines = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr);
int fullUpdateRequested = (lineNum == 0 &&
- endLine == totalLines &&
- doThisMuch == -1);
+ endLine == totalLines &&
+ doThisMuch == -1);
if (totalLines == 0) {
/*
@@ -3398,7 +3389,7 @@ TkTextUpdateLineMetrics(
GetYView(textPtr->interp, textPtr, 1);
}
if (fullUpdateRequested) {
- GenerateWidgetViewSyncEvent(textPtr, 1);
+ GenerateWidgetViewSyncEvent(textPtr, 1);
}
return lineNum;
}
@@ -3774,24 +3765,24 @@ CalculateDisplayLineHeight(
int pixelHeight;
if (tkTextDebug) {
- int oldtkTextDebug = tkTextDebug;
- /*
- * Check that the indexPtr we are given really is at the start of a
- * display line. The gymnastics with tkTextDebug is to prevent
- * failure of a test suite test, that checks that lines are rendered
- * exactly once. TkTextFindDisplayLineEnd is used here for checking
- * indexPtr but it calls LayoutDLine/FreeDLine which makes the
- * counting wrong. The debug mode shall therefore be switched off
- * when calling TkTextFindDisplayLineEnd.
- */
-
- TkTextIndex indexPtr2 = *indexPtr;
- tkTextDebug = 0;
- TkTextFindDisplayLineEnd(textPtr, &indexPtr2, 0, NULL);
- tkTextDebug = oldtkTextDebug;
- if (TkTextIndexCmp(&indexPtr2,indexPtr) != 0) {
- Tcl_Panic("CalculateDisplayLineHeight called with bad indexPtr");
- }
+ int oldtkTextDebug = tkTextDebug;
+ /*
+ * Check that the indexPtr we are given really is at the start of a
+ * display line. The gymnastics with tkTextDebug is to prevent
+ * failure of a test suite test, that checks that lines are rendered
+ * exactly once. TkTextFindDisplayLineEnd is used here for checking
+ * indexPtr but it calls LayoutDLine/FreeDLine which makes the
+ * counting wrong. The debug mode shall therefore be switched off
+ * when calling TkTextFindDisplayLineEnd.
+ */
+
+ TkTextIndex indexPtr2 = *indexPtr;
+ tkTextDebug = 0;
+ TkTextFindDisplayLineEnd(textPtr, &indexPtr2, 0, NULL);
+ tkTextDebug = oldtkTextDebug;
+ if (TkTextIndexCmp(&indexPtr2,indexPtr) != 0) {
+ Tcl_Panic("CalculateDisplayLineHeight called with bad indexPtr");
+ }
}
/*
@@ -3870,12 +3861,12 @@ TkTextIndexYPixels(
index = *indexPtr;
while (1) {
- TkTextFindDisplayLineEnd(textPtr, &index, 0, NULL);
- if (index.byteIndex == 0) {
- break;
- }
- TkTextIndexBackBytes(textPtr, &index, 1, &index);
- alreadyStartOfLine = 0;
+ TkTextFindDisplayLineEnd(textPtr, &index, 0, NULL);
+ if (index.byteIndex == 0) {
+ break;
+ }
+ TkTextIndexBackBytes(textPtr, &index, 1, &index);
+ alreadyStartOfLine = 0;
}
pixelHeight = TkBTreePixelsTo(textPtr, index.linePtr);
@@ -3887,7 +3878,7 @@ TkTextIndexYPixels(
*/
if (alreadyStartOfLine) {
- return pixelHeight;
+ return pixelHeight;
}
/*
@@ -3909,10 +3900,10 @@ TkTextIndexYPixels(
height = CalculateDisplayLineHeight(textPtr, &index, &bytes, NULL);
- TkTextIndexForwBytes(textPtr, &index, bytes, &index);
+ TkTextIndexForwBytes(textPtr, &index, bytes, &index);
- compare = TkTextIndexCmp(&index,indexPtr);
- if (compare > 0) {
+ compare = TkTextIndexCmp(&index,indexPtr);
+ if (compare > 0) {
return pixelHeight;
}
@@ -3920,7 +3911,7 @@ TkTextIndexYPixels(
pixelHeight += height;
}
- if (compare == 0) {
+ if (compare == 0) {
return pixelHeight;
}
}
@@ -4020,7 +4011,7 @@ TkTextUpdateOneLine(
* test below this while loop.
*/
- height = CalculateDisplayLineHeight(textPtr, indexPtr, &bytes,
+ height = CalculateDisplayLineHeight(textPtr, indexPtr, &bytes,
&logicalLines);
if (height > 0) {
@@ -4034,31 +4025,31 @@ TkTextUpdateOneLine(
break;
}
- if (mergedLines == 0) {
- if (indexPtr->linePtr != linePtr) {
- /*
- * If we reached the end of the logical line, then either way
- * we don't have a partial calculation.
- */
-
- partialCalc = 0;
- break;
- }
- } else {
- if (IsStartOfNotMergedLine(textPtr, indexPtr)) {
- /*
- * We've ended a logical line.
- */
-
- partialCalc = 0;
- break;
- }
-
- /*
- * We must still be on the same wrapped line, on a new logical
- * line merged with the logical line 'linePtr'.
- */
- }
+ if (mergedLines == 0) {
+ if (indexPtr->linePtr != linePtr) {
+ /*
+ * If we reached the end of the logical line, then either way
+ * we don't have a partial calculation.
+ */
+
+ partialCalc = 0;
+ break;
+ }
+ } else {
+ if (IsStartOfNotMergedLine(textPtr, indexPtr)) {
+ /*
+ * We've ended a logical line.
+ */
+
+ partialCalc = 0;
+ break;
+ }
+
+ /*
+ * We must still be on the same wrapped line, on a new logical
+ * line merged with the logical line 'linePtr'.
+ */
+ }
if (partialCalc && displayLines > 50 && mergedLines == 0) {
/*
* Only calculate 50 display lines at a time, to avoid huge
@@ -4182,6 +4173,8 @@ DisplayText(
int bottomY = 0; /* Initialization needed only to stop compiler
* warnings. */
Tcl_Interp *interp;
+ int padX, padY;
+ int borderWidth, highlightWidth;
if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
@@ -4192,22 +4185,6 @@ DisplayText(
return;
}
-#ifdef MAC_OSX_TK
- /*
- * If the toplevel is being resized it would be dangerous to try redrawing
- * the widget. But we can just clear the REDRAW_PENDING flag and return.
- * This display proc will be called again after the widget has been
- * reconfigured.
- */
-
- TkWindow *winPtr = (TkWindow *)(textPtr->tkwin);
- MacDrawable *macWin = winPtr->privatePtr;
- if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){
- dInfoPtr->flags &= ~REDRAW_PENDING;
- return;
- }
-#endif
-
interp = textPtr->interp;
Tcl_Preserve(interp);
@@ -4391,6 +4368,9 @@ DisplayText(
dInfoPtr->flags &= ~REDRAW_PENDING;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padXObj, &padX);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padYObj, &padY);
+
/*
* Redraw the borders if that's needed.
*/
@@ -4408,13 +4388,15 @@ DisplayText(
goto end;
}
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->highlightWidthObj, &highlightWidth);
Tk_Draw3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
- textPtr->border, textPtr->highlightWidth,
- textPtr->highlightWidth,
- Tk_Width(textPtr->tkwin) - 2*textPtr->highlightWidth,
- Tk_Height(textPtr->tkwin) - 2*textPtr->highlightWidth,
- textPtr->borderWidth, textPtr->relief);
- if (textPtr->highlightWidth > 0) {
+ textPtr->border, highlightWidth,
+ highlightWidth,
+ Tk_Width(textPtr->tkwin) - 2 * highlightWidth,
+ Tk_Height(textPtr->tkwin) - 2 * highlightWidth,
+ borderWidth, textPtr->relief);
+ if (highlightWidth > 0) {
GC fgGC, bgGC;
bgGC = Tk_GCForColor(textPtr->highlightBgColorPtr,
@@ -4423,35 +4405,35 @@ DisplayText(
fgGC = Tk_GCForColor(textPtr->highlightColorPtr,
Tk_WindowId(textPtr->tkwin));
Tk_DrawHighlightBorder(textPtr->tkwin, fgGC, bgGC,
- textPtr->highlightWidth, Tk_WindowId(textPtr->tkwin));
+ highlightWidth, Tk_WindowId(textPtr->tkwin));
} else {
Tk_DrawHighlightBorder(textPtr->tkwin, bgGC, bgGC,
- textPtr->highlightWidth, Tk_WindowId(textPtr->tkwin));
+ highlightWidth, Tk_WindowId(textPtr->tkwin));
}
}
- borders = textPtr->borderWidth + textPtr->highlightWidth;
- if (textPtr->padY > 0) {
+ borders = borderWidth + highlightWidth;
+ if (padY > 0) {
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border, borders, borders,
- Tk_Width(textPtr->tkwin) - 2*borders, textPtr->padY,
+ Tk_Width(textPtr->tkwin) - 2 * borders, padY,
0, TK_RELIEF_FLAT);
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border, borders,
- Tk_Height(textPtr->tkwin) - borders - textPtr->padY,
- Tk_Width(textPtr->tkwin) - 2*borders,
- textPtr->padY, 0, TK_RELIEF_FLAT);
+ Tk_Height(textPtr->tkwin) - borders - padY,
+ Tk_Width(textPtr->tkwin) - 2 * borders,
+ padY, 0, TK_RELIEF_FLAT);
}
- if (textPtr->padX > 0) {
+ if (padX > 0) {
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
- textPtr->border, borders, borders + textPtr->padY,
- textPtr->padX,
- Tk_Height(textPtr->tkwin) - 2*borders -2*textPtr->padY,
+ textPtr->border, borders, borders + padY,
+ padX,
+ Tk_Height(textPtr->tkwin) - 2 * borders -2 * padY,
0, TK_RELIEF_FLAT);
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border,
- Tk_Width(textPtr->tkwin) - borders - textPtr->padX,
- borders + textPtr->padY, textPtr->padX,
- Tk_Height(textPtr->tkwin) - 2*borders -2*textPtr->padY,
+ Tk_Width(textPtr->tkwin) - borders - padX,
+ borders + padY, padX,
+ Tk_Height(textPtr->tkwin) - 2 * borders -2 * padY,
0, TK_RELIEF_FLAT);
}
dInfoPtr->flags &= ~REDRAW_BORDERS;
@@ -4634,8 +4616,8 @@ DisplayText(
}
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
- textPtr->border, dInfoPtr->x - textPtr->padX, bottomY,
- dInfoPtr->maxX - (dInfoPtr->x - textPtr->padX),
+ textPtr->border, dInfoPtr->x - padX, bottomY,
+ dInfoPtr->maxX - (dInfoPtr->x - padX),
dInfoPtr->topOfEof-bottomY, 0, TK_RELIEF_FLAT);
}
dInfoPtr->topOfEof = bottomY;
@@ -4779,6 +4761,8 @@ TextInvalidateRegion(
TextDInfo *dInfoPtr = textPtr->dInfoPtr;
int maxY, inset;
XRectangle rect;
+ int padX, padY;
+ int borderWidth, highlightWidth;
/*
* Find all lines that overlap the given region and mark them for
@@ -4799,12 +4783,16 @@ TextInvalidateRegion(
dInfoPtr->topOfEof = maxY;
}
- inset = textPtr->borderWidth + textPtr->highlightWidth;
- if ((rect.x < (inset + textPtr->padX))
- || (rect.y < (inset + textPtr->padY))
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padXObj, &padX);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padYObj, &padY);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->highlightWidthObj, &highlightWidth);
+ inset = borderWidth + highlightWidth;
+ if ((rect.x < (inset + padX))
+ || (rect.y < (inset + padY))
|| ((int) (rect.x + rect.width) > (Tk_Width(textPtr->tkwin)
- - inset - textPtr->padX))
- || (maxY > (Tk_Height(textPtr->tkwin) - inset - textPtr->padY))) {
+ - inset - padX))
+ || (maxY > (Tk_Height(textPtr->tkwin) - inset - padY))) {
dInfoPtr->flags |= REDRAW_BORDERS;
}
}
@@ -4906,8 +4894,8 @@ TextChanged(
rounded.byteIndex = 0;
notBegin = 0;
while (!IsStartOfNotMergedLine(textPtr, &rounded) && notBegin) {
- notBegin = !TkTextIndexBackBytes(textPtr, &rounded, 1, &rounded);
- rounded.byteIndex = 0;
+ notBegin = !TkTextIndexBackBytes(textPtr, &rounded, 1, &rounded);
+ rounded.byteIndex = 0;
}
/*
@@ -4919,11 +4907,11 @@ TextChanged(
firstPtr = FindDLine(textPtr, dInfoPtr->dLinePtr, &rounded);
if (firstPtr == NULL) {
- /*
- * index1Ptr pertains to no display line, i.e this index is after
- * the last display line. Since index2Ptr is after index1Ptr, there
- * is no display line to free/redisplay and we can return early.
- */
+ /*
+ * index1Ptr pertains to no display line, i.e this index is after
+ * the last display line. Since index2Ptr is after index1Ptr, there
+ * is no display line to free/redisplay and we can return early.
+ */
return;
}
@@ -4931,38 +4919,38 @@ TextChanged(
rounded = *index2Ptr;
linePtr = index2Ptr->linePtr;
do {
- linePtr = TkBTreeNextLine(textPtr, linePtr);
- if (linePtr == NULL) {
- break;
- }
- rounded.linePtr = linePtr;
- rounded.byteIndex = 0;
+ linePtr = TkBTreeNextLine(textPtr, linePtr);
+ if (linePtr == NULL) {
+ break;
+ }
+ rounded.linePtr = linePtr;
+ rounded.byteIndex = 0;
} while (!IsStartOfNotMergedLine(textPtr, &rounded));
if (linePtr == NULL) {
- lastPtr = NULL;
+ lastPtr = NULL;
} else {
- /*
- * 'rounded' now points to the start of a display line as well as the
- * start of a logical line not merged with its previous line, and
- * this index is the closest after index2Ptr.
- */
+ /*
+ * 'rounded' now points to the start of a display line as well as the
+ * start of a logical line not merged with its previous line, and
+ * this index is the closest after index2Ptr.
+ */
- lastPtr = FindDLine(textPtr, dInfoPtr->dLinePtr, &rounded);
+ lastPtr = FindDLine(textPtr, dInfoPtr->dLinePtr, &rounded);
- /*
- * At least one display line is supposed to change. This makes the
- * redisplay OK in case the display line we expect to get here was
- * unlinked by a previous call to TkTextChanged and the text widget
- * did not update before reaching this point. This happens for
- * instance when moving the cursor up one line.
- * Note that lastPtr != NULL here, otherwise we would have returned
- * earlier when we tested for firstPtr being NULL.
- */
+ /*
+ * At least one display line is supposed to change. This makes the
+ * redisplay OK in case the display line we expect to get here was
+ * unlinked by a previous call to TkTextChanged and the text widget
+ * did not update before reaching this point. This happens for
+ * instance when moving the cursor up one line.
+ * Note that lastPtr != NULL here, otherwise we would have returned
+ * earlier when we tested for firstPtr being NULL.
+ */
- if (lastPtr == firstPtr) {
- lastPtr = lastPtr->nextPtr;
- }
+ if (lastPtr == firstPtr) {
+ lastPtr = lastPtr->nextPtr;
+ }
}
/*
@@ -5147,7 +5135,7 @@ TextRedrawTag(
} else {
TkTextIndex tmp = *curIndexPtr;
- TkTextIndexBackBytes(textPtr, &tmp, 1, &tmp);
+ TkTextIndexBackBytes(textPtr, &tmp, 1, &tmp);
dlPtr = FindDLine(textPtr, dlPtr, &tmp);
}
if (dlPtr == NULL) {
@@ -5166,7 +5154,7 @@ TextRedrawTag(
}
endPtr = FindDLine(textPtr, dlPtr, endIndexPtr);
if ((endPtr != NULL)
- && (TkTextIndexCmp(&endPtr->index,endIndexPtr) < 0)) {
+ && (TkTextIndexCmp(&endPtr->index,endIndexPtr) < 0)) {
endPtr = endPtr->nextPtr;
}
@@ -5219,6 +5207,8 @@ TkTextRelayoutWindow(
GC newGC;
XGCValues gcValues;
Bool inSync = 1;
+ int padX, padY;
+ int borderWidth, highlightWidth;
/*
* Schedule the window redisplay. See TkTextChanged for the reason why
@@ -5256,15 +5246,20 @@ TkTextRelayoutWindow(
* it.
*/
- if (textPtr->highlightWidth < 0) {
- textPtr->highlightWidth = 0;
- }
- dInfoPtr->x = textPtr->highlightWidth + textPtr->borderWidth
- + textPtr->padX;
- dInfoPtr->y = textPtr->highlightWidth + textPtr->borderWidth
- + textPtr->padY;
- dInfoPtr->maxX = Tk_Width(textPtr->tkwin) - textPtr->highlightWidth
- - textPtr->borderWidth - textPtr->padX;
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padXObj, &padX);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->padYObj, &padY);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->borderWidthObj, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, textPtr->tkwin, textPtr->highlightWidthObj, &highlightWidth);
+ if (highlightWidth < 0) {
+ highlightWidth = 0;
+ Tcl_DecrRefCount(textPtr->highlightWidthObj);
+ textPtr->highlightWidthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(textPtr->highlightWidthObj);
+ }
+ dInfoPtr->x = highlightWidth + borderWidth + padX;
+ dInfoPtr->y = highlightWidth + borderWidth + padY;
+ dInfoPtr->maxX = Tk_Width(textPtr->tkwin) - highlightWidth
+ - borderWidth - padX;
if (dInfoPtr->maxX <= dInfoPtr->x) {
dInfoPtr->maxX = dInfoPtr->x + 1;
}
@@ -5273,8 +5268,8 @@ TkTextRelayoutWindow(
* This is the only place where dInfoPtr->maxY is set.
*/
- dInfoPtr->maxY = Tk_Height(textPtr->tkwin) - textPtr->highlightWidth
- - textPtr->borderWidth - textPtr->padY;
+ dInfoPtr->maxY = Tk_Height(textPtr->tkwin) - highlightWidth
+ - borderWidth - padY;
if (dInfoPtr->maxY <= dInfoPtr->y) {
dInfoPtr->maxY = dInfoPtr->y + 1;
}
@@ -5327,7 +5322,7 @@ TkTextRelayoutWindow(
inSync = 0;
}
- GenerateWidgetViewSyncEvent(textPtr, inSync);
+ GenerateWidgetViewSyncEvent(textPtr, inSync);
}
}
@@ -5403,9 +5398,9 @@ TkTextSetYView(
*/
textPtr->topIndex = *indexPtr;
- if (!IsStartOfNotMergedLine(textPtr, indexPtr)) {
- TkTextFindDisplayLineEnd(textPtr, &textPtr->topIndex, 0, NULL);
- }
+ if (!IsStartOfNotMergedLine(textPtr, indexPtr)) {
+ TkTextFindDisplayLineEnd(textPtr, &textPtr->topIndex, 0, NULL);
+ }
dInfoPtr->newTopPixelOffset = pickPlace;
goto scheduleUpdate;
}
@@ -5428,23 +5423,23 @@ TkTextSetYView(
*/
dlPtr = NULL;
- } else {
- if (TkTextIndexCmp(&dlPtr->index, indexPtr) <= 0) {
- if (dInfoPtr->dLinePtr == dlPtr && dInfoPtr->topPixelOffset != 0) {
- /*
- * It is on the top line, but that line is hanging off the top
- * of the screen. Change the top overlap to zero and update.
- */
-
- dInfoPtr->newTopPixelOffset = 0;
- goto scheduleUpdate;
- }
- /*
- * The line is already on screen, with no need to scroll.
- */
- return;
- }
- }
+ } else {
+ if (TkTextIndexCmp(&dlPtr->index, indexPtr) <= 0) {
+ if (dInfoPtr->dLinePtr == dlPtr && dInfoPtr->topPixelOffset != 0) {
+ /*
+ * It is on the top line, but that line is hanging off the top
+ * of the screen. Change the top overlap to zero and update.
+ */
+
+ dInfoPtr->newTopPixelOffset = 0;
+ goto scheduleUpdate;
+ }
+ /*
+ * The line is already on screen, with no need to scroll.
+ */
+ return;
+ }
+ }
}
/*
@@ -5509,7 +5504,7 @@ TkTextSetYView(
*/
if (dInfoPtr->maxY - dInfoPtr->y < lineHeight) {
- bottomY = lineHeight;
+ bottomY = lineHeight;
}
/*
@@ -5645,8 +5640,8 @@ MeasureUp(
index.linePtr = TkBTreeFindLine(srcPtr->tree, textPtr, lineNum);
index.byteIndex = 0;
- TkTextFindDisplayLineEnd(textPtr, &index, 0, NULL);
- lineNum = TkBTreeLinesTo(textPtr, index.linePtr);
+ TkTextFindDisplayLineEnd(textPtr, &index, 0, NULL);
+ lineNum = TkBTreeLinesTo(textPtr, index.linePtr);
lowestPtr = NULL;
do {
dlPtr = LayoutDLine(textPtr, &index);
@@ -5667,21 +5662,21 @@ MeasureUp(
for (dlPtr = lowestPtr; dlPtr != NULL; dlPtr = dlPtr->nextPtr) {
distance -= dlPtr->height;
if (distance <= 0) {
- *dstPtr = dlPtr->index;
-
- /*
- * dstPtr is the start of a display line that is or is not
- * the start of a logical line. If it is the start of a
- * logical line, we must check whether this line is merged
- * with the previous logical line, and if so we must adjust
- * dstPtr to the start of the display line since a display
- * line start needs to be returned.
- */
- if (!IsStartOfNotMergedLine(textPtr, dstPtr)) {
- TkTextFindDisplayLineEnd(textPtr, dstPtr, 0, NULL);
- }
-
- if (overlap != NULL) {
+ *dstPtr = dlPtr->index;
+
+ /*
+ * dstPtr is the start of a display line that is or is not
+ * the start of a logical line. If it is the start of a
+ * logical line, we must check whether this line is merged
+ * with the previous logical line, and if so we must adjust
+ * dstPtr to the start of the display line since a display
+ * line start needs to be returned.
+ */
+ if (!IsStartOfNotMergedLine(textPtr, dstPtr)) {
+ TkTextFindDisplayLineEnd(textPtr, dstPtr, 0, NULL);
+ }
+
+ if (overlap != NULL) {
*overlap = -distance;
}
break;
@@ -5814,30 +5809,30 @@ TkTextSeeCmd(
*/
if (chunkPtr != NULL) {
- chunkPtr->bboxProc(textPtr, chunkPtr, byteCount,
- dlPtr->y + dlPtr->spaceAbove,
- dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow,
- dlPtr->baseline - dlPtr->spaceAbove, &x, &y, &width,
- &height);
- delta = x - dInfoPtr->curXPixelOffset;
- oneThird = lineWidth/3;
- if (delta < 0) {
- if (delta < -oneThird) {
- dInfoPtr->newXPixelOffset = x - lineWidth/2;
- } else {
- dInfoPtr->newXPixelOffset += delta;
- }
- } else {
- delta -= lineWidth - width;
- if (delta <= 0) {
- return TCL_OK;
- }
- if (delta > oneThird) {
- dInfoPtr->newXPixelOffset = x - lineWidth/2;
- } else {
- dInfoPtr->newXPixelOffset += delta;
- }
- }
+ chunkPtr->bboxProc(textPtr, chunkPtr, byteCount,
+ dlPtr->y + dlPtr->spaceAbove,
+ dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow,
+ dlPtr->baseline - dlPtr->spaceAbove, &x, &y, &width,
+ &height);
+ delta = x - dInfoPtr->curXPixelOffset;
+ oneThird = lineWidth/3;
+ if (delta < 0) {
+ if (delta < -oneThird) {
+ dInfoPtr->newXPixelOffset = x - lineWidth/2;
+ } else {
+ dInfoPtr->newXPixelOffset += delta;
+ }
+ } else {
+ delta -= lineWidth - width;
+ if (delta <= 0) {
+ return TCL_OK;
+ }
+ if (delta > oneThird) {
+ dInfoPtr->newXPixelOffset = x - lineWidth/2;
+ } else {
+ dInfoPtr->newXPixelOffset += delta;
+ }
+ }
}
dInfoPtr->flags |= DINFO_OUT_OF_DATE;
if (!(dInfoPtr->flags & REDRAW_PENDING)) {
@@ -6075,24 +6070,24 @@ YScrollByLines(
if (offset == 0) {
textPtr->topIndex = dlPtr->index;
- /*
- * topIndex is the start of a logical line. However, if
- * the eol of the previous logical line is elided, then
- * topIndex may be elsewhere than the first character of
- * a display line, which is unwanted. Adjust to the start
- * of the display line, if needed.
- * topIndex is the start of a display line that is or is
- * not the start of a logical line. If it is the start of
- * a logical line, we must check whether this line is
- * merged with the previous logical line, and if so we
- * must adjust topIndex to the start of the display line.
- */
- if (!IsStartOfNotMergedLine(textPtr, &textPtr->topIndex)) {
- TkTextFindDisplayLineEnd(textPtr, &textPtr->topIndex,
- 0, NULL);
- }
-
- break;
+ /*
+ * topIndex is the start of a logical line. However, if
+ * the eol of the previous logical line is elided, then
+ * topIndex may be elsewhere than the first character of
+ * a display line, which is unwanted. Adjust to the start
+ * of the display line, if needed.
+ * topIndex is the start of a display line that is or is
+ * not the start of a logical line. If it is the start of
+ * a logical line, we must check whether this line is
+ * merged with the previous logical line, and if so we
+ * must adjust topIndex to the start of the display line.
+ */
+ if (!IsStartOfNotMergedLine(textPtr, &textPtr->topIndex)) {
+ TkTextFindDisplayLineEnd(textPtr, &textPtr->topIndex,
+ 0, NULL);
+ }
+
+ break;
}
}
@@ -6922,63 +6917,63 @@ FindDLine(
*/
while (TkTextIndexCmp(&dlPtr->index,indexPtr) < 0) {
- dlPtrPrev = dlPtr;
- dlPtr = dlPtr->nextPtr;
- if (dlPtr == NULL) {
- /*
- * We're past the last display line, either because the desired
- * index lies past the visible text, or because the desired index
- * is on the last display line.
- */
- indexPtr2 = dlPtrPrev->index;
- TkTextIndexForwBytes(textPtr, &indexPtr2, dlPtrPrev->byteCount,
- &indexPtr2);
- if (TkTextIndexCmp(&indexPtr2,indexPtr) > 0) {
- /*
- * The desired index is on the last display line.
- * --> return this display line.
- */
- dlPtr = dlPtrPrev;
- } else {
- /*
- * The desired index is past the visible text. There is no
- * display line displaying something at the desired index.
- * --> return NULL.
- */
- }
- break;
- }
- if (TkTextIndexCmp(&dlPtr->index,indexPtr) > 0) {
- /*
- * If we're here then we would normally expect that:
- * dlPtrPrev->index <= indexPtr < dlPtr->index
- * i.e. we have found the searched display line being dlPtr.
- * However it is possible that some DLines were unlinked
- * previously, leading to a situation where going through
- * the list of display lines skips display lines that did
- * exist just a moment ago.
- */
- indexPtr2 = dlPtrPrev->index;
- TkTextIndexForwBytes(textPtr, &indexPtr2, dlPtrPrev->byteCount,
- &indexPtr2);
- if (TkTextIndexCmp(&indexPtr2,indexPtr) > 0) {
- /*
- * Confirmed:
- * dlPtrPrev->index <= indexPtr < dlPtr->index
- * --> return dlPtrPrev.
- */
- dlPtr = dlPtrPrev;
- } else {
- /*
- * The last (rightmost) index shown by dlPtrPrev is still
- * before the desired index. This may be because there was
- * previously a display line between dlPtrPrev and dlPtr
- * and this display line has been unlinked.
- * --> return dlPtr.
- */
- }
- break;
- }
+ dlPtrPrev = dlPtr;
+ dlPtr = dlPtr->nextPtr;
+ if (dlPtr == NULL) {
+ /*
+ * We're past the last display line, either because the desired
+ * index lies past the visible text, or because the desired index
+ * is on the last display line.
+ */
+ indexPtr2 = dlPtrPrev->index;
+ TkTextIndexForwBytes(textPtr, &indexPtr2, dlPtrPrev->byteCount,
+ &indexPtr2);
+ if (TkTextIndexCmp(&indexPtr2,indexPtr) > 0) {
+ /*
+ * The desired index is on the last display line.
+ * --> return this display line.
+ */
+ dlPtr = dlPtrPrev;
+ } else {
+ /*
+ * The desired index is past the visible text. There is no
+ * display line displaying something at the desired index.
+ * --> return NULL.
+ */
+ }
+ break;
+ }
+ if (TkTextIndexCmp(&dlPtr->index,indexPtr) > 0) {
+ /*
+ * If we're here then we would normally expect that:
+ * dlPtrPrev->index <= indexPtr < dlPtr->index
+ * i.e. we have found the searched display line being dlPtr.
+ * However it is possible that some DLines were unlinked
+ * previously, leading to a situation where going through
+ * the list of display lines skips display lines that did
+ * exist just a moment ago.
+ */
+ indexPtr2 = dlPtrPrev->index;
+ TkTextIndexForwBytes(textPtr, &indexPtr2, dlPtrPrev->byteCount,
+ &indexPtr2);
+ if (TkTextIndexCmp(&indexPtr2,indexPtr) > 0) {
+ /*
+ * Confirmed:
+ * dlPtrPrev->index <= indexPtr < dlPtr->index
+ * --> return dlPtrPrev.
+ */
+ dlPtr = dlPtrPrev;
+ } else {
+ /*
+ * The last (rightmost) index shown by dlPtrPrev is still
+ * before the desired index. This may be because there was
+ * previously a display line between dlPtrPrev and dlPtr
+ * and this display line has been unlinked.
+ * --> return dlPtr.
+ */
+ }
+ break;
+ }
}
return dlPtr;
@@ -7011,24 +7006,24 @@ IsStartOfNotMergedLine(
TkTextIndex indexPtr2;
if (indexPtr->byteIndex != 0) {
- /*
- * Not the start of a logical line.
- */
- return 0;
+ /*
+ * Not the start of a logical line.
+ */
+ return 0;
}
if (TkTextIndexBackBytes(textPtr, indexPtr, 1, &indexPtr2)) {
- /*
- * indexPtr is the first index of the text widget.
- */
- return 1;
+ /*
+ * indexPtr is the first index of the text widget.
+ */
+ return 1;
}
if (!TkTextIsElided(textPtr, &indexPtr2, NULL)) {
- /*
- * The eol of the line just before indexPtr is elided.
- */
- return 1;
+ /*
+ * The eol of the line just before indexPtr is elided.
+ */
+ return 1;
}
return 0;
@@ -7202,7 +7197,7 @@ DlineIndexOfX(
* We've reached the end of the text.
*/
- TkTextIndexBackChars(NULL, indexPtr, 1, indexPtr, COUNT_INDICES);
+ TkTextIndexBackChars(NULL, indexPtr, 1, indexPtr, COUNT_INDICES);
return;
}
if (chunkPtr->nextPtr == NULL) {
@@ -7210,7 +7205,7 @@ DlineIndexOfX(
* We've reached the end of the display line.
*/
- TkTextIndexBackChars(NULL, indexPtr, 1, indexPtr, COUNT_INDICES);
+ TkTextIndexBackChars(NULL, indexPtr, 1, indexPtr, COUNT_INDICES);
return;
}
chunkPtr = chunkPtr->nextPtr;
@@ -7434,9 +7429,9 @@ TkTextIndexBbox(
if (charWidthPtr != NULL) {
*charWidthPtr = dInfoPtr->maxX - *xPtr;
- if (*charWidthPtr > textPtr->charWidth) {
- *charWidthPtr = textPtr->charWidth;
- }
+ if (*charWidthPtr > textPtr->charWidth) {
+ *charWidthPtr = textPtr->charWidth;
+ }
}
if (*xPtr > dInfoPtr->maxX) {
*xPtr = dInfoPtr->maxX;
@@ -7725,21 +7720,21 @@ TkTextCharLayoutProc(
nextX = maxX;
bytesThatFit++;
}
- if (wrapMode == TEXT_WRAPMODE_WORD) {
- while (p[bytesThatFit] == ' ') {
- /*
- * Space characters that would go at the beginning of the
- * next line are allocated to the current line. This gives
- * the effect of trimming white spaces that would otherwise
- * be seen at the beginning of wrapped lines.
- * Note that testing for '\t' is useless here because the
- * chunk always includes at most one trailing \t, see
- * LayoutDLine.
- */
-
- bytesThatFit++;
- }
- }
+ if (wrapMode == TEXT_WRAPMODE_WORD) {
+ while (p[bytesThatFit] == ' ') {
+ /*
+ * Space characters that would go at the beginning of the
+ * next line are allocated to the current line. This gives
+ * the effect of trimming white spaces that would otherwise
+ * be seen at the beginning of wrapped lines.
+ * Note that testing for '\t' is useless here because the
+ * chunk always includes at most one trailing \t, see
+ * LayoutDLine.
+ */
+
+ bytesThatFit++;
+ }
+ }
if (p[bytesThatFit] == '\n') {
/*
* A newline character takes up no space, so if the previous