1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
$NetBSD: patch-ag,v 1.7 2010/08/30 19:29:26 adam Exp $
On MacOSX use Pasteboard Manager instead of deprecated Scrap Manager.
For details, see http://gna.org/bugs/?16576
--- src/clipboard.cpp.orig 2010-02-06 10:50:29.000000000 +0000
+++ src/clipboard.cpp
@@ -26,6 +26,8 @@
#include "SDL_syswm.h"
+#include <unistd.h>
+
/**
The following are two classes which wrap the SDL's interface to X,
including locking/unlocking, and which manage the atom internment.
@@ -483,7 +485,7 @@ void copy_to_clipboard(const std::string
{
std::string new_str;
new_str.reserve(text.size());
- for (int i = 0; i < text.size(); ++i)
+ for (unsigned int i = 0; i < text.size(); ++i)
{
if (text[i] == '\n')
{
@@ -493,33 +495,64 @@ void copy_to_clipboard(const std::string
}
}
OSStatus err = noErr;
- ScrapRef scrap = kScrapRefNone;
- err = ClearCurrentScrap();
+ PasteboardRef clipboard;
+ PasteboardSyncFlags syncFlags;
+ CFDataRef textData = NULL;
+ err = PasteboardCreate(kPasteboardClipboard, &clipboard);
if (err != noErr) return;
- err = GetCurrentScrap(&scrap);
+ err = PasteboardClear(clipboard);
if (err != noErr) return;
- PutScrapFlavor(scrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, text.size(), new_str.c_str());
+ syncFlags = PasteboardSynchronize(clipboard);
+ if ((syncFlags&kPasteboardModified) && !(syncFlags&kPasteboardClientIsOwner)) return;
+ textData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)new_str.c_str(), text.size());
+ PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), textData, 0);
}
std::string copy_from_clipboard(const bool)
{
- ScrapRef curscrap = kScrapRefNone;
- Size scrapsize = 0;
OSStatus err = noErr;
- err = GetCurrentScrap(&curscrap);
- if (err != noErr) return "";
- err = GetScrapFlavorSize(curscrap, kScrapFlavorTypeText, &scrapsize);
+ PasteboardRef clipboard;
+ PasteboardSyncFlags syncFlags;
+ ItemCount count;
+ err = PasteboardCreate(kPasteboardClipboard, &clipboard);
if (err != noErr) return "";
- std::string str;
- str.reserve(scrapsize);
- str.resize(scrapsize);
- err = GetScrapFlavorData(curscrap, kScrapFlavorTypeText, &scrapsize, const_cast<char*>(str.data()));
+ syncFlags = PasteboardSynchronize(clipboard);
+ if (syncFlags&kPasteboardModified) return "";
+ err = PasteboardGetItemCount(clipboard, &count);
if (err != noErr) return "";
- for (int i = 0; i < str.size(); ++i)
- {
- if (str[i] == '\r') str[i] = '\n';
+ for (UInt32 k = 1; k <= count; k++) {
+ PasteboardItemID itemID;
+ CFArrayRef flavorTypeArray;
+ CFIndex flavorCount;
+ err = PasteboardGetItemIdentifier(clipboard, k, &itemID);
+ if (err != noErr) return "";
+ err = PasteboardCopyItemFlavors(clipboard, itemID, &flavorTypeArray);
+ if (err != noErr) return "";
+ flavorCount = CFArrayGetCount(flavorTypeArray);
+ for (CFIndex j = 0; j < flavorCount; j++) {
+ CFStringRef flavorType;
+ CFDataRef flavorData;
+ CFIndex flavorDataSize;
+ flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, j);
+ if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text"))) {
+ err = PasteboardCopyItemFlavorData(clipboard, itemID, flavorType, &flavorData);
+ if (err != noErr) {
+ CFRelease(flavorTypeArray);
+ return "";
+ }
+ flavorDataSize = CFDataGetLength(flavorData);
+ std::string str;
+ str.reserve(flavorDataSize);
+ str.resize(flavorDataSize);
+ CFDataGetBytes(flavorData, CFRangeMake(0, flavorDataSize), (UInt8 *)str.data());
+ for (unsigned int i = 0; i < str.size(); ++i) {
+ if (str[i] == '\r') str[i] = '\n';
+ }
+ return str;
+ }
+ }
}
- return str;
+ return "";
}
void handle_system_event(const SDL_Event& event)
|