summaryrefslogtreecommitdiff
path: root/utils/vkeyedit/Vkeylistview.cpp
blob: 037f93a7611caa6b905c27fe64aab6857d5e3002 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//
// Vkeylistview.cpp : implementation file
//

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

#include <KeyValues.h>

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

/////////////////////////////////////////////////////////////////////////////
// CVkeylistview

IMPLEMENT_DYNCREATE(CVkeylistview, CListView)

CVkeylistview::CVkeylistview()
{
}

CVkeylistview::~CVkeylistview()
{
}


BEGIN_MESSAGE_MAP(CVkeylistview, CListView)
	//{{AFX_MSG_MAP(CVkeylistview)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVkeylistview drawing

void CVkeylistview::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CVkeylistview diagnostics

#ifdef _DEBUG
void CVkeylistview::AssertValid() const
{
	CListView::AssertValid();
}

void CVkeylistview::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CVkeylistview message handlers

void CVkeylistview::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
	
	CListCtrl &theList = GetListCtrl();

	theList.DeleteColumn( 0 );
	theList.DeleteColumn( 0 );
	
	theList.InsertColumn( 0, _T("Name"), LVCFMT_LEFT, 200 );
	theList.InsertColumn( 1, _T("Value"), LVCFMT_LEFT, 800 );

	theList.SetExtendedStyle( LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES );
}

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

BOOL CVkeylistview::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CListView::PreCreateWindow(cs);
}

BOOL CVkeylistview::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	dwStyle |= LVS_REPORT|LVS_SINGLESEL|LVS_EDITLABELS|LVS_AUTOARRANGE;
	
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

void CVkeylistview::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	KeyValues *kv = (KeyValues *)pHint;

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

	CListCtrl &theList = GetListCtrl();

	theList.DeleteAllItems();

	KeyValues *subkey = kv->GetFirstValue();

	LVITEM lvi;

	int i = 0;

	while ( subkey )
	{
		lvi.mask =  LVIF_TEXT;
		lvi.iItem = i;

		lvi.iSubItem = 0;
		lvi.pszText = (char*)subkey->GetName();
		theList.InsertItem(&lvi);

		lvi.iSubItem =1;
		lvi.pszText = (char*)subkey->GetString();
		theList.SetItem(&lvi);

		i++;

		subkey = subkey->GetNextValue();
	}
}