/
dnd.cpp
591 lines (515 loc) · 16.8 KB
/
dnd.cpp
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
///////////////////////////////////////////////////////////////////////////////
// Name: src/os2/dnd.cpp
// Purpose: wxDropTarget, wxDropSource, wxDataObject implementation
// Author: David Webster
// Modified by:
// Created: 10/21/99
// RCS-ID: $Id$
// Copyright: (c) 1998 AUTHOR
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/window.h"
#include "wx/gdicmn.h"
#endif
#define INCL_PM
#define INCL_DOS
#include <os2.h>
// ----------------------------------------------------------------------------
// global
// ----------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// Private functions
/////////////////////////////////////////////////////////////////////////////
#if 0
static wxDragResult ConvertDragEffectToResult (
DWORD dwEffect
)
{
switch (dwEffect)
{
case DO_COPY:
return wxDragCopy;
case DO_LINK:
return wxDragLink;
case DO_MOVE:
return wxDragMove;
default:
case DO_DEFAULT:
return wxDragNone;
}
} // end of ConvertDragEffectToResult
static DWORD ConvertDragResultToEffect (
wxDragResult eResult
)
{
switch (eResult)
{
case wxDragCopy:
return DO_COPY;
case wxDragLink:
return DO_LINK;
case wxDragMove:
return DO_MOVE;
default:
case wxDragNone:
return DO_DEFAULT;
}
} // end of ConvertDragResultToEffect
#endif
class CIDropTarget
{
public:
CIDropTarget(wxDropTarget* pTarget)
{
m_pTarget = pTarget;
m_pDragItem = NULL;
}
virtual ~CIDropTarget() { }
//
// Accessors for CDropTarget
//
void Free(void) { ::DrgFreeDraginfo(m_pDragInfo); }
PDRAGINFO GetDataSource(void) { return m_pDragInfo; }
void SetDataSource(PDRAGINFO pDragInfo) { m_pDragInfo = pDragInfo; }
void SetHWND(HWND hWnd) { m_hWnd = hWnd; }
//
// CIDropTarget methods
//
bool DragLeave(void);
MRESULT DragOver(void);
MRESULT Drop(void);
protected:
PDRAGINFO m_pDragInfo;
PDRAGITEM m_pDragItem; // !NULL between DragEnter and DragLeave/Drop
wxDropTarget* m_pTarget; // the real target (we're just a proxy)
HWND m_hWnd; // window we're associated with
}; // end of CLASS CIDropTarget
bool CIDropTarget::DragLeave()
{
//
// Remove the UI feedback
//
m_pTarget->OnLeave();
//
// Release the held object
//
Free();
return true;
} // end of CIDropTarget::DragLeave
MRESULT CIDropTarget::DragOver ()
{
char zBuffer[128];
ULONG ulBytes;
USHORT uOp = 0;
USHORT uIndicator;
ULONG ulItems;
ULONG i;
::DrgAccessDraginfo(m_pDragInfo);
switch(m_pDragInfo->usOperation)
{
case DO_UNKNOWN:
Free();
return (MRFROM2SHORT(DOR_NODROPOP, 0));
case DO_DEFAULT:
m_pDragItem = ::DrgQueryDragitemPtr(m_pDragInfo, 0);
ulBytes = ::DrgQueryStrName( m_pDragItem->hstrContainerName
,128
,zBuffer
);
if (!ulBytes)
return (MRFROM2SHORT(DOR_NODROPOP, 0));
else
uOp = DO_MOVE;
break;
case DO_COPY:
case DO_MOVE:
uOp = m_pDragInfo->usOperation;
break;
}
uIndicator = DOR_DROP;
ulItems = (ULONG)::DrgQueryDragitemCount(m_pDragInfo);
for (i = 0; i < ulItems; i++)
{
m_pDragItem = ::DrgQueryDragitemPtr(m_pDragInfo, i);
if (((m_pDragItem->fsSupportedOps & DO_COPYABLE) &&
(uOp == (USHORT)DO_COPY)) ||
((m_pDragItem->fsSupportedOps & DO_MOVEABLE) &&
(uOp == (USHORT)DO_COPY)))
{
if (::DrgVerifyRMF(m_pDragItem, "DRM_OS2FILE", "DRF_UNKNOWN"))
uIndicator = (USHORT)DOR_DROP;
else
uIndicator = (USHORT)DOR_NEVERDROP;
}
}
Free();
return (MRFROM2SHORT(uIndicator, uOp));
} // end of CIDropTarget::DragOver
// #pragma page "CIDropTarget::Drop"
/////////////////////////////////////////////////////////////////////////////
//
// CIDropTarget::Drop
//
// Instructs the drop target to paste data that was just now dropped on it.
//
// PARAMETERS
// pIDataSource -- the data to paste
// dwKeyState -- kbd & mouse state
// pt -- mouse coordinates
// pdwEffect -- effect flag
//
// RETURN VALUE
// STDMETHODIMP S_OK
//
/////////////////////////////////////////////////////////////////////////////
MRESULT CIDropTarget::Drop ()
{
char zBuffer[128];
ULONG ulBytes;
USHORT uOp = 0;
USHORT uIndicator;
ULONG ulItems;
ULONG i;
::DrgAccessDraginfo(m_pDragInfo);
switch(m_pDragInfo->usOperation)
{
case DO_UNKNOWN:
Free();
return (MRFROM2SHORT(DOR_NODROPOP, 0));
case DO_DEFAULT:
m_pDragItem = ::DrgQueryDragitemPtr(m_pDragInfo, 0);
ulBytes = ::DrgQueryStrName( m_pDragItem->hstrContainerName
,128
,zBuffer
);
if (!ulBytes)
return (MRFROM2SHORT(DOR_NODROPOP, 0));
else
uOp = DO_MOVE;
break;
case DO_COPY:
case DO_MOVE:
uOp = m_pDragInfo->usOperation;
break;
}
uIndicator = DOR_DROP;
ulItems = (ULONG)::DrgQueryDragitemCount(m_pDragInfo);
for (i = 0; i < ulItems; i++)
{
m_pDragItem = ::DrgQueryDragitemPtr(m_pDragInfo, i);
if (((m_pDragItem->fsSupportedOps & DO_COPYABLE) &&
(uOp == (USHORT)DO_COPY)) ||
((m_pDragItem->fsSupportedOps & DO_MOVEABLE) &&
(uOp == (USHORT)DO_COPY)))
{
if (::DrgVerifyRMF(m_pDragItem, "DRM_OS2FILE", "DRF_UNKNOWN"))
uIndicator = (USHORT)DOR_DROP;
else
uIndicator = (USHORT)DOR_NEVERDROP;
}
}
//
// First ask the drop target if it wants data
//
if (m_pTarget->OnDrop( m_pDragInfo->xDrop
,m_pDragInfo->yDrop
))
{
wxDragResult eRc = wxDragNone;
//
// And now it has the data
//
eRc = m_pTarget->OnData( m_pDragInfo->xDrop
,m_pDragInfo->yDrop
,eRc
);
}
//else: OnDrop() returned false, no need to copy data
//
// Release the held object
//
Free();
return (MRFROM2SHORT(uIndicator, uOp));
} // end of CIDropTarget::Drop
// ----------------------------------------------------------------------------
// wxDropTarget
// ----------------------------------------------------------------------------
wxDropTarget::wxDropTarget (
wxDataObject* pDataObject
)
{
m_dataObject = pDataObject;
m_pDropTarget = new CIDropTarget(this);
} // end of wxDropTarget::wxDropTarget
wxDropTarget::~wxDropTarget()
{
Release();
} // end of wxDropTarget::~wxDropTarget
bool wxDropTarget::GetData ()
{
wxDataFormat vFormat = GetSupportedFormat(m_pDropTarget->GetDataSource());
if (vFormat == wxDF_INVALID)
{
return false;
}
//
// Under OS/2 we already have the data via the attached DRAGITEM's
//
return true;
} // end of wxDropTarget::GetData
wxDataFormat wxDropTarget::GetSupportedFormat (
PDRAGINFO pDataSource
) const
{
PDRAGITEM pDragItem;
wxDataFormat vFormat;
wxDataFormat* pFormats;
ULONG ulFormats = m_dataObject->GetFormatCount(wxDataObject::Set);
ULONG ulItems = (ULONG)::DrgQueryDragitemCount(pDataSource);
ULONG i;
ULONG n;
wxString sMechanism;
wxString sFormat;
bool bValid = false;
pFormats = ulFormats == 1 ? &vFormat : new wxDataFormat[ulFormats];
m_dataObject->GetAllFormats( pFormats
,wxDataObject::Set
);
for (n = 0; n < ulFormats; n++)
{
switch(pFormats[n].GetType())
{
case wxDF_TEXT:
case wxDF_FILENAME:
case wxDF_HTML:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_TEXT");
break;
case wxDF_OEMTEXT:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_OEMTEXT");
break;
case wxDF_BITMAP:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_BITMAP");
break;
case wxDF_METAFILE:
case wxDF_ENHMETAFILE:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_METAFILE");
break;
case wxDF_TIFF:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_TIFF");
break;
case wxDF_SYLK:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_SYLK");
break;
case wxDF_DIF:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_DIF");
break;
case wxDF_DIB:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_DIB");
break;
case wxDF_PALETTE:
case wxDF_PENDATA:
case wxDF_RIFF:
case wxDF_WAVE:
case wxDF_UNICODETEXT:
case wxDF_LOCALE:
sMechanism = wxT("DRM_OS2FILE");
sFormat = wxT("DRF_UNKNOWN");
break;
case wxDF_PRIVATE:
sMechanism = wxT("DRM_OBJECT");
sFormat = wxT("DRF_UNKNOWN");
break;
}
for (i = 0; i < ulItems; i++)
{
pDragItem = ::DrgQueryDragitemPtr(pDataSource, i);
if (::DrgVerifyRMF(pDragItem, sMechanism.c_str(), sFormat.c_str()))
{
bValid = true;
break;
}
}
if (bValid)
{
vFormat = pFormats[n];
break;
}
}
if (pFormats != &vFormat)
{
//
// Free memory if we allocated it
//
delete [] pFormats;
}
return (n < ulFormats ? vFormat : wxFormatInvalid);
} // end of wxDropTarget::GetSupportedFormat
bool wxDropTarget::IsAcceptedData (
PDRAGINFO pDataSource
) const
{
return (GetSupportedFormat(pDataSource) != wxDF_INVALID);
} // end of wxDropTarget::IsAcceptedData
void wxDropTarget::Release ()
{
m_pDropTarget->Free();
} // end of wxDropTarget::Release
wxDragResult wxDropTarget::OnData (
wxCoord WXUNUSED(vX)
, wxCoord WXUNUSED(y)
, wxDragResult WXUNUSED(vResult)
)
{
return (wxDragResult)0;
} // end of wxDropTarget::OnData
bool wxDropTarget::OnDrop (
wxCoord WXUNUSED(x)
, wxCoord WXUNUSED(y)
)
{
return true;
} // end of wxDropTarget::OnDrop
//-------------------------------------------------------------------------
// wxDropSource
//-------------------------------------------------------------------------
wxDropSource::wxDropSource ( wxWindow* WXUNUSED(pWin) )
{
Init();
} // end of wxDropSource::wxDropSource
wxDropSource::wxDropSource ( wxDataObject& rData, wxWindow* WXUNUSED(pWin) )
{
Init();
SetData(rData);
} // end of wxDropSource::wxDropSource
wxDropSource::~wxDropSource ()
{
::DrgFreeDraginfo(m_pDragInfo);
} // end of wxDropSource::~wxDropSource
wxDragResult wxDropSource::DoDragDrop (
int WXUNUSED(flags)
)
{
//
// Need to specify drag items in derived classes that know their data types
// before calling DoDragDrop
//
if (::DrgDrag( m_pWindow->GetHWND()
,m_pDragInfo
,&m_vDragImage
,m_ulItems
,VK_BUTTON2
,NULL
) != NULLHANDLE)
{
switch(m_pDragInfo->usOperation)
{
case DO_COPY:
return wxDragCopy;
case DO_MOVE:
return wxDragCopy;
case DO_LINK:
return wxDragCopy;
default:
return wxDragNone;
}
}
return wxDragError;
} // end of wxDropSource::DoDragDrop
bool wxDropSource::GiveFeedback (
wxDragResult eEffect
)
{
const wxCursor& rCursor = GetCursor(eEffect);
if (rCursor.IsOk())
{
::WinSetPointer(HWND_DESKTOP, (HPOINTER)rCursor.GetHCURSOR());
m_vDragImage.hImage = (LHANDLE)rCursor.GetHCURSOR();
switch(eEffect)
{
case wxDragCopy:
m_pDragInfo->usOperation = DO_COPY;
break;
case wxDragMove:
m_pDragInfo->usOperation = DO_MOVE;
break;
case wxDragLink:
m_pDragInfo->usOperation = DO_LINK;
break;
case wxDragNone:
case wxDragCancel:
case wxDragError:
break;
}
return true;
}
else
{
return false;
}
} // end of GuiAdvDnd_CDropSource::GiveFeedback
void wxDropSource::Init ()
{
m_pDragInfo = ::DrgAllocDraginfo(m_ulItems);
//
// Set a default drag image struct with what we know so far
//
m_vDragImage.cb = sizeof(DRAGIMAGE);
m_vDragImage.cptl = 0; // non-zero if fl is DRG_POLYGON
m_vDragImage.hImage = 0; // Set in GiveFeedback
m_vDragImage.sizlStretch.cx = 20L;
m_vDragImage.sizlStretch.cy = 20L;
m_vDragImage.fl = DRG_ICON | DRG_STRETCH;
m_vDragImage.cxOffset = 0;
m_vDragImage.cyOffset = 0;
HSTR hStrType = ::DrgAddStrHandle(DRT_UNKNOWN);
HSTR hStrRMF;
HSTR hStrContainer;
wxChar zFormats[128];
wxChar zContainer[128];
USHORT uSize = (USHORT)(GetDataObject()->GetDataSize(GetDataObject()->GetPreferredFormat()) + 1);
wxChar* pzBuffer = new wxChar[uSize];
memset(pzBuffer, '\0', GetDataObject()->GetDataSize(GetDataObject()->GetPreferredFormat()));
pzBuffer[GetDataObject()->GetDataSize(GetDataObject()->GetPreferredFormat())] = '\0';
GetDataObject()->GetDataHere( GetDataObject()->GetPreferredFormat()
,(void*)pzBuffer
);
wxStrcpy(zFormats, wxT("<DRM_OS2FILE, DRF_UNKNOWN>"));
wxStrcpy(zContainer, GetDataObject()->GetPreferredFormat().GetId());
hStrRMF = ::DrgAddStrHandle((PSZ)zFormats);
hStrContainer = ::DrgAddStrHandle((PSZ)zContainer);
m_pDragItem = new DRAGITEM[m_ulItems];
for (ULONG i = 0; i < m_ulItems; i++)
{
m_pDragItem[i].hwndItem = m_pWindow->GetHWND();
m_pDragItem[i].hstrType = hStrType;
m_pDragItem[i].hstrRMF = hStrRMF;
m_pDragItem[i].hstrContainerName = hStrContainer;
m_pDragItem[i].fsControl = 0;
m_pDragItem[i].fsSupportedOps = DO_COPYABLE | DO_MOVEABLE | DO_LINKABLE;
m_pDragItem[i].hstrSourceName = ::DrgAddStrHandle((PSZ)pzBuffer);
m_pDragItem[i].hstrTargetName = m_pDragItem[i].hstrSourceName;
m_pDragItem[i].ulItemID = i;
::DrgSetDragitem( m_pDragInfo
,&m_pDragItem[i]
,sizeof(DRAGITEM)
,0
);
}
delete [] pzBuffer;
delete [] m_pDragItem;
} // end of wxDropSource::Init
#endif //wxUSE_DRAG_AND_DROP