1 /************************************************************************* 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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_extensions.hxx" 30 #include "formcontrolcontainer.hxx" 31 #include <tools/debug.hxx> 32 33 #include <algorithm> 34 #include <functional> 35 36 //......................................................................... 37 namespace bib 38 { 39 //......................................................................... 40 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::form; 43 using namespace ::com::sun::star::lang; 44 using namespace ::com::sun::star::awt; 45 46 //===================================================================== 47 //= FormControlContainer 48 //===================================================================== 49 //--------------------------------------------------------------------- 50 FormControlContainer::FormControlContainer( ) 51 :OLoadListener( m_aMutex ) 52 ,m_pFormAdapter( NULL ) 53 { 54 } 55 56 //--------------------------------------------------------------------- 57 //--- 18.10.01 18:54:57 ----------------------------------------------- 58 FormControlContainer::~FormControlContainer( ) 59 { 60 DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" ); 61 if ( isFormConnected() ) 62 disconnectForm(); 63 } 64 65 //--------------------------------------------------------------------- 66 //--- 18.10.01 17:03:14 ----------------------------------------------- 67 void FormControlContainer::disconnectForm() 68 { 69 ::osl::MutexGuard aGuard( m_aMutex ); 70 DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" ); 71 if ( isFormConnected() ) 72 { 73 m_pFormAdapter->dispose(); 74 m_pFormAdapter->release(); 75 m_pFormAdapter = NULL; 76 } 77 } 78 79 //--------------------------------------------------------------------- 80 //--- 18.10.01 16:56:01 ----------------------------------------------- 81 void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm ) 82 { 83 DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" ); 84 85 DBG_ASSERT( _rxForm.is(), "FormControlContainer::connectForm: invalid form!" ); 86 if ( !isFormConnected() && _rxForm.is() ) 87 { 88 m_pFormAdapter = new OLoadListenerAdapter( _rxForm ); 89 m_pFormAdapter->acquire(); 90 m_pFormAdapter->Init( this ); 91 92 ensureDesignMode(); 93 } 94 95 m_xForm = _rxForm; 96 } 97 98 //--------------------------------------------------------------------- 99 //--- 18.10.01 18:50:14 ----------------------------------------------- 100 struct ControlModeSwitch : public ::std::unary_function< Reference< XControl >, void > 101 { 102 sal_Bool bDesign; 103 ControlModeSwitch( sal_Bool _bDesign ) : bDesign( _bDesign ) { } 104 105 void operator() ( const Reference< XControl >& _rxControl ) const 106 { 107 if ( _rxControl.is() ) 108 _rxControl->setDesignMode( bDesign ); 109 } 110 }; 111 112 //--------------------------------------------------------------------- 113 //--- 18.10.01 18:49:57 ----------------------------------------------- 114 void FormControlContainer::implSetDesignMode( sal_Bool _bDesign ) 115 { 116 try 117 { 118 Reference< XControlContainer > xControlCont = getControlContainer(); 119 Sequence< Reference< XControl > > aControls; 120 if ( xControlCont.is() ) 121 aControls = xControlCont->getControls(); 122 123 ::std::for_each( 124 aControls.getConstArray(), 125 aControls.getConstArray() + aControls.getLength(), 126 ControlModeSwitch( _bDesign ) 127 ); 128 } 129 catch( const Exception& e) 130 { 131 (void) e; // make compiler happy 132 DBG_ERROR( "FormControlContainer::implSetDesignMode: caught an exception!" ); 133 } 134 } 135 136 //--------------------------------------------------------------------- 137 //--- 18.10.01 18:16:54 ----------------------------------------------- 138 void FormControlContainer::ensureDesignMode() 139 { 140 implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() ); 141 } 142 143 //--------------------------------------------------------------------- 144 //--- 18.10.01 16:45:33 ----------------------------------------------- 145 void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 146 { 147 implSetDesignMode( sal_False ); 148 } 149 150 //--------------------------------------------------------------------- 151 //--- 18.10.01 16:45:35 ----------------------------------------------- 152 void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 153 { 154 implSetDesignMode( sal_True ); 155 } 156 157 //--------------------------------------------------------------------- 158 //--- 18.10.01 16:45:36 ----------------------------------------------- 159 void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 160 { 161 } 162 163 //--------------------------------------------------------------------- 164 //--- 18.10.01 16:45:36 ----------------------------------------------- 165 void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 166 { 167 implSetDesignMode( sal_True ); 168 } 169 170 //--------------------------------------------------------------------- 171 //--- 18.10.01 16:45:37 ----------------------------------------------- 172 void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 173 { 174 implSetDesignMode( sal_False ); 175 } 176 177 //......................................................................... 178 } // namespace bib 179 //......................................................................... 180 181