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<XWizardController> & i_rController,const Sequence<Sequence<sal_Int16>> & i_rPaths)75 WizardShell::WizardShell( Window* i_pParent, const Reference< XWizardController >& i_rController, 76 const Sequence< Sequence< sal_Int16 > >& i_rPaths ) 77 :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE ) 78 ,m_xController( i_rController ) 79 ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) ) 80 { 81 ENSURE_OR_THROW( m_xController.is(), "invalid controller" ); 82 83 // declare the paths 84 for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i ) 85 { 86 const Sequence< sal_Int16 >& rPath( i_rPaths[i] ); 87 WizardPath aPath( rPath.getLength() ); 88 for ( sal_Int32 j=0; j<rPath.getLength(); ++j ) 89 aPath[j] = impl_pageIdToState( rPath[j] ); 90 declarePath( i, aPath ); 91 } 92 93 // create the first page, to know the page size 94 TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) ); 95 SetPageSizePixel( pStartPage->GetSizePixel() ); 96 97 // some defaults 98 ShowButtonFixedLine( true ); 99 SetRoadmapInteractive( true ); 100 enableAutomaticNextButtonState(); 101 } 102 103 //------------------------------------------------------------------------------------------------------------------ ~WizardShell()104 WizardShell::~WizardShell() 105 { 106 } 107 108 //------------------------------------------------------------------------------------------------------------------ Execute()109 short WizardShell::Execute() 110 { 111 ActivatePage(); 112 return WizardShell_Base::Execute(); 113 } 114 115 //------------------------------------------------------------------------------------------------------------------ convertCommitReasonToTravelType(const CommitPageReason i_eReason)116 sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason ) 117 { 118 switch ( i_eReason ) 119 { 120 case WizardTypes::eTravelForward: 121 return WizardTravelType::FORWARD; 122 123 case WizardTypes::eTravelBackward: 124 return WizardTravelType::BACKWARD; 125 126 case WizardTypes::eFinish: 127 return WizardTravelType::FINISH; 128 129 default: 130 break; 131 } 132 OSL_ENSURE( false, "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" ); 133 return WizardTravelType::FINISH; 134 } 135 136 //------------------------------------------------------------------------------------------------------------------ enterState(WizardState i_nState)137 void WizardShell::enterState( WizardState i_nState ) 138 { 139 WizardShell_Base::enterState( i_nState ); 140 141 if ( !m_xController.is() ) 142 return; 143 144 try 145 { 146 m_xController->onActivatePage( impl_stateToPageId( i_nState ) ); 147 } 148 catch( const Exception& ) 149 { 150 DBG_UNHANDLED_EXCEPTION(); 151 } 152 } 153 154 //------------------------------------------------------------------------------------------------------------------ leaveState(WizardState i_nState)155 sal_Bool WizardShell::leaveState( WizardState i_nState ) 156 { 157 if ( !WizardShell_Base::leaveState( i_nState ) ) 158 return sal_False; 159 160 if ( !m_xController.is() ) 161 return sal_True; 162 163 try 164 { 165 m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) ); 166 } 167 catch( const Exception& ) 168 { 169 DBG_UNHANDLED_EXCEPTION(); 170 } 171 172 return sal_True; 173 } 174 175 //------------------------------------------------------------------------------------------------------------------ impl_getController(TabPage * i_pPage) const176 PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const 177 { 178 Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage ); 179 ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() ); 180 return pos->second; 181 } 182 183 //------------------------------------------------------------------------------------------------------------------ getCurrentWizardPage() const184 Reference< XWizardPage > WizardShell::getCurrentWizardPage() const 185 { 186 const WizardState eState = getCurrentState(); 187 188 PWizardPageController pController( impl_getController( GetPage( eState ) ) ); 189 ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL ); 190 191 return pController->getWizardPage(); 192 } 193 194 //------------------------------------------------------------------------------------------------------------------ enablePage(const sal_Int16 i_nPageID,const sal_Bool i_bEnable)195 void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable ) 196 { 197 enableState( impl_pageIdToState( i_nPageID ), i_bEnable ); 198 } 199 200 //------------------------------------------------------------------------------------------------------------------ createPage(WizardState i_nState)201 TabPage* WizardShell::createPage( WizardState i_nState ) 202 { 203 ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL ); 204 205 ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) ); 206 TabPage* pPage = pController->getTabPage(); 207 OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" ); 208 if ( pPage == NULL ) 209 { 210 // fallback for ill-behaved clients: empty page 211 pPage = new TabPage( this, 0 ); 212 pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) ); 213 } 214 215 m_aPageControllers[ pPage ] = pController; 216 return pPage; 217 } 218 219 //------------------------------------------------------------------------------------------------------------------ getPageController(TabPage * i_pCurrentPage) const220 IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const 221 { 222 return impl_getController( i_pCurrentPage ).get(); 223 } 224 225 //------------------------------------------------------------------------------------------------------------------ getStateDisplayName(WizardState i_nState) const226 String WizardShell::getStateDisplayName( WizardState i_nState ) const 227 { 228 try 229 { 230 if ( m_xController.is() ) 231 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) ); 232 } 233 catch( const Exception& ) 234 { 235 DBG_UNHANDLED_EXCEPTION(); 236 } 237 // fallback for ill-behaved clients: the numeric state 238 return String::CreateFromInt32( i_nState ); 239 } 240 241 //------------------------------------------------------------------------------------------------------------------ canAdvance() const242 bool WizardShell::canAdvance() const 243 { 244 try 245 { 246 if ( m_xController.is() && !m_xController->canAdvance() ) 247 return false; 248 } 249 catch( const Exception& ) 250 { 251 DBG_UNHANDLED_EXCEPTION(); 252 } 253 254 return WizardShell_Base::canAdvance(); 255 } 256 257 //------------------------------------------------------------------------------------------------------------------ onFinish()258 sal_Bool WizardShell::onFinish() 259 { 260 try 261 { 262 if ( m_xController.is() && !m_xController->confirmFinish() ) 263 return sal_False; 264 } 265 catch( const Exception& ) 266 { 267 DBG_UNHANDLED_EXCEPTION(); 268 } 269 270 return WizardShell_Base::onFinish(); 271 } 272 273 //...................................................................................................................... 274 } } // namespace svt::uno 275 //...................................................................................................................... 276