Bump version to 5.0-14
[LibreOffice.git] / svtools / source / uno / wizard / wizardshell.cxx
blobb3504d9d5f5501871a00a9c14f4dc225d575dad2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "wizardshell.hxx"
22 #include "wizardpagecontroller.hxx"
24 #include <tools/diagnose_ex.h>
26 #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
28 #include <vcl/msgbox.hxx>
31 namespace svt { namespace uno
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::XInterface;
37 using ::com::sun::star::uno::UNO_QUERY;
38 using ::com::sun::star::uno::UNO_QUERY_THROW;
39 using ::com::sun::star::uno::UNO_SET_THROW;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::uno::RuntimeException;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::uno::makeAny;
44 using ::com::sun::star::uno::Sequence;
45 using ::com::sun::star::uno::Type;
46 using ::com::sun::star::ui::dialogs::XWizardController;
47 using ::com::sun::star::ui::dialogs::XWizard;
48 using ::com::sun::star::ui::dialogs::XWizardPage;
50 namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType;
53 namespace
56 sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
58 ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" );
59 return i_rPaths[0][0];
64 //= WizardShell
65 WizardShell::WizardShell( vcl::Window* i_pParent, const Reference< XWizardController >& i_rController,
66 const Sequence< Sequence< sal_Int16 > >& i_rPaths )
67 :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
68 ,m_xController( i_rController )
69 ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
71 ENSURE_OR_THROW( m_xController.is(), "invalid controller" );
73 // declare the paths
74 for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
76 const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
77 WizardPath aPath( rPath.getLength() );
78 for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
79 aPath[j] = impl_pageIdToState( rPath[j] );
80 declarePath( i, aPath );
83 // create the first page, to know the page size
84 TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
85 SetPageSizePixel( pStartPage->GetSizePixel() );
87 // some defaults
88 SetRoadmapInteractive( true );
89 enableAutomaticNextButtonState();
93 short WizardShell::Execute()
95 ActivatePage();
96 return WizardShell_Base::Execute();
100 sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
102 switch ( i_eReason )
104 case WizardTypes::eTravelForward:
105 return WizardTravelType::FORWARD;
107 case WizardTypes::eTravelBackward:
108 return WizardTravelType::BACKWARD;
110 case WizardTypes::eFinish:
111 return WizardTravelType::FINISH;
113 default:
114 break;
116 OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
117 return WizardTravelType::FINISH;
121 void WizardShell::enterState( WizardState i_nState )
123 WizardShell_Base::enterState( i_nState );
125 if ( !m_xController.is() )
126 return;
130 m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
132 catch( const Exception& )
134 DBG_UNHANDLED_EXCEPTION();
139 bool WizardShell::leaveState( WizardState i_nState )
141 if ( !WizardShell_Base::leaveState( i_nState ) )
142 return false;
144 if ( !m_xController.is() )
145 return true;
149 m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
151 catch( const Exception& )
153 DBG_UNHANDLED_EXCEPTION();
156 return true;
160 PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
162 Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
163 ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
164 return pos->second;
168 Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
170 const WizardState eState = getCurrentState();
172 PWizardPageController pController( impl_getController( GetPage( eState ) ) );
173 ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
175 return pController->getWizardPage();
179 void WizardShell::enablePage( const sal_Int16 i_nPageID, const bool i_bEnable )
181 enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
185 VclPtr<TabPage> WizardShell::createPage( WizardState i_nState )
187 ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
189 ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
190 VclPtr<TabPage> pPage = pController->getTabPage();
191 OSL_ENSURE( pPage, "WizardShell::createPage: illegal tab page!" );
192 if ( !pPage )
194 // fallback for ill-behaved clients: empty page
195 pPage = VclPtr<TabPage>::Create( this, 0 );
196 pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
199 m_aPageControllers[ pPage ] = pController;
200 return pPage;
203 IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
205 return impl_getController( i_pCurrentPage ).get();
209 OUString WizardShell::getStateDisplayName( WizardState i_nState ) const
213 if ( m_xController.is() )
214 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
216 catch( const Exception& )
218 DBG_UNHANDLED_EXCEPTION();
220 // fallback for ill-behaved clients: the numeric state
221 return OUString::number(i_nState);
225 bool WizardShell::canAdvance() const
229 if ( m_xController.is() && !m_xController->canAdvance() )
230 return false;
232 catch( const Exception& )
234 DBG_UNHANDLED_EXCEPTION();
237 return WizardShell_Base::canAdvance();
241 bool WizardShell::onFinish()
245 if ( m_xController.is() && !m_xController->confirmFinish() )
246 return false;
248 catch( const Exception& )
250 DBG_UNHANDLED_EXCEPTION();
253 return WizardShell_Base::onFinish();
257 } } // namespace svt::uno
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */