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