wizard.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:6k
- /*
- * wizard.cxx
- *
- * Wizard dialog classes.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: wizard.cxx,v $
- * Revision 1.4 1998/12/20 09:14:48 robertj
- * Added pragma implementation for GNU compiler.
- *
- * Revision 1.3 1998/11/30 04:52:21 robertj
- * New directory structure
- *
- * Revision 1.2 1998/09/23 06:29:59 robertj
- * Added open source copyright license.
- *
- * Revision 1.1 1998/09/15 11:47:20 robertj
- * Initial revision
- *
- */
- #ifdef __GNUC__
- #pragma implementation "wizard.h"
- #endif
- #include <pwlib.h>
- #include <pwclib/wizard.h>
- #define new PNEW
- //////////////////////////////////////////////////////////////////////////////
- // PWizardPage
- PWizardPage::PWizardPage(PInteractor * parent, PRESOURCE_ID resID)
- : PInteractorLayout(parent, resID)
- {
- SetBackgroundColour(owner->GetButtonBkColour());
- pageIdentifier = resID;
- }
- void PWizardPage::OnInitialisePage()
- {
- }
- void PWizardPage::OnCompletedPages()
- {
- }
- void PWizardPage::OnEnteringPage()
- {
- }
- BOOL PWizardPage::OnLeavingPage()
- {
- return TRUE;
- }
- BOOL PWizardPage::IsFinalPage() const
- {
- return FALSE;
- }
- PRESOURCE_ID PWizardPage::GetNextPage() const
- {
- return 0; // Next page as in AddPage() sequence.
- }
- //////////////////////////////////////////////////////////////////////////////
- // PWizardFrame
- PWizardFrame::PWizardFrame(PInteractor * parent, PRESOURCE_ID resID)
- : PInteractorLayout(parent, resID),
- originalSize(GetDimensions(PixelCoords))
- {
- pages.DisallowDeleteObjects();
- SetBackgroundColour(owner->GetButtonBkColour());
- currentPage = NULL;
- back = next = abort = finish = NULL;
- }
- void PWizardFrame::ConstructEnd(PRESOURCE_ID resID)
- {
- PInteractorLayout::ConstructEnd(resID);
- PDim dim = GetDimensions(PixelCoords);
- PDim offset = dim - originalSize;
- dim.SetHeight(offset.Height());
- PINDEX idx;
- for (idx = 0; idx < children.GetSize(); idx++) {
- PInteractor & child = children[idx];
- child.ShowAll();
- if (child.IsDescendant(PWizardPage::Class())) {
- if (&child != currentPage)
- child.Hide();
- child.SetDimensions(dim, PixelCoords);
- PWizardPage & page = (PWizardPage &)child;
- page.OnInitialisePage();
- page.UpdateControls();
- }
- else
- child.SetPosition(child.GetPosition(PixelCoords)+offset, TopLeftPixels, TopLeftPixels);
- }
- if (back != NULL)
- back->Disable();
- if (finish != NULL)
- finish->Hide();
- Show();
- }
- void PWizardFrame::AddPage(PWizardPage * page)
- {
- if (currentPage == NULL)
- currentPage = page;
- pages.SetAt(page->GetIdentifier(), page);
- PDim wiz_dim = GetDimensions(PixelCoords);
- wiz_dim.AddHeight(-(int)originalSize.Height());
- PDim page_dim = page->GetDimensions(PixelCoords);
- if (page_dim.Width() > wiz_dim.Width())
- wiz_dim.SetWidth(page_dim.Width());
- if (page_dim.Height() > wiz_dim.Height())
- wiz_dim.SetHeight(page_dim.Height());
- wiz_dim.AddHeight(originalSize.Height());
- SetDimensions(wiz_dim, PixelCoords);
- }
- void PWizardFrame::Back(class PTextButton &, int)
- {
- if (pageStack.IsEmpty())
- return;
- PAssert(currentPage != NULL, PLogicError);
- currentPage->Hide();
- currentPage = pageStack.Pop();
- currentPage->Show();
- if (back != NULL && pageStack.IsEmpty())
- back->Disable();
- if (next != NULL)
- next->Show();
- if (finish != NULL)
- finish->Hide();
- }
- void PWizardFrame::Next(class PTextButton &, int)
- {
- PAssert(currentPage != NULL, PLogicError);
- SetCurrentPage(currentPage->GetNextPage());
- }
- void PWizardFrame::Abort(class PTextButton &, int)
- {
- OnFinished(TRUE);
- }
- void PWizardFrame::Finish(class PTextButton &, int)
- {
- if (currentPage->OnLeavingPage())
- OnFinished(FALSE);
- }
- void PWizardFrame::OnFinished(BOOL aborted)
- {
- if (!aborted) {
- PINDEX idx;
- for (idx = 0; idx < pages.GetSize(); idx++)
- pages.GetDataAt(idx).OnCompletedPages();
- }
- if (parent->IsDescendant(PDialog::Class()))
- ((PDialog *)parent)->Close();
- else if (parent->IsDescendant(PTitledWindow::Class()))
- ((PTitledWindow *)parent)->Close();
- }
- BOOL PWizardFrame::SetCurrentPage(PRESOURCE_ID nextId)
- {
- PAssert(currentPage != NULL, PLogicError);
- if (currentPage->GetIdentifier() == nextId)
- return FALSE;
- if (!currentPage->OnLeavingPage())
- return FALSE;
- PWizardPage * nextPage = NULL;
- if (nextId != 0)
- nextPage = pages.GetAt(nextId);
- else {
- PINDEX idx = children.GetObjectsIndex(currentPage);
- if (idx != P_MAX_INDEX) {
- while (++idx < children.GetSize()) {
- if (children[idx].IsDescendant(PWizardPage::Class())) {
- nextPage = (PWizardPage *)&children[idx];
- break;
- }
- }
- }
- }
- if (nextPage == NULL)
- return FALSE;
- pageStack.Push(currentPage);
- currentPage->Hide();
- currentPage = nextPage;
- currentPage->OnEnteringPage();
- currentPage->Show();
- if (back != NULL)
- back->Enable();
- if (!currentPage->IsFinalPage())
- return TRUE;
- if (next != NULL)
- next->Hide();
- if (finish != NULL)
- finish->Show();
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////////
- // PWizardDialog
- PWizardDialog::PWizardDialog(PInteractor * parent, PWizardFrame * frame)
- : PModalDialog(parent)
- {
- SetDimensions(frame->GetDimensions(PixelCoords), PixelCoords);
- }
- // End Of File ///////////////////////////////////////////////////////////////