LCOV - code coverage report
Current view: top level - svtools/source/dialogs - roadmapwizard.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 277 0.0 %
Date: 2014-04-14 Functions: 0 32 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             : 
      21             : #include <svtools/roadmapwizard.hxx>
      22             : #include <svtools/svtools.hrc>
      23             : #include <svtools/svtresid.hxx>
      24             : #include <svtools/roadmap.hxx>
      25             : #include <tools/debug.hxx>
      26             : 
      27             : #include <stdarg.h>
      28             : 
      29             : #include <vector>
      30             : #include <map>
      31             : #include <set>
      32             : 
      33             : 
      34             : namespace svt
      35             : {
      36             : 
      37             : 
      38             :     namespace
      39             :     {
      40             :         typedef ::std::set< WizardTypes::WizardState >          StateSet;
      41             : 
      42             :         typedef ::std::map<
      43             :                     RoadmapWizardTypes::PathId,
      44             :                     RoadmapWizardTypes::WizardPath
      45             :                 >                                               Paths;
      46             : 
      47             :         typedef ::std::map<
      48             :                     WizardTypes::WizardState,
      49             :                     ::std::pair<
      50             :                         OUString,
      51             :                         RoadmapWizardTypes::RoadmapPageFactory
      52             :                     >
      53             :                 >                                               StateDescriptions;
      54             :     }
      55             : 
      56             :     struct RoadmapWizardImpl : public RoadmapWizardTypes
      57             :     {
      58             :         ORoadmap*           pRoadmap;
      59             :         Paths               aPaths;
      60             :         PathId              nActivePath;
      61             :         StateDescriptions   aStateDescriptors;
      62             :         StateSet            aDisabledStates;
      63             :         bool                bActivePathIsDefinite;
      64             :            FixedLine*           pFixedLine;
      65             : 
      66           0 :         RoadmapWizardImpl()
      67             :             :pRoadmap( NULL )
      68             :             ,nActivePath( -1 )
      69             :             ,bActivePathIsDefinite( false )
      70           0 :             ,pFixedLine(NULL)
      71             :         {
      72           0 :         }
      73             : 
      74           0 :         ~RoadmapWizardImpl()
      75           0 :         {
      76           0 :             delete pRoadmap;
      77           0 :             delete pFixedLine;
      78           0 :         }
      79             : 
      80             :         /// returns the index of the current state in given path, or -1
      81             :         sal_Int32 getStateIndexInPath( WizardTypes::WizardState _nState, const WizardPath& _rPath );
      82             :         /// returns the index of the current state in the path with the given id, or -1
      83             :         sal_Int32 getStateIndexInPath( WizardTypes::WizardState _nState, PathId _nPathId );
      84             :         /// returns the index of the first state in which the two given paths differ
      85             :         sal_Int32 getFirstDifferentIndex( const WizardPath& _rLHS, const WizardPath& _rRHS );
      86             :     };
      87             : 
      88             : 
      89           0 :     sal_Int32 RoadmapWizardImpl::getStateIndexInPath( WizardTypes::WizardState _nState, const WizardPath& _rPath )
      90             :     {
      91           0 :         sal_Int32 nStateIndexInPath = 0;
      92           0 :         WizardPath::const_iterator aPathLoop = _rPath.begin();
      93           0 :         for ( ; aPathLoop != _rPath.end(); ++aPathLoop, ++nStateIndexInPath )
      94           0 :             if ( *aPathLoop == _nState )
      95           0 :                 break;
      96           0 :         if ( aPathLoop == _rPath.end() )
      97           0 :             nStateIndexInPath = -1;
      98           0 :         return nStateIndexInPath;
      99             :     }
     100             : 
     101             : 
     102           0 :     sal_Int32 RoadmapWizardImpl::getStateIndexInPath( WizardTypes::WizardState _nState, PathId _nPathId )
     103             :     {
     104           0 :         sal_Int32 nStateIndexInPath = -1;
     105           0 :         Paths::const_iterator aPathPos = aPaths.find( _nPathId );
     106           0 :         if ( aPathPos != aPaths.end( ) )
     107           0 :             nStateIndexInPath = getStateIndexInPath( _nState, aPathPos->second );
     108           0 :         return nStateIndexInPath;
     109             :     }
     110             : 
     111             : 
     112           0 :     sal_Int32 RoadmapWizardImpl::getFirstDifferentIndex( const WizardPath& _rLHS, const WizardPath& _rRHS )
     113             :     {
     114           0 :         sal_Int32 nMinLength = ::std::min( _rLHS.size(), _rRHS.size() );
     115           0 :         for ( sal_Int32 nCheck = 0; nCheck < nMinLength; ++nCheck )
     116             :         {
     117           0 :             if ( _rLHS[ nCheck ] != _rRHS[ nCheck ] )
     118           0 :                 return nCheck;
     119             :         }
     120           0 :         return nMinLength;
     121             :     }
     122             : 
     123             : 
     124             :     //= RoadmapWizard
     125             : 
     126             : 
     127             : #ifdef DBG_UTIL
     128             :     const char* CheckInvariants( const void* pVoid )
     129             :     {
     130             :         return static_cast< const RoadmapWizard* >( pVoid )->checkInvariants();
     131             :     }
     132             : 
     133             : 
     134             :     const sal_Char* RoadmapWizard::checkInvariants() const
     135             :     {
     136             :         // all paths have to start with the same state
     137             :         WizardState nSharedFirstState = WZS_INVALID_STATE;
     138             :         for ( Paths::const_iterator aPath = m_pImpl->aPaths.begin();
     139             :               aPath != m_pImpl->aPaths.end();
     140             :               ++aPath
     141             :             )
     142             :         {
     143             :             if ( aPath->second.empty() )
     144             :                 return "RoadmapWizard::checkInvariants: paths should not be empty!";
     145             : 
     146             :             if ( nSharedFirstState == WZS_INVALID_STATE )
     147             :                 // first path
     148             :                 nSharedFirstState = aPath->second[ 0 ];
     149             :             else
     150             :                 if ( nSharedFirstState != aPath->second[ 0 ] )
     151             :                     return "RoadmapWizard::checkInvariants: alls paths must start with the same state!";
     152             :         }
     153             : 
     154             :         if ( !m_pImpl->aPaths.empty() )
     155             :         {
     156             :             Paths::const_iterator aCurrentPathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath );
     157             :             if ( aCurrentPathPos == m_pImpl->aPaths.end() )
     158             :                 return "RoadmapWizard::checkInvariants: invalid active path!";
     159             : 
     160             :             if ( -1 == m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath ) )
     161             :                 return "RoadmapWizard::checkInvariants: the current state is not part of the current path!";
     162             :         }
     163             : 
     164             :         return NULL;
     165             :     }
     166             : #endif
     167             : 
     168             : 
     169           0 :     RoadmapWizard::RoadmapWizard( Window* _pParent, const ResId& _rRes, sal_uInt32 _nButtonFlags )
     170             :         :OWizardMachine( _pParent, _rRes, _nButtonFlags )
     171           0 :         ,m_pImpl( new RoadmapWizardImpl )
     172             :     {
     173           0 :         impl_construct();
     174           0 :     }
     175             : 
     176             : 
     177           0 :     RoadmapWizard::RoadmapWizard( Window* _pParent, const WinBits i_nStyle, sal_uInt32 _nButtonFlags )
     178             :         :OWizardMachine( _pParent, i_nStyle, _nButtonFlags )
     179           0 :         ,m_pImpl( new RoadmapWizardImpl )
     180             :     {
     181           0 :         impl_construct();
     182           0 :     }
     183             : 
     184             : 
     185           0 :     void RoadmapWizard::impl_construct()
     186             :     {
     187           0 :         SetLeftAlignedButtonCount( 1 );
     188           0 :         SetEmptyViewMargin();
     189             : 
     190           0 :         m_pImpl->pRoadmap = new ORoadmap( this, WB_TABSTOP );
     191           0 :         m_pImpl->pRoadmap->SetText( SVT_RESSTR( STR_WIZDLG_ROADMAP_TITLE ) );
     192           0 :         m_pImpl->pRoadmap->SetPosPixel( Point( 0, 0 ) );
     193           0 :         m_pImpl->pRoadmap->SetItemSelectHdl( LINK( this, RoadmapWizard, OnRoadmapItemSelected ) );
     194             : 
     195           0 :         Size aRoadmapSize =( LogicToPixel( Size( 85, 0 ), MAP_APPFONT ) );
     196           0 :         aRoadmapSize.Height() = GetSizePixel().Height();
     197           0 :         m_pImpl->pRoadmap->SetSizePixel( aRoadmapSize );
     198             : 
     199           0 :         m_pImpl->pFixedLine = new FixedLine( this, WB_VERT );
     200           0 :         m_pImpl->pFixedLine->Show();
     201           0 :         m_pImpl->pFixedLine->SetPosPixel( Point( aRoadmapSize.Width() + 1, 0 ) );
     202           0 :         m_pImpl->pFixedLine->SetSizePixel( Size( LogicToPixel( Size( 2, 0 ) ).Width(), aRoadmapSize.Height() ) );
     203             : 
     204           0 :         SetViewWindow( m_pImpl->pRoadmap );
     205           0 :         SetViewAlign( WINDOWALIGN_LEFT );
     206           0 :         m_pImpl->pRoadmap->Show();
     207           0 :     }
     208             : 
     209             : 
     210           0 :     RoadmapWizard::~RoadmapWizard()
     211             :     {
     212           0 :         delete m_pImpl;
     213           0 :     }
     214             : 
     215             : 
     216           0 :     void RoadmapWizard::SetRoadmapHelpId( const OString& _rId )
     217             :     {
     218           0 :         m_pImpl->pRoadmap->SetHelpId( _rId );
     219           0 :     }
     220             : 
     221             : 
     222           0 :     void RoadmapWizard::SetRoadmapInteractive( bool _bInteractive )
     223             :     {
     224           0 :         m_pImpl->pRoadmap->SetRoadmapInteractive( _bInteractive );
     225           0 :     }
     226             : 
     227             : 
     228           0 :     void RoadmapWizard::declarePath( PathId _nPathId, const WizardPath& _lWizardStates)
     229             :     {
     230             : 
     231           0 :         m_pImpl->aPaths.insert( Paths::value_type( _nPathId, _lWizardStates ) );
     232             : 
     233           0 :         if ( m_pImpl->aPaths.size() == 1 )
     234             :             // the very first path -> activate it
     235           0 :             activatePath( _nPathId, false );
     236             :         else
     237           0 :             implUpdateRoadmap( );
     238           0 :     }
     239             : 
     240             : 
     241           0 :     void RoadmapWizard::declarePath( PathId _nPathId, WizardState _nFirstState, ... )
     242             :     {
     243             : 
     244             :         DBG_ASSERT( _nFirstState != WZS_INVALID_STATE, "RoadmapWizard::declarePath: there should be at least one state in the path!" );
     245           0 :         if ( _nFirstState == WZS_INVALID_STATE )
     246           0 :             return;
     247             : 
     248           0 :         WizardPath aNewPath;
     249             : 
     250             :         // collect the elements of the path
     251             :         va_list aStateList;
     252           0 :         va_start( aStateList, _nFirstState );
     253             : 
     254           0 :         WizardState nState = _nFirstState;
     255           0 :         while ( nState != WZS_INVALID_STATE )
     256             :         {
     257           0 :             aNewPath.push_back( nState );
     258             :             nState = sal::static_int_cast< WizardState >(
     259           0 :                 va_arg( aStateList, int ));
     260             :         }
     261           0 :         va_end( aStateList );
     262             : 
     263             :         DBG_ASSERT( _nFirstState == 0, "RoadmapWizard::declarePath: first state must be NULL." );
     264             :             // The WizardDialog (our very base class) always starts with a mnCurLevel == 0
     265             : 
     266           0 :         declarePath( _nPathId, aNewPath );
     267             :     }
     268             : 
     269             : 
     270           0 :     void RoadmapWizard::describeState( WizardState _nState, const OUString& _rStateDisplayName, RoadmapPageFactory _pPageFactory )
     271             :     {
     272             :         OSL_ENSURE( m_pImpl->aStateDescriptors.find( _nState ) == m_pImpl->aStateDescriptors.end(),
     273             :             "RoadmapWizard::describeState: there already is a descriptor for this state!" );
     274           0 :         m_pImpl->aStateDescriptors[ _nState ] = StateDescriptions::mapped_type( _rStateDisplayName, _pPageFactory );
     275           0 :     }
     276             : 
     277             : 
     278           0 :     void RoadmapWizard::activatePath( PathId _nPathId, bool _bDecideForIt )
     279             :     {
     280             : 
     281           0 :         if ( ( _nPathId == m_pImpl->nActivePath ) && ( _bDecideForIt == m_pImpl->bActivePathIsDefinite ) )
     282             :             // nothing to do
     283           0 :             return;
     284             : 
     285             :         // does the given path exist?
     286           0 :         Paths::const_iterator aNewPathPos = m_pImpl->aPaths.find( _nPathId );
     287             :         DBG_ASSERT( aNewPathPos != m_pImpl->aPaths.end(), "RoadmapWizard::activate: there is no such path!" );
     288           0 :         if ( aNewPathPos == m_pImpl->aPaths.end() )
     289           0 :             return;
     290             : 
     291             :         // determine the index of the current state in the current path
     292           0 :         sal_Int32 nCurrentStatePathIndex = -1;
     293           0 :         if ( m_pImpl->nActivePath != -1 )
     294           0 :             nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath );
     295             : 
     296             :         DBG_ASSERT( (sal_Int32)aNewPathPos->second.size() > nCurrentStatePathIndex,
     297             :             "RoadmapWizard::activate: you cannot activate a path which has less states than we've already advanced!" );
     298             :             // If this asserts, this for instance means that we are already in state number, say, 5
     299             :             // of our current path, and the caller tries to activate a path which has less than 5
     300             :             // states
     301           0 :         if ( (sal_Int32)aNewPathPos->second.size() <= nCurrentStatePathIndex )
     302           0 :             return;
     303             : 
     304             :         // assert that the current and the new path are equal, up to nCurrentStatePathIndex
     305           0 :         Paths::const_iterator aActivePathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath );
     306           0 :         if ( aActivePathPos != m_pImpl->aPaths.end() )
     307             :         {
     308           0 :             if ( m_pImpl->getFirstDifferentIndex( aActivePathPos->second, aNewPathPos->second ) <= nCurrentStatePathIndex )
     309             :             {
     310             :                 OSL_FAIL( "RoadmapWizard::activate: you cannot activate a path which conflicts with the current one *before* the current state!" );
     311           0 :                 return;
     312             :             }
     313             :         }
     314             : 
     315           0 :         m_pImpl->nActivePath = _nPathId;
     316           0 :         m_pImpl->bActivePathIsDefinite = _bDecideForIt;
     317             : 
     318           0 :         implUpdateRoadmap( );
     319             :     }
     320             : 
     321             : 
     322           0 :     void RoadmapWizard::implUpdateRoadmap( )
     323             :     {
     324             : 
     325             :         DBG_ASSERT( m_pImpl->aPaths.find( m_pImpl->nActivePath ) != m_pImpl->aPaths.end(),
     326             :             "RoadmapWizard::implUpdateRoadmap: there is no such path!" );
     327           0 :         const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] );
     328             : 
     329           0 :         sal_Int32 nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( getCurrentState(), rActivePath );
     330             : 
     331             :         // determine up to which index (in the new path) we have to display the items
     332           0 :         RoadmapTypes::ItemIndex nUpperStepBoundary = (RoadmapTypes::ItemIndex)rActivePath.size();
     333           0 :         sal_Bool bIncompletePath = sal_False;
     334           0 :         if ( !m_pImpl->bActivePathIsDefinite )
     335             :         {
     336           0 :             for ( Paths::const_iterator aPathPos = m_pImpl->aPaths.begin();
     337           0 :                   aPathPos != m_pImpl->aPaths.end();
     338             :                   ++aPathPos
     339             :                 )
     340             :             {
     341           0 :                 if ( aPathPos->first == m_pImpl->nActivePath )
     342             :                     // it's the path we are just activating -> no need to check anything
     343           0 :                     continue;
     344             :                 // the index from which on both paths differ
     345           0 :                 sal_Int32 nDivergenceIndex = m_pImpl->getFirstDifferentIndex( rActivePath, aPathPos->second );
     346           0 :                 if ( nDivergenceIndex <= nCurrentStatePathIndex )
     347             :                     // they differ in an index which we have already left behind us
     348             :                     // -> this is no conflict anymore
     349           0 :                     continue;
     350             : 
     351             :                 // the path conflicts with our new path -> don't activate the
     352             :                 // *complete* new path, but only up to the step which is unambiguous
     353           0 :                 nUpperStepBoundary = nDivergenceIndex;
     354           0 :                 bIncompletePath = sal_True;
     355             :             }
     356             :         }
     357             : 
     358             :         // can we advance from the current page?
     359           0 :         bool bCurrentPageCanAdvance = true;
     360           0 :         TabPage* pCurrentPage = GetPage( getCurrentState() );
     361           0 :         if ( pCurrentPage )
     362             :         {
     363           0 :             const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
     364             :             OSL_ENSURE( pController != NULL, "RoadmapWizard::implUpdateRoadmap: no controller for the current page!" );
     365           0 :             bCurrentPageCanAdvance = !pController || pController->canAdvance();
     366             :         }
     367             : 
     368             :         // now, we have to remove all items after nCurrentStatePathIndex, and insert the items from the active
     369             :         // path, up to (excluding) nUpperStepBoundary
     370           0 :         RoadmapTypes::ItemIndex nLoopUntil = ::std::max( (RoadmapTypes::ItemIndex)nUpperStepBoundary, m_pImpl->pRoadmap->GetItemCount() );
     371           0 :         for ( RoadmapTypes::ItemIndex nItemIndex = nCurrentStatePathIndex; nItemIndex < nLoopUntil; ++nItemIndex )
     372             :         {
     373           0 :             bool bExistentItem = ( nItemIndex < m_pImpl->pRoadmap->GetItemCount() );
     374           0 :             bool bNeedItem = ( nItemIndex < nUpperStepBoundary );
     375             : 
     376           0 :             bool bInsertItem = false;
     377           0 :             if ( bExistentItem )
     378             :             {
     379           0 :                 if ( !bNeedItem )
     380             :                 {
     381           0 :                     while ( nItemIndex < m_pImpl->pRoadmap->GetItemCount() )
     382           0 :                         m_pImpl->pRoadmap->DeleteRoadmapItem( nItemIndex );
     383           0 :                     break;
     384             :                 }
     385             :                 else
     386             :                 {
     387             :                     // there is an item with this index in the roadmap - does it match what is requested by
     388             :                     // the respective state in the active path?
     389           0 :                     RoadmapTypes::ItemId nPresentItemId = m_pImpl->pRoadmap->GetItemID( nItemIndex );
     390           0 :                     WizardState nRequiredState = rActivePath[ nItemIndex ];
     391           0 :                     if ( nPresentItemId != nRequiredState )
     392             :                     {
     393           0 :                         m_pImpl->pRoadmap->DeleteRoadmapItem( nItemIndex );
     394           0 :                         bInsertItem = true;
     395             :                     }
     396             :                 }
     397             :             }
     398             :             else
     399             :             {
     400             :                 DBG_ASSERT( bNeedItem, "RoadmapWizard::implUpdateRoadmap: ehm - none needed, none present - why did the loop not terminate?" );
     401           0 :                 bInsertItem = bNeedItem;
     402             :             }
     403             : 
     404           0 :             WizardState nState( rActivePath[ nItemIndex ] );
     405           0 :             if ( bInsertItem )
     406             :             {
     407             :                 m_pImpl->pRoadmap->InsertRoadmapItem(
     408             :                     nItemIndex,
     409           0 :                     getStateDisplayName( nState ),
     410             :                     nState
     411           0 :                 );
     412             :             }
     413             : 
     414             :             // if the item is *after* the current state, but the current page does not
     415             :             // allow advancing, the disable the state. This relieves derived classes
     416             :             // from disabling all future states just because the current state does not
     417             :             // (yet) allow advancing.
     418           0 :             const bool nUnconditionedDisable = !bCurrentPageCanAdvance && ( nItemIndex > nCurrentStatePathIndex );
     419           0 :             const bool bEnable = !nUnconditionedDisable && ( m_pImpl->aDisabledStates.find( nState ) == m_pImpl->aDisabledStates.end() );
     420             : 
     421           0 :             m_pImpl->pRoadmap->EnableRoadmapItem( m_pImpl->pRoadmap->GetItemID( nItemIndex ), bEnable );
     422             :         }
     423             : 
     424           0 :         m_pImpl->pRoadmap->SetRoadmapComplete( !bIncompletePath );
     425           0 :     }
     426             : 
     427             : 
     428           0 :     WizardTypes::WizardState RoadmapWizard::determineNextState( WizardState _nCurrentState ) const
     429             :     {
     430             : 
     431           0 :         sal_Int32 nCurrentStatePathIndex = -1;
     432             : 
     433           0 :         Paths::const_iterator aActivePathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath );
     434           0 :         if ( aActivePathPos != m_pImpl->aPaths.end() )
     435           0 :             nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( _nCurrentState, aActivePathPos->second );
     436             : 
     437             :         DBG_ASSERT( nCurrentStatePathIndex != -1, "RoadmapWizard::determineNextState: ehm - how can we travel if there is no (valid) active path?" );
     438           0 :         if ( nCurrentStatePathIndex == -1 )
     439           0 :             return WZS_INVALID_STATE;
     440             : 
     441           0 :         sal_Int32 nNextStateIndex = nCurrentStatePathIndex + 1;
     442             : 
     443           0 :         while   (   ( nNextStateIndex < (sal_Int32)aActivePathPos->second.size() )
     444           0 :                 &&  ( m_pImpl->aDisabledStates.find( aActivePathPos->second[ nNextStateIndex ] ) != m_pImpl->aDisabledStates.end() )
     445             :                 )
     446             :         {
     447           0 :             ++nNextStateIndex;
     448             :         }
     449             : 
     450           0 :         if ( nNextStateIndex >= (sal_Int32)aActivePathPos->second.size() )
     451             :             // there is no next state in the current path (at least none which is enabled)
     452           0 :             return WZS_INVALID_STATE;
     453             : 
     454           0 :         return aActivePathPos->second[ nNextStateIndex ];
     455             :     }
     456             : 
     457             : 
     458           0 :     bool RoadmapWizard::canAdvance() const
     459             :     {
     460           0 :         if ( !m_pImpl->bActivePathIsDefinite )
     461             :         {
     462             :             // check how many paths are still allowed
     463           0 :             const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] );
     464           0 :             sal_Int32 nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( getCurrentState(), rActivePath );
     465             : 
     466           0 :             size_t nPossiblePaths(0);
     467           0 :             for (   Paths::const_iterator aPathPos = m_pImpl->aPaths.begin();
     468           0 :                     aPathPos != m_pImpl->aPaths.end();
     469             :                     ++aPathPos
     470             :                 )
     471             :             {
     472             :                 // the index from which on both paths differ
     473           0 :                 sal_Int32 nDivergenceIndex = m_pImpl->getFirstDifferentIndex( rActivePath, aPathPos->second );
     474             : 
     475           0 :                 if ( nDivergenceIndex > nCurrentStatePathIndex )
     476             :                     // this path is still a possible path
     477           0 :                     nPossiblePaths += 1;
     478             :             }
     479             : 
     480             :             // if we have more than one path which is still possible, then we assume
     481             :             // to always have a next state. Though there might be scenarios where this
     482             :             // is not true, but this is too sophisticated (means not really needed) right now.
     483           0 :             if ( nPossiblePaths > 1 )
     484           0 :                 return true;
     485             :         }
     486             : 
     487           0 :         const WizardPath& rPath = m_pImpl->aPaths[ m_pImpl->nActivePath ];
     488           0 :         if ( *rPath.rbegin() == getCurrentState() )
     489           0 :             return false;
     490             : 
     491           0 :         return true;
     492             :     }
     493             : 
     494             : 
     495           0 :     void RoadmapWizard::updateTravelUI()
     496             :     {
     497           0 :         OWizardMachine::updateTravelUI();
     498             : 
     499             :         // disable the "Previous" button if all states in our history are disabled
     500           0 :         ::std::vector< WizardState > aHistory;
     501           0 :         getStateHistory( aHistory );
     502           0 :         bool bHaveEnabledState = false;
     503           0 :         for (   ::std::vector< WizardState >::const_iterator state = aHistory.begin();
     504           0 :                 state != aHistory.end() && !bHaveEnabledState;
     505             :                 ++state
     506             :             )
     507             :         {
     508           0 :             if ( isStateEnabled( *state ) )
     509           0 :                 bHaveEnabledState = true;
     510             :         }
     511             : 
     512           0 :         enableButtons( WZB_PREVIOUS, bHaveEnabledState );
     513             : 
     514           0 :         implUpdateRoadmap();
     515           0 :     }
     516             : 
     517             : 
     518           0 :     IMPL_LINK_NOARG(RoadmapWizard, OnRoadmapItemSelected)
     519             :     {
     520             : 
     521           0 :         RoadmapTypes::ItemId nCurItemId = m_pImpl->pRoadmap->GetCurrentRoadmapItemID();
     522           0 :         if ( nCurItemId == getCurrentState() )
     523             :             // nothing to do
     524           0 :             return 1L;
     525             : 
     526           0 :         if ( isTravelingSuspended() )
     527           0 :             return 0;
     528             : 
     529           0 :         WizardTravelSuspension aTravelGuard( *this );
     530             : 
     531           0 :         sal_Int32 nCurrentIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath );
     532           0 :         sal_Int32 nNewIndex     = m_pImpl->getStateIndexInPath( nCurItemId, m_pImpl->nActivePath );
     533             : 
     534             :         DBG_ASSERT( ( nCurrentIndex != -1 ) && ( nNewIndex != -1 ),
     535             :             "RoadmapWizard::OnRoadmapItemSelected: something's wrong here!" );
     536           0 :         if ( ( nCurrentIndex == -1 ) || ( nNewIndex == -1 ) )
     537             :         {
     538           0 :             return 0L;
     539             :         }
     540             : 
     541           0 :         sal_Bool bResult = sal_True;
     542           0 :         if ( nNewIndex > nCurrentIndex )
     543             :         {
     544           0 :             bResult = skipUntil( (WizardState)nCurItemId );
     545           0 :             WizardState nTemp = (WizardState)nCurItemId;
     546           0 :             while( nTemp )
     547             :             {
     548           0 :                 if( m_pImpl->aDisabledStates.find( --nTemp ) != m_pImpl->aDisabledStates.end() )
     549           0 :                     removePageFromHistory( nTemp );
     550             :             }
     551             :         }
     552             :         else
     553           0 :             bResult = skipBackwardUntil( (WizardState)nCurItemId );
     554             : 
     555           0 :         if ( !bResult )
     556           0 :             m_pImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() );
     557             : 
     558           0 :         return 1L;
     559             :     }
     560             : 
     561             : 
     562           0 :     void RoadmapWizard::enterState( WizardState _nState )
     563             :     {
     564             : 
     565           0 :         OWizardMachine::enterState( _nState );
     566             : 
     567             :         // synchronize the roadmap
     568           0 :         implUpdateRoadmap( );
     569           0 :         m_pImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() );
     570           0 :     }
     571             : 
     572             : 
     573           0 :     OUString RoadmapWizard::getStateDisplayName( WizardState _nState ) const
     574             :     {
     575           0 :         OUString sDisplayName;
     576             : 
     577           0 :         StateDescriptions::const_iterator pos = m_pImpl->aStateDescriptors.find( _nState );
     578             :         OSL_ENSURE( pos != m_pImpl->aStateDescriptors.end(),
     579             :             "RoadmapWizard::getStateDisplayName: no default implementation available for this state!" );
     580           0 :         if ( pos != m_pImpl->aStateDescriptors.end() )
     581           0 :             sDisplayName = pos->second.first;
     582             : 
     583           0 :         return sDisplayName;
     584             :     }
     585             : 
     586             : 
     587           0 :     TabPage* RoadmapWizard::createPage( WizardState _nState )
     588             :     {
     589           0 :         TabPage* pPage( NULL );
     590             : 
     591           0 :         StateDescriptions::const_iterator pos = m_pImpl->aStateDescriptors.find( _nState );
     592             :         OSL_ENSURE( pos != m_pImpl->aStateDescriptors.end(),
     593             :             "RoadmapWizard::createPage: no default implementation available for this state!" );
     594           0 :         if ( pos != m_pImpl->aStateDescriptors.end() )
     595             :         {
     596           0 :             RoadmapPageFactory pFactory = pos->second.second;
     597           0 :             pPage = (*pFactory)( *this );
     598             :         }
     599             : 
     600           0 :         return pPage;
     601             :     }
     602             : 
     603             : 
     604           0 :     void RoadmapWizard::enableState( WizardState _nState, bool _bEnable )
     605             :     {
     606             : 
     607             :         // remember this (in case the state appears in the roadmap later on)
     608           0 :         if ( _bEnable )
     609           0 :             m_pImpl->aDisabledStates.erase( _nState );
     610             :         else
     611             :         {
     612           0 :             m_pImpl->aDisabledStates.insert( _nState );
     613           0 :             removePageFromHistory( _nState );
     614             :         }
     615             : 
     616             :         // if the state is currently in the roadmap, reflect it's new status
     617           0 :         m_pImpl->pRoadmap->EnableRoadmapItem( (RoadmapTypes::ItemId)_nState, _bEnable );
     618           0 :     }
     619             : 
     620             : 
     621           0 :     bool RoadmapWizard::knowsState( WizardState i_nState ) const
     622             :     {
     623           0 :         for (   Paths::const_iterator path = m_pImpl->aPaths.begin();
     624           0 :                 path != m_pImpl->aPaths.end();
     625             :                 ++path
     626             :             )
     627             :         {
     628           0 :             for (   WizardPath::const_iterator state = path->second.begin();
     629           0 :                     state != path->second.end();
     630             :                     ++state
     631             :                 )
     632             :             {
     633           0 :                 if ( *state == i_nState )
     634           0 :                     return true;
     635             :             }
     636             :         }
     637           0 :         return false;
     638             :     }
     639             : 
     640             : 
     641           0 :     bool RoadmapWizard::isStateEnabled( WizardState _nState ) const
     642             :     {
     643           0 :         return m_pImpl->aDisabledStates.find( _nState ) == m_pImpl->aDisabledStates.end();
     644             :     }
     645             : 
     646             : 
     647           0 :     void RoadmapWizard::Resize()
     648             :     {
     649           0 :         OWizardMachine::Resize();
     650             : 
     651           0 :         if ( IsReallyShown() && !IsInInitShow() )
     652           0 :             ResizeFixedLine();
     653           0 :     }
     654             : 
     655             : 
     656             : 
     657           0 :     void RoadmapWizard::StateChanged( StateChangedType nType )
     658             :     {
     659           0 :         WizardDialog::StateChanged( nType );
     660             : 
     661           0 :         if ( nType == STATE_CHANGE_INITSHOW )
     662           0 :             ResizeFixedLine();
     663           0 :     }
     664             : 
     665             : 
     666           0 :     void RoadmapWizard::ResizeFixedLine()
     667             :     {
     668           0 :         Size aSize( m_pImpl->pRoadmap->GetSizePixel() );
     669           0 :         aSize.Width() = m_pImpl->pFixedLine->GetSizePixel().Width();
     670           0 :         m_pImpl->pFixedLine->SetSizePixel( aSize );
     671           0 :     }
     672             : 
     673             : 
     674           0 :     void RoadmapWizard::updateRoadmapItemLabel( WizardState _nState )
     675             :     {
     676           0 :         const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] );
     677           0 :         RoadmapTypes::ItemIndex nUpperStepBoundary = (RoadmapTypes::ItemIndex)rActivePath.size();
     678           0 :         RoadmapTypes::ItemIndex nLoopUntil = ::std::max( (RoadmapTypes::ItemIndex)nUpperStepBoundary, m_pImpl->pRoadmap->GetItemCount() );
     679           0 :         sal_Int32 nCurrentStatePathIndex = -1;
     680           0 :         if ( m_pImpl->nActivePath != -1 )
     681           0 :             nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath );
     682           0 :         for ( RoadmapTypes::ItemIndex nItemIndex = nCurrentStatePathIndex; nItemIndex < nLoopUntil; ++nItemIndex )
     683             :         {
     684           0 :             bool bExistentItem = ( nItemIndex < m_pImpl->pRoadmap->GetItemCount() );
     685           0 :             if ( bExistentItem )
     686             :             {
     687             :                 // there is an item with this index in the roadmap - does it match what is requested by
     688             :                 // the respective state in the active path?
     689           0 :                 RoadmapTypes::ItemId nPresentItemId = m_pImpl->pRoadmap->GetItemID( nItemIndex );
     690           0 :                 WizardState nRequiredState = rActivePath[ nItemIndex ];
     691           0 :                 if ( _nState == nRequiredState )
     692             :                 {
     693           0 :                     m_pImpl->pRoadmap->ChangeRoadmapItemLabel( nPresentItemId, getStateDisplayName( nRequiredState ) );
     694           0 :                     break;
     695             :                 }
     696             :             }
     697             :         }
     698           0 :     }
     699             : 
     700             : 
     701             : }   // namespace svt
     702             : 
     703             : 
     704             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10