1 // IDataObjectImpl.h: interface for the CIDataObjectImpl class.
2 /**************************************************************************
3 THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF
4 ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
5 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
7 Author: Leon Finker 1/2001
8 **************************************************************************/
9 #ifndef __DRAGDROPIMPL_H__
10 #define __DRAGDROPIMPL_H__
11 //#include <ShlDisp.h>
12 ///////////////////////////////////////////////////////////////////////////////////////////////
13 class CEnumFormatEtc
: public IEnumFORMATETC
17 CSimpleArray
<FORMATETC
> m_pFmtEtc
;
21 CEnumFormatEtc(const CSimpleArray
<FORMATETC
>& ArrFE
);
22 CEnumFormatEtc(const CSimpleArray
<FORMATETC
*>& ArrFE
);
24 STDMETHOD(QueryInterface
)(REFIID
, void FAR
* FAR
*);
25 STDMETHOD_(ULONG
, AddRef
)(void);
26 STDMETHOD_(ULONG
, Release
)(void);
28 //IEnumFORMATETC members
29 STDMETHOD(Next
)(ULONG
, LPFORMATETC
, ULONG FAR
*);
30 STDMETHOD(Skip
)(ULONG
);
31 STDMETHOD(Reset
)(void);
32 STDMETHOD(Clone
)(IEnumFORMATETC FAR
* FAR
*);
35 ///////////////////////////////////////////////////////////////////////////////////////////////
36 class CIDropSource
: public IDropSource
42 CIDropSource::CIDropSource():m_cRefCount(0),m_bDropped(false) {}
44 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(
45 /* [in] */ REFIID riid
,
46 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
);
47 virtual ULONG STDMETHODCALLTYPE
AddRef( void);
48 virtual ULONG STDMETHODCALLTYPE
Release( void);
50 virtual HRESULT STDMETHODCALLTYPE
QueryContinueDrag(
51 /* [in] */ BOOL fEscapePressed
,
52 /* [in] */ DWORD grfKeyState
);
54 virtual HRESULT STDMETHODCALLTYPE
GiveFeedback(
55 /* [in] */ DWORD dwEffect
);
58 ///////////////////////////////////////////////////////////////////////////////////////////////
59 class CIDataObject
: public IDataObject
//,public IAsyncOperation
61 CIDropSource
* m_pDropSource
;
63 CSimpleArray
<FORMATETC
*> m_ArrFormatEtc
;
64 CSimpleArray
<STGMEDIUM
*> m_StgMedium
;
66 CIDataObject(CIDropSource
* pDropSource
);
68 void CopyMedium(STGMEDIUM
* pMedDest
, STGMEDIUM
* pMedSrc
, FORMATETC
* pFmtSrc
);
70 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(
71 /* [in] */ REFIID riid
,
72 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
);
73 virtual ULONG STDMETHODCALLTYPE
AddRef( void);
74 virtual ULONG STDMETHODCALLTYPE
Release( void);
77 virtual /* [local] */ HRESULT STDMETHODCALLTYPE
GetData(
78 /* [unique][in] */ FORMATETC __RPC_FAR
*pformatetcIn
,
79 /* [out] */ STGMEDIUM __RPC_FAR
*pmedium
);
81 virtual /* [local] */ HRESULT STDMETHODCALLTYPE
GetDataHere(
82 /* [unique][in] */ FORMATETC __RPC_FAR
*pformatetc
,
83 /* [out][in] */ STGMEDIUM __RPC_FAR
*pmedium
);
85 virtual HRESULT STDMETHODCALLTYPE
QueryGetData(
86 /* [unique][in] */ FORMATETC __RPC_FAR
*pformatetc
);
88 virtual HRESULT STDMETHODCALLTYPE
GetCanonicalFormatEtc(
89 /* [unique][in] */ FORMATETC __RPC_FAR
*pformatectIn
,
90 /* [out] */ FORMATETC __RPC_FAR
*pformatetcOut
);
92 virtual /* [local] */ HRESULT STDMETHODCALLTYPE
SetData(
93 /* [unique][in] */ FORMATETC __RPC_FAR
*pformatetc
,
94 /* [unique][in] */ STGMEDIUM __RPC_FAR
*pmedium
,
95 /* [in] */ BOOL fRelease
);
97 virtual HRESULT STDMETHODCALLTYPE
EnumFormatEtc(
98 /* [in] */ DWORD dwDirection
,
99 /* [out] */ IEnumFORMATETC __RPC_FAR
*__RPC_FAR
*ppenumFormatEtc
);
101 virtual HRESULT STDMETHODCALLTYPE
DAdvise(
102 /* [in] */ FORMATETC __RPC_FAR
*pformatetc
,
103 /* [in] */ DWORD advf
,
104 /* [unique][in] */ IAdviseSink __RPC_FAR
*pAdvSink
,
105 /* [out] */ DWORD __RPC_FAR
*pdwConnection
);
107 virtual HRESULT STDMETHODCALLTYPE
DUnadvise(
108 /* [in] */ DWORD dwConnection
);
110 virtual HRESULT STDMETHODCALLTYPE
EnumDAdvise(
111 /* [out] */ IEnumSTATDATA __RPC_FAR
*__RPC_FAR
*ppenumAdvise
);
114 //virtual HRESULT STDMETHODCALLTYPE SetAsyncMode(
115 // /* [in] */ BOOL fDoOpAsync)
120 //virtual HRESULT STDMETHODCALLTYPE GetAsyncMode(
121 // /* [out] */ BOOL __RPC_FAR *pfIsOpAsync)
126 //virtual HRESULT STDMETHODCALLTYPE StartOperation(
127 // /* [optional][unique][in] */ IBindCtx __RPC_FAR *pbcReserved)
132 //virtual HRESULT STDMETHODCALLTYPE InOperation(
133 // /* [out] */ BOOL __RPC_FAR *pfInAsyncOp)
138 //virtual HRESULT STDMETHODCALLTYPE EndOperation(
139 // /* [in] */ HRESULT hResult,
140 // /* [unique][in] */ IBindCtx __RPC_FAR *pbcReserved,
141 // /* [in] */ DWORD dwEffects)
147 ///////////////////////////////////////////////////////////////////////////////////////////////
148 class CIDropTarget
: public IDropTarget
152 struct IDropTargetHelper
*m_pDropTargetHelper
;
153 CSimpleArray
<FORMATETC
> m_formatetc
;
154 FORMATETC
* m_pSupportedFrmt
;
159 CIDropTarget(HWND m_hTargetWnd
);
160 virtual ~CIDropTarget();
161 void AddSuportedFormat(FORMATETC
& ftetc
) { m_formatetc
.Add(ftetc
); }
163 //return values: true - release the medium. false - don't release the medium
164 virtual bool OnDrop(FORMATETC
* pFmtEtc
, STGMEDIUM
& medium
,DWORD
*pdwEffect
, POINTL pt
) = 0;
166 virtual HRESULT STDMETHODCALLTYPE
QueryInterface(
167 /* [in] */ REFIID riid
,
168 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
);
169 virtual ULONG STDMETHODCALLTYPE
AddRef( void) { ATLTRACE("CIDropTarget::AddRef\n"); return ++m_cRefCount
; }
170 virtual ULONG STDMETHODCALLTYPE
Release( void);
172 bool QueryDrop(DWORD grfKeyState
, LPDWORD pdwEffect
);
173 virtual HRESULT STDMETHODCALLTYPE
DragEnter(
174 /* [unique][in] */ IDataObject __RPC_FAR
*pDataObj
,
175 /* [in] */ DWORD grfKeyState
,
176 /* [in] */ POINTL pt
,
177 /* [out][in] */ DWORD __RPC_FAR
*pdwEffect
);
178 virtual HRESULT STDMETHODCALLTYPE
DragOver(
179 /* [in] */ DWORD grfKeyState
,
180 /* [in] */ POINTL pt
,
181 /* [out][in] */ DWORD __RPC_FAR
*pdwEffect
);
182 virtual HRESULT STDMETHODCALLTYPE
DragLeave( void);
183 virtual HRESULT STDMETHODCALLTYPE
Drop(
184 /* [unique][in] */ IDataObject __RPC_FAR
*pDataObj
,
185 /* [in] */ DWORD grfKeyState
,
186 /* [in] */ POINTL pt
,
187 /* [out][in] */ DWORD __RPC_FAR
*pdwEffect
);
190 class CDragSourceHelper
192 IDragSourceHelper
* pDragSourceHelper
;
196 pDragSourceHelper
= NULL
;
197 if(FAILED(CoCreateInstance(CLSID_DragDropHelper
,
199 CLSCTX_INPROC_SERVER
,
200 IID_IDragSourceHelper
,
201 (void**)&pDragSourceHelper
)))
202 pDragSourceHelper
= NULL
;
204 virtual ~CDragSourceHelper()
206 if( pDragSourceHelper
!= NULL
)
208 pDragSourceHelper
->Release();
209 pDragSourceHelper
=NULL
;
214 HRESULT
InitializeFromBitmap(HBITMAP hBitmap
,
215 POINT
& pt
, // cursor position in client coords of the window
216 RECT
& rc
, // selected item's bounding rect
217 IDataObject
* pDataObject
,
218 COLORREF crColorKey
=GetSysColor(COLOR_WINDOW
)// color of the window used for transparent effect.
221 if(pDragSourceHelper
== NULL
)
226 GetObject(hBitmap
, sizeof(bm
), &bm
);
227 di
.sizeDragImage
.cx
= bm
.bmWidth
;
228 di
.sizeDragImage
.cy
= bm
.bmHeight
;
229 di
.hbmpDragImage
= hBitmap
;
230 di
.crColorKey
= crColorKey
;
231 di
.ptOffset
.x
= pt
.x
- rc
.left
;
232 di
.ptOffset
.y
= pt
.y
- rc
.top
;
233 return pDragSourceHelper
->InitializeFromBitmap(&di
, pDataObject
);
235 HRESULT
InitializeFromWindow(HWND hwnd
, POINT
& pt
,IDataObject
* pDataObject
)
237 if(pDragSourceHelper
== NULL
)
239 return pDragSourceHelper
->InitializeFromWindow(hwnd
, &pt
, pDataObject
);
242 #endif //__DRAGDROPIMPL_H__