xref: /aoo41x/main/forms/source/component/File.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 
31 
32 #include "File.hxx"
33 
34 #include <com/sun/star/form/FormComponentType.hpp>
35 
36 #ifndef _FRM_PROPERTY_HRC_
37 #include "property.hrc"
38 #endif
39 #include "services.hxx"
40 #include <tools/debug.hxx>
41 #include <comphelper/container.hxx>
42 #include <comphelper/basicio.hxx>
43 #include <comphelper/guarding.hxx>
44 
45 //.........................................................................
46 namespace frm
47 {
48 //.........................................................................
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::sdb;
51 using namespace ::com::sun::star::sdbc;
52 using namespace ::com::sun::star::sdbcx;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::container;
55 using namespace ::com::sun::star::form;
56 using namespace ::com::sun::star::awt;
57 using namespace ::com::sun::star::io;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::util;
60 
61 //------------------------------------------------------------------
62 InterfaceRef SAL_CALL OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
63 {
64 	return *(new OFileControlModel(_rxFactory));
65 }
66 
67 //------------------------------------------------------------------------------
68 Sequence<Type> OFileControlModel::_getTypes()
69 {
70 	static Sequence<Type> aTypes;
71 	if (!aTypes.getLength())
72 	{
73 		// my base class
74 		Sequence<Type> aBaseClassTypes = OControlModel::_getTypes();
75 
76 		Sequence<Type> aOwnTypes(1);
77 		Type* pOwnTypes = aOwnTypes.getArray();
78 		pOwnTypes[0] = getCppuType((Reference<XReset>*)NULL);
79 
80 		aTypes = concatSequences(aBaseClassTypes, aOwnTypes);
81 	}
82 	return aTypes;
83 }
84 
85 
86 // XServiceInfo
87 //------------------------------------------------------------------------------
88 StringSequence	OFileControlModel::getSupportedServiceNames() throw(RuntimeException)
89 {
90 	StringSequence aSupported = OControlModel::getSupportedServiceNames();
91 	aSupported.realloc(aSupported.getLength() + 1);
92 
93 	::rtl::OUString*pArray = aSupported.getArray();
94 	pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_FILECONTROL;
95 	return aSupported;
96 }
97 
98 //------------------------------------------------------------------
99 DBG_NAME( OFileControlModel )
100 //------------------------------------------------------------------
101 OFileControlModel::OFileControlModel(const Reference<XMultiServiceFactory>& _rxFactory)
102 					:OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
103 					,m_aResetListeners(m_aMutex)
104 {
105 	DBG_CTOR( OFileControlModel, NULL );
106 	m_nClassId = FormComponentType::FILECONTROL;
107 }
108 
109 //------------------------------------------------------------------
110 OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
111 	:OControlModel( _pOriginal, _rxFactory )
112 	,m_aResetListeners( m_aMutex )
113 {
114 	DBG_CTOR( OFileControlModel, NULL );
115 
116 	m_sDefaultValue = _pOriginal->m_sDefaultValue;
117 }
118 
119 //------------------------------------------------------------------
120 OFileControlModel::~OFileControlModel()
121 {
122 	if (!OComponentHelper::rBHelper.bDisposed)
123 	{
124 		acquire();
125 		dispose();
126 	}
127 	DBG_DTOR( OFileControlModel, NULL );
128 }
129 
130 //------------------------------------------------------------------------------
131 IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
132 
133 //------------------------------------------------------------------------------
134 Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType) throw (RuntimeException)
135 {
136 	Any aReturn = OControlModel::queryAggregation(_rType);
137 	if (!aReturn.hasValue())
138 		aReturn = ::cppu::queryInterface(_rType
139 			,static_cast<XReset*>(this)
140 		);
141 
142 	return aReturn;
143 }
144 
145 // OComponentHelper
146 //-----------------------------------------------------------------------------
147 void OFileControlModel::disposing()
148 {
149 	OControlModel::disposing();
150 
151 	EventObject aEvt(static_cast<XWeak*>(this));
152 	m_aResetListeners.disposeAndClear(aEvt);
153 }
154 
155 //------------------------------------------------------------------------------
156 Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
157 {
158 	Any aReturn;
159 	switch ( _nHandle )
160 	{
161         case PROPERTY_ID_DEFAULT_TEXT:
162             return makeAny( ::rtl::OUString() );
163     }
164 	return OControlModel::getPropertyDefaultByHandle( _nHandle );
165 }
166 
167 //------------------------------------------------------------------------------
168 void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
169 {
170 	switch (nHandle)
171 	{
172 		case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
173 		default:
174 			OControlModel::getFastPropertyValue(rValue, nHandle);
175 	}
176 }
177 
178 //------------------------------------------------------------------------------
179 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception)
180 {
181 	switch (nHandle)
182 	{
183 		case PROPERTY_ID_DEFAULT_TEXT :
184 			DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
185 			rValue >>= m_sDefaultValue;
186 			break;
187 		default:
188 			OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
189 	}
190 }
191 
192 //------------------------------------------------------------------------------
193 sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
194 							throw( IllegalArgumentException )
195 {
196 	switch (nHandle)
197 	{
198 		case PROPERTY_ID_DEFAULT_TEXT :
199 			return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
200 		default:
201 			return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
202 	}
203 }
204 
205 //------------------------------------------------------------------------------
206 void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
207 {
208 	BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
209 		DECL_PROP1(DEFAULT_TEXT,	::rtl::OUString,	BOUND);
210 		DECL_PROP1(TABINDEX,		sal_Int16,			BOUND);
211 	END_DESCRIBE_PROPERTIES();
212 }
213 
214 //------------------------------------------------------------------------------
215 ::rtl::OUString SAL_CALL OFileControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
216 {
217 	return FRM_COMPONENT_FILECONTROL;	// old (non-sun) name for compatibility !
218 }
219 
220 //------------------------------------------------------------------------------
221 void OFileControlModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
222 {
223 	OControlModel::write(_rxOutStream);
224 
225 	::osl::MutexGuard aGuard(m_aMutex);
226 
227 	// Version
228 	_rxOutStream->writeShort(0x0002);
229 	// Default-Wert
230 	_rxOutStream << m_sDefaultValue;
231 	writeHelpTextCompatibly(_rxOutStream);
232 }
233 
234 //------------------------------------------------------------------------------
235 void OFileControlModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
236 {
237 	OControlModel::read(_rxInStream);
238 	::osl::MutexGuard aGuard(m_aMutex);
239 
240 	// Version
241 	sal_uInt16 nVersion = _rxInStream->readShort();
242 	// Default-Wert
243 	switch (nVersion)
244 	{
245 		case 1:
246 			_rxInStream >> m_sDefaultValue; break;
247 		case 2:
248 			_rxInStream >> m_sDefaultValue;
249 			readHelpTextCompatibly(_rxInStream);
250 			break;
251 		default:
252 			DBG_ERROR("OFileControlModel::read : unknown version !");
253 			m_sDefaultValue = ::rtl::OUString();
254 	}
255 
256 	// Nach dem Lesen die Defaultwerte anzeigen
257 //	_reset();
258 }
259 
260 //-----------------------------------------------------------------------------
261 void SAL_CALL OFileControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException)
262 {
263 	::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
264 	EventObject aEvt(static_cast<XWeak*>(this));
265 	sal_Bool bContinue = sal_True;
266 	while (aIter.hasMoreElements() && bContinue)
267 		bContinue =((XResetListener*)aIter.next())->approveReset(aEvt);
268 
269 	if (bContinue)
270 	{
271 		{
272 			// Wenn Models threadSave
273 			::osl::MutexGuard aGuard(m_aMutex);
274 			_reset();
275 		}
276         m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
277 	}
278 }
279 
280 //-----------------------------------------------------------------------------
281 void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
282 {
283 	m_aResetListeners.addInterface(_rxListener);
284 }
285 
286 //-----------------------------------------------------------------------------
287 void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
288 {
289 	m_aResetListeners.removeInterface(_rxListener);
290 }
291 
292 //------------------------------------------------------------------------------
293 void OFileControlModel::_reset()
294 {
295 	{	// release our mutex once (it's acquired in the calling method !), as setting aggregate properties
296 		// may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
297 		// our own mutex locked
298 		// FS - 72451 - 31.01.00
299 		MutexRelease aRelease(m_aMutex);
300 		m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
301 	}
302 }
303 
304 //.........................................................................
305 }	// namespace frm
306 //.........................................................................
307 
308