nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / component / File.cxx
blobe92f168d3de3f4473c2871a7c58cae8e66d55967
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "File.hxx"
22 #include <com/sun/star/form/FormComponentType.hpp>
24 #include <property.hxx>
25 #include <services.hxx>
26 #include <cppuhelper/queryinterface.hxx>
27 #include <tools/debug.hxx>
28 #include <comphelper/basicio.hxx>
29 #include <comphelper/property.hxx>
31 using namespace comphelper;
34 namespace frm
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::sdb;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::form;
43 using namespace ::com::sun::star::awt;
44 using namespace ::com::sun::star::io;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::util;
49 Sequence<Type> OFileControlModel::_getTypes()
51 static Sequence<Type> const aTypes =
52 concatSequences(OControlModel::_getTypes(), Sequence<Type>{ cppu::UnoType<XReset>::get() });
53 return aTypes;
57 // XServiceInfo
59 css::uno::Sequence<OUString> OFileControlModel::getSupportedServiceNames()
61 css::uno::Sequence<OUString> aSupported = OControlModel::getSupportedServiceNames();
62 aSupported.realloc(aSupported.getLength() + 2);
64 OUString*pArray = aSupported.getArray();
65 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_FILECONTROL;
66 pArray[aSupported.getLength()-1] = FRM_COMPONENT_FILECONTROL;
67 return aSupported;
71 OFileControlModel::OFileControlModel(const Reference<XComponentContext>& _rxFactory)
72 :OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
73 ,m_aResetListeners(m_aMutex)
75 m_nClassId = FormComponentType::FILECONTROL;
79 OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
80 :OControlModel( _pOriginal, _rxFactory )
81 ,m_aResetListeners( m_aMutex )
84 m_sDefaultValue = _pOriginal->m_sDefaultValue;
88 OFileControlModel::~OFileControlModel()
90 if (!OComponentHelper::rBHelper.bDisposed)
92 acquire();
93 dispose();
98 IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
101 Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType)
103 Any aReturn = OControlModel::queryAggregation(_rType);
104 if (!aReturn.hasValue())
105 aReturn = ::cppu::queryInterface(_rType
106 ,static_cast<XReset*>(this)
109 return aReturn;
112 // OComponentHelper
114 void OFileControlModel::disposing()
116 OControlModel::disposing();
118 EventObject aEvt(static_cast<XWeak*>(this));
119 m_aResetListeners.disposeAndClear(aEvt);
123 Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
125 switch ( _nHandle )
127 case PROPERTY_ID_DEFAULT_TEXT:
128 return makeAny( OUString() );
130 return OControlModel::getPropertyDefaultByHandle( _nHandle );
134 void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
136 switch (nHandle)
138 case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
139 default:
140 OControlModel::getFastPropertyValue(rValue, nHandle);
145 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue)
147 switch (nHandle)
149 case PROPERTY_ID_DEFAULT_TEXT :
150 DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
151 rValue >>= m_sDefaultValue;
152 break;
153 default:
154 OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
159 sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
161 switch (nHandle)
163 case PROPERTY_ID_DEFAULT_TEXT :
164 return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
165 default:
166 return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
171 void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
173 BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
174 DECL_PROP1(DEFAULT_TEXT, OUString, BOUND);
175 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
176 END_DESCRIBE_PROPERTIES();
180 OUString SAL_CALL OFileControlModel::getServiceName()
182 return FRM_COMPONENT_FILECONTROL; // old (non-sun) name for compatibility !
186 void OFileControlModel::write(const Reference<css::io::XObjectOutputStream>& _rxOutStream)
188 OControlModel::write(_rxOutStream);
190 ::osl::MutexGuard aGuard(m_aMutex);
192 // Version
193 _rxOutStream->writeShort(0x0002);
194 // Default value
195 _rxOutStream << m_sDefaultValue;
196 writeHelpTextCompatibly(_rxOutStream);
200 void OFileControlModel::read(const Reference<css::io::XObjectInputStream>& _rxInStream)
202 OControlModel::read(_rxInStream);
203 ::osl::MutexGuard aGuard(m_aMutex);
205 // Version
206 sal_uInt16 nVersion = _rxInStream->readShort();
207 // Default value
208 switch (nVersion)
210 case 1:
211 _rxInStream >> m_sDefaultValue; break;
212 case 2:
213 _rxInStream >> m_sDefaultValue;
214 readHelpTextCompatibly(_rxInStream);
215 break;
216 default:
217 OSL_FAIL("OFileControlModel::read : unknown version !");
218 m_sDefaultValue.clear();
221 // Display default values after read
222 // _reset();
226 void SAL_CALL OFileControlModel::reset()
228 ::comphelper::OInterfaceIteratorHelper2 aIter(m_aResetListeners);
229 EventObject aEvt(static_cast<XWeak*>(this));
230 bool bContinue = true;
231 while (aIter.hasMoreElements() && bContinue)
232 bContinue = static_cast<XResetListener*>(aIter.next())->approveReset(aEvt);
234 if (bContinue)
236 // don't lock our mutex as setting aggregate properties
237 // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
238 // our own mutex locked
239 m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
240 m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
245 void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener)
247 m_aResetListeners.addInterface(_rxListener);
251 void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener)
253 m_aResetListeners.removeInterface(_rxListener);
257 } // namespace frm
259 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
260 com_sun_star_form_OFileControlModel_get_implementation(css::uno::XComponentContext* component,
261 css::uno::Sequence<css::uno::Any> const &)
263 return cppu::acquire(new frm::OFileControlModel(component));
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */