LibreOffice Module svtools (master) 1
wizardshell.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "wizardshell.hxx"
23
25
26#include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
27
29
30namespace svt::uno
31{
32
33
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;
39
40 namespace WizardTravelType = css::ui::dialogs::WizardTravelType;
41
42
43 namespace
44 {
45
46 sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
47 {
48 ENSURE_OR_THROW( i_rPaths.hasElements() && i_rPaths[0].hasElements(), "illegal paths" );
49 return i_rPaths[0][0];
50 }
51 }
52
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 ) )
59 {
60 ENSURE_OR_THROW( m_xController.is(), "invalid controller" );
61
62 // declare the paths
63 for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
64 {
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 );
70 }
71
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);
75
76 // some defaults
78 }
79
81 {
83 return WizardShell_Base::run();
84 }
85
87 {
88 return OUString::number(impl_stateToPageId(nState));
89 }
90
91 WizardState WizardShell::getStateFromPageIdent(const OUString& rIdent) const
92 {
93 return impl_pageIdToState(rIdent.toInt32());
94 }
95
97 {
98 switch ( i_eReason )
99 {
101 return WizardTravelType::FORWARD;
102
104 return WizardTravelType::BACKWARD;
105
107 return WizardTravelType::FINISH;
108
109 default:
110 break;
111 }
112 OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
113 return WizardTravelType::FINISH;
114 }
115
116
118 {
120
121 if ( !m_xController.is() )
122 return;
123
124 try
125 {
126 m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
127 }
128 catch( const Exception& )
129 {
130 DBG_UNHANDLED_EXCEPTION("svtools.uno");
131 }
132 }
133
134
136 {
137 if ( !WizardShell_Base::leaveState( i_nState ) )
138 return false;
139
140 if ( !m_xController.is() )
141 return true;
142
143 try
144 {
145 m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
146 }
147 catch( const Exception& )
148 {
149 DBG_UNHANDLED_EXCEPTION("svtools.uno");
150 }
151
152 return true;
153 }
154
155
157 {
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;
161 }
162
163
164 Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
165 {
166 const WizardState eState = getCurrentState();
167
168 PWizardPageController pController( impl_getController( GetPage( eState ) ) );
169 ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", nullptr );
170
171 return pController->getWizardPage();
172 }
173
174 void WizardShell::enablePage( const sal_Int16 i_nPageID, const bool i_bEnable )
175 {
176 enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
177 }
178
179 namespace
180 {
181 class EmptyPage : public BuilderPage
182 {
183 public:
184 EmptyPage(weld::Widget* pParent, weld::DialogController* pController)
185 : BuilderPage(pParent, pController, "svt/ui/emptypage.ui", "EmptyPage")
186 {
187 m_xContainer->set_size_request(m_xContainer->get_approximate_digit_width() * 70,
188 m_xContainer->get_text_height() * 10);
189 }
190 weld::Container* GetContainer() const { return m_xContainer.get(); }
191 };
192 }
193
194 std::unique_ptr<BuilderPage> WizardShell::createPage( WizardState i_nState )
195 {
196 ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", nullptr );
197
198 sal_Int16 nPageId = impl_stateToPageId(i_nState);
199
200 OUString sIdent(OUString::number(nPageId));
201 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
202
203 auto xPage = std::make_unique<EmptyPage>(pPageContainer, this);
204 auto pController = std::make_shared<WizardPageController>(xPage->GetContainer(), m_xController, nPageId);
205
206 m_aPageControllers[xPage.get()] = pController;
207
208 return xPage;
209 }
210
211 vcl::IWizardPageController* WizardShell::getPageController(BuilderPage* i_pCurrentPage) const
212 {
213 return impl_getController( i_pCurrentPage ).get();
214 }
215
217 {
218 try
219 {
220 if ( m_xController.is() )
221 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
222 }
223 catch( const Exception& )
224 {
225 DBG_UNHANDLED_EXCEPTION("svtools.uno");
226 }
227 // fallback for ill-behaved clients: the numeric state
228 return OUString::number(i_nState);
229 }
230
231
233 {
234 try
235 {
236 if ( m_xController.is() && !m_xController->canAdvance() )
237 return false;
238 }
239 catch( const Exception& )
240 {
241 DBG_UNHANDLED_EXCEPTION("svtools.uno");
242 }
243
245 }
246
247
249 {
250 try
251 {
252 if ( m_xController.is() && !m_xController->confirmFinish() )
253 return false;
254 }
255 catch( const Exception& )
256 {
257 DBG_UNHANDLED_EXCEPTION("svtools.uno");
258 }
259
261 }
262
263
264} // namespace svt::uno
265
266
267/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 nPageId
virtual bool leaveState(WizardState i_nState) override
WizardState impl_pageIdToState(const sal_Int16 i_nPageId) const
css::uno::Reference< css::ui::dialogs::XWizardPage > getCurrentWizardPage() const
virtual vcl::IWizardPageController * getPageController(BuilderPage *pCurrentPage) const override
virtual std::unique_ptr< BuilderPage > createPage(WizardState i_nState) override
virtual OUString getStateDisplayName(WizardState i_nState) const override
const css::uno::Reference< css::ui::dialogs::XWizardController > m_xController
virtual WizardState getStateFromPageIdent(const OUString &rIdent) const override
Definition: wizardshell.cxx:91
virtual bool onFinish() override
Page2ControllerMap m_aPageControllers
virtual OUString getPageIdentForState(WizardState nState) const override
Definition: wizardshell.cxx:86
sal_Int16 impl_stateToPageId(const WizardState i_nState) const
Definition: wizardshell.hxx:97
PWizardPageController impl_getController(BuilderPage *i_pPage) const
virtual void enterState(WizardState i_nState) override
WizardShell(weld::Window *pParent, const css::uno::Reference< css::ui::dialogs::XWizardController > &i_rController, const css::uno::Sequence< css::uno::Sequence< sal_Int16 > > &i_rPaths)
Definition: wizardshell.cxx:54
virtual short run() override
Definition: wizardshell.cxx:80
void enablePage(const sal_Int16 i_PageID, const bool i_Enable)
static sal_Int16 convertCommitReasonToTravelType(const CommitPageReason i_eReason)
Definition: wizardshell.cxx:96
virtual bool canAdvance() const override
void declarePath(RoadmapWizardTypes::PathId _nPathId, const RoadmapWizardTypes::WizardPath &_lWizardStates)
virtual void enterState(WizardTypes::WizardState nState) override
virtual bool canAdvance() const override
void enableState(WizardTypes::WizardState nState, bool _bEnable=true)
virtual bool leaveState(WizardTypes::WizardState nState)
virtual bool onFinish()
void enableAutomaticNextButtonState()
virtual void ActivatePage()
BuilderPage * GetOrCreatePage(const WizardTypes::WizardState i_nState)
WizardTypes::WizardState getCurrentState() const
BuilderPage * GetPage(WizardTypes::WizardState eState) const
std::unique_ptr< weld::Assistant > m_xAssistant
virtual short run()
#define ENSURE_OR_THROW(c, m)
#define ENSURE_OR_RETURN(c, m, r)
#define DBG_UNHANDLED_EXCEPTION(...)
sal_Int32 nState
Definition: embedhlp.cxx:75
@ Exception
int i
std::shared_ptr< WizardPageController > PWizardPageController
Definition: wizardshell.hxx:34
::std::vector< WizardTypes::WizardState > WizardPath
sal_Int16 WizardState
CommitPageReason
Reference< XNameAccess > m_xContainer
size_t pos