fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / uno / wizard / wizardshell.cxx
blob82503616390b2758eac16e077ec6cc9c65afa94e
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>
30 //......................................................................................................................
31 namespace svt { namespace uno
33 //......................................................................................................................
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;
52 //==================================================================================================================
53 namespace
55 //--------------------------------------------------------------------------------------------------------------
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];
63 //==================================================================================================================
64 //= WizardShell
65 //==================================================================================================================
66 //------------------------------------------------------------------------------------------------------------------
67 WizardShell::WizardShell( Window* i_pParent, const Reference< XWizard >& i_rWizard, const Reference< XWizardController >& i_rController,
68 const Sequence< Sequence< sal_Int16 > >& i_rPaths )
69 :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
70 ,m_xWizard( i_rWizard )
71 ,m_xController( i_rController )
72 ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
74 ENSURE_OR_THROW( m_xWizard.is() && m_xController.is(), "invalid wizard/controller" );
76 // declare the paths
77 for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
79 const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
80 WizardPath aPath( rPath.getLength() );
81 for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
82 aPath[j] = impl_pageIdToState( rPath[j] );
83 declarePath( i, aPath );
86 // create the first page, to know the page size
87 TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
88 SetPageSizePixel( pStartPage->GetSizePixel() );
90 // some defaults
91 ShowButtonFixedLine( true );
92 SetRoadmapInteractive( true );
93 enableAutomaticNextButtonState();
96 //------------------------------------------------------------------------------------------------------------------
97 WizardShell::~WizardShell()
101 //------------------------------------------------------------------------------------------------------------------
102 short WizardShell::Execute()
104 ActivatePage();
105 return WizardShell_Base::Execute();
108 //------------------------------------------------------------------------------------------------------------------
109 sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
111 switch ( i_eReason )
113 case WizardTypes::eTravelForward:
114 return WizardTravelType::FORWARD;
116 case WizardTypes::eTravelBackward:
117 return WizardTravelType::BACKWARD;
119 case WizardTypes::eFinish:
120 return WizardTravelType::FINISH;
122 default:
123 break;
125 OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
126 return WizardTravelType::FINISH;
129 //------------------------------------------------------------------------------------------------------------------
130 void WizardShell::enterState( WizardState i_nState )
132 WizardShell_Base::enterState( i_nState );
134 if ( !m_xController.is() )
135 return;
139 m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
141 catch( const Exception& )
143 DBG_UNHANDLED_EXCEPTION();
147 //------------------------------------------------------------------------------------------------------------------
148 sal_Bool WizardShell::leaveState( WizardState i_nState )
150 if ( !WizardShell_Base::leaveState( i_nState ) )
151 return sal_False;
153 if ( !m_xController.is() )
154 return sal_True;
158 m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
160 catch( const Exception& )
162 DBG_UNHANDLED_EXCEPTION();
165 return sal_True;
168 //------------------------------------------------------------------------------------------------------------------
169 PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
171 Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
172 ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
173 return pos->second;
176 //------------------------------------------------------------------------------------------------------------------
177 Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
179 const WizardState eState = getCurrentState();
181 PWizardPageController pController( impl_getController( GetPage( eState ) ) );
182 ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
184 return pController->getWizardPage();
187 //------------------------------------------------------------------------------------------------------------------
188 void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable )
190 enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
193 //------------------------------------------------------------------------------------------------------------------
194 TabPage* WizardShell::createPage( WizardState i_nState )
196 ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
198 ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
199 TabPage* pPage = pController->getTabPage();
200 OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
201 if ( pPage == NULL )
203 // fallback for ill-behaved clients: empty page
204 pPage = new TabPage( this, 0 );
205 pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
208 m_aPageControllers[ pPage ] = pController;
209 return pPage;
212 //------------------------------------------------------------------------------------------------------------------
213 IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
215 return impl_getController( i_pCurrentPage ).get();
218 //------------------------------------------------------------------------------------------------------------------
219 String WizardShell::getStateDisplayName( WizardState i_nState ) const
223 if ( m_xController.is() )
224 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
226 catch( const Exception& )
228 DBG_UNHANDLED_EXCEPTION();
230 // fallback for ill-behaved clients: the numeric state
231 return OUString::number(i_nState);
234 //------------------------------------------------------------------------------------------------------------------
235 bool WizardShell::canAdvance() const
239 if ( m_xController.is() && !m_xController->canAdvance() )
240 return false;
242 catch( const Exception& )
244 DBG_UNHANDLED_EXCEPTION();
247 return WizardShell_Base::canAdvance();
250 //------------------------------------------------------------------------------------------------------------------
251 sal_Bool WizardShell::onFinish()
255 if ( m_xController.is() && !m_xController->confirmFinish() )
256 return sal_False;
258 catch( const Exception& )
260 DBG_UNHANDLED_EXCEPTION();
263 return WizardShell_Base::onFinish();
266 //......................................................................................................................
267 } } // namespace svt::uno
268 //......................................................................................................................
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */