Navigate selection history via log jump up/down button
[TortoiseGit.git] / src / Utils / DragDropImpl.h
blob7f05e8d505207941318b5f891eddaf2dae1a7ae6
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
6 PARTICULAR PURPOSE.
7 Author: Leon Finker 1/2001
8 **************************************************************************/
9 #ifndef __DRAGDROPIMPL_H__
10 #define __DRAGDROPIMPL_H__
11 //#include <ShlDisp.h>
12 #include <shobjidl.h>
13 #include <shlobj.h>
15 ///////////////////////////////////////////////////////////////////////////////////////////////
16 class CDragSourceNotify : IDropSourceNotify
18 private:
19 LONG refCount;
21 public:
23 CDragSourceNotify(void)
25 refCount = 0;
28 ~CDragSourceNotify(void)
32 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
34 if(!ppvObject)
36 return E_POINTER;
39 if (IsEqualIID(riid, IID_IUnknown))
41 *ppvObject = static_cast<IUnknown*>(this);
43 else if (IsEqualIID(riid, IID_IDropSourceNotify))
45 *ppvObject = static_cast<IDropSourceNotify*>(this);
47 else
49 *ppvObject = NULL;
50 return E_NOINTERFACE;
53 AddRef();
54 return S_OK;
57 ULONG STDMETHODCALLTYPE AddRef(void)
59 return InterlockedIncrement(&refCount);
62 ULONG STDMETHODCALLTYPE Release(void)
64 ULONG ret = InterlockedDecrement(&refCount);
65 if(!ret) {
66 delete this;
68 return ret;
71 HRESULT STDMETHODCALLTYPE DragEnterTarget(HWND /*hWndTarget*/)
73 return S_OK;
76 HRESULT STDMETHODCALLTYPE DragLeaveTarget(void)
78 return S_OK;
84 ///////////////////////////////////////////////////////////////////////////////////////////////
85 class CEnumFormatEtc : public IEnumFORMATETC
87 private:
88 ULONG m_cRefCount;
89 CSimpleArray<FORMATETC> m_pFmtEtc;
90 int m_iCur;
92 public:
93 CEnumFormatEtc(const CSimpleArray<FORMATETC>& ArrFE);
94 CEnumFormatEtc(const CSimpleArray<FORMATETC*>& ArrFE);
95 //IUnknown members
96 STDMETHOD(QueryInterface)(REFIID, void FAR* FAR*);
97 STDMETHOD_(ULONG, AddRef)(void);
98 STDMETHOD_(ULONG, Release)(void);
100 //IEnumFORMATETC members
101 STDMETHOD(Next)(ULONG, LPFORMATETC, ULONG FAR *);
102 STDMETHOD(Skip)(ULONG);
103 STDMETHOD(Reset)(void);
104 STDMETHOD(Clone)(IEnumFORMATETC FAR * FAR*);
107 ///////////////////////////////////////////////////////////////////////////////////////////////
108 class CIDropSource : public IDropSource
110 long m_cRefCount;
111 public:
112 bool m_bDropped;
113 IDataObject * m_pIDataObj;
114 CDragSourceNotify* pDragSourceNotify;
117 CIDropSource():m_cRefCount(0),m_bDropped(false),m_pIDataObj(NULL)
119 pDragSourceNotify = new CDragSourceNotify();
120 pDragSourceNotify->AddRef();
122 ~CIDropSource()
124 if (m_pIDataObj)
126 m_pIDataObj->Release();
127 m_pIDataObj = NULL;
129 if (pDragSourceNotify)
131 pDragSourceNotify->Release();
132 pDragSourceNotify = NULL;
135 //IUnknown
136 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
137 /* [in] */ REFIID riid,
138 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
139 virtual ULONG STDMETHODCALLTYPE AddRef( void);
140 virtual ULONG STDMETHODCALLTYPE Release( void);
141 //IDropSource
142 virtual HRESULT STDMETHODCALLTYPE QueryContinueDrag(
143 /* [in] */ BOOL fEscapePressed,
144 /* [in] */ DWORD grfKeyState);
146 virtual HRESULT STDMETHODCALLTYPE GiveFeedback(
147 /* [in] */ DWORD dwEffect);
150 ///////////////////////////////////////////////////////////////////////////////////////////////
151 class CIDataObject : public IDataObject//,public IAsyncOperation
153 CIDropSource* m_pDropSource;
154 long m_cRefCount;
155 CSimpleArray<FORMATETC*> m_ArrFormatEtc;
156 CSimpleArray<STGMEDIUM*> m_StgMedium;
157 public:
158 CIDataObject(CIDropSource* pDropSource);
159 ~CIDataObject();
160 void CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc);
161 //IUnknown
162 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
163 /* [in] */ REFIID riid,
164 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
165 virtual ULONG STDMETHODCALLTYPE AddRef( void);
166 virtual ULONG STDMETHODCALLTYPE Release( void);
168 //IDataObject
169 virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetData(
170 /* [unique][in] */ FORMATETC __RPC_FAR *pformatetcIn,
171 /* [out] */ STGMEDIUM __RPC_FAR *pmedium);
173 virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetDataHere(
174 /* [unique][in] */ FORMATETC __RPC_FAR *pformatetc,
175 /* [out][in] */ STGMEDIUM __RPC_FAR *pmedium);
177 virtual HRESULT STDMETHODCALLTYPE QueryGetData(
178 /* [unique][in] */ FORMATETC __RPC_FAR *pformatetc);
180 virtual HRESULT STDMETHODCALLTYPE GetCanonicalFormatEtc(
181 /* [unique][in] */ FORMATETC __RPC_FAR *pformatectIn,
182 /* [out] */ FORMATETC __RPC_FAR *pformatetcOut);
184 virtual /* [local] */ HRESULT STDMETHODCALLTYPE SetData(
185 /* [unique][in] */ FORMATETC __RPC_FAR *pformatetc,
186 /* [unique][in] */ STGMEDIUM __RPC_FAR *pmedium,
187 /* [in] */ BOOL fRelease);
189 virtual HRESULT STDMETHODCALLTYPE EnumFormatEtc(
190 /* [in] */ DWORD dwDirection,
191 /* [out] */ IEnumFORMATETC __RPC_FAR *__RPC_FAR *ppenumFormatEtc);
193 virtual HRESULT STDMETHODCALLTYPE DAdvise(
194 /* [in] */ FORMATETC __RPC_FAR *pformatetc,
195 /* [in] */ DWORD advf,
196 /* [unique][in] */ IAdviseSink __RPC_FAR *pAdvSink,
197 /* [out] */ DWORD __RPC_FAR *pdwConnection);
199 virtual HRESULT STDMETHODCALLTYPE DUnadvise(
200 /* [in] */ DWORD dwConnection);
202 virtual HRESULT STDMETHODCALLTYPE EnumDAdvise(
203 /* [out] */ IEnumSTATDATA __RPC_FAR *__RPC_FAR *ppenumAdvise);
205 //IAsyncOperation
206 //virtual HRESULT STDMETHODCALLTYPE SetAsyncMode(
207 // /* [in] */ BOOL fDoOpAsync)
209 // return E_NOTIMPL;
212 //virtual HRESULT STDMETHODCALLTYPE GetAsyncMode(
213 // /* [out] */ BOOL __RPC_FAR *pfIsOpAsync)
215 // return E_NOTIMPL;
218 //virtual HRESULT STDMETHODCALLTYPE StartOperation(
219 // /* [optional][unique][in] */ IBindCtx __RPC_FAR *pbcReserved)
221 // return E_NOTIMPL;
224 //virtual HRESULT STDMETHODCALLTYPE InOperation(
225 // /* [out] */ BOOL __RPC_FAR *pfInAsyncOp)
227 // return E_NOTIMPL;
230 //virtual HRESULT STDMETHODCALLTYPE EndOperation(
231 // /* [in] */ HRESULT hResult,
232 // /* [unique][in] */ IBindCtx __RPC_FAR *pbcReserved,
233 // /* [in] */ DWORD dwEffects)
235 // return E_NOTIMPL;
239 // helper function
240 HRESULT SetDropDescription(DROPIMAGETYPE image, LPCTSTR format, LPCTSTR insert);
243 ///////////////////////////////////////////////////////////////////////////////////////////////
244 class CIDropTarget : public IDropTarget
246 DWORD m_cRefCount;
247 bool m_bAllowDrop;
248 IDropTargetHelper *m_pDropTargetHelper;
249 CSimpleArray<FORMATETC> m_formatetc;
250 FORMATETC* m_pSupportedFrmt;
251 protected:
252 HWND m_hTargetWnd;
253 IDataObject * m_pIDataObject;
254 public:
256 CIDropTarget(HWND m_hTargetWnd);
257 virtual ~CIDropTarget();
258 void AddSuportedFormat(FORMATETC& ftetc) { m_formatetc.Add(ftetc); }
260 //return values: true - release the medium. false - don't release the medium
261 virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium,DWORD *pdwEffect, POINTL pt) = 0;
263 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
264 /* [in] */ REFIID riid,
265 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
266 virtual ULONG STDMETHODCALLTYPE AddRef( void) { ATLTRACE("CIDropTarget::AddRef\n"); return ++m_cRefCount; }
267 virtual ULONG STDMETHODCALLTYPE Release( void);
269 bool QueryDrop(DWORD grfKeyState, LPDWORD pdwEffect);
270 virtual HRESULT STDMETHODCALLTYPE DragEnter(
271 /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
272 /* [in] */ DWORD grfKeyState,
273 /* [in] */ POINTL pt,
274 /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
275 virtual HRESULT STDMETHODCALLTYPE DragOver(
276 /* [in] */ DWORD grfKeyState,
277 /* [in] */ POINTL pt,
278 /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
279 virtual HRESULT STDMETHODCALLTYPE DragLeave( void);
280 virtual HRESULT STDMETHODCALLTYPE Drop(
281 /* [unique][in] */ IDataObject __RPC_FAR *pDataObj,
282 /* [in] */ DWORD grfKeyState,
283 /* [in] */ POINTL pt,
284 /* [out][in] */ DWORD __RPC_FAR *pdwEffect);
286 // helper function
287 HRESULT SetDropDescription(DROPIMAGETYPE image, LPCTSTR format, LPCTSTR insert);
290 class CDragSourceHelper
292 IDragSourceHelper2* pDragSourceHelper2;
293 IDragSourceHelper* pDragSourceHelper;
295 public:
296 CDragSourceHelper()
298 pDragSourceHelper = NULL;
299 pDragSourceHelper2 = NULL;
300 if(FAILED(CoCreateInstance(CLSID_DragDropHelper,
301 NULL,
302 CLSCTX_INPROC_SERVER,
303 IID_IDragSourceHelper2,
304 (void**)&pDragSourceHelper2)))
306 pDragSourceHelper2 = NULL;
307 if(FAILED(CoCreateInstance(CLSID_DragDropHelper,
308 NULL,
309 CLSCTX_INPROC_SERVER,
310 IID_IDragSourceHelper,
311 (void**)&pDragSourceHelper)))
312 pDragSourceHelper = NULL;
315 virtual ~CDragSourceHelper()
317 if( pDragSourceHelper2!= NULL )
319 pDragSourceHelper2->Release();
320 pDragSourceHelper2=NULL;
322 if( pDragSourceHelper!= NULL )
324 pDragSourceHelper->Release();
325 pDragSourceHelper=NULL;
329 // IDragSourceHelper
330 HRESULT InitializeFromBitmap(HBITMAP hBitmap,
331 POINT& pt, // cursor position in client coords of the window
332 RECT& rc, // selected item's bounding rect
333 IDataObject* pDataObject,
334 BOOL allowDropDescription=TRUE,
335 COLORREF crColorKey=GetSysColor(COLOR_WINDOW)// color of the window used for transparent effect.
338 if((pDragSourceHelper == NULL)&&(pDragSourceHelper2 == NULL))
339 return E_FAIL;
341 if ((allowDropDescription)&&(pDragSourceHelper2))
342 pDragSourceHelper2->SetFlags(DSH_ALLOWDROPDESCRIPTIONTEXT);
344 SHDRAGIMAGE di;
345 BITMAP bm;
346 GetObject(hBitmap, sizeof(bm), &bm);
347 di.sizeDragImage.cx = bm.bmWidth;
348 di.sizeDragImage.cy = bm.bmHeight;
349 di.hbmpDragImage = hBitmap;
350 di.crColorKey = crColorKey;
351 di.ptOffset.x = pt.x - rc.left;
352 di.ptOffset.y = pt.y - rc.top;
353 if (pDragSourceHelper2)
354 return pDragSourceHelper2->InitializeFromBitmap(&di, pDataObject);
355 if (pDragSourceHelper == NULL)
356 return E_FAIL;
357 return pDragSourceHelper->InitializeFromBitmap(&di, pDataObject);
359 HRESULT InitializeFromWindow(HWND hwnd, POINT& pt, IDataObject* pDataObject, BOOL allowDropDescription=TRUE)
361 if((pDragSourceHelper == NULL)&&(pDragSourceHelper2 == NULL))
362 return E_FAIL;
363 if ((allowDropDescription)&&(pDragSourceHelper2))
364 pDragSourceHelper2->SetFlags(DSH_ALLOWDROPDESCRIPTIONTEXT);
365 if (pDragSourceHelper2)
366 return pDragSourceHelper2->InitializeFromWindow(hwnd, &pt, pDataObject);
367 if (pDragSourceHelper == NULL)
368 return E_FAIL;
369 return pDragSourceHelper->InitializeFromWindow(hwnd, &pt, pDataObject);
372 #endif //__DRAGDROPIMPL_H__