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::form
;
43 using namespace ::com::sun::star::io
;
44 using namespace ::com::sun::star::lang
;
45 using namespace ::com::sun::star::util
;
48 Sequence
<Type
> OFileControlModel::_getTypes()
50 static Sequence
<Type
> const aTypes
=
51 concatSequences(OControlModel::_getTypes(), std::initializer_list
<Type
>{ cppu::UnoType
<XReset
>::get() });
58 css::uno::Sequence
<OUString
> OFileControlModel::getSupportedServiceNames()
60 css::uno::Sequence
<OUString
> aSupported
= OControlModel::getSupportedServiceNames();
61 aSupported
.realloc(aSupported
.getLength() + 2);
63 OUString
*pArray
= aSupported
.getArray();
64 pArray
[aSupported
.getLength()-2] = FRM_SUN_COMPONENT_FILECONTROL
;
65 pArray
[aSupported
.getLength()-1] = FRM_COMPONENT_FILECONTROL
;
70 OFileControlModel::OFileControlModel(const Reference
<XComponentContext
>& _rxFactory
)
71 :OControlModel(_rxFactory
, VCL_CONTROLMODEL_FILECONTROL
)
72 ,m_aResetListeners(m_aMutex
)
74 m_nClassId
= FormComponentType::FILECONTROL
;
78 OFileControlModel::OFileControlModel( const OFileControlModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
79 :OControlModel( _pOriginal
, _rxFactory
)
80 ,m_aResetListeners( m_aMutex
)
83 m_sDefaultValue
= _pOriginal
->m_sDefaultValue
;
87 OFileControlModel::~OFileControlModel()
89 if (!OComponentHelper::rBHelper
.bDisposed
)
97 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OFileControlModel::createClone()
99 rtl::Reference
<OFileControlModel
> pClone
= new OFileControlModel(this, getContext());
100 pClone
->clonedFrom(this);
105 Any SAL_CALL
OFileControlModel::queryAggregation(const Type
& _rType
)
107 Any aReturn
= OControlModel::queryAggregation(_rType
);
108 if (!aReturn
.hasValue())
109 aReturn
= ::cppu::queryInterface(_rType
110 ,static_cast<XReset
*>(this)
118 void OFileControlModel::disposing()
120 OControlModel::disposing();
122 EventObject
aEvt(static_cast<XWeak
*>(this));
123 m_aResetListeners
.disposeAndClear(aEvt
);
127 Any
OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
131 case PROPERTY_ID_DEFAULT_TEXT
:
132 return Any( OUString() );
134 return OControlModel::getPropertyDefaultByHandle( _nHandle
);
138 void OFileControlModel::getFastPropertyValue(Any
& rValue
, sal_Int32 nHandle
) const
142 case PROPERTY_ID_DEFAULT_TEXT
: rValue
<<= m_sDefaultValue
; break;
144 OControlModel::getFastPropertyValue(rValue
, nHandle
);
149 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
, const Any
& rValue
)
153 case PROPERTY_ID_DEFAULT_TEXT
:
154 DBG_ASSERT(rValue
.getValueTypeClass() == TypeClass_STRING
, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
155 rValue
>>= m_sDefaultValue
;
158 OControlModel::setFastPropertyValue_NoBroadcast(nHandle
, rValue
);
163 sal_Bool
OFileControlModel::convertFastPropertyValue(Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
167 case PROPERTY_ID_DEFAULT_TEXT
:
168 return tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, m_sDefaultValue
);
170 return OControlModel::convertFastPropertyValue(rConvertedValue
, rOldValue
, nHandle
, rValue
);
175 void OFileControlModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
177 OControlModel::describeFixedProperties( _rProps
);
178 sal_Int32 nOldCount
= _rProps
.getLength();
179 _rProps
.realloc( nOldCount
+ 2);
180 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
181 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_TEXT
, PROPERTY_ID_DEFAULT_TEXT
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::BOUND
);
182 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
183 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
187 OUString SAL_CALL
OFileControlModel::getServiceName()
189 return FRM_COMPONENT_FILECONTROL
; // old (non-sun) name for compatibility !
193 void OFileControlModel::write(const Reference
<css::io::XObjectOutputStream
>& _rxOutStream
)
195 OControlModel::write(_rxOutStream
);
197 ::osl::MutexGuard
aGuard(m_aMutex
);
200 _rxOutStream
->writeShort(0x0002);
202 _rxOutStream
<< m_sDefaultValue
;
203 writeHelpTextCompatibly(_rxOutStream
);
207 void OFileControlModel::read(const Reference
<css::io::XObjectInputStream
>& _rxInStream
)
209 OControlModel::read(_rxInStream
);
210 ::osl::MutexGuard
aGuard(m_aMutex
);
213 sal_uInt16 nVersion
= _rxInStream
->readShort();
218 _rxInStream
>> m_sDefaultValue
; break;
220 _rxInStream
>> m_sDefaultValue
;
221 readHelpTextCompatibly(_rxInStream
);
224 OSL_FAIL("OFileControlModel::read : unknown version !");
225 m_sDefaultValue
.clear();
228 // Display default values after read
233 void SAL_CALL
OFileControlModel::reset()
235 ::comphelper::OInterfaceIteratorHelper3
aIter(m_aResetListeners
);
236 EventObject
aEvt(static_cast<XWeak
*>(this));
237 bool bContinue
= true;
238 while (aIter
.hasMoreElements() && bContinue
)
239 bContinue
= aIter
.next()->approveReset(aEvt
);
243 // don't lock our mutex as setting aggregate properties
244 // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
245 // our own mutex locked
246 m_xAggregateSet
->setPropertyValue(PROPERTY_TEXT
, Any(m_sDefaultValue
));
247 m_aResetListeners
.notifyEach( &XResetListener::resetted
, aEvt
);
252 void OFileControlModel::addResetListener(const Reference
<XResetListener
>& _rxListener
)
254 m_aResetListeners
.addInterface(_rxListener
);
258 void OFileControlModel::removeResetListener(const Reference
<XResetListener
>& _rxListener
)
260 m_aResetListeners
.removeInterface(_rxListener
);
266 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
267 com_sun_star_form_OFileControlModel_get_implementation(css::uno::XComponentContext
* component
,
268 css::uno::Sequence
<css::uno::Any
> const &)
270 return cppu::acquire(new frm::OFileControlModel(component
));
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */