GridDropTarget.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // GridDropTarget.cpp : implementation file
  2. //
  3. // CGridDropTarget is an OLE drop target for CGridCtrl. All it does
  4. // is handle the drag and drop windows messages and pass them
  5. // directly onto the grid control.
  6. //
  7. // Written by Chris Maunder 
  8. //        mailto:chrismaunder@codeguru.com
  9. //
  10. // Copyright (c) 1998.
  11. #include "stdafx.h"
  12. #include "GridCtrl.h"
  13. #ifndef GRIDCONTROL_NO_DRAGDROP
  14. #include "GridDropTarget.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CGridDropTarget
  22. CGridDropTarget::CGridDropTarget()
  23. {
  24.     m_pGridCtrl = NULL;
  25.     m_bRegistered = FALSE;
  26. }
  27. CGridDropTarget::~CGridDropTarget()
  28. {
  29. }
  30. // Overloaded Register() function performs the normal COleDropTarget::Register
  31. // but also serves to connect this COleDropTarget with the parent grid control,
  32. // where all drop messages will ultimately be forwarded.
  33. BOOL CGridDropTarget::Register(CGridCtrl *pGridCtrl)
  34. {
  35.     if (m_bRegistered) return FALSE;
  36.     ASSERT(pGridCtrl->IsKindOf(RUNTIME_CLASS(CGridCtrl)));
  37.     ASSERT(pGridCtrl);
  38.     if (!pGridCtrl || !pGridCtrl->IsKindOf(RUNTIME_CLASS(CGridCtrl)))
  39.         return FALSE;
  40.     m_pGridCtrl = pGridCtrl;
  41.     m_bRegistered = COleDropTarget::Register(pGridCtrl);
  42.     return m_bRegistered;
  43. }
  44. void CGridDropTarget::Revoke()
  45. {
  46.     m_bRegistered = FALSE;
  47.     COleDropTarget::Revoke();
  48. }
  49. BEGIN_MESSAGE_MAP(CGridDropTarget, COleDropTarget)
  50.     //{{AFX_MSG_MAP(CGridDropTarget)
  51.     //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CGridDropTarget message handlers
  55. DROPEFFECT CGridDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint /*point*/)
  56. {
  57. //    TRACE("In CGridDropTarget::OnDragScrolln");
  58.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  59.     {
  60.         if (dwKeyState & MK_CONTROL)
  61.             return DROPEFFECT_COPY;
  62.         else
  63.             return DROPEFFECT_MOVE;
  64.     } else
  65.         return DROPEFFECT_NONE;
  66. }
  67. DROPEFFECT CGridDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, 
  68.                                         DWORD dwKeyState, CPoint point)
  69. {
  70.     TRACE(_T("In CGridDropTarget::OnDragEntern"));
  71.     ASSERT(m_pGridCtrl);
  72.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  73.         return m_pGridCtrl->OnDragEnter(pDataObject, dwKeyState, point);
  74.     else
  75.         return DROPEFFECT_NONE;
  76. }
  77. void CGridDropTarget::OnDragLeave(CWnd* pWnd)
  78. {
  79.     TRACE(_T("In CGridDropTarget::OnDragLeaven"));
  80.     ASSERT(m_pGridCtrl);
  81.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  82.         m_pGridCtrl->OnDragLeave();
  83. }
  84. DROPEFFECT CGridDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, 
  85.                                        DWORD dwKeyState, CPoint point)
  86. {
  87. //    TRACE("In CGridDropTarget::OnDragOvern");
  88.     ASSERT(m_pGridCtrl);
  89.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  90.         return m_pGridCtrl->OnDragOver(pDataObject, dwKeyState, point);
  91.     else
  92.         return DROPEFFECT_NONE;
  93. }
  94. BOOL CGridDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
  95.                              DROPEFFECT dropEffect, CPoint point)
  96. {
  97.     TRACE(_T("In CGridDropTarget::OnDropn"));
  98.     ASSERT(m_pGridCtrl);
  99.     if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
  100.         return m_pGridCtrl->OnDrop(pDataObject, dropEffect, point);
  101.     else
  102.         return FALSE;
  103. }
  104. #endif // GRIDCONTROL_NO_DRAGDROP