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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include "CtrlCore.h"

NAMESPACE_UPP

ClipData::ClipData(const Value& data, String (*render)(const Value& data))
: data(data), render(render)
{}

String sRawClipData(const Value& data)
{
return data;
}

ClipData::ClipData(const String& data)
: data(data), render(sRawClipData)
{}

ClipData::ClipData()
: render(sRawClipData)
{}

void Ctrl::DragAndDrop(Point p, PasteClip& d) {}
void Ctrl::FrameDragAndDrop(Point p, PasteClip& d) {}
void Ctrl::DragEnter() {}
void Ctrl::DragRepeat(Point p) {}
void Ctrl::DragLeave() {}

PasteClip& Ctrl::Clipboard()
{
GuiLock __;
static PasteClip d;
d.fmt.Clear();
return d;
}

PasteClip& Ctrl::Selection()
{
GuiLock __;
static PasteClip d;
GuiPlatformSelection(d);
return d;
}

String Ctrl::GetDropData(const String& fmt) const
{
return GetSelectionData(fmt);
}

String Ctrl::GetSelectionData(const String& fmt) const
{
return Null;
}

bool PasteClip::Accept()
{
accepted = true;
return paste;
}

bool PasteClip::Accept(const char *_fmt)
{
Vector<String> f = Split(_fmt, ';');
for(int i = 0; i < f.GetCount(); i++) {
if(IsAccepted() && fmt == f[i])
return paste;
if(IsAvailable(f[i])) {
accepted = true;
if(paste) {
fmt = f[i];
data = Get(f[i]);
return true;
}
break;
}
}
return false;
}

PasteClip::PasteClip()
{
paste = true;
accepted = false;
GuiPlatformConstruct();
}

int Ctrl::DoDragAndDrop(const char *fmts, const Image& sample, dword actions)
{
VectorMap<String, ClipData> dummy;
return DoDragAndDrop(fmts, sample, actions, dummy);
}

int Ctrl::DoDragAndDrop(const VectorMap<String, ClipData>& data, const Image& sample, dword actions)
{
return DoDragAndDrop("", sample, actions, data);
}

Uuid sDndUuid;
const void *sInternalPtr;

String GetInternalDropId__(const char *type, const char *id)
{
return "U++ Internal clip:" + AsString(sDndUuid) + '-' + type + '-' + id;
}

void NewInternalDrop__(const void *ptr)
{
sDndUuid = Uuid::Create();
sInternalPtr = ptr;
}

const void *GetInternalDropPtr__()
{
return sInternalPtr;
}

String Unicode__(const WString& w)
{
return String((const char *)~w, 2 * w.GetLength());
}

WString Unicode__(const String& s)
{
return WString((const wchar *)~s, s.GetLength() / 2);
}

void GuiPlatformAdjustDragImage(ImageBuffer& b);

Image MakeDragImage(const Image& arrow, Image sample)
{
ImageBuffer b;
if(IsNull(sample)) {
sample = CtrlCoreImg::DndData();
b = sample;
Over(b, Point(0, 0), arrow, arrow.GetSize());
}
else {
b.Create(128, 128);
memset(~b, 0, sizeof(RGBA) * b.GetLength());
Over(b, Point(2, 22), sample, sample.GetSize());
Unmultiply(b);
for(int y = 20; y < 96; y++) {
RGBA *s = b[y];
RGBA *e = s + 96;
while(s < e)
(s++)->a >>= 1;
e += 32;
int q = 128;
while(s < e) {
s->a = (s->a * q) >> 8;
q -= 4;
s++;
}
}
int qq = 128;
for(int y = 96; y < 128; y++) {
RGBA *s = b[y];
RGBA *e = s + 96;
while(s < e) {
s->a = (s->a * qq) >> 8;
s++;
}
e += 32;
int q = 255;
while(s < e) {
s->a = (s->a * q * qq) >> 16;
q -= 8;
s++;
}
qq -= 4;
}
RGBA *s = b[21] + 1;
RGBA c1 = Blue();
RGBA c2 = White();
for(int a = 255; a > 0; a -= 3) {
c1.a = c2.a = a;
*s++ = c1;
Swap(c1, c2);
}
s = b[21] + 1;
c1 = Black();
c2 = White();
for(int a = 255; a > 0; a -= 8) {
c1.a = c2.a = a;
*s = c1;
s += b.GetWidth();
Swap(c1, c2);
}
Premultiply(b);
GuiPlatformAdjustDragImage(b);
Over(b, Point(0, 0), arrow, arrow.GetSize());
}

return b;
}

Ptr<Ctrl> Ctrl::dndctrl;
Point Ctrl::dndpos;
bool Ctrl::dndframe;
PasteClip Ctrl::dndclip;

void Ctrl::DnDRepeat()
{
GuiLock __;
if(dndctrl) {
dndctrl->DragRepeat(dndpos);
if(dndctrl) {
PasteClip d = dndclip;
if(dndframe)
dndctrl->FrameDragAndDrop(dndpos, d);
else
dndctrl->DragAndDrop(dndpos, d);
}
}
else
UPP::KillTimeCallback(&dndpos);
}

void Ctrl::DnD(Point p, PasteClip& clip)
{
GuiLock __;
UPP::KillTimeCallback(&dndpos);
dndclip = clip;
Point hp = p - GetScreenRect().TopLeft();
Ptr<Ctrl> ctrl = this;
while(ctrl && ctrl->IsEnabled()) {
Rect view = ctrl->GetScreenView();
if(ctrl->IsMouseActive())
if(view.Contains(p)) {
dndpos = p - view.TopLeft();
dndframe = false;
ctrl->DragAndDrop(dndpos, clip);
if(clip.IsAccepted())
break;
}
else {
dndpos = p - ctrl->GetScreenRect().TopLeft();
dndframe = true;
ctrl->FrameDragAndDrop(dndpos, clip);
if(clip.IsAccepted())
break;
}
ctrl = ctrl->ChildFromPoint(hp);
}
if(ctrl != dndctrl) {
if(dndctrl)
dndctrl->DragLeave();
dndctrl = ctrl;
if(dndctrl)
dndctrl->DragEnter();
}
if(dndctrl)
UPP::SetTimeCallback(-40, callback(DnDRepeat), &dndpos);
}

void Ctrl::DnDLeave()
{
GuiLock __;
if(dndctrl) {
dndctrl->DragLeave();
UPP::KillTimeCallback(&dndpos);
dndctrl = NULL;
}
}

Ctrl *Ctrl::GetDragAndDropTarget()
{
GuiLock __;
return dndctrl;
}

void InitRichImage(String (*fGetImageClip)(const Image& img, const String& fmt),
bool (*fAcceptImage)(PasteClip& clip),
Image (*fGetImage)(PasteClip& clip),
const char *(*fClipFmtsImage)());

INITBLOCK {
InitRichImage(GetImageClip, AcceptImage, GetImage, ClipFmtsImage);
}

END_UPP_NAMESPACE

Change log

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
Go to: 
Project members, sign in to write a code review

Older revisions

r4004 by cxl on Oct 13, 2011   Diff
*CtrlCore: Fixed semantics of
PasteClip Accept (problem with D&D in
LineEdit)
r3882 by cxl on Sep 18, 2011   Diff
CtrlCore: PasteClip GetFormat,
refactored Get (now equals to
Get(GetFormat()), documented
r3702 by cxl on Jul 22, 2011   Diff
.developing rainbow
All revisions of this file

File info

Size: 5354 bytes, 280 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting