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