Branch data Line data Source code
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 <comphelper/propstate.hxx>
21 : : #include <com/sun/star/uno/genfunc.h>
22 : : #include <cppuhelper/queryinterface.hxx>
23 : : #include <comphelper/sequence.hxx>
24 : : #include <rtl/instance.hxx>
25 : :
26 : : //.........................................................................
27 : : namespace comphelper
28 : : {
29 : : //.........................................................................
30 : :
31 : : using ::com::sun::star::uno::Reference;
32 : : using ::com::sun::star::uno::Type;
33 : : using ::com::sun::star::uno::RuntimeException;
34 : : using ::com::sun::star::uno::Sequence;
35 : : using ::com::sun::star::lang::XTypeProvider;
36 : : using ::com::sun::star::uno::Any;
37 : : using ::com::sun::star::uno::cpp_queryInterface;
38 : : using ::com::sun::star::uno::cpp_release;
39 : : using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE;
40 : : using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
41 : :
42 : : //=====================================================================
43 : : // OPropertyStateHelper
44 : : //=====================================================================
45 : :
46 : : //---------------------------------------------------------------------
47 : 157309 : ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const ::com::sun::star::uno::Type& _rType) throw( ::com::sun::star::uno::RuntimeException)
48 : : {
49 : 157309 : ::com::sun::star::uno::Any aReturn = OPropertySetHelper2::queryInterface(_rType);
50 : : // our own ifaces
51 [ + + ]: 157309 : if ( !aReturn.hasValue() )
52 [ + - ]: 92903 : aReturn = ::cppu::queryInterface(_rType, static_cast< ::com::sun::star::beans::XPropertyState*>(this));
53 : :
54 : 157309 : return aReturn;
55 : : }
56 : :
57 : : //---------------------------------------------------------------------
58 : 100 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> OPropertyStateHelper::getTypes() throw( ::com::sun::star::uno::RuntimeException)
59 : : {
60 : 100 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> aTypes(4);
61 [ + - ]: 100 : ::com::sun::star::uno::Type* pTypes = aTypes.getArray();
62 : : // base class types
63 [ + - ]: 100 : pTypes[0] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>*)NULL);
64 [ + - ]: 100 : pTypes[1] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>*)NULL);
65 [ + - ]: 100 : pTypes[2] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>*)NULL);
66 : : // my own type
67 [ + - ]: 100 : pTypes[3] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>*)NULL);
68 : 100 : return aTypes;
69 : : }
70 : :
71 : 768 : OPropertyStateHelper::OPropertyStateHelper(
72 : : ::cppu::OBroadcastHelper& rBHlp,
73 : : ::cppu::IEventNotificationHook *i_pFireEvents)
74 : 768 : : ::cppu::OPropertySetHelper2(rBHlp, i_pFireEvents) { }
75 : :
76 [ - + ]: 2041 : OPropertyStateHelper::~OPropertyStateHelper() {}
77 : :
78 : : //---------------------------------------------------------------------
79 : 199 : void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aNewValue, const ::com::sun::star::uno::Any& aOldValue)
80 : : {
81 : 199 : fire(&nHandle, &aNewValue, &aOldValue, 1, sal_False);
82 : 199 : }
83 : :
84 : : // XPropertyState
85 : : //---------------------------------------------------------------------
86 : 7308 : ::com::sun::star::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
87 : : {
88 : 7308 : cppu::IPropertyArrayHelper& rPH = getInfoHelper();
89 : 7308 : sal_Int32 nHandle = rPH.getHandleByName(_rsName);
90 : :
91 [ - + ]: 7308 : if (nHandle == -1)
92 [ # # ]: 0 : throw ::com::sun::star::beans::UnknownPropertyException();
93 : :
94 : 7308 : return getPropertyStateByHandle(nHandle);
95 : : }
96 : :
97 : : //---------------------------------------------------------------------
98 : 602 : void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
99 : : {
100 : 602 : cppu::IPropertyArrayHelper& rPH = getInfoHelper();
101 : 602 : sal_Int32 nHandle = rPH.getHandleByName(_rsName);
102 : :
103 [ - + ]: 602 : if (nHandle == -1)
104 [ # # ]: 0 : throw ::com::sun::star::beans::UnknownPropertyException();
105 : :
106 : 602 : setPropertyToDefaultByHandle(nHandle);
107 : 602 : }
108 : :
109 : : //---------------------------------------------------------------------
110 : 696 : ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
111 : : {
112 : 696 : cppu::IPropertyArrayHelper& rPH = getInfoHelper();
113 : 696 : sal_Int32 nHandle = rPH.getHandleByName(_rsName);
114 : :
115 [ - + ]: 696 : if (nHandle == -1)
116 [ # # ]: 0 : throw ::com::sun::star::beans::UnknownPropertyException();
117 : :
118 : 696 : return getPropertyDefaultByHandle(nHandle);
119 : : }
120 : :
121 : : //---------------------------------------------------------------------
122 : 36 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rPropertyNames) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
123 : : {
124 : 36 : sal_Int32 nLen = _rPropertyNames.getLength();
125 [ + - ]: 36 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> aRet(nLen);
126 [ + - ]: 36 : ::com::sun::star::beans::PropertyState* pValues = aRet.getArray();
127 : 36 : const ::rtl::OUString* pNames = _rPropertyNames.getConstArray();
128 : :
129 [ + - ]: 36 : cppu::IPropertyArrayHelper& rHelper = getInfoHelper();
130 : :
131 [ + - ]: 36 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps = rHelper.getProperties();
132 : 36 : const ::com::sun::star::beans::Property* pProps = aProps.getConstArray();
133 : 36 : sal_Int32 nPropCount = aProps.getLength();
134 : :
135 [ + - ]: 36 : osl::MutexGuard aGuard(rBHelper.rMutex);
136 [ + - ][ + + ]: 74 : for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps)
[ + + ]
137 : : {
138 : : // get the values only for valid properties
139 [ + + ]: 38 : if (pProps->Name.equals(*pNames))
140 : : {
141 [ + - ]: 36 : *pValues = getPropertyState(*pNames);
142 : 36 : ++pValues;
143 : 36 : ++pNames;
144 : 36 : ++j;
145 : : }
146 : : }
147 : :
148 [ + - ][ + - ]: 36 : return aRet;
149 : : }
150 : :
151 : : //---------------------------------------------------------------------
152 : 22042 : ::com::sun::star::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle )
153 : : {
154 : : // simply compare the current and the default value
155 [ + - ]: 22042 : Any aCurrentValue = getPropertyDefaultByHandle( _nHandle );
156 [ + - ]: 22042 : Any aDefaultValue; getFastPropertyValue( aDefaultValue, _nHandle );
157 : :
158 : : sal_Bool bEqual = uno_type_equalData(
159 : 44084 : const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(),
160 : 44084 : const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(),
161 : : reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
162 : : reinterpret_cast< uno_ReleaseFunc >(cpp_release)
163 : 66126 : );
164 [ + + ]: 22042 : return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
165 : : }
166 : :
167 : : //---------------------------------------------------------------------
168 : 602 : void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle )
169 : : {
170 [ + - ]: 602 : setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) );
171 : 602 : }
172 : :
173 : : //---------------------------------------------------------------------
174 : 0 : ::com::sun::star::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const
175 : : {
176 : 0 : return ::com::sun::star::uno::Any();
177 : : }
178 : :
179 : : //=====================================================================
180 : : // OStatefulPropertySet
181 : : //=====================================================================
182 : : //---------------------------------------------------------------------
183 : 0 : OStatefulPropertySet::OStatefulPropertySet()
184 [ # # ][ # # ]: 0 : :OPropertyStateHelper( GetBroadcastHelper() )
185 : : {
186 : 0 : }
187 : :
188 : : //---------------------------------------------------------------------
189 [ # # ][ # # ]: 0 : OStatefulPropertySet::~OStatefulPropertySet()
190 : : {
191 [ # # ]: 0 : }
192 : :
193 : : //---------------------------------------------------------------------
194 : 0 : Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes() throw(RuntimeException)
195 : : {
196 [ # # ]: 0 : Sequence< Type > aOwnTypes( 2 );
197 [ # # ][ # # ]: 0 : aOwnTypes[0] = XWeak::static_type();
198 [ # # ][ # # ]: 0 : aOwnTypes[1] = XTypeProvider::static_type();
199 : :
200 : : return concatSequences(
201 : : aOwnTypes,
202 : : OPropertyStateHelper::getTypes()
203 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
204 : : }
205 : :
206 : : namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
207 : :
208 : : //---------------------------------------------------------------------
209 : 0 : Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId() throw(RuntimeException)
210 : : {
211 : 0 : ::cppu::OImplementationId &rID = lcl_ImplId::get();
212 : 0 : return rID.getImplementationId();
213 : : }
214 : :
215 : : //---------------------------------------------------------------------
216 : 0 : Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType ) throw(RuntimeException)
217 : : {
218 : 0 : Any aReturn = OWeakObject::queryInterface( _rType );
219 [ # # ]: 0 : if ( !aReturn.hasValue() )
220 [ # # ]: 0 : aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) );
221 [ # # ]: 0 : if ( !aReturn.hasValue() )
222 [ # # ]: 0 : aReturn = OPropertyStateHelper::queryInterface( _rType );
223 : 0 : return aReturn;
224 : : }
225 : :
226 : : //---------------------------------------------------------------------
227 : 0 : void SAL_CALL OStatefulPropertySet::acquire() throw()
228 : : {
229 : 0 : ::cppu::OWeakObject::acquire();
230 : 0 : }
231 : :
232 : : //---------------------------------------------------------------------
233 : 0 : void SAL_CALL OStatefulPropertySet::release() throw()
234 : : {
235 : 0 : ::cppu::OWeakObject::release();
236 : 0 : }
237 : :
238 : : //.........................................................................
239 : : }
240 : : //.........................................................................
241 : :
242 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|