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.

101 lines
2.3 KiB

  1. #include <windows.h>
  2. #include "dropsrc.h"
  3. #include "common.h"
  4. //-----------------------------------------------------------------
  5. typedef struct {
  6. IDropSource dsrc;
  7. UINT cRef;
  8. DWORD grfInitialKeyState;
  9. } CDropSource;
  10. IDropSourceVtbl c_CDropSourceVtbl; // forward decl
  11. HRESULT CDropSource_CreateInstance(IDropSource **ppdsrc)
  12. {
  13. CDropSource *this = (CDropSource *)LocalAlloc(LPTR, sizeof(CDropSource));
  14. if (this)
  15. {
  16. this->dsrc.lpVtbl = &c_CDropSourceVtbl;
  17. this->cRef = 1;
  18. *ppdsrc = &this->dsrc;
  19. return S_OK;
  20. }
  21. else
  22. {
  23. *ppdsrc = NULL;
  24. return E_OUTOFMEMORY;
  25. }
  26. }
  27. STDMETHODIMP CDropSource_QueryInterface(IDropSource *pdsrc, REFIID riid, void **ppvObj)
  28. {
  29. CDropSource *this = IToClass(CDropSource, dsrc, pdsrc);
  30. if (IsEqualIID(riid, &IID_IDropSource) || IsEqualIID(riid, &IID_IUnknown))
  31. {
  32. *ppvObj = this;
  33. this->cRef++;
  34. return S_OK;
  35. }
  36. *ppvObj = NULL;
  37. return E_NOINTERFACE;
  38. }
  39. STDMETHODIMP_(ULONG) CDropSource_AddRef(IDropSource *pdsrc)
  40. {
  41. CDropSource *this = IToClass(CDropSource, dsrc, pdsrc);
  42. this->cRef++;
  43. return this->cRef;
  44. }
  45. STDMETHODIMP_(ULONG) CDropSource_Release(IDropSource *pdsrc)
  46. {
  47. CDropSource *this = IToClass(CDropSource, dsrc, pdsrc);
  48. this->cRef--;
  49. if (this->cRef > 0)
  50. return this->cRef;
  51. LocalFree((HLOCAL)this);
  52. return 0;
  53. }
  54. STDMETHODIMP CDropSource_QueryContinueDrag(IDropSource *pdsrc, BOOL fEscapePressed, DWORD grfKeyState)
  55. {
  56. CDropSource *this = IToClass(CDropSource, dsrc, pdsrc);
  57. if (fEscapePressed)
  58. return DRAGDROP_S_CANCEL;
  59. // initialize ourself with the drag begin button
  60. if (this->grfInitialKeyState == 0)
  61. this->grfInitialKeyState = (grfKeyState & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON));
  62. Assert(this->grfInitialKeyState);
  63. if (!(grfKeyState & this->grfInitialKeyState))
  64. return DRAGDROP_S_DROP;
  65. else
  66. return S_OK;
  67. }
  68. STDMETHODIMP CDropSource_GiveFeedback(IDropSource *pdsrc, DWORD dwEffect)
  69. {
  70. CDropSource *this = IToClass(CDropSource, dsrc, pdsrc);
  71. return DRAGDROP_S_USEDEFAULTCURSORS;
  72. }
  73. IDropSourceVtbl c_CDropSourceVtbl = {
  74. CDropSource_QueryInterface, CDropSource_AddRef, CDropSource_Release,
  75. CDropSource_QueryContinueDrag,
  76. CDropSource_GiveFeedback
  77. };