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.

384 lines
9.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 "app.h"
  14. #include "doc.h"
  15. #include "site.h"
  16. #include "dxferobj.h"
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Member: CSimpleDoc::FailureNotifyHelper(
  20. //
  21. // Synopsis: Report a drag drop error
  22. //
  23. // Arguments: [pszMsg] - Message
  24. // [dwData] - Data to print out
  25. //
  26. // Algorithm: Print a message box for fatal errors during drag drop
  27. // operation.
  28. //
  29. // History: dd-mmm-yy Author Comment
  30. // 06-May-94 Ricksa author
  31. //
  32. //--------------------------------------------------------------------------
  33. void CSimpleDoc::FailureNotifyHelper(TCHAR *pszMsg, DWORD dwData)
  34. {
  35. TCHAR pszBuf[256];
  36. wsprintf(pszBuf, TEXT("%s %lx"), pszMsg, dwData);
  37. MessageBox(m_hDocWnd, pszBuf, TEXT("Drag/Drop Error"), MB_OK);
  38. }
  39. //**********************************************************************
  40. //
  41. // CSimpleDoc::QueryDrag
  42. //
  43. // Purpose:
  44. //
  45. // Check to see if Drag operation should be initiated based on the
  46. // current position of the mouse.
  47. //
  48. // Parameters:
  49. //
  50. // POINT pt - position of mouse
  51. //
  52. // Return Value:
  53. //
  54. // BOOL - TRUE if drag should take place,
  55. // else FALSE
  56. //
  57. // Function Calls:
  58. // Function Location
  59. //
  60. // CSimpleSite::GetObjRect SITE.CPP
  61. // PtInRect Windows API
  62. //
  63. //
  64. //********************************************************************
  65. BOOL CSimpleDoc::QueryDrag(POINT pt)
  66. {
  67. // if pt is within rect of object, then start drag
  68. if (m_lpSite)
  69. {
  70. RECT rect;
  71. m_lpSite->GetObjRect(&rect);
  72. return ( PtInRect(&rect, pt) ? TRUE : FALSE );
  73. }
  74. else
  75. return FALSE;
  76. }
  77. //**********************************************************************
  78. //
  79. // CSimpleDoc::DoDragDrop
  80. //
  81. // Purpose:
  82. //
  83. // Actually perform a drag/drop operation with the current
  84. // selection in the source document.
  85. //
  86. // Parameters:
  87. //
  88. // none.
  89. //
  90. // Return Value:
  91. //
  92. // DWORD - returns the result effect of the
  93. // drag/drop operation:
  94. // DROPEFFECT_NONE,
  95. // DROPEFFECT_COPY,
  96. // DROPEFFECT_MOVE, or
  97. // DROPEFFECT_LINK
  98. //
  99. // Function Calls:
  100. // Function Location
  101. //
  102. // CDataXferObj::Create DXFEROBJ.CPP
  103. // CDataXferObj::QueryInterface DXFEROBJ.CPP
  104. // CDataXferObj::Release DXFEROBJ.CPP
  105. // DoDragDrop OLE API
  106. // TestDebugOut Windows API
  107. // MessageBox Windows API
  108. //
  109. //
  110. //********************************************************************
  111. DWORD CSimpleDoc::DoDragDrop (void)
  112. {
  113. DWORD dwEffect = 0;
  114. LPDATAOBJECT lpDataObj;
  115. TestDebugOut("In CSimpleDoc::DoDragDrop\r\n");
  116. // Create a data transfer object by cloning the existing OLE object
  117. CDataXferObj FAR* pDataXferObj = CDataXferObj::Create(m_lpSite,NULL);
  118. if (! pDataXferObj)
  119. {
  120. MessageBox(NULL, TEXT("Out-of-memory"), TEXT("SimpDnD"),
  121. MB_SYSTEMMODAL | MB_ICONHAND);
  122. return DROPEFFECT_NONE;
  123. }
  124. // initially obj is created with 0 refcnt. this QI will make it go to 1.
  125. pDataXferObj->QueryInterface(IID_IDataObject, (LPVOID FAR*)&lpDataObj);
  126. assert(lpDataObj);
  127. m_fLocalDrop = FALSE;
  128. m_fLocalDrag = TRUE;
  129. HRESULT hRes;
  130. hRes=::DoDragDrop(lpDataObj,
  131. &m_DropSource,
  132. m_lpApp->m_dwSourceEffect, // we only allow copy
  133. &dwEffect);
  134. if (hRes!=ResultFromScode(S_OK)
  135. && hRes!=ResultFromScode(DRAGDROP_S_DROP)
  136. && hRes!=ResultFromScode(DRAGDROP_S_CANCEL))
  137. {
  138. FailureNotifyHelper(
  139. TEXT("Unexpected error from DoDragDrop"), hRes);
  140. }
  141. // Validate the responses
  142. if (hRes == ResultFromScode(DRAGDROP_S_DROP))
  143. {
  144. // Drop was successful so make sure the effects make sense
  145. if (((dwEffect & m_lpApp->m_dwSourceEffect) == 0)
  146. && (dwEffect != DROPEFFECT_NONE))
  147. {
  148. FailureNotifyHelper(
  149. TEXT("Unexpected Effect on DRAGDROP_S_DROP from DoDragDrop"),
  150. dwEffect);
  151. }
  152. }
  153. else if ((hRes == ResultFromScode(DRAGDROP_S_CANCEL))
  154. || (hRes == ResultFromScode(S_OK)))
  155. {
  156. // Drop was cancelled/or never happened so the effect s/b none
  157. if (dwEffect != DROPEFFECT_NONE)
  158. {
  159. FailureNotifyHelper(
  160. TEXT("Unexpected Effect on S_OK or Cancel from DoDragDrop"),
  161. dwEffect);
  162. }
  163. }
  164. m_fLocalDrag = FALSE;
  165. /* if after the Drag/Drop modal (mouse capture) loop is finished
  166. ** and a drag MOVE operation was performed, then we must delete
  167. ** the selection that was dragged.
  168. */
  169. if ( (dwEffect & DROPEFFECT_MOVE) != 0 )
  170. {
  171. // Dump our object - we never save it.
  172. m_lpApp->lCreateDoc(m_lpApp->m_hAppWnd, 0, 0, 0);
  173. }
  174. pDataXferObj->Release(); // this should destroy the DataXferObj
  175. return dwEffect;
  176. }
  177. //**********************************************************************
  178. //
  179. // CDropSource::QueryInterface
  180. //
  181. // Purpose:
  182. //
  183. // Return a pointer to a requested interface
  184. //
  185. // Parameters:
  186. //
  187. // REFIID riid - ID of interface to be returned
  188. // LPVOID FAR* ppvObj - Location to return the interface
  189. //
  190. // Return Value:
  191. //
  192. // S_OK - Interface supported
  193. // E_NOINTERFACE - Interface NOT supported
  194. //
  195. // Function Calls:
  196. // Function Location
  197. //
  198. // TestDebugOut Windows API
  199. // CSimpleDoc::QueryInterface DOC.CPP
  200. //
  201. //
  202. //********************************************************************
  203. STDMETHODIMP CDropSource::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  204. {
  205. TestDebugOut("In IDS::QueryInterface\r\n");
  206. // delegate to the document
  207. return m_pDoc->QueryInterface(riid, ppvObj);
  208. }
  209. //**********************************************************************
  210. //
  211. // CDropSource::AddRef
  212. //
  213. // Purpose:
  214. //
  215. // Increments the reference count of CSimpleDoc. Since CDropSource is
  216. // a nested class of CSimpleDoc, we don't need a separate reference
  217. // count for the CDropSource. We can safely use the reference count
  218. // of CSimpleDoc here.
  219. //
  220. // Parameters:
  221. //
  222. // None
  223. //
  224. // Return Value:
  225. //
  226. // The new reference count of CSimpleDoc
  227. //
  228. // Function Calls:
  229. // Function Location
  230. //
  231. // CSimpleDoc::AddRef DOC.CPP
  232. // TestDebugOut Windows API
  233. //
  234. //
  235. //********************************************************************
  236. STDMETHODIMP_(ULONG) CDropSource::AddRef()
  237. {
  238. TestDebugOut("In IDS::AddRef\r\n");
  239. // delegate to the document Object
  240. return m_pDoc->AddRef();
  241. }
  242. //**********************************************************************
  243. //
  244. // CDropSource::Release
  245. //
  246. // Purpose:
  247. //
  248. // Decrements the reference count of CSimpleDoc. Since CDropSource is
  249. // a nested class of CSimpleDoc, we don't need a separate reference
  250. // count for the CDropSource. We can safely use the reference count
  251. // of CSimpleDoc here.
  252. //
  253. // Parameters:
  254. //
  255. // None
  256. //
  257. // Return Value:
  258. //
  259. // The new reference count of CSimpleDoc
  260. //
  261. // Function Calls:
  262. // Function Location
  263. //
  264. // CSimpleDoc::Release DOC.CPP
  265. // TestDebugOut Windows API
  266. //
  267. //
  268. //********************************************************************
  269. STDMETHODIMP_(ULONG) CDropSource::Release()
  270. {
  271. TestDebugOut("In IDS::Release\r\n");
  272. // delegate to the document object
  273. return m_pDoc->Release();
  274. }
  275. //**********************************************************************
  276. //
  277. // CDropSource::QueryContinueDrag
  278. //
  279. // Purpose:
  280. //
  281. // Called to determine if a drop should take place or be canceled.
  282. //
  283. // Parameters:
  284. //
  285. // BOOL fEscapePressed - TRUE if ESCAPE key has been pressed
  286. // DWORD grfKeyState - key state
  287. //
  288. // Return Value:
  289. //
  290. // DRAGDROP_S_CANCEL - drag operation should be canceled
  291. // DRAGDROP_S_DROP - drop operation should be performed
  292. // S_OK - dragging should continue
  293. //
  294. //
  295. // Function Calls:
  296. // Function Location
  297. //
  298. // ResultFromScode OLE API
  299. //
  300. //
  301. //********************************************************************
  302. STDMETHODIMP CDropSource::QueryContinueDrag (
  303. BOOL fEscapePressed,
  304. DWORD grfKeyState
  305. )
  306. {
  307. if (fEscapePressed)
  308. return ResultFromScode(DRAGDROP_S_CANCEL);
  309. else
  310. if (!(grfKeyState & MK_LBUTTON))
  311. return ResultFromScode(DRAGDROP_S_DROP);
  312. else
  313. return NOERROR;
  314. }
  315. //**********************************************************************
  316. //
  317. // CDropSource::GiveFeedback
  318. //
  319. // Purpose:
  320. //
  321. // Called to set cursor feedback
  322. //
  323. // Parameters:
  324. //
  325. // DWORD dwEffect - drop operation to give feedback for
  326. //
  327. // Return Value:
  328. //
  329. // DRAGDROP_S_USEDEFAULTCURSORS - tells OLE to use standard cursors
  330. //
  331. // Function Calls:
  332. // Function Location
  333. //
  334. // ResultFromScode OLE API
  335. //
  336. //
  337. //********************************************************************
  338. STDMETHODIMP CDropSource::GiveFeedback (DWORD dwEffect)
  339. {
  340. return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
  341. }
  342.