Changes to support native C++ Run Time Type Information
[pwlib.git] / src / pwclib / wizard.cxx
blob145b9f88d4f00972f04a355e8b71f46a06ac6f51
1 /*
2 * wizard.cxx
4 * Wizard dialog classes.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
29 * $Log$
30 * Revision 1.5 2004/04/04 13:24:23 rjongbloed
31 * Changes to support native C++ Run Time Type Information
33 * Revision 1.4 1998/12/20 09:14:48 robertj
34 * Added pragma implementation for GNU compiler.
36 * Revision 1.3 1998/11/30 04:52:21 robertj
37 * New directory structure
39 * Revision 1.2 1998/09/23 06:29:59 robertj
40 * Added open source copyright license.
42 * Revision 1.1 1998/09/15 11:47:20 robertj
43 * Initial revision
47 #ifdef __GNUC__
48 #pragma implementation "wizard.h"
49 #endif
51 #include <pwlib.h>
52 #include <pwclib/wizard.h>
54 #define new PNEW
57 //////////////////////////////////////////////////////////////////////////////
58 // PWizardPage
60 PWizardPage::PWizardPage(PInteractor * parent, PRESOURCE_ID resID)
61 : PInteractorLayout(parent, resID)
63 SetBackgroundColour(owner->GetButtonBkColour());
64 pageIdentifier = resID;
68 void PWizardPage::OnInitialisePage()
73 void PWizardPage::OnCompletedPages()
78 void PWizardPage::OnEnteringPage()
83 BOOL PWizardPage::OnLeavingPage()
85 return TRUE;
89 BOOL PWizardPage::IsFinalPage() const
91 return FALSE;
95 PRESOURCE_ID PWizardPage::GetNextPage() const
97 return 0; // Next page as in AddPage() sequence.
101 //////////////////////////////////////////////////////////////////////////////
102 // PWizardFrame
104 PWizardFrame::PWizardFrame(PInteractor * parent, PRESOURCE_ID resID)
105 : PInteractorLayout(parent, resID),
106 originalSize(GetDimensions(PixelCoords))
108 pages.DisallowDeleteObjects();
109 SetBackgroundColour(owner->GetButtonBkColour());
110 currentPage = NULL;
111 back = next = abort = finish = NULL;
115 void PWizardFrame::ConstructEnd(PRESOURCE_ID resID)
117 PInteractorLayout::ConstructEnd(resID);
119 PDim dim = GetDimensions(PixelCoords);
120 PDim offset = dim - originalSize;
121 dim.SetHeight(offset.Height());
123 PINDEX idx;
124 for (idx = 0; idx < children.GetSize(); idx++) {
125 PInteractor & child = children[idx];
126 child.ShowAll();
127 if (PIsDescendant(&child, PWizardPage)) {
128 if (&child != currentPage)
129 child.Hide();
130 child.SetDimensions(dim, PixelCoords);
131 PWizardPage & page = (PWizardPage &)child;
132 page.OnInitialisePage();
133 page.UpdateControls();
135 else
136 child.SetPosition(child.GetPosition(PixelCoords)+offset, TopLeftPixels, TopLeftPixels);
139 if (back != NULL)
140 back->Disable();
142 if (finish != NULL)
143 finish->Hide();
145 Show();
149 void PWizardFrame::AddPage(PWizardPage * page)
151 if (currentPage == NULL)
152 currentPage = page;
154 pages.SetAt(page->GetIdentifier(), page);
156 PDim wiz_dim = GetDimensions(PixelCoords);
157 wiz_dim.AddHeight(-(int)originalSize.Height());
159 PDim page_dim = page->GetDimensions(PixelCoords);
161 if (page_dim.Width() > wiz_dim.Width())
162 wiz_dim.SetWidth(page_dim.Width());
164 if (page_dim.Height() > wiz_dim.Height())
165 wiz_dim.SetHeight(page_dim.Height());
167 wiz_dim.AddHeight(originalSize.Height());
169 SetDimensions(wiz_dim, PixelCoords);
173 void PWizardFrame::Back(class PTextButton &, int)
175 if (pageStack.IsEmpty())
176 return;
178 PAssert(currentPage != NULL, PLogicError);
180 currentPage->Hide();
181 currentPage = pageStack.Pop();
182 currentPage->Show();
184 if (back != NULL && pageStack.IsEmpty())
185 back->Disable();
187 if (next != NULL)
188 next->Show();
190 if (finish != NULL)
191 finish->Hide();
195 void PWizardFrame::Next(class PTextButton &, int)
197 PAssert(currentPage != NULL, PLogicError);
198 SetCurrentPage(currentPage->GetNextPage());
202 void PWizardFrame::Abort(class PTextButton &, int)
204 OnFinished(TRUE);
208 void PWizardFrame::Finish(class PTextButton &, int)
210 if (currentPage->OnLeavingPage())
211 OnFinished(FALSE);
215 void PWizardFrame::OnFinished(BOOL aborted)
217 if (!aborted) {
218 PINDEX idx;
219 for (idx = 0; idx < pages.GetSize(); idx++)
220 pages.GetDataAt(idx).OnCompletedPages();
223 if (PIsDescendant(parent, PDialog))
224 ((PDialog *)parent)->Close();
225 else if (PIsDescendant(parent, PTitledWindow))
226 ((PTitledWindow *)parent)->Close();
230 BOOL PWizardFrame::SetCurrentPage(PRESOURCE_ID nextId)
232 PAssert(currentPage != NULL, PLogicError);
234 if (currentPage->GetIdentifier() == nextId)
235 return FALSE;
237 if (!currentPage->OnLeavingPage())
238 return FALSE;
240 PWizardPage * nextPage = NULL;
242 if (nextId != 0)
243 nextPage = pages.GetAt(nextId);
244 else {
245 PINDEX idx = children.GetObjectsIndex(currentPage);
246 if (idx != P_MAX_INDEX) {
247 while (++idx < children.GetSize()) {
248 if (PIsDescendant(&children[idx], PWizardPage)) {
249 nextPage = (PWizardPage *)&children[idx];
250 break;
256 if (nextPage == NULL)
257 return FALSE;
259 pageStack.Push(currentPage);
260 currentPage->Hide();
261 currentPage = nextPage;
262 currentPage->OnEnteringPage();
263 currentPage->Show();
265 if (back != NULL)
266 back->Enable();
268 if (!currentPage->IsFinalPage())
269 return TRUE;
271 if (next != NULL)
272 next->Hide();
274 if (finish != NULL)
275 finish->Show();
276 return TRUE;
280 //////////////////////////////////////////////////////////////////////////////
281 // PWizardDialog
283 PWizardDialog::PWizardDialog(PInteractor * parent, PWizardFrame * frame)
284 : PModalDialog(parent)
286 SetDimensions(frame->GetDimensions(PixelCoords), PixelCoords);
290 // End Of File ///////////////////////////////////////////////////////////////