My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "Fb.h"

#ifdef GUI_FB

NAMESPACE_UPP

#define LLOG(x) // LOG(x)

static VectorMap<String, ClipData> fbClipboard;

void ClearClipboard()
{
GuiLock __;
fbClipboard.Clear();
}

void AppendClipboard(const char *format, const Value& data, String (*render)(const Value&))
{
GuiLock __;
ClipData& cd = fbClipboard.GetAdd(format);
cd.data = data;
cd.render = render;
}

static String sRawRender(const Value& v)
{
return v;
}

void AppendClipboard(const char *format, const String& data)
{
GuiLock __;
AppendClipboard(format, data, sRawRender);
}

void AppendClipboard(const char *format, const byte *data, int length)
{
GuiLock __;
AppendClipboard(format, String(data, length));
}

String ReadClipboard(const char *format)
{
GuiLock __;
int q = fbClipboard.Find(format);
return q >= 0 ? (*fbClipboard[q].render)(fbClipboard[q].data) : String();
}

void AppendClipboardText(const String& s)
{
AppendClipboard("text", ToSystemCharset(s));
}

void AppendClipboardUnicodeText(const WString& s)
{
AppendClipboard("wtext", (byte *)~s, 2 * s.GetLength());
}

const char *ClipFmtsText()
{
return "wtext;text";
}

String GetString(PasteClip& clip)
{
GuiLock __;
if(clip.Accept("wtext")) {
String s = ~clip;
return WString((const wchar *)~s, wstrlen((const wchar *)~s)).ToString();
}
if(clip.IsAvailable("text"))
return ~clip;
return Null;
}

WString GetWString(PasteClip& clip)
{
GuiLock __;
if(clip.Accept("wtext")) {
String s = ~clip;
return WString((const wchar *)~s, wstrlen((const wchar *)~s));
}
if(clip.IsAvailable("text"))
return (~clip).ToWString();
return Null;
}


bool AcceptText(PasteClip& clip)
{
return clip.Accept(ClipFmtsText());
}

static String sText(const Value& data)
{
return data;
}

static String sWText(const Value& data)
{
return Unicode__(WString(data));
}

void Append(VectorMap<String, ClipData>& data, const String& text)
{
data.GetAdd("text", ClipData(text, sText));
data.GetAdd("wtext", ClipData(text, sWText));
}

void Append(VectorMap<String, ClipData>& data, const WString& text)
{
data.GetAdd("text", ClipData(text, sText));
data.GetAdd("wtext", ClipData(text, sWText));
}

String GetTextClip(const WString& text, const String& fmt)
{
if(fmt == "text")
return text.ToString();
if(fmt == "wtext")
return Unicode__(text);
return Null;
}

String GetTextClip(const String& text, const String& fmt)
{
if(fmt == "text")
return text;
if(fmt == "wtext")
return Unicode__(text.ToWString());
return Null;
}

String ReadClipboardText()
{
String w = ReadClipboard("text");
return w.GetCount() ? w : ReadClipboardUnicodeText().ToString();
}

WString ReadClipboardUnicodeText()
{
String w = ReadClipboard("wtext");
if(w.GetCount())
return WString((const wchar *)~w, w.GetLength() / 2);
return ReadClipboard("text").ToWString();
}

bool IsClipboardAvailable(const char *id)
{
return fbClipboard.Find(id) >= 0;
}

bool IsClipboardAvailableText()
{
return IsClipboardAvailable("text") || IsClipboardAvailable("wtext");
}

const char *ClipFmtsImage()
{
static const char *q;
ONCELOCK {
static String s = "dib;" + ClipFmt<Image>();
q = s;
}
return q;
}

bool AcceptImage(PasteClip& clip)
{
GuiLock __;
return clip.Accept(ClipFmtsImage());
}

Image GetImage(PasteClip& clip)
{
GuiLock __;
Image m;
if(Accept<Image>(clip)) {
LoadFromString(m, ~clip);
if(!m.IsEmpty())
return m;
}
return Null;
}

Image ReadClipboardImage()
{
GuiLock __;
PasteClip d = Ctrl::Clipboard();
return GetImage(d);
}

String sImage(const Value& image)
{
Image img = image;
return StoreAsString(const_cast<Image&>(img));
}

String GetImageClip(const Image& img, const String& fmt)
{
GuiLock __;
if(img.IsEmpty()) return Null;
if(fmt == ClipFmt<Image>())
return sImage(img);
return Null;
}

void AppendClipboardImage(const Image& img)
{
GuiLock __;
if(img.IsEmpty()) return;
AppendClipboard(ClipFmt<Image>(), img, sImage);
}

bool AcceptFiles(PasteClip& clip)
{
if(clip.Accept("files")) {
clip.SetAction(DND_COPY);
return true;
}
return false;
}

bool IsAvailableFiles(PasteClip& clip)
{
return clip.IsAvailable("files");
}

Vector<String> GetFiles(PasteClip& clip)
{
GuiLock __;
Vector<String> f;
return f;
}

END_UPP_NAMESPACE

#endif

Change log

r4158 by cxl on Nov 10, 2011   Diff
*Rainbow: Fixed text clipboard issue (RM
#153, thanks Sender Ghost)
Go to: 
Project members, sign in to write a code review

Older revisions

r3701 by cxl on Jul 22, 2011   Diff
.Developing rainbow FB
r3628 by cxl on Jul 9, 2011   Diff
.developing rainbow
r3610 by cxl on Jul 5, 2011   Diff
.developing rainbow
All revisions of this file

File info

Size: 4472 bytes, 238 lines
Powered by Google Project Hosting