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.

330 lines
7.8 KiB

  1. //**********************************************************************
  2. // File name: IDS.CPP
  3. //
  4. // Implementation file for CDropSource
  5. //
  6. // Functions:
  7. //
  8. // See IDS.H for class definition
  9. //
  10. // Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "doc.h"
  14. #include "site.h"
  15. #include "dxferobj.h"
  16. //**********************************************************************
  17. //
  18. // CSimpleDoc::QueryDrag
  19. //
  20. // Purpose:
  21. //
  22. // Check to see if Drag operation should be initiated based on the
  23. // current position of the mouse.
  24. //
  25. // Parameters:
  26. //
  27. // POINT pt - position of mouse
  28. //
  29. // Return Value:
  30. //
  31. // BOOL - TRUE if drag should take place,
  32. // else FALSE
  33. //
  34. // Function Calls:
  35. // Function Location
  36. //
  37. // CSimpleSite::GetObjRect SITE.CPP
  38. // PtInRect Windows API
  39. //
  40. // Comments:
  41. //
  42. //********************************************************************
  43. BOOL CSimpleDoc::QueryDrag(POINT pt)
  44. {
  45. // if pt is within rect of object, then start drag
  46. if (m_lpSite)
  47. {
  48. RECT rect;
  49. m_lpSite->GetObjRect(&rect);
  50. return ( PtInRect(&rect, pt) ? TRUE : FALSE );
  51. }
  52. else
  53. return FALSE;
  54. }
  55. //**********************************************************************
  56. //
  57. // CSimpleDoc::DoDragDrop
  58. //
  59. // Purpose:
  60. //
  61. // Actually perform a drag/drop operation with the current
  62. // selection in the source document.
  63. //
  64. // Parameters:
  65. //
  66. // none.
  67. //
  68. // Return Value:
  69. //
  70. // DWORD - returns the result effect of the
  71. // drag/drop operation:
  72. // DROPEFFECT_NONE,
  73. // DROPEFFECT_COPY,
  74. // DROPEFFECT_MOVE, or
  75. // DROPEFFECT_LINK
  76. //
  77. // Function Calls:
  78. // Function Location
  79. //
  80. // CDataXferObj::Create DXFEROBJ.CPP
  81. // CDataXferObj::QueryInterface DXFEROBJ.CPP
  82. // CDataXferObj::Release DXFEROBJ.CPP
  83. // DoDragDrop OLE API
  84. // TestDebugOut Windows API
  85. //
  86. // Comments:
  87. //
  88. //********************************************************************
  89. DWORD CSimpleDoc::DoDragDrop (void)
  90. {
  91. DWORD dwEffect = 0;
  92. LPDATAOBJECT lpDataObj;
  93. TestDebugOut("In CSimpleDoc::DoDragDrop\r\n");
  94. // Create a data transfer object by cloning the existing OLE object
  95. CDataXferObj FAR* pDataXferObj = CDataXferObj::Create(m_lpSite,NULL);
  96. if (! pDataXferObj) {
  97. MessageBox(NULL,"Out-of-memory","SimpDnD",MB_SYSTEMMODAL|MB_ICONHAND);
  98. return DROPEFFECT_NONE;
  99. }
  100. // initially obj is created with 0 refcnt. this QI will make it go to 1.
  101. pDataXferObj->QueryInterface(IID_IDataObject, (LPVOID FAR*)&lpDataObj);
  102. assert(lpDataObj);
  103. m_fLocalDrop = FALSE;
  104. m_fLocalDrag = TRUE;
  105. ::DoDragDrop ( lpDataObj,
  106. &m_DropSource,
  107. DROPEFFECT_COPY, // we only allow copy
  108. &dwEffect
  109. );
  110. m_fLocalDrag = FALSE;
  111. /* if after the Drag/Drop modal (mouse capture) loop is finished
  112. ** and a drag MOVE operation was performed, then we must delete
  113. ** the selection that was dragged.
  114. */
  115. if ( (dwEffect & DROPEFFECT_MOVE) != 0 ) {
  116. // ... delete source object here (we do NOT support MOVE)
  117. }
  118. pDataXferObj->Release(); // this should destroy the DataXferObj
  119. return dwEffect;
  120. }
  121. //**********************************************************************
  122. //
  123. // CDropSource::QueryInterface
  124. //
  125. // Purpose:
  126. //
  127. // Return a pointer to a requested interface
  128. //
  129. // Parameters:
  130. //
  131. // REFIID riid - ID of interface to be returned
  132. // LPVOID FAR* ppvObj - Location to return the interface
  133. //
  134. // Return Value:
  135. //
  136. // S_OK - Interface supported
  137. // E_NOINTERFACE - Interface NOT supported
  138. //
  139. // Function Calls:
  140. // Function Location
  141. //
  142. // TestDebugOut Windows API
  143. // CSimpleDoc::QueryInterface DOC.CPP
  144. //
  145. // Comments:
  146. //
  147. //********************************************************************
  148. STDMETHODIMP CDropSource::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  149. {
  150. TestDebugOut("In IDS::QueryInterface\r\n");
  151. // delegate to the document
  152. return m_pDoc->QueryInterface(riid, ppvObj);
  153. }
  154. //**********************************************************************
  155. //
  156. // CDropSource::AddRef
  157. //
  158. // Purpose:
  159. //
  160. // Increments the reference count on this interface
  161. //
  162. // Parameters:
  163. //
  164. // None
  165. //
  166. // Return Value:
  167. //
  168. // The current reference count on this interface.
  169. //
  170. // Function Calls:
  171. // Function Location
  172. //
  173. // CSimpleObj::AddReff OBJ.CPP
  174. // TestDebugOut Windows API
  175. //
  176. // Comments:
  177. //
  178. // This function adds one to the ref count of the interface,
  179. // and calls then calls CSimpleDoc to increment its ref.
  180. // count.
  181. //
  182. //********************************************************************
  183. STDMETHODIMP_(ULONG) CDropSource::AddRef()
  184. {
  185. TestDebugOut("In IDS::AddRef\r\n");
  186. // increment the interface reference count (for debugging only)
  187. ++m_nCount;
  188. // delegate to the document Object
  189. return m_pDoc->AddRef();
  190. }
  191. //**********************************************************************
  192. //
  193. // CDropSource::Release
  194. //
  195. // Purpose:
  196. //
  197. // Decrements the reference count on this interface
  198. //
  199. // Parameters:
  200. //
  201. // None
  202. //
  203. // Return Value:
  204. //
  205. // The current reference count on this interface.
  206. //
  207. // Function Calls:
  208. // Function Location
  209. //
  210. // CSimpleObj::Release OBJ.CPP
  211. // TestDebugOut Windows API
  212. //
  213. // Comments:
  214. //
  215. // This function subtracts one from the ref count of the interface,
  216. // and calls then calls CSimpleDoc to decrement its ref.
  217. // count.
  218. //
  219. //********************************************************************
  220. STDMETHODIMP_(ULONG) CDropSource::Release()
  221. {
  222. TestDebugOut("In IDS::Release\r\n");
  223. // decrement the interface reference count (for debugging only)
  224. --m_nCount;
  225. // delegate to the document object
  226. return m_pDoc->Release();
  227. }
  228. //**********************************************************************
  229. //
  230. // CDropSource::QueryContinueDrag
  231. //
  232. // Purpose:
  233. //
  234. // Called to determine if a drop should take place or be canceled.
  235. //
  236. // Parameters:
  237. //
  238. // BOOL fEscapePressed - TRUE if ESCAPE key has been pressed
  239. // DWORD grfKeyState - key state
  240. //
  241. // Return Value:
  242. //
  243. // DRAGDROP_S_CANCEL - drag operation should be canceled
  244. // DRAGDROP_S_DROP - drop operation should be performed
  245. // S_OK - dragging should continue
  246. //
  247. //
  248. // Function Calls:
  249. // Function Location
  250. //
  251. // ResultFromScode OLE API
  252. //
  253. // Comments:
  254. //
  255. //********************************************************************
  256. STDMETHODIMP CDropSource::QueryContinueDrag (
  257. BOOL fEscapePressed,
  258. DWORD grfKeyState
  259. )
  260. {
  261. if (fEscapePressed)
  262. return ResultFromScode(DRAGDROP_S_CANCEL);
  263. else if (!(grfKeyState & MK_LBUTTON))
  264. return ResultFromScode(DRAGDROP_S_DROP);
  265. else
  266. return NOERROR;
  267. }
  268. //**********************************************************************
  269. //
  270. // CDropSource::GiveFeedback
  271. //
  272. // Purpose:
  273. //
  274. // Called to set cursor feedback
  275. //
  276. // Parameters:
  277. //
  278. // DWORD dwEffect - drop operation to give feedback for
  279. //
  280. // Return Value:
  281. //
  282. // DRAGDROP_S_USEDEFAULTCURSORS - tells OLE to use standard cursors
  283. //
  284. // Function Calls:
  285. // Function Location
  286. //
  287. // ResultFromScode OLE API
  288. //
  289. // Comments:
  290. //
  291. //********************************************************************
  292. STDMETHODIMP CDropSource::GiveFeedback (DWORD dwEffect)
  293. {
  294. return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
  295. }