summaryrefslogtreecommitdiff
path: root/Checklist/AdvancedPage.cpp
blob: edef443afec6942a576cdf3e3d0bc7c16fef96bf (plain)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// AdvancedPage.cpp : implementation file
//

#include "stdafx.h"
#include "AdvancedPage.h"

/////////////////////////////////////////////////////////////////////////////
// CAdvancedPage property page

CAdvancedPage::CAdvancedPage(CNightSecWizard* pParent, UINT nType, UINT nIDD, UINT nPos /*= WIZPAGE_MIDDLE*/) 
	: CPropertyPage(nIDD),

	// Set const variables
	m_nType(nType),  	// Either COMPONENT_WIN or COMPONENT_DOS

	m_nPos(nPos)		// Position in the Wizard (WIZPAGE_FIRST, WIZPAGE_MIDDLE 
						// or WIZPAGE_LAST)

{
	m_pCurPropPage = NULL;		// NULL means no Proppage shown
	m_pCurComponent = NULL;

	ASSERT(pParent != NULL);	// Have to have a valid parent
	m_pParentSheet = pParent;	// or we can't survive

}

CAdvancedPage::~CAdvancedPage()
{
	m_pParentSheet = NULL;
	m_pCurPropPage = NULL;
	m_pCurComponent = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// CAdvancedPage message handlers

//////////////////////////////////////////////////////////////////
// List box selection has changed

LRESULT CAdvancedPage::OnComponentsSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
{
	// Make sure we have a matching PropPage up
	SetCurrentComponent();

	return 1;
}

LRESULT CAdvancedPage::OnPageSelChange(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	// Make sure we have a matching PropPage up
	SetCurrentPage();

	return 1;
}

//////////////////////////////////////////////////////////////////
// InitDialog

LRESULT CAdvancedPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
{
	m_ctlDrag.SubclassWindow(GetDlgItem(IDC_COMPONENTS));
	m_ctlCheck.SubclassWindow(GetDlgItem(IDC_COMPONENTS));
//	m_ctlCheck = GetDlgItem(IDC_COMPONENTS);

	m_ctlTabs = GetDlgItem(IDC_PAGETABS);

	int nIndex = 0;

	// Loop through and Add Components to Box
	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) 
	{
		// Make sure it's our internal type (set from constructor)
		if(g_aComponents[nCnt]->GetType() == m_nType) 
		{
			// Add the Title
			nIndex = m_ctlCheck.AddString(g_aComponents[nCnt]->GetName());

			// Save a Pointer to the component in the Listbox Data
			m_ctlCheck.SetItemDataPtr(nIndex, (void*)g_aComponents[nCnt]);


			// Check if Enabled
			m_ctlCheck.SetCheck(nIndex, g_aComponents[nCnt]->IsEnabled());

		}

	}


	// Set the Proppage Rectangle to the Place Holder
	::GetWindowRect(GetDlgItem(IDC_PROPHOLDER), &m_rcPropPage);
	ScreenToClient(&m_rcPropPage);

//	m_ctlTabs.Set


	// Remove Place Holder Control
	::DestroyWindow(GetDlgItem(IDC_PROPHOLDER));


	// Select first item and display prop page
	m_ctlCheck.SetCurSel(0);
	SetCurrentComponent();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//////////////////////////////////////////////////////////////////
// When the Finish Button on Wizard is pressed

LRESULT CAdvancedPage::OnWizFinish(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	// If we have a PropPage then Save it
	if(m_pCurPropPage != NULL) 
		m_pCurPropPage->Apply();

	// Save Pos and Enabled Status
	SaveChanges();
	
	return 0;
}

//////////////////////////////////////////////////////////////////
// Basically saves Position of component and Enabled Status

HRESULT CAdvancedPage::SaveChanges()
{
	HRESULT hrRet = S_OK;
	CComponentHolder* pComponent;

	// Loop though and save Pos and Enabled Status
	for(int nCnt = 0; nCnt < m_ctlCheck.GetCount(); nCnt++) 
	{
		// Get the Pointer from Listbox Data
		pComponent = (CComponentHolder*)m_ctlCheck.GetItemDataPtr(nCnt);

		if(pComponent) 
		{
			// Save to Component Data
			pComponent->Enable(m_ctlCheck.GetCheck(nCnt) ? true : false);
			pComponent->SetPos((nCnt * 2) + m_nType - 1); // Need special calculations because we have a number of type sharing same position list
		}
		else
			// Bummed out and don't know why
			hrRet = E_UNEXPECTED;
	}

	return hrRet;
}

//////////////////////////////////////////////////////////////////
// Make sure our buttons are properly enabled based on our 
// position (passed in constructor)

LRESULT CAdvancedPage::OnSetActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	DWORD dwButtons;

	// Depening on our Position in the Wizard
	// Set the Buttons at the bottom on and off

	switch(m_nPos)
	{
		case WIZPAGE_FIRST:
			dwButtons = PSWIZB_NEXT;
			break;
		case WIZPAGE_LAST:
			dwButtons = PSWIZB_BACK | PSWIZB_FINISH;
			break;
		default:
			dwButtons = PSWIZB_BACK | PSWIZB_NEXT;
			break;
	}

	m_pParentSheet->SetWizardButtons(dwButtons);

	return 0;
}

