summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstanton <stanton>1999-03-30 04:12:54 (GMT)
committerstanton <stanton>1999-03-30 04:12:54 (GMT)
commit972f48be963549c14625ebae0251268ebded7727 (patch)
tree57a02adab1c57d9f785cee49eb57a23b6bbe70fd
parent69b4a640eb954dbb23cc09e9d993c41b214e765c (diff)
downloadtk-972f48be963549c14625ebae0251268ebded7727.zip
tk-972f48be963549c14625ebae0251268ebded7727.tar.gz
tk-972f48be963549c14625ebae0251268ebded7727.tar.bz2
* doc/MeasureChar.3:
* doc/TextLayout.3: * generic/tk.decls: * generic/tkCanvText.c: * generic/tkEntry.c: * generic/tkFont.c: * generic/tkListbox.c: * generic/tkMessage.c: * mac/tkMacFont.c: * unix/tkUnixButton.c: * unix/tkUnixFont.c: * unix/tkUnixMenu.c: * win/tkWinFont.c: * win/tkWinMenu.c: Standardized text layout and font interfaces so they are consistent with respect to byte versus character oriented indices. The layout functions all manipulate character oriented values while the lower level measurement functions all operate on byte oriented values. This distinction was not clear and so the functions were being used improperly in a number of places. [Bug: 1053, 747, 749, 1646] * generic/tk.decls: Eliminated uses of C++ STL types string and list from declarations. * generic/tkFont.c: Changes to named fonts were not being propagated in some cases. [Bug: 1144]
-rw-r--r--doc/MeasureChar.347
-rw-r--r--doc/TextLayout.318
-rw-r--r--generic/tk.decls65
-rw-r--r--generic/tkCanvText.c117
-rw-r--r--generic/tkDecls.h92
-rw-r--r--generic/tkEntry.c91
-rw-r--r--generic/tkFont.c123
-rw-r--r--generic/tkIntXlibDecls.h23
-rw-r--r--generic/tkListbox.c4
-rw-r--r--generic/tkMessage.c10
-rw-r--r--generic/tkStubInit.c5
-rw-r--r--mac/tkMacFont.c4
-rw-r--r--unix/tkUnixButton.c11
-rw-r--r--unix/tkUnixFont.c4
-rw-r--r--unix/tkUnixMenu.c10
-rw-r--r--win/tkWinFont.c6
-rw-r--r--win/tkWinMenu.c6
17 files changed, 346 insertions, 290 deletions
diff --git a/doc/MeasureChar.3 b/doc/MeasureChar.3
index 6f5c1c7..fe80739 100644
--- a/doc/MeasureChar.3
+++ b/doc/MeasureChar.3
@@ -4,10 +4,10 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: MeasureChar.3,v 1.1.4.2 1998/11/25 04:10:25 stanton Exp $
+'\" RCS: @(#) $Id: MeasureChar.3,v 1.1.4.3 1999/03/30 04:12:54 stanton Exp $
'\"
.so man.macros
-.TH Tk_MeasureChars 3 "" Tk "Tk Library Procedures"
+.TH Tk_MeasureChars 3 8.1 Tk "Tk Library Procedures"
.BS
.SH NAME
Tk_MeasureChars, Tk_TextWidth, Tk_DrawChars, Tk_UnderlineChars \- routines to measure and display simple single-line strings.
@@ -19,13 +19,13 @@ int
\fBTk_MeasureChars(\fItkfont, string, numBytes, maxPixels, flags, lengthPtr\fB)\fR
.sp
int
-\fBTk_TextWidth(\fItkfont, string, numChars\fB)\fR
+\fBTk_TextWidth(\fItkfont, string, numBytes\fB)\fR
.sp
void
-\fBTk_DrawChars(\fIdisplay, drawable, gc, tkfont, string, numChars, x, y\fB)\fR
+\fBTk_DrawChars(\fIdisplay, drawable, gc, tkfont, string, numBytes, x, y\fB)\fR
.sp
void
-\fBTk_UnderlineChars(\fIdisplay, drawable, gc, tkfont, string, x, y, firstChar, lastChar\fB)\fR
+\fBTk_UnderlineChars(\fIdisplay, drawable, gc, tkfont, string, x, y, firstByte, lastByte\fB)\fR
.sp
.SH ARGUMENTS
.AS "const char" firstChar
@@ -37,9 +37,11 @@ Text to be measured or displayed. Need not be null terminated. Any
non-printing meta-characters in the string (such as tabs, newlines, and
other control characters) will be measured or displayed in a
platform-dependent manner.
+.VS 8.1
.AP int numBytes in
-The maximum number of bytes to consider when measuring \fIstring\fR.
-Must be greater than or equal to 0.
+The maximum number of bytes to consider when measuring or drawing
+\fIstring\fR. Must be greater than or equal to 0.
+.VE 8.1
.AP int maxPixels in
If \fImaxPixels\fR is greater than 0, it specifies the longest permissible
line length in pixels. Characters from \fIstring\fR are processed only
@@ -59,9 +61,6 @@ letter will still be returned.
.AP int *lengthPtr out
Filled with the number of pixels occupied by the number of characters
returned as the result of \fBTk_MeasureChars\fR.
-.AP int numChars in
-The total number of characters to measure or draw from \fIstring\fR. Must
-be greater than or equal to 0.
.AP Display *display in
Display on which to draw.
.AP Drawable drawable in
@@ -72,13 +71,15 @@ must be the same as the \fItkfont\fR.
.AP int "x, y" in
Coordinates at which to place the left edge of the baseline when displaying
\fIstring\fR.
-.AP int firstChar in
-The index of the first character to underline in the \fIstring\fR.
-Underlining begins at the left edge of this character.
-.AP int lastChar in
-The index of the last character up to which the underline will
-be drawn. The character specified by \fIlastChar\fR will not itself be
-underlined.
+.VS 8.1
+.AP int firstByte in
+The index of the first byte of the first character to underline in the
+\fIstring\fR. Underlining begins at the left edge of this character.
+.AP int lastByte in
+The index of the first byte of the last character up to which the
+underline will be drawn. The character specified by \fIlastByte\fR
+will not itself be underlined.
+.VE 8.1
.BE
.SH DESCRIPTION
@@ -88,7 +89,13 @@ single-line, strings. To measure and display single-font, multi-line,
justified text, refer to the documentation for \fBTk_ComputeTextLayout\fR.
There is no programming interface in the core of Tk that supports
multi-font, multi-line text; support for that behavior must be built on
-top of simpler layers.
+top of simpler layers.
+.VS 8.1
+Note that the interfaces described here are
+byte-oriented not character-oriented, so index values coming from Tcl
+scripts need to be converted to byte offsets using the
+\fBTcl_UtfAtIndex\fR and related routines.
+.VE 8.1
.PP
A glyph is the displayable picture of a letter, number, or some other
symbol. Not all character codes in a given font have a glyph.
@@ -103,10 +110,10 @@ newlines/returns into multi-line text.
.PP
\fBTk_MeasureChars\fR is used both to compute the length of a given
string and to compute how many characters from a string fit in a given
-amount of space. The return value is the number of characters from
+amount of space. The return value is the number of bytes from
\fIstring\fR that fit in the space specified by \fImaxPixels\fR subject to
the conditions described by \fIflags\fR. If all characters fit, the return
-value will be \fImaxChars\fR. \fI*lengthPtr\fR is filled with the computed
+value will be \fInumBytes\fR. \fI*lengthPtr\fR is filled with the computed
width, in pixels, of the portion of the string that was measured. For
example, if the return value is 5, then \fI*lengthPtr\fR is filled with the
distance between the left edge of \fIstring\fR[0] and the right edge of
diff --git a/doc/TextLayout.3 b/doc/TextLayout.3
index 461633a..1e0d47f 100644
--- a/doc/TextLayout.3
+++ b/doc/TextLayout.3
@@ -4,10 +4,10 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: TextLayout.3,v 1.1.4.1 1998/09/30 02:16:09 stanton Exp $
+'\" RCS: @(#) $Id: TextLayout.3,v 1.1.4.2 1999/03/30 04:12:54 stanton Exp $
'\"
.so man.macros
-.TH Tk_ComputeTextLayout 3 "" Tk "Tk Library Procedures"
+.TH Tk_ComputeTextLayout 3 8.1 Tk "Tk Library Procedures"
.BS
.SH NAME
Tk_ComputeTextLayout, Tk_FreeTextLayout, Tk_DrawTextLayout, Tk_UnderlineTextLayout, Tk_PointToChar, Tk_CharBbox, Tk_DistanceToTextLayout, Tk_IntersectTextLayout, Tk_TextLayoutToPostscript \- routines to measure and display single-font, multi-line, justified text.
@@ -55,7 +55,10 @@ lifetime of the text layout.
.AP int numChars in
The number of characters to consider from \fIstring\fR. If
\fInumChars\fR is less than 0, then assumes \fIstring\fR is null
-terminated and uses \fBstrlen(\fIstring\fB)\fR.
+.VS 8.1
+terminated and uses \fBTcl_NumUtfChars\fR to determine the length of
+\fIstring\fR.
+.VE
.AP int wrapLength in
Longest permissible line length, in pixels. Lines in \fIstring\fR will
automatically be broken at word boundaries and wrapped when they reach
@@ -133,7 +136,14 @@ justified text. To measure and display simple single-font, single-line
strings, refer to the documentation for \fBTk_MeasureChars\fR. There is
no programming interface in the core of Tk that supports multi-font,
multi-line text; support for that behavior must be built on top of
-simpler layers.
+simpler layers.
+.VS 8.1
+Note that unlike the lower level text display routines, the functions
+described here all operate on character-oriented lengths and indices
+rather than byte-oriented values. See the description of
+\fBTcl_UtfAtIndex\fR for more details on converting between character
+and byte offsets.
+.VE 8.1
.PP
The routines described here are built on top of the programming interface
described in the \fBTk_MeasureChars\fR documentation. Tab characters and
diff --git a/generic/tk.decls b/generic/tk.decls
index d27e574..9c9630a 100644
--- a/generic/tk.decls
+++ b/generic/tk.decls
@@ -10,7 +10,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: tk.decls,v 1.2.2.1 1999/03/10 07:13:36 stanton Exp $
+# RCS: @(#) $Id: tk.decls,v 1.2.2.2 1999/03/30 04:12:55 stanton Exp $
library tk
@@ -77,7 +77,7 @@ declare 8 generic {
declare 9 generic {
int Tk_CanvasGetCoord (Tcl_Interp *interp, \
- Tk_Canvas canvas, char *string, double *doublePtr)
+ Tk_Canvas canvas, char *str, double *doublePtr)
}
declare 10 generic {
@@ -186,7 +186,7 @@ declare 30 generic {
declare 31 generic {
Tk_TextLayout Tk_ComputeTextLayout (Tk_Font font, \
- CONST char *string, int numChars, int wrapLength, \
+ CONST char *str, int numChars, int wrapLength, \
Tk_Justify justify, int flags, int *widthPtr, \
int *heightPtr)
}
@@ -198,7 +198,7 @@ declare 32 generic {
declare 33 generic {
unsigned long Tk_CreateBinding (Tcl_Interp *interp, \
Tk_BindingTable bindingTable, ClientData object, \
- char *eventString, char *command, int append)
+ char *eventStr, char *command, int append)
}
declare 34 generic {
@@ -251,8 +251,8 @@ declare 43 generic {
}
declare 44 generic {
- int Tk_DefineBitmap (Tcl_Interp *interp, \
- Tk_Uid name, char *source, int width, int height)
+ int Tk_DefineBitmap (Tcl_Interp *interp, CONST char *name, char *source, \
+ int width, int height)
}
declare 45 generic {
@@ -266,7 +266,7 @@ declare 46 generic {
declare 47 generic {
int Tk_DeleteBinding (Tcl_Interp *interp, \
Tk_BindingTable bindingTable, ClientData object, \
- char *eventString)
+ char *eventStr)
}
declare 48 generic {
@@ -315,22 +315,19 @@ declare 57 generic {
}
declare 58 generic {
- void Tk_Draw3DRectangle (Tk_Window tkwin, \
- Drawable drawable, Tk_3DBorder border, int x, \
- int y, int width, int height, int borderWidth, \
- int relief)
+ void Tk_Draw3DRectangle (Tk_Window tkwin, Drawable drawable, \
+ Tk_3DBorder border, int x, int y, int width, int height, \
+ int borderWidth, int relief)
}
declare 59 generic {
- void Tk_DrawChars (Display *display, \
- Drawable drawable, GC gc, Tk_Font tkfont, \
- CONST char *source, int numChars, int x, \
- int y)
+ void Tk_DrawChars (Display *display, Drawable drawable, GC gc, \
+ Tk_Font tkfont, CONST char *source, int numBytes, int x, int y)
}
declare 60 generic {
- void Tk_DrawFocusHighlight (Tk_Window tkwin, \
- GC gc, int width, Drawable drawable)
+ void Tk_DrawFocusHighlight (Tk_Window tkwin, GC gc, int width, \
+ Drawable drawable)
}
declare 61 generic {
@@ -430,7 +427,7 @@ declare 81 generic {
declare 82 generic {
int Tk_GetAnchor (Tcl_Interp *interp, \
- char *string, Tk_Anchor *anchorPtr)
+ char *str, Tk_Anchor *anchorPtr)
}
declare 83 generic {
@@ -440,11 +437,11 @@ declare 83 generic {
declare 84 generic {
char * Tk_GetBinding (Tcl_Interp *interp, \
Tk_BindingTable bindingTable, ClientData object, \
- char *eventString)
+ char *eventStr)
}
declare 85 generic {
- Pixmap Tk_GetBitmap (Tcl_Interp *interp, Tk_Window tkwin, Tk_Uid string)
+ Pixmap Tk_GetBitmap (Tcl_Interp *interp, Tk_Window tkwin, CONST char * str)
}
declare 86 generic {
@@ -453,7 +450,7 @@ declare 86 generic {
}
declare 87 generic {
- int Tk_GetCapStyle (Tcl_Interp *interp, char *string, int *capPtr)
+ int Tk_GetCapStyle (Tcl_Interp *interp, char *str, int *capPtr)
}
declare 88 generic {
@@ -465,12 +462,12 @@ declare 89 generic {
}
declare 90 generic {
- Colormap Tk_GetColormap (Tcl_Interp *interp, Tk_Window tkwin, char *string)
+ Colormap Tk_GetColormap (Tcl_Interp *interp, Tk_Window tkwin, char *str)
}
declare 91 generic {
Tk_Cursor Tk_GetCursor (Tcl_Interp *interp, Tk_Window tkwin, \
- Tk_Uid string)
+ Tk_Uid str)
}
declare 92 generic {
@@ -482,7 +479,7 @@ declare 92 generic {
declare 93 generic {
Tk_Font Tk_GetFont (Tcl_Interp *interp, \
- Tk_Window tkwin, CONST char *string)
+ Tk_Window tkwin, CONST char *str)
}
declare 94 generic {
@@ -512,12 +509,12 @@ declare 99 generic {
}
declare 100 generic {
- int Tk_GetJoinStyle (Tcl_Interp *interp, char *string, int *joinPtr)
+ int Tk_GetJoinStyle (Tcl_Interp *interp, char *str, int *joinPtr)
}
declare 101 generic {
int Tk_GetJustify (Tcl_Interp *interp, \
- char *string, Tk_Justify *justifyPtr)
+ char *str, Tk_Justify *justifyPtr)
}
declare 102 generic {
@@ -530,7 +527,7 @@ declare 103 generic {
declare 104 generic {
int Tk_GetPixels (Tcl_Interp *interp, \
- Tk_Window tkwin, char *string, int *intPtr)
+ Tk_Window tkwin, char *str, int *intPtr)
}
declare 105 generic {
@@ -553,7 +550,7 @@ declare 108 generic {
declare 109 generic {
int Tk_GetScreenMM (Tcl_Interp *interp, \
- Tk_Window tkwin, char *string, double *doublePtr)
+ Tk_Window tkwin, char *str, double *doublePtr)
}
declare 110 generic {
@@ -563,12 +560,12 @@ declare 110 generic {
}
declare 111 generic {
- Tk_Uid Tk_GetUid (CONST char *string)
+ Tk_Uid Tk_GetUid (CONST char *str)
}
declare 112 generic {
Visual * Tk_GetVisual (Tcl_Interp *interp, \
- Tk_Window tkwin, char *string, int *depthPtr, \
+ Tk_Window tkwin, char *str, int *depthPtr, \
Colormap *colormapPtr)
}
@@ -631,7 +628,7 @@ declare 125 generic {
declare 126 generic {
int Tk_MeasureChars (Tk_Font tkfont, \
- CONST char *source, int maxChars, int maxPixels, \
+ CONST char *source, int numBytes, int maxPixels, \
int flags, int *lengthPtr)
}
@@ -849,7 +846,7 @@ declare 175 generic {
}
declare 176 generic {
- int Tk_TextWidth (Tk_Font font, CONST char *string, int numChars)
+ int Tk_TextWidth (Tk_Font font, CONST char *str, int numBytes)
}
declare 177 generic {
@@ -859,8 +856,8 @@ declare 177 generic {
declare 178 generic {
void Tk_UnderlineChars (Display *display, \
Drawable drawable, GC gc, Tk_Font tkfont, \
- CONST char *source, int x, int y, int firstChar, \
- int lastChar)
+ CONST char *source, int x, int y, int firstByte, \
+ int lastByte)
}
declare 179 generic {
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index fbda648..5178546 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCanvText.c,v 1.1.4.3 1998/11/25 21:16:31 stanton Exp $
+ * RCS: @(#) $Id: tkCanvText.c,v 1.1.4.4 1999/03/30 04:12:55 stanton Exp $
*/
#include <stdio.h>
@@ -36,8 +36,8 @@ typedef struct TextItem {
*/
double x, y; /* Positioning point for text. */
- int insertPos; /* Byte index of character just before which
- * the insertion cursor is displayed. */
+ int insertPos; /* Character index of character just before
+ * which the insertion cursor is displayed. */
/*
* Configuration settings that are updated by Tk_ConfigureWidget.
@@ -57,6 +57,7 @@ typedef struct TextItem {
* configuration settings above.
*/
+ int numChars; /* Length of text in characters. */
int numBytes; /* Length of text in bytes. */
Tk_TextLayout textLayout; /* Cached text layout information. */
int leftEdge; /* Pixel location of the left edge of the
@@ -231,6 +232,7 @@ CreateText(interp, canvas, itemPtr, argc, argv)
textPtr->text = NULL;
textPtr->width = 0;
+ textPtr->numChars = 0;
textPtr->numBytes = 0;
textPtr->textLayout = NULL;
textPtr->leftEdge = 0;
@@ -401,24 +403,23 @@ ConfigureText(interp, canvas, itemPtr, argc, argv, flags)
*/
textPtr->numBytes = strlen(textPtr->text);
+ textPtr->numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes);
if (textInfoPtr->selItemPtr == itemPtr) {
- int numChars;
- numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes);
- if (textInfoPtr->selectFirst >= numChars) {
+ if (textInfoPtr->selectFirst >= textPtr->numChars) {
textInfoPtr->selItemPtr = NULL;
} else {
- if (textInfoPtr->selectLast >= numChars) {
- textInfoPtr->selectLast = numChars - 1;
+ if (textInfoPtr->selectLast >= textPtr->numChars) {
+ textInfoPtr->selectLast = textPtr->numChars - 1;
}
if ((textInfoPtr->anchorItemPtr == itemPtr)
- && (textInfoPtr->selectAnchor >= numChars)) {
- textInfoPtr->selectAnchor = numChars - 1;
+ && (textInfoPtr->selectAnchor >= textPtr->numChars)) {
+ textInfoPtr->selectAnchor = textPtr->numChars - 1;
}
}
}
- if (textPtr->insertPos >= textPtr->numBytes) {
- textPtr->insertPos = textPtr->numBytes;
+ if (textPtr->insertPos >= textPtr->numChars) {
+ textPtr->insertPos = textPtr->numChars;
}
ComputeTextBbox(canvas, textPtr);
@@ -504,7 +505,7 @@ ComputeTextBbox(canvas, textPtr)
Tk_FreeTextLayout(textPtr->textLayout);
textPtr->textLayout = Tk_ComputeTextLayout(textPtr->tkfont,
- textPtr->text, textPtr->numBytes, textPtr->width,
+ textPtr->text, textPtr->numChars, textPtr->width,
textPtr->justify, 0, &width, &height);
/*
@@ -601,7 +602,7 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height)
{
TextItem *textPtr;
Tk_CanvasTextInfo *textInfoPtr;
- int selFirst, selLast;
+ int selFirstChar, selLastChar;
short drawableX, drawableY;
textPtr = (TextItem *) itemPtr;
@@ -621,18 +622,17 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height)
Tk_CanvasSetStippleOrigin(canvas, textPtr->gc);
}
- selFirst = -1;
- selLast = 0; /* lint. */
+ selFirstChar = -1;
+ selLastChar = 0; /* lint. */
+
if (textInfoPtr->selItemPtr == itemPtr) {
char *text;
- int numChars, selFirstChar, selLastChar;
text = textPtr->text;
- numChars = Tcl_NumUtfChars(text, textPtr->numBytes);
selFirstChar = textInfoPtr->selectFirst;
selLastChar = textInfoPtr->selectLast;
- if (selLastChar >= numChars) {
- selLastChar = numChars - 1;
+ if (selLastChar >= textPtr->numChars) {
+ selLastChar = textPtr->numChars - 1;
}
if ((selFirstChar >= 0) && (selFirstChar <= selLastChar)) {
int xFirst, yFirst, hFirst;
@@ -642,12 +642,9 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height)
* Draw a special background under the selection.
*/
- selFirst = Tcl_UtfAtIndex(text, selFirstChar) - text;
- selLast = Tcl_UtfAtIndex(text, selLastChar + 1) - text;
-
- Tk_CharBbox(textPtr->textLayout, selFirst, &xFirst, &yFirst,
+ Tk_CharBbox(textPtr->textLayout, selFirstChar, &xFirst, &yFirst,
NULL, &hFirst);
- Tk_CharBbox(textPtr->textLayout, selLast, &xLast, &yLast,
+ Tk_CharBbox(textPtr->textLayout, selLastChar, &xLast, &yLast,
NULL, NULL);
/*
@@ -732,10 +729,10 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height)
Tk_DrawTextLayout(display, drawable, textPtr->gc, textPtr->textLayout,
drawableX, drawableY, 0, -1);
- if ((selFirst >= 0) && (textPtr->selTextGC != textPtr->gc)) {
+ if ((selFirstChar >= 0) && (textPtr->selTextGC != textPtr->gc)) {
Tk_DrawTextLayout(display, drawable, textPtr->selTextGC,
- textPtr->textLayout, drawableX, drawableY, selFirst,
- selLast + 1);
+ textPtr->textLayout, drawableX, drawableY, selFirstChar,
+ selLastChar + 1);
}
if (textPtr->stipple != None) {
@@ -770,18 +767,17 @@ TextInsert(canvas, itemPtr, index, string)
char *string; /* New characters to be inserted. */
{
TextItem *textPtr = (TextItem *) itemPtr;
- int numChars, byteIndex, byteCount, charsAdded;
+ int byteIndex, byteCount, charsAdded;
char *new, *text;
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
text = textPtr->text;
- numChars = Tcl_NumUtfChars(text, textPtr->numBytes);
if (index < 0) {
index = 0;
}
- if (index > numChars) {
- index = numChars;
+ if (index > textPtr->numChars) {
+ index = textPtr->numChars;
}
byteIndex = Tcl_UtfAtIndex(text, index) - text;
byteCount = strlen(string);
@@ -796,10 +792,10 @@ TextInsert(canvas, itemPtr, index, string)
ckfree(text);
textPtr->text = new;
+ charsAdded = Tcl_NumUtfChars(string, byteCount);
+ textPtr->numChars += charsAdded;
textPtr->numBytes += byteCount;
- charsAdded = Tcl_NumUtfChars(new, textPtr->numBytes) - numChars;
-
/*
* Inserting characters invalidates indices such as those for the
* selection and cursor. Update the indices appropriately.
@@ -817,8 +813,8 @@ TextInsert(canvas, itemPtr, index, string)
textInfoPtr->selectAnchor += charsAdded;
}
}
- if (textPtr->insertPos >= byteIndex) {
- textPtr->insertPos += byteCount;
+ if (textPtr->insertPos >= index) {
+ textPtr->insertPos += charsAdded;
}
ComputeTextBbox(canvas, textPtr);
}
@@ -851,25 +847,25 @@ TextDeleteChars(canvas, itemPtr, first, last)
* delete (inclusive). */
{
TextItem *textPtr = (TextItem *) itemPtr;
- int count, numChars, byteIndex, byteCount, charsRemoved;
+ int byteIndex, byteCount, charsRemoved;
char *new, *text;
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
text = textPtr->text;
- numChars = Tcl_NumUtfChars(text, textPtr->numBytes);
if (first < 0) {
first = 0;
}
- if (last >= numChars) {
- last = numChars - 1;
+ if (last >= textPtr->numChars) {
+ last = textPtr->numChars - 1;
}
if (first > last) {
return;
}
- count = last + 1 - first;
+ charsRemoved = last + 1 - first;
byteIndex = Tcl_UtfAtIndex(text, first) - text;
- byteCount = Tcl_UtfAtIndex(text + byteIndex, count) - (text + byteIndex);
+ byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved)
+ - (text + byteIndex);
new = (char *) ckalloc((unsigned) (textPtr->numBytes + 1 - byteCount));
memcpy(new, text, (size_t) byteIndex);
@@ -877,10 +873,9 @@ TextDeleteChars(canvas, itemPtr, first, last)
ckfree(text);
textPtr->text = new;
+ textPtr->numChars -= charsRemoved;
textPtr->numBytes -= byteCount;
- charsRemoved = numChars - Tcl_NumUtfChars(new, textPtr->numBytes);
-
/*
* Update indexes for the selection and cursor to reflect the
* renumbering of the remaining characters.
@@ -910,10 +905,10 @@ TextDeleteChars(canvas, itemPtr, first, last)
}
}
}
- if (textPtr->insertPos > byteIndex) {
- textPtr->insertPos -= byteCount;
- if (textPtr->insertPos < byteIndex) {
- textPtr->insertPos = byteIndex;
+ if (textPtr->insertPos > first) {
+ textPtr->insertPos -= charsRemoved;
+ if (textPtr->insertPos < first) {
+ textPtr->insertPos = first;
}
}
ComputeTextBbox(canvas, textPtr);
@@ -1099,11 +1094,9 @@ GetTextIndex(interp, canvas, itemPtr, string, indexPtr)
length = strlen(string);
if ((c == 'e') && (strncmp(string, "end", length) == 0)) {
- *indexPtr = Tcl_UtfAtIndex(textPtr->text, textPtr->numBytes)
- - textPtr->text;
+ *indexPtr = textPtr->numChars;
} else if ((c == 'i') && (strncmp(string, "insert", length) == 0)) {
- *indexPtr = Tcl_UtfAtIndex(textPtr->text, textPtr->insertPos)
- - textPtr->text;
+ *indexPtr = textPtr->insertPos;
} else if ((c == 's') && (strncmp(string, "sel.first", length) == 0)
&& (length >= 5)) {
if (textInfoPtr->selItemPtr != itemPtr) {
@@ -1119,7 +1112,7 @@ GetTextIndex(interp, canvas, itemPtr, string, indexPtr)
}
*indexPtr = textInfoPtr->selectLast;
} else if (c == '@') {
- int x, y, byteIndex;
+ int x, y;
double tmp;
char *end, *p;
@@ -1135,18 +1128,14 @@ GetTextIndex(interp, canvas, itemPtr, string, indexPtr)
goto badIndex;
}
y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);
- byteIndex = Tk_PointToChar(textPtr->textLayout,
+ *indexPtr = Tk_PointToChar(textPtr->textLayout,
x + canvasPtr->scrollX1 - textPtr->leftEdge,
y + canvasPtr->scrollY1 - textPtr->header.y1);
- *indexPtr = Tcl_UtfAtIndex(textPtr->text, byteIndex) - textPtr->text;
} else if (Tcl_GetInt(interp, string, indexPtr) == TCL_OK) {
- int numChars;
-
- numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes);
if (*indexPtr < 0){
*indexPtr = 0;
- } else if (*indexPtr > numChars) {
- *indexPtr = numChars;
+ } else if (*indexPtr > textPtr->numChars) {
+ *indexPtr = textPtr->numChars;
}
} else {
/*
@@ -1185,15 +1174,15 @@ SetTextCursor(canvas, itemPtr, index)
Tk_Canvas canvas; /* Record describing canvas widget. */
Tk_Item *itemPtr; /* Text item in which cursor position is to
* be set. */
- int index; /* Byte index of character just before which
- * cursor is to be positioned. */
+ int index; /* Character index of character just before
+ * which cursor is to be positioned. */
{
TextItem *textPtr = (TextItem *) itemPtr;
if (index < 0) {
textPtr->insertPos = 0;
- } else if (index > textPtr->numBytes) {
- textPtr->insertPos = textPtr->numBytes;
+ } else if (index > textPtr->numChars) {
+ textPtr->insertPos = textPtr->numChars;
} else {
textPtr->insertPos = index;
}
diff --git a/generic/tkDecls.h b/generic/tkDecls.h
index 67268c4..4099f29 100644
--- a/generic/tkDecls.h
+++ b/generic/tkDecls.h
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkDecls.h,v 1.2.2.2 1999/03/30 02:07:59 redman Exp $
+ * RCS: @(#) $Id: tkDecls.h,v 1.2.2.3 1999/03/30 04:12:55 stanton Exp $
*/
#ifndef _TKDECLS
@@ -66,7 +66,7 @@ EXTERN void Tk_CanvasEventuallyRedraw _ANSI_ARGS_((
int y2));
/* 9 */
EXTERN int Tk_CanvasGetCoord _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Canvas canvas, char * string,
+ Tk_Canvas canvas, char * str,
double * doublePtr));
/* 10 */
EXTERN Tk_CanvasTextInfo * Tk_CanvasGetTextInfo _ANSI_ARGS_((
@@ -146,7 +146,7 @@ EXTERN void Tk_ConfigureWindow _ANSI_ARGS_((Tk_Window tkwin,
XWindowChanges * valuePtr));
/* 31 */
EXTERN Tk_TextLayout Tk_ComputeTextLayout _ANSI_ARGS_((Tk_Font font,
- CONST char * string, int numChars,
+ CONST char * str, int numChars,
int wrapLength, Tk_Justify justify,
int flags, int * widthPtr, int * heightPtr));
/* 32 */
@@ -155,7 +155,7 @@ EXTERN Tk_Window Tk_CoordsToWindow _ANSI_ARGS_((int rootX, int rootY,
/* 33 */
EXTERN unsigned long Tk_CreateBinding _ANSI_ARGS_((Tcl_Interp * interp,
Tk_BindingTable bindingTable,
- ClientData object, char * eventString,
+ ClientData object, char * eventStr,
char * command, int append));
/* 34 */
EXTERN Tk_BindingTable Tk_CreateBindingTable _ANSI_ARGS_((
@@ -195,7 +195,7 @@ EXTERN Tk_Window Tk_CreateWindowFromPath _ANSI_ARGS_((
char * pathName, char * screenName));
/* 44 */
EXTERN int Tk_DefineBitmap _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Uid name, char * source, int width,
+ CONST char * name, char * source, int width,
int height));
/* 45 */
EXTERN void Tk_DefineCursor _ANSI_ARGS_((Tk_Window window,
@@ -207,7 +207,7 @@ EXTERN void Tk_DeleteAllBindings _ANSI_ARGS_((
/* 47 */
EXTERN int Tk_DeleteBinding _ANSI_ARGS_((Tcl_Interp * interp,
Tk_BindingTable bindingTable,
- ClientData object, char * eventString));
+ ClientData object, char * eventStr));
/* 48 */
EXTERN void Tk_DeleteBindingTable _ANSI_ARGS_((
Tk_BindingTable bindingTable));
@@ -247,7 +247,7 @@ EXTERN void Tk_Draw3DRectangle _ANSI_ARGS_((Tk_Window tkwin,
/* 59 */
EXTERN void Tk_DrawChars _ANSI_ARGS_((Display * display,
Drawable drawable, GC gc, Tk_Font tkfont,
- CONST char * source, int numChars, int x,
+ CONST char * source, int numBytes, int x,
int y));
/* 60 */
EXTERN void Tk_DrawFocusHighlight _ANSI_ARGS_((Tk_Window tkwin,
@@ -318,24 +318,24 @@ EXTERN void Tk_GetAllBindings _ANSI_ARGS_((Tcl_Interp * interp,
ClientData object));
/* 82 */
EXTERN int Tk_GetAnchor _ANSI_ARGS_((Tcl_Interp * interp,
- char * string, Tk_Anchor * anchorPtr));
+ char * str, Tk_Anchor * anchorPtr));
/* 83 */
EXTERN char * Tk_GetAtomName _ANSI_ARGS_((Tk_Window tkwin,
Atom atom));
/* 84 */
EXTERN char * Tk_GetBinding _ANSI_ARGS_((Tcl_Interp * interp,
Tk_BindingTable bindingTable,
- ClientData object, char * eventString));
+ ClientData object, char * eventStr));
/* 85 */
EXTERN Pixmap Tk_GetBitmap _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, Tk_Uid string));
+ Tk_Window tkwin, CONST char * str));
/* 86 */
EXTERN Pixmap Tk_GetBitmapFromData _ANSI_ARGS_((
Tcl_Interp * interp, Tk_Window tkwin,
char * source, int width, int height));
/* 87 */
EXTERN int Tk_GetCapStyle _ANSI_ARGS_((Tcl_Interp * interp,
- char * string, int * capPtr));
+ char * str, int * capPtr));
/* 88 */
EXTERN XColor * Tk_GetColor _ANSI_ARGS_((Tcl_Interp * interp,
Tk_Window tkwin, Tk_Uid name));
@@ -344,10 +344,10 @@ EXTERN XColor * Tk_GetColorByValue _ANSI_ARGS_((Tk_Window tkwin,
XColor * colorPtr));
/* 90 */
EXTERN Colormap Tk_GetColormap _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, char * string));
+ Tk_Window tkwin, char * str));
/* 91 */
EXTERN Tk_Cursor Tk_GetCursor _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, Tk_Uid string));
+ Tk_Window tkwin, Tk_Uid str));
/* 92 */
EXTERN Tk_Cursor Tk_GetCursorFromData _ANSI_ARGS_((
Tcl_Interp * interp, Tk_Window tkwin,
@@ -356,7 +356,7 @@ EXTERN Tk_Cursor Tk_GetCursorFromData _ANSI_ARGS_((
Tk_Uid bg));
/* 93 */
EXTERN Tk_Font Tk_GetFont _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, CONST char * string));
+ Tk_Window tkwin, CONST char * str));
/* 94 */
EXTERN Tk_Font Tk_GetFontFromObj _ANSI_ARGS_((Tk_Window tkwin,
Tcl_Obj * objPtr));
@@ -380,10 +380,10 @@ EXTERN ClientData Tk_GetImageMasterData _ANSI_ARGS_((
EXTERN Tk_ItemType * Tk_GetItemTypes _ANSI_ARGS_((void));
/* 100 */
EXTERN int Tk_GetJoinStyle _ANSI_ARGS_((Tcl_Interp * interp,
- char * string, int * joinPtr));
+ char * str, int * joinPtr));
/* 101 */
EXTERN int Tk_GetJustify _ANSI_ARGS_((Tcl_Interp * interp,
- char * string, Tk_Justify * justifyPtr));
+ char * str, Tk_Justify * justifyPtr));
/* 102 */
EXTERN int Tk_GetNumMainWindows _ANSI_ARGS_((void));
/* 103 */
@@ -391,7 +391,7 @@ EXTERN Tk_Uid Tk_GetOption _ANSI_ARGS_((Tk_Window tkwin,
char * name, char * className));
/* 104 */
EXTERN int Tk_GetPixels _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, char * string, int * intPtr));
+ Tk_Window tkwin, char * str, int * intPtr));
/* 105 */
EXTERN Pixmap Tk_GetPixmap _ANSI_ARGS_((Display * display,
Drawable d, int width, int height, int depth));
@@ -407,18 +407,18 @@ EXTERN int Tk_GetScrollInfo _ANSI_ARGS_((Tcl_Interp * interp,
int * intPtr));
/* 109 */
EXTERN int Tk_GetScreenMM _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, char * string,
+ Tk_Window tkwin, char * str,
double * doublePtr));
/* 110 */
EXTERN int Tk_GetSelection _ANSI_ARGS_((Tcl_Interp * interp,
Tk_Window tkwin, Atom selection, Atom target,
Tk_GetSelProc * proc, ClientData clientData));
/* 111 */
-EXTERN Tk_Uid Tk_GetUid _ANSI_ARGS_((CONST char * string));
+EXTERN Tk_Uid Tk_GetUid _ANSI_ARGS_((CONST char * str));
/* 112 */
EXTERN Visual * Tk_GetVisual _ANSI_ARGS_((Tcl_Interp * interp,
- Tk_Window tkwin, char * string,
- int * depthPtr, Colormap * colormapPtr));
+ Tk_Window tkwin, char * str, int * depthPtr,
+ Colormap * colormapPtr));
/* 113 */
EXTERN void Tk_GetVRootGeometry _ANSI_ARGS_((Tk_Window tkwin,
int * xPtr, int * yPtr, int * widthPtr,
@@ -459,7 +459,7 @@ EXTERN void Tk_ManageGeometry _ANSI_ARGS_((Tk_Window tkwin,
EXTERN void Tk_MapWindow _ANSI_ARGS_((Tk_Window tkwin));
/* 126 */
EXTERN int Tk_MeasureChars _ANSI_ARGS_((Tk_Font tkfont,
- CONST char * source, int maxChars,
+ CONST char * source, int numBytes,
int maxPixels, int flags, int * lengthPtr));
/* 127 */
EXTERN void Tk_MoveResizeWindow _ANSI_ARGS_((Tk_Window tkwin,
@@ -611,14 +611,14 @@ EXTERN void Tk_TextLayoutToPostscript _ANSI_ARGS_((
Tcl_Interp * interp, Tk_TextLayout layout));
/* 176 */
EXTERN int Tk_TextWidth _ANSI_ARGS_((Tk_Font font,
- CONST char * string, int numChars));
+ CONST char * str, int numBytes));
/* 177 */
EXTERN void Tk_UndefineCursor _ANSI_ARGS_((Tk_Window window));
/* 178 */
EXTERN void Tk_UnderlineChars _ANSI_ARGS_((Display * display,
Drawable drawable, GC gc, Tk_Font tkfont,
CONST char * source, int x, int y,
- int firstChar, int lastChar));
+ int firstByte, int lastByte));
/* 179 */
EXTERN void Tk_UnderlineTextLayout _ANSI_ARGS_((
Display * display, Drawable drawable, GC gc,
@@ -763,7 +763,7 @@ typedef struct TkStubs {
void (*tk_BindEvent) _ANSI_ARGS_((Tk_BindingTable bindingTable, XEvent * eventPtr, Tk_Window tkwin, int numObjects, ClientData * objectPtr)); /* 6 */
void (*tk_CanvasDrawableCoords) _ANSI_ARGS_((Tk_Canvas canvas, double x, double y, short * drawableXPtr, short * drawableYPtr)); /* 7 */
void (*tk_CanvasEventuallyRedraw) _ANSI_ARGS_((Tk_Canvas canvas, int x1, int y1, int x2, int y2)); /* 8 */
- int (*tk_CanvasGetCoord) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Canvas canvas, char * string, double * doublePtr)); /* 9 */
+ int (*tk_CanvasGetCoord) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Canvas canvas, char * str, double * doublePtr)); /* 9 */
Tk_CanvasTextInfo * (*tk_CanvasGetTextInfo) _ANSI_ARGS_((Tk_Canvas canvas)); /* 10 */
int (*tk_CanvasPsBitmap) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Canvas canvas, Pixmap bitmap, int x, int y, int width, int height)); /* 11 */
int (*tk_CanvasPsColor) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Canvas canvas, XColor * colorPtr)); /* 12 */
@@ -785,9 +785,9 @@ typedef struct TkStubs {
int (*tk_ConfigureValue) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_ConfigSpec * specs, char * widgRec, char * argvName, int flags)); /* 28 */
int (*tk_ConfigureWidget) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_ConfigSpec * specs, int argc, char ** argv, char * widgRec, int flags)); /* 29 */
void (*tk_ConfigureWindow) _ANSI_ARGS_((Tk_Window tkwin, unsigned int valueMask, XWindowChanges * valuePtr)); /* 30 */
- Tk_TextLayout (*tk_ComputeTextLayout) _ANSI_ARGS_((Tk_Font font, CONST char * string, int numChars, int wrapLength, Tk_Justify justify, int flags, int * widthPtr, int * heightPtr)); /* 31 */
+ Tk_TextLayout (*tk_ComputeTextLayout) _ANSI_ARGS_((Tk_Font font, CONST char * str, int numChars, int wrapLength, Tk_Justify justify, int flags, int * widthPtr, int * heightPtr)); /* 31 */
Tk_Window (*tk_CoordsToWindow) _ANSI_ARGS_((int rootX, int rootY, Tk_Window tkwin)); /* 32 */
- unsigned long (*tk_CreateBinding) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object, char * eventString, char * command, int append)); /* 33 */
+ unsigned long (*tk_CreateBinding) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object, char * eventStr, char * command, int append)); /* 33 */
Tk_BindingTable (*tk_CreateBindingTable) _ANSI_ARGS_((Tcl_Interp * interp)); /* 34 */
Tk_ErrorHandler (*tk_CreateErrorHandler) _ANSI_ARGS_((Display * display, int errNum, int request, int minorCode, Tk_ErrorProc * errorProc, ClientData clientData)); /* 35 */
void (*tk_CreateEventHandler) _ANSI_ARGS_((Tk_Window token, unsigned long mask, Tk_EventProc * proc, ClientData clientData)); /* 36 */
@@ -798,10 +798,10 @@ typedef struct TkStubs {
void (*tk_CreateSelHandler) _ANSI_ARGS_((Tk_Window tkwin, Atom selection, Atom target, Tk_SelectionProc * proc, ClientData clientData, Atom format)); /* 41 */
Tk_Window (*tk_CreateWindow) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window parent, char * name, char * screenName)); /* 42 */
Tk_Window (*tk_CreateWindowFromPath) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * pathName, char * screenName)); /* 43 */
- int (*tk_DefineBitmap) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Uid name, char * source, int width, int height)); /* 44 */
+ int (*tk_DefineBitmap) _ANSI_ARGS_((Tcl_Interp * interp, CONST char * name, char * source, int width, int height)); /* 44 */
void (*tk_DefineCursor) _ANSI_ARGS_((Tk_Window window, Tk_Cursor cursor)); /* 45 */
void (*tk_DeleteAllBindings) _ANSI_ARGS_((Tk_BindingTable bindingTable, ClientData object)); /* 46 */
- int (*tk_DeleteBinding) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object, char * eventString)); /* 47 */
+ int (*tk_DeleteBinding) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object, char * eventStr)); /* 47 */
void (*tk_DeleteBindingTable) _ANSI_ARGS_((Tk_BindingTable bindingTable)); /* 48 */
void (*tk_DeleteErrorHandler) _ANSI_ARGS_((Tk_ErrorHandler handler)); /* 49 */
void (*tk_DeleteEventHandler) _ANSI_ARGS_((Tk_Window token, unsigned long mask, Tk_EventProc * proc, ClientData clientData)); /* 50 */
@@ -813,7 +813,7 @@ typedef struct TkStubs {
int (*tk_DistanceToTextLayout) _ANSI_ARGS_((Tk_TextLayout layout, int x, int y)); /* 56 */
void (*tk_Draw3DPolygon) _ANSI_ARGS_((Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, XPoint * pointPtr, int numPoints, int borderWidth, int leftRelief)); /* 57 */
void (*tk_Draw3DRectangle) _ANSI_ARGS_((Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, int x, int y, int width, int height, int borderWidth, int relief)); /* 58 */
- void (*tk_DrawChars) _ANSI_ARGS_((Display * display, Drawable drawable, GC gc, Tk_Font tkfont, CONST char * source, int numChars, int x, int y)); /* 59 */
+ void (*tk_DrawChars) _ANSI_ARGS_((Display * display, Drawable drawable, GC gc, Tk_Font tkfont, CONST char * source, int numBytes, int x, int y)); /* 59 */
void (*tk_DrawFocusHighlight) _ANSI_ARGS_((Tk_Window tkwin, GC gc, int width, Drawable drawable)); /* 60 */
void (*tk_DrawTextLayout) _ANSI_ARGS_((Display * display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, int firstChar, int lastChar)); /* 61 */
void (*tk_Fill3DPolygon) _ANSI_ARGS_((Tk_Window tkwin, Drawable drawable, Tk_3DBorder border, XPoint * pointPtr, int numPoints, int borderWidth, int leftRelief)); /* 62 */
@@ -836,37 +836,37 @@ typedef struct TkStubs {
void (*tk_GeometryRequest) _ANSI_ARGS_((Tk_Window tkwin, int reqWidth, int reqHeight)); /* 79 */
Tk_3DBorder (*tk_Get3DBorder) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_Uid colorName)); /* 80 */
void (*tk_GetAllBindings) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object)); /* 81 */
- int (*tk_GetAnchor) _ANSI_ARGS_((Tcl_Interp * interp, char * string, Tk_Anchor * anchorPtr)); /* 82 */
+ int (*tk_GetAnchor) _ANSI_ARGS_((Tcl_Interp * interp, char * str, Tk_Anchor * anchorPtr)); /* 82 */
char * (*tk_GetAtomName) _ANSI_ARGS_((Tk_Window tkwin, Atom atom)); /* 83 */
- char * (*tk_GetBinding) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object, char * eventString)); /* 84 */
- Pixmap (*tk_GetBitmap) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_Uid string)); /* 85 */
+ char * (*tk_GetBinding) _ANSI_ARGS_((Tcl_Interp * interp, Tk_BindingTable bindingTable, ClientData object, char * eventStr)); /* 84 */
+ Pixmap (*tk_GetBitmap) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, CONST char * str)); /* 85 */
Pixmap (*tk_GetBitmapFromData) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * source, int width, int height)); /* 86 */
- int (*tk_GetCapStyle) _ANSI_ARGS_((Tcl_Interp * interp, char * string, int * capPtr)); /* 87 */
+ int (*tk_GetCapStyle) _ANSI_ARGS_((Tcl_Interp * interp, char * str, int * capPtr)); /* 87 */
XColor * (*tk_GetColor) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_Uid name)); /* 88 */
XColor * (*tk_GetColorByValue) _ANSI_ARGS_((Tk_Window tkwin, XColor * colorPtr)); /* 89 */
- Colormap (*tk_GetColormap) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * string)); /* 90 */
- Tk_Cursor (*tk_GetCursor) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_Uid string)); /* 91 */
+ Colormap (*tk_GetColormap) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * str)); /* 90 */
+ Tk_Cursor (*tk_GetCursor) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Tk_Uid str)); /* 91 */
Tk_Cursor (*tk_GetCursorFromData) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * source, char * mask, int width, int height, int xHot, int yHot, Tk_Uid fg, Tk_Uid bg)); /* 92 */
- Tk_Font (*tk_GetFont) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, CONST char * string)); /* 93 */
+ Tk_Font (*tk_GetFont) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, CONST char * str)); /* 93 */
Tk_Font (*tk_GetFontFromObj) _ANSI_ARGS_((Tk_Window tkwin, Tcl_Obj * objPtr)); /* 94 */
void (*tk_GetFontMetrics) _ANSI_ARGS_((Tk_Font font, Tk_FontMetrics * fmPtr)); /* 95 */
GC (*tk_GetGC) _ANSI_ARGS_((Tk_Window tkwin, unsigned long valueMask, XGCValues * valuePtr)); /* 96 */
Tk_Image (*tk_GetImage) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * name, Tk_ImageChangedProc * changeProc, ClientData clientData)); /* 97 */
ClientData (*tk_GetImageMasterData) _ANSI_ARGS_((Tcl_Interp * interp, char * name, Tk_ImageType ** typePtrPtr)); /* 98 */
Tk_ItemType * (*tk_GetItemTypes) _ANSI_ARGS_((void)); /* 99 */
- int (*tk_GetJoinStyle) _ANSI_ARGS_((Tcl_Interp * interp, char * string, int * joinPtr)); /* 100 */
- int (*tk_GetJustify) _ANSI_ARGS_((Tcl_Interp * interp, char * string, Tk_Justify * justifyPtr)); /* 101 */
+ int (*tk_GetJoinStyle) _ANSI_ARGS_((Tcl_Interp * interp, char * str, int * joinPtr)); /* 100 */
+ int (*tk_GetJustify) _ANSI_ARGS_((Tcl_Interp * interp, char * str, Tk_Justify * justifyPtr)); /* 101 */
int (*tk_GetNumMainWindows) _ANSI_ARGS_((void)); /* 102 */
Tk_Uid (*tk_GetOption) _ANSI_ARGS_((Tk_Window tkwin, char * name, char * className)); /* 103 */
- int (*tk_GetPixels) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * string, int * intPtr)); /* 104 */
+ int (*tk_GetPixels) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * str, int * intPtr)); /* 104 */
Pixmap (*tk_GetPixmap) _ANSI_ARGS_((Display * display, Drawable d, int width, int height, int depth)); /* 105 */
int (*tk_GetRelief) _ANSI_ARGS_((Tcl_Interp * interp, char * name, int * reliefPtr)); /* 106 */
void (*tk_GetRootCoords) _ANSI_ARGS_((Tk_Window tkwin, int * xPtr, int * yPtr)); /* 107 */
int (*tk_GetScrollInfo) _ANSI_ARGS_((Tcl_Interp * interp, int argc, char ** argv, double * dblPtr, int * intPtr)); /* 108 */
- int (*tk_GetScreenMM) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * string, double * doublePtr)); /* 109 */
+ int (*tk_GetScreenMM) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * str, double * doublePtr)); /* 109 */
int (*tk_GetSelection) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, Atom selection, Atom target, Tk_GetSelProc * proc, ClientData clientData)); /* 110 */
- Tk_Uid (*tk_GetUid) _ANSI_ARGS_((CONST char * string)); /* 111 */
- Visual * (*tk_GetVisual) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * string, int * depthPtr, Colormap * colormapPtr)); /* 112 */
+ Tk_Uid (*tk_GetUid) _ANSI_ARGS_((CONST char * str)); /* 111 */
+ Visual * (*tk_GetVisual) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, char * str, int * depthPtr, Colormap * colormapPtr)); /* 112 */
void (*tk_GetVRootGeometry) _ANSI_ARGS_((Tk_Window tkwin, int * xPtr, int * yPtr, int * widthPtr, int * heightPtr)); /* 113 */
int (*tk_Grab) _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin, int grabGlobal)); /* 114 */
void (*tk_HandleEvent) _ANSI_ARGS_((XEvent * eventPtr)); /* 115 */
@@ -880,7 +880,7 @@ typedef struct TkStubs {
void (*tk_MakeWindowExist) _ANSI_ARGS_((Tk_Window tkwin)); /* 123 */
void (*tk_ManageGeometry) _ANSI_ARGS_((Tk_Window tkwin, Tk_GeomMgr * mgrPtr, ClientData clientData)); /* 124 */
void (*tk_MapWindow) _ANSI_ARGS_((Tk_Window tkwin)); /* 125 */
- int (*tk_MeasureChars) _ANSI_ARGS_((Tk_Font tkfont, CONST char * source, int maxChars, int maxPixels, int flags, int * lengthPtr)); /* 126 */
+ int (*tk_MeasureChars) _ANSI_ARGS_((Tk_Font tkfont, CONST char * source, int numBytes, int maxPixels, int flags, int * lengthPtr)); /* 126 */
void (*tk_MoveResizeWindow) _ANSI_ARGS_((Tk_Window tkwin, int x, int y, int width, int height)); /* 127 */
void (*tk_MoveWindow) _ANSI_ARGS_((Tk_Window tkwin, int x, int y)); /* 128 */
void (*tk_MoveToplevelWindow) _ANSI_ARGS_((Tk_Window tkwin, int x, int y)); /* 129 */
@@ -930,9 +930,9 @@ typedef struct TkStubs {
void (*tk_SizeOfImage) _ANSI_ARGS_((Tk_Image image, int * widthPtr, int * heightPtr)); /* 173 */
int (*tk_StrictMotif) _ANSI_ARGS_((Tk_Window tkwin)); /* 174 */
void (*tk_TextLayoutToPostscript) _ANSI_ARGS_((Tcl_Interp * interp, Tk_TextLayout layout)); /* 175 */
- int (*tk_TextWidth) _ANSI_ARGS_((Tk_Font font, CONST char * string, int numChars)); /* 176 */
+ int (*tk_TextWidth) _ANSI_ARGS_((Tk_Font font, CONST char * str, int numBytes)); /* 176 */
void (*tk_UndefineCursor) _ANSI_ARGS_((Tk_Window window)); /* 177 */
- void (*tk_UnderlineChars) _ANSI_ARGS_((Display * display, Drawable drawable, GC gc, Tk_Font tkfont, CONST char * source, int x, int y, int firstChar, int lastChar)); /* 178 */
+ void (*tk_UnderlineChars) _ANSI_ARGS_((Display * display, Drawable drawable, GC gc, Tk_Font tkfont, CONST char * source, int x, int y, int firstByte, int lastByte)); /* 178 */
void (*tk_UnderlineTextLayout) _ANSI_ARGS_((Display * display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, int underline)); /* 179 */
void (*tk_Ungrab) _ANSI_ARGS_((Tk_Window tkwin)); /* 180 */
void (*tk_UnmaintainGeometry) _ANSI_ARGS_((Tk_Window slave, Tk_Window master)); /* 181 */
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index cedd835..8a46300 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkEntry.c,v 1.1.4.4 1999/02/16 11:39:31 lfb Exp $
+ * RCS: @(#) $Id: tkEntry.c,v 1.1.4.5 1999/03/30 04:12:56 stanton Exp $
*/
#include "tkInt.h"
@@ -580,7 +580,7 @@ EntryWidgetObjCmd(clientData, interp, objc, objv)
switch (cmdIndex) {
case COMMAND_BBOX: {
- int index, byteIndex, x, y, width, height;
+ int index, x, y, width, height;
char *string;
char buf[TCL_INTEGER_SPACE * 4];
@@ -596,8 +596,7 @@ EntryWidgetObjCmd(clientData, interp, objc, objv)
index--;
}
string = entryPtr->displayString;
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
- Tk_CharBbox(entryPtr->textLayout, byteIndex, &x, &y,
+ Tk_CharBbox(entryPtr->textLayout, index, &x, &y,
&width, &height);
sprintf(buf, "%d %d %d %d", x + entryPtr->layoutX,
y + entryPtr->layoutY, width, height);
@@ -1259,7 +1258,7 @@ DisplayEntry(clientData)
int xBound;
Tk_FontMetrics fm;
Pixmap pixmap;
- int showSelection, selFirstByte, selLastByte, leftByte;
+ int showSelection;
char *string;
entryPtr->flags &= ~REDRAW_PENDING;
@@ -1322,17 +1321,13 @@ DisplayEntry(clientData)
if (entryPtr->selectFirst <= entryPtr->leftIndex) {
selStartX = entryPtr->leftX;
} else {
- selFirstByte = Tcl_UtfAtIndex(string, entryPtr->selectFirst)
- - string;
- Tk_CharBbox(entryPtr->textLayout, selFirstByte, &selStartX, NULL,
- NULL, NULL);
+ Tk_CharBbox(entryPtr->textLayout, entryPtr->selectFirst,
+ &selStartX, NULL, NULL, NULL);
selStartX += entryPtr->layoutX;
}
if ((selStartX - entryPtr->selBorderWidth) < xBound) {
- selLastByte = Tcl_UtfAtIndex(string, entryPtr->selectLast)
- - string;
- Tk_CharBbox(entryPtr->textLayout, selLastByte, &selEndX, NULL,
- NULL, NULL);
+ Tk_CharBbox(entryPtr->textLayout, entryPtr->selectLast,
+ &selEndX, NULL, NULL, NULL);
selEndX += entryPtr->layoutX;
Tk_Fill3DRectangle(tkwin, pixmap, entryPtr->selBorder,
selStartX - entryPtr->selBorderWidth,
@@ -1355,11 +1350,7 @@ DisplayEntry(clientData)
if ((entryPtr->insertPos >= entryPtr->leftIndex)
&& (entryPtr->state == STATE_NORMAL)
&& (entryPtr->flags & GOT_FOCUS)) {
- int insertByte;
-
- insertByte = Tcl_UtfAtIndex(string, entryPtr->insertPos)
- - string;
- Tk_CharBbox(entryPtr->textLayout, insertByte, &cursorX, NULL,
+ Tk_CharBbox(entryPtr->textLayout, entryPtr->insertPos, &cursorX, NULL,
NULL, NULL);
cursorX += entryPtr->layoutX;
cursorX -= (entryPtr->insertWidth)/2;
@@ -1382,25 +1373,23 @@ DisplayEntry(clientData)
* selected portion on top of it.
*/
- leftByte = Tcl_UtfAtIndex(string, entryPtr->leftIndex) - string;
Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
- leftByte, entryPtr->numDisplayBytes);
+ entryPtr->leftIndex, entryPtr->numChars);
if (showSelection
&& (entryPtr->selTextGC != entryPtr->textGC)
&& (entryPtr->selectFirst < entryPtr->selectLast)) {
+ int selFirst;
+
if (entryPtr->selectFirst < entryPtr->leftIndex) {
- selFirstByte = leftByte;
+ selFirst = entryPtr->leftIndex;
} else {
- selFirstByte = Tcl_UtfAtIndex(string, entryPtr->selectFirst)
- - string;
+ selFirst = entryPtr->selectFirst;
}
- selLastByte = Tcl_UtfAtIndex(string, entryPtr->selectLast)
- - string;
Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->selTextGC,
entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
- selFirstByte, selLastByte);
+ selFirst, entryPtr->selectLast);
}
/*
@@ -1463,7 +1452,7 @@ EntryComputeGeometry(entryPtr)
Entry *entryPtr; /* Widget record for entry. */
{
int totalLength, overflow, maxOffScreen, rightX;
- int height, width, i, leftByte;
+ int height, width, i;
Tk_FontMetrics fm;
char *p;
@@ -1483,8 +1472,16 @@ EntryComputeGeometry(entryPtr)
char buf[TCL_UTF_MAX];
int size;
+ /*
+ * Normalize the special character so we can safely duplicate it
+ * in the display string. If we didn't do this, then two malformed
+ * characters might end up looking like one valid UTF character in
+ * the resulting string.
+ */
+
Tcl_UtfToUniChar(entryPtr->showChar, &ch);
size = Tcl_UniCharToUtf(ch, buf);
+
entryPtr->numDisplayBytes = entryPtr->numChars * size;
entryPtr->displayString =
(char *) ckalloc((unsigned) (entryPtr->numDisplayBytes + 1));
@@ -1497,7 +1494,7 @@ EntryComputeGeometry(entryPtr)
}
Tk_FreeTextLayout(entryPtr->textLayout);
entryPtr->textLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
- entryPtr->displayString, entryPtr->numDisplayBytes, 0,
+ entryPtr->displayString, entryPtr->numChars, 0,
entryPtr->justify, TK_IGNORE_NEWLINES, &totalLength, &height);
entryPtr->layoutY = (Tk_Height(entryPtr->tkwin) - height) / 2;
@@ -1538,9 +1535,8 @@ EntryComputeGeometry(entryPtr)
if (entryPtr->leftIndex > maxOffScreen) {
entryPtr->leftIndex = maxOffScreen;
}
- leftByte = Tcl_UtfAtIndex(entryPtr->displayString, entryPtr->leftIndex)
- - entryPtr->displayString;
- Tk_CharBbox(entryPtr->textLayout, leftByte, &rightX, NULL, NULL, NULL);
+ Tk_CharBbox(entryPtr->textLayout, entryPtr->leftIndex, &rightX,
+ NULL, NULL, NULL);
entryPtr->leftX = entryPtr->inset;
entryPtr->layoutX = entryPtr->leftX - rightX;
}
@@ -1609,7 +1605,7 @@ InsertChars(entryPtr, index, value)
* sequences could result in actually forming valid UTF-8 sequences;
* the number of characters added may not be Tcl_NumUtfChars(string, -1),
* because of context. The actual number of characters added is how
- * many characters were are in the string now minus the number that
+ * many characters are in the string now minus the number that
* used to be there.
*/
@@ -1961,10 +1957,10 @@ EntryCmdDeletedProc(clientData)
* or an error.
*
* Results:
- * A standard Tcl result. If all went well, then *byteIndexPtr is
- * filled in with the index (into entryPtr) corresponding to
+ * A standard Tcl result. If all went well, then *indexPtr is
+ * filled in with the character index (into entryPtr) corresponding to
* string. The index value is guaranteed to lie between 0 and
- * the number of bytes in the string, inclusive. If an
+ * the number of characters in the string, inclusive. If an
* error occurs then an error message is left in the interp's result.
*
* Side effects:
@@ -2030,7 +2026,7 @@ GetEntryIndex(interp, entryPtr, string, indexPtr)
goto badIndex;
}
} else if (string[0] == '@') {
- int x, roundUp, byteIndex;
+ int x, roundUp;
if (Tcl_GetInt(interp, string + 1, &x) != TCL_OK) {
goto badIndex;
@@ -2043,9 +2039,8 @@ GetEntryIndex(interp, entryPtr, string, indexPtr)
x = Tk_Width(entryPtr->tkwin) - entryPtr->inset - 1;
roundUp = 1;
}
- byteIndex = Tk_PointToChar(entryPtr->textLayout,
+ *indexPtr = Tk_PointToChar(entryPtr->textLayout,
x - entryPtr->layoutX, 0);
- *indexPtr = Tcl_NumUtfChars(entryPtr->displayString, byteIndex);
/*
* Special trick: if the x-position was off-screen to the right,
@@ -2350,29 +2345,23 @@ EntryVisibleRange(entryPtr, firstPtr, lastPtr)
double *lastPtr; /* Return position of char just after last
* visible one. */
{
- int bytesInWindow, leftByte, charsInWindow;
- char *string;
+ int charsInWindow;
if (entryPtr->numChars == 0) {
*firstPtr = 0.0;
*lastPtr = 1.0;
} else {
- string = entryPtr->displayString;
-
- bytesInWindow = Tk_PointToChar(entryPtr->textLayout,
+ charsInWindow = Tk_PointToChar(entryPtr->textLayout,
Tk_Width(entryPtr->tkwin) - entryPtr->inset
- entryPtr->layoutX - 1, 0);
- if (bytesInWindow < entryPtr->numDisplayBytes) {
- bytesInWindow = Tcl_UtfNext(string + bytesInWindow) - string;
+ if (charsInWindow < entryPtr->numChars) {
+ charsInWindow++;
}
- bytesInWindow -= entryPtr->leftIndex;
- if (bytesInWindow == 0) {
- bytesInWindow = 1;
+ charsInWindow -= entryPtr->leftIndex;
+ if (charsInWindow == 0) {
+ charsInWindow = 1;
}
- leftByte = Tcl_UtfAtIndex(string, entryPtr->leftIndex) - string;
- charsInWindow = Tcl_NumUtfChars(string + leftByte, bytesInWindow);
-
*firstPtr = (double) entryPtr->leftIndex / entryPtr->numChars;
*lastPtr = (double) (entryPtr->leftIndex + charsInWindow)
/ entryPtr->numChars;
diff --git a/generic/tkFont.c b/generic/tkFont.c
index f923209..0c439de 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkFont.c,v 1.1.4.5 1998/11/25 23:06:42 stanton Exp $
+ * RCS: @(#) $Id: tkFont.c,v 1.1.4.6 1999/03/30 04:12:56 stanton Exp $
*/
#include "tkPort.h"
@@ -71,6 +71,7 @@ typedef struct LayoutChunk {
CONST char *start; /* Pointer to simple string to be displayed.
* This is a pointer into the TkTextLayout's
* string. */
+ int numBytes; /* The number of bytes in this chunk. */
int numChars; /* The number of characters in this chunk. */
int numDisplayChars; /* The number of characters to display when
* this chunk is displayed. Can be less than
@@ -800,7 +801,7 @@ UpdateDependentFonts(fiPtr, tkwin, namedHashPtr)
cacheHashPtr = Tcl_FirstHashEntry(&fiPtr->fontCache, &search);
while (cacheHashPtr != NULL) {
for (fontPtr = (TkFont *) Tcl_GetHashValue(cacheHashPtr);
- fontPtr->nextPtr != NULL; fontPtr = fontPtr->nextPtr) {
+ fontPtr != NULL; fontPtr = fontPtr->nextPtr) {
if (fontPtr->namedHashPtr == namedHashPtr) {
TkpGetFontFromAttributes(fontPtr, tkwin, &nfPtr->fa);
if (fiPtr->updatePending == 0) {
@@ -1683,18 +1684,18 @@ Tk_PostscriptFontName(tkfont, dsPtr)
*/
int
-Tk_TextWidth(tkfont, string, numChars)
+Tk_TextWidth(tkfont, string, numBytes)
Tk_Font tkfont; /* Font in which text will be measured. */
CONST char *string; /* String whose width will be computed. */
- int numChars; /* Number of characters to consider from
+ int numBytes; /* Number of bytes to consider from
* string, or < 0 for strlen(). */
{
int width;
- if (numChars < 0) {
- numChars = strlen(string);
+ if (numBytes < 0) {
+ numBytes = strlen(string);
}
- Tk_MeasureChars(tkfont, string, numChars, -1, 0, &width);
+ Tk_MeasureChars(tkfont, string, numBytes, -1, 0, &width);
return width;
}
@@ -1721,8 +1722,8 @@ Tk_TextWidth(tkfont, string, numChars)
*/
void
-Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstChar,
- lastChar)
+Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstByte,
+ lastByte)
Display *display; /* Display on which to draw. */
Drawable drawable; /* Window or pixmap in which to draw. */
GC gc; /* Graphics context for actually drawing
@@ -1734,18 +1735,17 @@ Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstChar,
* underlined or overstruck. */
int x, y; /* Coordinates at which first character of
* string is drawn. */
- int firstChar; /* Index of first character. */
- int lastChar; /* Index of one after the last character. */
+ int firstByte; /* Index of first byte of first character. */
+ int lastByte; /* Index of first byte after the last
+ * character. */
{
TkFont *fontPtr;
int startX, endX;
fontPtr = (TkFont *) tkfont;
- Tk_MeasureChars(tkfont, string,
- (Tcl_UtfAtIndex(string, firstChar) - string), -1, 0, &startX);
- Tk_MeasureChars(tkfont, string,
- (Tcl_UtfAtIndex(string, lastChar) - string), -1, 0, &endX);
+ Tk_MeasureChars(tkfont, string, firstByte, -1, 0, &startX);
+ Tk_MeasureChars(tkfont, string, lastByte, -1, 0, &endX);
XFillRectangle(display, drawable, gc, x + startX,
y + fontPtr->underlinePos, (unsigned int) (endX - startX),
@@ -1806,7 +1806,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
{
TkFont *fontPtr;
CONST char *start, *end, *special;
- int n, y, charsThisChunk, maxChunks;
+ int n, y, bytesThisChunk, maxChunks;
int baseline, height, curX, newX, maxWidth;
TextLayout *layoutPtr;
LayoutChunk *chunkPtr;
@@ -1823,7 +1823,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
height = fmPtr->ascent + fmPtr->descent;
if (numChars < 0) {
- numChars = strlen(string);
+ numChars = Tcl_NumUtfChars(string, -1);
}
if (wrapLength == 0) {
wrapLength = -1;
@@ -1846,7 +1846,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
curX = 0;
- end = string + numChars;
+ end = Tcl_UtfAtIndex(string, numChars);
special = string;
flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
@@ -1855,6 +1855,11 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
if (start >= special) {
/*
* Find the next special character in the string.
+ *
+ * INTL: Note that it is safe to increment by byte, because we are
+ * looking for 7-bit characters that will appear unchanged in
+ * UTF-8. At some point we may need to support the full Unicode
+ * whitespace set.
*/
for (special = start; special < end; special++) {
@@ -1878,15 +1883,15 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
chunkPtr = NULL;
if (start < special) {
- charsThisChunk = Tk_MeasureChars(tkfont, start, special - start,
+ bytesThisChunk = Tk_MeasureChars(tkfont, start, special - start,
wrapLength - curX, flags, &newX);
newX += curX;
flags &= ~TK_AT_LEAST_ONE;
- if (charsThisChunk > 0) {
+ if (bytesThisChunk > 0) {
chunkPtr = NewChunk(&layoutPtr, &maxChunks, start,
- charsThisChunk, curX, newX, baseline);
+ bytesThisChunk, curX, newX, baseline);
- start += charsThisChunk;
+ start += bytesThisChunk;
curX = newX;
}
}
@@ -1894,6 +1899,9 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
if ((start == special) && (special < end)) {
/*
* Handle the special character.
+ *
+ * INTL: Special will be pointing at a 7-bit character so we
+ * can safely treat it as a single byte.
*/
chunkPtr = NULL;
@@ -1941,15 +1949,21 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
start++;
}
if (chunkPtr != NULL) {
+ CONST char *end;
+
/*
* Append all the extra spaces on this line to the end of the
- * last text chunk.
+ * last text chunk. This is a little tricky because we are
+ * switching back and forth between characters and bytes.
*/
- charsThisChunk = start - (chunkPtr->start + chunkPtr->numChars);
- if (charsThisChunk > 0) {
- chunkPtr->numChars += Tk_MeasureChars(tkfont,
- chunkPtr->start + chunkPtr->numChars, charsThisChunk,
+
+ end = chunkPtr->start + chunkPtr->numBytes;
+ bytesThisChunk = start - end;
+ if (bytesThisChunk > 0) {
+ bytesThisChunk = Tk_MeasureChars(tkfont, end, bytesThisChunk,
-1, 0, &chunkPtr->totalWidth);
+ chunkPtr->numBytes += bytesThisChunk;
+ chunkPtr->numChars += Tcl_NumUtfChars(end, bytesThisChunk);
chunkPtr->totalWidth += curX;
}
}
@@ -2006,6 +2020,7 @@ Tk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,
layoutPtr->numChunks = 1;
layoutPtr->chunks[0].start = string;
+ layoutPtr->chunks[0].numBytes = 0;
layoutPtr->chunks[0].numChars = 0;
layoutPtr->chunks[0].numDisplayChars = -1;
layoutPtr->chunks[0].x = 0;
@@ -2118,6 +2133,8 @@ Tk_DrawTextLayout(display, drawable, gc, layout, x, y, firstChar, lastChar)
{
TextLayout *layoutPtr;
int i, numDisplayChars, drawX;
+ CONST char *firstByte;
+ CONST char *lastByte;
LayoutChunk *chunkPtr;
layoutPtr = (TextLayout *) layout;
@@ -2135,15 +2152,18 @@ Tk_DrawTextLayout(display, drawable, gc, layout, x, y, firstChar, lastChar)
if (firstChar <= 0) {
drawX = 0;
firstChar = 0;
+ firstByte = chunkPtr->start;
} else {
- Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start, firstChar,
- -1, 0, &drawX);
+ firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
+ Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
+ firstByte - chunkPtr->start, -1, 0, &drawX);
}
if (lastChar < numDisplayChars) {
numDisplayChars = lastChar;
}
+ lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont,
- chunkPtr->start + firstChar, numDisplayChars - firstChar,
+ firstByte, lastByte - firstByte,
x + chunkPtr->x + drawX, y + chunkPtr->y);
}
firstChar -= chunkPtr->numChars;
@@ -2249,7 +2269,7 @@ Tk_PointToChar(layout, x, y)
TextLayout *layoutPtr;
LayoutChunk *chunkPtr, *lastPtr;
TkFont *fontPtr;
- int i, n, dummy, baseline, pos;
+ int i, n, dummy, baseline, pos, numChars;
if (y < 0) {
/*
@@ -2267,6 +2287,7 @@ Tk_PointToChar(layout, x, y)
layoutPtr = (TextLayout *) layout;
fontPtr = (TkFont *) layoutPtr->tkfont;
lastPtr = chunkPtr = layoutPtr->chunks;
+ numChars = 0;
for (i = 0; i < layoutPtr->numChunks; i++) {
baseline = chunkPtr->y;
if (y < baseline + fontPtr->fm.descent) {
@@ -2276,7 +2297,7 @@ Tk_PointToChar(layout, x, y)
* the index of the first character on this line.
*/
- return chunkPtr->start - layoutPtr->string;
+ return numChars;
}
if (x >= layoutPtr->width) {
/*
@@ -2307,13 +2328,14 @@ Tk_PointToChar(layout, x, y)
* tab or newline char.
*/
- return chunkPtr->start - layoutPtr->string;
+ return numChars;
}
n = Tk_MeasureChars((Tk_Font) fontPtr, chunkPtr->start,
- chunkPtr->numChars, x - chunkPtr->x,
+ chunkPtr->numBytes, x - chunkPtr->x,
0, &dummy);
- return (chunkPtr->start + n) - layoutPtr->string;
+ return numChars + Tcl_NumUtfChars(chunkPtr->start, n);
}
+ numChars += chunkPtr->numChars;
lastPtr = chunkPtr;
chunkPtr++;
i++;
@@ -2325,12 +2347,13 @@ Tk_PointToChar(layout, x, y)
* chunk on this line.
*/
- pos = (lastPtr->start + lastPtr->numChars) - layoutPtr->string;
+ pos = numChars;
if (i < layoutPtr->numChunks) {
pos--;
}
return pos;
}
+ numChars += chunkPtr->numChars;
lastPtr = chunkPtr;
chunkPtr++;
}
@@ -2397,6 +2420,7 @@ Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr)
int i, x, w;
Tk_Font tkfont;
TkFont *fontPtr;
+ CONST char *end;
if (index < 0) {
return 0;
@@ -2415,12 +2439,15 @@ Tk_CharBbox(layout, index, xPtr, yPtr, widthPtr, heightPtr)
goto check;
}
} else if (index < chunkPtr->numChars) {
+ end = Tcl_UtfAtIndex(chunkPtr->start, index);
if (xPtr != NULL) {
- Tk_MeasureChars(tkfont, chunkPtr->start, index, -1, 0, &x);
+ Tk_MeasureChars(tkfont, chunkPtr->start,
+ end - chunkPtr->start, -1, 0, &x);
x += chunkPtr->x;
}
if (widthPtr != NULL) {
- Tk_MeasureChars(tkfont, chunkPtr->start + index, 1, -1, 0, &w);
+ Tk_MeasureChars(tkfont, end, Tcl_UtfNext(end) - end,
+ -1, 0, &w);
}
goto check;
}
@@ -2694,6 +2721,8 @@ Tk_TextLayoutToPostscript(interp, layout)
char buf[MAXUSE+10];
LayoutChunk *chunkPtr;
int i, j, used, c, baseline;
+ Tcl_UniChar ch;
+ CONST char *p;
TextLayout *layoutPtr;
layoutPtr = (TextLayout *) layout;
@@ -2714,8 +2743,16 @@ Tk_TextLayoutToPostscript(interp, layout)
buf[used++] = 't';
}
} else {
+ p = chunkPtr->start;
for (j = 0; j < chunkPtr->numDisplayChars; j++) {
- c = UCHAR(chunkPtr->start[j]);
+ /*
+ * INTL: For now we just treat the characters as binary
+ * data and display the lower byte. Eventually this should
+ * be revised to handle international postscript fonts.
+ */
+
+ p += Tcl_UtfToUniChar(p, &ch);
+ c = UCHAR(ch & 0xff);
if ((c == '(') || (c == ')') || (c == '\\') || (c < 0x20)
|| (c >= UCHAR(0x7f))) {
/*
@@ -3120,18 +3157,18 @@ ParseFontNameObj(interp, tkwin, objPtr, faPtr)
*---------------------------------------------------------------------------
*/
static LayoutChunk *
-NewChunk(layoutPtrPtr, maxPtr, start, numChars, curX, newX, y)
+NewChunk(layoutPtrPtr, maxPtr, start, numBytes, curX, newX, y)
TextLayout **layoutPtrPtr;
int *maxPtr;
CONST char *start;
- int numChars;
+ int numBytes;
int curX;
int newX;
int y;
{
TextLayout *layoutPtr;
LayoutChunk *chunkPtr;
- int maxChunks;
+ int maxChunks, numChars;
size_t s;
layoutPtr = *layoutPtrPtr;
@@ -3144,8 +3181,10 @@ NewChunk(layoutPtrPtr, maxPtr, start, numChars, curX, newX, y)
*layoutPtrPtr = layoutPtr;
*maxPtr = maxChunks;
}
+ numChars = Tcl_NumUtfChars(start, numBytes);
chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks];
chunkPtr->start = start;
+ chunkPtr->numBytes = numBytes;
chunkPtr->numChars = numChars;
chunkPtr->numDisplayChars = numChars;
chunkPtr->x = curX;
diff --git a/generic/tkIntXlibDecls.h b/generic/tkIntXlibDecls.h
index bae250c..e1e616e 100644
--- a/generic/tkIntXlibDecls.h
+++ b/generic/tkIntXlibDecls.h
@@ -9,7 +9,7 @@
* Copyright (c) 1998-1999 by Scriptics Corporation.
* All rights reserved.
*
- * RCS: @(#) $Id: tkIntXlibDecls.h,v 1.2.2.3 1999/03/30 02:08:01 redman Exp $
+ * RCS: @(#) $Id: tkIntXlibDecls.h,v 1.2.2.4 1999/03/30 04:12:57 stanton Exp $
*/
#ifndef _TKINTXLIBDECLS
@@ -277,6 +277,11 @@ EXTERN void TkPutImage _ANSI_ARGS_((unsigned long * colors,
GC gc, XImage* image, int src_x, int src_y,
int dest_x, int dest_y, unsigned int width,
unsigned int height));
+/* Slot 81 is reserved */
+/* 82 */
+EXTERN Status XParseColor _ANSI_ARGS_((Display * display,
+ Colormap map, _Xconst char* spec,
+ XColor * colorPtr));
#endif /* __WIN32__ */
#ifdef MAC_TCL
/* Slot 0 is reserved */
@@ -457,6 +462,10 @@ EXTERN void TkPutImage _ANSI_ARGS_((unsigned long * colors,
GC gc, XImage* image, int src_x, int src_y,
int dest_x, int dest_y, unsigned int width,
unsigned int height));
+/* 58 */
+EXTERN Status XParseColor _ANSI_ARGS_((Display * display,
+ Colormap map, _Xconst char* spec,
+ XColor * colorPtr));
#endif /* MAC_TCL */
typedef struct TkIntXlibStubs {
@@ -545,6 +554,8 @@ typedef struct TkIntXlibStubs {
Bool (*xFilterEvent) _ANSI_ARGS_((XEvent* x, Window w)); /* 78 */
int (*xmbLookupString) _ANSI_ARGS_((XIC xi, XKeyPressedEvent* xk, char* c, int i, KeySym* k, Status* s)); /* 79 */
void (*tkPutImage) _ANSI_ARGS_((unsigned long * colors, int ncolors, Display* display, Drawable d, GC gc, XImage* image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height)); /* 80 */
+ void *reserved81;
+ Status (*xParseColor) _ANSI_ARGS_((Display * display, Colormap map, _Xconst char* spec, XColor * colorPtr)); /* 82 */
#endif /* __WIN32__ */
#ifdef MAC_TCL
void *reserved0;
@@ -605,6 +616,7 @@ typedef struct TkIntXlibStubs {
void (*xUngrabPointer) _ANSI_ARGS_((Display* d, Time t)); /* 55 */
void (*xUnmapWindow) _ANSI_ARGS_((Display* d, Window w)); /* 56 */
void (*tkPutImage) _ANSI_ARGS_((unsigned long * colors, int ncolors, Display* display, Drawable d, GC gc, XImage* image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height)); /* 57 */
+ Status (*xParseColor) _ANSI_ARGS_((Display * display, Colormap map, _Xconst char* spec, XColor * colorPtr)); /* 58 */
#endif /* MAC_TCL */
} TkIntXlibStubs;
@@ -938,6 +950,11 @@ extern TkIntXlibStubs *tkIntXlibStubsPtr;
#define TkPutImage \
(tkIntXlibStubsPtr->tkPutImage) /* 80 */
#endif
+/* Slot 81 is reserved */
+#ifndef XParseColor
+#define XParseColor \
+ (tkIntXlibStubsPtr->xParseColor) /* 82 */
+#endif
#endif /* __WIN32__ */
#ifdef MAC_TCL
/* Slot 0 is reserved */
@@ -1169,6 +1186,10 @@ extern TkIntXlibStubs *tkIntXlibStubsPtr;
#define TkPutImage \
(tkIntXlibStubsPtr->tkPutImage) /* 57 */
#endif
+#ifndef XParseColor
+#define XParseColor \
+ (tkIntXlibStubsPtr->xParseColor) /* 58 */
+#endif
#endif /* MAC_TCL */
#endif /* defined(USE_TK_STUBS) && !defined(USE_TK_STUB_PROCS) */
diff --git a/generic/tkListbox.c b/generic/tkListbox.c
index e799553..d67cb3f 100644
--- a/generic/tkListbox.c
+++ b/generic/tkListbox.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkListbox.c,v 1.1.4.2 1998/09/30 02:17:06 stanton Exp $
+ * RCS: @(#) $Id: tkListbox.c,v 1.1.4.3 1999/03/30 04:12:57 stanton Exp $
*/
#include "tkPort.h"
@@ -24,7 +24,7 @@
*/
typedef struct Element {
- int textLength; /* # non-NULL characters in text. */
+ int textLength; /* # non-NULL bytes in text string. */
int lBearing; /* Distance from first character's
* origin to left edge of character. */
int pixelWidth; /* Total width of element in pixels (including
diff --git a/generic/tkMessage.c b/generic/tkMessage.c
index 46e93b9..92dc087 100644
--- a/generic/tkMessage.c
+++ b/generic/tkMessage.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMessage.c,v 1.1.4.2 1998/09/30 02:17:11 stanton Exp $
+ * RCS: @(#) $Id: tkMessage.c,v 1.1.4.3 1999/03/30 04:12:58 stanton Exp $
*/
#include "tkPort.h"
@@ -40,7 +40,7 @@ typedef struct {
char *string; /* String displayed in message. */
int numChars; /* Number of characters in string, not
- * including terminating NULL character. */
+ * including terminating NULL. */
char *textVarName; /* Name of variable (malloc'ed) or NULL.
* If non-NULL, message displays the contents
* of this variable. */
@@ -465,7 +465,7 @@ ConfigureMessage(interp, msgPtr, argc, argv, flags)
* that couldn't be specified to Tk_ConfigureWidget.
*/
- msgPtr->numChars = strlen(msgPtr->string);
+ msgPtr->numChars = Tcl_NumUtfChars(msgPtr->string, -1);
Tk_SetBackgroundFromBorder(msgPtr->tkwin, msgPtr->border);
@@ -834,8 +834,8 @@ MessageTextVarProc(clientData, interp, name1, name2, flags)
if (msgPtr->string != NULL) {
ckfree(msgPtr->string);
}
- msgPtr->numChars = strlen(value);
- msgPtr->string = (char *) ckalloc((unsigned) (msgPtr->numChars + 1));
+ msgPtr->numChars = Tcl_NumUtfChars(value, -1);
+ msgPtr->string = (char *) ckalloc((unsigned) (strlen(value) + 1));
strcpy(msgPtr->string, value);
ComputeMessageGeometry(msgPtr);
diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c
index c833b75..5428263 100644
--- a/generic/tkStubInit.c
+++ b/generic/tkStubInit.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkStubInit.c,v 1.2.2.2 1999/03/12 03:12:47 stanton Exp $
+ * RCS: @(#) $Id: tkStubInit.c,v 1.2.2.3 1999/03/30 04:12:58 stanton Exp $
*/
#include "tkInt.h"
@@ -598,6 +598,8 @@ TkIntXlibStubs tkIntXlibStubs = {
XFilterEvent, /* 78 */
XmbLookupString, /* 79 */
TkPutImage, /* 80 */
+ NULL, /* 81 */
+ XParseColor, /* 82 */
#endif /* __WIN32__ */
#ifdef MAC_TCL
NULL, /* 0 */
@@ -658,6 +660,7 @@ TkIntXlibStubs tkIntXlibStubs = {
XUngrabPointer, /* 55 */
XUnmapWindow, /* 56 */
TkPutImage, /* 57 */
+ XParseColor, /* 58 */
#endif /* MAC_TCL */
};
diff --git a/mac/tkMacFont.c b/mac/tkMacFont.c
index 4cd088b..0c47abb 100644
--- a/mac/tkMacFont.c
+++ b/mac/tkMacFont.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacFont.c,v 1.1.4.2 1998/09/30 02:18:07 stanton Exp $
+ * RCS: @(#) $Id: tkMacFont.c,v 1.1.4.3 1999/03/30 04:12:58 stanton Exp $
*/
#include <Windows.h>
@@ -653,7 +653,7 @@ TkpGetSubFonts(interp, tkfont)
* the characters.
*
* Results:
- * The return value is the number of characters from source that
+ * The return value is the number of bytes from source that
* fit into the span that extends from 0 to maxLength. *lengthPtr is
* filled with the x-coordinate of the right edge of the last
* character that did fit.
diff --git a/unix/tkUnixButton.c b/unix/tkUnixButton.c
index 25228d2..bd1d7f1 100644
--- a/unix/tkUnixButton.c
+++ b/unix/tkUnixButton.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixButton.c,v 1.1.4.2 1998/09/30 02:19:14 stanton Exp $
+ * RCS: @(#) $Id: tkUnixButton.c,v 1.1.4.3 1999/03/30 04:12:59 stanton Exp $
*/
#include "tkButton.h"
@@ -395,12 +395,8 @@ TkpComputeButtonGeometry(butPtr)
register TkButton *butPtr; /* Button whose geometry may have changed. */
{
int width, height, avgWidth;
- int length;
- char *text;
Tk_FontMetrics fm;
- text = Tcl_GetStringFromObj(butPtr->textPtr, &length);
-
butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth;
/*
@@ -433,9 +429,10 @@ TkpComputeButtonGeometry(butPtr)
goto imageOrBitmap;
} else {
Tk_FreeTextLayout(butPtr->textLayout);
+
butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
- text, length, butPtr->wrapLength, butPtr->justify, 0,
- &butPtr->textWidth, &butPtr->textHeight);
+ Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength,
+ butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);
width = butPtr->textWidth;
height = butPtr->textHeight;
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c
index 6c4afdf..c4844c6 100644
--- a/unix/tkUnixFont.c
+++ b/unix/tkUnixFont.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixFont.c,v 1.1.4.6 1998/12/13 08:14:39 lfb Exp $
+ * RCS: @(#) $Id: tkUnixFont.c,v 1.1.4.7 1999/03/30 04:12:59 stanton Exp $
*/
#include "tkUnixInt.h"
@@ -679,7 +679,7 @@ TkpGetSubFonts(interp, tkfont)
* the characters.
*
* Results:
- * The return value is the number of characters from source that
+ * The return value is the number of bytes from source that
* fit into the span that extends from 0 to maxLength. *lengthPtr is
* filled with the x-coordinate of the right edge of the last
* character that did fit.
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index 4ab1221..adbfb52 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixMenu.c,v 1.1.4.6 1999/03/09 01:36:07 lfb Exp $
+ * RCS: @(#) $Id: tkUnixMenu.c,v 1.1.4.7 1999/03/30 04:13:00 stanton Exp $
*/
#include "tkPort.h"
@@ -803,6 +803,8 @@ DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
int activeBorderWidth;
int leftEdge;
char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+ char *start = Tcl_UtfAtIndex(label, mePtr->underline);
+ char *end = Tcl_UtfNext(start);
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
menuPtr->activeBorderWidthPtr, &activeBorderWidth);
@@ -810,10 +812,10 @@ DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)
if (menuPtr->menuType == MENUBAR) {
leftEdge += 5;
}
-
+
Tk_UnderlineChars(menuPtr->display, d, gc, tkfont, label,
leftEdge, y + (height + fmPtr->ascent - fmPtr->descent) / 2,
- mePtr->underline, mePtr->underline + 1);
+ start - label, end - label);
}
}
@@ -903,7 +905,7 @@ GetTearoffEntryGeometry(menuPtr, mePtr, tkfont, fmPtr, widthPtr, heightPtr)
*widthPtr = 0;
} else {
*heightPtr = fmPtr->linespace;
- *widthPtr = Tk_TextWidth(tkfont, "W", -1);
+ *widthPtr = Tk_TextWidth(tkfont, "W", 1);
}
}
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index 2194689..e404ae8 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinFont.c,v 1.1.4.4 1999/02/11 04:13:50 stanton Exp $
+ * RCS: @(#) $Id: tkWinFont.c,v 1.1.4.5 1999/03/30 04:13:00 stanton Exp $
*/
#include "tkWinInt.h"
@@ -567,13 +567,13 @@ TkpGetSubFonts(
*
* Tk_MeasureChars --
*
- * Determine the number of characters from the string that will fit
+ * Determine the number of bytes from the string that will fit
* in the given horizontal span. The measurement is done under the
* assumption that Tk_DrawChars() will be used to actually display
* the characters.
*
* Results:
- * The return value is the number of characters from source that
+ * The return value is the number of bytes from source that
* fit into the span that extends from 0 to maxLength. *lengthPtr is
* filled with the x-coordinate of the right edge of the last
* character that did fit.
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index 8b61ad4..8474e9f 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinMenu.c,v 1.1.4.10 1999/03/09 01:36:06 lfb Exp $
+ * RCS: @(#) $Id: tkWinMenu.c,v 1.1.4.11 1999/03/30 04:13:01 stanton Exp $
*/
#define OEMRESOURCE
@@ -1733,11 +1733,13 @@ DrawMenuUnderline(
{
if (mePtr->underline >= 0) {
char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+ char *start = Tcl_UtfAtIndex(label, mePtr->underline);
+ char *end = Tcl_UtfNext(start);
Tk_UnderlineChars(menuPtr->display, d,
gc, tkfont, label, x + mePtr->indicatorSpace,
y + (height + fmPtr->ascent - fmPtr->descent) / 2,
- mePtr->underline, mePtr->underline + 1);
+ start - label, end - label);
}
}