summaryrefslogtreecommitdiff
path: root/Checklist/NormalPage.cpp
blob: de35ff26d3d36a097db6a59c9aca672c5042d5ec (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
// NormalPage.cpp : implementation file
//

#include "stdafx.h"
#include "NormalPage.h"
#include "ExtraPage.h"

/////////////////////////////////////////////////////////////////////////////
// CNormalPage property page


CNormalPage::CNormalPage(CPropertySheet* pParent, UINT nPos) 
	: CPropertyPage(IDD),
	  m_nPos(nPos)
{
	ASSERT(pParent);		// Have to have a valid parent
	m_pParentSheet = pParent;	// or we can't survive
	SetHelp(true);
}

CNormalPage::~CNormalPage()
{
	m_pParentSheet = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// CNormalPage message handlers

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

	int nIndex = 0;

	// Loop through and Add Components to Box
	for(int nCnt = 0; nCnt < g_aComponents.size(); nCnt++) 
	{
		// Only show if enabled or Not a component that Hides in Normal Mode
		if(!g_aComponents[nCnt]->GetInfoInt(nsHideNormal, FALSE) || g_aComponents[nCnt]->IsEnabled())
		{
			// 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());
		}

	}

	// Select first item and display help text
	m_ctlCheck.SetCurSel(0);
	SetTips();

	// Set the Help ID for our Help File
//	m_nIDHelp = 1;

	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 CNormalPage::OnWizBack(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	// Save Pos and Enabled Status
	SaveChanges();
	return 0;
}

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

LRESULT CNormalPage::OnWizFinish(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	SaveChanges();
	return 0;
}

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

LRESULT CNormalPage::OnWizNext(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) 
{
	SaveChanges();
	return 0;
}

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

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

LRESULT CNormalPage::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;
}


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

HRESULT CNormalPage::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;

}

//////////////////////////////////////////////////////////////////
// Change Help text for each new component

LRESULT CNormalPage::OnComponentsSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
{
	SetTips();
	return 1;
}

//////////////////////////////////////////////////////////////////
// Display Help Text

void CNormalPage::SetTips()
{

	// Get current selection
	int nCurSel = m_ctlCheck.GetCurSel();

	if(nCurSel == LB_ERR)
		return;

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

	if(pComponent) 
		SetDlgItemText(IDC_TIPS, pComponent->GetInfoStr(nsHelpText, _T("(No help available)")));
}