GridDropTarget.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // GridDropTarget.cpp : implementation file
  2. //
  3. // MFC Grid Control - Drag/Drop target implementation
  4. //
  5. // CGridDropTarget is an OLE drop target for CGridCtrl. All it does
  6. // is handle the drag and drop windows messages and pass them
  7. // directly onto the grid control.
  8. //
  9. // Written by Chris Maunder <cmaunder@mail.com>
  10. // Copyright (c) 1998-2001. All Rights Reserved.
  11. //
  12. // This code may be used in compiled form in any way you desire. This
  13. // file may be redistributed unmodified by any means PROVIDING it is
  14. // not sold for profit without the authors written consent, and
  15. // providing that this notice and the authors name and all copyright
  16. // notices remains intact.
  17. //
  18. // An email letting me know how you are using it would be nice as well.
  19. //
  20. // This file is provided "as is" with no expressed or implied warranty.
  21. // The author accepts no liability for any damage/loss of business that
  22. // this product may cause.
  23. //
  24. // For use with CGridCtrl v2.10+
  25. //
  26. /////////////////////////////////////////////////////////////////////////////
  27. #include "stdafx.h"
  28. #include "GridCtrl.h"
  29. #ifndef GRIDCONTROL_NO_DRAGDROP
  30. #include "GridDropTarget.h"
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CGridDropTarget
  38. CGridDropTarget::CGridDropTarget()
  39. {
  40. m_pGridCtrl = NULL;
  41. m_bRegistered = FALSE;
  42. }
  43. CGridDropTarget::~CGridDropTarget()
  44. {
  45. }
  46. // Overloaded Register() function performs the normal COleDropTarget::Register
  47. // but also serves to connect this COleDropTarget with the parent grid control,
  48. // where all drop messages will ultimately be forwarded.
  49. BOOL CGridDropTarget::Register(CGridCtrl *pGridCtrl)
  50. {
  51. if (m_bRegistered)
  52. return FALSE;
  53. // Stop re-entry problems
  54. static BOOL bInProcedure = FALSE;
  55. if (bInProcedure)
  56. return FALSE;
  57. bInProcedure = TRUE;
  58. ASSERT(pGridCtrl->IsKindOf(RUNTIME_CLASS(CGridCtrl)));
  59. ASSERT(pGridCtrl);
  60. if (!pGridCtrl || !pGridCtrl->IsKindOf(RUNTIME_CLASS(CGridCtrl)))
  61. {
  62. bInProcedure = FALSE;
  63. return FALSE;
  64. }
  65. m_pGridCtrl = pGridCtrl;
  66. m_bRegistered = COleDropTarget::Register(pGridCtrl);
  67. bInProcedure = FALSE;
  68. return m_bRegistered;
  69. }
  70. void CGridDropTarget::Revoke()
  71. {
  72. m_bRegistered = FALSE;
  73. COleDropTarget::Revoke();
  74. }
  75. BEGIN_MESSAGE_MAP(CGridDropTarget, COleDropTarget)
  76. //{{AFX_MSG_MAP(CGridDropTarget)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CGridDropTarget message handlers
  81. DROPEFFECT CGridDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint /*point*/)
  82. {
  83. // TRACE("In CGridDropTarget::OnDragScroll\n");
  84. if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  85. {
  86. if (dwKeyState & MK_CONTROL)
  87. return DROPEFFECT_COPY;
  88. else
  89. return DROPEFFECT_MOVE;
  90. }
  91. else
  92. return DROPEFFECT_NONE;
  93. }
  94. DROPEFFECT CGridDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject,
  95. DWORD dwKeyState, CPoint point)
  96. {
  97. TRACE(_T("In CGridDropTarget::OnDragEnter\n"));
  98. ASSERT(m_pGridCtrl);
  99. if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  100. return m_pGridCtrl->OnDragEnter(pDataObject, dwKeyState, point);
  101. else
  102. return DROPEFFECT_NONE;
  103. }
  104. void CGridDropTarget::OnDragLeave(CWnd* pWnd)
  105. {
  106. TRACE(_T("In CGridDropTarget::OnDragLeave\n"));
  107. ASSERT(m_pGridCtrl);
  108. if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  109. m_pGridCtrl->OnDragLeave();
  110. }
  111. DROPEFFECT CGridDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject,
  112. DWORD dwKeyState, CPoint point)
  113. {
  114. // TRACE("In CGridDropTarget::OnDragOver\n");
  115. ASSERT(m_pGridCtrl);
  116. if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  117. return m_pGridCtrl->OnDragOver(pDataObject, dwKeyState, point);
  118. else
  119. return DROPEFFECT_NONE;
  120. }
  121. BOOL CGridDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
  122. DROPEFFECT dropEffect, CPoint point)
  123. {
  124. TRACE(_T("In CGridDropTarget::OnDrop\n"));
  125. ASSERT(m_pGridCtrl);
  126. if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  127. return m_pGridCtrl->OnDrop(pDataObject, dropEffect, point);
  128. else
  129. return FALSE;
  130. }
  131. #endif // GRIDCONTROL_NO_DRAGDROP