150 lines
4.3 KiB
C++
150 lines
4.3 KiB
C++
// GridDropTarget.cpp : implementation file
|
|
//
|
|
// MFC Grid Control - Drag/Drop target implementation
|
|
//
|
|
// CMfcGridCtrlDropTarget is an OLE drop target for CMfcGridCtrl. All it does
|
|
// is handle the drag and drop windows messages and pass them
|
|
// directly onto the grid control.
|
|
//
|
|
// Written by Chris Maunder <cmaunder@mail.com>
|
|
// Copyright (c) 1998-2002. All Rights Reserved.
|
|
//
|
|
// This code may be used in compiled form in any way you desire. This
|
|
// file may be redistributed unmodified by any means PROVIDING it is
|
|
// not sold for profit without the authors written consent, and
|
|
// providing that this notice and the authors name and all copyright
|
|
// notices remains intact.
|
|
//
|
|
// An email letting me know how you are using it would be nice as well.
|
|
//
|
|
// This file is provided "as is" with no expressed or implied warranty.
|
|
// The author accepts no liability for any damage/loss of business that
|
|
// this product may cause.
|
|
//
|
|
// For use with CMfcGridCtrl v2.10+
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "MfcGridCtrl.h"
|
|
|
|
#ifndef GRIDCONTROL_NO_DRAGDROP
|
|
#include "MfcGridCtrlDropTarget.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
CMfcGridCtrlDropTarget::CMfcGridCtrlDropTarget()
|
|
{
|
|
m_pGridCtrl = NULL;
|
|
m_bRegistered = FALSE;
|
|
}
|
|
|
|
CMfcGridCtrlDropTarget::~CMfcGridCtrlDropTarget()
|
|
{
|
|
}
|
|
|
|
// Overloaded Register() function performs the normal COleDropTarget::Register
|
|
// but also serves to connect this COleDropTarget with the parent grid control,
|
|
// where all drop messages will ultimately be forwarded.
|
|
BOOL CMfcGridCtrlDropTarget::Register(CMfcGridCtrl *pGridCtrl)
|
|
{
|
|
if (m_bRegistered)
|
|
return FALSE;
|
|
|
|
// Stop re-entry problems
|
|
static BOOL bInProcedure = FALSE;
|
|
if (bInProcedure)
|
|
return FALSE;
|
|
bInProcedure = TRUE;
|
|
|
|
ASSERT(pGridCtrl->IsKindOf(RUNTIME_CLASS(CMfcGridCtrl)));
|
|
ASSERT(pGridCtrl);
|
|
|
|
if (!pGridCtrl || !pGridCtrl->IsKindOf(RUNTIME_CLASS(CMfcGridCtrl)))
|
|
{
|
|
bInProcedure = FALSE;
|
|
return FALSE;
|
|
}
|
|
|
|
m_pGridCtrl = pGridCtrl;
|
|
|
|
m_bRegistered = COleDropTarget::Register(pGridCtrl);
|
|
|
|
bInProcedure = FALSE;
|
|
return m_bRegistered;
|
|
}
|
|
|
|
void CMfcGridCtrlDropTarget::Revoke()
|
|
{
|
|
m_bRegistered = FALSE;
|
|
COleDropTarget::Revoke();
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CMfcGridCtrlDropTarget, COleDropTarget)
|
|
//{{AFX_MSG_MAP(CMfcGridCtrlDropTarget)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
DROPEFFECT CMfcGridCtrlDropTarget::OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint /*point*/)
|
|
{
|
|
// TRACE("In CMfcGridCtrlDropTarget::OnDragScroll\n");
|
|
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
|
|
{
|
|
if (dwKeyState & MK_CONTROL)
|
|
return DROPEFFECT_COPY;
|
|
else
|
|
return DROPEFFECT_MOVE;
|
|
} else
|
|
return DROPEFFECT_NONE;
|
|
}
|
|
|
|
DROPEFFECT CMfcGridCtrlDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DWORD dwKeyState, CPoint point)
|
|
{
|
|
TRACE(_T("In CMfcGridCtrlDropTarget::OnDragEnter\n"));
|
|
ASSERT(m_pGridCtrl);
|
|
|
|
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
|
|
return m_pGridCtrl->OnDragEnter(pDataObject, dwKeyState, point);
|
|
else
|
|
return DROPEFFECT_NONE;
|
|
}
|
|
|
|
void CMfcGridCtrlDropTarget::OnDragLeave(CWnd* pWnd)
|
|
{
|
|
TRACE(_T("In CMfcGridCtrlDropTarget::OnDragLeave\n"));
|
|
ASSERT(m_pGridCtrl);
|
|
|
|
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
|
|
m_pGridCtrl->OnDragLeave();
|
|
}
|
|
|
|
DROPEFFECT CMfcGridCtrlDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DWORD dwKeyState, CPoint point)
|
|
{
|
|
// TRACE("In CMfcGridCtrlDropTarget::OnDragOver\n");
|
|
ASSERT(m_pGridCtrl);
|
|
|
|
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
|
|
return m_pGridCtrl->OnDragOver(pDataObject, dwKeyState, point);
|
|
else
|
|
return DROPEFFECT_NONE;
|
|
}
|
|
|
|
BOOL CMfcGridCtrlDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DROPEFFECT dropEffect, CPoint point)
|
|
{
|
|
TRACE(_T("In CMfcGridCtrlDropTarget::OnDrop\n"));
|
|
ASSERT(m_pGridCtrl);
|
|
|
|
if (pWnd->GetSafeHwnd() == m_pGridCtrl->GetSafeHwnd())
|
|
return m_pGridCtrl->OnDrop(pDataObject, dropEffect, point);
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
#endif // GRIDCONTROL_NO_DRAGDROP
|