1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/form/FormComponentType.hpp>
25 #include <property.hxx>
26 #include <services.hxx>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <tools/debug.hxx>
29 #include <comphelper/basicio.hxx>
30 #include <comphelper/property.hxx>
32 using namespace comphelper
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::sdb
;
40 using namespace ::com::sun::star::sdbc
;
41 using namespace ::com::sun::star::beans
;
42 using namespace ::com::sun::star::container
;
43 using namespace ::com::sun::star::form
;
44 using namespace ::com::sun::star::awt
;
45 using namespace ::com::sun::star::io
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::util
;
50 Sequence
<Type
> OFileControlModel::_getTypes()
52 static Sequence
<Type
> const aTypes
=
53 concatSequences(OControlModel::_getTypes(), Sequence
<Type
>{ cppu::UnoType
<XReset
>::get() });
60 css::uno::Sequence
<OUString
> OFileControlModel::getSupportedServiceNames()
62 css::uno::Sequence
<OUString
> aSupported
= OControlModel::getSupportedServiceNames();
63 aSupported
.realloc(aSupported
.getLength() + 2);
65 OUString
*pArray
= aSupported
.getArray();
66 pArray
[aSupported
.getLength()-2] = FRM_SUN_COMPONENT_FILECONTROL
;
67 pArray
[aSupported
.getLength()-1] = FRM_COMPONENT_FILECONTROL
;
72 OFileControlModel::OFileControlModel(const Reference
<XComponentContext
>& _rxFactory
)
73 :OControlModel(_rxFactory
, VCL_CONTROLMODEL_FILECONTROL
)
74 ,m_aResetListeners(m_aMutex
)
76 m_nClassId
= FormComponentType::FILECONTROL
;
80 OFileControlModel::OFileControlModel( const OFileControlModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
81 :OControlModel( _pOriginal
, _rxFactory
)
82 ,m_aResetListeners( m_aMutex
)
85 m_sDefaultValue
= _pOriginal
->m_sDefaultValue
;
89 OFileControlModel::~OFileControlModel()
91 if (!OComponentHelper::rBHelper
.bDisposed
)
99 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OFileControlModel::createClone()
101 rtl::Reference
<OFileControlModel
> pClone
= new OFileControlModel(this, getContext());
102 pClone
->clonedFrom(this);
107 Any SAL_CALL
OFileControlModel::queryAggregation(const Type
& _rType
)
109 Any aReturn
= OControlModel::queryAggregation(_rType
);
110 if (!aReturn
.hasValue())
111 aReturn
= ::cppu::queryInterface(_rType
112 ,static_cast<XReset
*>(this)
120 void OFileControlModel::disposing()
122 OControlModel::disposing();
124 EventObject
aEvt(static_cast<XWeak
*>(this));
125 m_aResetListeners
.disposeAndClear(aEvt
);
129 Any
OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
133 case PROPERTY_ID_DEFAULT_TEXT
:
134 return Any( OUString() );
136 return OControlModel::getPropertyDefaultByHandle( _nHandle
);
140 void OFileControlModel::getFastPropertyValue(Any
& rValue
, sal_Int32 nHandle
) const
144 case PROPERTY_ID_DEFAULT_TEXT
: rValue
<<= m_sDefaultValue
; break;
146 OControlModel::getFastPropertyValue(rValue
, nHandle
);
151 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const Any
& rValue
)
155 case PROPERTY_ID_DEFAULT_TEXT
:
156 DBG_ASSERT(rValue
.getValueType().getTypeClass() == TypeClass_STRING
, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
157 rValue
>>= m_sDefaultValue
;
160 OControlModel::setFastPropertyValue_NoBroadcast(nHandle
, rValue
);
165 sal_Bool
OFileControlModel::convertFastPropertyValue(Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
169 case PROPERTY_ID_DEFAULT_TEXT
:
170 return tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_sDefaultValue
);
172 return OControlModel::convertFastPropertyValue(rConvertedValue
, rOldValue
, nHandle
, rValue
);
177 void OFileControlModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
179 OControlModel::describeFixedProperties( _rProps
);
180 sal_Int32 nOldCount
= _rProps
.getLength();
181 _rProps
.realloc( nOldCount
+ 2);
182 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
183 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_TEXT
, PROPERTY_ID_DEFAULT_TEXT
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::BOUND
);
184 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
185 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
189 OUString SAL_CALL
OFileControlModel::getServiceName()
191 return FRM_COMPONENT_FILECONTROL
; // old (non-sun) name for compatibility !
195 void OFileControlModel::write(const Reference
<css::io::XObjectOutputStream
>& _rxOutStream
)
197 OControlModel::write(_rxOutStream
);
199 ::osl::MutexGuard
aGuard(m_aMutex
);
202 _rxOutStream
->writeShort(0x0002);
204 _rxOutStream
<< m_sDefaultValue
;
205 writeHelpTextCompatibly(_rxOutStream
);
209 void OFileControlModel::read(const Reference
<css::io::XObjectInputStream
>& _rxInStream
)
211 OControlModel::read(_rxInStream
);
212 ::osl::MutexGuard
aGuard(m_aMutex
);
215 sal_uInt16 nVersion
= _rxInStream
->readShort();
220 _rxInStream
>> m_sDefaultValue
; break;
222 _rxInStream
>> m_sDefaultValue
;
223 readHelpTextCompatibly(_rxInStream
);
226 OSL_FAIL("OFileControlModel::read : unknown version !");
227 m_sDefaultValue
.clear();
230 // Display default values after read
235 void SAL_CALL
OFileControlModel::reset()
237 ::comphelper::OInterfaceIteratorHelper3
aIter(m_aResetListeners
);
238 EventObject
aEvt(static_cast<XWeak
*>(this));
239 bool bContinue
= true;
240 while (aIter
.hasMoreElements() && bContinue
)
241 bContinue
= aIter
.next()->approveReset(aEvt
);
245 // don't lock our mutex as setting aggregate properties
246 // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
247 // our own mutex locked
248 m_xAggregateSet
->setPropertyValue(PROPERTY_TEXT
, Any(m_sDefaultValue
));
249 m_aResetListeners
.notifyEach( &XResetListener::resetted
, aEvt
);
254 void OFileControlModel::addResetListener(const Reference
<XResetListener
>& _rxListener
)
256 m_aResetListeners
.addInterface(_rxListener
);
260 void OFileControlModel::removeResetListener(const Reference
<XResetListener
>& _rxListener
)
262 m_aResetListeners
.removeInterface(_rxListener
);
268 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
269 com_sun_star_form_OFileControlModel_get_implementation(css::uno::XComponentContext
* component
,
270 css::uno::Sequence
<css::uno::Any
> const &)
272 return cppu::acquire(new frm::OFileControlModel(component
));
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */