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

Generated by: LCOV version 1.10