summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--macosx/tkMacOSXClipboard.c47
2 files changed, 49 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 43a622c..679d7f7 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/tkWinDraw.c (XFillRectangles): correctly handle the
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);
}