LibreOffice Module comphelper (master) 1
propstate.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
23
24namespace comphelper
25{
26
27
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;
36
37
38 // OPropertyStateHelper
39
40
41 css::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const css::uno::Type& _rType)
42 {
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));
47
48 return aReturn;
49 }
50
51
52 css::uno::Sequence<css::uno::Type> OPropertyStateHelper::getTypes()
53 {
54 return {
60 }
61
62 OPropertyStateHelper::OPropertyStateHelper(
64 ::cppu::IEventNotificationHook *i_pFireEvents)
65 : ::cppu::OPropertySetHelper2(rBHlp, i_pFireEvents) { }
66
67 OPropertyStateHelper::~OPropertyStateHelper() {}
68
69
70 void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const css::uno::Any& aNewValue, const css::uno::Any& aOldValue)
71 {
72 fire(&nHandle, &aNewValue, &aOldValue, 1, false);
73 }
74
75 // XPropertyState
76
77 css::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const OUString& _rsName)
78 {
79 cppu::IPropertyArrayHelper& rPH = getInfoHelper();
80 sal_Int32 nHandle = rPH.getHandleByName(_rsName);
81
82 if (nHandle == -1)
83 throw css::beans::UnknownPropertyException(_rsName);
84
85 return getPropertyStateByHandle(nHandle);
86 }
87
88
89 void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const OUString& _rsName)
90 {
91 cppu::IPropertyArrayHelper& rPH = getInfoHelper();
92 sal_Int32 nHandle = rPH.getHandleByName(_rsName);
93
94 if (nHandle == -1)
95 throw css::beans::UnknownPropertyException(_rsName);
96
97 setPropertyToDefaultByHandle(nHandle);
98 }
99
100
101 css::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const OUString& _rsName)
102 {
103 cppu::IPropertyArrayHelper& rPH = getInfoHelper();
104 sal_Int32 nHandle = rPH.getHandleByName(_rsName);
105
106 if (nHandle == -1)
107 throw css::beans::UnknownPropertyException(_rsName);
108
109 return getPropertyDefaultByHandle(nHandle);
110 }
111
112
113 css::uno::Sequence< css::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const css::uno::Sequence< OUString >& _rPropertyNames)
114 {
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();
119
120 cppu::IPropertyArrayHelper& rHelper = getInfoHelper();
121
122 css::uno::Sequence< css::beans::Property> aProps = rHelper.getProperties();
123 const css::beans::Property* pProps = aProps.getConstArray();
124 sal_Int32 nPropCount = aProps.getLength();
125
126 osl::MutexGuard aGuard(rBHelper.rMutex);
127 for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps)
128 {
129 // get the values only for valid properties
130 if (pProps->Name == *pNames)
131 {
132 *pValues = getPropertyState(*pNames);
133 ++pValues;
134 ++pNames;
135 ++j;
136 }
137 }
138
139 return aRet;
140 }
141
142
143 css::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle )
144 {
145 // simply compare the current and the default value
146 Any aCurrentValue = getPropertyDefaultByHandle( _nHandle );
147 Any aDefaultValue;
148 getFastPropertyValue( aDefaultValue, _nHandle );
149
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)
155 );
156 return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
157 }
158
159
160 void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle )
161 {
162 setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) );
163 }
164
165
166 css::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const
167 {
168 return css::uno::Any();
169 }
170
171
172 // OStatefulPropertySet
173
174
175 OStatefulPropertySet::OStatefulPropertySet()
176 :OPropertyStateHelper( GetBroadcastHelper() )
177 {
178 }
179
180
181 OStatefulPropertySet::~OStatefulPropertySet()
182 {
183 }
184
185
186 Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes()
187 {
188 return concatSequences(
189 Sequence {
192 OPropertyStateHelper::getTypes()
193 );
194 }
195
196 Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId()
197 {
198 return css::uno::Sequence<sal_Int8>();
199 }
200
201
202 Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType )
203 {
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;
210 }
211
212
213 void SAL_CALL OStatefulPropertySet::acquire() noexcept
214 {
216 }
217
218
219 void SAL_CALL OStatefulPropertySet::release() noexcept
220 {
222 }
223
224
225}
226
227
228/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
virtual sal_Int32 SAL_CALL getHandleByName(const ::rtl::OUString &rPropertyName)=0
virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties()=0
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
css::uno::Type const & get()
sal_Bool SAL_CALL uno_type_equalData(void *pVal1, typelib_TypeDescriptionReference *pVal1Type, void *pVal2, typelib_TypeDescriptionReference *pVal2Type, uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Type
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &_rLeft, const css::uno::Sequence< T > &_rRight)
int i
sal_Int32 nHandle