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

Generated by: LCOV version 1.10