-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.cpp
266 lines (215 loc) · 6.55 KB
/
page.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
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
// Page.cpp : implementation file
//
#include "stdafx.h"
#include "page.h"
#include "gui_resources.h"
#include "main_dialog.h"
#include "graphics.h"
#ifdef _DBEUG
#define new DEBUG_NEW
#endif
// Page dialog
IMPLEMENT_DYNAMIC(Page, CDialog)
CImageList Page::imageList_;
Page::Page(UINT templateId, CWnd* pParent /*=NULL*/)
: CDialog(templateId, pParent) {
header_.icon = NULL;
header_.bgColor = RGB(255, 255, 255);
header_.textColor = RGB(0, 0, 0);
ZeroMemory(header_.buttons, sizeof(header_.buttons));
header_.visible = false;
header_.height = 64;
}
Page::~Page() {
}
void Page::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
}
void Page::OnEnter(int leavePageId) {
}
bool Page::OnLeave(int enterPageId) {
return true;
}
void Page::SetHeaderButtons(HeaderButton *buttons, int count) {
ASSERT(count < _countof(header_.buttons));
for (int i = 0; i < _countof(header_.buttons); i++) //3个Button全都还没有赋值
{
if (header_.buttons[i] != NULL) {
header_.buttons[i]->DestroyWindow();
delete header_.buttons[i];
header_.buttons[i] = NULL;
}
}
ButtonStyle buttonStyle;//蓝底白字
buttonStyle.bgColor = RGB(54, 133, 214);
buttonStyle.textColor = RGB(255, 255, 255);
for (int i = 0; i < count; i++) {
CString caption;
caption.LoadString(buttons[i].textResId);
Button *button = new Button();
button->Create(caption, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, CRect(0, 0, 64, 32), this, buttons[i].id);
button->SetFont(GuiResources::GetInstance()->GetFont(GuiResources::FONT_NORMAL));
button->SetStyle(BUTTON_STATE_NORMAL, buttonStyle);
button->SetStyle(BUTTON_STATE_OVER, buttonStyle);
button->SetStyle(BUTTON_STATE_DOWN, buttonStyle);
header_.buttons[i] = button;
}
LayoutHeaderButtons();
}
void Page::SetHeaderInfo(int style, int textResId, int subTextResId) {
CString text, subText;
text.LoadString(textResId);
subText.LoadString(subTextResId);
SetHeaderInfo(style, text, subText);
}
void Page::SetHeaderInfo(int style, LPCTSTR text, LPCTSTR subText) {
header_.text = text;
header_.subText = subText;
switch (style) {
case HEADER_STYLE_ERROR:
header_.icon = ICON_ERROR;
header_.bgColor = RGB(255, 238, 238);
header_.textColor = RGB(227, 0, 0);
break;
case HEADER_STYLE_OK:
header_.icon = ICON_OK;
header_.bgColor = RGB(233, 255, 224);
header_.textColor = RGB(38, 179, 0);
break;
default:
header_.icon = ICON_INFO;
header_.bgColor = RGB(238, 238, 238);
header_.textColor = RGB(54, 133, 214);
break;
}
Invalidate(FALSE);
}
void Page::SetHeaderButtonText(int id, int textResId) {
CString text;
text.LoadString(textResId);
SetDlgItemText(id, text);
}
void Page::ShowHeaderButton(int id, bool visibility) {
CWnd *button = GetDlgItem(id);
if (button != NULL) {
button->ShowWindow(visibility ? SW_SHOW : SW_HIDE);
}
}
void Page::ShowHeader(bool visibility) {
header_.visible = visibility;
Invalidate(FALSE);
}
bool Page::ShowPage(int pageId) {
MainDialog *mainDialog = (MainDialog *)GetParent();
ASSERT(mainDialog != NULL);
return mainDialog->ShowPage(pageId);
}
bool Page::GotoStep(int step) {
MainDialog *mainDialog = (MainDialog *)GetParent();
ASSERT(mainDialog != NULL);
return mainDialog->GotoStep(step);
}
void Page::EnableConnectionCheck(bool enabled) {
MainDialog *mainDialog = (MainDialog *)GetParent();
ASSERT(mainDialog != NULL);
mainDialog->EnableConnectionCheck(enabled);
}
void Page::OnOK()
{
CDialog::OnOK();
}
void Page::OnCancel() {
}
BEGIN_MESSAGE_MAP(Page, CDialog)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
END_MESSAGE_MAP()
// Page message handlers
void Page::OnPaint() {
BufferredPaintDC dc(this);
CRect rectClient;
GetClientRect(&rectClient);
dc.FillSolidRect(rectClient, GetBgColor());
if (header_.visible) {
DrawHeader(dc);
rectClient.top += header_.height;
}
DrawClient(dc, rectClient);
}
void Page::DrawHeader(CDC &dc) {
CRect rect;
GetClientRect(&rect);
rect.bottom = rect.top + header_.height;
dc.FillSolidRect(rect, header_.bgColor);
int x = rect.left + 40;
int y = rect.top + (rect.Height() - 32) / 2;
imageList_.Draw(&dc, header_.icon, CPoint(x, y), ILD_NORMAL);
x += 32 + 8;
dc.SetTextColor(header_.textColor);
dc.SetBkMode(TRANSPARENT);
CFont *oldFont = dc.SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_BIG));
if (header_.subText.IsEmpty()) {
CRect rectText(rect);
rectText.left = x;
dc.DrawText(header_.text, &rectText, DT_SINGLELINE | DT_VCENTER);
} else {
int textHeight = dc.GetTextExtent(header_.text).cy;
dc.SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_NORMAL));
int subTextHeight = dc.GetTextExtent(header_.subText).cy;
int y = rect.top + (rect.Height() - textHeight - subTextHeight) / 2;
dc.SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_BIG));
dc.TextOut(x, y, header_.text);
dc.SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_NORMAL));
dc.TextOut(x, y + textHeight, header_.subText);
}
dc.SelectObject(oldFont);
}
void Page::DrawClient(CDC &dc, const CRect &rect) {
}
BOOL Page::OnEraseBkgnd(CDC* pDC) {
return TRUE;
}
BOOL Page::OnInitDialog() {
CDialog::OnInitDialog();
if (imageList_.GetSafeHandle() == NULL) {
CBitmap bitmap;
bitmap.LoadBitmap(IDB_STATUS);
imageList_.Create(32, 32, ILC_COLOR32 | ILC_MASK, 3, 0);
imageList_.Add(&bitmap, RGB(255, 0, 255));
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Page::OnSize(UINT nType, int cx, int cy) {
CDialog::OnSize(nType, cx, cy);
if (::IsWindow(m_hWnd)) {
LayoutHeaderButtons();
}
}
void Page::LayoutHeaderButtons() {
CRect clientRect;
GetClientRect(&clientRect);
int count = 0;
for (int i = 0; i < _countof(header_.buttons); i++) {
if (header_.buttons[i] != NULL) {
count++;
}
}
if (count > 0) {
HDWP hdwp = BeginDeferWindowPos(count);
int x = clientRect.right - 40;
for (int i = 0; i < _countof(header_.buttons); i++) {
if (header_.buttons[i] != NULL) {
CRect buttonRect;
header_.buttons[i]->GetWindowRect(&buttonRect);
x -= buttonRect.Width();
int y = clientRect.top + (header_.height - buttonRect.Height()) / 2;
DeferWindowPos(hdwp, header_.buttons[i]->GetSafeHwnd(),
NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
x -= 8;
}
}
EndDeferWindowPos(hdwp);
}
}