Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 : : *
5 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
6 : : *
7 : : * OpenOffice.org - a multi-platform office productivity suite
8 : : *
9 : : * This file is part of OpenOffice.org.
10 : : *
11 : : * OpenOffice.org is free software: you can redistribute it and/or modify
12 : : * it under the terms of the GNU Lesser General Public License version 3
13 : : * only, as published by the Free Software Foundation.
14 : : *
15 : : * OpenOffice.org is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU Lesser General Public License version 3 for more details
19 : : * (a copy is included in the LICENSE file that accompanied this code).
20 : : *
21 : : * You should have received a copy of the GNU Lesser General Public License
22 : : * version 3 along with OpenOffice.org. If not, see
23 : : * <http://www.openoffice.org/license.html>
24 : : * for a copy of the LGPLv3 License.
25 : : *
26 : : ************************************************************************/
27 : :
28 : :
29 : : #include "wizardshell.hxx"
30 : : #include "wizardpagecontroller.hxx"
31 : :
32 : : #include <tools/diagnose_ex.h>
33 : :
34 : : #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
35 : :
36 : : #include <vcl/msgbox.hxx>
37 : :
38 : : //......................................................................................................................
39 : : namespace svt { namespace uno
40 : : {
41 : : //......................................................................................................................
42 : :
43 : : /** === begin UNO using === **/
44 : : using ::com::sun::star::uno::Reference;
45 : : using ::com::sun::star::uno::XInterface;
46 : : using ::com::sun::star::uno::UNO_QUERY;
47 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
48 : : using ::com::sun::star::uno::UNO_SET_THROW;
49 : : using ::com::sun::star::uno::Exception;
50 : : using ::com::sun::star::uno::RuntimeException;
51 : : using ::com::sun::star::uno::Any;
52 : : using ::com::sun::star::uno::makeAny;
53 : : using ::com::sun::star::uno::Sequence;
54 : : using ::com::sun::star::uno::Type;
55 : : using ::com::sun::star::ui::dialogs::XWizardController;
56 : : using ::com::sun::star::ui::dialogs::XWizard;
57 : : using ::com::sun::star::ui::dialogs::XWizardPage;
58 : : /** === end UNO using === **/
59 : : namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType;
60 : :
61 : : //==================================================================================================================
62 : : namespace
63 : : {
64 : : //--------------------------------------------------------------------------------------------------------------
65 : 0 : sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
66 : : {
67 [ # # ][ # # ]: 0 : ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" );
[ # # ][ # # ]
[ # # ][ # # ]
68 : 0 : return i_rPaths[0][0];
69 : : }
70 : : }
71 : :
72 : : //==================================================================================================================
73 : : //= WizardShell
74 : : //==================================================================================================================
75 : : //------------------------------------------------------------------------------------------------------------------
76 : 0 : WizardShell::WizardShell( Window* i_pParent, const Reference< XWizard >& i_rWizard, const Reference< XWizardController >& i_rController,
77 : : const Sequence< Sequence< sal_Int16 > >& i_rPaths )
78 : : :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
79 : : ,m_xWizard( i_rWizard )
80 : : ,m_xController( i_rController )
81 [ # # ][ # # ]: 0 : ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
82 : : {
83 [ # # ][ # # ]: 0 : ENSURE_OR_THROW( m_xWizard.is() && m_xController.is(), "invalid wizard/controller" );
[ # # ][ # # ]
[ # # ][ # # ]
84 : :
85 : : // declare the paths
86 [ # # ]: 0 : for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
87 : : {
88 : 0 : const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
89 [ # # ]: 0 : WizardPath aPath( rPath.getLength() );
90 [ # # ]: 0 : for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
91 [ # # ]: 0 : aPath[j] = impl_pageIdToState( rPath[j] );
92 [ # # ]: 0 : declarePath( i, aPath );
93 : 0 : }
94 : :
95 : : // create the first page, to know the page size
96 [ # # ]: 0 : TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
97 [ # # ]: 0 : SetPageSizePixel( pStartPage->GetSizePixel() );
98 : :
99 : : // some defaults
100 [ # # ]: 0 : ShowButtonFixedLine( true );
101 [ # # ]: 0 : SetRoadmapInteractive( true );
102 [ # # ]: 0 : enableAutomaticNextButtonState();
103 : 0 : }
104 : :
105 : : //------------------------------------------------------------------------------------------------------------------
106 : 0 : WizardShell::~WizardShell()
107 : : {
108 [ # # ]: 0 : }
109 : :
110 : : //------------------------------------------------------------------------------------------------------------------
111 : 0 : short WizardShell::Execute()
112 : : {
113 : 0 : ActivatePage();
114 : 0 : return WizardShell_Base::Execute();
115 : : }
116 : :
117 : : //------------------------------------------------------------------------------------------------------------------
118 : 0 : sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
119 : : {
120 [ # # # # ]: 0 : switch ( i_eReason )
121 : : {
122 : : case WizardTypes::eTravelForward:
123 : 0 : return WizardTravelType::FORWARD;
124 : :
125 : : case WizardTypes::eTravelBackward:
126 : 0 : return WizardTravelType::BACKWARD;
127 : :
128 : : case WizardTypes::eFinish:
129 : 0 : return WizardTravelType::FINISH;
130 : :
131 : : default:
132 : 0 : break;
133 : : }
134 : : OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
135 : 0 : return WizardTravelType::FINISH;
136 : : }
137 : :
138 : : //------------------------------------------------------------------------------------------------------------------
139 : 0 : void WizardShell::enterState( WizardState i_nState )
140 : : {
141 : 0 : WizardShell_Base::enterState( i_nState );
142 : :
143 [ # # ]: 0 : if ( !m_xController.is() )
144 [ # # ]: 0 : return;
145 : :
146 : : try
147 : : {
148 [ # # ][ # # ]: 0 : m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
149 : : }
150 : 0 : catch( const Exception& )
151 : : {
152 : : DBG_UNHANDLED_EXCEPTION();
153 : : }
154 : : }
155 : :
156 : : //------------------------------------------------------------------------------------------------------------------
157 : 0 : sal_Bool WizardShell::leaveState( WizardState i_nState )
158 : : {
159 [ # # ]: 0 : if ( !WizardShell_Base::leaveState( i_nState ) )
160 : 0 : return sal_False;
161 : :
162 [ # # ]: 0 : if ( !m_xController.is() )
163 : 0 : return sal_True;
164 : :
165 : : try
166 : : {
167 [ # # ][ # # ]: 0 : m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
168 : : }
169 : 0 : catch( const Exception& )
170 : : {
171 : : DBG_UNHANDLED_EXCEPTION();
172 : : }
173 : :
174 [ # # ]: 0 : return sal_True;
175 : : }
176 : :
177 : : //------------------------------------------------------------------------------------------------------------------
178 : 0 : PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
179 : : {
180 [ # # ]: 0 : Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
181 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
182 [ # # ]: 0 : return pos->second;
183 : : }
184 : :
185 : : //------------------------------------------------------------------------------------------------------------------
186 : 0 : Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
187 : : {
188 : 0 : const WizardState eState = getCurrentState();
189 : :
190 [ # # ][ # # ]: 0 : PWizardPageController pController( impl_getController( GetPage( eState ) ) );
191 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
192 : :
193 [ # # ]: 0 : return pController->getWizardPage();
194 : : }
195 : :
196 : : //------------------------------------------------------------------------------------------------------------------
197 : 0 : void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable )
198 : : {
199 : 0 : enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
200 : 0 : }
201 : :
202 : : //------------------------------------------------------------------------------------------------------------------
203 : 0 : TabPage* WizardShell::createPage( WizardState i_nState )
204 : : {
205 [ # # ]: 0 : ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
206 : :
207 [ # # ][ # # ]: 0 : ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
[ # # ]
208 [ # # ]: 0 : TabPage* pPage = pController->getTabPage();
209 : : OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
210 [ # # ]: 0 : if ( pPage == NULL )
211 : : {
212 : : // fallback for ill-behaved clients: empty page
213 [ # # ][ # # ]: 0 : pPage = new TabPage( this, 0 );
214 [ # # ][ # # ]: 0 : pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
[ # # ][ # # ]
215 : : }
216 : :
217 [ # # ][ # # ]: 0 : m_aPageControllers[ pPage ] = pController;
218 [ # # ]: 0 : return pPage;
219 : : }
220 : :
221 : : //------------------------------------------------------------------------------------------------------------------
222 : 0 : IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
223 : : {
224 : 0 : return impl_getController( i_pCurrentPage ).get();
225 : : }
226 : :
227 : : //------------------------------------------------------------------------------------------------------------------
228 : 0 : String WizardShell::getStateDisplayName( WizardState i_nState ) const
229 : : {
230 : : try
231 : : {
232 [ # # ]: 0 : if ( m_xController.is() )
233 [ # # ][ # # ]: 0 : return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
[ # # ][ # # ]
234 : : }
235 : 0 : catch( const Exception& )
236 : : {
237 : : DBG_UNHANDLED_EXCEPTION();
238 : : }
239 : : // fallback for ill-behaved clients: the numeric state
240 [ # # ]: 0 : return rtl::OUString::valueOf(static_cast<sal_Int32>(i_nState));
241 : : }
242 : :
243 : : //------------------------------------------------------------------------------------------------------------------
244 : 0 : bool WizardShell::canAdvance() const
245 : : {
246 : : try
247 : : {
248 [ # # ][ # # ]: 0 : if ( m_xController.is() && !m_xController->canAdvance() )
[ # # ][ # # ]
[ # # ]
249 : 0 : return false;
250 : : }
251 : 0 : catch( const Exception& )
252 : : {
253 : : DBG_UNHANDLED_EXCEPTION();
254 : : }
255 : :
256 [ # # ]: 0 : return WizardShell_Base::canAdvance();
257 : : }
258 : :
259 : : //------------------------------------------------------------------------------------------------------------------
260 : 0 : sal_Bool WizardShell::onFinish()
261 : : {
262 : : try
263 : : {
264 [ # # ][ # # ]: 0 : if ( m_xController.is() && !m_xController->confirmFinish() )
[ # # ][ # # ]
[ # # ]
265 : 0 : return sal_False;
266 : : }
267 : 0 : catch( const Exception& )
268 : : {
269 : : DBG_UNHANDLED_EXCEPTION();
270 : : }
271 : :
272 [ # # ]: 0 : return WizardShell_Base::onFinish();
273 : : }
274 : :
275 : : //......................................................................................................................
276 : : } } // namespace svt::uno
277 : : //......................................................................................................................
278 : :
279 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|