diff options
author | hobbs <hobbs> | 2003-11-11 18:21:48 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2003-11-11 18:21:48 (GMT) |
commit | b72176dd81d39902420c6eff92e01288887e0ae0 (patch) | |
tree | 4f3f6e23b34cf562cfa42d2241eb48a31456b543 /macosx/tkMacOSXClipboard.c | |
parent | 9f264415fc12875ecd14a27dae3983d8ce7b01ba (diff) | |
download | tk-b72176dd81d39902420c6eff92e01288887e0ae0.zip tk-b72176dd81d39902420c6eff92e01288887e0ae0.tar.gz tk-b72176dd81d39902420c6eff92e01288887e0ae0.tar.bz2 |
* macosx/tkMacOSXClipboard.c (TkSuspendClipboard, TkSelGetSelection):
add unicode clipboard support. [Patch #840107] (senn)
Diffstat (limited to 'macosx/tkMacOSXClipboard.c')
-rw-r--r-- | macosx/tkMacOSXClipboard.c | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c index 26fde2a..76bf710 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.3 2003/05/10 19:43:08 wolfsuit Exp $ + * RCS: @(#) $Id: tkMacOSXClipboard.c,v 1.4 2003/11/11 18:21:48 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; @@ -310,9 +340,22 @@ TkSuspendClipboard() ClearCurrentScrap(); GetCurrentScrap(&scrapRef); - Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer, length, &encodedText); - PutScrapFlavor(scrapRef, 'TEXT', 0, Tcl_DStringLength(&encodedText), Tcl_DStringValue(&encodedText) ); + 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); } |