Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

428 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: drag.h
  7. //
  8. // Contents: Classes used in drag operation
  9. //
  10. // Classes: CPoint
  11. // CDragDefaultCursors
  12. // CDragOperation
  13. // CWin31DropTarget
  14. //
  15. // History: dd-mmm-yy Author Comment
  16. // 20-Oct-94 alexgo added CWin31DropTarget to handle Win3.1
  17. // style drag drop
  18. // 21-Apr-94 ricksa split out from drag.cpp
  19. //
  20. // Notes: This exists as a separate file to facilitate the special
  21. // processing required for WM_CANCELMODE during drag/drop.
  22. //
  23. //--------------------------------------------------------------------------
  24. #ifndef _DRAG_H
  25. #define _DRAG_H
  26. void DragDropProcessUninitialize(void);
  27. //+-------------------------------------------------------------------------
  28. //
  29. // Class: CPoint
  30. //
  31. // Purpose: Handles strangness of the POINTL & POINT structures.
  32. //
  33. // Interface: Set - set value of data
  34. // GetPOINT - return a reference to a POINT structure
  35. // GetPOINTL - return a reference to a POINTL structure
  36. // GetAddressOfPOINT - return address of point structure
  37. //
  38. // History: dd-mmm-yy Author Comment
  39. // 04-Apr-94 Ricksa Created
  40. //
  41. // Notes: This class is created because we have two structures
  42. // that are exactly the same in Win32 but have different
  43. // types. This class will have to be modified for use
  44. // in Win16 if we ever do that again.
  45. //
  46. //--------------------------------------------------------------------------
  47. class CPoint
  48. {
  49. public:
  50. CPoint(void);
  51. void Set(LONG x, LONG y);
  52. POINT& GetPOINT(void);
  53. POINTL& GetPOINTL(void);
  54. POINT * GetAddressOfPOINT(void);
  55. private:
  56. POINT _pt;
  57. };
  58. //+-------------------------------------------------------------------------
  59. //
  60. // Function: CPoint::CPoint
  61. //
  62. // Synopsis: Initialize object to zero
  63. //
  64. // History: dd-mmm-yy Author Comment
  65. // 04-Apr-94 Ricksa Created
  66. //
  67. //--------------------------------------------------------------------------
  68. inline CPoint::CPoint(void)
  69. {
  70. _pt.x = 0;
  71. _pt.y = 0;
  72. }
  73. //+-------------------------------------------------------------------------
  74. //
  75. // Function: CPoint::Set
  76. //
  77. // Synopsis: Set value of structure
  78. //
  79. // History: dd-mmm-yy Author Comment
  80. // 04-Apr-94 Ricksa Created
  81. //
  82. //--------------------------------------------------------------------------
  83. inline void CPoint::Set(LONG x, LONG y)
  84. {
  85. _pt.x = x;
  86. _pt.y = y;
  87. }
  88. //+-------------------------------------------------------------------------
  89. //
  90. // Function: CPoint::GetPOINT
  91. //
  92. // Synopsis: Return a reference to a POINT type for function calls
  93. //
  94. // History: dd-mmm-yy Author Comment
  95. // 04-Apr-94 Ricksa Created
  96. //
  97. //--------------------------------------------------------------------------
  98. inline POINT& CPoint::GetPOINT(void)
  99. {
  100. return _pt;
  101. }
  102. //+-------------------------------------------------------------------------
  103. //
  104. // Function: CPoint::GetPOINTL
  105. //
  106. // Synopsis: Return a reference to a POINTL type for function calls
  107. //
  108. // History: dd-mmm-yy Author Comment
  109. // 04-Apr-94 Ricksa Created
  110. //
  111. //--------------------------------------------------------------------------
  112. inline POINTL& CPoint::GetPOINTL(void)
  113. {
  114. return *((POINTL *) &_pt);
  115. }
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Function: CPoint::GetAddressOfPOINT
  119. //
  120. // Synopsis: Return address of POINT type for function calls
  121. //
  122. // History: dd-mmm-yy Author Comment
  123. // 04-Apr-94 Ricksa Created
  124. //
  125. //--------------------------------------------------------------------------
  126. inline POINT *CPoint::GetAddressOfPOINT(void)
  127. {
  128. return &_pt;
  129. }
  130. //+-------------------------------------------------------------------------
  131. //
  132. // Class: CDragDefaultCursors
  133. //
  134. // Purpose: Handles init/setting default drag cursors
  135. //
  136. // Interface: NeedInit - whether object needs to be initialized
  137. // Init - does initialization
  138. // SetCursor - sets cursor to appropriate default
  139. //
  140. // History: dd-mmm-yy Author Comment
  141. // 19-Apr-94 Ricksa Created
  142. //
  143. // Notes: This class specifically avoids a constructor and depends
  144. // on the behavior of of static data being initialized to
  145. // NULL. The reason for this is two fold: (1) it makes start
  146. // up faster by avoiding a page fault when the constructor
  147. // would be called and (2) it allows this ole32 to be loaded
  148. // at boot time before cursors exist.
  149. //
  150. //--------------------------------------------------------------------------
  151. class CDragDefaultCursors : public CPrivAlloc
  152. {
  153. public:
  154. BOOL Init(void);
  155. void SetCursor(DWORD dwEffect);
  156. void SetCursorNone(void);
  157. static CDragDefaultCursors *GetDefaultCursorObject(void);
  158. private:
  159. enum SCROLL_TYPE {NO_SCROLL, SCROLL};
  160. enum CURSOR_ID {NO_DROP, MOVE_DROP, COPY_DROP, LINK_DROP};
  161. HCURSOR ahcursorDefaults[2][4];
  162. };
  163. //+-------------------------------------------------------------------------
  164. //
  165. // Function: CDragDefaultCursors::SetCursorNone
  166. //
  167. // Synopsis: Set the cursor to none
  168. //
  169. // History: dd-mmm-yy Author Comment
  170. // 19-Apr-94 Ricksa Created
  171. //
  172. //--------------------------------------------------------------------------
  173. inline void CDragDefaultCursors::SetCursorNone(void)
  174. {
  175. ::SetCursor(ahcursorDefaults[NO_SCROLL][NO_DROP]);
  176. }
  177. //+-------------------------------------------------------------------------
  178. //
  179. // Class: CDragOperation
  180. //
  181. // Purpose: Handles breaking down drag operation into managable pieces
  182. //
  183. // Interface: UpdateTarget - update where we are trying to drop
  184. // HandleFeedBack - handle cursor feedback
  185. // DragOver - handle dragging object over target
  186. // HandleMessages - Handle windows messages
  187. // CompleteDrop - Do drop or clean up
  188. // CancelDrag - notify operation that drag is canceled.
  189. // ReleaseCapture - release capture on the mouse
  190. // GetDropTarget - get target for drop
  191. //
  192. // History: dd-mmm-yy Author Comment
  193. // 04-Apr-94 Ricksa Created
  194. //
  195. //--------------------------------------------------------------------------
  196. class CDragOperation
  197. {
  198. public:
  199. CDragOperation(
  200. LPDATAOBJECT pDataObject,
  201. LPDROPSOURCE pDropSource,
  202. DWORD dwOKEffects,
  203. DWORD FAR *pdwEffect,
  204. HRESULT& hr);
  205. ~CDragOperation(void);
  206. BOOL UpdateTarget(void);
  207. BOOL HandleFeedBack(HRESULT hr);
  208. BOOL DragOver(void);
  209. BOOL HandleMessages(void);
  210. HRESULT CompleteDrop(void);
  211. void CancelDrag(void);
  212. void ReleaseCapture(void);
  213. IFBuffer GetDOBuffer(void);
  214. private:
  215. void InitCursors(void);
  216. void InitScrollInt(void);
  217. HRESULT GetDropTarget(HWND hwnd31,HWND hwndDropTarget);
  218. LPDATAOBJECT _pDataObject;
  219. IFBuffer _DOBuffer; // a buffer for the marshalled
  220. // data object
  221. LPDROPSOURCE _pDropSource;
  222. LPDROPTARGET _pDropTarget;
  223. LPDROPTARGET _pRealDropTarget;
  224. HANDLE _hFormats;
  225. CPoint _cpt;
  226. DWORD _dwOKEffects;
  227. DWORD FAR * _pdwEffect;
  228. BOOL _fEscapePressed;
  229. HCURSOR _curOld;
  230. HWND _hwndLast;
  231. DWORD _grfKeyState;
  232. HRESULT _hrDragResult;
  233. BOOL _fReleasedCapture;
  234. CDragDefaultCursors* _pcddcDefault;
  235. BOOL _fUseWin31;
  236. static LONG s_wScrollInt;
  237. };
  238. //+-------------------------------------------------------------------------
  239. //
  240. // Function: CDragOperation::ReleaseCapture
  241. //
  242. // Synopsis: Tell clipboard window to turn off mouse capture if we haven't
  243. // already done so.
  244. //
  245. // History: dd-mmm-yy Author Comment
  246. // 07-Jul-94 Ricksa Created
  247. //
  248. //--------------------------------------------------------------------------
  249. inline void CDragOperation::ReleaseCapture(void)
  250. {
  251. if (!_fReleasedCapture)
  252. {
  253. _fReleasedCapture = TRUE;
  254. ClipReleaseCaptureForDrag();
  255. }
  256. }
  257. //+-------------------------------------------------------------------------
  258. //
  259. // Member: CDragOperation::GetDOBuffer
  260. //
  261. // Synopsis: returns the interface buffer for the marshalled
  262. // data object interface
  263. //
  264. // Effects:
  265. //
  266. // Arguments:
  267. //
  268. // Requires:
  269. //
  270. // Returns: IFBuffer *
  271. //
  272. // Signals:
  273. //
  274. // Modifies:
  275. //
  276. // Derivation:
  277. //
  278. // Algorithm:
  279. //
  280. // History: dd-mmm-yy Author Comment
  281. // 02-Dec-94 alexgo author
  282. //
  283. // Notes:
  284. //
  285. //--------------------------------------------------------------------------
  286. inline IFBuffer CDragOperation::GetDOBuffer(void)
  287. {
  288. return _DOBuffer;
  289. }
  290. //+-------------------------------------------------------------------------
  291. //
  292. // Class: CDropTarget
  293. //
  294. // Purpose: Implements IDropTarget for the DoDragLoop. This class
  295. // will either delegate to a real drop target (registered
  296. // with RegisterDragDrop) or translate IDropTarget methods
  297. // into the Win3.1 drag drop protocol.
  298. //
  299. // Interface: IDropTarget
  300. //
  301. // History: dd-mmm-yy Author Comment
  302. // 20-Oct-94 alexgo author
  303. //
  304. // Notes: This class is NOT thread safe, nor is it safe to pass
  305. // outside of the CDragOperation class (which is why
  306. // QueryInterface is not implemented). As long as
  307. // DoDropDrag works by a modal loop on the calling thread,
  308. // this should not have to change.
  309. //
  310. //--------------------------------------------------------------------------
  311. class CDropTarget : public IDropTarget, public CPrivAlloc
  312. {
  313. public:
  314. STDMETHOD(QueryInterface) (REFIID riid, LPVOID *ppv);
  315. STDMETHOD_(ULONG, AddRef) (void);
  316. STDMETHOD_(ULONG, Release) (void);
  317. STDMETHOD(DragEnter) (IDataObject *pDataObject, DWORD grfKeyState,
  318. POINTL ptl, DWORD *pdwEffect);
  319. STDMETHOD(DragOver) (DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect);
  320. STDMETHOD(DragLeave) (void);
  321. STDMETHOD(Drop) (IDataObject *pDataObject, DWORD grfKeyState, POINTL pt,
  322. DWORD *pdwEffect);
  323. private:
  324. CDropTarget(HWND hwnd31, HWND hwndOLE, DWORD _dwEffectLast,
  325. CDragOperation *pdo, DDInfo hDDInfo);
  326. ~CDropTarget();
  327. HWND _hwndOLE;
  328. HWND _hwnd31;
  329. DWORD _dwEffectLast;
  330. ULONG _crefs;
  331. CDragOperation * _pdo;
  332. DDInfo _hDDInfo;
  333. // make CDragOperation a friend so it can create an instance of our
  334. // class (the constructor is private)
  335. friend class CDragOperation;
  336. };
  337. #endif // _DRAG_H