1*5900e8ecSAndrew Rist /**************************************************************
2*5900e8ecSAndrew Rist  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew 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<XWizard> & i_rWizard,const Reference<XWizardController> & i_rController,const Sequence<Sequence<sal_Int16>> & i_rPaths)75cdf0e10cSrcweir     WizardShell::WizardShell( Window* i_pParent, const Reference< XWizard >& i_rWizard, const Reference< XWizardController >& i_rController,
76cdf0e10cSrcweir             const Sequence< Sequence< sal_Int16 > >& i_rPaths )
77cdf0e10cSrcweir         :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
78cdf0e10cSrcweir         ,m_xWizard( i_rWizard )
79cdf0e10cSrcweir         ,m_xController( i_rController )
80cdf0e10cSrcweir         ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         ENSURE_OR_THROW( m_xWizard.is() && m_xController.is(), "invalid wizard/controller" );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         // declare the paths
85cdf0e10cSrcweir         for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
86cdf0e10cSrcweir         {
87cdf0e10cSrcweir             const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
88cdf0e10cSrcweir             WizardPath aPath( rPath.getLength() );
89cdf0e10cSrcweir             for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
90cdf0e10cSrcweir                 aPath[j] = impl_pageIdToState( rPath[j] );
91cdf0e10cSrcweir             declarePath( i, aPath );
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         // create the first page, to know the page size
95cdf0e10cSrcweir         TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
96cdf0e10cSrcweir         SetPageSizePixel( pStartPage->GetSizePixel() );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         // some defaults
99cdf0e10cSrcweir         ShowButtonFixedLine( true );
100cdf0e10cSrcweir         SetRoadmapInteractive( true );
101cdf0e10cSrcweir         enableAutomaticNextButtonState();
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~WizardShell()105cdf0e10cSrcweir     WizardShell::~WizardShell()
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
Execute()110cdf0e10cSrcweir     short WizardShell::Execute()
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         ActivatePage();
113cdf0e10cSrcweir         return WizardShell_Base::Execute();
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
convertCommitReasonToTravelType(const CommitPageReason i_eReason)117cdf0e10cSrcweir     sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         switch ( i_eReason )
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir         case WizardTypes::eTravelForward:
122cdf0e10cSrcweir             return WizardTravelType::FORWARD;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         case WizardTypes::eTravelBackward:
125cdf0e10cSrcweir             return WizardTravelType::BACKWARD;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         case WizardTypes::eFinish:
128cdf0e10cSrcweir             return WizardTravelType::FINISH;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         default:
131cdf0e10cSrcweir             break;
132cdf0e10cSrcweir         }
133cdf0e10cSrcweir         OSL_ENSURE( false, "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
134cdf0e10cSrcweir         return WizardTravelType::FINISH;
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
enterState(WizardState i_nState)138cdf0e10cSrcweir 	void WizardShell::enterState( WizardState i_nState )
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         WizardShell_Base::enterState( i_nState );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         if ( !m_xController.is() )
143cdf0e10cSrcweir             return;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         try
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir         catch( const Exception& )
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
leaveState(WizardState i_nState)156cdf0e10cSrcweir     sal_Bool WizardShell::leaveState( WizardState i_nState )
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         if ( !WizardShell_Base::leaveState( i_nState ) )
159cdf0e10cSrcweir             return sal_False;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         if ( !m_xController.is() )
162cdf0e10cSrcweir             return sal_True;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         try
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir             m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir         catch( const Exception& )
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         return sal_True;
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
impl_getController(TabPage * i_pPage) const177cdf0e10cSrcweir     PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
180cdf0e10cSrcweir         ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
181cdf0e10cSrcweir         return pos->second;
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getCurrentWizardPage() const185cdf0e10cSrcweir     Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         const WizardState eState = getCurrentState();
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         PWizardPageController pController( impl_getController( GetPage( eState ) ) );
190cdf0e10cSrcweir         ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         return pController->getWizardPage();
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
enablePage(const sal_Int16 i_nPageID,const sal_Bool i_bEnable)196cdf0e10cSrcweir     void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable )
197cdf0e10cSrcweir     {
198cdf0e10cSrcweir         enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
createPage(WizardState i_nState)202cdf0e10cSrcweir 	TabPage* WizardShell::createPage( WizardState i_nState )
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
207cdf0e10cSrcweir         TabPage* pPage = pController->getTabPage();
208cdf0e10cSrcweir         OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
209cdf0e10cSrcweir         if ( pPage == NULL )
210cdf0e10cSrcweir         {
211cdf0e10cSrcweir             // fallback for ill-behaved clients: empty page
212cdf0e10cSrcweir             pPage = new TabPage( this, 0 );
213cdf0e10cSrcweir             pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
214cdf0e10cSrcweir         }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         m_aPageControllers[ pPage ] = pController;
217cdf0e10cSrcweir         return pPage;
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getPageController(TabPage * i_pCurrentPage) const221cdf0e10cSrcweir 	IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         return impl_getController( i_pCurrentPage ).get();
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
getStateDisplayName(WizardState i_nState) const227cdf0e10cSrcweir     String WizardShell::getStateDisplayName( WizardState i_nState ) const
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         try
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             if ( m_xController.is() )
232cdf0e10cSrcweir                 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir         catch( const Exception& )
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir         // fallback for ill-behaved clients: the numeric state
239cdf0e10cSrcweir         return String::CreateFromInt32( i_nState );
240cdf0e10cSrcweir     }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
canAdvance() const243cdf0e10cSrcweir     bool WizardShell::canAdvance() const
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         try
246cdf0e10cSrcweir         {
247cdf0e10cSrcweir             if ( m_xController.is() && !m_xController->canAdvance() )
248cdf0e10cSrcweir                 return false;
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir         catch( const Exception& )
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
253cdf0e10cSrcweir         }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         return WizardShell_Base::canAdvance();
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
onFinish()259cdf0e10cSrcweir     sal_Bool WizardShell::onFinish()
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         try
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir             if ( m_xController.is() && !m_xController->confirmFinish() )
264cdf0e10cSrcweir                 return sal_False;
265cdf0e10cSrcweir         }
266cdf0e10cSrcweir         catch( const Exception& )
267cdf0e10cSrcweir         {
268cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         return WizardShell_Base::onFinish();
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir //......................................................................................................................
275cdf0e10cSrcweir } } // namespace svt::uno
276cdf0e10cSrcweir //......................................................................................................................
277