summaryrefslogtreecommitdiff
path: root/Checklist/NightSecWizard.cpp
blob: d394d0747a5014e56fa55ac330ff4f5ca25b5451 (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
// NightSecWizard.cpp: implementation of the CNightSecWizard class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "NightSecWizard.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CNightSecWizard::~CNightSecWizard()
{
	PropertyPageMap::iterator iter = m_mapPages.begin();

	for( ; iter != m_mapPages.end(); iter++)
		delete iter->second;

	m_mapPages.clear();	
};

HRESULT CNightSecWizard::LoadPropertyPages(CComponentHolder* pComponent)
{
	IUnknown* pUnk = pComponent->GetUnknown();

	IUnknown* apUnks[2];
	apUnks[0] = pUnk;
	apUnks[1] = pComponent->GetData()->GetUnknown();

	// Don't use smart pointer here because we'll probably
	// copy this to our map
	IPropertyPage* pPage;
	HRESULT hr = pUnk->QueryInterface(IID_IPropertyPage, (void**)&pPage);

	// Found a single property page
	if(SUCCEEDED(hr))
	{
		// Add to map and return
		hr = pPage->SetObjects(countof(apUnks), apUnks);

		if(SUCCEEDED(hr))
		{
			CPropPageHolder* pPropPage = new CComObjectMember<CPropPageHolder>;
			hr = pPropPage->Initialize(pPage, GetUnknown());

			if(SUCCEEDED(hr))
				m_mapPages.insert(make_pair(pComponent, pPropPage));
			else
				delete pPropPage;
		}

		pPage->Release();
		return hr;
	}
		
	// Look for multiple property pages
	ISpecifyPropertyPagesPtr pPages = pUnk;

	if(pPages)
	{
		CAUUID cauuid;
		memset(&cauuid, 0, sizeof(CAUUID));

		hr = pPages->GetPages(&cauuid);

		if(FAILED(hr))
			return hr;

		HRESULT hRet = S_FALSE;

		for(int nCnt = 0; nCnt < cauuid.cElems; nCnt++)
		{
			IPropertyPagePtr pPage;
			hr = pPage.CreateInstance(cauuid.pElems[nCnt], NULL);

			if(FAILED(hr))
				continue;

			hr = pPage->SetObjects(countof(apUnks), apUnks);
			
			if(SUCCEEDED(hr))
			{
				CPropPageHolder* pPropPage = new CComObjectMember<CPropPageHolder>;
				hr = pPropPage->Initialize(pPage, GetUnknown());

				if(SUCCEEDED(hr))
				{
					m_mapPages.insert(make_pair(pComponent, pPropPage));
					hRet = S_OK;
				}
			}

		}

		CoTaskMemFree(cauuid.pElems);

		return hRet;
	}

	return S_FALSE;
}

IUnknown* CNightSecWizard::GetIUnknown(bool bAddRef /*= false*/)
{
	// If asked not to increment then Release
	if(bAddRef)
		this->AddRef();

	return GetUnknown();
}

void CNightSecWizard::SetSite(IUnknown* pSite /*= NULL*/)
{
	if(!pSite)
		pSite = GetUnknown();

	IUnknown* pUnk = NULL;
	IObjectWithSitePtr pWithSite;

	// Cycle through components and set Site Pointer
	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
	{
		if(pUnk = g_aComponents[nCnt]->GetUnknown())
		{
			pWithSite = pUnk;

			if(pWithSite != NULL)
				pWithSite->SetSite(pSite);

			pUnk->Release();
		}	
	}
}

void CNightSecWizard::ClearSite()
{
	IUnknown* pUnk = NULL;
	IObjectWithSitePtr pWithSite;

	// Cycle through Components and Clear Site Pointer
	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
	{
		if(pUnk = g_aComponents[nCnt]->GetUnknown())
		{
			pWithSite = pUnk;

			if(pWithSite != NULL)
				pWithSite->SetSite(NULL);

			pUnk->Release();
		}	
	}
}

LRESULT CNightSecWizard::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// Make sure that that CPropertySheet::OnInitDialog gets called
	bHandled = FALSE;

	ModifyStyle(0, WS_SYSMENU);
	ModifyStyleEx(0, WS_EX_APPWINDOW | WS_EX_CONTEXTHELP); 
	SetWindowText(_T("Night Security Checklist"));


	return 0;
}

/////////////////////////////////////////////////////////////////////////////////////
// CAdvancedWizard

LRESULT CAdvancedWizardT::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// Make sure that that CPropertySheet::OnInitDialog gets called
	bHandled = FALSE;

	SetSite();

	// Cycle through components and...
	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
	{
		// And Load Property Pages for that Component
		LoadPropertyPages(g_aComponents[nCnt]);
	}

	return 0;
}

LRESULT CAdvancedWizardT::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	ClearSite();

	// And Destroy all Property Pages
	PropertyPageMap::iterator iter = m_mapPages.begin();
	for( ; iter != m_mapPages.end(); iter++)
		iter->second->Destroy();

	return 0;
}

STDMETHODIMP CAdvancedWizardT::get_Info(/*[in]*/ NightSecSiteInfo nsItem, /*[out, retval]*/ VARIANT* pvVal)
{
	::VariantClear(pvVal);

	// CComBSTR bsRetVal;
	switch(nsItem)
	{
	case nsAdvanced:
		pvVal->vt = VT_BOOL;
		pvVal->bVal = TRUE;
		return S_OK;
	}

	return S_FALSE;
}


////////////////////////////////////////////////////////////////////////////////
// CNormalWizard

CNormalWizardT::~CNormalWizardT() 
{
	ExtraPageArray::iterator iter = m_aPages.begin();
	for( ; iter != m_aPages.end(); iter++)
		delete *iter;

	m_aPages.clear();	
}

STDMETHODIMP CNormalWizardT::get_Info(/*[in]*/ NightSecSiteInfo nsItem, /*[out, retval]*/ VARIANT* pvVal)
{
	::VariantClear(pvVal);

	// CComBSTR bsRetVal;
	switch(nsItem)
	{
	case nsAdvanced:
		pvVal->vt = VT_BOOL;
		pvVal->bVal = FALSE;
		return S_OK;
	}

	return S_FALSE;
}

LRESULT CNormalWizardT::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// Make sure that that CPropertySheet::OnInitDialog gets called
	bHandled = FALSE;

	if(!m_bSiteSet)
	{
		SetSite();
		m_bSiteSet = true;
	}

	return 0;
};

LRESULT CNormalWizardT::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	ClearSite();

	PropertyPageMap::iterator iter = m_mapPages.begin();
	for( ; iter != m_mapPages.end(); iter++)
		iter->second->Destroy();

	return 0;
};

void CNormalWizardT::AddExtraPages()
{
	if(!m_bSiteSet)
	{
		SetSite();
		m_bSiteSet = true;
	}

	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++)
	{
		if(g_aComponents[nCnt]->GetInfoInt(nsForceShow, 0))
			LoadPropertyPages(g_aComponents[nCnt]);
	}

	PropertyPageMap::iterator iter = m_mapPages.begin();
	for( ; iter != m_mapPages.end(); iter++)
	{
		CExtraPage* pPage = new CExtraPage(this, iter->first, iter->second);
		AddPage(pPage);
		m_aPages.insert(m_aPages.end(), pPage);
	}
}