15900e8ecSAndrew Rist /**************************************************************
25900e8ecSAndrew Rist  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
105900e8ecSAndrew Rist  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
195900e8ecSAndrew Rist  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_svtools.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "wizardshell.hxx"
27cdf0e10cSrcweir #include "wizardpagecontroller.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/diagnose_ex.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
33cdf0e10cSrcweir /** === end UNO includes === **/
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //......................................................................................................................
38cdf0e10cSrcweir namespace svt { namespace uno
39cdf0e10cSrcweir {
40cdf0e10cSrcweir //......................................................................................................................
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	/** === begin UNO using === **/
43cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
44cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
45cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
46cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
53cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
54cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizardController;
55cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizard;
56cdf0e10cSrcweir     using ::com::sun::star::ui::dialogs::XWizardPage;
57cdf0e10cSrcweir 	/** === end UNO using === **/
58cdf0e10cSrcweir     namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	//==================================================================================================================
61cdf0e10cSrcweir     namespace
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
lcl_determineFirstPageID(const Sequence<Sequence<sal_Int16>> & i_rPaths)64cdf0e10cSrcweir         sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" );
67cdf0e10cSrcweir             return i_rPaths[0][0];
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	//==================================================================================================================
72cdf0e10cSrcweir 	//= WizardShell
73cdf0e10cSrcweir 	//==================================================================================================================
74cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
WizardShell(Window * i_pParent,const Reference<XWizardController> & i_rController,const Sequence<Sequence<sal_Int16>> & i_rPaths)75*89763fdbSAriel Constenla-Haile     WizardShell::WizardShell( Window* i_pParent, const Reference< XWizardController >& i_rController,
76cdf0e10cSrcweir             const Sequence< Sequence< sal_Int16 > >& i_rPaths )
77cdf0e10cSrcweir         :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
78cdf0e10cSrcweir         ,m_xController( i_rController )
79cdf0e10cSrcweir         ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
80cdf0e10cSrcweir     {
81*89763fdbSAriel Constenla-Haile         ENSURE_OR_THROW( m_xController.is(), "invalid controller" );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // declare the paths
84cdf0e10cSrcweir         for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
85cdf0e10cSrcweir         {
86cdf0e10cSrcweir             const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
87cdf0e10cSrcweir             WizardPath aPath( rPath.getLength() );
88cdf0e10cSrcweir             for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
89cdf0e10cSrcweir                 aPath[j] = impl_pageIdToState( rPath[j] );
90cdf0e10cSrcweir             declarePath( i, aPath );
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         // create the first page, to know the page size
94cdf0e10cSrcweir         TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
95cdf0e10cSrcweir         SetPageSizePixel( pStartPage->GetSizePixel() );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         // some defaults
98cdf0e10cSrcweir         ShowButtonFixedLine( true );
99cdf0e10cSrcweir         SetRoadmapInteractive( true );
100cdf0e10cSrcweir         enableAutomaticNextButtonState();
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~WizardShell()104cdf0e10cSrcweir     WizardShell::~WizardShell()
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
Execute()109cdf0e10cSrcweir     short WizardShell::Execute()
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         ActivatePage();
112cdf0e10cSrcweir         return WizardShell_Base::Execute();
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
convertCommitReasonToTravelType(const CommitPageReason i_eReason)116cdf0e10cSrcweir     sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         switch ( i_eReason )
119cdf0e10cSrcweir         {
120cdf0e10cSrcweir         case WizardTypes::eTravelForward:
121cdf0e10cSrcweir             return WizardTravelType::FORWARD;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         case WizardTypes::eTravelBackward:
124cdf0e10cSrcweir             return WizardTravelType::BACKWARD;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         case WizardTypes::eFinish:
127cdf0e10cSrcweir             return WizardTravelType::FINISH;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         default:
130cdf0e10cSrcweir             break;
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         OSL_ENSURE( false, "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
133cdf0e10cSrcweir         return WizardTravelType::FINISH;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
enterState(WizardState i_nState)137cdf0e10cSrcweir 	void WizardShell::enterState( WizardState i_nState )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         WizardShell_Base::enterState( i_nState );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         if ( !m_xController.is() )
142cdf0e10cSrcweir             return;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         try
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir         catch( const Exception& )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
leaveState(WizardState i_nState)155cdf0e10cSrcweir     sal_Bool WizardShell::leaveState( WizardState i_nState )
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         if ( !WizardShell_Base::leaveState( i_nState ) )
158cdf0e10cSrcweir             return sal_False;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         if ( !m_xController.is() )
161cdf0e10cSrcweir             return sal_True;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         try
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir         catch( const Exception& )
168cdf0e10cSrcweir         {
169cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         return sal_True;
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
impl_getController(TabPage * i_pPage) const176cdf0e10cSrcweir     PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir         Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
179cdf0e10cSrcweir         ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
180cdf0e10cSrcweir         return pos->second;
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getCurrentWizardPage() const184cdf0e10cSrcweir     Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         const WizardState eState = getCurrentState();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         PWizardPageController pController( impl_getController( GetPage( eState ) ) );
189cdf0e10cSrcweir         ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         return pController->getWizardPage();
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
enablePage(const sal_Int16 i_nPageID,const sal_Bool i_bEnable)195cdf0e10cSrcweir     void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable )
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
createPage(WizardState i_nState)201cdf0e10cSrcweir 	TabPage* WizardShell::createPage( WizardState i_nState )
202cdf0e10cSrcweir     {
203cdf0e10cSrcweir         ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
206cdf0e10cSrcweir         TabPage* pPage = pController->getTabPage();
207cdf0e10cSrcweir         OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
208cdf0e10cSrcweir         if ( pPage == NULL )
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             // fallback for ill-behaved clients: empty page
211cdf0e10cSrcweir             pPage = new TabPage( this, 0 );
212cdf0e10cSrcweir             pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
213cdf0e10cSrcweir         }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         m_aPageControllers[ pPage ] = pController;
216cdf0e10cSrcweir         return pPage;
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getPageController(TabPage * i_pCurrentPage) const220cdf0e10cSrcweir 	IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         return impl_getController( i_pCurrentPage ).get();
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getStateDisplayName(WizardState i_nState) const226cdf0e10cSrcweir     String WizardShell::getStateDisplayName( WizardState i_nState ) const
227cdf0e10cSrcweir     {
228cdf0e10cSrcweir         try
229cdf0e10cSrcweir         {
230cdf0e10cSrcweir             if ( m_xController.is() )
231cdf0e10cSrcweir                 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir         catch( const Exception& )
234cdf0e10cSrcweir         {
235cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir         // fallback for ill-behaved clients: the numeric state
238cdf0e10cSrcweir         return String::CreateFromInt32( i_nState );
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
canAdvance() const242cdf0e10cSrcweir     bool WizardShell::canAdvance() const
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         try
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             if ( m_xController.is() && !m_xController->canAdvance() )
247cdf0e10cSrcweir                 return false;
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir         catch( const Exception& )
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         return WizardShell_Base::canAdvance();
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
onFinish()258cdf0e10cSrcweir     sal_Bool WizardShell::onFinish()
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         try
261cdf0e10cSrcweir         {
262cdf0e10cSrcweir             if ( m_xController.is() && !m_xController->confirmFinish() )
263cdf0e10cSrcweir                 return sal_False;
264cdf0e10cSrcweir         }
265cdf0e10cSrcweir         catch( const Exception& )
266cdf0e10cSrcweir         {
267cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         return WizardShell_Base::onFinish();
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //......................................................................................................................
274cdf0e10cSrcweir } } // namespace svt::uno
275cdf0e10cSrcweir //......................................................................................................................
276