Uncommented beaudio code
[pwlib.git] / src / pwclib / wizard.cxx
blobba7a96e8653b311c114ce97cd841f00f2ca86188
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.4 1998/12/20 09:14:48 robertj
31 * Added pragma implementation for GNU compiler.
33 * Revision 1.3 1998/11/30 04:52:21 robertj
34 * New directory structure
36 * Revision 1.2 1998/09/23 06:29:59 robertj
37 * Added open source copyright license.
39 * Revision 1.1 1998/09/15 11:47:20 robertj
40 * Initial revision
44 #ifdef __GNUC__
45 #pragma implementation "wizard.h"
46 #endif
48 #include <pwlib.h>
49 #include <pwclib/wizard.h>
51 #define new PNEW
54 //////////////////////////////////////////////////////////////////////////////
55 // PWizardPage
57 PWizardPage::PWizardPage(PInteractor * parent, PRESOURCE_ID resID)
58 : PInteractorLayout(parent, resID)
60 SetBackgroundColour(owner->GetButtonBkColour());
61 pageIdentifier = resID;
65 void PWizardPage::OnInitialisePage()
70 void PWizardPage::OnCompletedPages()
75 void PWizardPage::OnEnteringPage()
80 BOOL PWizardPage::OnLeavingPage()
82 return TRUE;
86 BOOL PWizardPage::IsFinalPage() const
88 return FALSE;
92 PRESOURCE_ID PWizardPage::GetNextPage() const
94 return 0; // Next page as in AddPage() sequence.
98 //////////////////////////////////////////////////////////////////////////////
99 // PWizardFrame
101 PWizardFrame::PWizardFrame(PInteractor * parent, PRESOURCE_ID resID)
102 : PInteractorLayout(parent, resID),
103 originalSize(GetDimensions(PixelCoords))
105 pages.DisallowDeleteObjects();
106 SetBackgroundColour(owner->GetButtonBkColour());
107 currentPage = NULL;
108 back = next = abort = finish = NULL;
112 void PWizardFrame::ConstructEnd(PRESOURCE_ID resID)
114 PInteractorLayout::ConstructEnd(resID);
116 PDim dim = GetDimensions(PixelCoords);
117 PDim offset = dim - originalSize;
118 dim.SetHeight(offset.Height());
120 PINDEX idx;
121 for (idx = 0; idx < children.GetSize(); idx++) {
122 PInteractor & child = children[idx];
123 child.ShowAll();
124 if (child.IsDescendant(PWizardPage::Class())) {
125 if (&child != currentPage)
126 child.Hide();
127 child.SetDimensions(dim, PixelCoords);
128 PWizardPage & page = (PWizardPage &)child;
129 page.OnInitialisePage();
130 page.UpdateControls();
132 else
133 child.SetPosition(child.GetPosition(PixelCoords)+offset, TopLeftPixels, TopLeftPixels);
136 if (back != NULL)
137 back->Disable();
139 if (finish != NULL)
140 finish->Hide();
142 Show();
146 void PWizardFrame::AddPage(PWizardPage * page)
148 if (currentPage == NULL)
149 currentPage = page;
151 pages.SetAt(page->GetIdentifier(), page);
153 PDim wiz_dim = GetDimensions(PixelCoords);
154 wiz_dim.AddHeight(-(int)originalSize.Height());
156 PDim page_dim = page->GetDimensions(PixelCoords);
158 if (page_dim.Width() > wiz_dim.Width())
159 wiz_dim.SetWidth(page_dim.Width());
161 if (page_dim.Height() > wiz_dim.Height())
162 wiz_dim.SetHeight(page_dim.Height());
164 wiz_dim.AddHeight(originalSize.Height());
166 SetDimensions(wiz_dim, PixelCoords);
170 void PWizardFrame::Back(class PTextButton &, int)
172 if (pageStack.IsEmpty())
173 return;
175 PAssert(currentPage != NULL, PLogicError);
177 currentPage->Hide();
178 currentPage = pageStack.Pop();
179 currentPage->Show();
181 if (back != NULL && pageStack.IsEmpty())
182 back->Disable();
184 if (next != NULL)
185 next->Show();
187 if (finish != NULL)
188 finish->Hide();
192 void PWizardFrame::Next(class PTextButton &, int)
194 PAssert(currentPage != NULL, PLogicError);
195 SetCurrentPage(currentPage->GetNextPage());
199 void PWizardFrame::Abort(class PTextButton &, int)
201 OnFinished(TRUE);
205 void PWizardFrame::Finish(class PTextButton &, int)
207 if (currentPage->OnLeavingPage())
208 OnFinished(FALSE);
212 void PWizardFrame::OnFinished(BOOL aborted)
214 if (!aborted) {
215 PINDEX idx;
216 for (idx = 0; idx < pages.GetSize(); idx++)
217 pages.GetDataAt(idx).OnCompletedPages();
220 if (parent->IsDescendant(PDialog::Class()))
221 ((PDialog *)parent)->Close();
222 else if (parent->IsDescendant(PTitledWindow::Class()))
223 ((PTitledWindow *)parent)->Close();
227 BOOL PWizardFrame::SetCurrentPage(PRESOURCE_ID nextId)
229 PAssert(currentPage != NULL, PLogicError);
231 if (currentPage->GetIdentifier() == nextId)
232 return FALSE;
234 if (!currentPage->OnLeavingPage())
235 return FALSE;
237 PWizardPage * nextPage = NULL;
239 if (nextId != 0)
240 nextPage = pages.GetAt(nextId);
241 else {
242 PINDEX idx = children.GetObjectsIndex(currentPage);
243 if (idx != P_MAX_INDEX) {
244 while (++idx < children.GetSize()) {
245 if (children[idx].IsDescendant(PWizardPage::Class())) {
246 nextPage = (PWizardPage *)&children[idx];
247 break;
253 if (nextPage == NULL)
254 return FALSE;
256 pageStack.Push(currentPage);
257 currentPage->Hide();
258 currentPage = nextPage;
259 currentPage->OnEnteringPage();
260 currentPage->Show();
262 if (back != NULL)
263 back->Enable();
265 if (!currentPage->IsFinalPage())
266 return TRUE;
268 if (next != NULL)
269 next->Hide();
271 if (finish != NULL)
272 finish->Show();
273 return TRUE;
277 //////////////////////////////////////////////////////////////////////////////
278 // PWizardDialog
280 PWizardDialog::PWizardDialog(PInteractor * parent, PWizardFrame * frame)
281 : PModalDialog(parent)
283 SetDimensions(frame->GetDimensions(PixelCoords), PixelCoords);
287 // End Of File ///////////////////////////////////////////////////////////////