diff options
author | hobbs <hobbs@noemail.net> | 2003-11-11 18:21:08 (GMT) |
---|---|---|
committer | hobbs <hobbs@noemail.net> | 2003-11-11 18:21:08 (GMT) |
commit | 032513563e8defaa52a266f1c989d598f6f6d00c (patch) | |
tree | e8137f8c0548d7c7c431fa136a43ac9cf4a1ff6d /macosx/tkMacOSXClipboard.c | |
parent | ab638a7e678fb6e8c2016f8c52de57ebc2d6a4fa (diff) | |
download | tk-032513563e8defaa52a266f1c989d598f6f6d00c.zip tk-032513563e8defaa52a266f1c989d598f6f6d00c.tar.gz tk-032513563e8defaa52a266f1c989d598f6f6d00c.tar.bz2 |
* macosx/tkMacOSXClipboard.c (TkSuspendClipboard, TkSelGetSelection):
add unicode clipboard support. [Patch #840107] (senn)
FossilOrigin-Name: bc9f3d85db21bccba6240b48aae35432a0547a59
Diffstat (limited to 'macosx/tkMacOSXClipboard.c')
-rw-r--r-- | macosx/tkMacOSXClipboard.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c index b327b90..3c083e1 100644 --- a/macosx/tkMacOSXClipboard.c +++ b/macosx/tkMacOSXClipboard.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: tkMacOSXClipboard.c,v 1.2.2.1 2003/05/13 02:42:57 das Exp $ + * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.2.2.2 2003/11/11 18:21:09 hobbs Exp $ */ #include "tkInt.h" @@ -72,8 +72,37 @@ TkSelGetSelection( " GetCurrentScrap failed.", (char *) NULL); return TCL_ERROR; } - - err=GetScrapFlavorSize(scrapRef,'TEXT',&length); + + /* + * Try UNICODE first + */ + err = GetScrapFlavorSize(scrapRef, kScrapFlavorTypeUnicode, &length); + if (err == noErr && length > 0) { + Tcl_DString ds; + char *data; + + buf = (char *) ckalloc(length + 2); + buf[length] = 0; + buf[length+1] = 0; /* 2-byte unicode null */ + err = GetScrapFlavorData(scrapRef, kScrapFlavorTypeUnicode, + &length, buf); + if (err == noErr) { + Tcl_DStringInit(&ds); + Tcl_UniCharToUtfDString((Tcl_UniChar *)buf, + Tcl_UniCharLen((Tcl_UniChar *)buf), &ds); + for (data = Tcl_DStringValue(&ds); *data != '\0'; data++) { + if (*data == '\r') { + *data = '\n'; + } + } + result = (*proc)(clientData, interp, Tcl_DStringValue(&ds)); + Tcl_DStringFree(&ds); + ckfree(buf); + return result; + } + } + + err = GetScrapFlavorSize(scrapRef, 'TEXT', &length); if (err != noErr) { Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection), " GetScrapFlavorSize failed.", (char *) NULL); @@ -287,6 +316,7 @@ TkSuspendClipboard() } if (targetPtr != NULL) { Tcl_DString encodedText; + Tcl_DString unicodedText; length = 0; for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL; @@ -313,6 +343,17 @@ TkSuspendClipboard() Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer, length, &encodedText); PutScrapFlavor(scrapRef, 'TEXT', 0, Tcl_DStringLength(&encodedText), Tcl_DStringValue(&encodedText) ); Tcl_DStringFree(&encodedText); + + /* + * Also put unicode data on scrap + */ + Tcl_DStringInit(&unicodedText); + Tcl_UtfToUniCharDString(buffer, length, &unicodedText); + PutScrapFlavor(scrapRef, kScrapFlavorTypeUnicode, 0, + Tcl_DStringLength(&unicodedText), + Tcl_DStringValue(&unicodedText)); + Tcl_DStringFree(&unicodedText); + ckfree(buffer); } |