xref: /aoo42x/main/forms/source/component/File.cxx (revision 24acc546)
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_forms.hxx"
26 
27 
28 #include "File.hxx"
29 
30 #include <com/sun/star/form/FormComponentType.hpp>
31 
32 #ifndef _FRM_PROPERTY_HRC_
33 #include "property.hrc"
34 #endif
35 #include "services.hxx"
36 #include <tools/debug.hxx>
37 #include <comphelper/container.hxx>
38 #include <comphelper/basicio.hxx>
39 #include <comphelper/guarding.hxx>
40 
41 //.........................................................................
42 namespace frm
43 {
44 //.........................................................................
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::sdb;
47 using namespace ::com::sun::star::sdbc;
48 using namespace ::com::sun::star::sdbcx;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::form;
52 using namespace ::com::sun::star::awt;
53 using namespace ::com::sun::star::io;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::util;
56 
57 //------------------------------------------------------------------
OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)58 InterfaceRef SAL_CALL OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
59 {
60 	return *(new OFileControlModel(_rxFactory));
61 }
62 
63 //------------------------------------------------------------------------------
_getTypes()64 Sequence<Type> OFileControlModel::_getTypes()
65 {
66 	static Sequence<Type> aTypes;
67 	if (!aTypes.getLength())
68 	{
69 		// my base class
70 		Sequence<Type> aBaseClassTypes = OControlModel::_getTypes();
71 
72 		Sequence<Type> aOwnTypes(1);
73 		Type* pOwnTypes = aOwnTypes.getArray();
74 		pOwnTypes[0] = getCppuType((Reference<XReset>*)NULL);
75 
76 		aTypes = concatSequences(aBaseClassTypes, aOwnTypes);
77 	}
78 	return aTypes;
79 }
80 
81 
82 // XServiceInfo
83 //------------------------------------------------------------------------------
getSupportedServiceNames()84 StringSequence	OFileControlModel::getSupportedServiceNames() throw(RuntimeException)
85 {
86 	StringSequence aSupported = OControlModel::getSupportedServiceNames();
87 	aSupported.realloc(aSupported.getLength() + 1);
88 
89 	::rtl::OUString*pArray = aSupported.getArray();
90 	pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_FILECONTROL;
91 	return aSupported;
92 }
93 
94 //------------------------------------------------------------------
DBG_NAME(OFileControlModel)95 DBG_NAME( OFileControlModel )
96 //------------------------------------------------------------------
97 OFileControlModel::OFileControlModel(const Reference<XMultiServiceFactory>& _rxFactory)
98 					:OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
99 					,m_aResetListeners(m_aMutex)
100 {
101 	DBG_CTOR( OFileControlModel, NULL );
102 	m_nClassId = FormComponentType::FILECONTROL;
103 }
104 
105 //------------------------------------------------------------------
OFileControlModel(const OFileControlModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)106 OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
107 	:OControlModel( _pOriginal, _rxFactory )
108 	,m_aResetListeners( m_aMutex )
109 {
110 	DBG_CTOR( OFileControlModel, NULL );
111 
112 	m_sDefaultValue = _pOriginal->m_sDefaultValue;
113 }
114 
115 //------------------------------------------------------------------
~OFileControlModel()116 OFileControlModel::~OFileControlModel()
117 {
118 	if (!OComponentHelper::rBHelper.bDisposed)
119 	{
120 		acquire();
121 		dispose();
122 	}
123 	DBG_DTOR( OFileControlModel, NULL );
124 }
125 
126 //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OFileControlModel)127 IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
128 
129 //------------------------------------------------------------------------------
130 Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType) throw (RuntimeException)
131 {
132 	Any aReturn = OControlModel::queryAggregation(_rType);
133 	if (!aReturn.hasValue())
134 		aReturn = ::cppu::queryInterface(_rType
135 			,static_cast<XReset*>(this)
136 		);
137 
138 	return aReturn;
139 }
140 
141 // OComponentHelper
142 //-----------------------------------------------------------------------------
disposing()143 void OFileControlModel::disposing()
144 {
145 	OControlModel::disposing();
146 
147 	EventObject aEvt(static_cast<XWeak*>(this));
148 	m_aResetListeners.disposeAndClear(aEvt);
149 }
150 
151 //------------------------------------------------------------------------------
getPropertyDefaultByHandle(sal_Int32 _nHandle) const152 Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
153 {
154 	Any aReturn;
155 	switch ( _nHandle )
156 	{
157         case PROPERTY_ID_DEFAULT_TEXT:
158             return makeAny( ::rtl::OUString() );
159     }
160 	return OControlModel::getPropertyDefaultByHandle( _nHandle );
161 }
162 
163 //------------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const164 void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
165 {
166 	switch (nHandle)
167 	{
168 		case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
169 		default:
170 			OControlModel::getFastPropertyValue(rValue, nHandle);
171 	}
172 }
173 
174 //------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)175 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception)
176 {
177 	switch (nHandle)
178 	{
179 		case PROPERTY_ID_DEFAULT_TEXT :
180 			DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
181 			rValue >>= m_sDefaultValue;
182 			break;
183 		default:
184 			OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
185 	}
186 }
187 
188 //------------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)189 sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
190 							throw( IllegalArgumentException )
191 {
192 	switch (nHandle)
193 	{
194 		case PROPERTY_ID_DEFAULT_TEXT :
195 			return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
196 		default:
197 			return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
198 	}
199 }
200 
201 //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const202 void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
203 {
204 	BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
205 		DECL_PROP1(DEFAULT_TEXT,	::rtl::OUString,	BOUND);
206 		DECL_PROP1(TABINDEX,		sal_Int16,			BOUND);
207 	END_DESCRIBE_PROPERTIES();
208 }
209 
210 //------------------------------------------------------------------------------
getServiceName()211 ::rtl::OUString SAL_CALL OFileControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
212 {
213 	return FRM_COMPONENT_FILECONTROL;	// old (non-sun) name for compatibility !
214 }
215 
216 //------------------------------------------------------------------------------
write(const Reference<stario::XObjectOutputStream> & _rxOutStream)217 void OFileControlModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
218 {
219 	OControlModel::write(_rxOutStream);
220 
221 	::osl::MutexGuard aGuard(m_aMutex);
222 
223 	// Version
224 	_rxOutStream->writeShort(0x0002);
225 	// Default-Wert
226 	_rxOutStream << m_sDefaultValue;
227 	writeHelpTextCompatibly(_rxOutStream);
228 }
229 
230 //------------------------------------------------------------------------------
read(const Reference<stario::XObjectInputStream> & _rxInStream)231 void OFileControlModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
232 {
233 	OControlModel::read(_rxInStream);
234 	::osl::MutexGuard aGuard(m_aMutex);
235 
236 	// Version
237 	sal_uInt16 nVersion = _rxInStream->readShort();
238 	// Default-Wert
239 	switch (nVersion)
240 	{
241 		case 1:
242 			_rxInStream >> m_sDefaultValue; break;
243 		case 2:
244 			_rxInStream >> m_sDefaultValue;
245 			readHelpTextCompatibly(_rxInStream);
246 			break;
247 		default:
248 			DBG_ERROR("OFileControlModel::read : unknown version !");
249 			m_sDefaultValue = ::rtl::OUString();
250 	}
251 
252 	// Nach dem Lesen die Defaultwerte anzeigen
253 //	_reset();
254 }
255 
256 //-----------------------------------------------------------------------------
reset()257 void SAL_CALL OFileControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException)
258 {
259 	::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
260 	EventObject aEvt(static_cast<XWeak*>(this));
261 	sal_Bool bContinue = sal_True;
262 	while (aIter.hasMoreElements() && bContinue)
263 		bContinue =((XResetListener*)aIter.next())->approveReset(aEvt);
264 
265 	if (bContinue)
266 	{
267 		{
268 			// Wenn Models threadSave
269 			::osl::MutexGuard aGuard(m_aMutex);
270 			_reset();
271 		}
272         m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
273 	}
274 }
275 
276 //-----------------------------------------------------------------------------
addResetListener(const Reference<XResetListener> & _rxListener)277 void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
278 {
279 	m_aResetListeners.addInterface(_rxListener);
280 }
281 
282 //-----------------------------------------------------------------------------
removeResetListener(const Reference<XResetListener> & _rxListener)283 void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
284 {
285 	m_aResetListeners.removeInterface(_rxListener);
286 }
287 
288 //------------------------------------------------------------------------------
_reset()289 void OFileControlModel::_reset()
290 {
291 	{	// release our mutex once (it's acquired in the calling method !), as setting aggregate properties
292 		// may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
293 		// our own mutex locked
294 		// FS - 72451 - 31.01.00
295 		MutexRelease aRelease(m_aMutex);
296 		m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
297 	}
298 }
299 
300 //.........................................................................
301 }	// namespace frm
302 //.........................................................................
303 
304