From c866b69aaca5708edbb15d8a51b9346e2d77a740 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 4 Dec 2019 20:35:17 +0000 Subject: Make MODULE_SCOPE functions start with "Tk". Also simplify TkUtfToNSString(), making use of Tcl_UtfToUniCharDString() --- macosx/tkMacOSXClipboard.c | 4 ++-- macosx/tkMacOSXFont.c | 43 ++++++++++++++++++------------------------- macosx/tkMacOSXKeyEvent.c | 2 +- macosx/tkMacOSXPrivate.h | 10 +++------- macosx/tkMacOSXRegion.c | 2 +- 5 files changed, 25 insertions(+), 36 deletions(-) diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c index db45428..825cafa 100644 --- a/macosx/tkMacOSXClipboard.c +++ b/macosx/tkMacOSXClipboard.c @@ -35,7 +35,7 @@ static Tk_Window clipboardOwner = NULL; targetPtr->type == dispPtr->utf8Atom) { for (TkClipboardBuffer *cbPtr = targetPtr->firstBufferPtr; cbPtr; cbPtr = cbPtr->nextPtr) { - NSString *s = TclUniToNSString(cbPtr->buffer, cbPtr->length); + NSString *s = TkUtfToNSString(cbPtr->buffer, cbPtr->length); [string appendString:s]; [s release]; } @@ -144,7 +144,7 @@ TkSelGetSelection( * does produce a 3-byte sequence.) */ - char *bytes = NSStringToTclUni(string, NULL); + char *bytes = TkNSStringToUtf(string, NULL); result = proc(clientData, interp, bytes); if (bytes) { ckfree(bytes); diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 9b2d11c..c8fce8b 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -104,7 +104,7 @@ static void DrawCharsInContext(Display *display, Drawable drawable, /* *--------------------------------------------------------------------------- * - * TclUniToNSString -- + * TkUtfToNSString -- * * When Tcl is compiled with TCL_UTF_MAX = 3 (the default for 8.6) it cannot * deal directly with UTF-8 encoded non-BMP characters, since their UTF-8 @@ -127,32 +127,25 @@ static void DrawCharsInContext(Display *display, Drawable drawable, */ MODULE_SCOPE NSString* -TclUniToNSString( +TkUtfToNSString( const char *source, - int numBytes) + size_t numBytes) { - NSString *string = [[NSString alloc] initWithBytesNoCopy:(void *)source - length:numBytes - encoding:NSUTF8StringEncoding - freeWhenDone:NO]; - if (!string) { - const unichar *characters = ckalloc(numBytes*sizeof(unichar)); - const char *in = source; - unichar *out = (unichar *) characters; - while (in < source + numBytes) { - in += Tcl_UtfToUniChar(in, out++); - } - string = [[NSString alloc] initWithCharacters:characters - length:(out - characters)]; - ckfree(characters); - } + NSString *string; + Tcl_DString ds; + + Tcl_DStringInit(&ds); + Tcl_UtfToUniCharDString(source, numBytes, &ds); + string = [[NSString alloc] initWithCharacters:(const unichar *)Tcl_DStringValue(&ds) + length:(Tcl_DStringLength(&ds)>>1)]; + Tcl_DStringFree(&ds); return string; } /* *--------------------------------------------------------------------------- * - * TclUniAtIndex -- + * TkUtfAtIndex -- * * Write a sequence of bytes up to length 6 which is an encoding of a UTF-16 * character in an NSString. Also record the unicode code point of the character. @@ -170,7 +163,7 @@ TclUniToNSString( */ MODULE_SCOPE int -TclUniAtIndex( +TkUtfAtIndex( NSString *string, int index, char *uni, @@ -198,7 +191,7 @@ TclUniAtIndex( /* *--------------------------------------------------------------------------- * - * NSStringToTclUni -- + * TkNSStringToUtf -- * * Encodes the unicode string represented by an NSString object with the * internal encoding that Tcl uses when TCL_UTF_MAX = 3. This encoding @@ -219,7 +212,7 @@ TclUniAtIndex( */ MODULE_SCOPE char* -NSStringToTclUni( +TkNSStringToUtf( NSString *string, int *numBytes) { @@ -230,7 +223,7 @@ NSStringToTclUni( ptr = bytes; if (ptr) { for (i = 0; i < [string length]; i++) { - ptr += TclUniAtIndex(string, i, ptr, &code); + ptr += TkUtfAtIndex(string, i, ptr, &code); if (code > 0xffff){ i++; } @@ -986,7 +979,7 @@ TkpMeasureCharsInContext( if (maxLength > 32767) { maxLength = 32767; } - string = TclUniToNSString((const char *)source, numBytes); + string = TkUtfToNSString((const char *)source, numBytes); if (!string) { length = 0; fit = rangeLength; @@ -1265,7 +1258,7 @@ DrawCharsInContext( !TkMacOSXSetupDrawingContext(drawable, gc, 1, &drawingContext)) { return; } - string = TclUniToNSString((const char *)source, numBytes); + string = TkUtfToNSString((const char *)source, numBytes); if (!string) { return; } diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c index 7ea085b..d3704d2 100644 --- a/macosx/tkMacOSXKeyEvent.c +++ b/macosx/tkMacOSXKeyEvent.c @@ -347,7 +347,7 @@ static unsigned isFunctionKey(unsigned int code); */ for (i = 0; i < len; i++) { - xEvent.xkey.nbytes = TclUniAtIndex(str, i, xEvent.xkey.trans_chars, + xEvent.xkey.nbytes = TkUtfAtIndex(str, i, xEvent.xkey.trans_chars, &xEvent.xkey.keycode); if (xEvent.xkey.keycode > 0xffff){ i++; diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index 9417b62..64a0cd3 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -143,10 +143,6 @@ MODULE_SCOPE long tkMacOSXMacOSXVersion; * Prototypes for TkMacOSXRegion.c. */ -#if 0 -MODULE_SCOPE void TkMacOSXEmtpyRegion(TkRegion r); -MODULE_SCOPE int TkMacOSXIsEmptyRegion(TkRegion r); -#endif MODULE_SCOPE HIShapeRef TkMacOSXGetNativeRegion(TkRegion r); MODULE_SCOPE void TkMacOSXSetWithNativeRegion(TkRegion r, HIShapeRef rgn); @@ -239,10 +235,10 @@ MODULE_SCOPE int TkMacOSXServices_Init(Tcl_Interp *interp); MODULE_SCOPE int TkMacOSXRegisterServiceWidgetObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -MODULE_SCOPE NSString* TclUniToNSString(const char *source, int numBytes); -MODULE_SCOPE int TclUniAtIndex(NSString *string, int index, char *uni, +MODULE_SCOPE NSString* TkUtfToNSString(const char *source, size_t numBytes); +MODULE_SCOPE int TkUtfAtIndex(NSString *string, int index, char *uni, unsigned int *code); -MODULE_SCOPE char* NSStringToTclUni(NSString *string, int *numBytes); +MODULE_SCOPE char* TkNSStringToUtf(NSString *string, int *numBytes); #pragma mark Private Objective-C Classes diff --git a/macosx/tkMacOSXRegion.c b/macosx/tkMacOSXRegion.c index 1511f90..db19c94 100644 --- a/macosx/tkMacOSXRegion.c +++ b/macosx/tkMacOSXRegion.c @@ -175,7 +175,7 @@ TkUnionRectWithRegion( *---------------------------------------------------------------------- */ -int +static int TkMacOSXIsEmptyRegion( TkRegion r) { -- cgit v0.12