summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhobbs <hobbs>2003-11-11 18:21:48 (GMT)
committerhobbs <hobbs>2003-11-11 18:21:48 (GMT)
commitbbf3f6c3e74e218b131dad46b3f29511d8c27867 (patch)
tree4f3f6e23b34cf562cfa42d2241eb48a31456b543
parent74a15ae894b72d7c796f5d4ede4699dda9a7af4a (diff)
downloadtk-bbf3f6c3e74e218b131dad46b3f29511d8c27867.zip
tk-bbf3f6c3e74e218b131dad46b3f29511d8c27867.tar.gz
tk-bbf3f6c3e74e218b131dad46b3f29511d8c27867.tar.bz2
* macosx/tkMacOSXClipboard.c (TkSuspendClipboard, TkSelGetSelection):
add unicode clipboard support. [Patch #840107] (senn)
-rw-r--r--ChangeLog5
-rw-r--r--macosx/tkMacOSXClipboard.c53
2 files changed, 53 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 4262f06..5514506 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-11-11 Jeff Hobbs <jeffh@ActiveState.com>
+
+ * macosx/tkMacOSXClipboard.c (TkSuspendClipboard, TkSelGetSelection):
+ add unicode clipboard support. [Patch #840107] (senn)
+
2003-11-10 Jeff Hobbs <jeffh@ActiveState.com>
* win/configure:
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);
}