summaryrefslogtreecommitdiff
path: root/src/Fl_mac.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2008-12-21 00:44:55 +0000
committerMatthias Melcher <fltk@matthiasm.com>2008-12-21 00:44:55 +0000
commitac4edf2aedc9c7dc7fc516561fce443984730ea8 (patch)
treefc8770f7127fbe6cdd572eac5def169a603c4337 /src/Fl_mac.cxx
parent47fbe07afeb364d29e901b6b0c498993f94aa149 (diff)
Adding utf8 support for copy and paste under OS X 10.5 (and hopefully below)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6594 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_mac.cxx')
-rw-r--r--src/Fl_mac.cxx65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx
index 7db76cbdf..eb239a0c2 100644
--- a/src/Fl_mac.cxx
+++ b/src/Fl_mac.cxx
@@ -43,6 +43,11 @@
// to implement clipping. This should be changed into pure
// Quartz calls in the near future.
+// FIXME moving away from Carbon, I am replacing the Scrap manager calls with Pasteboard
+// calls that support utf8 encoding. As soon as these unction haven proven working
+// the Scrap manager calls should be removed
+#define USE_PASTEBOARD 1
+
// we don't need the following definition because we deliver only
// true mouse moves. On very slow systems however, this flag may
// still be useful.
@@ -2489,6 +2494,14 @@ Fl_Widget *fl_selection_requestor = 0;
char *fl_selection_buffer[2];
int fl_selection_length[2];
int fl_selection_buffer_length[2];
+#ifdef USE_PASTEBOARD
+static PasteboardRef myPasteboard = 0;
+static void allocatePasteboard() {
+ if (!myPasteboard)
+ PasteboardCreate(kPasteboardClipboard, &myPasteboard);
+}
+#else
+#endif
static ScrapRef myScrap = 0;
/**
@@ -2508,6 +2521,14 @@ void Fl::copy(const char *stuff, int len, int clipboard) {
fl_selection_buffer[clipboard][len] = 0; // needed for direct paste
fl_selection_length[clipboard] = len;
if (clipboard) {
+#ifdef USE_PASTEBOARD
+ // FIXME no error checking done yet!
+ allocatePasteboard();
+ PasteboardClear(myPasteboard);
+ PasteboardSynchronize(myPasteboard);
+ CFDataRef text = CFDataCreate(kCFAllocatorDefault, (UInt8*)fl_selection_buffer[1], len);
+ PasteboardPutItemFlavor(myPasteboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), text, 0);
+#else
ClearCurrentScrap();
OSStatus ret = GetCurrentScrap( &myScrap );
if ( ret != noErr ) {
@@ -2519,6 +2540,7 @@ void Fl::copy(const char *stuff, int len, int clipboard) {
// needed. Check to see if this is necessary on OS/X.
PutScrapFlavor( myScrap, kScrapFlavorTypeText, 0,
len, fl_selection_buffer[1] );
+#endif
}
}
@@ -2526,8 +2548,48 @@ void Fl::copy(const char *stuff, int len, int clipboard) {
void Fl::paste(Fl_Widget &receiver, int clipboard) {
if (clipboard) {
// see if we own the selection, if not go get it:
- ScrapRef scrap = 0;
Size len = 0;
+#ifdef USE_PASTEBOARD
+ // FIXME no error checking done yet!
+ OSStatus err = noErr;
+ allocatePasteboard();
+ PasteboardSynchronize(myPasteboard);
+ ItemCount nFlavor = 0, i;
+ err = PasteboardGetItemCount(myPasteboard, &nFlavor);
+ for (i=1; i<=nFlavor; i++) {
+ PasteboardItemID itemID;
+ CFArrayRef flavorTypeArray;
+ CFIndex flavorCount;
+ err = PasteboardGetItemIdentifier(myPasteboard, i, &itemID);
+ err = PasteboardCopyItemFlavors(myPasteboard, itemID, &flavorTypeArray);
+ flavorCount = CFArrayGetCount(flavorTypeArray);
+ for (CFIndex flavorIndex=0; flavorIndex<flavorCount; flavorIndex++) {
+ CFStringRef flavorType;
+ CFDataRef flavorData;
+ CFIndex len;
+ flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex);
+ if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text"))) {
+ err = PasteboardCopyItemFlavorData( myPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData );
+ len = CFDataGetLength(flavorData);
+
+ if ( len >= fl_selection_buffer_length[1] ) {
+ fl_selection_buffer_length[1] = len + 32;
+ delete[] fl_selection_buffer[1];
+ fl_selection_buffer[1] = new char[len + 32];
+ }
+ fl_selection_length[1] = len; len++;
+ char *data = (char*)CFDataGetBytePtr(flavorData);
+ memcpy(fl_selection_buffer[1], data, len);
+
+ CFRelease (flavorData);
+ i = nFlavor+1;
+ break;
+ }
+ }
+ CFRelease (flavorTypeArray);
+ }
+#else
+ ScrapRef scrap = 0;
if (GetCurrentScrap(&scrap) == noErr && scrap != myScrap &&
GetScrapFlavorSize(scrap, kScrapFlavorTypeText, &len) == noErr) {
if ( len >= fl_selection_buffer_length[1] ) {
@@ -2545,6 +2607,7 @@ void Fl::paste(Fl_Widget &receiver, int clipboard) {
fl_selection_buffer[1][x] = '\n';
}
}
+#endif
}
Fl::e_text = fl_selection_buffer[clipboard];
Fl::e_length = fl_selection_length[clipboard];