1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 * 25 ************************************************************************/ 26 27 #include "precompiled_svtools.hxx" 28 29 #include "wizardpagecontroller.hxx" 30 #include "wizardshell.hxx" 31 32 /** === begin UNO includes === **/ 33 #include <com/sun/star/lang/XComponent.hpp> 34 #include <com/sun/star/awt/XControl.hpp> 35 /** === end UNO includes === **/ 36 37 #include <toolkit/helper/vclunohelper.hxx> 38 #include <tools/diagnose_ex.h> 39 40 //...................................................................................................................... 41 namespace svt { namespace uno 42 { 43 //...................................................................................................................... 44 45 /** === begin UNO using === **/ 46 using ::com::sun::star::uno::Reference; 47 using ::com::sun::star::uno::XInterface; 48 using ::com::sun::star::uno::UNO_QUERY; 49 using ::com::sun::star::uno::UNO_QUERY_THROW; 50 using ::com::sun::star::uno::UNO_SET_THROW; 51 using ::com::sun::star::uno::Exception; 52 using ::com::sun::star::uno::RuntimeException; 53 using ::com::sun::star::uno::Any; 54 using ::com::sun::star::uno::makeAny; 55 using ::com::sun::star::uno::Sequence; 56 using ::com::sun::star::uno::Type; 57 using ::com::sun::star::ui::dialogs::XWizardController; 58 using ::com::sun::star::awt::XWindow; 59 using ::com::sun::star::lang::XComponent; 60 using ::com::sun::star::awt::XControl; 61 /** === end UNO using === **/ 62 using namespace ::com::sun::star; 63 64 //================================================================================================================== 65 //= WizardPageController 66 //================================================================================================================== 67 //------------------------------------------------------------------------------------------------------------------ 68 WizardPageController::WizardPageController( WizardShell& i_rParent, const Reference< XWizardController >& i_rController, 69 const sal_Int16 i_nPageId ) 70 :m_xController( i_rController ) 71 ,m_xWizardPage() 72 ,m_nPageId( i_nPageId ) 73 { 74 ENSURE_OR_THROW( m_xController.is(), "no controller" ); 75 try 76 { 77 m_xWizardPage.set( m_xController->createPage( 78 Reference< XWindow >( i_rParent.GetComponentInterface( sal_True ), UNO_QUERY_THROW ), 79 m_nPageId 80 ), UNO_SET_THROW ); 81 82 Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW ); 83 xPageWindow->setVisible( sal_True ); 84 85 TabPage* pTabPage( getTabPage() ); 86 if ( pTabPage ) 87 pTabPage->SetStyle( pTabPage->GetStyle() | WB_CHILDDLGCTRL | WB_DIALOGCONTROL ); 88 } 89 catch( const Exception& ) 90 { 91 DBG_UNHANDLED_EXCEPTION(); 92 } 93 } 94 95 //------------------------------------------------------------------------------------------------------------------ 96 WizardPageController::~WizardPageController() 97 { 98 try 99 { 100 if ( m_xWizardPage.is() ) 101 m_xWizardPage->dispose(); 102 } 103 catch( const Exception& ) 104 { 105 DBG_UNHANDLED_EXCEPTION(); 106 } 107 } 108 109 //------------------------------------------------------------------------------------------------------------------ 110 TabPage* WizardPageController::getTabPage() const 111 { 112 ENSURE_OR_RETURN( m_xWizardPage.is(), "WizardPageController::getTabPage: no external wizard page!", NULL ); 113 try 114 { 115 Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW ); 116 Window* pPageWindow = VCLUnoHelper::GetWindow( xPageWindow ); 117 if ( pPageWindow == NULL ) 118 { 119 // windows created via the XContainerWindowProvider might be controls, not real windows, so resolve 120 // that one indirection 121 const Reference< XControl > xPageControl( m_xWizardPage->getWindow(), UNO_QUERY_THROW ); 122 xPageWindow.set( xPageControl->getPeer(), UNO_QUERY_THROW ); 123 pPageWindow = VCLUnoHelper::GetWindow( xPageWindow ); 124 } 125 126 OSL_ENSURE( pPageWindow != NULL, "WizardPageController::getTabPage: unable to find the Window implementation for the page's window!" ); 127 return dynamic_cast< TabPage* >( pPageWindow ); 128 } 129 catch( const Exception& ) 130 { 131 DBG_UNHANDLED_EXCEPTION(); 132 } 133 return NULL; 134 } 135 136 //------------------------------------------------------------------------------------------------------------------ 137 void WizardPageController::initializePage() 138 { 139 if ( !m_xWizardPage.is() ) 140 return; 141 142 try 143 { 144 m_xWizardPage->activatePage(); 145 } 146 catch( const Exception& ) 147 { 148 DBG_UNHANDLED_EXCEPTION(); 149 } 150 } 151 152 //------------------------------------------------------------------------------------------------------------------ 153 sal_Bool WizardPageController::commitPage( WizardTypes::CommitPageReason i_eReason ) 154 { 155 if ( !m_xWizardPage.is() ) 156 return sal_True; 157 158 try 159 { 160 return m_xWizardPage->commitPage( WizardShell::convertCommitReasonToTravelType( i_eReason ) ); 161 } 162 catch( const Exception& ) 163 { 164 DBG_UNHANDLED_EXCEPTION(); 165 } 166 167 return sal_True; 168 } 169 170 //------------------------------------------------------------------------------------------------------------------ 171 bool WizardPageController::canAdvance() const 172 { 173 if ( !m_xWizardPage.is() ) 174 return true; 175 176 try 177 { 178 return m_xWizardPage->canAdvance(); 179 } 180 catch( const Exception& ) 181 { 182 DBG_UNHANDLED_EXCEPTION(); 183 } 184 185 return true; 186 } 187 188 //...................................................................................................................... 189 } } // namespace svt::uno 190 //...................................................................................................................... 191