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