Line data Source code
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"
22 : #include "wizardpagecontroller.hxx"
23 :
24 : #include <tools/diagnose_ex.h>
25 :
26 : #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
27 :
28 : #include <vcl/msgbox.hxx>
29 :
30 :
31 : namespace svt { namespace uno
32 : {
33 :
34 :
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;
49 :
50 : namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType;
51 :
52 :
53 : namespace
54 : {
55 :
56 0 : sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
57 : {
58 0 : ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" );
59 0 : return i_rPaths[0][0];
60 : }
61 : }
62 :
63 :
64 : //= WizardShell
65 0 : 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 0 : ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
70 : {
71 0 : ENSURE_OR_THROW( m_xController.is(), "invalid controller" );
72 :
73 : // declare the paths
74 0 : for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
75 : {
76 0 : const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
77 0 : WizardPath aPath( rPath.getLength() );
78 0 : for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
79 0 : aPath[j] = impl_pageIdToState( rPath[j] );
80 0 : declarePath( i, aPath );
81 0 : }
82 :
83 : // create the first page, to know the page size
84 0 : TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
85 0 : SetPageSizePixel( pStartPage->GetSizePixel() );
86 :
87 : // some defaults
88 0 : SetRoadmapInteractive( true );
89 0 : enableAutomaticNextButtonState();
90 0 : }
91 :
92 :
93 0 : short WizardShell::Execute()
94 : {
95 0 : ActivatePage();
96 0 : return WizardShell_Base::Execute();
97 : }
98 :
99 :
100 0 : sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
101 : {
102 0 : switch ( i_eReason )
103 : {
104 : case WizardTypes::eTravelForward:
105 0 : return WizardTravelType::FORWARD;
106 :
107 : case WizardTypes::eTravelBackward:
108 0 : return WizardTravelType::BACKWARD;
109 :
110 : case WizardTypes::eFinish:
111 0 : return WizardTravelType::FINISH;
112 :
113 : default:
114 0 : break;
115 : }
116 : OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
117 0 : return WizardTravelType::FINISH;
118 : }
119 :
120 :
121 0 : void WizardShell::enterState( WizardState i_nState )
122 : {
123 0 : WizardShell_Base::enterState( i_nState );
124 :
125 0 : if ( !m_xController.is() )
126 0 : return;
127 :
128 : try
129 : {
130 0 : m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
131 : }
132 0 : catch( const Exception& )
133 : {
134 : DBG_UNHANDLED_EXCEPTION();
135 : }
136 : }
137 :
138 :
139 0 : bool WizardShell::leaveState( WizardState i_nState )
140 : {
141 0 : if ( !WizardShell_Base::leaveState( i_nState ) )
142 0 : return false;
143 :
144 0 : if ( !m_xController.is() )
145 0 : return true;
146 :
147 : try
148 : {
149 0 : m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
150 : }
151 0 : catch( const Exception& )
152 : {
153 : DBG_UNHANDLED_EXCEPTION();
154 : }
155 :
156 0 : return true;
157 : }
158 :
159 :
160 0 : PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
161 : {
162 0 : Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
163 0 : ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
164 0 : return pos->second;
165 : }
166 :
167 :
168 0 : Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
169 : {
170 0 : const WizardState eState = getCurrentState();
171 :
172 0 : PWizardPageController pController( impl_getController( GetPage( eState ) ) );
173 0 : ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
174 :
175 0 : return pController->getWizardPage();
176 : }
177 :
178 :
179 0 : void WizardShell::enablePage( const sal_Int16 i_nPageID, const bool i_bEnable )
180 : {
181 0 : enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
182 0 : }
183 :
184 :
185 0 : VclPtr<TabPage> WizardShell::createPage( WizardState i_nState )
186 : {
187 0 : ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
188 :
189 0 : ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
190 0 : VclPtr<TabPage> pPage = pController->getTabPage();
191 : OSL_ENSURE( pPage, "WizardShell::createPage: illegal tab page!" );
192 0 : if ( !pPage )
193 : {
194 : // fallback for ill-behaved clients: empty page
195 0 : pPage = VclPtr<TabPage>::Create( this, 0 );
196 0 : pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
197 : }
198 :
199 0 : m_aPageControllers[ pPage ] = pController;
200 0 : return pPage;
201 : }
202 :
203 0 : IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
204 : {
205 0 : return impl_getController( i_pCurrentPage ).get();
206 : }
207 :
208 :
209 0 : OUString WizardShell::getStateDisplayName( WizardState i_nState ) const
210 : {
211 : try
212 : {
213 0 : if ( m_xController.is() )
214 0 : return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
215 : }
216 0 : catch( const Exception& )
217 : {
218 : DBG_UNHANDLED_EXCEPTION();
219 : }
220 : // fallback for ill-behaved clients: the numeric state
221 0 : return OUString::number(i_nState);
222 : }
223 :
224 :
225 0 : bool WizardShell::canAdvance() const
226 : {
227 : try
228 : {
229 0 : if ( m_xController.is() && !m_xController->canAdvance() )
230 0 : return false;
231 : }
232 0 : catch( const Exception& )
233 : {
234 : DBG_UNHANDLED_EXCEPTION();
235 : }
236 :
237 0 : return WizardShell_Base::canAdvance();
238 : }
239 :
240 :
241 0 : bool WizardShell::onFinish()
242 : {
243 : try
244 : {
245 0 : if ( m_xController.is() && !m_xController->confirmFinish() )
246 0 : return false;
247 : }
248 0 : catch( const Exception& )
249 : {
250 : DBG_UNHANDLED_EXCEPTION();
251 : }
252 :
253 0 : return WizardShell_Base::onFinish();
254 : }
255 :
256 :
257 : } } // namespace svt::uno
258 :
259 :
260 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|