]>
Commit | Line | Data |
---|---|---|
66cd017c | 1 | /////////////////////////////////////////////////////////////////////////////// |
94c09a19 | 2 | // Name: src/generic/wizard.cpp |
66cd017c VZ |
3 | // Purpose: generic implementation of wxWizard class |
4 | // Author: Vadim Zeitlin | |
a0a48a3f VZ |
5 | // Modified by: Robert Cavanaugh |
6 | // 1) Added capability for wxWizardPage to accept resources | |
7 | // 2) Added "Help" button handler stub | |
8 | // 3) Fixed ShowPage() bug on displaying bitmaps | |
07f20d9a | 9 | // Robert Vazan (sizers) |
66cd017c VZ |
10 | // Created: 15.08.99 |
11 | // RCS-ID: $Id$ | |
12 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 13 | // Licence: wxWindows licence |
66cd017c VZ |
14 | /////////////////////////////////////////////////////////////////////////////// |
15 | ||
16 | // ============================================================================ | |
17 | // declarations | |
18 | // ============================================================================ | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // headers | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
66cd017c VZ |
24 | // For compilers that support precompilation, includes "wx.h". |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_WIZARDDLG |
32 | ||
66cd017c VZ |
33 | #ifndef WX_PRECOMP |
34 | #include "wx/dynarray.h" | |
35 | #include "wx/intl.h" | |
b87654f3 | 36 | #include "wx/statbmp.h" |
f6bcfd97 | 37 | #include "wx/button.h" |
9eddec69 | 38 | #include "wx/settings.h" |
ed2fbeb8 | 39 | #include "wx/sizer.h" |
66cd017c VZ |
40 | #endif //WX_PRECOMP |
41 | ||
42 | #include "wx/statline.h" | |
43 | ||
d9af3670 | 44 | #include "wx/scrolwin.h" |
66cd017c | 45 | #include "wx/wizard.h" |
d9af3670 | 46 | #include "wx/dcmemory.h" |
66cd017c | 47 | |
aedd6d6a VZ |
48 | // ---------------------------------------------------------------------------- |
49 | // wxWizardSizer | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | class wxWizardSizer : public wxSizer | |
53 | { | |
54 | public: | |
55 | wxWizardSizer(wxWizard *owner); | |
56 | ||
0a9ed8f1 VZ |
57 | virtual wxSizerItem *Insert(size_t index, wxSizerItem *item); |
58 | ||
88517d90 VZ |
59 | virtual void RecalcSizes(); |
60 | virtual wxSize CalcMin(); | |
aedd6d6a | 61 | |
88517d90 | 62 | // get the max size of all wizard pages |
aedd6d6a | 63 | wxSize GetMaxChildSize(); |
88517d90 VZ |
64 | |
65 | // return the border which can be either set using wxWizard::SetBorder() or | |
66 | // have default value | |
67 | int GetBorder() const; | |
ca65c044 | 68 | |
0a9ed8f1 VZ |
69 | // hide the pages which we temporarily "show" when they're added to this |
70 | // sizer (see Insert()) | |
71 | void HidePages(); | |
72 | ||
aedd6d6a VZ |
73 | private: |
74 | wxSize SiblingSize(wxSizerItem *child); | |
ca65c044 | 75 | |
aedd6d6a | 76 | wxWizard *m_owner; |
aedd6d6a VZ |
77 | wxSize m_childSize; |
78 | }; | |
79 | ||
66cd017c VZ |
80 | // ---------------------------------------------------------------------------- |
81 | // event tables and such | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
9b11752c VZ |
84 | wxDEFINE_EVENT( wxEVT_WIZARD_PAGE_CHANGED, wxWizardEvent ); |
85 | wxDEFINE_EVENT( wxEVT_WIZARD_PAGE_CHANGING, wxWizardEvent ); | |
86 | wxDEFINE_EVENT( wxEVT_WIZARD_CANCEL, wxWizardEvent ); | |
87 | wxDEFINE_EVENT( wxEVT_WIZARD_FINISHED, wxWizardEvent ); | |
88 | wxDEFINE_EVENT( wxEVT_WIZARD_HELP, wxWizardEvent ); | |
2e4df4bf | 89 | |
74b31181 VZ |
90 | BEGIN_EVENT_TABLE(wxWizard, wxDialog) |
91 | EVT_BUTTON(wxID_CANCEL, wxWizard::OnCancel) | |
f80bf901 VZ |
92 | EVT_BUTTON(wxID_BACKWARD, wxWizard::OnBackOrNext) |
93 | EVT_BUTTON(wxID_FORWARD, wxWizard::OnBackOrNext) | |
94 | EVT_BUTTON(wxID_HELP, wxWizard::OnHelp) | |
91c68292 | 95 | |
ca65c044 WS |
96 | EVT_WIZARD_PAGE_CHANGED(wxID_ANY, wxWizard::OnWizEvent) |
97 | EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxWizard::OnWizEvent) | |
98 | EVT_WIZARD_CANCEL(wxID_ANY, wxWizard::OnWizEvent) | |
99 | EVT_WIZARD_FINISHED(wxID_ANY, wxWizard::OnWizEvent) | |
100 | EVT_WIZARD_HELP(wxID_ANY, wxWizard::OnWizEvent) | |
66cd017c VZ |
101 | END_EVENT_TABLE() |
102 | ||
74b31181 | 103 | IMPLEMENT_DYNAMIC_CLASS(wxWizard, wxDialog) |
066f1b7a SC |
104 | |
105 | /* | |
ca65c044 WS |
106 | TODO PROPERTIES : |
107 | wxWizard | |
108 | extstyle | |
109 | title | |
066f1b7a SC |
110 | */ |
111 | ||
74b31181 VZ |
112 | IMPLEMENT_ABSTRACT_CLASS(wxWizardPage, wxPanel) |
113 | IMPLEMENT_DYNAMIC_CLASS(wxWizardPageSimple, wxWizardPage) | |
66cd017c VZ |
114 | IMPLEMENT_DYNAMIC_CLASS(wxWizardEvent, wxNotifyEvent) |
115 | ||
116 | // ============================================================================ | |
117 | // implementation | |
118 | // ============================================================================ | |
119 | ||
74b31181 VZ |
120 | // ---------------------------------------------------------------------------- |
121 | // wxWizardPage | |
122 | // ---------------------------------------------------------------------------- | |
123 | ||
c7de4135 VS |
124 | void wxWizardPage::Init() |
125 | { | |
126 | m_bitmap = wxNullBitmap; | |
127 | } | |
128 | ||
a0a48a3f | 129 | wxWizardPage::wxWizardPage(wxWizard *parent, |
cf63f3d3 | 130 | const wxBitmap& bitmap) |
74b31181 | 131 | { |
cf63f3d3 | 132 | Create(parent, bitmap); |
c7de4135 | 133 | } |
91c68292 | 134 | |
c7de4135 | 135 | bool wxWizardPage::Create(wxWizard *parent, |
cf63f3d3 | 136 | const wxBitmap& bitmap) |
c7de4135 | 137 | { |
ca65c044 WS |
138 | if ( !wxPanel::Create(parent, wxID_ANY) ) |
139 | return false; | |
c7de4135 | 140 | |
636d266b | 141 | m_bitmap = bitmap; |
a0a48a3f | 142 | |
74b31181 VZ |
143 | // initially the page is hidden, it's shown only when it becomes current |
144 | Hide(); | |
91c68292 | 145 | |
ca65c044 | 146 | return true; |
74b31181 VZ |
147 | } |
148 | ||
149 | // ---------------------------------------------------------------------------- | |
150 | // wxWizardPageSimple | |
151 | // ---------------------------------------------------------------------------- | |
152 | ||
153 | wxWizardPage *wxWizardPageSimple::GetPrev() const | |
154 | { | |
155 | return m_prev; | |
156 | } | |
157 | ||
158 | wxWizardPage *wxWizardPageSimple::GetNext() const | |
159 | { | |
160 | return m_next; | |
161 | } | |
07f20d9a VZ |
162 | |
163 | // ---------------------------------------------------------------------------- | |
164 | // wxWizardSizer | |
165 | // ---------------------------------------------------------------------------- | |
166 | ||
07f20d9a | 167 | wxWizardSizer::wxWizardSizer(wxWizard *owner) |
0a089246 VZ |
168 | : m_owner(owner), |
169 | m_childSize(wxDefaultSize) | |
07f20d9a | 170 | { |
07f20d9a VZ |
171 | } |
172 | ||
0a9ed8f1 VZ |
173 | wxSizerItem *wxWizardSizer::Insert(size_t index, wxSizerItem *item) |
174 | { | |
0a089246 VZ |
175 | m_owner->m_usingSizer = true; |
176 | ||
0a9ed8f1 VZ |
177 | if ( item->IsWindow() ) |
178 | { | |
179 | // we must pretend that the window is shown as otherwise it wouldn't be | |
180 | // taken into account for the layout -- but avoid really showing it, so | |
181 | // just set the internal flag instead of calling wxWindow::Show() | |
182 | item->GetWindow()->wxWindowBase::Show(); | |
183 | } | |
184 | ||
185 | return wxSizer::Insert(index, item); | |
186 | } | |
187 | ||
188 | void wxWizardSizer::HidePages() | |
189 | { | |
190 | for ( wxSizerItemList::compatibility_iterator node = GetChildren().GetFirst(); | |
191 | node; | |
192 | node = node->GetNext() ) | |
193 | { | |
194 | wxSizerItem * const item = node->GetData(); | |
195 | if ( item->IsWindow() ) | |
196 | item->GetWindow()->wxWindowBase::Show(false); | |
197 | } | |
198 | } | |
199 | ||
07f20d9a VZ |
200 | void wxWizardSizer::RecalcSizes() |
201 | { | |
202 | // Effect of this function depends on m_owner->m_page and | |
203 | // it should be called whenever it changes (wxWizard::ShowPage) | |
204 | if ( m_owner->m_page ) | |
205 | { | |
0a089246 | 206 | m_owner->m_page->SetSize(wxRect(m_position, m_size)); |
07f20d9a VZ |
207 | } |
208 | } | |
209 | ||
210 | wxSize wxWizardSizer::CalcMin() | |
211 | { | |
212 | return m_owner->GetPageSize(); | |
213 | } | |
214 | ||
215 | wxSize wxWizardSizer::GetMaxChildSize() | |
216 | { | |
07f20d9a | 217 | wxSize maxOfMin; |
07f20d9a | 218 | |
0a089246 VZ |
219 | for ( wxSizerItemList::compatibility_iterator childNode = m_children.GetFirst(); |
220 | childNode; | |
221 | childNode = childNode->GetNext() ) | |
07f20d9a VZ |
222 | { |
223 | wxSizerItem *child = childNode->GetData(); | |
224 | maxOfMin.IncTo(child->CalcMin()); | |
225 | maxOfMin.IncTo(SiblingSize(child)); | |
226 | } | |
227 | ||
07f20d9a VZ |
228 | if ( m_owner->m_started ) |
229 | { | |
07f20d9a VZ |
230 | m_childSize = maxOfMin; |
231 | } | |
ca65c044 | 232 | |
07f20d9a VZ |
233 | return maxOfMin; |
234 | } | |
235 | ||
88517d90 | 236 | int wxWizardSizer::GetBorder() const |
07f20d9a | 237 | { |
0a089246 | 238 | return m_owner->m_border; |
07f20d9a VZ |
239 | } |
240 | ||
241 | wxSize wxWizardSizer::SiblingSize(wxSizerItem *child) | |
242 | { | |
243 | wxSize maxSibling; | |
ca65c044 | 244 | |
07f20d9a VZ |
245 | if ( child->IsWindow() ) |
246 | { | |
247 | wxWizardPage *page = wxDynamicCast(child->GetWindow(), wxWizardPage); | |
248 | if ( page ) | |
249 | { | |
250 | for ( wxWizardPage *sibling = page->GetNext(); | |
251 | sibling; | |
252 | sibling = sibling->GetNext() ) | |
253 | { | |
254 | if ( sibling->GetSizer() ) | |
255 | { | |
256 | maxSibling.IncTo(sibling->GetSizer()->CalcMin()); | |
257 | } | |
258 | } | |
259 | } | |
260 | } | |
ca65c044 | 261 | |
07f20d9a VZ |
262 | return maxSibling; |
263 | } | |
264 | ||
66cd017c VZ |
265 | // ---------------------------------------------------------------------------- |
266 | // generic wxWizard implementation | |
267 | // ---------------------------------------------------------------------------- | |
268 | ||
77436c4c JS |
269 | void wxWizard::Init() |
270 | { | |
271 | m_posWizard = wxDefaultPosition; | |
d3b9f782 | 272 | m_page = NULL; |
77436c4c JS |
273 | m_btnPrev = m_btnNext = NULL; |
274 | m_statbmp = NULL; | |
aedd6d6a | 275 | m_sizerBmpAndPage = NULL; |
07f20d9a | 276 | m_sizerPage = NULL; |
0a089246 | 277 | m_border = 5; |
07f20d9a | 278 | m_started = false; |
94c09a19 | 279 | m_wasModal = false; |
0a089246 | 280 | m_usingSizer = false; |
3aa8e4ea JS |
281 | m_bitmapBackgroundColour = *wxWHITE; |
282 | m_bitmapPlacement = 0; | |
283 | m_bitmapMinimumWidth = 115; | |
77436c4c JS |
284 | } |
285 | ||
286 | bool wxWizard::Create(wxWindow *parent, | |
aedd6d6a VZ |
287 | int id, |
288 | const wxString& title, | |
289 | const wxBitmap& bitmap, | |
290 | const wxPoint& pos, | |
291 | long style) | |
66cd017c | 292 | { |
07f20d9a | 293 | bool result = wxDialog::Create(parent,id,title,pos,wxDefaultSize,style); |
ca65c044 | 294 | |
77436c4c JS |
295 | m_posWizard = pos; |
296 | m_bitmap = bitmap ; | |
636d266b | 297 | |
07f20d9a | 298 | DoCreateControls(); |
ca65c044 | 299 | |
07f20d9a | 300 | return result; |
f6bcfd97 BP |
301 | } |
302 | ||
781130bf VZ |
303 | wxWizard::~wxWizard() |
304 | { | |
305 | // normally we don't have to delete this sizer as it's deleted by the | |
306 | // associated window but if we never used it or didn't set it as the window | |
307 | // sizer yet, do delete it manually | |
308 | if ( !m_usingSizer || !m_started ) | |
309 | delete m_sizerPage; | |
310 | } | |
311 | ||
07f20d9a | 312 | void wxWizard::AddBitmapRow(wxBoxSizer *mainColumn) |
f6bcfd97 | 313 | { |
07f20d9a VZ |
314 | m_sizerBmpAndPage = new wxBoxSizer(wxHORIZONTAL); |
315 | mainColumn->Add( | |
316 | m_sizerBmpAndPage, | |
317 | 1, // Vertically stretchable | |
318 | wxEXPAND // Horizonal stretching, no border | |
319 | ); | |
320 | mainColumn->Add(0,5, | |
321 | 0, // No vertical stretching | |
322 | wxEXPAND // No border, (mostly useless) horizontal stretching | |
323 | ); | |
66cd017c | 324 | |
461dae94 | 325 | #if wxUSE_STATBMP |
f6bcfd97 | 326 | if ( m_bitmap.Ok() ) |
66cd017c | 327 | { |
3aa8e4ea JS |
328 | wxSize bitmapSize(wxDefaultSize); |
329 | if (GetBitmapPlacement()) | |
330 | bitmapSize.x = GetMinimumBitmapWidth(); | |
331 | ||
332 | m_statbmp = new wxStaticBitmap(this, wxID_ANY, m_bitmap, wxDefaultPosition, bitmapSize); | |
07f20d9a VZ |
333 | m_sizerBmpAndPage->Add( |
334 | m_statbmp, | |
335 | 0, // No horizontal stretching | |
336 | wxALL, // Border all around, top alignment | |
337 | 5 // Border width | |
338 | ); | |
339 | m_sizerBmpAndPage->Add( | |
340 | 5,0, | |
341 | 0, // No horizontal stretching | |
342 | wxEXPAND // No border, (mostly useless) vertical stretching | |
343 | ); | |
66cd017c | 344 | } |
461dae94 | 345 | #endif |
f1df0927 | 346 | |
0a089246 | 347 | // Added to m_sizerBmpAndPage later |
07f20d9a VZ |
348 | m_sizerPage = new wxWizardSizer(this); |
349 | } | |
74b31181 | 350 | |
07f20d9a VZ |
351 | void wxWizard::AddStaticLine(wxBoxSizer *mainColumn) |
352 | { | |
74b31181 | 353 | #if wxUSE_STATLINE |
07f20d9a | 354 | mainColumn->Add( |
ca65c044 | 355 | new wxStaticLine(this, wxID_ANY), |
07f20d9a VZ |
356 | 0, // Vertically unstretchable |
357 | wxEXPAND | wxALL, // Border all around, horizontally stretchable | |
358 | 5 // Border width | |
359 | ); | |
360 | mainColumn->Add(0,5, | |
361 | 0, // No vertical stretching | |
362 | wxEXPAND // No border, (mostly useless) horizontal stretching | |
363 | ); | |
364 | #else | |
365 | (void)mainColumn; | |
f6bcfd97 | 366 | #endif // wxUSE_STATLINE |
07f20d9a | 367 | } |
74b31181 | 368 | |
07f20d9a VZ |
369 | void wxWizard::AddBackNextPair(wxBoxSizer *buttonRow) |
370 | { | |
54cf600d | 371 | wxASSERT_MSG( m_btnNext && m_btnPrev, |
9a83f860 VZ |
372 | wxT("You must create the buttons before calling ") |
373 | wxT("wxWizard::AddBackNextPair") ); | |
54cf600d | 374 | |
07f20d9a VZ |
375 | // margin between Back and Next buttons |
376 | #ifdef __WXMAC__ | |
377 | static const int BACKNEXT_MARGIN = 10; | |
378 | #else | |
379 | static const int BACKNEXT_MARGIN = 0; | |
380 | #endif | |
66cd017c | 381 | |
07f20d9a VZ |
382 | wxBoxSizer *backNextPair = new wxBoxSizer(wxHORIZONTAL); |
383 | buttonRow->Add( | |
384 | backNextPair, | |
385 | 0, // No horizontal stretching | |
386 | wxALL, // Border all around | |
387 | 5 // Border width | |
388 | ); | |
ca65c044 | 389 | |
07f20d9a VZ |
390 | backNextPair->Add(m_btnPrev); |
391 | backNextPair->Add(BACKNEXT_MARGIN,0, | |
392 | 0, // No horizontal stretching | |
393 | wxEXPAND // No border, (mostly useless) vertical stretching | |
394 | ); | |
07f20d9a VZ |
395 | backNextPair->Add(m_btnNext); |
396 | } | |
66cd017c | 397 | |
07f20d9a VZ |
398 | void wxWizard::AddButtonRow(wxBoxSizer *mainColumn) |
399 | { | |
9473e9a4 VZ |
400 | // the order in which the buttons are created determines the TAB order - at least under MSWindows... |
401 | // although the 'back' button appears before the 'next' button, a more userfriendly tab order is | |
402 | // to activate the 'next' button first (create the next button before the back button). | |
403 | // The reason is: The user will repeatedly enter information in the wizard pages and then wants to | |
404 | // press 'next'. If a user uses mostly the keyboard, he would have to skip the 'back' button | |
405 | // everytime. This is annoying. There is a second reason: RETURN acts as TAB. If the 'next' | |
406 | // button comes first in the TAB order, the user can enter information very fast using the RETURN | |
407 | // key to TAB to the next entry field and page. This would not be possible, if the 'back' button | |
408 | // was created before the 'next' button. | |
409 | ||
a6328131 | 410 | bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
94c09a19 | 411 | int buttonStyle = isPda ? wxBU_EXACTFIT : 0; |
a6328131 | 412 | |
07f20d9a | 413 | wxBoxSizer *buttonRow = new wxBoxSizer(wxHORIZONTAL); |
977a3818 JS |
414 | #ifdef __WXMAC__ |
415 | if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) | |
416 | mainColumn->Add( | |
417 | buttonRow, | |
418 | 0, // Vertically unstretchable | |
419 | wxGROW|wxALIGN_CENTRE | |
420 | ); | |
421 | else | |
422 | #endif | |
07f20d9a VZ |
423 | mainColumn->Add( |
424 | buttonRow, | |
425 | 0, // Vertically unstretchable | |
426 | wxALIGN_RIGHT // Right aligned, no border | |
427 | ); | |
66cd017c | 428 | |
9473e9a4 VZ |
429 | // Desired TAB order is 'next', 'cancel', 'help', 'back'. This makes the 'back' button the last control on the page. |
430 | // Create the buttons in the right order... | |
977a3818 JS |
431 | wxButton *btnHelp=0; |
432 | #ifdef __WXMAC__ | |
433 | if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) | |
d90443b8 | 434 | btnHelp=new wxButton(this, wxID_HELP, wxEmptyString, wxDefaultPosition, wxDefaultSize, buttonStyle); |
977a3818 JS |
435 | #endif |
436 | ||
9473e9a4 | 437 | m_btnNext = new wxButton(this, wxID_FORWARD, _("&Next >")); |
a6328131 | 438 | wxButton *btnCancel=new wxButton(this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
977a3818 | 439 | #ifndef __WXMAC__ |
07f20d9a | 440 | if (GetExtraStyle() & wxWIZARD_EX_HELPBUTTON) |
a6328131 | 441 | btnHelp=new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
977a3818 | 442 | #endif |
a6328131 | 443 | m_btnPrev = new wxButton(this, wxID_BACKWARD, _("< &Back"), wxDefaultPosition, wxDefaultSize, buttonStyle); |
9473e9a4 VZ |
444 | |
445 | if (btnHelp) | |
977a3818 | 446 | { |
07f20d9a | 447 | buttonRow->Add( |
9473e9a4 | 448 | btnHelp, |
07f20d9a VZ |
449 | 0, // Horizontally unstretchable |
450 | wxALL, // Border all around, top aligned | |
451 | 5 // Border width | |
977a3818 JS |
452 | ); |
453 | #ifdef __WXMAC__ | |
454 | // Put stretchable space between help button and others | |
455 | buttonRow->Add(0, 0, 1, wxALIGN_CENTRE, 0); | |
456 | #endif | |
457 | } | |
07f20d9a VZ |
458 | |
459 | AddBackNextPair(buttonRow); | |
ca65c044 | 460 | |
07f20d9a | 461 | buttonRow->Add( |
9473e9a4 | 462 | btnCancel, |
07f20d9a VZ |
463 | 0, // Horizontally unstretchable |
464 | wxALL, // Border all around, top aligned | |
465 | 5 // Border width | |
466 | ); | |
467 | } | |
66cd017c | 468 | |
07f20d9a VZ |
469 | void wxWizard::DoCreateControls() |
470 | { | |
471 | // do nothing if the controls were already created | |
472 | if ( WasCreated() ) | |
473 | return; | |
ca65c044 | 474 | |
a6328131 | 475 | bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
94c09a19 | 476 | |
a6328131 JS |
477 | // Horizontal stretching, and if not PDA, border all around |
478 | int mainColumnSizerFlags = isPda ? wxEXPAND : wxALL|wxEXPAND ; | |
94c09a19 | 479 | |
07f20d9a VZ |
480 | // wxWindow::SetSizer will be called at end |
481 | wxBoxSizer *windowSizer = new wxBoxSizer(wxVERTICAL); | |
ca65c044 | 482 | |
07f20d9a VZ |
483 | wxBoxSizer *mainColumn = new wxBoxSizer(wxVERTICAL); |
484 | windowSizer->Add( | |
485 | mainColumn, | |
486 | 1, // Vertical stretching | |
a6328131 | 487 | mainColumnSizerFlags, |
07f20d9a VZ |
488 | 5 // Border width |
489 | ); | |
ca65c044 | 490 | |
07f20d9a | 491 | AddBitmapRow(mainColumn); |
94c09a19 | 492 | |
a6328131 JS |
493 | if (!isPda) |
494 | AddStaticLine(mainColumn); | |
94c09a19 | 495 | |
07f20d9a | 496 | AddButtonRow(mainColumn); |
ca65c044 | 497 | |
07f20d9a | 498 | SetSizer(windowSizer); |
66cd017c VZ |
499 | } |
500 | ||
f6bcfd97 BP |
501 | void wxWizard::SetPageSize(const wxSize& size) |
502 | { | |
0a089246 | 503 | wxCHECK_RET(!m_started, wxT("wxWizard::SetPageSize after RunWizard")); |
f6bcfd97 BP |
504 | m_sizePage = size; |
505 | } | |
506 | ||
07f20d9a VZ |
507 | void wxWizard::FitToPage(const wxWizardPage *page) |
508 | { | |
0a089246 | 509 | wxCHECK_RET(!m_started, wxT("wxWizard::FitToPage after RunWizard")); |
ca65c044 | 510 | |
c73b439f VZ |
511 | while ( page ) |
512 | { | |
513 | wxSize size = page->GetBestSize(); | |
514 | ||
07f20d9a | 515 | m_sizePage.IncTo(size); |
c73b439f VZ |
516 | |
517 | page = page->GetNext(); | |
518 | } | |
c73b439f VZ |
519 | } |
520 | ||
74b31181 | 521 | bool wxWizard::ShowPage(wxWizardPage *page, bool goingForward) |
66cd017c | 522 | { |
223d09f6 | 523 | wxASSERT_MSG( page != m_page, wxT("this is useless") ); |
66cd017c | 524 | |
0a089246 VZ |
525 | wxSizerFlags flags(1); |
526 | flags.Border(wxALL, m_border).Expand(); | |
527 | ||
528 | if ( !m_started ) | |
529 | { | |
530 | if ( m_usingSizer ) | |
531 | { | |
532 | m_sizerBmpAndPage->Add(m_sizerPage, flags); | |
533 | ||
534 | // now that our layout is computed correctly, hide the pages | |
535 | // artificially shown in wxWizardSizer::Insert() back again | |
536 | m_sizerPage->HidePages(); | |
537 | } | |
538 | } | |
539 | ||
540 | ||
0a089246 VZ |
541 | // remember the old bitmap (if any) to compare with the new one later |
542 | wxBitmap bmpPrev; | |
7cc5041d VZ |
543 | |
544 | // check for previous page | |
74b31181 | 545 | if ( m_page ) |
66cd017c | 546 | { |
74b31181 | 547 | // send the event to the old page |
0a089246 VZ |
548 | wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGING, GetId(), |
549 | goingForward, m_page); | |
74b31181 VZ |
550 | if ( m_page->GetEventHandler()->ProcessEvent(event) && |
551 | !event.IsAllowed() ) | |
552 | { | |
553 | // vetoed by the page | |
ca65c044 | 554 | return false; |
74b31181 | 555 | } |
66cd017c | 556 | |
74b31181 VZ |
557 | m_page->Hide(); |
558 | ||
0a089246 VZ |
559 | bmpPrev = m_page->GetBitmap(); |
560 | ||
561 | if ( !m_usingSizer ) | |
562 | m_sizerBmpAndPage->Detach(m_page); | |
dee5b92f | 563 | } |
66cd017c | 564 | |
7cc5041d | 565 | // set the new page |
66cd017c | 566 | m_page = page; |
66cd017c | 567 | |
74b31181 VZ |
568 | // is this the end? |
569 | if ( !m_page ) | |
66cd017c | 570 | { |
74b31181 | 571 | // terminate successfully |
0a089246 | 572 | if ( IsModal() ) |
b3eb133b WS |
573 | { |
574 | EndModal(wxID_OK); | |
575 | } | |
576 | else | |
577 | { | |
578 | SetReturnCode(wxID_OK); | |
579 | Hide(); | |
580 | } | |
64c2fa13 VZ |
581 | |
582 | // and notify the user code (this is especially useful for modeless | |
583 | // wizards) | |
ca65c044 | 584 | wxWizardEvent event(wxEVT_WIZARD_FINISHED, GetId(), false, 0); |
64c2fa13 VZ |
585 | (void)GetEventHandler()->ProcessEvent(event); |
586 | ||
ca65c044 | 587 | return true; |
74b31181 | 588 | } |
66cd017c | 589 | |
74b31181 VZ |
590 | // position and show the new page |
591 | (void)m_page->TransferDataToWindow(); | |
ca65c044 | 592 | |
0a089246 | 593 | if ( m_usingSizer ) |
7cc5041d | 594 | { |
0a089246 VZ |
595 | // wxWizardSizer::RecalcSizes wants to be called when m_page changes |
596 | m_sizerPage->RecalcSizes(); | |
597 | } | |
598 | else // pages are not managed by the sizer | |
599 | { | |
600 | m_sizerBmpAndPage->Add(m_page, flags); | |
601 | m_sizerBmpAndPage->SetItemMinSize(m_page, GetPageSize()); | |
7cc5041d VZ |
602 | } |
603 | ||
461dae94 | 604 | #if wxUSE_STATBMP |
0a089246 | 605 | // update the bitmap if:it changed |
3aa8e4ea | 606 | wxBitmap bmp; |
0a089246 | 607 | if ( m_statbmp ) |
f1df0927 | 608 | { |
3aa8e4ea | 609 | bmp = m_page->GetBitmap(); |
0a089246 | 610 | if ( !bmp.Ok() ) |
cfd88569 | 611 | bmp = m_bitmap; |
0a089246 VZ |
612 | |
613 | if ( !bmpPrev.Ok() ) | |
614 | bmpPrev = m_bitmap; | |
615 | ||
3aa8e4ea JS |
616 | if (!GetBitmapPlacement()) |
617 | { | |
618 | if ( !bmp.IsSameAs(bmpPrev) ) | |
619 | m_statbmp->SetBitmap(bmp); | |
620 | } | |
f1df0927 | 621 | } |
0a089246 VZ |
622 | #endif // wxUSE_STATBMP |
623 | ||
f1df0927 | 624 | |
74b31181 | 625 | // and update the buttons state |
2b5f62a0 | 626 | m_btnPrev->Enable(HasPrevPage(m_page)); |
66cd017c | 627 | |
7f3bf33a VZ |
628 | const bool hasNext = HasNextPage(m_page); |
629 | const wxString label = hasNext ? _("&Next >") : _("&Finish"); | |
630 | if ( label != m_btnNext->GetLabel() ) | |
631 | m_btnNext->SetLabel(label); | |
66cd017c | 632 | |
0a089246 VZ |
633 | m_btnNext->SetDefault(); |
634 | ||
635 | ||
5bc28e84 | 636 | // send the change event to the new page now |
2365e5cb | 637 | wxWizardEvent event(wxEVT_WIZARD_PAGE_CHANGED, GetId(), goingForward, m_page); |
5bc28e84 VZ |
638 | (void)m_page->GetEventHandler()->ProcessEvent(event); |
639 | ||
640 | // and finally show it | |
641 | m_page->Show(); | |
642 | m_page->SetFocus(); | |
643 | ||
0a089246 VZ |
644 | if ( !m_usingSizer ) |
645 | m_sizerBmpAndPage->Layout(); | |
646 | ||
647 | if ( !m_started ) | |
648 | { | |
649 | m_started = true; | |
650 | ||
3aa8e4ea JS |
651 | DoWizardLayout(); |
652 | } | |
653 | ||
634bb98a | 654 | if (GetBitmapPlacement() && m_statbmp) |
3aa8e4ea JS |
655 | { |
656 | ResizeBitmap(bmp); | |
634bb98a | 657 | |
3aa8e4ea JS |
658 | if ( !bmp.IsSameAs(bmpPrev) ) |
659 | m_statbmp->SetBitmap(bmp); | |
634bb98a | 660 | |
3aa8e4ea JS |
661 | if (m_usingSizer) |
662 | m_sizerPage->RecalcSizes(); | |
0a089246 VZ |
663 | } |
664 | ||
ca65c044 | 665 | return true; |
66cd017c VZ |
666 | } |
667 | ||
3aa8e4ea JS |
668 | /// Do fit, and adjust to screen size if necessary |
669 | void wxWizard::DoWizardLayout() | |
670 | { | |
671 | if ( wxSystemSettings::GetScreenType() > wxSYS_SCREEN_PDA ) | |
672 | { | |
673 | if (CanDoLayoutAdaptation()) | |
674 | DoLayoutAdaptation(); | |
675 | else | |
676 | GetSizer()->SetSizeHints(this); | |
677 | ||
678 | if ( m_posWizard == wxDefaultPosition ) | |
679 | CentreOnScreen(); | |
680 | } | |
681 | ||
682 | SetLayoutAdaptationDone(true); | |
683 | } | |
684 | ||
74b31181 | 685 | bool wxWizard::RunWizard(wxWizardPage *firstPage) |
66cd017c | 686 | { |
ca65c044 WS |
687 | wxCHECK_MSG( firstPage, false, wxT("can't run empty wizard") ); |
688 | ||
ca65c044 WS |
689 | // can't return false here because there is no old page |
690 | (void)ShowPage(firstPage, true /* forward */); | |
66cd017c | 691 | |
94c09a19 | 692 | m_wasModal = true; |
37f6a080 | 693 | |
66cd017c VZ |
694 | return ShowModal() == wxID_OK; |
695 | } | |
696 | ||
74b31181 | 697 | wxWizardPage *wxWizard::GetCurrentPage() const |
66cd017c | 698 | { |
74b31181 | 699 | return m_page; |
66cd017c VZ |
700 | } |
701 | ||
4fe5383d | 702 | wxSize wxWizard::GetPageSize() const |
07f20d9a VZ |
703 | { |
704 | // default width and height of the page | |
0a089246 VZ |
705 | int DEFAULT_PAGE_WIDTH, |
706 | DEFAULT_PAGE_HEIGHT; | |
707 | if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA ) | |
a6328131 JS |
708 | { |
709 | // Make the default page size small enough to fit on screen | |
710 | DEFAULT_PAGE_WIDTH = wxSystemSettings::GetMetric(wxSYS_SCREEN_X) / 2; | |
711 | DEFAULT_PAGE_HEIGHT = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) / 2; | |
712 | } | |
0a089246 VZ |
713 | else // !PDA |
714 | { | |
715 | DEFAULT_PAGE_WIDTH = | |
716 | DEFAULT_PAGE_HEIGHT = 270; | |
717 | } | |
94c09a19 | 718 | |
0a089246 VZ |
719 | // start with default minimal size |
720 | wxSize pageSize(DEFAULT_PAGE_WIDTH, DEFAULT_PAGE_HEIGHT); | |
ca65c044 | 721 | |
0a089246 VZ |
722 | // make the page at least as big as specified by user |
723 | pageSize.IncTo(m_sizePage); | |
ca65c044 | 724 | |
aedd6d6a VZ |
725 | if ( m_statbmp ) |
726 | { | |
0a089246 VZ |
727 | // make the page at least as tall as the bitmap |
728 | pageSize.IncTo(wxSize(0, m_bitmap.GetHeight())); | |
aedd6d6a | 729 | } |
ca65c044 | 730 | |
0a089246 VZ |
731 | if ( m_usingSizer ) |
732 | { | |
733 | // make it big enough to contain all pages added to the sizer | |
734 | pageSize.IncTo(m_sizerPage->GetMaxChildSize()); | |
735 | } | |
736 | ||
737 | return pageSize; | |
738 | } | |
739 | ||
740 | wxSizer *wxWizard::GetPageAreaSizer() const | |
741 | { | |
742 | return m_sizerPage; | |
743 | } | |
744 | ||
745 | void wxWizard::SetBorder(int border) | |
746 | { | |
747 | wxCHECK_RET(!m_started, wxT("wxWizard::SetBorder after RunWizard")); | |
748 | ||
749 | m_border = border; | |
4fe5383d VZ |
750 | } |
751 | ||
20f18ea1 | 752 | void wxWizard::OnCancel(wxCommandEvent& WXUNUSED(eventUnused)) |
66cd017c | 753 | { |
74b31181 VZ |
754 | // this function probably can never be called when we don't have an active |
755 | // page, but a small extra check won't hurt | |
756 | wxWindow *win = m_page ? (wxWindow *)m_page : (wxWindow *)this; | |
757 | ||
ca65c044 | 758 | wxWizardEvent event(wxEVT_WIZARD_CANCEL, GetId(), false, m_page); |
74b31181 | 759 | if ( !win->GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) |
66cd017c VZ |
760 | { |
761 | // no objections - close the dialog | |
b3eb133b WS |
762 | if(IsModal()) |
763 | { | |
764 | EndModal(wxID_CANCEL); | |
765 | } | |
766 | else | |
767 | { | |
768 | SetReturnCode(wxID_CANCEL); | |
769 | Hide(); | |
770 | } | |
66cd017c VZ |
771 | } |
772 | //else: request to Cancel ignored | |
773 | } | |
774 | ||
74b31181 | 775 | void wxWizard::OnBackOrNext(wxCommandEvent& event) |
66cd017c VZ |
776 | { |
777 | wxASSERT_MSG( (event.GetEventObject() == m_btnNext) || | |
778 | (event.GetEventObject() == m_btnPrev), | |
223d09f6 | 779 | wxT("unknown button") ); |
66cd017c | 780 | |
9a83f860 | 781 | wxCHECK_RET( m_page, wxT("should have a valid current page") ); |
47e64664 | 782 | |
f6bcfd97 BP |
783 | // ask the current page first: notice that we do it before calling |
784 | // GetNext/Prev() because the data transfered from the controls of the page | |
785 | // may change the value returned by these methods | |
47e64664 | 786 | if ( !m_page->Validate() || !m_page->TransferDataFromWindow() ) |
f6bcfd97 BP |
787 | { |
788 | // the page data is incorrect, don't do anything | |
789 | return; | |
790 | } | |
791 | ||
74b31181 | 792 | bool forward = event.GetEventObject() == m_btnNext; |
66cd017c | 793 | |
74b31181 VZ |
794 | wxWizardPage *page; |
795 | if ( forward ) | |
66cd017c | 796 | { |
74b31181 | 797 | page = m_page->GetNext(); |
66cd017c | 798 | } |
74b31181 | 799 | else // back |
66cd017c | 800 | { |
74b31181 VZ |
801 | page = m_page->GetPrev(); |
802 | ||
223d09f6 | 803 | wxASSERT_MSG( page, wxT("\"<Back\" button should have been disabled") ); |
66cd017c | 804 | } |
74b31181 | 805 | |
0a089246 | 806 | // just pass to the new page (or maybe not - but we don't care here) |
74b31181 | 807 | (void)ShowPage(page, forward); |
66cd017c VZ |
808 | } |
809 | ||
f80bf901 VZ |
810 | void wxWizard::OnHelp(wxCommandEvent& WXUNUSED(event)) |
811 | { | |
812 | // this function probably can never be called when we don't have an active | |
813 | // page, but a small extra check won't hurt | |
814 | if(m_page != NULL) | |
815 | { | |
816 | // Create and send the help event to the specific page handler | |
817 | // event data contains the active page so that context-sensitive | |
818 | // help is possible | |
ca65c044 | 819 | wxWizardEvent eventHelp(wxEVT_WIZARD_HELP, GetId(), true, m_page); |
f80bf901 VZ |
820 | (void)m_page->GetEventHandler()->ProcessEvent(eventHelp); |
821 | } | |
822 | } | |
823 | ||
91c68292 VZ |
824 | void wxWizard::OnWizEvent(wxWizardEvent& event) |
825 | { | |
826 | // the dialogs have wxWS_EX_BLOCK_EVENTS style on by default but we want to | |
827 | // propagate wxEVT_WIZARD_XXX to the parent (if any), so do it manually | |
828 | if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) | |
829 | { | |
830 | // the event will be propagated anyhow | |
0a640208 | 831 | event.Skip(); |
91c68292 | 832 | } |
b3eb133b WS |
833 | else |
834 | { | |
835 | wxWindow *parent = GetParent(); | |
91c68292 | 836 | |
b3eb133b WS |
837 | if ( !parent || !parent->GetEventHandler()->ProcessEvent(event) ) |
838 | { | |
839 | event.Skip(); | |
840 | } | |
841 | } | |
37f6a080 | 842 | |
94c09a19 | 843 | if ( ( !m_wasModal ) && |
37f6a080 JS |
844 | event.IsAllowed() && |
845 | ( event.GetEventType() == wxEVT_WIZARD_FINISHED || | |
846 | event.GetEventType() == wxEVT_WIZARD_CANCEL | |
847 | ) | |
848 | ) | |
849 | { | |
37f6a080 JS |
850 | Destroy(); |
851 | } | |
91c68292 | 852 | } |
f80bf901 | 853 | |
f49fd6d0 JS |
854 | void wxWizard::SetBitmap(const wxBitmap& bitmap) |
855 | { | |
856 | m_bitmap = bitmap; | |
857 | if (m_statbmp) | |
858 | m_statbmp->SetBitmap(m_bitmap); | |
859 | } | |
860 | ||
66cd017c VZ |
861 | // ---------------------------------------------------------------------------- |
862 | // wxWizardEvent | |
863 | // ---------------------------------------------------------------------------- | |
864 | ||
f80bf901 | 865 | wxWizardEvent::wxWizardEvent(wxEventType type, int id, bool direction, wxWizardPage* page) |
66cd017c VZ |
866 | : wxNotifyEvent(type, id) |
867 | { | |
f80bf901 VZ |
868 | // Modified 10-20-2001 Robert Cavanaugh |
869 | // add the active page to the event data | |
74b31181 | 870 | m_direction = direction; |
f80bf901 | 871 | m_page = page; |
66cd017c | 872 | } |
74b31181 | 873 | |
3aa8e4ea JS |
874 | /// Do the adaptation |
875 | bool wxWizard::DoLayoutAdaptation() | |
876 | { | |
877 | wxWindowList windows; | |
878 | wxWindowList pages; | |
879 | ||
880 | // Make all the pages (that use sizers) scrollable | |
881 | for ( wxSizerItemList::compatibility_iterator node = m_sizerPage->GetChildren().GetFirst(); node; node = node->GetNext() ) | |
882 | { | |
883 | wxSizerItem * const item = node->GetData(); | |
884 | if ( item->IsWindow() ) | |
885 | { | |
886 | wxWizardPage* page = wxDynamicCast(item->GetWindow(), wxWizardPage); | |
887 | if (page) | |
888 | { | |
889 | while (page) | |
890 | { | |
891 | if (!pages.Find(page) && page->GetSizer()) | |
892 | { | |
893 | // Create a scrolled window and reparent | |
894 | wxScrolledWindow* scrolledWindow = new wxScrolledWindow(page, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxVSCROLL|wxHSCROLL|wxBORDER_NONE); | |
895 | wxSizer* oldSizer = page->GetSizer(); | |
634bb98a | 896 | |
3aa8e4ea JS |
897 | wxSizer* newSizer = new wxBoxSizer(wxVERTICAL); |
898 | newSizer->Add(scrolledWindow,1, wxEXPAND, 0); | |
634bb98a | 899 | |
3aa8e4ea | 900 | page->SetSizer(newSizer, false /* don't delete the old sizer */); |
634bb98a | 901 | |
3aa8e4ea | 902 | scrolledWindow->SetSizer(oldSizer); |
634bb98a | 903 | |
3aa8e4ea | 904 | wxStandardDialogLayoutAdapter::DoReparentControls(page, scrolledWindow); |
634bb98a | 905 | |
3aa8e4ea JS |
906 | pages.Append(page); |
907 | windows.Append(scrolledWindow); | |
908 | } | |
909 | page = page->GetNext(); | |
910 | } | |
911 | } | |
912 | } | |
913 | } | |
914 | ||
915 | wxStandardDialogLayoutAdapter::DoFitWithScrolling(this, windows); | |
916 | ||
a8eeee19 JS |
917 | // Size event doesn't get sent soon enough on wxGTK |
918 | DoLayout(); | |
03647350 | 919 | |
3aa8e4ea JS |
920 | SetLayoutAdaptationDone(true); |
921 | ||
922 | return true; | |
923 | } | |
924 | ||
925 | bool wxWizard::ResizeBitmap(wxBitmap& bmp) | |
926 | { | |
927 | if (!GetBitmapPlacement()) | |
928 | return false; | |
929 | ||
930 | if (bmp.Ok()) | |
931 | { | |
932 | wxSize pageSize = m_sizerPage->GetSize(); | |
49b75749 JS |
933 | if (pageSize == wxSize(0,0)) |
934 | pageSize = GetPageSize(); | |
3aa8e4ea JS |
935 | int bitmapWidth = wxMax(bmp.GetWidth(), GetMinimumBitmapWidth()); |
936 | int bitmapHeight = pageSize.y; | |
937 | ||
634bb98a | 938 | if (!m_statbmp->GetBitmap().Ok() || m_statbmp->GetBitmap().GetHeight() != bitmapHeight) |
3aa8e4ea JS |
939 | { |
940 | wxBitmap bitmap(bitmapWidth, bitmapHeight); | |
941 | { | |
942 | wxMemoryDC dc; | |
943 | dc.SelectObject(bitmap); | |
944 | dc.SetBackground(wxBrush(m_bitmapBackgroundColour)); | |
945 | dc.Clear(); | |
946 | ||
947 | if (GetBitmapPlacement() & wxWIZARD_TILE) | |
948 | { | |
949 | TileBitmap(wxRect(0, 0, bitmapWidth, bitmapHeight), dc, bmp); | |
950 | } | |
951 | else | |
952 | { | |
953 | int x, y; | |
954 | ||
955 | if (GetBitmapPlacement() & wxWIZARD_HALIGN_LEFT) | |
956 | x = 0; | |
957 | else if (GetBitmapPlacement() & wxWIZARD_HALIGN_RIGHT) | |
634bb98a | 958 | x = bitmapWidth - bmp.GetWidth(); |
3aa8e4ea | 959 | else |
634bb98a | 960 | x = (bitmapWidth - bmp.GetWidth())/2; |
3aa8e4ea JS |
961 | |
962 | if (GetBitmapPlacement() & wxWIZARD_VALIGN_TOP) | |
963 | y = 0; | |
964 | else if (GetBitmapPlacement() & wxWIZARD_VALIGN_BOTTOM) | |
634bb98a | 965 | y = bitmapHeight - bmp.GetHeight(); |
3aa8e4ea | 966 | else |
634bb98a | 967 | y = (bitmapHeight - bmp.GetHeight())/2; |
3aa8e4ea JS |
968 | |
969 | dc.DrawBitmap(bmp, x, y, true); | |
970 | dc.SelectObject(wxNullBitmap); | |
971 | } | |
972 | } | |
973 | ||
974 | bmp = bitmap; | |
975 | } | |
976 | } | |
977 | ||
978 | return true; | |
979 | } | |
980 | ||
981 | bool wxWizard::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap) | |
982 | { | |
983 | int w = bitmap.GetWidth(); | |
984 | int h = bitmap.GetHeight(); | |
985 | ||
986 | wxMemoryDC dcMem; | |
987 | ||
988 | dcMem.SelectObjectAsSource(bitmap); | |
989 | ||
990 | int i, j; | |
991 | for (i = rect.x; i < rect.x + rect.width; i += w) | |
992 | { | |
993 | for (j = rect.y; j < rect.y + rect.height; j+= h) | |
994 | dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0); | |
995 | } | |
996 | dcMem.SelectObject(wxNullBitmap); | |
997 | ||
998 | return true; | |
999 | } | |
1000 | ||
1e6feb95 | 1001 | #endif // wxUSE_WIZARDDLG |