-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConfigureBridgeLinkDlg.cpp
executable file
·191 lines (155 loc) · 4.83 KB
/
ConfigureBridgeLinkDlg.cpp
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
// ConfigureBridgeLinkDlg.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "BridgeLink.h"
#include "ConfigureBridgeLinkDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CConfigureBridgeLinkDlg
IMPLEMENT_DYNAMIC(CConfigureBridgeLinkDlg, CPropertySheet)
CConfigureBridgeLinkDlg::CConfigureBridgeLinkDlg(std::map<IDType,IBridgeLinkConfigurationCallback*>& configurationPageCallbacks,CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(_T("Configure BridgeLink"), pParentWnd, iSelectPage)
{
Init(configurationPageCallbacks);
}
CConfigureBridgeLinkDlg::~CConfigureBridgeLinkDlg()
{
DestroyExtensionPages();
}
INT_PTR CConfigureBridgeLinkDlg::DoModal()
{
INT_PTR result = CPropertySheet::DoModal();
if ( result == ID_WIZFINISH )
{
NotifyExtensionPages();
result = IDOK;
}
return result;
}
void CConfigureBridgeLinkDlg::Init(std::map<IDType,IBridgeLinkConfigurationCallback*>& configurationPageCallbacks)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_psh.dwFlags |= PSH_HASHELP | PSH_NOAPPLYNOW | PSH_WIZARD97 /*| PSH_HEADER*/ | PSH_WATERMARK;
m_psh.pszbmWatermark = MAKEINTRESOURCE(IDB_CONFIGURATION_WATERMARK);
//m_psh.pszbmHeader = MAKEINTRESOURCE(IDB_CONFIGURATION_HEADER);
m_psh.hInstance = AfxGetInstanceHandle();
SetWizardMode();
m_Pages.reserve(configurationPageCallbacks.size() + 1);
AddPage( &m_BridgeLinkPage );
m_Pages.push_back((LRESULT)m_BridgeLinkPage.m_psp.pszTemplate);
std::map<IDType,IBridgeLinkConfigurationCallback*>::iterator iter(configurationPageCallbacks.begin());
std::map<IDType,IBridgeLinkConfigurationCallback*>::iterator end(configurationPageCallbacks.end());
for ( ; iter != end; iter++ )
{
IBridgeLinkConfigurationCallback* pCallback = iter->second;
CPropertyPage* pPage = pCallback->CreatePropertyPage();
m_vExtensionPages.emplace_back(pCallback,pPage);
if ( pPage )
{
AddPage(pPage);
m_Pages.push_back((LRESULT)pPage->m_psp.pszTemplate);
}
}
m_CurrentPage = m_Pages.begin();
}
void CConfigureBridgeLinkDlg::DestroyExtensionPages()
{
std::vector<std::pair<IBridgeLinkConfigurationCallback*,CPropertyPage*>>::iterator pageIter(m_vExtensionPages.begin());
std::vector<std::pair<IBridgeLinkConfigurationCallback*,CPropertyPage*>>::iterator pageIterEnd(m_vExtensionPages.end());
for ( ; pageIter != pageIterEnd; pageIter++ )
{
CPropertyPage* pPage = pageIter->second;
if ( pPage )
{
delete pPage;
}
}
m_vExtensionPages.clear();
}
void CConfigureBridgeLinkDlg::NotifyExtensionPages()
{
std::vector<std::pair<IBridgeLinkConfigurationCallback*,CPropertyPage*>>::iterator pageIter(m_vExtensionPages.begin());
std::vector<std::pair<IBridgeLinkConfigurationCallback*,CPropertyPage*>>::iterator pageIterEnd(m_vExtensionPages.end());
for ( ; pageIter != pageIterEnd; pageIter++ )
{
IBridgeLinkConfigurationCallback* pCallback = pageIter->first;
CPropertyPage* pPage = pageIter->second;
pCallback->OnOK(pPage);
}
}
BEGIN_MESSAGE_MAP(CConfigureBridgeLinkDlg, CPropertySheet)
ON_MESSAGE(WM_KICKIDLE,OnKickIdle)
END_MESSAGE_MAP()
BOOL CConfigureBridgeLinkDlg::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
SetTitle(_T("Configure BridgeLink"));
if ( m_Pages.size() == 0 )
{
SetWizardButtons(PSWIZB_FINISH);
}
else
{
SetWizardButtons(PSWIZB_NEXT);
}
return bResult;
}
LRESULT CConfigureBridgeLinkDlg::GetNextPage()
{
m_CurrentPage++;
if ( IsLastPage() )
{
SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
}
else
{
SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
}
return *m_CurrentPage;
}
LRESULT CConfigureBridgeLinkDlg::GetBackPage()
{
m_CurrentPage--;
if ( IsFirstPage() )
{
SetWizardButtons(PSWIZB_NEXT);
}
else
{
SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
}
return *m_CurrentPage;
}
bool CConfigureBridgeLinkDlg::IsLastPage()
{
return (m_CurrentPage == m_Pages.end()-1 ? true : false );
}
bool CConfigureBridgeLinkDlg::IsFirstPage()
{
return (m_CurrentPage == m_Pages.begin() ? true : false);
}
// CConfigureBridgeLinkDlg message handlers
LRESULT CConfigureBridgeLinkDlg::OnKickIdle(WPARAM wp, LPARAM lp)
{
// The CPropertySheet::OnKickIdle method calls GetActivePage()
// which doesn't work with extension pages. Since GetActivePage
// is not virtual, we have to replace the implementation of
// OnKickIdle.
// The same problem exists with OnCommandHelp
ASSERT_VALID(this);
CPropertyPage* pPage = GetPage(GetActiveIndex());
/* Forward the message on to the active page of the property sheet */
if( pPage != nullptr )
{
//ASSERT_VALID(pPage);
return pPage->SendMessage( WM_KICKIDLE, wp, lp );
}
else
{
return 0;
}
}