-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeViewExt.cpp
115 lines (92 loc) · 2.44 KB
/
TreeViewExt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// TreeViewExt.cpp : implementation file
//
#include "stdafx.h"
#include "ICE.h"
#include "TreeViewExt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTreeViewExt
IMPLEMENT_DYNCREATE(CTreeViewExt, CTreeView)
CTreeViewExt::CTreeViewExt()
{
m_bDraggingNow = FALSE;
m_hDraggedItem = NULL;
m_pDragImageList = NULL;
}
CTreeViewExt::~CTreeViewExt()
{
}
BEGIN_MESSAGE_MAP(CTreeViewExt, CTreeView)
ON_NOTIFY_REFLECT(TVN_BEGINDRAG, OnBegindrag)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTreeViewExt message handlers
void CTreeViewExt::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
if (!m_bDraggingNow)
{
if (ItemCanBeDragged(pNMTreeView->itemNew.hItem))
{
CTreeCtrl& tree = GetTreeCtrl();
tree.SetCapture();
m_bDraggingNow = TRUE;
m_hDraggedItem = pNMTreeView->itemNew.hItem;
tree.Select(m_hDraggedItem, TVGN_CARET);
m_pDragImageList = tree.CreateDragImage(m_hDraggedItem);
m_pDragImageList->DragEnter(&tree, pNMTreeView->ptDrag);
m_pDragImageList->BeginDrag(0, CPoint(0, 0));
}
}
*pResult = 0;
}
void CTreeViewExt::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bDraggingNow)
{
CTreeCtrl& tree = GetTreeCtrl();
m_pDragImageList->DragEnter(&tree, point);
m_pDragImageList->DragMove(point);
}
CTreeView::OnMouseMove(nFlags, point);
}
void CTreeViewExt::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_bDraggingNow)
{
ReleaseCapture();
m_bDraggingNow = FALSE;
m_pDragImageList->EndDrag();
delete m_pDragImageList;
m_pDragImageList = NULL;
CTreeCtrl& tree = GetTreeCtrl();
UINT flags;
HTREEITEM hTargetItem = tree.HitTest(point, &flags);
if (hTargetItem != NULL && IsItemCanBeDroppedOn(m_hDraggedItem, hTargetItem))
{
HTREEITEM hNewItem = tree.InsertItem("Untitled", hTargetItem);
CopyItemProperties(hNewItem, m_hDraggedItem);
if (nFlags != MK_CONTROL)
tree.DeleteItem(m_hDraggedItem);
}
m_hDraggedItem = NULL;
}
CTreeView::OnLButtonUp(nFlags, point);
}
BOOL CTreeViewExt::ItemCanBeDragged(HTREEITEM hItem)
{
return FALSE;
}
BOOL CTreeViewExt::IsItemCanBeDroppedOn(HTREEITEM hSource, HTREEITEM hTarget)
{
return FALSE;
}
void CTreeViewExt::CopyItemProperties(HTREEITEM hNewItem, HTREEITEM hDraggedItem)
{
}