//////////////////////////////////////////////////////////////////
// Have to save our changes when focus changes cause
// OnWizardFinish doesn't get called for each sheet

LRESULT CAdvancedPage::OnWizBack(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	// If we have a PropPage then Save it
	if(m_pCurPropPage != NULL) 
		m_pCurPropPage->Apply();

	SaveChanges();
	
	return 0;
}

//////////////////////////////////////////////////////////////////
// Have to save our changes when focus changes cause
// OnWizardFinish doesn't get called for each sheet

LRESULT CAdvancedPage::OnWizNext(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	// If we have a PropPage then Save it
	if(m_pCurPropPage != NULL)
		m_pCurPropPage->Apply();

	SaveChanges();
	
	return 0;
}

LRESULT CAdvancedPage::OnHelp(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
	WinHelp(NS_HELP_FILE, HELP_FINDER, 0);
	return 1;
}

//////////////////////////////////////////////////////////////////
// Shows the appropriate Property sheet for the current component
// in List box

void CAdvancedPage::SetCurrentComponent()
{
	// Get the selection
	int nCurSel = m_ctlCheck.GetCurSel();

	if(nCurSel == LB_ERR)
		return;

	// Get current selection
	CComponentHolder* pComponent = (CComponentHolder*)m_ctlCheck.GetItemDataPtr(nCurSel);

	// Only change if a different component
	if(pComponent == NULL || pComponent == m_pCurComponent)
		return;

	m_ctlTabs.DeleteAllItems();
	
	PropertyPageMap::iterator iterPages = m_pParentSheet->m_mapPages.lower_bound(pComponent);
	PropertyPageMap::iterator endPages = m_pParentSheet->m_mapPages.upper_bound(pComponent);
	for( ; iterPages != endPages && iterPages != m_pParentSheet->m_mapPages.end(); iterPages++)
	{
		string sTitle = iterPages->second->GetTitle();
		TCITEM tci;
		tci.mask = TCIF_TEXT | TCIF_PARAM;
		tci.pszText = sTitle.get_buffer();
		tci.iImage = -1;
		tci.lParam = (LPARAM)iterPages->second;

		m_ctlTabs.InsertItem(m_ctlTabs.GetItemCount(), &tci);
	}

	m_pCurComponent = pComponent;
	SetCurrentPage();
}


void CAdvancedPage::SetCurrentPage()
{
	// Get the selection
	int nCurSel = m_ctlTabs.GetCurSel();

	CPropPageHolder* pPropPage = NULL;

	if(nCurSel != -1)
	{

		// Get current selection
		TCITEM tci;
		memset(&tci, 0, sizeof(TCITEM));
		tci.mask = TCIF_PARAM;

		m_ctlTabs.GetItem(nCurSel, &tci);

		pPropPage = (CPropPageHolder*)tci.lParam;
		ASSERT(pPropPage);
	}

	// Only change if a different component
	if(pPropPage != NULL && pPropPage != m_pCurPropPage)
	{
		// If it's already created then just show it
		if(pPropPage->IsActivated())
		{
			pPropPage->Show(SW_SHOW);
		}
		// Otherwise Create
		else
		{
			pPropPage->Create(m_hWnd, m_rcPropPage, true);
			pPropPage->Show(SW_SHOW);
		}

	}

	// Now Hide Old One (Hide after show to avoid flicker)
	if(m_pCurPropPage != NULL && m_pCurPropPage != pPropPage) 
	{
		m_pCurPropPage->Show(SW_HIDE);

		// Save Changes before going out
		m_pCurPropPage->Apply();

	}

	// Current Selection Update
	m_pCurPropPage = pPropPage;
}

LRESULT CAdvancedPage::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 
{
	// If we have a PropPage then Destroy it
	if(m_pCurPropPage != NULL)
		m_pCurPropPage->Destroy();

	return 0;
}