LCOV - code coverage report
Current view: top level - svtools/source/dialogs - wizardmachine.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 328 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 53 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svtools/wizardmachine.hxx>
      21             : #include <svtools/helpid.hrc>
      22             : #include <tools/debug.hxx>
      23             : #include <tools/diagnose_ex.h>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <svtools/svtresid.hxx>
      26             : #include <svtools/svtools.hrc>
      27             : 
      28             : 
      29             : namespace svt
      30             : {
      31             : 
      32             : 
      33             : 
      34             :     //= WizardPageImplData
      35             : 
      36             :     struct WizardPageImplData
      37             :     {
      38           0 :         WizardPageImplData()
      39             :         {
      40           0 :         }
      41             :     };
      42             : 
      43           0 :     OWizardPage::OWizardPage(vcl::Window *pParent, const OString& rID,
      44             :         const OUString& rUIXMLDescription)
      45             :         : TabPage(pParent, rID, rUIXMLDescription)
      46           0 :         , m_pImpl(new WizardPageImplData)
      47             :     {
      48           0 :     }
      49             : 
      50           0 :     OWizardPage::~OWizardPage()
      51             :     {
      52           0 :         disposeOnce();
      53           0 :     }
      54             : 
      55           0 :     void OWizardPage::dispose()
      56             :     {
      57           0 :         delete m_pImpl;
      58           0 :         TabPage::dispose();
      59           0 :     }
      60             : 
      61           0 :     void OWizardPage::initializePage()
      62             :     {
      63           0 :     }
      64             : 
      65           0 :     void OWizardPage::ActivatePage()
      66             :     {
      67           0 :         TabPage::ActivatePage();
      68           0 :         updateDialogTravelUI();
      69           0 :     }
      70             : 
      71           0 :     void OWizardPage::updateDialogTravelUI()
      72             :     {
      73           0 :         OWizardMachine* pWizardMachine = dynamic_cast< OWizardMachine* >( GetParent() );
      74           0 :         if ( pWizardMachine )
      75           0 :             pWizardMachine->updateTravelUI();
      76           0 :     }
      77             : 
      78           0 :     bool OWizardPage::canAdvance() const
      79             :     {
      80           0 :         return true;
      81             :     }
      82             : 
      83           0 :     bool OWizardPage::commitPage( WizardTypes::CommitPageReason )
      84             :     {
      85           0 :         return true;
      86             :     }
      87             : 
      88           0 :     struct WizardMachineImplData : public WizardTypes
      89             :     {
      90             :         OUString                        sTitleBase;         // the base for the title
      91             :         ::std::stack< WizardState >     aStateHistory;      // the history of all states (used for implementing "Back")
      92             : 
      93             :         WizardState                     nFirstUnknownPage;
      94             :             // the WizardDialog does not allow non-linear transitions (e.g. it's
      95             :             // not possible to add pages in a non-linear order), so we need some own maintenance data
      96             : 
      97             :         bool                            m_bAutoNextButtonState;
      98             : 
      99             :         bool                            m_bTravelingSuspended;
     100             : 
     101           0 :         WizardMachineImplData()
     102             :             :nFirstUnknownPage( 0 )
     103             :             ,m_bAutoNextButtonState( false )
     104           0 :             ,m_bTravelingSuspended( false )
     105             :         {
     106           0 :         }
     107             :     };
     108             : 
     109           0 :     OWizardMachine::OWizardMachine(vcl::Window* _pParent, const WinBits i_nStyle, WizardButtonFlags _nButtonFlags )
     110             :         :WizardDialog( _pParent, i_nStyle )
     111             :         ,m_pFinish(NULL)
     112             :         ,m_pCancel(NULL)
     113             :         ,m_pNextPage(NULL)
     114             :         ,m_pPrevPage(NULL)
     115             :         ,m_pHelp(NULL)
     116           0 :         ,m_pImpl( new WizardMachineImplData )
     117             :     {
     118           0 :         implConstruct( _nButtonFlags );
     119           0 :     }
     120             : 
     121           0 :     OWizardMachine::OWizardMachine(vcl::Window* _pParent, WizardButtonFlags _nButtonFlags )
     122             :         :WizardDialog( _pParent, "WizardDialog", "svt/ui/wizarddialog.ui" )
     123             :         ,m_pFinish(NULL)
     124             :         ,m_pCancel(NULL)
     125             :         ,m_pNextPage(NULL)
     126             :         ,m_pPrevPage(NULL)
     127             :         ,m_pHelp(NULL)
     128           0 :         ,m_pImpl( new WizardMachineImplData )
     129             :     {
     130           0 :         implConstruct( _nButtonFlags );
     131           0 :     }
     132             : 
     133             : 
     134           0 :     void OWizardMachine::implConstruct( const WizardButtonFlags _nButtonFlags )
     135             :     {
     136           0 :         m_pImpl->sTitleBase = GetText();
     137             : 
     138             :         // create the buttons according to the wizard button flags
     139             :         // the help button
     140           0 :         if (_nButtonFlags & WizardButtonFlags::HELP)
     141             :         {
     142           0 :             m_pHelp= VclPtr<HelpButton>::Create(this, WB_TABSTOP);
     143           0 :             m_pHelp->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
     144           0 :             m_pHelp->Show();
     145           0 :             AddButton( m_pHelp, WIZARDDIALOG_BUTTON_STDOFFSET_X);
     146             :         }
     147             : 
     148             :         // the previous button
     149           0 :         if (_nButtonFlags & WizardButtonFlags::PREVIOUS)
     150             :         {
     151           0 :             m_pPrevPage = VclPtr<PushButton>::Create(this, WB_TABSTOP);
     152           0 :             m_pPrevPage->SetHelpId( HID_WIZARD_PREVIOUS );
     153           0 :             m_pPrevPage->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
     154           0 :             m_pPrevPage->SetText(SVT_RESSTR(STR_WIZDLG_PREVIOUS));
     155           0 :             m_pPrevPage->Show();
     156             : 
     157           0 :             if (_nButtonFlags & WizardButtonFlags::NEXT)
     158           0 :                 AddButton( m_pPrevPage, ( WIZARDDIALOG_BUTTON_SMALLSTDOFFSET_X) );      // half x-offset to the next button
     159             :             else
     160           0 :                 AddButton( m_pPrevPage, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     161           0 :             SetPrevButton( m_pPrevPage );
     162           0 :             m_pPrevPage->SetClickHdl( LINK( this, OWizardMachine, OnPrevPage ) );
     163             :         }
     164             : 
     165             :         // the next button
     166           0 :         if (_nButtonFlags & WizardButtonFlags::NEXT)
     167             :         {
     168           0 :             m_pNextPage = VclPtr<PushButton>::Create(this, WB_TABSTOP);
     169           0 :             m_pNextPage->SetHelpId( HID_WIZARD_NEXT );
     170           0 :             m_pNextPage->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
     171           0 :             m_pNextPage->SetText(OUString(SVT_RESSTR(STR_WIZDLG_NEXT)));
     172           0 :             m_pNextPage->Show();
     173             : 
     174           0 :             AddButton( m_pNextPage, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     175           0 :             SetNextButton( m_pNextPage );
     176           0 :             m_pNextPage->SetClickHdl( LINK( this, OWizardMachine, OnNextPage ) );
     177             :         }
     178             : 
     179             :         // the finish button
     180           0 :         if (_nButtonFlags & WizardButtonFlags::FINISH)
     181             :         {
     182           0 :             m_pFinish = VclPtr<OKButton>::Create(this, WB_TABSTOP);
     183           0 :             m_pFinish->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
     184           0 :             m_pFinish->SetText(SVT_RESSTR(STR_WIZDLG_FINISH));
     185           0 :             m_pFinish->Show();
     186             : 
     187           0 :             AddButton( m_pFinish, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     188           0 :             m_pFinish->SetClickHdl( LINK( this, OWizardMachine, OnFinish ) );
     189             :         }
     190             : 
     191             :         // the cancel button
     192           0 :         if (_nButtonFlags & WizardButtonFlags::CANCEL)
     193             :         {
     194           0 :             m_pCancel = VclPtr<CancelButton>::Create(this, WB_TABSTOP);
     195           0 :             m_pCancel->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
     196           0 :             m_pCancel->Show();
     197             : 
     198           0 :             AddButton( m_pCancel, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     199             :         }
     200           0 :     }
     201             : 
     202             : 
     203           0 :     OWizardMachine::~OWizardMachine()
     204             :     {
     205           0 :         disposeOnce();
     206           0 :     }
     207             : 
     208           0 :     void OWizardMachine::dispose()
     209             :     {
     210           0 :         m_pFinish.disposeAndClear();
     211           0 :         m_pCancel.disposeAndClear();
     212           0 :         m_pNextPage.disposeAndClear();
     213           0 :         m_pPrevPage.disposeAndClear();
     214           0 :         m_pHelp.disposeAndClear();
     215             : 
     216           0 :         if (m_pImpl)
     217             :         {
     218           0 :             for (WizardState i = 0; i < m_pImpl->nFirstUnknownPage; ++i)
     219             :             {
     220           0 :                 TabPage *pPage = GetPage(i);
     221           0 :                 if (pPage)
     222           0 :                     pPage->disposeOnce();
     223             :             }
     224           0 :             delete m_pImpl;
     225           0 :             m_pImpl = NULL;
     226             :         }
     227             : 
     228           0 :         WizardDialog::dispose();
     229           0 :     }
     230             : 
     231             : 
     232           0 :     void OWizardMachine::implUpdateTitle()
     233             :     {
     234           0 :         OUString sCompleteTitle(m_pImpl->sTitleBase);
     235             : 
     236             :         // append the page title
     237           0 :         TabPage* pCurrentPage = GetPage(getCurrentState());
     238           0 :         if ( pCurrentPage && !pCurrentPage->GetText().isEmpty() )
     239             :         {
     240           0 :             sCompleteTitle += (" - " + pCurrentPage->GetText());
     241             :         }
     242             : 
     243           0 :         SetText(sCompleteTitle);
     244           0 :     }
     245             : 
     246             : 
     247           0 :     void OWizardMachine::setTitleBase(const OUString& _rTitleBase)
     248             :     {
     249           0 :         m_pImpl->sTitleBase = _rTitleBase;
     250           0 :         implUpdateTitle();
     251           0 :     }
     252             : 
     253             : 
     254           0 :     TabPage* OWizardMachine::GetOrCreatePage( const WizardState i_nState )
     255             :     {
     256           0 :         if ( NULL == GetPage( i_nState ) )
     257             :         {
     258           0 :             TabPage* pNewPage = createPage( i_nState );
     259             :             DBG_ASSERT( pNewPage, "OWizardMachine::GetOrCreatePage: invalid new page (NULL)!" );
     260             : 
     261             :             // fill up the page sequence of our base class (with dummies)
     262           0 :             while ( m_pImpl->nFirstUnknownPage < i_nState )
     263             :             {
     264           0 :                 AddPage( NULL );
     265           0 :                 ++m_pImpl->nFirstUnknownPage;
     266             :             }
     267             : 
     268           0 :             if ( m_pImpl->nFirstUnknownPage == i_nState )
     269             :             {
     270             :                 // encountered this page number the first time
     271           0 :                 AddPage( pNewPage );
     272           0 :                 ++m_pImpl->nFirstUnknownPage;
     273             :             }
     274             :             else
     275             :                 // already had this page - just change it
     276           0 :                 SetPage( i_nState, pNewPage );
     277             :         }
     278           0 :         return GetPage( i_nState );
     279             :     }
     280             : 
     281             : 
     282           0 :     void OWizardMachine::ActivatePage()
     283             :     {
     284           0 :         WizardDialog::ActivatePage();
     285             : 
     286           0 :         WizardState nCurrentLevel = GetCurLevel();
     287           0 :         GetOrCreatePage( nCurrentLevel );
     288             : 
     289           0 :         enterState( nCurrentLevel );
     290           0 :     }
     291             : 
     292             : 
     293           0 :     bool OWizardMachine::DeactivatePage()
     294             :     {
     295           0 :         WizardState nCurrentState = getCurrentState();
     296           0 :         if (!leaveState(nCurrentState) || !WizardDialog::DeactivatePage())
     297           0 :             return false;
     298           0 :         return true;
     299             :     }
     300             : 
     301             : 
     302           0 :     void OWizardMachine::defaultButton(WizardButtonFlags _nWizardButtonFlags)
     303             :     {
     304             :         // the new default button
     305           0 :         PushButton* pNewDefButton = NULL;
     306           0 :         if (m_pFinish && (_nWizardButtonFlags & WizardButtonFlags::FINISH))
     307           0 :             pNewDefButton = m_pFinish;
     308           0 :         if (m_pNextPage && (_nWizardButtonFlags & WizardButtonFlags::NEXT))
     309           0 :             pNewDefButton = m_pNextPage;
     310           0 :         if (m_pPrevPage && (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS))
     311           0 :             pNewDefButton = m_pPrevPage;
     312           0 :         if (m_pHelp && (_nWizardButtonFlags & WizardButtonFlags::HELP))
     313           0 :             pNewDefButton = m_pHelp;
     314           0 :         if (m_pCancel && (_nWizardButtonFlags & WizardButtonFlags::CANCEL))
     315           0 :             pNewDefButton = m_pCancel;
     316             : 
     317           0 :         if ( pNewDefButton )
     318           0 :             defaultButton( pNewDefButton );
     319             :         else
     320           0 :             implResetDefault( this );
     321           0 :     }
     322             : 
     323             : 
     324           0 :     void OWizardMachine::implResetDefault(vcl::Window* _pWindow)
     325             :     {
     326           0 :         vcl::Window* pChildLoop = _pWindow->GetWindow(GetWindowType::FirstChild);
     327           0 :         while (pChildLoop)
     328             :         {
     329             :             // does the window participate in the tabbing order?
     330           0 :             if (pChildLoop->GetStyle() & WB_DIALOGCONTROL)
     331           0 :                 implResetDefault(pChildLoop);
     332             : 
     333             :             // is it a button?
     334           0 :             WindowType eType = pChildLoop->GetType();
     335           0 :             if  (   (WINDOW_BUTTON == eType)
     336           0 :                 ||  (WINDOW_PUSHBUTTON == eType)
     337           0 :                 ||  (WINDOW_OKBUTTON == eType)
     338           0 :                 ||  (WINDOW_CANCELBUTTON == eType)
     339           0 :                 ||  (WINDOW_HELPBUTTON == eType)
     340           0 :                 ||  (WINDOW_IMAGEBUTTON == eType)
     341           0 :                 ||  (WINDOW_MENUBUTTON == eType)
     342           0 :                 ||  (WINDOW_MOREBUTTON == eType)
     343             :                 )
     344             :             {
     345           0 :                 pChildLoop->SetStyle(pChildLoop->GetStyle() & ~WB_DEFBUTTON);
     346             :             }
     347             : 
     348             :             // the next one ...
     349           0 :             pChildLoop = pChildLoop->GetWindow(GetWindowType::Next);
     350             :         }
     351           0 :     }
     352             : 
     353             : 
     354           0 :     void OWizardMachine::defaultButton(PushButton* _pNewDefButton)
     355             :     {
     356             :         // loop through all (direct and indirect) descendants which participate in our tabbing order, and
     357             :         // reset the WB_DEFBUTTON for every window which is a button
     358           0 :         implResetDefault(this);
     359             : 
     360             :         // set it's new style
     361           0 :         if (_pNewDefButton)
     362           0 :             _pNewDefButton->SetStyle(_pNewDefButton->GetStyle() | WB_DEFBUTTON);
     363           0 :     }
     364             : 
     365             : 
     366           0 :     void OWizardMachine::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
     367             :     {
     368           0 :         if (m_pFinish && (_nWizardButtonFlags & WizardButtonFlags::FINISH))
     369           0 :             m_pFinish->Enable(_bEnable);
     370           0 :         if (m_pNextPage && (_nWizardButtonFlags & WizardButtonFlags::NEXT))
     371           0 :             m_pNextPage->Enable(_bEnable);
     372           0 :         if (m_pPrevPage && (_nWizardButtonFlags & WizardButtonFlags::PREVIOUS))
     373           0 :             m_pPrevPage->Enable(_bEnable);
     374           0 :         if (m_pHelp && (_nWizardButtonFlags & WizardButtonFlags::HELP))
     375           0 :             m_pHelp->Enable(_bEnable);
     376           0 :         if (m_pCancel && (_nWizardButtonFlags & WizardButtonFlags::CANCEL))
     377           0 :             m_pCancel->Enable(_bEnable);
     378           0 :     }
     379             : 
     380             : 
     381           0 :     void OWizardMachine::enterState(WizardState _nState)
     382             :     {
     383             :         // tell the page
     384           0 :         IWizardPageController* pController = getPageController( GetPage( _nState ) );
     385             :         OSL_ENSURE( pController, "OWizardMachine::enterState: no controller for the given page!" );
     386           0 :         if ( pController )
     387           0 :             pController->initializePage();
     388             : 
     389           0 :         if ( isAutomaticNextButtonStateEnabled() )
     390           0 :             enableButtons( WizardButtonFlags::NEXT, canAdvance() );
     391             : 
     392           0 :         enableButtons( WizardButtonFlags::PREVIOUS, !m_pImpl->aStateHistory.empty() );
     393             : 
     394             :         // set the new title - it depends on the current page (i.e. state)
     395           0 :         implUpdateTitle();
     396           0 :     }
     397             : 
     398             : 
     399           0 :     bool OWizardMachine::leaveState(WizardState)
     400             :     {
     401             :         // no need to ask the page here.
     402             :         // If we reach this point, we already gave the current page the chance to commit it's data,
     403             :         // and it was allowed to commit it's data
     404             : 
     405           0 :         return true;
     406             :     }
     407             : 
     408             : 
     409           0 :     bool OWizardMachine::onFinish()
     410             :     {
     411           0 :         return Finish( RET_OK );
     412             :     }
     413             : 
     414             : 
     415           0 :     IMPL_LINK_NOARG(OWizardMachine, OnFinish)
     416             :     {
     417           0 :         if ( isTravelingSuspended() )
     418           0 :             return 0;
     419           0 :         WizardTravelSuspension aTravelGuard( *this );
     420           0 :         if ( !prepareLeaveCurrentState( eFinish ) )
     421             :         {
     422           0 :             return 0L;
     423             :         }
     424           0 :         return onFinish() ? 1L : 0L;
     425             :     }
     426             : 
     427             : 
     428           0 :     OWizardMachine::WizardState OWizardMachine::determineNextState( WizardState _nCurrentState ) const
     429             :     {
     430           0 :         return _nCurrentState + 1;
     431             :     }
     432             : 
     433             : 
     434           0 :     bool OWizardMachine::prepareLeaveCurrentState( CommitPageReason _eReason )
     435             :     {
     436           0 :         IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
     437           0 :         ENSURE_OR_RETURN( pController != NULL, "OWizardMachine::prepareLeaveCurrentState: no controller for the current page!", true );
     438           0 :         return pController->commitPage( _eReason );
     439             :     }
     440             : 
     441             : 
     442           0 :     bool OWizardMachine::skipBackwardUntil( WizardState _nTargetState )
     443             :     {
     444             :         // allowed to leave the current page?
     445           0 :         if ( !prepareLeaveCurrentState( eTravelBackward ) )
     446           0 :             return false;
     447             : 
     448             :         // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong
     449           0 :         ::std::stack< WizardState > aTravelVirtually = m_pImpl->aStateHistory;
     450           0 :         ::std::stack< WizardState > aOldStateHistory = m_pImpl->aStateHistory;
     451             : 
     452           0 :         WizardState nCurrentRollbackState = getCurrentState();
     453           0 :         while ( nCurrentRollbackState != _nTargetState )
     454             :         {
     455             :             DBG_ASSERT( !aTravelVirtually.empty(), "OWizardMachine::skipBackwardUntil: this target state does not exist in the history!" );
     456           0 :             nCurrentRollbackState = aTravelVirtually.top();
     457           0 :             aTravelVirtually.pop();
     458             :         }
     459           0 :         m_pImpl->aStateHistory = aTravelVirtually;
     460           0 :         if ( !ShowPage( _nTargetState ) )
     461             :         {
     462           0 :             m_pImpl->aStateHistory = aOldStateHistory;
     463           0 :             return false;
     464             :         }
     465           0 :         return true;
     466             :     }
     467             : 
     468             : 
     469           0 :     bool OWizardMachine::skipUntil( WizardState _nTargetState )
     470             :     {
     471           0 :         WizardState nCurrentState = getCurrentState();
     472             : 
     473             :         // allowed to leave the current page?
     474           0 :         if ( !prepareLeaveCurrentState( nCurrentState < _nTargetState ? eTravelForward : eTravelBackward ) )
     475           0 :             return false;
     476             : 
     477             :         // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong
     478           0 :         ::std::stack< WizardState > aTravelVirtually = m_pImpl->aStateHistory;
     479           0 :         ::std::stack< WizardState > aOldStateHistory = m_pImpl->aStateHistory;
     480           0 :         while ( nCurrentState != _nTargetState )
     481             :         {
     482           0 :             WizardState nNextState = determineNextState( nCurrentState );
     483           0 :             if ( WZS_INVALID_STATE == nNextState )
     484             :             {
     485             :                 OSL_FAIL( "OWizardMachine::skipUntil: the given target state does not exist!" );
     486           0 :                 return false;
     487             :             }
     488             : 
     489             :             // remember the skipped state in the history
     490           0 :             aTravelVirtually.push( nCurrentState );
     491             : 
     492             :             // get the next state
     493           0 :             nCurrentState = nNextState;
     494             :         }
     495           0 :         m_pImpl->aStateHistory = aTravelVirtually;
     496             :         // show the target page
     497           0 :         if ( !ShowPage( nCurrentState ) )
     498             :         {
     499             :             // argh! prepareLeaveCurrentPage succeeded, determineNextState succeeded,
     500             :             // but ShowPage doesn't? Somebody behaves very strange here ....
     501             :             OSL_FAIL( "OWizardMachine::skipUntil: very unpolite ...." );
     502           0 :             m_pImpl->aStateHistory = aOldStateHistory;
     503           0 :             return false;
     504             :         }
     505           0 :         return true;
     506             :     }
     507             : 
     508             : 
     509           0 :     bool OWizardMachine::skip(sal_Int32 _nSteps)
     510             :     {
     511             :         DBG_ASSERT(_nSteps > 0, "OWizardMachine::skip: invalid number of steps!");
     512             :         // allowed to leave the current page?
     513           0 :         if ( !prepareLeaveCurrentState( eTravelForward ) )
     514           0 :             return false;
     515             : 
     516           0 :         WizardState nCurrentState = getCurrentState();
     517           0 :         WizardState nNextState = determineNextState(nCurrentState);
     518             :         // loop _nSteps steps
     519           0 :         while (_nSteps-- > 0)
     520             :         {
     521           0 :             if (WZS_INVALID_STATE == nNextState)
     522           0 :                 return false;
     523             : 
     524             :             // remember the skipped state in the history
     525           0 :             m_pImpl->aStateHistory.push(nCurrentState);
     526             : 
     527             :             // get the next state
     528           0 :             nCurrentState = nNextState;
     529           0 :             nNextState = determineNextState(nCurrentState);
     530             :         }
     531             : 
     532             :         // show the (n+1)th page
     533           0 :         if (!ShowPage(nCurrentState))
     534             :         {
     535             :             // TODO: this leaves us in a state where we have no current page and an inconsistent state history.
     536             :             // Perhaps we should rollback the skipping here ....
     537             :             OSL_FAIL("OWizardMachine::skip: very unpolite ....");
     538             :                 // if somebody does a skip and then does not allow to leave ...
     539             :                 // (can't be a commit error, as we've already committed the current page. So if ShowPage fails here,
     540             :                 // somebody behaves really strange ...)
     541           0 :             return false;
     542             :         }
     543             : 
     544             :         // all fine
     545           0 :         return true;
     546             :     }
     547             : 
     548             : 
     549           0 :     bool OWizardMachine::travelNext()
     550             :     {
     551             :         // allowed to leave the current page?
     552           0 :         if ( !prepareLeaveCurrentState( eTravelForward ) )
     553           0 :             return false;
     554             : 
     555             :         // determine the next state to travel to
     556           0 :         WizardState nCurrentState = getCurrentState();
     557           0 :         WizardState nNextState = determineNextState(nCurrentState);
     558           0 :         if (WZS_INVALID_STATE == nNextState)
     559           0 :             return false;
     560             : 
     561             :         // the state history is used by the enterState method
     562             :         // all fine
     563           0 :         m_pImpl->aStateHistory.push(nCurrentState);
     564           0 :         if (!ShowPage(nNextState))
     565             :         {
     566           0 :             m_pImpl->aStateHistory.pop();
     567           0 :             return false;
     568             :         }
     569             : 
     570           0 :         return true;
     571             :     }
     572             : 
     573             : 
     574           0 :     bool OWizardMachine::travelPrevious()
     575             :     {
     576             :         DBG_ASSERT(m_pImpl->aStateHistory.size() > 0, "OWizardMachine::travelPrevious: have no previous page!");
     577             : 
     578             :         // allowed to leave the current page?
     579           0 :         if ( !prepareLeaveCurrentState( eTravelBackward ) )
     580           0 :             return false;
     581             : 
     582             :         // the next state to switch to
     583           0 :         WizardState nPreviousState = m_pImpl->aStateHistory.top();
     584             : 
     585             :         // the state history is used by the enterState method
     586           0 :         m_pImpl->aStateHistory.pop();
     587             :         // show this page
     588           0 :         if (!ShowPage(nPreviousState))
     589             :         {
     590           0 :             m_pImpl->aStateHistory.push(nPreviousState);
     591           0 :             return false;
     592             :         }
     593             : 
     594             :         // all fine
     595           0 :         return true;
     596             :     }
     597             : 
     598             : 
     599           0 :     void  OWizardMachine::removePageFromHistory( WizardState nToRemove )
     600             :     {
     601             : 
     602           0 :         ::std::stack< WizardState > aTemp;
     603           0 :         while(!m_pImpl->aStateHistory.empty())
     604             :         {
     605           0 :             WizardState nPreviousState = m_pImpl->aStateHistory.top();
     606           0 :             m_pImpl->aStateHistory.pop();
     607           0 :             if(nPreviousState != nToRemove)
     608           0 :                 aTemp.push( nPreviousState );
     609             :             else
     610           0 :                 break;
     611             :         }
     612           0 :         while(!aTemp.empty())
     613             :         {
     614           0 :             m_pImpl->aStateHistory.push( aTemp.top() );
     615           0 :             aTemp.pop();
     616           0 :         }
     617           0 :     }
     618             : 
     619             : 
     620           0 :     void OWizardMachine::enableAutomaticNextButtonState( bool _bEnable )
     621             :     {
     622           0 :         m_pImpl->m_bAutoNextButtonState = _bEnable;
     623           0 :     }
     624             : 
     625             : 
     626           0 :     bool OWizardMachine::isAutomaticNextButtonStateEnabled() const
     627             :     {
     628           0 :         return m_pImpl->m_bAutoNextButtonState;
     629             :     }
     630             : 
     631             : 
     632           0 :     IMPL_LINK_NOARG(OWizardMachine, OnPrevPage)
     633             :     {
     634           0 :         if ( isTravelingSuspended() )
     635           0 :             return 0;
     636           0 :         WizardTravelSuspension aTravelGuard( *this );
     637           0 :         bool nRet = travelPrevious();
     638           0 :         return nRet ? 1 : 0;
     639             :     }
     640             : 
     641             : 
     642           0 :     IMPL_LINK_NOARG(OWizardMachine, OnNextPage)
     643             :     {
     644           0 :         if ( isTravelingSuspended() )
     645           0 :             return 0;
     646           0 :         WizardTravelSuspension aTravelGuard( *this );
     647           0 :         bool nRet = travelNext();
     648           0 :         return nRet ? 1 : 0;
     649             :     }
     650             : 
     651             : 
     652           0 :     IWizardPageController* OWizardMachine::getPageController( TabPage* _pCurrentPage ) const
     653             :     {
     654           0 :         IWizardPageController* pController = dynamic_cast< IWizardPageController* >( _pCurrentPage );
     655           0 :         return pController;
     656             :     }
     657             : 
     658             : 
     659           0 :     void OWizardMachine::getStateHistory( ::std::vector< WizardState >& _out_rHistory )
     660             :     {
     661           0 :         ::std::stack< WizardState > aHistoryCopy( m_pImpl->aStateHistory );
     662           0 :         while ( !aHistoryCopy.empty() )
     663             :         {
     664           0 :             _out_rHistory.push_back( aHistoryCopy.top() );
     665           0 :             aHistoryCopy.pop();
     666           0 :         }
     667           0 :     }
     668             : 
     669             : 
     670           0 :     bool OWizardMachine::canAdvance() const
     671             :     {
     672           0 :         return WZS_INVALID_STATE != determineNextState( getCurrentState() );
     673             :     }
     674             : 
     675             : 
     676           0 :     void OWizardMachine::updateTravelUI()
     677             :     {
     678           0 :         const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
     679             :         OSL_ENSURE( pController != NULL, "RoadmapWizard::updateTravelUI: no controller for the current page!" );
     680             : 
     681             :         bool bCanAdvance =
     682           0 :                 ( !pController || pController->canAdvance() )   // the current page allows to advance
     683           0 :             &&  canAdvance();                                   // the dialog as a whole allows to advance
     684           0 :         enableButtons( WizardButtonFlags::NEXT, bCanAdvance );
     685           0 :     }
     686             : 
     687             : 
     688           0 :     bool OWizardMachine::isTravelingSuspended() const
     689             :     {
     690           0 :         return m_pImpl->m_bTravelingSuspended;
     691             :     }
     692             : 
     693             : 
     694           0 :     void OWizardMachine::suspendTraveling( AccessGuard )
     695             :     {
     696             :         DBG_ASSERT( !m_pImpl->m_bTravelingSuspended, "OWizardMachine::suspendTraveling: already suspended!" );
     697           0 :        m_pImpl->m_bTravelingSuspended = true;
     698           0 :     }
     699             : 
     700             : 
     701           0 :     void OWizardMachine::resumeTraveling( AccessGuard )
     702             :     {
     703             :         DBG_ASSERT( m_pImpl->m_bTravelingSuspended, "OWizardMachine::resumeTraveling: nothing to resume!" );
     704           0 :        m_pImpl->m_bTravelingSuspended = false;
     705           0 :     }
     706             : 
     707             : 
     708             : }   // namespace svt
     709             : 
     710             : 
     711             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11