android: Update app-specific/MIME type icons
[LibreOffice.git] / svtools / source / uno / wizard / wizardshell.cxx
blobd9cbca5874dd6ca23c89078d5a71b3f1b5d0327d
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 <comphelper/diagnose_ex.hxx>
26 #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
28 using vcl::RoadmapWizardTypes::WizardPath;
30 namespace svt::uno
34 using css::uno::Reference;
35 using css::uno::Exception;
36 using css::uno::Sequence;
37 using css::ui::dialogs::XWizardController;
38 using css::ui::dialogs::XWizardPage;
40 namespace WizardTravelType = css::ui::dialogs::WizardTravelType;
43 namespace
46 sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
48 ENSURE_OR_THROW( i_rPaths.hasElements() && i_rPaths[0].hasElements(), "illegal paths" );
49 return i_rPaths[0][0];
53 //= WizardShell
54 WizardShell::WizardShell(weld::Window* i_pParent, const Reference< XWizardController >& i_rController,
55 const Sequence< Sequence< sal_Int16 > >& i_rPaths)
56 :WizardShell_Base( i_pParent )
57 ,m_xController( i_rController )
58 ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
60 ENSURE_OR_THROW( m_xController.is(), "invalid controller" );
62 // declare the paths
63 for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
65 const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
66 WizardPath aPath( rPath.getLength() );
67 std::transform(rPath.begin(), rPath.end(), aPath.begin(),
68 [this](const sal_Int16 nPageId) -> WizardPath::value_type { return impl_pageIdToState(nPageId); });
69 declarePath( i, aPath );
72 // create the first page, to know the page size
73 GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
74 m_xAssistant->set_current_page(0);
76 // some defaults
77 enableAutomaticNextButtonState();
80 short WizardShell::run()
82 ActivatePage();
83 return WizardShell_Base::run();
86 OUString WizardShell::getPageIdentForState(WizardState nState) const
88 return OUString::number(impl_stateToPageId(nState));
91 WizardState WizardShell::getStateFromPageIdent(const OUString& rIdent) const
93 return impl_pageIdToState(rIdent.toInt32());
96 sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
98 switch ( i_eReason )
100 case vcl::WizardTypes::eTravelForward:
101 return WizardTravelType::FORWARD;
103 case vcl::WizardTypes::eTravelBackward:
104 return WizardTravelType::BACKWARD;
106 case vcl::WizardTypes::eFinish:
107 return WizardTravelType::FINISH;
109 default:
110 break;
112 OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
113 return WizardTravelType::FINISH;
117 void WizardShell::enterState( WizardState i_nState )
119 WizardShell_Base::enterState( i_nState );
121 if ( !m_xController.is() )
122 return;
126 m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
128 catch( const Exception& )
130 DBG_UNHANDLED_EXCEPTION("svtools.uno");
135 bool WizardShell::leaveState( WizardState i_nState )
137 if ( !WizardShell_Base::leaveState( i_nState ) )
138 return false;
140 if ( !m_xController.is() )
141 return true;
145 m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
147 catch( const Exception& )
149 DBG_UNHANDLED_EXCEPTION("svtools.uno");
152 return true;
156 PWizardPageController WizardShell::impl_getController(BuilderPage* i_pPage) const
158 Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
159 ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
160 return pos->second;
164 Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
166 const WizardState eState = getCurrentState();
168 PWizardPageController pController( impl_getController( GetPage( eState ) ) );
169 ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", nullptr );
171 return pController->getWizardPage();
174 void WizardShell::enablePage( const sal_Int16 i_nPageID, const bool i_bEnable )
176 enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
179 namespace
181 class EmptyPage : public BuilderPage
183 public:
184 EmptyPage(weld::Widget* pParent, weld::DialogController* pController)
185 : BuilderPage(pParent, pController, "svt/ui/emptypage.ui", "EmptyPage")
187 m_xContainer->set_size_request(m_xContainer->get_approximate_digit_width() * 70,
188 m_xContainer->get_text_height() * 10);
190 weld::Container* GetContainer() const { return m_xContainer.get(); }
194 std::unique_ptr<BuilderPage> WizardShell::createPage( WizardState i_nState )
196 ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", nullptr );
198 sal_Int16 nPageId = impl_stateToPageId(i_nState);
200 OUString sIdent(OUString::number(nPageId));
201 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
203 auto xPage = std::make_unique<EmptyPage>(pPageContainer, this);
204 auto pController = std::make_shared<WizardPageController>(xPage->GetContainer(), m_xController, nPageId);
206 m_aPageControllers[xPage.get()] = pController;
208 return xPage;
211 vcl::IWizardPageController* WizardShell::getPageController(BuilderPage* i_pCurrentPage) const
213 return impl_getController( i_pCurrentPage ).get();
216 OUString WizardShell::getStateDisplayName( WizardState i_nState ) const
220 if ( m_xController.is() )
221 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
223 catch( const Exception& )
225 DBG_UNHANDLED_EXCEPTION("svtools.uno");
227 // fallback for ill-behaved clients: the numeric state
228 return OUString::number(i_nState);
232 bool WizardShell::canAdvance() const
236 if ( m_xController.is() && !m_xController->canAdvance() )
237 return false;
239 catch( const Exception& )
241 DBG_UNHANDLED_EXCEPTION("svtools.uno");
244 return WizardShell_Base::canAdvance();
248 bool WizardShell::onFinish()
252 if ( m_xController.is() && !m_xController->confirmFinish() )
253 return false;
255 catch( const Exception& )
257 DBG_UNHANDLED_EXCEPTION("svtools.uno");
260 return WizardShell_Base::onFinish();
264 } // namespace svt::uno
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */