1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "precompiled_svtools.hxx" 25 26 #include "wizardshell.hxx" 27 #include "wizardpagecontroller.hxx" 28 29 #include <tools/diagnose_ex.h> 30 31 /** === begin UNO includes === **/ 32 #include <com/sun/star/ui/dialogs/WizardTravelType.hpp> 33 /** === end UNO includes === **/ 34 35 #include <vcl/msgbox.hxx> 36 37 //...................................................................................................................... 38 namespace svt { namespace uno 39 { 40 //...................................................................................................................... 41 42 /** === begin UNO using === **/ 43 using ::com::sun::star::uno::Reference; 44 using ::com::sun::star::uno::XInterface; 45 using ::com::sun::star::uno::UNO_QUERY; 46 using ::com::sun::star::uno::UNO_QUERY_THROW; 47 using ::com::sun::star::uno::UNO_SET_THROW; 48 using ::com::sun::star::uno::Exception; 49 using ::com::sun::star::uno::RuntimeException; 50 using ::com::sun::star::uno::Any; 51 using ::com::sun::star::uno::makeAny; 52 using ::com::sun::star::uno::Sequence; 53 using ::com::sun::star::uno::Type; 54 using ::com::sun::star::ui::dialogs::XWizardController; 55 using ::com::sun::star::ui::dialogs::XWizard; 56 using ::com::sun::star::ui::dialogs::XWizardPage; 57 /** === end UNO using === **/ 58 namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType; 59 60 //================================================================================================================== 61 namespace 62 { 63 //-------------------------------------------------------------------------------------------------------------- lcl_determineFirstPageID(const Sequence<Sequence<sal_Int16>> & i_rPaths)64 sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths ) 65 { 66 ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" ); 67 return i_rPaths[0][0]; 68 } 69 } 70 71 //================================================================================================================== 72 //= WizardShell 73 //================================================================================================================== 74 //------------------------------------------------------------------------------------------------------------------ WizardShell(Window * i_pParent,const Reference<XWizard> & i_rWizard,const Reference<XWizardController> & i_rController,const Sequence<Sequence<sal_Int16>> & i_rPaths)75 WizardShell::WizardShell( Window* i_pParent, const Reference< XWizard >& i_rWizard, const Reference< XWizardController >& i_rController, 76 const Sequence< Sequence< sal_Int16 > >& i_rPaths ) 77 :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE ) 78 ,m_xWizard( i_rWizard ) 79 ,m_xController( i_rController ) 80 ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) ) 81 { 82 ENSURE_OR_THROW( m_xWizard.is() && m_xController.is(), "invalid wizard/controller" ); 83 84 // declare the paths 85 for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i ) 86 { 87 const Sequence< sal_Int16 >& rPath( i_rPaths[i] ); 88 WizardPath aPath( rPath.getLength() ); 89 for ( sal_Int32 j=0; j<rPath.getLength(); ++j ) 90 aPath[j] = impl_pageIdToState( rPath[j] ); 91 declarePath( i, aPath ); 92 } 93 94 // create the first page, to know the page size 95 TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) ); 96 SetPageSizePixel( pStartPage->GetSizePixel() ); 97 98 // some defaults 99 ShowButtonFixedLine( true ); 100 SetRoadmapInteractive( true ); 101 enableAutomaticNextButtonState(); 102 } 103 104 //------------------------------------------------------------------------------------------------------------------ ~WizardShell()105 WizardShell::~WizardShell() 106 { 107 } 108 109 //------------------------------------------------------------------------------------------------------------------ Execute()110 short WizardShell::Execute() 111 { 112 ActivatePage(); 113 return WizardShell_Base::Execute(); 114 } 115 116 //------------------------------------------------------------------------------------------------------------------ convertCommitReasonToTravelType(const CommitPageReason i_eReason)117 sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason ) 118 { 119 switch ( i_eReason ) 120 { 121 case WizardTypes::eTravelForward: 122 return WizardTravelType::FORWARD; 123 124 case WizardTypes::eTravelBackward: 125 return WizardTravelType::BACKWARD; 126 127 case WizardTypes::eFinish: 128 return WizardTravelType::FINISH; 129 130 default: 131 break; 132 } 133 OSL_ENSURE( false, "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" ); 134 return WizardTravelType::FINISH; 135 } 136 137 //------------------------------------------------------------------------------------------------------------------ enterState(WizardState i_nState)138 void WizardShell::enterState( WizardState i_nState ) 139 { 140 WizardShell_Base::enterState( i_nState ); 141 142 if ( !m_xController.is() ) 143 return; 144 145 try 146 { 147 m_xController->onActivatePage( impl_stateToPageId( i_nState ) ); 148 } 149 catch( const Exception& ) 150 { 151 DBG_UNHANDLED_EXCEPTION(); 152 } 153 } 154 155 //------------------------------------------------------------------------------------------------------------------ leaveState(WizardState i_nState)156 sal_Bool WizardShell::leaveState( WizardState i_nState ) 157 { 158 if ( !WizardShell_Base::leaveState( i_nState ) ) 159 return sal_False; 160 161 if ( !m_xController.is() ) 162 return sal_True; 163 164 try 165 { 166 m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) ); 167 } 168 catch( const Exception& ) 169 { 170 DBG_UNHANDLED_EXCEPTION(); 171 } 172 173 return sal_True; 174 } 175 176 //------------------------------------------------------------------------------------------------------------------ impl_getController(TabPage * i_pPage) const177 PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const 178 { 179 Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage ); 180 ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() ); 181 return pos->second; 182 } 183 184 //------------------------------------------------------------------------------------------------------------------ getCurrentWizardPage() const185 Reference< XWizardPage > WizardShell::getCurrentWizardPage() const 186 { 187 const WizardState eState = getCurrentState(); 188 189 PWizardPageController pController( impl_getController( GetPage( eState ) ) ); 190 ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL ); 191 192 return pController->getWizardPage(); 193 } 194 195 //------------------------------------------------------------------------------------------------------------------ enablePage(const sal_Int16 i_nPageID,const sal_Bool i_bEnable)196 void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable ) 197 { 198 enableState( impl_pageIdToState( i_nPageID ), i_bEnable ); 199 } 200 201 //------------------------------------------------------------------------------------------------------------------ createPage(WizardState i_nState)202 TabPage* WizardShell::createPage( WizardState i_nState ) 203 { 204 ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL ); 205 206 ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) ); 207 TabPage* pPage = pController->getTabPage(); 208 OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" ); 209 if ( pPage == NULL ) 210 { 211 // fallback for ill-behaved clients: empty page 212 pPage = new TabPage( this, 0 ); 213 pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) ); 214 } 215 216 m_aPageControllers[ pPage ] = pController; 217 return pPage; 218 } 219 220 //------------------------------------------------------------------------------------------------------------------ getPageController(TabPage * i_pCurrentPage) const221 IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const 222 { 223 return impl_getController( i_pCurrentPage ).get(); 224 } 225 226 //------------------------------------------------------------------------------------------------------------------ getStateDisplayName(WizardState i_nState) const227 String WizardShell::getStateDisplayName( WizardState i_nState ) const 228 { 229 try 230 { 231 if ( m_xController.is() ) 232 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) ); 233 } 234 catch( const Exception& ) 235 { 236 DBG_UNHANDLED_EXCEPTION(); 237 } 238 // fallback for ill-behaved clients: the numeric state 239 return String::CreateFromInt32( i_nState ); 240 } 241 242 //------------------------------------------------------------------------------------------------------------------ canAdvance() const243 bool WizardShell::canAdvance() const 244 { 245 try 246 { 247 if ( m_xController.is() && !m_xController->canAdvance() ) 248 return false; 249 } 250 catch( const Exception& ) 251 { 252 DBG_UNHANDLED_EXCEPTION(); 253 } 254 255 return WizardShell_Base::canAdvance(); 256 } 257 258 //------------------------------------------------------------------------------------------------------------------ onFinish()259 sal_Bool WizardShell::onFinish() 260 { 261 try 262 { 263 if ( m_xController.is() && !m_xController->confirmFinish() ) 264 return sal_False; 265 } 266 catch( const Exception& ) 267 { 268 DBG_UNHANDLED_EXCEPTION(); 269 } 270 271 return WizardShell_Base::onFinish(); 272 } 273 274 //...................................................................................................................... 275 } } // namespace svt::uno 276 //...................................................................................................................... 277