merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / bibliography / formcontrolcontainer.cxx
blob5ee7511a3ba97c647697c2a66c80b83af1f32056
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formcontrolcontainer.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "formcontrolcontainer.hxx"
34 #include <tools/debug.hxx>
36 #include <algorithm>
37 #include <functional>
39 //.........................................................................
40 namespace bib
42 //.........................................................................
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::form;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::awt;
49 //=====================================================================
50 //= FormControlContainer
51 //=====================================================================
52 //---------------------------------------------------------------------
53 FormControlContainer::FormControlContainer( )
54 :OLoadListener( m_aMutex )
55 ,m_pFormAdapter( NULL )
59 //---------------------------------------------------------------------
60 //--- 18.10.01 18:54:57 -----------------------------------------------
61 FormControlContainer::~FormControlContainer( )
63 DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
64 if ( isFormConnected() )
65 disconnectForm();
68 //---------------------------------------------------------------------
69 //--- 18.10.01 17:03:14 -----------------------------------------------
70 void FormControlContainer::disconnectForm()
72 ::osl::MutexGuard aGuard( m_aMutex );
73 DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" );
74 if ( isFormConnected() )
76 m_pFormAdapter->dispose();
77 m_pFormAdapter->release();
78 m_pFormAdapter = NULL;
82 //---------------------------------------------------------------------
83 //--- 18.10.01 16:56:01 -----------------------------------------------
84 void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm )
86 DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" );
88 DBG_ASSERT( _rxForm.is(), "FormControlContainer::connectForm: invalid form!" );
89 if ( !isFormConnected() && _rxForm.is() )
91 m_pFormAdapter = new OLoadListenerAdapter( _rxForm );
92 m_pFormAdapter->acquire();
93 m_pFormAdapter->Init( this );
95 ensureDesignMode();
98 m_xForm = _rxForm;
101 //---------------------------------------------------------------------
102 //--- 18.10.01 18:50:14 -----------------------------------------------
103 struct ControlModeSwitch : public ::std::unary_function< Reference< XControl >, void >
105 sal_Bool bDesign;
106 ControlModeSwitch( sal_Bool _bDesign ) : bDesign( _bDesign ) { }
108 void operator() ( const Reference< XControl >& _rxControl ) const
110 if ( _rxControl.is() )
111 _rxControl->setDesignMode( bDesign );
115 //---------------------------------------------------------------------
116 //--- 18.10.01 18:49:57 -----------------------------------------------
117 void FormControlContainer::implSetDesignMode( sal_Bool _bDesign )
121 Reference< XControlContainer > xControlCont = getControlContainer();
122 Sequence< Reference< XControl > > aControls;
123 if ( xControlCont.is() )
124 aControls = xControlCont->getControls();
126 ::std::for_each(
127 aControls.getConstArray(),
128 aControls.getConstArray() + aControls.getLength(),
129 ControlModeSwitch( _bDesign )
132 catch( const Exception& e)
134 (void) e; // make compiler happy
135 DBG_ERROR( "FormControlContainer::implSetDesignMode: caught an exception!" );
139 //---------------------------------------------------------------------
140 //--- 18.10.01 18:16:54 -----------------------------------------------
141 void FormControlContainer::ensureDesignMode()
143 implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() );
146 //---------------------------------------------------------------------
147 //--- 18.10.01 16:45:33 -----------------------------------------------
148 void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
150 implSetDesignMode( sal_False );
153 //---------------------------------------------------------------------
154 //--- 18.10.01 16:45:35 -----------------------------------------------
155 void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
157 implSetDesignMode( sal_True );
160 //---------------------------------------------------------------------
161 //--- 18.10.01 16:45:36 -----------------------------------------------
162 void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
166 //---------------------------------------------------------------------
167 //--- 18.10.01 16:45:36 -----------------------------------------------
168 void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
170 implSetDesignMode( sal_True );
173 //---------------------------------------------------------------------
174 //--- 18.10.01 16:45:37 -----------------------------------------------
175 void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
177 implSetDesignMode( sal_False );
180 //.........................................................................
181 } // namespace bib
182 //.........................................................................