summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2020-05-30 14:35:52 (GMT)
committerculler <culler>2020-05-30 14:35:52 (GMT)
commitf5badcc4c99f99da82da6b138e7afb70f492305d (patch)
tree0ecea9e34f94573adbb451ace3b802c30ea32058
parent3315ad85a29eee53ac2c7b8b9845f148ff99edaf (diff)
parent9ba4c746ec344f1455e03c2f97ca0ae7c95d139f (diff)
downloadtk-f5badcc4c99f99da82da6b138e7afb70f492305d.zip
tk-f5badcc4c99f99da82da6b138e7afb70f492305d.tar.gz
tk-f5badcc4c99f99da82da6b138e7afb70f492305d.tar.bz2
Merge 8.6
-rw-r--r--.travis.yml30
-rw-r--r--doc/text.n7
-rw-r--r--generic/tkCanvText.c10
-rw-r--r--generic/tkEntry.c12
-rw-r--r--generic/tkFont.c22
-rw-r--r--generic/tkInt.decls9
-rw-r--r--generic/tkInt.h4
-rw-r--r--generic/tkIntDecls.h36
-rw-r--r--generic/tkSelect.c4
-rw-r--r--generic/tkStubInit.c20
-rw-r--r--generic/tkTextDisp.c36
-rw-r--r--generic/tkTextIndex.c6
-rw-r--r--generic/tkUtil.c67
-rw-r--r--generic/ttk/ttkEntry.c18
-rw-r--r--macosx/tkMacOSXBitmap.c1
-rw-r--r--macosx/tkMacOSXFont.c33
-rw-r--r--macosx/tkMacOSXInt.h2
-rw-r--r--macosx/tkMacOSXPrivate.h2
-rw-r--r--macosx/tkMacOSXSubwindows.c8
-rw-r--r--macosx/tkMacOSXWindowEvent.c35
-rw-r--r--macosx/tkMacOSXWm.c34
-rw-r--r--unix/tkUnixMenu.c6
-rw-r--r--unix/tkUnixPort.h2
-rw-r--r--win/tkWinMenu.c10
-rw-r--r--win/tkWinPort.h7
-rw-r--r--win/ttkWinXPTheme.c2
26 files changed, 287 insertions, 136 deletions
diff --git a/.travis.yml b/.travis.yml
index 2e9ec93..a3bc25d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -114,49 +114,49 @@ matrix:
- BUILD_DIR=unix
- CFGOPT="--enable-symbols"
# Testing on Mac, various styles
- - name: "macOS/Xcode 11.4/Shared"
+ - name: "macOS/Xcode 11.5/Shared"
os: osx
- osx_image: xcode11.4
+ osx_image: xcode11.5
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
- - name: "macOS/Xcode 11.4/Static"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - name: "macOS/Xcode 11.5/Static"
os: osx
- osx_image: xcode11.4
+ osx_image: xcode11.5
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua --disable-shared CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
- - name: "macOS/Xcode 11.4/Debug"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua --disable-shared CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - name: "macOS/Xcode 11.5/Debug"
os: osx
- osx_image: xcode11.4
+ osx_image: xcode11.5
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua --enable-symbols CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
- - name: "macOS/Xcode 11.4/Shared/XQuartz"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua --enable-symbols CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - name: "macOS/Xcode 11.5/Shared/XQuartz"
os: osx
- osx_image: xcode11.4
+ osx_image: xcode11.5
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --disable-corefoundation --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --disable-corefoundation --x-includes=/opt/X11/include --x-libraries=/opt/X11/lib CFLAGS=-I/usr/local/opt/tcl-tk/include"
# Older MacOS versions
- name: "macOS/Xcode 11/Shared"
os: osx
osx_image: xcode11
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include"
- name: "macOS/Xcode 10/Shared"
os: osx
osx_image: xcode10.3
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include"
- name: "macOS/Xcode 9/Shared"
os: osx
osx_image: xcode9.4
env:
- BUILD_DIR=unix
- - CFGOPT="--prefix=/usr/local/opt/tcl-tk --with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CC=clang CFLAGS=-I/usr/local/opt/tcl-tk/include"
+ - CFGOPT="--with-tcl=/usr/local/opt/tcl-tk/lib --enable-aqua CFLAGS=-I/usr/local/opt/tcl-tk/include"
# Test on Windows with MSVC native
# - name: "Windows/MSVC/Shared"
# os: windows
diff --git a/doc/text.n b/doc/text.n
index 90834df..f08ed9e 100644
--- a/doc/text.n
+++ b/doc/text.n
@@ -2025,10 +2025,11 @@ integer. This command used to be used for scrolling, but now it is obsolete.
.SH BINDINGS
.PP
Tk automatically creates class bindings for texts that give them the following
-default behavior. In the descriptions below,
+default behavior.
+In the descriptions below,
.QW word
-is dependent on the value of the \fBtcl_wordchars\fR variable. See
-\fBtclvars\fR(n).
+is dependent on the value of
+the \fBtcl_wordchars\fR variable. See \fBtclvars\fR(n).
.IP [1]
Clicking mouse button 1 positions the insertion cursor just before the
character underneath the mouse cursor, sets the input focus to this widget,
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index 1e58ce9..9a27efc 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -1025,7 +1025,7 @@ TextInsert(
if (index > textPtr->numChars) {
index = textPtr->numChars;
}
- byteIndex = Tcl_UtfAtIndex(text, index) - text;
+ byteIndex = TkUtfAtIndex(text, index) - text;
byteCount = strlen(string);
if (byteCount == 0) {
return;
@@ -1108,8 +1108,8 @@ TextDeleteChars(
}
charsRemoved = last + 1 - first;
- byteIndex = Tcl_UtfAtIndex(text, first) - text;
- byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved)
+ byteIndex = TkUtfAtIndex(text, first) - text;
+ byteCount = TkUtfAtIndex(text + byteIndex, charsRemoved)
- (text + byteIndex);
newStr = ckalloc(textPtr->numBytes + 1 - byteCount);
@@ -1497,8 +1497,8 @@ GetSelText(
return 0;
}
text = textPtr->text;
- selStart = Tcl_UtfAtIndex(text, textInfoPtr->selectFirst);
- selEnd = Tcl_UtfAtIndex(selStart,
+ selStart = TkUtfAtIndex(text, textInfoPtr->selectFirst);
+ selEnd = TkUtfAtIndex(selStart,
textInfoPtr->selectLast + 1 - textInfoPtr->selectFirst);
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index 9c53769..fc5ba63 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -2049,7 +2049,7 @@ InsertChars(
char *newStr;
string = entryPtr->string;
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
+ byteIndex = TkUtfAtIndex(string, index) - string;
byteCount = strlen(value);
if (byteCount == 0) {
return TCL_OK;
@@ -2073,6 +2073,8 @@ InsertChars(
entryPtr->string = newStr;
/*
+ * ??? Is this construction still needed with Tcl_NumUtfChars ???
+ *
* The following construction is used because inserting improperly formed
* UTF-8 sequences between other improperly formed UTF-8 sequences could
* result in actually forming valid UTF-8 sequences; the number of
@@ -2153,8 +2155,8 @@ DeleteChars(
}
string = entryPtr->string;
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
- byteCount = Tcl_UtfAtIndex(string + byteIndex, count) - (string+byteIndex);
+ byteIndex = TkUtfAtIndex(string, index) - string;
+ byteCount = TkUtfAtIndex(string + byteIndex, count) - (string+byteIndex);
newByteCount = entryPtr->numBytes + 1 - byteCount;
newStr = ckalloc(newByteCount);
@@ -2815,8 +2817,8 @@ EntryFetchSelection(
return -1;
}
string = entryPtr->displayString;
- selStart = Tcl_UtfAtIndex(string, entryPtr->selectFirst);
- selEnd = Tcl_UtfAtIndex(selStart,
+ selStart = TkUtfAtIndex(string, entryPtr->selectFirst);
+ selEnd = TkUtfAtIndex(selStart,
entryPtr->selectLast - entryPtr->selectFirst);
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
diff --git a/generic/tkFont.c b/generic/tkFont.c
index bf35626..448f918 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -13,9 +13,7 @@
#include "tkInt.h"
#include "tkFont.h"
-#if defined(MAC_OSX_TK)
-#include "tkMacOSXInt.h"
-#endif
+
/*
* The following structure is used to keep track of all the fonts that exist
* in the current application. It must be stored in the TkMainInfo for the
@@ -874,18 +872,18 @@ TheWorldHasChanged(
ClientData clientData) /* Info about application's fonts. */
{
TkFontInfo *fiPtr = clientData;
-#if defined(MAC_OSX_TK)
/*
* On macOS it is catastrophic to recompute all widgets while the
* [NSView drawRect] method is drawing. The best that we can do in
* that situation is to abort the recomputation and hope for the best.
+ * This is ignored on other platforms.
*/
- if (TkpAppIsDrawing()) {
+ if (TkpAppCanDraw(NULL)) {
return;
}
-#endif
+
fiPtr->updatePending = 0;
RecomputeWidgets(fiPtr->mainPtr->winPtr);
}
@@ -2021,7 +2019,7 @@ Tk_ComputeTextLayout(
curX = 0;
- end = Tcl_UtfAtIndex(string, numChars);
+ end = TkUtfAtIndex(string, numChars);
special = string;
flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
@@ -2325,14 +2323,14 @@ Tk_DrawTextLayout(
firstChar = 0;
firstByte = chunkPtr->start;
} else {
- firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
+ firstByte = TkUtfAtIndex(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);
+ lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars);
Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont, firstByte,
lastByte - firstByte, x+chunkPtr->x+drawX, y+chunkPtr->y);
}
@@ -2387,14 +2385,14 @@ TkDrawAngledTextLayout(
firstChar = 0;
firstByte = chunkPtr->start;
} else {
- firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
+ firstByte = TkUtfAtIndex(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);
+ lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars);
dx = cosA * (chunkPtr->x + drawX) + sinA * (chunkPtr->y);
dy = -sinA * (chunkPtr->x + drawX) + cosA * (chunkPtr->y);
if (angle == 0.0) {
@@ -2736,7 +2734,7 @@ Tk_CharBbox(
goto check;
}
} else if (index < chunkPtr->numChars) {
- end = Tcl_UtfAtIndex(chunkPtr->start, index);
+ end = TkUtfAtIndex(chunkPtr->start, index);
if (xPtr != NULL) {
Tk_MeasureChars(tkfont, chunkPtr->start,
end - chunkPtr->start, -1, 0, &x);
diff --git a/generic/tkInt.decls b/generic/tkInt.decls
index bb2057b..da591cb 100644
--- a/generic/tkInt.decls
+++ b/generic/tkInt.decls
@@ -634,6 +634,15 @@ declare 184 {
Tk_Font tkfont, const char *source, int numBytes, double x,
double y, double angle)
}
+
+# Support for aqua's inability to draw outside [NSView drawRect:]
+declare 185 aqua {
+ void TkpRedrawWidget(Tk_Window tkwin)
+}
+declare 186 aqua {
+ int TkpAppCanDraw(Tk_Window tkwin)
+}
+
##############################################################################
diff --git a/generic/tkInt.h b/generic/tkInt.h
index d87cd03..3a8328f 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -1290,9 +1290,13 @@ MODULE_SCOPE void TkUnixSetXftClipRegion(TkRegion clipRegion);
#if TCL_UTF_MAX > 4
# define TkUtfToUniChar Tcl_UtfToUniChar
# define TkUniCharToUtf Tcl_UniCharToUtf
+# define TkUtfPrev Tcl_UtfPrev
+# define TkUtfAtIndex Tcl_UtfAtIndex
#else
MODULE_SCOPE int TkUtfToUniChar(const char *, int *);
MODULE_SCOPE int TkUniCharToUtf(int, char *);
+ MODULE_SCOPE const char *TkUtfPrev(const char *, const char *);
+ MODULE_SCOPE const char *TkUtfAtIndex(const char *src, int index);
#endif
/*
diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h
index fa1833e..7bf9bd7 100644
--- a/generic/tkIntDecls.h
+++ b/generic/tkIntDecls.h
@@ -550,6 +550,14 @@ EXTERN void TkDrawAngledChars(Display *display,
Drawable drawable, GC gc, Tk_Font tkfont,
const char *source, int numBytes, double x,
double y, double angle);
+#ifdef MAC_OSX_TK /* AQUA */
+/* 185 */
+EXTERN void TkpRedrawWidget(Tk_Window tkwin);
+#endif /* AQUA */
+#ifdef MAC_OSX_TK /* AQUA */
+/* 186 */
+EXTERN int TkpAppCanDraw(Tk_Window tkwin);
+#endif /* AQUA */
typedef struct TkIntStubs {
int magic;
@@ -767,6 +775,26 @@ typedef struct TkIntStubs {
void (*tkUnderlineAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, int underline); /* 182 */
int (*tkIntersectAngledTextLayout) (Tk_TextLayout layout, int x, int y, int width, int height, double angle); /* 183 */
void (*tkDrawAngledChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle); /* 184 */
+#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
+ void (*reserved185)(void);
+#endif /* X11 */
+#if defined(_WIN32) /* WIN */
+ void (*reserved185)(void);
+#endif /* WIN */
+#ifdef MAC_OSX_TK /* AQUA */
+ void (*reserved185)(void); /* Dummy entry for stubs table backwards compatibility */
+ void (*tkpRedrawWidget) (Tk_Window tkwin); /* 185 */
+#endif /* AQUA */
+#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
+ void (*reserved186)(void);
+#endif /* X11 */
+#if defined(_WIN32) /* WIN */
+ void (*reserved186)(void);
+#endif /* WIN */
+#ifdef MAC_OSX_TK /* AQUA */
+ void (*reserved186)(void); /* Dummy entry for stubs table backwards compatibility */
+ int (*tkpAppCanDraw) (Tk_Window tkwin); /* 186 */
+#endif /* AQUA */
} TkIntStubs;
extern const TkIntStubs *tkIntStubsPtr;
@@ -1139,6 +1167,14 @@ extern const TkIntStubs *tkIntStubsPtr;
(tkIntStubsPtr->tkIntersectAngledTextLayout) /* 183 */
#define TkDrawAngledChars \
(tkIntStubsPtr->tkDrawAngledChars) /* 184 */
+#ifdef MAC_OSX_TK /* AQUA */
+#define TkpRedrawWidget \
+ (tkIntStubsPtr->tkpRedrawWidget) /* 185 */
+#endif /* AQUA */
+#ifdef MAC_OSX_TK /* AQUA */
+#define TkpAppCanDraw \
+ (tkIntStubsPtr->tkpAppCanDraw) /* 186 */
+#endif /* AQUA */
#endif /* defined(USE_TK_STUBS) */
diff --git a/generic/tkSelect.c b/generic/tkSelect.c
index 5c71465..ef16ff5 100644
--- a/generic/tkSelect.c
+++ b/generic/tkSelect.c
@@ -1400,12 +1400,12 @@ HandleTclCommand(
cmdInfoPtr->charOffset += Tcl_NumUtfChars(string, -1);
cmdInfoPtr->buffer[0] = '\0';
} else {
- Tcl_UniChar ch = 0;
+ int ch;
p = string;
string += count;
numChars = 0;
while (p < string) {
- p += Tcl_UtfToUniChar(p, &ch);
+ p += TkUtfToUniChar(p, &ch);
numChars++;
}
cmdInfoPtr->charOffset += numChars;
diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c
index 61c698a..045c86e 100644
--- a/generic/tkStubInit.c
+++ b/generic/tkStubInit.c
@@ -485,6 +485,26 @@ static const TkIntStubs tkIntStubs = {
TkUnderlineAngledTextLayout, /* 182 */
TkIntersectAngledTextLayout, /* 183 */
TkDrawAngledChars, /* 184 */
+#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
+ 0, /* 185 */
+#endif /* X11 */
+#if defined(_WIN32) /* WIN */
+ 0, /* 185 */
+#endif /* WIN */
+#ifdef MAC_OSX_TK /* AQUA */
+ 0, /* 185 */ /* Dummy entry for stubs table backwards compatibility */
+ TkpRedrawWidget, /* 185 */
+#endif /* AQUA */
+#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */
+ 0, /* 186 */
+#endif /* X11 */
+#if defined(_WIN32) /* WIN */
+ 0, /* 186 */
+#endif /* WIN */
+#ifdef MAC_OSX_TK /* AQUA */
+ 0, /* 186 */ /* Dummy entry for stubs table backwards compatibility */
+ TkpAppCanDraw, /* 186 */
+#endif /* AQUA */
};
static const TkIntPlatStubs tkIntPlatStubs = {
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index c848fd2..084fd64 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -20,15 +20,13 @@
#include "tkWinInt.h"
#elif defined(__CYGWIN__)
#include "tkUnixInt.h"
+#elif defined(MAC_OSX_TK)
+#include "tkMacOSXInt.h"
+#define OK_TO_LOG (!TkpAppCanDraw(textPtr->tkwin))
#endif
-#ifdef MAC_OSX_TK
-#include "tkMacOSXInt.h"
-#define OK_TO_LOG (!TkpAppIsDrawing())
-#define FORCE_DISPLAY(winPtr) TkpDisplayWindow(winPtr)
-#else
+#if !defined(MAC_OSX_TK)
#define OK_TO_LOG 1
-#define FORCE_DISPLAY(winPtr)
#endif
/*
@@ -3157,7 +3155,7 @@ GenerateWidgetViewSyncEvent(
*/
if (!tkTextDebug) {
- FORCE_DISPLAY(textPtr->tkwin);
+ TkpRedrawWidget(textPtr->tkwin);
}
if (NewSyncState != OldSyncState) {
@@ -4176,11 +4174,23 @@ DisplayText(
* warnings. */
Tcl_Interp *interp;
+
+ if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
+ /*
+ * The widget has been deleted. Don't do anything.
+ */
+
+ return;
+ }
+
#ifdef MAC_OSX_TK
/*
- * If drawing is disabled, all we need to do is
- * clear the REDRAW_PENDING flag.
+ * 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)){
@@ -4189,14 +4199,6 @@ DisplayText(
}
#endif
- if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) {
- /*
- * The widget has been deleted. Don't do anything.
- */
-
- return;
- }
-
interp = textPtr->interp;
Tcl_Preserve(interp);
diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c
index 056902a..8f30b7d 100644
--- a/generic/tkTextIndex.c
+++ b/generic/tkTextIndex.c
@@ -436,7 +436,7 @@ TkTextMakeByteIndex(
*/
start = segPtr->body.chars + (byteIndex - index);
- p = Tcl_UtfPrev(start, segPtr->body.chars);
+ p = TkUtfPrev(start, segPtr->body.chars);
p += TkUtfToUniChar(p, &ch);
indexPtr->byteIndex += p - start;
}
@@ -2125,7 +2125,7 @@ TkTextIndexBackChars(
if (segPtr->typePtr == &tkTextCharType) {
start = segPtr->body.chars;
end = segPtr->body.chars + segSize;
- for (p = end; ; p = Tcl_UtfPrev(p, start)) {
+ for (p = end; ; p = TkUtfPrev(p, start)) {
if (charCount == 0) {
dstPtr->byteIndex -= (end - p);
goto backwardCharDone;
@@ -2366,7 +2366,7 @@ StartEnd(
}
if (offset > 0) {
chSize = (segPtr->body.chars + offset
- - Tcl_UtfPrev(segPtr->body.chars + offset,
+ - TkUtfPrev(segPtr->body.chars + offset,
segPtr->body.chars));
}
firstChar = 0;
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index 7a15410..17ba443 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -1264,9 +1264,76 @@ int TkUniCharToUtf(int ch, char *buf)
}
return Tcl_UniCharToUtf(ch, buf);
}
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TkUtfPrev --
+ *
+ * Almost the same as Tcl_UtfPrev.
+ * This function is capable of jumping over a upper/lower surrogate pair.
+ * So, might jump back up to 6 bytes.
+ *
+ * Results:
+ * pointer to the first byte of the current UTF-8 character. A surrogate
+ * pair is also handled as being a single entity.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+const char *
+TkUtfPrev(
+ const char *src, /* The UTF-8 string. */
+ const char *start) /* Start position of string */
+{
+ const char *p = Tcl_UtfPrev(src, start);
+ const char *first = Tcl_UtfPrev(p, start);
+ int ch;
+
+#if TCL_UTF_MAX == 3
+ if ((src - start > 3) && ((src[-1] & 0xC0) == 0x80) && ((src[-2] & 0xC0) == 0x80)
+ && ((src[-3] & 0xC0) == 0x80) && (UCHAR(src[-4]) >= 0xF0)) {
+ return src - 4;
+ }
+#endif
+ return (first + TkUtfToUniChar(first, &ch) >= src) ? first : p ;
+}
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TkUtfAtIndex --
+ *
+ * Returns a pointer to the specified character (not byte) position in
+ * a CESU-8 string. This will never point at a low surrogate.
+ *
+ * Results:
+ * As above.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+const char *
+TkUtfAtIndex(
+ const char *src, /* The UTF-8 string. */
+ int index) /* The position of the desired character. */
+{
+ int ch;
+ const char *p = Tcl_UtfAtIndex(src, index);
+ if ((p > src) && (UCHAR(p[-1]) >= 0xF0)) {
+ --p;
+ return p + TkUtfToUniChar(p, &ch);
+ }
+ return p;
+}
#endif
+
/*
* Local Variables:
* mode: c
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index 96f3cf2..29f69a1 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -339,8 +339,8 @@ EntryFetchSelection(
}
string = entryPtr->entry.displayString;
- selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst);
- selEnd = Tcl_UtfAtIndex(selStart,
+ selStart = TkUtfAtIndex(string, entryPtr->entry.selectFirst);
+ selEnd = TkUtfAtIndex(selStart,
entryPtr->entry.selectLast - entryPtr->entry.selectFirst);
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
@@ -458,11 +458,11 @@ ExpandPercents(
break;
case 'S': /* string to be inserted/deleted, if any */
if (reason == VALIDATE_INSERT) {
- string = Tcl_UtfAtIndex(new, index);
- stringLength = Tcl_UtfAtIndex(string, count) - string;
+ string = TkUtfAtIndex(new, index);
+ stringLength = TkUtfAtIndex(string, count) - string;
} else if (reason == VALIDATE_DELETE) {
- string = Tcl_UtfAtIndex(entryPtr->entry.string, index);
- stringLength = Tcl_UtfAtIndex(string, count) - string;
+ string = TkUtfAtIndex(entryPtr->entry.string, index);
+ stringLength = TkUtfAtIndex(string, count) - string;
} else {
string = "";
stringLength = 0;
@@ -812,7 +812,7 @@ InsertChars(
const char *value) /* New characters to add */
{
char *string = entryPtr->entry.string;
- size_t byteIndex = Tcl_UtfAtIndex(string, index) - string;
+ size_t byteIndex = TkUtfAtIndex(string, index) - string;
size_t byteCount = strlen(value);
int charsAdded = Tcl_NumUtfChars(value, byteCount);
size_t newByteCount = entryPtr->entry.numBytes + byteCount + 1;
@@ -866,8 +866,8 @@ DeleteChars(
return TCL_OK;
}
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
- byteCount = Tcl_UtfAtIndex(string+byteIndex, count) - (string+byteIndex);
+ byteIndex = TkUtfAtIndex(string, index) - string;
+ byteCount = TkUtfAtIndex(string+byteIndex, count) - (string+byteIndex);
newByteCount = entryPtr->entry.numBytes + 1 - byteCount;
new = ckalloc(newByteCount);
diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c
index 615192b..2b08235 100644
--- a/macosx/tkMacOSXBitmap.c
+++ b/macosx/tkMacOSXBitmap.c
@@ -317,7 +317,6 @@ TkpGetNativeAppBitmap(
OSType iconType;
if (OSTypeFromString(name, &iconType) == TCL_OK) {
NSString *iconUTI = OSTYPE_TO_UTI(iconType);
- printf("Found image for UTI %s\n", iconUTI.UTF8String);
NSImage *iconImage = [[NSWorkspace sharedWorkspace]
iconForFileType: iconUTI];
pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 7fc0113..13a5de0 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -105,7 +105,7 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
* To avoid an extra copy, a TKNSString object wraps a Tcl_DString with an
* NSString that uses the DString's buffer as its character buffer. It can be
* constructed from a Tcl_DString and it has a DString property that handles
- * converting from an NSString to a Tcl_DString
+ * converting from an NSString to a Tcl_DString.
*/
@implementation TKNSString
@@ -133,7 +133,6 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
_string = [[NSString alloc] initWithString:aString];
self.UTF8String = _string.UTF8String;
}
- printf("Initialized with string %s\n", self.UTF8String);
return self;
}
@@ -166,32 +165,16 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
* The DString has not been initialized. Construct it from
* our string's unicode characters.
*/
-
- char buffer[2*TCL_UTF_MAX];
- unsigned int index, length, ch;
+ char *p;
+ unsigned int index;
Tcl_DStringInit(&_ds);
-#if TCL_UTF_MAX == 3
- for (index = 0; index < [_string length]; index++) {
- UniChar uni = [_string characterAtIndex: index];
-
- if (CFStringIsSurrogateHighCharacter(uni)) {
- UniChar low = [_string characterAtIndex: ++index];
- ch = CFStringGetLongCharacterForSurrogatePair(uni, low);
- } else {
- ch = uni;
- }
- length = TkUniCharToUtf(ch, buffer);
- Tcl_DStringAppend(&_ds, buffer, length);
- }
-#else
+ Tcl_DStringSetLength(&_ds, 3 * [_string length]);
+ p = Tcl_DStringValue(&_ds);
for (index = 0; index < [_string length]; index++) {
- ch = (int) [_string characterAtIndex: index];
- length = Tcl_UniCharToUtf(ch, buffer);
- Tcl_DStringAppend(&_ds, buffer, length);
+ p += Tcl_UniCharToUtf([_string characterAtIndex: index], p);
}
-
-#endif
+ Tcl_DStringSetLength(&_ds, p - Tcl_DStringValue(&_ds));
}
return _ds;
}
@@ -1056,7 +1039,7 @@ TkpMeasureCharsInContext(
[attributedString release];
[string release];
length = ceil(width - offset);
- fit = (Tcl_UtfAtIndex(source, index) - source) - rangeStart;
+ fit = (TkUtfAtIndex(source, index) - source) - rangeStart;
done:
#ifdef TK_MAC_DEBUG_FONTS
TkMacOSXDbgMsg("measure: source=\"%s\" range=\"%.*s\" maxLength=%d "
diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h
index 9cb75d2..58761d5 100644
--- a/macosx/tkMacOSXInt.h
+++ b/macosx/tkMacOSXInt.h
@@ -200,8 +200,6 @@ MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x,
MODULE_SCOPE void TkpRetainRegion(TkRegion r);
MODULE_SCOPE void TkpReleaseRegion(TkRegion r);
MODULE_SCOPE void TkpShiftButton(NSButton *button, NSPoint delta);
-MODULE_SCOPE Bool TkpAppIsDrawing(void);
-MODULE_SCOPE void TkpDisplayWindow(Tk_Window tkwin);
MODULE_SCOPE Bool TkTestLogDisplay(void);
MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin);
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index a0645f7..be69fcd 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -527,7 +527,7 @@ VISIBILITY_HIDDEN
* byte sequence as initial data. So we add a new class which does provide
* such a constructor. It also has a DString property which is a DString whose
* string pointer is a byte sequence encoding the NSString with the current Tk
- * encoding, namely UTF-8 if TCL_MAX >= 4 or CESU-8 if TCL_MAX = 3.
+ * encoding, namely UTF-8 if TCL_UTF_MAX >= 4 or CESU-8 if TCL_UTF_MAX = 3.
*
*---------------------------------------------------------------------------
*/
diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c
index 5063fa3..6602564 100644
--- a/macosx/tkMacOSXSubwindows.c
+++ b/macosx/tkMacOSXSubwindows.c
@@ -698,16 +698,10 @@ XConfigureWindow(
if (value_mask & CWStackMode) {
NSView *view = TkMacOSXDrawableView(macWin);
- Rect bounds;
- NSRect r;
if (view) {
TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr);
- TkMacOSXWinBounds(winPtr, &bounds);
- r = NSMakeRect(bounds.left,
- [view bounds].size.height - bounds.bottom,
- bounds.right - bounds.left, bounds.bottom - bounds.top);
- [view setNeedsDisplayInRect:r];
+ TkpRedrawWidget((Tk_Window) winPtr);
}
}
diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c
index cb4ffd1..76b2b04 100644
--- a/macosx/tkMacOSXWindowEvent.c
+++ b/macosx/tkMacOSXWindowEvent.c
@@ -382,26 +382,41 @@ extern NSString *NSWindowDidOrderOffScreenNotification;
/*
*----------------------------------------------------------------------
*
- * TkpAppIsDrawing --
+ * TkpAppCanDraw --
*
* A widget display procedure can call this to determine whether it is
- * being run inside of the drawRect method. This is needed for some tests,
- * especially of the Text widget, which record data in a global Tcl
- * variable and assume that display procedures will be run in a
- * predictable sequence as Tcl idle tasks.
+ * being run inside of the drawRect method. If not, it may be desirable
+ * for the display procedure to simply clear the REDRAW_PENDING flag
+ * and return. The widget can be recorded in order to schedule a
+ * redraw, via and Expose event, from within drawRect.
+ *
+ * This is also needed for some tests, especially of the Text widget,
+ * which record data in a global Tcl variable and assume that display
+ * procedures will be run in a predictable sequence as Tcl idle tasks.
*
* Results:
- * True only while running the drawRect method of a TKContentView;
+ * True if called from the drawRect method of a TKContentView with
+ * tkwin NULL or pointing to a widget in the current focusView.
*
* Side effects:
- * None
+ * The tkwin parameter may be recorded to handle redrawing the widget
+ * later.
*
*----------------------------------------------------------------------
*/
-MODULE_SCOPE Bool
-TkpAppIsDrawing(void) {
- return [NSApp isDrawing];
+int
+TkpAppCanDraw(Tk_Window tkwin) {
+ if (![NSApp isDrawing]) {
+ return 0;
+ }
+ if (tkwin) {
+ TkWindow *winPtr = (TkWindow *)tkwin;
+ NSView *view = TkMacOSXDrawableView(winPtr->privatePtr);
+ return (view == [NSView focusView]);
+ } else {
+ return 1;
+ }
}
/*
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index 9117159..cab2b9a 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -6174,28 +6174,40 @@ TkMacOSXMakeRealWindowExist(
/*
*----------------------------------------------------------------------
*
- * TkpDisplayWindow --
+ * TkpRedrawWidget --
*
- * Mark the contentView of this window as needing display so the window
- * will be drawn by the window manager. If this is called within the
- * drawRect method, do nothing.
+ * Mark the bounding rectangle of this widget as needing display so the
+ * widget will be drawn by [NSView drawRect:]. If this is called within
+ * the drawRect method, do nothing.
*
* Results:
* None.
*
* Side effects:
- * The window's contentView is marked as needing display.
+ * The widget's bounding rectangle is marked as dirty.
*
*----------------------------------------------------------------------
*/
-MODULE_SCOPE void
-TkpDisplayWindow(Tk_Window tkwin) {
- if (![NSApp isDrawing]) {
- TkWindow *winPtr = (TkWindow *) tkwin;
- NSWindow *w = TkMacOSXDrawableWindow(winPtr->window);
+void
+TkpRedrawWidget(Tk_Window tkwin) {
+ TkWindow *winPtr = (TkWindow *) tkwin;
+ NSWindow *w;
+ Rect tkBounds;
+ NSRect bounds;
- [[w contentView] setNeedsDisplay: YES];
+ if ([NSApp isDrawing]) {
+ return;
+ }
+ w = TkMacOSXDrawableWindow(winPtr->window);
+ if (w) {
+ NSView *view = [w contentView];
+ TkMacOSXWinBounds(winPtr, &tkBounds);
+ bounds = NSMakeRect(tkBounds.left,
+ [view bounds].size.height - tkBounds.bottom,
+ tkBounds.right - tkBounds.left,
+ tkBounds.bottom - tkBounds.top);
+ [view setNeedsDisplayInRect:bounds];
}
}
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index f7e1860..aa54897 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -859,12 +859,12 @@ DrawMenuUnderline(
len = Tcl_GetCharLength(mePtr->labelPtr);
if (mePtr->underline < len) {
- int activeBorderWidth, leftEdge;
+ int activeBorderWidth, leftEdge, ch;
const char *label, *start, *end;
label = Tcl_GetString(mePtr->labelPtr);
- start = Tcl_UtfAtIndex(label, mePtr->underline);
- end = Tcl_UtfNext(start);
+ start = TkUtfAtIndex(label, mePtr->underline);
+ end = start + TkUtfToUniChar(start, &ch);
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
menuPtr->activeBorderWidthPtr, &activeBorderWidth);
diff --git a/unix/tkUnixPort.h b/unix/tkUnixPort.h
index 09ff558..8fd56fe 100644
--- a/unix/tkUnixPort.h
+++ b/unix/tkUnixPort.h
@@ -167,6 +167,8 @@
#define TkpButtonSetDefaults() {}
#define TkpDestroyButton(butPtr) {}
+#define TkpAppCanDraw(tkwin) 1
+#define TkpRedrawWidget(tkwin)
#define TkSelUpdateClipboard(a,b) {}
#ifndef __CYGWIN__
#define TkSetPixmapColormap(p,c) {}
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index 18ef441..6c55164 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -511,6 +511,7 @@ GetEntryText(
: Tcl_GetString(mePtr->accelPtr);
const char *p, *next;
Tcl_DString itemString;
+ int ch;
/*
* We have to construct the string with an ampersand preceeding the
@@ -527,7 +528,7 @@ GetEntryText(
if (*p == '&') {
Tcl_DStringAppend(&itemString, "&", 1);
}
- next = Tcl_UtfNext(p);
+ next = p + TkUtfToUniChar(p, &ch);
Tcl_DStringAppend(&itemString, p, (int) (next - p));
}
if (mePtr->accelLength > 0) {
@@ -536,7 +537,7 @@ GetEntryText(
if (*p == '&') {
Tcl_DStringAppend(&itemString, "&", 1);
}
- next = Tcl_UtfNext(p);
+ next = p + TkUtfToUniChar(p, &ch);
Tcl_DStringAppend(&itemString, p, (int) (next - p));
}
}
@@ -2134,10 +2135,11 @@ DrawMenuUnderline(
len = Tcl_GetCharLength(mePtr->labelPtr);
if (mePtr->underline < len) {
const char *label, *start, *end;
+ int ch;
label = Tcl_GetString(mePtr->labelPtr);
- start = Tcl_UtfAtIndex(label, mePtr->underline);
- end = Tcl_UtfNext(start);
+ start = TkUtfAtIndex(label, mePtr->underline);
+ end = start + TkUtfToUniChar(start, &ch);
Tk_UnderlineChars(menuPtr->display, d,
gc, tkfont, label, x + mePtr->indicatorSpace,
y + (height + fmPtr->ascent - fmPtr->descent) / 2,
diff --git a/win/tkWinPort.h b/win/tkWinPort.h
index 8cc5677..4ef8680 100644
--- a/win/tkWinPort.h
+++ b/win/tkWinPort.h
@@ -125,4 +125,11 @@
#define TkpCreateNativeBitmap(display, source) None
#define TkpGetNativeAppBitmap(display, name, w, h) None
+/*
+ * Other functions not used under Windows
+ */
+
+#define TkpAppCanDraw(tkwin) 1
+#define TkpRedrawWidget(tkwin)
+
#endif /* _WINPORT */
diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c
index 4391fdd..436fe00 100644
--- a/win/ttkWinXPTheme.c
+++ b/win/ttkWinXPTheme.c
@@ -510,7 +510,7 @@ static void GenericElementSize(
if (!(elementData->info->flags & IGNORE_THEMESIZE)) {
result = elementData->procs->GetThemePartSize(
elementData->hTheme,
- elementData->hDC,
+ NULL,
elementData->info->partId,
Ttk_StateTableLookup(elementData->info->statemap, 0),
NULL /*RECT *prc*/,