156 lines
4.4 KiB
C++
156 lines
4.4 KiB
C++
// UserDropTarget.cpp: implementation of the CUserDropTarget class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "CorpSms.h"
|
|
#include "UserDropTarget.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#define RECT_BORDER 10
|
|
|
|
#include "CorpSmsDoc.h"
|
|
#include "FuncView.h"
|
|
|
|
HWND CUserDropTarget::m_shWndTreeCtrl = NULL;
|
|
long CUserDropTarget::m_lAddressType = -1;
|
|
CUserDropTarget::CUserDropTarget()
|
|
{
|
|
|
|
}
|
|
|
|
CUserDropTarget::~CUserDropTarget()
|
|
{
|
|
|
|
}
|
|
DROPEFFECT CUserDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DWORD dwKeyState, CPoint point)
|
|
{
|
|
DROPEFFECT dropeffectRet = DROPEFFECT_COPY;
|
|
if ( (dwKeyState & MK_SHIFT) == MK_SHIFT)
|
|
dropeffectRet = DROPEFFECT_MOVE;
|
|
return dropeffectRet;
|
|
}
|
|
|
|
DROPEFFECT CUserDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DWORD dwKeyState, CPoint point)
|
|
{
|
|
DROPEFFECT dropeffectRet = DROPEFFECT_COPY;
|
|
if ( (dwKeyState & MK_SHIFT) == MK_SHIFT)
|
|
dropeffectRet = DROPEFFECT_MOVE;
|
|
|
|
if ( m_shWndTreeCtrl != pWnd->GetSafeHwnd() ) //拖动的目标不是自己,应该是拖住发送列表的,不处理
|
|
return dropeffectRet;
|
|
|
|
// Expand and highlight the item under the mouse and
|
|
CTreeCtrl * pTreeCtrl = (CTreeCtrl *)pWnd;
|
|
HTREEITEM hTItem = pTreeCtrl->HitTest(point);
|
|
if ( hTItem != NULL && m_shWndTreeCtrl ) //判断只有在本通讯录内才可以自由拖动
|
|
{
|
|
CFuncView * pFuncView = (CFuncView*)CFuncView::FromHandle(m_shWndTreeCtrl);
|
|
if ( pFuncView->GetItemAddressType(hTItem)==m_lAddressType)
|
|
{
|
|
pTreeCtrl->Expand(hTItem, TVE_EXPAND);
|
|
pTreeCtrl->SelectDropTarget(hTItem);
|
|
}
|
|
}
|
|
// Scroll Tree control depending on mouse position
|
|
CRect rectClient;
|
|
pWnd->GetClientRect(&rectClient);
|
|
pWnd->ClientToScreen(rectClient);
|
|
pWnd->ClientToScreen(&point);
|
|
int nScrollDir = -1;
|
|
if ( point.y >= rectClient.bottom - RECT_BORDER)
|
|
nScrollDir = SB_LINEDOWN;
|
|
else
|
|
if ( (point.y <= rectClient.top + RECT_BORDER) )
|
|
nScrollDir = SB_LINEUP;
|
|
|
|
|
|
if ( nScrollDir != -1 )
|
|
{
|
|
int nScrollPos = pWnd->GetScrollPos(SB_VERT);
|
|
WPARAM wParam = MAKELONG(nScrollDir, nScrollPos);
|
|
pWnd->SendMessage(WM_VSCROLL, wParam);
|
|
}
|
|
|
|
nScrollDir = -1;
|
|
if ( point.x <= rectClient.left + RECT_BORDER )
|
|
nScrollDir = SB_LINELEFT;
|
|
else
|
|
if ( point.x >= rectClient.right - RECT_BORDER)
|
|
nScrollDir = SB_LINERIGHT;
|
|
|
|
if ( nScrollDir != -1 )
|
|
{
|
|
int nScrollPos = pWnd->GetScrollPos(SB_VERT);
|
|
WPARAM wParam = MAKELONG(nScrollDir, nScrollPos);
|
|
pWnd->SendMessage(WM_HSCROLL, wParam);
|
|
}
|
|
return dropeffectRet;
|
|
}
|
|
|
|
BOOL CUserDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DROPEFFECT dropEffect, CPoint point)
|
|
{
|
|
/*
|
|
if (pWnd->IsKindOf(RUNTIME_CLASS(CView)))//if CView,Call base class
|
|
return COleDropTarget::OnDrop(pWnd, pDataObject,dropEffect,point);
|
|
*/
|
|
if ( m_shWndTreeCtrl != pWnd->GetSafeHwnd() ) //拖动的目标不是自己,应该是拖住发送列表的,不处理
|
|
return ::SendMessage( pWnd->GetSafeHwnd(), DROPM_DROP, (WPARAM)pDataObject, 0 );
|
|
|
|
if ( !m_shWndTreeCtrl || !pWnd )
|
|
{
|
|
return false;
|
|
}
|
|
//处理拖动
|
|
CFuncView * pFuncView = (CFuncView*)CFuncView::FromHandle(m_shWndTreeCtrl);
|
|
CTreeCtrl * pTreeCtrl = (CTreeCtrl *)pWnd;
|
|
HTREEITEM hSelectedItem = pTreeCtrl->GetSelectedItem();
|
|
HTREEITEM hTDropItem =pTreeCtrl->GetDropHilightItem();
|
|
|
|
pFuncView->MoveItem(hSelectedItem,hTDropItem,m_lAddressType);
|
|
/*
|
|
// Get the image indexes from ImageList, if one exists
|
|
int nImage = 0;
|
|
int nSelImage = 0;
|
|
GetItemImages(hSelectedItem, nImage, nSelImage);
|
|
|
|
// Add the items to destination tree control
|
|
m_hDestItem = m_pDestTreeCtrl->AddItem(hTDropItem, m_pSourceTreeCtrl->GetItemText(hSelectedItem), TVI_LAST, nImage, nSelImage, 0);
|
|
AddItem(m_pSourceTreeCtrl->GetChildItem(hSelectedItem),m_hDestItem);
|
|
*/
|
|
//Remove highlighting
|
|
pTreeCtrl->SendMessage(TVM_SELECTITEM, TVGN_DROPHILITE,0);
|
|
|
|
return true;
|
|
}
|
|
|
|
void CUserDropTarget::OnDragLeave(CWnd* pWnd)
|
|
{
|
|
/*
|
|
// Remove Highlighting
|
|
CTreeCtrl * pTreeCtrl= (CTreeCtrl *)pWnd;
|
|
pTreeCtrl->SendMessage(TVM_SELECTITEM, TVGN_DROPHILITE,0);
|
|
*/
|
|
}
|
|
/*
|
|
DROPEFFECT CUserDropTarget::OnDropEx(CWnd* pWnd, COleDataObject* pDataObject,
|
|
DROPEFFECT dropEffect, DROPEFFECT dropEffectList, CPoint point)
|
|
{
|
|
if (pWnd->IsKindOf(RUNTIME_CLASS(CView)))//if CView,Call base class
|
|
return COleDropTarget::OnDropEx( pWnd, pDataObject, dropEffect, dropEffectList, point) ;
|
|
|
|
return -1;
|
|
}
|
|
*/ |