summaryrefslogtreecommitdiff
path: root/utils/vkeyedit/vkeyeditView.cpp
blob: 0b69ca5bf9aac3fde76e4263c7940c3a16dfaf40 (plain) (blame)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//
// vkeyeditView.cpp : implementation of the CVkeyeditView class
//

#include "stdafx.h"
#include "vkeyedit.h"

#include "vkeyeditDoc.h"
#include "vkeyeditView.h"
#include <COMMCTRL.H>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVkeyeditView

IMPLEMENT_DYNCREATE(CVkeyeditView, CTreeView)

BEGIN_MESSAGE_MAP(CVkeyeditView, CTreeView)
	//{{AFX_MSG_MAP(CVkeyeditView)
	ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVkeyeditView construction/destruction

CVkeyeditView::CVkeyeditView()
{
	// TODO: add construction code here

}

CVkeyeditView::~CVkeyeditView()
{
}

BOOL CVkeyeditView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	cs.style |= TVS_HASLINES|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_LINESATROOT;

	return CTreeView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CVkeyeditView drawing

void CVkeyeditView::OnDraw(CDC* pDC)
{
	CVkeyeditDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

//DEL void CVkeyeditView::OnInitialUpdate()
//DEL {
//DEL 	CTreeView::OnInitialUpdate();
//DEL 
//DEL 	CTreeCtrl &tree = GetTreeCtrl();
//DEL 
//DEL //	tree.InsertItem( _T("Test") );
//DEL 
//DEL 
//DEL 	// TODO: You may populate your TreeView with items by directly accessing
//DEL 	//  its tree control through a call to GetTreeCtrl().
//DEL }

/////////////////////////////////////////////////////////////////////////////
// CVkeyeditView printing

BOOL CVkeyeditView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CVkeyeditView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CVkeyeditView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CVkeyeditView diagnostics

#ifdef _DEBUG
void CVkeyeditView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CVkeyeditView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}

CVkeyeditDoc* CVkeyeditView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVkeyeditDoc)));
	return (CVkeyeditDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CVkeyeditView message handlers

void CVkeyeditView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CTreeView::CalcWindowRect(lpClientRect, nAdjustType);
}

// Sort the item in reverse alphabetical order.
static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
   return strcmp( ((KeyValues*)(lParam1))->GetName(), ((KeyValues*)(lParam2))->GetName()  );
}

void CVkeyeditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	CTreeCtrl &theTree = GetTreeCtrl();

	KeyValues *kv = (KeyValues *)pHint;

	if ( !kv || lHint != 1 )
		return;

	theTree.DeleteAllItems();

	while ( kv )
	{
		InsertKeyValues( kv, TVI_ROOT );

		kv = kv->GetNextKey();
	}

   // The pointer to my tree control.
   TVSORTCB tvs;
   // Sort the tree control's items using my
   // callback procedure.
   tvs.hParent = TVI_ROOT;
   tvs.lpfnCompare = MyCompareProc;
   tvs.lParam = (LPARAM) &theTree;

   theTree.SortChildrenCB(&tvs);

}

bool CVkeyeditView::InsertKeyValues(KeyValues *kv, HTREEITEM hParent)
{
	CTreeCtrl &theTree = GetTreeCtrl();

	TVINSERTSTRUCT tvInsert;
	tvInsert.hParent = hParent;
	tvInsert.hInsertAfter = TVI_LAST;
	tvInsert.item.mask = TVIF_TEXT;
	tvInsert.item.lParam = (LPARAM)kv;
	tvInsert.item.pszText = (char*)kv->GetName();

	HTREEITEM hItem = theTree.InsertItem( &tvInsert );

	theTree.SetItemData(hItem, (DWORD) kv );

	KeyValues * subkey = kv->GetFirstTrueSubKey();

	while ( subkey )
	{
		InsertKeyValues( subkey, hItem );
		subkey = subkey->GetNextKey();
	}

	 // The pointer to my tree control.
   TVSORTCB tvs;
   // Sort the tree control's items using my
   // callback procedure.
   tvs.hParent = hParent;
   tvs.lpfnCompare = MyCompareProc;
   tvs.lParam = (LPARAM) &theTree;

   theTree.SortChildrenCB(&tvs);

	return true;
}

void CVkeyeditView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW*) pNMHDR;
    CTreeCtrl   &tTree = this->GetTreeCtrl ();
	
	 CTreeCtrl &theTree = this->GetTreeCtrl ();

	 HTREEITEM hItem = pNMTreeView->itemNew.hItem;

	GetDocument()->UpdateAllViews ( this, 2, (CObject*)theTree.GetItemData(hItem) );

    *pResult = 0;

}