1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove 25*b1cdbd2cSJim Jagielski #include "precompiled_extensions.hxx" 26*b1cdbd2cSJim Jagielski #include "formcontrolcontainer.hxx" 27*b1cdbd2cSJim Jagielski #include <tools/debug.hxx> 28*b1cdbd2cSJim Jagielski 29*b1cdbd2cSJim Jagielski #include <algorithm> 30*b1cdbd2cSJim Jagielski #include <functional> 31*b1cdbd2cSJim Jagielski 32*b1cdbd2cSJim Jagielski //......................................................................... 33*b1cdbd2cSJim Jagielski namespace bib 34*b1cdbd2cSJim Jagielski { 35*b1cdbd2cSJim Jagielski //......................................................................... 36*b1cdbd2cSJim Jagielski 37*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::uno; 38*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::form; 39*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::lang; 40*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::awt; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski //===================================================================== 43*b1cdbd2cSJim Jagielski //= FormControlContainer 44*b1cdbd2cSJim Jagielski //===================================================================== 45*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- FormControlContainer()46*b1cdbd2cSJim Jagielski FormControlContainer::FormControlContainer( ) 47*b1cdbd2cSJim Jagielski :OLoadListener( m_aMutex ) 48*b1cdbd2cSJim Jagielski ,m_pFormAdapter( NULL ) 49*b1cdbd2cSJim Jagielski { 50*b1cdbd2cSJim Jagielski } 51*b1cdbd2cSJim Jagielski 52*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 53*b1cdbd2cSJim Jagielski //--- 18.10.01 18:54:57 ----------------------------------------------- ~FormControlContainer()54*b1cdbd2cSJim Jagielski FormControlContainer::~FormControlContainer( ) 55*b1cdbd2cSJim Jagielski { 56*b1cdbd2cSJim Jagielski DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" ); 57*b1cdbd2cSJim Jagielski if ( isFormConnected() ) 58*b1cdbd2cSJim Jagielski disconnectForm(); 59*b1cdbd2cSJim Jagielski } 60*b1cdbd2cSJim Jagielski 61*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 62*b1cdbd2cSJim Jagielski //--- 18.10.01 17:03:14 ----------------------------------------------- disconnectForm()63*b1cdbd2cSJim Jagielski void FormControlContainer::disconnectForm() 64*b1cdbd2cSJim Jagielski { 65*b1cdbd2cSJim Jagielski ::osl::MutexGuard aGuard( m_aMutex ); 66*b1cdbd2cSJim Jagielski DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" ); 67*b1cdbd2cSJim Jagielski if ( isFormConnected() ) 68*b1cdbd2cSJim Jagielski { 69*b1cdbd2cSJim Jagielski m_pFormAdapter->dispose(); 70*b1cdbd2cSJim Jagielski m_pFormAdapter->release(); 71*b1cdbd2cSJim Jagielski m_pFormAdapter = NULL; 72*b1cdbd2cSJim Jagielski } 73*b1cdbd2cSJim Jagielski } 74*b1cdbd2cSJim Jagielski 75*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 76*b1cdbd2cSJim Jagielski //--- 18.10.01 16:56:01 ----------------------------------------------- connectForm(const Reference<XLoadable> & _rxForm)77*b1cdbd2cSJim Jagielski void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm ) 78*b1cdbd2cSJim Jagielski { 79*b1cdbd2cSJim Jagielski DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" ); 80*b1cdbd2cSJim Jagielski 81*b1cdbd2cSJim Jagielski DBG_ASSERT( _rxForm.is(), "FormControlContainer::connectForm: invalid form!" ); 82*b1cdbd2cSJim Jagielski if ( !isFormConnected() && _rxForm.is() ) 83*b1cdbd2cSJim Jagielski { 84*b1cdbd2cSJim Jagielski m_pFormAdapter = new OLoadListenerAdapter( _rxForm ); 85*b1cdbd2cSJim Jagielski m_pFormAdapter->acquire(); 86*b1cdbd2cSJim Jagielski m_pFormAdapter->Init( this ); 87*b1cdbd2cSJim Jagielski 88*b1cdbd2cSJim Jagielski ensureDesignMode(); 89*b1cdbd2cSJim Jagielski } 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski m_xForm = _rxForm; 92*b1cdbd2cSJim Jagielski } 93*b1cdbd2cSJim Jagielski 94*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 95*b1cdbd2cSJim Jagielski //--- 18.10.01 18:50:14 ----------------------------------------------- 96*b1cdbd2cSJim Jagielski struct ControlModeSwitch : public ::std::unary_function< Reference< XControl >, void > 97*b1cdbd2cSJim Jagielski { 98*b1cdbd2cSJim Jagielski sal_Bool bDesign; ControlModeSwitchbib::ControlModeSwitch99*b1cdbd2cSJim Jagielski ControlModeSwitch( sal_Bool _bDesign ) : bDesign( _bDesign ) { } 100*b1cdbd2cSJim Jagielski operator ()bib::ControlModeSwitch101*b1cdbd2cSJim Jagielski void operator() ( const Reference< XControl >& _rxControl ) const 102*b1cdbd2cSJim Jagielski { 103*b1cdbd2cSJim Jagielski if ( _rxControl.is() ) 104*b1cdbd2cSJim Jagielski _rxControl->setDesignMode( bDesign ); 105*b1cdbd2cSJim Jagielski } 106*b1cdbd2cSJim Jagielski }; 107*b1cdbd2cSJim Jagielski 108*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 109*b1cdbd2cSJim Jagielski //--- 18.10.01 18:49:57 ----------------------------------------------- implSetDesignMode(sal_Bool _bDesign)110*b1cdbd2cSJim Jagielski void FormControlContainer::implSetDesignMode( sal_Bool _bDesign ) 111*b1cdbd2cSJim Jagielski { 112*b1cdbd2cSJim Jagielski try 113*b1cdbd2cSJim Jagielski { 114*b1cdbd2cSJim Jagielski Reference< XControlContainer > xControlCont = getControlContainer(); 115*b1cdbd2cSJim Jagielski Sequence< Reference< XControl > > aControls; 116*b1cdbd2cSJim Jagielski if ( xControlCont.is() ) 117*b1cdbd2cSJim Jagielski aControls = xControlCont->getControls(); 118*b1cdbd2cSJim Jagielski 119*b1cdbd2cSJim Jagielski ::std::for_each( 120*b1cdbd2cSJim Jagielski aControls.getConstArray(), 121*b1cdbd2cSJim Jagielski aControls.getConstArray() + aControls.getLength(), 122*b1cdbd2cSJim Jagielski ControlModeSwitch( _bDesign ) 123*b1cdbd2cSJim Jagielski ); 124*b1cdbd2cSJim Jagielski } 125*b1cdbd2cSJim Jagielski catch( const Exception& e) 126*b1cdbd2cSJim Jagielski { 127*b1cdbd2cSJim Jagielski (void) e; // make compiler happy 128*b1cdbd2cSJim Jagielski DBG_ERROR( "FormControlContainer::implSetDesignMode: caught an exception!" ); 129*b1cdbd2cSJim Jagielski } 130*b1cdbd2cSJim Jagielski } 131*b1cdbd2cSJim Jagielski 132*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 133*b1cdbd2cSJim Jagielski //--- 18.10.01 18:16:54 ----------------------------------------------- ensureDesignMode()134*b1cdbd2cSJim Jagielski void FormControlContainer::ensureDesignMode() 135*b1cdbd2cSJim Jagielski { 136*b1cdbd2cSJim Jagielski implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() ); 137*b1cdbd2cSJim Jagielski } 138*b1cdbd2cSJim Jagielski 139*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 140*b1cdbd2cSJim Jagielski //--- 18.10.01 16:45:33 ----------------------------------------------- _loaded(const::com::sun::star::lang::EventObject &)141*b1cdbd2cSJim Jagielski void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 142*b1cdbd2cSJim Jagielski { 143*b1cdbd2cSJim Jagielski implSetDesignMode( sal_False ); 144*b1cdbd2cSJim Jagielski } 145*b1cdbd2cSJim Jagielski 146*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 147*b1cdbd2cSJim Jagielski //--- 18.10.01 16:45:35 ----------------------------------------------- _unloading(const::com::sun::star::lang::EventObject &)148*b1cdbd2cSJim Jagielski void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 149*b1cdbd2cSJim Jagielski { 150*b1cdbd2cSJim Jagielski implSetDesignMode( sal_True ); 151*b1cdbd2cSJim Jagielski } 152*b1cdbd2cSJim Jagielski 153*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 154*b1cdbd2cSJim Jagielski //--- 18.10.01 16:45:36 ----------------------------------------------- _unloaded(const::com::sun::star::lang::EventObject &)155*b1cdbd2cSJim Jagielski void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 156*b1cdbd2cSJim Jagielski { 157*b1cdbd2cSJim Jagielski } 158*b1cdbd2cSJim Jagielski 159*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 160*b1cdbd2cSJim Jagielski //--- 18.10.01 16:45:36 ----------------------------------------------- _reloading(const::com::sun::star::lang::EventObject &)161*b1cdbd2cSJim Jagielski void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 162*b1cdbd2cSJim Jagielski { 163*b1cdbd2cSJim Jagielski implSetDesignMode( sal_True ); 164*b1cdbd2cSJim Jagielski } 165*b1cdbd2cSJim Jagielski 166*b1cdbd2cSJim Jagielski //--------------------------------------------------------------------- 167*b1cdbd2cSJim Jagielski //--- 18.10.01 16:45:37 ----------------------------------------------- _reloaded(const::com::sun::star::lang::EventObject &)168*b1cdbd2cSJim Jagielski void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ ) 169*b1cdbd2cSJim Jagielski { 170*b1cdbd2cSJim Jagielski implSetDesignMode( sal_False ); 171*b1cdbd2cSJim Jagielski } 172*b1cdbd2cSJim Jagielski 173*b1cdbd2cSJim Jagielski //......................................................................... 174*b1cdbd2cSJim Jagielski } // namespace bib 175*b1cdbd2cSJim Jagielski //......................................................................... 176*b1cdbd2cSJim Jagielski 177