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