1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: File.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
37 #include <com/sun/star/form/FormComponentType.hpp>
39 #ifndef _FRM_PROPERTY_HRC_
40 #include "property.hrc"
42 #include "services.hxx"
43 #include <tools/debug.hxx>
44 #include <comphelper/container.hxx>
45 #include <comphelper/basicio.hxx>
46 #include <comphelper/guarding.hxx>
48 //.........................................................................
51 //.........................................................................
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::sdb
;
54 using namespace ::com::sun::star::sdbc
;
55 using namespace ::com::sun::star::sdbcx
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::container
;
58 using namespace ::com::sun::star::form
;
59 using namespace ::com::sun::star::awt
;
60 using namespace ::com::sun::star::io
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::util
;
64 //------------------------------------------------------------------
65 InterfaceRef SAL_CALL
OFileControlModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
67 return *(new OFileControlModel(_rxFactory
));
70 //------------------------------------------------------------------------------
71 Sequence
<Type
> OFileControlModel::_getTypes()
73 static Sequence
<Type
> aTypes
;
74 if (!aTypes
.getLength())
77 Sequence
<Type
> aBaseClassTypes
= OControlModel::_getTypes();
79 Sequence
<Type
> aOwnTypes(1);
80 Type
* pOwnTypes
= aOwnTypes
.getArray();
81 pOwnTypes
[0] = getCppuType((Reference
<XReset
>*)NULL
);
83 aTypes
= concatSequences(aBaseClassTypes
, aOwnTypes
);
90 //------------------------------------------------------------------------------
91 StringSequence
OFileControlModel::getSupportedServiceNames() throw(RuntimeException
)
93 StringSequence aSupported
= OControlModel::getSupportedServiceNames();
94 aSupported
.realloc(aSupported
.getLength() + 1);
96 ::rtl::OUString
*pArray
= aSupported
.getArray();
97 pArray
[aSupported
.getLength()-1] = FRM_SUN_COMPONENT_FILECONTROL
;
101 //------------------------------------------------------------------
102 DBG_NAME( OFileControlModel
)
103 //------------------------------------------------------------------
104 OFileControlModel::OFileControlModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
105 :OControlModel(_rxFactory
, VCL_CONTROLMODEL_FILECONTROL
)
106 ,m_aResetListeners(m_aMutex
)
108 DBG_CTOR( OFileControlModel
, NULL
);
109 m_nClassId
= FormComponentType::FILECONTROL
;
112 //------------------------------------------------------------------
113 OFileControlModel::OFileControlModel( const OFileControlModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
114 :OControlModel( _pOriginal
, _rxFactory
)
115 ,m_aResetListeners( m_aMutex
)
117 DBG_CTOR( OFileControlModel
, NULL
);
119 m_sDefaultValue
= _pOriginal
->m_sDefaultValue
;
122 //------------------------------------------------------------------
123 OFileControlModel::~OFileControlModel()
125 if (!OComponentHelper::rBHelper
.bDisposed
)
130 DBG_DTOR( OFileControlModel
, NULL
);
133 //------------------------------------------------------------------------------
134 IMPLEMENT_DEFAULT_CLONING( OFileControlModel
)
136 //------------------------------------------------------------------------------
137 Any SAL_CALL
OFileControlModel::queryAggregation(const Type
& _rType
) throw (RuntimeException
)
139 Any aReturn
= OControlModel::queryAggregation(_rType
);
140 if (!aReturn
.hasValue())
141 aReturn
= ::cppu::queryInterface(_rType
142 ,static_cast<XReset
*>(this)
149 //-----------------------------------------------------------------------------
150 void OFileControlModel::disposing()
152 OControlModel::disposing();
154 EventObject
aEvt(static_cast<XWeak
*>(this));
155 m_aResetListeners
.disposeAndClear(aEvt
);
158 //------------------------------------------------------------------------------
159 Any
OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
164 case PROPERTY_ID_DEFAULT_TEXT
:
165 return makeAny( ::rtl::OUString() );
167 return OControlModel::getPropertyDefaultByHandle( _nHandle
);
170 //------------------------------------------------------------------------------
171 void OFileControlModel::getFastPropertyValue(Any
& rValue
, sal_Int32 nHandle
) const
175 case PROPERTY_ID_DEFAULT_TEXT
: rValue
<<= m_sDefaultValue
; break;
177 OControlModel::getFastPropertyValue(rValue
, nHandle
);
181 //------------------------------------------------------------------------------
182 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const Any
& rValue
) throw ( ::com::sun::star::uno::Exception
)
186 case PROPERTY_ID_DEFAULT_TEXT
:
187 DBG_ASSERT(rValue
.getValueType().getTypeClass() == TypeClass_STRING
, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
188 rValue
>>= m_sDefaultValue
;
191 OControlModel::setFastPropertyValue_NoBroadcast(nHandle
, rValue
);
195 //------------------------------------------------------------------------------
196 sal_Bool
OFileControlModel::convertFastPropertyValue(Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
197 throw( IllegalArgumentException
)
201 case PROPERTY_ID_DEFAULT_TEXT
:
202 return tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_sDefaultValue
);
204 return OControlModel::convertFastPropertyValue(rConvertedValue
, rOldValue
, nHandle
, rValue
);
208 //------------------------------------------------------------------------------
209 void OFileControlModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
211 BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel
)
212 DECL_PROP1(DEFAULT_TEXT
, ::rtl::OUString
, BOUND
);
213 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
214 END_DESCRIBE_PROPERTIES();
217 //------------------------------------------------------------------------------
218 ::rtl::OUString SAL_CALL
OFileControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
220 return FRM_COMPONENT_FILECONTROL
; // old (non-sun) name for compatibility !
223 //------------------------------------------------------------------------------
224 void OFileControlModel::write(const Reference
<stario::XObjectOutputStream
>& _rxOutStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
226 OControlModel::write(_rxOutStream
);
228 ::osl::MutexGuard
aGuard(m_aMutex
);
231 _rxOutStream
->writeShort(0x0002);
233 _rxOutStream
<< m_sDefaultValue
;
234 writeHelpTextCompatibly(_rxOutStream
);
237 //------------------------------------------------------------------------------
238 void OFileControlModel::read(const Reference
<stario::XObjectInputStream
>& _rxInStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
240 OControlModel::read(_rxInStream
);
241 ::osl::MutexGuard
aGuard(m_aMutex
);
244 sal_uInt16 nVersion
= _rxInStream
->readShort();
249 _rxInStream
>> m_sDefaultValue
; break;
251 _rxInStream
>> m_sDefaultValue
;
252 readHelpTextCompatibly(_rxInStream
);
255 DBG_ERROR("OFileControlModel::read : unknown version !");
256 m_sDefaultValue
= ::rtl::OUString();
259 // Nach dem Lesen die Defaultwerte anzeigen
263 //-----------------------------------------------------------------------------
264 void SAL_CALL
OFileControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException
)
266 ::cppu::OInterfaceIteratorHelper
aIter(m_aResetListeners
);
267 EventObject
aEvt(static_cast<XWeak
*>(this));
268 sal_Bool bContinue
= sal_True
;
269 while (aIter
.hasMoreElements() && bContinue
)
270 bContinue
=((XResetListener
*)aIter
.next())->approveReset(aEvt
);
275 // Wenn Models threadSave
276 ::osl::MutexGuard
aGuard(m_aMutex
);
279 m_aResetListeners
.notifyEach( &XResetListener::resetted
, aEvt
);
283 //-----------------------------------------------------------------------------
284 void OFileControlModel::addResetListener(const Reference
<XResetListener
>& _rxListener
) throw ( ::com::sun::star::uno::RuntimeException
)
286 m_aResetListeners
.addInterface(_rxListener
);
289 //-----------------------------------------------------------------------------
290 void OFileControlModel::removeResetListener(const Reference
<XResetListener
>& _rxListener
) throw ( ::com::sun::star::uno::RuntimeException
)
292 m_aResetListeners
.removeInterface(_rxListener
);
295 //------------------------------------------------------------------------------
296 void OFileControlModel::_reset()
298 { // release our mutex once (it's acquired in the calling method !), as setting aggregate properties
299 // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
300 // our own mutex locked
301 // FS - 72451 - 31.01.00
302 MutexRelease
aRelease(m_aMutex
);
303 m_xAggregateSet
->setPropertyValue(PROPERTY_TEXT
, makeAny(m_sDefaultValue
));
307 //.........................................................................
309 //.........................................................................