LibreOffice Module forms (master) 1
File.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "File.hxx"
21
22#include <com/sun/star/beans/PropertyAttribute.hpp>
23#include <com/sun/star/form/FormComponentType.hpp>
24
25#include <property.hxx>
26#include <services.hxx>
28#include <tools/debug.hxx>
31
32using namespace comphelper;
33
34
35namespace frm
36{
37
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::sdb;
40using namespace ::com::sun::star::sdbc;
41using namespace ::com::sun::star::beans;
42using namespace ::com::sun::star::container;
43using namespace ::com::sun::star::form;
44using namespace ::com::sun::star::awt;
45using namespace ::com::sun::star::io;
46using namespace ::com::sun::star::lang;
47using namespace ::com::sun::star::util;
48
49
51{
52 static Sequence<Type> const aTypes =
54 return aTypes;
55}
56
57
58// XServiceInfo
59
60css::uno::Sequence<OUString> OFileControlModel::getSupportedServiceNames()
61{
62 css::uno::Sequence<OUString> aSupported = OControlModel::getSupportedServiceNames();
63 aSupported.realloc(aSupported.getLength() + 2);
64
65 OUString*pArray = aSupported.getArray();
66 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_FILECONTROL;
67 pArray[aSupported.getLength()-1] = FRM_COMPONENT_FILECONTROL;
68 return aSupported;
69}
70
71
72OFileControlModel::OFileControlModel(const Reference<XComponentContext>& _rxFactory)
74 ,m_aResetListeners(m_aMutex)
75{
76 m_nClassId = FormComponentType::FILECONTROL;
77}
78
79
80OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
81 :OControlModel( _pOriginal, _rxFactory )
82 ,m_aResetListeners( m_aMutex )
83{
84
85 m_sDefaultValue = _pOriginal->m_sDefaultValue;
86}
87
88
90{
91 if (!OComponentHelper::rBHelper.bDisposed)
92 {
93 acquire();
94 dispose();
95 }
96}
97
98
99css::uno::Reference< css::util::XCloneable > SAL_CALL OFileControlModel::createClone()
100{
102 pClone->clonedFrom(this);
103 return pClone;
104}
105
106
108{
109 Any aReturn = OControlModel::queryAggregation(_rType);
110 if (!aReturn.hasValue())
111 aReturn = ::cppu::queryInterface(_rType
112 ,static_cast<XReset*>(this)
113 );
114
115 return aReturn;
116}
117
118// OComponentHelper
119
121{
123
124 EventObject aEvt(static_cast<XWeak*>(this));
126}
127
128
130{
131 switch ( _nHandle )
132 {
134 return Any( OUString() );
135 }
137}
138
139
140void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
141{
142 switch (nHandle)
143 {
144 case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
145 default:
147 }
148}
149
150
151void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue)
152{
153 switch (nHandle)
154 {
156 DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
157 rValue >>= m_sDefaultValue;
158 break;
159 default:
161 }
162}
163
164
165sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
166{
167 switch (nHandle)
168 {
170 return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
171 default:
172 return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
173 }
174}
175
176
177void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
178{
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 ?");
186}
187
188
190{
191 return FRM_COMPONENT_FILECONTROL; // old (non-sun) name for compatibility !
192}
193
194
195void OFileControlModel::write(const Reference<css::io::XObjectOutputStream>& _rxOutStream)
196{
197 OControlModel::write(_rxOutStream);
198
199 ::osl::MutexGuard aGuard(m_aMutex);
200
201 // Version
202 _rxOutStream->writeShort(0x0002);
203 // Default value
204 _rxOutStream << m_sDefaultValue;
205 writeHelpTextCompatibly(_rxOutStream);
206}
207
208
209void OFileControlModel::read(const Reference<css::io::XObjectInputStream>& _rxInStream)
210{
211 OControlModel::read(_rxInStream);
212 ::osl::MutexGuard aGuard(m_aMutex);
213
214 // Version
215 sal_uInt16 nVersion = _rxInStream->readShort();
216 // Default value
217 switch (nVersion)
218 {
219 case 1:
220 _rxInStream >> m_sDefaultValue; break;
221 case 2:
222 _rxInStream >> m_sDefaultValue;
223 readHelpTextCompatibly(_rxInStream);
224 break;
225 default:
226 OSL_FAIL("OFileControlModel::read : unknown version !");
227 m_sDefaultValue.clear();
228 }
229
230 // Display default values after read
231// _reset();
232}
233
234
236{
238 EventObject aEvt(static_cast<XWeak*>(this));
239 bool bContinue = true;
240 while (aIter.hasMoreElements() && bContinue)
241 bContinue = aIter.next()->approveReset(aEvt);
242
243 if (bContinue)
244 {
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 );
250 }
251}
252
253
254void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener)
255{
256 m_aResetListeners.addInterface(_rxListener);
257}
258
259
260void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener)
261{
263}
264
265
266} // namespace frm
267
268extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
269com_sun_star_form_OFileControlModel_get_implementation(css::uno::XComponentContext* component,
270 css::uno::Sequence<css::uno::Any> const &)
271{
272 return cppu::acquire(new frm::OFileControlModel(component));
273}
274
275/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OFileControlModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: File.cxx:269
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
css::uno::Reference< ListenerT > const & next()
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL dispose() SAL_OVERRIDE
css::uno::Type const & get()
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
describes the properties provided by this class, or its respective derived class
virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream) override
virtual css::uno::Sequence< css::uno::Type > _getTypes()
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
::osl::Mutex m_aMutex
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL disposing() override
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
void writeHelpTextCompatibly(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream)
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream) override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &_rConvertedValue, css::uno::Any &_rOldValue, sal_Int32 _nHandle, const css::uno::Any &_rValue) override
void readHelpTextCompatibly(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream)
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
Definition: File.cxx:177
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: File.cxx:60
virtual ~OFileControlModel() override
Definition: File.cxx:89
virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener > &_rxListener) override
Definition: File.cxx:260
OFileControlModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual void SAL_CALL disposing() override
Definition: File.cxx:120
virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream) override
Definition: File.cxx:209
virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener > &_rxListener) override
Definition: File.cxx:254
virtual void SAL_CALL reset() override
Definition: File.cxx:235
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: File.cxx:99
OUString m_sDefaultValue
Definition: File.hxx:34
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 _nHandle) const override
Definition: File.cxx:129
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
Definition: File.cxx:107
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
Definition: File.cxx:50
virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream) override
Definition: File.cxx:195
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
Definition: File.cxx:140
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: File.cxx:165
virtual OUString SAL_CALL getServiceName() override
Definition: File.cxx:189
::comphelper::OInterfaceContainerHelper3< css::form::XResetListener > m_aResetListeners
Definition: File.hxx:33
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: File.cxx:151
#define DBG_ASSERT(sCon, aError)
sal_Int16 nVersion
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_DEFAULT_TEXT
Definition: frm_strings.hxx:64
constexpr OUStringLiteral PROPERTY_TEXT
Definition: frm_strings.hxx:33
std::mutex m_aMutex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
Type
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
#define PROPERTY_ID_DEFAULT_TEXT
Definition: property.hxx:106
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
sal_Int32 nHandle
constexpr OUStringLiteral VCL_CONTROLMODEL_FILECONTROL
Definition: services.hxx:48
constexpr OUStringLiteral FRM_COMPONENT_FILECONTROL
Definition: services.hxx:77
constexpr OUStringLiteral FRM_SUN_COMPONENT_FILECONTROL
Definition: services.hxx:123
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]