1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir  *
4*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir  *
8*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir  *
10*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir  *
25*cdf0e10cSrcweir  ************************************************************************/
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "wizardshell.hxx"
30*cdf0e10cSrcweir #include "wizardpagecontroller.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir /** === begin UNO includes === **/
35*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
36*cdf0e10cSrcweir /** === end UNO includes === **/
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //......................................................................................................................
41*cdf0e10cSrcweir namespace svt { namespace uno
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir //......................................................................................................................
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 	/** === begin UNO using === **/
46*cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
47*cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
48*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
49*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
50*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
51*cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
52*cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
53*cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
54*cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
55*cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
56*cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
57*cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizardController;
58*cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizard;
59*cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizardPage;
60*cdf0e10cSrcweir 	/** === end UNO using === **/
61*cdf0e10cSrcweir     namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	//==================================================================================================================
64*cdf0e10cSrcweir     namespace
65*cdf0e10cSrcweir     {
66*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
67*cdf0e10cSrcweir         sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
68*cdf0e10cSrcweir         {
69*cdf0e10cSrcweir             ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" );
70*cdf0e10cSrcweir             return i_rPaths[0][0];
71*cdf0e10cSrcweir         }
72*cdf0e10cSrcweir     }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	//==================================================================================================================
75*cdf0e10cSrcweir 	//= WizardShell
76*cdf0e10cSrcweir 	//==================================================================================================================
77*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
78*cdf0e10cSrcweir     WizardShell::WizardShell( Window* i_pParent, const Reference< XWizard >& i_rWizard, const Reference< XWizardController >& i_rController,
79*cdf0e10cSrcweir             const Sequence< Sequence< sal_Int16 > >& i_rPaths )
80*cdf0e10cSrcweir         :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
81*cdf0e10cSrcweir         ,m_xWizard( i_rWizard )
82*cdf0e10cSrcweir         ,m_xController( i_rController )
83*cdf0e10cSrcweir         ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
84*cdf0e10cSrcweir     {
85*cdf0e10cSrcweir         ENSURE_OR_THROW( m_xWizard.is() && m_xController.is(), "invalid wizard/controller" );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         // declare the paths
88*cdf0e10cSrcweir         for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
89*cdf0e10cSrcweir         {
90*cdf0e10cSrcweir             const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
91*cdf0e10cSrcweir             WizardPath aPath( rPath.getLength() );
92*cdf0e10cSrcweir             for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
93*cdf0e10cSrcweir                 aPath[j] = impl_pageIdToState( rPath[j] );
94*cdf0e10cSrcweir             declarePath( i, aPath );
95*cdf0e10cSrcweir         }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         // create the first page, to know the page size
98*cdf0e10cSrcweir         TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
99*cdf0e10cSrcweir         SetPageSizePixel( pStartPage->GetSizePixel() );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir         // some defaults
102*cdf0e10cSrcweir         ShowButtonFixedLine( true );
103*cdf0e10cSrcweir         SetRoadmapInteractive( true );
104*cdf0e10cSrcweir         enableAutomaticNextButtonState();
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
108*cdf0e10cSrcweir     WizardShell::~WizardShell()
109*cdf0e10cSrcweir     {
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
113*cdf0e10cSrcweir     short WizardShell::Execute()
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         ActivatePage();
116*cdf0e10cSrcweir         return WizardShell_Base::Execute();
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
120*cdf0e10cSrcweir     sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         switch ( i_eReason )
123*cdf0e10cSrcweir         {
124*cdf0e10cSrcweir         case WizardTypes::eTravelForward:
125*cdf0e10cSrcweir             return WizardTravelType::FORWARD;
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir         case WizardTypes::eTravelBackward:
128*cdf0e10cSrcweir             return WizardTravelType::BACKWARD;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         case WizardTypes::eFinish:
131*cdf0e10cSrcweir             return WizardTravelType::FINISH;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         default:
134*cdf0e10cSrcweir             break;
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir         OSL_ENSURE( false, "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
137*cdf0e10cSrcweir         return WizardTravelType::FINISH;
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
141*cdf0e10cSrcweir 	void WizardShell::enterState( WizardState i_nState )
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         WizardShell_Base::enterState( i_nState );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         if ( !m_xController.is() )
146*cdf0e10cSrcweir             return;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         try
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir         catch( const Exception& )
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
155*cdf0e10cSrcweir         }
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
159*cdf0e10cSrcweir     sal_Bool WizardShell::leaveState( WizardState i_nState )
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         if ( !WizardShell_Base::leaveState( i_nState ) )
162*cdf0e10cSrcweir             return sal_False;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         if ( !m_xController.is() )
165*cdf0e10cSrcweir             return sal_True;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         try
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir         catch( const Exception& )
172*cdf0e10cSrcweir         {
173*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         return sal_True;
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
180*cdf0e10cSrcweir     PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
181*cdf0e10cSrcweir     {
182*cdf0e10cSrcweir         Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
183*cdf0e10cSrcweir         ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
184*cdf0e10cSrcweir         return pos->second;
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
188*cdf0e10cSrcweir     Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         const WizardState eState = getCurrentState();
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir         PWizardPageController pController( impl_getController( GetPage( eState ) ) );
193*cdf0e10cSrcweir         ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir         return pController->getWizardPage();
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
199*cdf0e10cSrcweir     void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable )
200*cdf0e10cSrcweir     {
201*cdf0e10cSrcweir         enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
205*cdf0e10cSrcweir 	TabPage* WizardShell::createPage( WizardState i_nState )
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
210*cdf0e10cSrcweir         TabPage* pPage = pController->getTabPage();
211*cdf0e10cSrcweir         OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
212*cdf0e10cSrcweir         if ( pPage == NULL )
213*cdf0e10cSrcweir         {
214*cdf0e10cSrcweir             // fallback for ill-behaved clients: empty page
215*cdf0e10cSrcweir             pPage = new TabPage( this, 0 );
216*cdf0e10cSrcweir             pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir         m_aPageControllers[ pPage ] = pController;
220*cdf0e10cSrcweir         return pPage;
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
224*cdf0e10cSrcweir 	IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         return impl_getController( i_pCurrentPage ).get();
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
230*cdf0e10cSrcweir     String WizardShell::getStateDisplayName( WizardState i_nState ) const
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         try
233*cdf0e10cSrcweir         {
234*cdf0e10cSrcweir             if ( m_xController.is() )
235*cdf0e10cSrcweir                 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir         catch( const Exception& )
238*cdf0e10cSrcweir         {
239*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
240*cdf0e10cSrcweir         }
241*cdf0e10cSrcweir         // fallback for ill-behaved clients: the numeric state
242*cdf0e10cSrcweir         return String::CreateFromInt32( i_nState );
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
246*cdf0e10cSrcweir     bool WizardShell::canAdvance() const
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         try
249*cdf0e10cSrcweir         {
250*cdf0e10cSrcweir             if ( m_xController.is() && !m_xController->canAdvance() )
251*cdf0e10cSrcweir                 return false;
252*cdf0e10cSrcweir         }
253*cdf0e10cSrcweir         catch( const Exception& )
254*cdf0e10cSrcweir         {
255*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
256*cdf0e10cSrcweir         }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir         return WizardShell_Base::canAdvance();
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
262*cdf0e10cSrcweir     sal_Bool WizardShell::onFinish()
263*cdf0e10cSrcweir     {
264*cdf0e10cSrcweir         try
265*cdf0e10cSrcweir         {
266*cdf0e10cSrcweir             if ( m_xController.is() && !m_xController->confirmFinish() )
267*cdf0e10cSrcweir                 return sal_False;
268*cdf0e10cSrcweir         }
269*cdf0e10cSrcweir         catch( const Exception& )
270*cdf0e10cSrcweir         {
271*cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
272*cdf0e10cSrcweir         }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir         return WizardShell_Base::onFinish();
275*cdf0e10cSrcweir     }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir //......................................................................................................................
278*cdf0e10cSrcweir } } // namespace svt::uno
279*cdf0e10cSrcweir //......................................................................................................................
280