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