]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDropTarget, wxDropSource, wxDataObject implementation
4 // Author: David Webster
8 // Copyright: (c) 1998 AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dnd.h"
19 #include "wx/window.h"
21 #include "wx/gdicmn.h"
24 #if wxUSE_DRAG_AND_DROP
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 /////////////////////////////////////////////////////////////////////////////
32 /////////////////////////////////////////////////////////////////////////////
34 static wxDragResult
ConvertDragEffectToResult (
53 } // end of ConvertDragEffectToResult
55 static DWORD
ConvertDragResultToEffect (
74 } // end of ConvertDragResultToEffect
79 CIDropTarget(wxDropTarget
* pTarget
)
84 virtual ~CIDropTarget() { }
87 // Accessors for CDropTarget
89 void Free(void) { ::DrgFreeDraginfo(m_pDragInfo
); }
90 PDRAGINFO
GetDataSource(void) { return m_pDragInfo
; }
91 void SetDataSource(PDRAGINFO pDragInfo
) { m_pDragInfo
= pDragInfo
; }
92 void SetHWND(HWND hWnd
) { m_hWnd
= hWnd
; }
95 // CIDropTarget methods
98 MRESULT
DragOver(void);
103 PDRAGINFO m_pDragInfo
;
104 PDRAGITEM m_pDragItem
; // !NULL between DragEnter and DragLeave/Drop
105 wxDropTarget
* m_pTarget
; // the real target (we're just a proxy)
106 HWND m_hWnd
; // window we're associated with
107 }; // end of CLASS CIDropTarget
109 bool CIDropTarget::DragLeave()
112 // Remove the UI feedback
114 m_pTarget
->OnLeave();
117 // Release the held object
121 } // end of CIDropTarget::DragLeave
123 MRESULT
CIDropTarget::DragOver ()
132 ::DrgAccessDraginfo(m_pDragInfo
);
133 switch(m_pDragInfo
->usOperation
)
137 return (MRFROM2SHORT(DOR_NODROPOP
, 0));
140 m_pDragItem
= ::DrgQueryDragitemPtr(m_pDragInfo
, 0);
141 ulBytes
= ::DrgQueryStrName( m_pDragItem
->hstrContainerName
146 return (MRFROM2SHORT(DOR_NODROPOP
, 0));
153 uOp
= m_pDragInfo
->usOperation
;
156 uIndicator
= DOR_DROP
;
157 ulItems
= (ULONG
)::DrgQueryDragitemCount(m_pDragInfo
);
158 for (i
= 0; i
< ulItems
; i
++)
160 m_pDragItem
= ::DrgQueryDragitemPtr(m_pDragInfo
, i
);
161 if (((m_pDragItem
->fsSupportedOps
& DO_COPYABLE
) &&
162 (uOp
== (USHORT
)DO_COPY
)) ||
163 ((m_pDragItem
->fsSupportedOps
& DO_MOVEABLE
) &&
164 (uOp
== (USHORT
)DO_COPY
)))
166 if (::DrgVerifyRMF(m_pDragItem
, "DRM_OS2FILE", "DRF_UNKNOWN"))
167 uIndicator
= (USHORT
)DOR_DROP
;
169 uIndicator
= (USHORT
)DOR_NEVERDROP
;
173 return (MRFROM2SHORT(uIndicator
, uOp
));
174 } // end of CIDropTarget::DragOver
176 // #pragma page "CIDropTarget::Drop"
177 /////////////////////////////////////////////////////////////////////////////
179 // CIDropTarget::Drop
181 // Instructs the drop target to paste data that was just now dropped on it.
184 // pIDataSource -- the data to paste
185 // dwKeyState -- kbd & mouse state
186 // pt -- mouse coordinates
187 // pdwEffect -- effect flag
192 /////////////////////////////////////////////////////////////////////////////
193 MRESULT
CIDropTarget::Drop ()
202 ::DrgAccessDraginfo(m_pDragInfo
);
203 switch(m_pDragInfo
->usOperation
)
207 return (MRFROM2SHORT(DOR_NODROPOP
, 0));
210 m_pDragItem
= ::DrgQueryDragitemPtr(m_pDragInfo
, 0);
211 ulBytes
= ::DrgQueryStrName( m_pDragItem
->hstrContainerName
216 return (MRFROM2SHORT(DOR_NODROPOP
, 0));
223 uOp
= m_pDragInfo
->usOperation
;
226 uIndicator
= DOR_DROP
;
227 ulItems
= (ULONG
)::DrgQueryDragitemCount(m_pDragInfo
);
228 for (i
= 0; i
< ulItems
; i
++)
230 m_pDragItem
= ::DrgQueryDragitemPtr(m_pDragInfo
, i
);
231 if (((m_pDragItem
->fsSupportedOps
& DO_COPYABLE
) &&
232 (uOp
== (USHORT
)DO_COPY
)) ||
233 ((m_pDragItem
->fsSupportedOps
& DO_MOVEABLE
) &&
234 (uOp
== (USHORT
)DO_COPY
)))
236 if (::DrgVerifyRMF(m_pDragItem
, "DRM_OS2FILE", "DRF_UNKNOWN"))
237 uIndicator
= (USHORT
)DOR_DROP
;
239 uIndicator
= (USHORT
)DOR_NEVERDROP
;
244 // First ask the drop target if it wants data
246 if (m_pTarget
->OnDrop( m_pDragInfo
->xDrop
253 // And now it has the data
255 eRc
= m_pTarget
->OnData( m_pDragInfo
->xDrop
260 //else: OnDrop() returned FALSE, no need to copy data
263 // Release the held object
266 return (MRFROM2SHORT(uIndicator
, uOp
));
267 } // end of CIDropTarget::Drop
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 wxDropTarget::wxDropTarget (
274 wxDataObject
* pDataObject
277 m_dataObject
= pDataObject
;
278 m_pDropTarget
= new CIDropTarget(this);
279 } // end of wxDropTarget::wxDropTarget
281 wxDropTarget::~wxDropTarget()
284 } // end of wxDropTarget::~wxDropTarget
286 bool wxDropTarget::GetData ()
288 wxDataFormat vFormat
= GetSupportedFormat(m_pDropTarget
->GetDataSource());
290 if (vFormat
== wxDF_INVALID
)
295 // Under OS/2 we already have the data via the attached DRAGITEM's
298 } // end of wxDropTarget::GetData
300 wxDataFormat
wxDropTarget::GetSupportedFormat (
301 PDRAGINFO pDataSource
305 wxDataFormat vFormat
;
306 wxDataFormat
* pFormats
;
307 ULONG ulFormats
= m_dataObject
->GetFormatCount(wxDataObject::Set
);
308 ULONG ulItems
= (ULONG
)::DrgQueryDragitemCount(pDataSource
);
315 pFormats
= ulFormats
== 1 ? &vFormat
: new wxDataFormat
[ulFormats
];
316 m_dataObject
->GetAllFormats( pFormats
320 for (n
= 0; n
< ulFormats
; n
++)
322 switch(pFormats
[n
].GetType())
327 sMechanism
= "DRM_OS2FILE";
328 sFormat
= "DRF_TEXT";
332 sMechanism
= "DRM_OS2FILE";
333 sFormat
= "DRF_OEMTEXT";
337 sMechanism
= "DRM_OS2FILE";
338 sFormat
= "DRF_BITMAP";
342 case wxDF_ENHMETAFILE
:
343 sMechanism
= "DRM_OS2FILE";
344 sFormat
= "DRF_METAFILE";
348 sMechanism
= "DRM_OS2FILE";
349 sFormat
= "DRF_TIFF";
353 sMechanism
= "DRM_OS2FILE";
354 sFormat
= "DRF_SYLK";
358 sMechanism
= "DRM_OS2FILE";
363 sMechanism
= "DRM_OS2FILE";
371 case wxDF_UNICODETEXT
:
373 sMechanism
= "DRM_OS2FILE";
374 sFormat
= "DRF_UNKNOWN";
378 sMechanism
= "DRM_OBJECT";
379 sFormat
= "DRF_UNKNOWN";
382 for (i
= 0; i
< ulItems
; i
++)
384 pDragItem
= ::DrgQueryDragitemPtr(pDataSource
, i
);
385 if (::DrgVerifyRMF(pDragItem
, sMechanism
.c_str(), sFormat
.c_str()))
393 vFormat
= pFormats
[n
];
397 if (pFormats
!= &vFormat
)
400 // Free memory if we allocated it
404 return (n
< ulFormats
? vFormat
: wxFormatInvalid
);
405 } // end of wxDropTarget::GetSupportedFormat
407 bool wxDropTarget::IsAcceptedData (
408 PDRAGINFO pDataSource
411 return (GetSupportedFormat(pDataSource
) != wxDF_INVALID
);
412 } // end of wxDropTarget::IsAcceptedData
414 void wxDropTarget::Release ()
416 m_pDropTarget
->Free();
417 } // end of wxDropTarget::Release
420 wxDragResult
wxDropTarget::OnData (
422 , wxCoord
WXUNUSED(y
)
423 , wxDragResult
WXUNUSED(vResult
)
426 return (wxDragResult
)0;
427 } // end of wxDropTarget::OnData
429 bool wxDropTarget::OnDrop (
431 , wxCoord
WXUNUSED(y
)
435 } // end of wxDropTarget::OnDrop
437 //-------------------------------------------------------------------------
439 //-------------------------------------------------------------------------
441 wxDropSource::wxDropSource (
446 } // end of wxDropSource::wxDropSource
448 wxDropSource::wxDropSource (
455 } // end of wxDropSource::wxDropSource
457 wxDropSource::~wxDropSource ()
459 ::DrgFreeDraginfo(m_pDragInfo
);
460 } // end of wxDropSource::~wxDropSource
462 wxDragResult
wxDropSource::DoDragDrop (
467 // Need to specify drag items in derived classes that know their data types
468 // before calling DoDragDrop
470 if (::DrgDrag( m_pWindow
->GetHWND()
478 switch(m_pDragInfo
->usOperation
)
494 } // end of wxDropSource::DoDragDrop
496 bool wxDropSource::GiveFeedback (
500 const wxCursor
& rCursor
= GetCursor(eEffect
);
504 ::WinSetPointer(HWND_DESKTOP
, (HPOINTER
)rCursor
.GetHCURSOR());
505 m_vDragImage
.hImage
= (LHANDLE
)rCursor
.GetHCURSOR();
509 m_pDragInfo
->usOperation
= DO_COPY
;
513 m_pDragInfo
->usOperation
= DO_MOVE
;
517 m_pDragInfo
->usOperation
= DO_LINK
;
526 } // end of GuiAdvDnd_CDropSource::GiveFeedback
528 void wxDropSource::Init ()
530 m_pDragInfo
= ::DrgAllocDraginfo(m_ulItems
);
533 // Set a default drag image struct with what we know so far
535 m_vDragImage
.cb
= sizeof(DRAGIMAGE
);
536 m_vDragImage
.cptl
= 0; // non-zero if fl is DRG_POLYGON
537 m_vDragImage
.hImage
= 0; // Set in GiveFeedback
538 m_vDragImage
.sizlStretch
.cx
= 20L;
539 m_vDragImage
.sizlStretch
.cy
= 20L;
540 m_vDragImage
.fl
= DRG_ICON
| DRG_STRETCH
;
541 m_vDragImage
.cxOffset
= 0;
542 m_vDragImage
.cyOffset
= 0;
544 HSTR hStrType
= ::DrgAddStrHandle(DRT_UNKNOWN
);
548 char zContainer
[128];
549 USHORT uSize
= GetDataObject()->GetDataSize(GetDataObject()->GetPreferredFormat()) + 1;
550 char* pzBuffer
= new char[uSize
];
552 memset(pzBuffer
, '\0', GetDataObject()->GetDataSize(GetDataObject()->GetPreferredFormat()));
553 pzBuffer
[GetDataObject()->GetDataSize(GetDataObject()->GetPreferredFormat())] = '\0';
554 GetDataObject()->GetDataHere( GetDataObject()->GetPreferredFormat()
558 strcpy(zFormats
, "<DRM_OS2FILE, DRF_UNKNOWN>");
559 strcpy(zContainer
, GetDataObject()->GetPreferredFormat().GetId().c_str());
561 hStrRMF
= ::DrgAddStrHandle(zFormats
);
562 hStrContainer
= ::DrgAddStrHandle(zContainer
);
564 m_pDragItem
= new DRAGITEM
[m_ulItems
];
565 for (ULONG i
= 0; i
< m_ulItems
; i
++);
567 m_pDragItem
[i
].hwndItem
= m_pWindow
->GetHWND();
568 m_pDragItem
[i
].hstrType
= hStrType
;
569 m_pDragItem
[i
].hstrRMF
= hStrRMF
;
570 m_pDragItem
[i
].hstrContainerName
= hStrContainer
;
571 m_pDragItem
[i
].fsControl
= 0;
572 m_pDragItem
[i
].fsSupportedOps
= DO_COPYABLE
| DO_MOVEABLE
| DO_LINKABLE
;
573 m_pDragItem
[i
].hstrSourceName
= ::DrgAddStrHandle(pzBuffer
);
574 m_pDragItem
[i
].hstrTargetName
= m_pDragItem
[i
].hstrSourceName
;
575 m_pDragItem
[i
].ulItemID
= i
;
576 ::DrgSetDragitem( m_pDragInfo
583 delete [] m_pDragItem
;
584 } // end of wxDropSource::Init
586 #endif //wxUSE_DRAG_AND_DROP