Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / source / property / propstate.cxx
blob183f51efcedfdbbfc5c81f9cc200fb2a04d4529d
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 <comphelper/propstate.hxx>
21 #include <cppuhelper/queryinterface.hxx>
22 #include <comphelper/sequence.hxx>
24 namespace comphelper
28 using ::com::sun::star::uno::Type;
29 using ::com::sun::star::uno::Sequence;
30 using ::com::sun::star::lang::XTypeProvider;
31 using ::com::sun::star::uno::Any;
32 using ::com::sun::star::uno::cpp_queryInterface;
33 using ::com::sun::star::uno::cpp_release;
34 using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE;
35 using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
38 // OPropertyStateHelper
41 css::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const css::uno::Type& _rType)
43 css::uno::Any aReturn = OPropertySetHelper2::queryInterface(_rType);
44 // our own ifaces
45 if ( !aReturn.hasValue() )
46 aReturn = ::cppu::queryInterface(_rType, static_cast< css::beans::XPropertyState*>(this));
48 return aReturn;
52 css::uno::Sequence<css::uno::Type> OPropertyStateHelper::getTypes()
54 return {
55 cppu::UnoType<css::beans::XPropertySet>::get(),
56 cppu::UnoType<css::beans::XMultiPropertySet>::get(),
57 cppu::UnoType<css::beans::XFastPropertySet>::get(),
58 cppu::UnoType<css::beans::XPropertySetOption>::get(),
59 cppu::UnoType<css::beans::XPropertyState>::get()};
62 OPropertyStateHelper::OPropertyStateHelper(
63 ::cppu::OBroadcastHelper& rBHlp,
64 ::cppu::IEventNotificationHook *i_pFireEvents)
65 : ::cppu::OPropertySetHelper2(rBHlp, i_pFireEvents) { }
67 OPropertyStateHelper::~OPropertyStateHelper() {}
70 void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const css::uno::Any& aNewValue, const css::uno::Any& aOldValue)
72 fire(&nHandle, &aNewValue, &aOldValue, 1, false);
75 // XPropertyState
77 css::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const OUString& _rsName)
79 cppu::IPropertyArrayHelper& rPH = getInfoHelper();
80 sal_Int32 nHandle = rPH.getHandleByName(_rsName);
82 if (nHandle == -1)
83 throw css::beans::UnknownPropertyException(_rsName);
85 return getPropertyStateByHandle(nHandle);
89 void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const OUString& _rsName)
91 cppu::IPropertyArrayHelper& rPH = getInfoHelper();
92 sal_Int32 nHandle = rPH.getHandleByName(_rsName);
94 if (nHandle == -1)
95 throw css::beans::UnknownPropertyException(_rsName);
97 setPropertyToDefaultByHandle(nHandle);
101 css::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const OUString& _rsName)
103 cppu::IPropertyArrayHelper& rPH = getInfoHelper();
104 sal_Int32 nHandle = rPH.getHandleByName(_rsName);
106 if (nHandle == -1)
107 throw css::beans::UnknownPropertyException(_rsName);
109 return getPropertyDefaultByHandle(nHandle);
113 css::uno::Sequence< css::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const css::uno::Sequence< OUString >& _rPropertyNames)
115 sal_Int32 nLen = _rPropertyNames.getLength();
116 css::uno::Sequence< css::beans::PropertyState> aRet(nLen);
117 css::beans::PropertyState* pValues = aRet.getArray();
118 const OUString* pNames = _rPropertyNames.getConstArray();
120 cppu::IPropertyArrayHelper& rHelper = getInfoHelper();
122 css::uno::Sequence< css::beans::Property> aProps = rHelper.getProperties();
123 const css::beans::Property* pProps = aProps.getConstArray();
124 sal_Int32 nPropCount = aProps.getLength();
126 osl::MutexGuard aGuard(rBHelper.rMutex);
127 for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps)
129 // get the values only for valid properties
130 if (pProps->Name == *pNames)
132 *pValues = getPropertyState(*pNames);
133 ++pValues;
134 ++pNames;
135 ++j;
139 return aRet;
143 css::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle )
145 // simply compare the current and the default value
146 Any aCurrentValue = getPropertyDefaultByHandle( _nHandle );
147 Any aDefaultValue;
148 getFastPropertyValue( aDefaultValue, _nHandle );
150 bool bEqual = uno_type_equalData(
151 const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(),
152 const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(),
153 reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
154 reinterpret_cast< uno_ReleaseFunc >(cpp_release)
156 return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
160 void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle )
162 setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) );
166 css::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const
168 return css::uno::Any();
172 // OStatefulPropertySet
175 OStatefulPropertySet::OStatefulPropertySet()
176 :OPropertyStateHelper( GetBroadcastHelper() )
181 OStatefulPropertySet::~OStatefulPropertySet()
186 Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes()
188 return concatSequences(
189 Sequence {
190 cppu::UnoType<XWeak>::get(),
191 cppu::UnoType<XTypeProvider>::get() },
192 OPropertyStateHelper::getTypes()
196 Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId()
198 return css::uno::Sequence<sal_Int8>();
202 Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType )
204 Any aReturn = OWeakObject::queryInterface( _rType );
205 if ( !aReturn.hasValue() )
206 aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) );
207 if ( !aReturn.hasValue() )
208 aReturn = OPropertyStateHelper::queryInterface( _rType );
209 return aReturn;
213 void SAL_CALL OStatefulPropertySet::acquire() noexcept
215 ::cppu::OWeakObject::acquire();
219 void SAL_CALL OStatefulPropertySet::release() noexcept
221 ::cppu::OWeakObject::release();
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */