bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / File.cxx
blob015a9fb641d8d729bccdb8160fbc3357ef3ce084
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.hrc"
25 #include "services.hxx"
26 #include <cppuhelper/queryinterface.hxx>
27 #include <tools/debug.hxx>
28 #include <comphelper/container.hxx>
29 #include <comphelper/basicio.hxx>
30 #include <comphelper/guarding.hxx>
31 #include <comphelper/processfactory.hxx>
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::sdbcx;
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> aTypes;
53 if (!aTypes.getLength())
55 // my base class
56 Sequence<Type> aBaseClassTypes = OControlModel::_getTypes();
58 Sequence<Type> aOwnTypes(1);
59 Type* pOwnTypes = aOwnTypes.getArray();
60 pOwnTypes[0] = cppu::UnoType<XReset>::get();
62 aTypes = concatSequences(aBaseClassTypes, aOwnTypes);
64 return aTypes;
68 // XServiceInfo
70 StringSequence OFileControlModel::getSupportedServiceNames() throw(RuntimeException, std::exception)
72 StringSequence aSupported = OControlModel::getSupportedServiceNames();
73 aSupported.realloc(aSupported.getLength() + 2);
75 OUString*pArray = aSupported.getArray();
76 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_FILECONTROL;
77 pArray[aSupported.getLength()-1] = FRM_COMPONENT_FILECONTROL;
78 return aSupported;
83 OFileControlModel::OFileControlModel(const Reference<XComponentContext>& _rxFactory)
84 :OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
85 ,m_aResetListeners(m_aMutex)
87 m_nClassId = FormComponentType::FILECONTROL;
91 OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
92 :OControlModel( _pOriginal, _rxFactory )
93 ,m_aResetListeners( m_aMutex )
96 m_sDefaultValue = _pOriginal->m_sDefaultValue;
100 OFileControlModel::~OFileControlModel()
102 if (!OComponentHelper::rBHelper.bDisposed)
104 acquire();
105 dispose();
110 IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
113 Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType) throw (RuntimeException, std::exception)
115 Any aReturn = OControlModel::queryAggregation(_rType);
116 if (!aReturn.hasValue())
117 aReturn = ::cppu::queryInterface(_rType
118 ,static_cast<XReset*>(this)
121 return aReturn;
124 // OComponentHelper
126 void OFileControlModel::disposing()
128 OControlModel::disposing();
130 EventObject aEvt(static_cast<XWeak*>(this));
131 m_aResetListeners.disposeAndClear(aEvt);
135 Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
137 switch ( _nHandle )
139 case PROPERTY_ID_DEFAULT_TEXT:
140 return makeAny( OUString() );
142 return OControlModel::getPropertyDefaultByHandle( _nHandle );
146 void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
148 switch (nHandle)
150 case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
151 default:
152 OControlModel::getFastPropertyValue(rValue, nHandle);
157 void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception, std::exception)
159 switch (nHandle)
161 case PROPERTY_ID_DEFAULT_TEXT :
162 DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
163 rValue >>= m_sDefaultValue;
164 break;
165 default:
166 OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
171 sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
172 throw( IllegalArgumentException )
174 switch (nHandle)
176 case PROPERTY_ID_DEFAULT_TEXT :
177 return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
178 default:
179 return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
184 void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
186 BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
187 DECL_PROP1(DEFAULT_TEXT, OUString, BOUND);
188 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
189 END_DESCRIBE_PROPERTIES();
193 OUString SAL_CALL OFileControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
195 return OUString(FRM_COMPONENT_FILECONTROL); // old (non-sun) name for compatibility !
199 void OFileControlModel::write(const Reference<css::io::XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
201 OControlModel::write(_rxOutStream);
203 ::osl::MutexGuard aGuard(m_aMutex);
205 // Version
206 _rxOutStream->writeShort(0x0002);
207 // Default value
208 _rxOutStream << m_sDefaultValue;
209 writeHelpTextCompatibly(_rxOutStream);
213 void OFileControlModel::read(const Reference<css::io::XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
215 OControlModel::read(_rxInStream);
216 ::osl::MutexGuard aGuard(m_aMutex);
218 // Version
219 sal_uInt16 nVersion = _rxInStream->readShort();
220 // Default value
221 switch (nVersion)
223 case 1:
224 _rxInStream >> m_sDefaultValue; break;
225 case 2:
226 _rxInStream >> m_sDefaultValue;
227 readHelpTextCompatibly(_rxInStream);
228 break;
229 default:
230 OSL_FAIL("OFileControlModel::read : unknown version !");
231 m_sDefaultValue.clear();
234 // Display default values after read
235 // _reset();
239 void SAL_CALL OFileControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
241 ::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
242 EventObject aEvt(static_cast<XWeak*>(this));
243 bool bContinue = true;
244 while (aIter.hasMoreElements() && bContinue)
245 bContinue = static_cast<XResetListener*>(aIter.next())->approveReset(aEvt);
247 if (bContinue)
250 // If Models are threadSave
251 ::osl::MutexGuard aGuard(m_aMutex);
252 _reset();
254 m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
259 void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
261 m_aResetListeners.addInterface(_rxListener);
265 void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
267 m_aResetListeners.removeInterface(_rxListener);
271 void OFileControlModel::_reset()
273 { // release our mutex once (it's acquired in the calling method !), as setting aggregate properties
274 // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
275 // our own mutex locked
276 MutexRelease aRelease(m_aMutex);
277 m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
281 } // namespace frm
283 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
284 com_sun_star_form_OFileControlModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
285 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
287 return cppu::acquire(new frm::OFileControlModel(component));
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */