1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "OPropertySet.hxx"
27cdf0e10cSrcweir #include "ImplOPropertySet.hxx"
28cdf0e10cSrcweir #include "ContainerHelper.hxx"
29cdf0e10cSrcweir #include <rtl/uuid.h>
30cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <vector>
33cdf0e10cSrcweir #include <algorithm>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using ::com::sun::star::style::XStyleSupplier;
38cdf0e10cSrcweir // using ::com::sun::star::beans::XFastPropertyState;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
41cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
42cdf0e10cSrcweir using ::com::sun::star::uno::Any;
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir using ::osl::MutexGuard;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // needed for MS compiler
47cdf0e10cSrcweir using ::cppu::OBroadcastHelper;
48cdf0e10cSrcweir using ::cppu::OPropertySetHelper;
49cdf0e10cSrcweir using ::cppu::OWeakObject;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace property
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 
OPropertySet(::osl::Mutex & par_rMutex)54cdf0e10cSrcweir OPropertySet::OPropertySet( ::osl::Mutex & par_rMutex ) :
55cdf0e10cSrcweir         OBroadcastHelper( par_rMutex ),
56cdf0e10cSrcweir         // the following causes a warning; there seems to be no way to avoid it
57cdf0e10cSrcweir         OPropertySetHelper( static_cast< OBroadcastHelper & >( *this )),
58cdf0e10cSrcweir         m_rMutex( par_rMutex ),
59cdf0e10cSrcweir         m_pImplProperties( new impl::ImplOPropertySet() ),
60cdf0e10cSrcweir         m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault(false)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
OPropertySet(const OPropertySet & rOther,::osl::Mutex & par_rMutex)64cdf0e10cSrcweir OPropertySet::OPropertySet( const OPropertySet & rOther, ::osl::Mutex & par_rMutex ) :
65cdf0e10cSrcweir         OBroadcastHelper( par_rMutex ),
66cdf0e10cSrcweir         // the following causes a warning; there seems to be no way to avoid it
67cdf0e10cSrcweir         OPropertySetHelper( static_cast< OBroadcastHelper & >( *this )),
68cdf0e10cSrcweir         m_rMutex( par_rMutex ),
69cdf0e10cSrcweir         m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault(false)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     // /--
72cdf0e10cSrcweir     MutexGuard aGuard( m_rMutex );
73cdf0e10cSrcweir     if( rOther.m_pImplProperties.get())
74cdf0e10cSrcweir         m_pImplProperties.reset( new impl::ImplOPropertySet( * rOther.m_pImplProperties.get()));
75cdf0e10cSrcweir     // \--
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
SetNewValuesExplicitlyEvenIfTheyEqualDefault()78cdf0e10cSrcweir void OPropertySet::SetNewValuesExplicitlyEvenIfTheyEqualDefault()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault = true;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
~OPropertySet()83cdf0e10cSrcweir OPropertySet::~OPropertySet()
84cdf0e10cSrcweir {}
85cdf0e10cSrcweir 
disposePropertySet()86cdf0e10cSrcweir void OPropertySet::disposePropertySet()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     m_pImplProperties.reset( 0 );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
queryInterface(const uno::Type & aType)91cdf0e10cSrcweir Any SAL_CALL OPropertySet::queryInterface( const uno::Type& aType )
92cdf0e10cSrcweir     throw (uno::RuntimeException)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     return ::cppu::queryInterface(
95cdf0e10cSrcweir         aType,
96cdf0e10cSrcweir //         static_cast< uno::XInterface * >(
97cdf0e10cSrcweir //             static_cast< uno::XWeak * >( this )),
98cdf0e10cSrcweir //         static_cast< uno::XWeak * >( this ),
99cdf0e10cSrcweir //         static_cast< lang::XServiceInfo * >( this ),
100cdf0e10cSrcweir         static_cast< lang::XTypeProvider * >( this ),
101cdf0e10cSrcweir         static_cast< beans::XPropertySet * >( this ),
102cdf0e10cSrcweir         static_cast< beans::XMultiPropertySet * >( this ),
103cdf0e10cSrcweir         static_cast< beans::XFastPropertySet * >( this ),
104cdf0e10cSrcweir         static_cast< beans::XPropertyState * >( this ),
105cdf0e10cSrcweir         static_cast< beans::XMultiPropertyStates * >( this ),
106cdf0e10cSrcweir         static_cast< XStyleSupplier * >( this ) );
107cdf0e10cSrcweir //         static_cast< XFastPropertyState * >( this ) );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir // void SAL_CALL OPropertySet::acquire() throw ()
111cdf0e10cSrcweir // {
112cdf0e10cSrcweir //     OWeakObject::acquire();
113cdf0e10cSrcweir // }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // void SAL_CALL OPropertySet::release() throw ()
116cdf0e10cSrcweir // {
117cdf0e10cSrcweir //     OWeakObject::release();
118cdf0e10cSrcweir // }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // ____ XServiceInfo ____
122cdf0e10cSrcweir // OUString SAL_CALL
123cdf0e10cSrcweir //     OPropertySet::getImplementationName()
124cdf0e10cSrcweir //     throw (uno::RuntimeException)
125cdf0e10cSrcweir // {
126cdf0e10cSrcweir //     return OUString( RTL_CONSTASCII_USTRINGPARAM( "property::OPropertySet" ));
127cdf0e10cSrcweir // }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir // sal_Bool SAL_CALL
130cdf0e10cSrcweir //     OPropertySet::supportsService( const OUString& ServiceName )
131cdf0e10cSrcweir //     throw (uno::RuntimeException)
132cdf0e10cSrcweir // {
133cdf0e10cSrcweir //     return ( 0 == ServiceName.reverseCompareToAsciiL(
134cdf0e10cSrcweir //                  RTL_CONSTASCII_STRINGPARAM( "com.sun.star.beans.PropertySet" )));
135cdf0e10cSrcweir // }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // Sequence< OUString > SAL_CALL
138cdf0e10cSrcweir //     OPropertySet::getSupportedServiceNames()
139cdf0e10cSrcweir //     throw (uno::RuntimeException)
140cdf0e10cSrcweir // {
141cdf0e10cSrcweir //     Sequence< OUString > aServiceNames( 1 );
142cdf0e10cSrcweir //     aServiceNames[ 0 ] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.beans.PropertySet" ));
143cdf0e10cSrcweir //     return aServiceNames;
144cdf0e10cSrcweir // }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir #define LCL_PROP_CPPUTYPE(t) (::getCppuType( reinterpret_cast< const Reference<t> *>(0)))
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // // ____ XTypeProvider ____
149cdf0e10cSrcweir Sequence< uno::Type > SAL_CALL
getTypes()150cdf0e10cSrcweir     OPropertySet::getTypes()
151cdf0e10cSrcweir     throw (uno::RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     static Sequence< uno::Type > aTypeList;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // /--
156cdf0e10cSrcweir     MutexGuard aGuard( m_rMutex );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     if( aTypeList.getLength() == 0 )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         ::std::vector< uno::Type > aTypes;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //         aTypes.push_back( LCL_PROP_CPPUTYPE( uno::XWeak ));
163cdf0e10cSrcweir //         aTypes.push_back( LCL_PROP_CPPUTYPE( lang::XServiceInfo ));
164cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( lang::XTypeProvider ));
165cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XPropertySet ));
166cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XMultiPropertySet ));
167cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XFastPropertySet ));
168cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XPropertyState ));
169cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( beans::XMultiPropertyStates ));
170cdf0e10cSrcweir         aTypes.push_back( LCL_PROP_CPPUTYPE( XStyleSupplier ));
171cdf0e10cSrcweir //         aTypes.push_back( LCL_PROP_CPPUTYPE( XFastPropertyState ));
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         aTypeList = ::chart::ContainerHelper::ContainerToSequence( aTypes );
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     return aTypeList;
177cdf0e10cSrcweir     // \--
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL
getImplementationId()181cdf0e10cSrcweir     OPropertySet::getImplementationId()
182cdf0e10cSrcweir     throw (uno::RuntimeException)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	static uno::Sequence< sal_Int8 > aId;
185cdf0e10cSrcweir 	if( aId.getLength() == 0 )
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		aId.realloc( 16 );
188cdf0e10cSrcweir 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
189cdf0e10cSrcweir 	}
190cdf0e10cSrcweir 	return aId;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // ____ XPropertyState ____
195cdf0e10cSrcweir beans::PropertyState SAL_CALL
getPropertyState(const OUString & PropertyName)196cdf0e10cSrcweir     OPropertySet::getPropertyState( const OUString& PropertyName )
197cdf0e10cSrcweir     throw (beans::UnknownPropertyException,
198cdf0e10cSrcweir            uno::RuntimeException)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	cppu::IPropertyArrayHelper & rPH = getInfoHelper();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     return m_pImplProperties->GetPropertyStateByHandle(
203cdf0e10cSrcweir         rPH.getHandleByName( PropertyName ));
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir Sequence< beans::PropertyState > SAL_CALL
getPropertyStates(const Sequence<OUString> & aPropertyName)207cdf0e10cSrcweir     OPropertySet::getPropertyStates( const Sequence< OUString >& aPropertyName )
208cdf0e10cSrcweir     throw (beans::UnknownPropertyException,
209cdf0e10cSrcweir            uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	cppu::IPropertyArrayHelper & rPH = getInfoHelper();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     sal_Int32 * pHandles = new sal_Int32[ aPropertyName.getLength() ];
214cdf0e10cSrcweir     rPH.fillHandles( pHandles, aPropertyName );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     ::std::vector< sal_Int32 > aHandles( pHandles, pHandles + aPropertyName.getLength());
217cdf0e10cSrcweir     delete[] pHandles;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     return m_pImplProperties->GetPropertyStatesByHandle( aHandles );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir void SAL_CALL
setPropertyToDefault(const OUString & PropertyName)223cdf0e10cSrcweir     OPropertySet::setPropertyToDefault( const OUString& PropertyName )
224cdf0e10cSrcweir     throw (beans::UnknownPropertyException,
225cdf0e10cSrcweir            uno::RuntimeException)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	cppu::IPropertyArrayHelper & rPH = getInfoHelper();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     m_pImplProperties->SetPropertyToDefault( rPH.getHandleByName( PropertyName ));
230cdf0e10cSrcweir     firePropertyChangeEvent();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir Any SAL_CALL
getPropertyDefault(const OUString & aPropertyName)234cdf0e10cSrcweir     OPropertySet::getPropertyDefault( const OUString& aPropertyName )
235cdf0e10cSrcweir     throw (beans::UnknownPropertyException,
236cdf0e10cSrcweir            lang::WrappedTargetException,
237cdf0e10cSrcweir            uno::RuntimeException)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir 	cppu::IPropertyArrayHelper & rPH = getInfoHelper();
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     return GetDefaultValue( rPH.getHandleByName( aPropertyName ) );
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir // ____ XMultiPropertyStates ____
246cdf0e10cSrcweir 
247cdf0e10cSrcweir // Note: getPropertyStates() is already implemented in XPropertyState with the
248cdf0e10cSrcweir // same signature
249cdf0e10cSrcweir 
250cdf0e10cSrcweir void SAL_CALL
setAllPropertiesToDefault()251cdf0e10cSrcweir     OPropertySet::setAllPropertiesToDefault()
252cdf0e10cSrcweir     throw (uno::RuntimeException)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     m_pImplProperties->SetAllPropertiesToDefault();
255cdf0e10cSrcweir     firePropertyChangeEvent();
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir void SAL_CALL
setPropertiesToDefault(const Sequence<OUString> & aPropertyNames)259cdf0e10cSrcweir     OPropertySet::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames )
260cdf0e10cSrcweir     throw (beans::UnknownPropertyException,
261cdf0e10cSrcweir            uno::RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir 	cppu::IPropertyArrayHelper & rPH = getInfoHelper();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     sal_Int32 * pHandles = new sal_Int32[ aPropertyNames.getLength() ];
266cdf0e10cSrcweir     rPH.fillHandles( pHandles, aPropertyNames );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     ::std::vector< sal_Int32 > aHandles( pHandles, pHandles + aPropertyNames.getLength());
269cdf0e10cSrcweir     delete[] pHandles;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     m_pImplProperties->SetPropertiesToDefault( aHandles );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir Sequence< Any > SAL_CALL
getPropertyDefaults(const Sequence<OUString> & aPropertyNames)275cdf0e10cSrcweir     OPropertySet::getPropertyDefaults( const Sequence< OUString >& aPropertyNames )
276cdf0e10cSrcweir     throw (beans::UnknownPropertyException,
277cdf0e10cSrcweir            lang::WrappedTargetException,
278cdf0e10cSrcweir            uno::RuntimeException)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper & rPH = getInfoHelper();
281cdf0e10cSrcweir     const sal_Int32 nElements = aPropertyNames.getLength();
282cdf0e10cSrcweir 
283cdf0e10cSrcweir     Sequence< Any > aResult( nElements );
284cdf0e10cSrcweir     Any * pResultArray = aResult.getArray();
285cdf0e10cSrcweir     sal_Int32 nI = 0;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     for( ; nI < nElements; ++nI )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         pResultArray[ nI ] = GetDefaultValue(
290cdf0e10cSrcweir             rPH.getHandleByName( aPropertyNames[ nI ] ));
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     return aResult;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)296cdf0e10cSrcweir sal_Bool SAL_CALL OPropertySet::convertFastPropertyValue
297cdf0e10cSrcweir     ( Any & rConvertedValue,
298cdf0e10cSrcweir       Any & rOldValue,
299cdf0e10cSrcweir       sal_Int32 nHandle,
300cdf0e10cSrcweir       const Any& rValue )
301cdf0e10cSrcweir     throw (lang::IllegalArgumentException)
302cdf0e10cSrcweir {
303cdf0e10cSrcweir     getFastPropertyValue( rOldValue, nHandle );
304cdf0e10cSrcweir     //accept longs also for short values
305cdf0e10cSrcweir     {
306cdf0e10cSrcweir         sal_Int16 nValue;
307cdf0e10cSrcweir         if( (rOldValue>>=nValue) && !(rValue>>=nValue) )
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir             sal_Int32 n32Value = 0;
310cdf0e10cSrcweir             if( rValue>>=n32Value )
311cdf0e10cSrcweir             {
312cdf0e10cSrcweir                 rConvertedValue = uno::makeAny( static_cast<sal_Int16>(n32Value) );
313cdf0e10cSrcweir                 return sal_True;
314cdf0e10cSrcweir             }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir             sal_Int64 n64Value = 0;
317cdf0e10cSrcweir             if( rValue>>=n64Value )
318cdf0e10cSrcweir             {
319cdf0e10cSrcweir                 rConvertedValue = uno::makeAny( static_cast<sal_Int16>(n64Value) );
320cdf0e10cSrcweir                 return sal_True;
321cdf0e10cSrcweir             }
322cdf0e10cSrcweir         }
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir     rConvertedValue = rValue;
325cdf0e10cSrcweir     if( !m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault && rOldValue == rConvertedValue )
326cdf0e10cSrcweir         return sal_False;//no change necessary
327cdf0e10cSrcweir     return sal_True;
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)330cdf0e10cSrcweir void SAL_CALL OPropertySet::setFastPropertyValue_NoBroadcast
331cdf0e10cSrcweir     ( sal_Int32 nHandle,
332cdf0e10cSrcweir       const Any& rValue )
333cdf0e10cSrcweir     throw (uno::Exception)
334cdf0e10cSrcweir {
335cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
336cdf0e10cSrcweir     if( rValue.hasValue())
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         cppu::IPropertyArrayHelper & rPH = getInfoHelper();
339cdf0e10cSrcweir         OUString aName;
340cdf0e10cSrcweir         rPH.fillPropertyMembersByHandle( &aName, 0, nHandle );
341cdf0e10cSrcweir         OSL_ENSURE( rValue.isExtractableTo( rPH.getPropertyByName( aName ).Type ),
342cdf0e10cSrcweir                     "Property type is wrong" );
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir #endif
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     Any aDefault;
347cdf0e10cSrcweir     try
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         aDefault = GetDefaultValue( nHandle );
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir     catch( beans::UnknownPropertyException ex )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         aDefault.clear();
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir     m_pImplProperties->SetPropertyValueByHandle( nHandle, rValue );
356cdf0e10cSrcweir     if( !m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault && aDefault.hasValue() && aDefault == rValue ) //#i98893# don't export defaults to file
357cdf0e10cSrcweir         m_pImplProperties->SetPropertyToDefault( nHandle );
358cdf0e10cSrcweir     else
359cdf0e10cSrcweir         m_pImplProperties->SetPropertyValueByHandle( nHandle, rValue );
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const362cdf0e10cSrcweir void SAL_CALL OPropertySet::getFastPropertyValue
363cdf0e10cSrcweir     ( Any& rValue,
364cdf0e10cSrcweir       sal_Int32 nHandle ) const
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     if( ! m_pImplProperties->GetPropertyValueByHandle( rValue, nHandle ))
367cdf0e10cSrcweir     {
368cdf0e10cSrcweir //         OSL_TRACE( "OPropertySet: asking style for property" );
369cdf0e10cSrcweir         // property was not set -> try style
370cdf0e10cSrcweir         uno::Reference< beans::XFastPropertySet > xStylePropSet( m_pImplProperties->GetStyle(), uno::UNO_QUERY );
371cdf0e10cSrcweir         if( xStylePropSet.is() )
372cdf0e10cSrcweir         {
373cdf0e10cSrcweir #ifdef DBG_UTIL
374cdf0e10cSrcweir             {
375cdf0e10cSrcweir                 // check if the handle of the style points to the same property
376cdf0e10cSrcweir                 // name as the handle in this property set
377cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xPropSet( xStylePropSet, uno::UNO_QUERY );
378cdf0e10cSrcweir                 if( xPropSet.is())
379cdf0e10cSrcweir                 {
380cdf0e10cSrcweir                     uno::Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo(),
381cdf0e10cSrcweir                                                                      uno::UNO_QUERY );
382cdf0e10cSrcweir                     if( xInfo.is() )
383cdf0e10cSrcweir                     {
384cdf0e10cSrcweir                         // for some reason the virtual method getInfoHelper() is
385cdf0e10cSrcweir                         // not const
386cdf0e10cSrcweir                         ::cppu::IPropertyArrayHelper & rPH =
387cdf0e10cSrcweir                               const_cast< OPropertySet * >( this )->getInfoHelper();
388cdf0e10cSrcweir 
389cdf0e10cSrcweir                         // find the Property with Handle nHandle in Style
390cdf0e10cSrcweir                         Sequence< beans::Property > aProps( xInfo->getProperties() );
391cdf0e10cSrcweir                         sal_Int32 nI = aProps.getLength() - 1;
392cdf0e10cSrcweir                         while( ( nI >= 0 ) && nHandle != aProps[ nI ].Handle )
393cdf0e10cSrcweir                             --nI;
394cdf0e10cSrcweir 
395cdf0e10cSrcweir                         if( nI >= 0 ) // => nHandle == aProps[nI].Handle
396cdf0e10cSrcweir                         {
397cdf0e10cSrcweir                             // check whether the handle in this property set is
398cdf0e10cSrcweir                             // the same as the one in the style
399cdf0e10cSrcweir                             beans::Property aProp( rPH.getPropertyByName( aProps[ nI ].Name ) );
400cdf0e10cSrcweir                             OSL_ENSURE( nHandle == aProp.Handle,
401cdf0e10cSrcweir                                         "HandleCheck: Handles for same property differ!" );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir                             if( nHandle == aProp.Handle )
404cdf0e10cSrcweir                             {
405cdf0e10cSrcweir                                 OSL_ENSURE( aProp.Type == aProps[nI].Type,
406cdf0e10cSrcweir                                             "HandleCheck: Types differ!" );
407cdf0e10cSrcweir                                 OSL_ENSURE( aProp.Attributes == aProps[nI].Attributes,
408cdf0e10cSrcweir                                             "HandleCheck: Attributes differ!" );
409cdf0e10cSrcweir                             }
410cdf0e10cSrcweir                         }
411cdf0e10cSrcweir                         else
412cdf0e10cSrcweir                         {
413cdf0e10cSrcweir                             OSL_ENSURE( false,  "HandleCheck: Handle not found in Style" );
414cdf0e10cSrcweir                         }
415cdf0e10cSrcweir                     }
416cdf0e10cSrcweir                     else
417cdf0e10cSrcweir                         OSL_ENSURE( false, "HandleCheck: Invalid XPropertySetInfo returned" );
418cdf0e10cSrcweir                 }
419cdf0e10cSrcweir                 else
420cdf0e10cSrcweir                     OSL_ENSURE( false, "HandleCheck: XPropertySet not supported" );
421cdf0e10cSrcweir             }
422cdf0e10cSrcweir #endif
423cdf0e10cSrcweir             rValue = xStylePropSet->getFastPropertyValue( nHandle );
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir         else
426cdf0e10cSrcweir         {
427cdf0e10cSrcweir //             OSL_TRACE( "OPropertySet: no style => getting default for property" );
428cdf0e10cSrcweir             // there is no style (or the style does not support XFastPropertySet)
429cdf0e10cSrcweir             // => take the default value
430cdf0e10cSrcweir             try
431cdf0e10cSrcweir             {
432cdf0e10cSrcweir                 rValue = GetDefaultValue( nHandle );
433cdf0e10cSrcweir             }
434cdf0e10cSrcweir             catch( beans::UnknownPropertyException ex )
435cdf0e10cSrcweir             {
436cdf0e10cSrcweir                 rValue.clear();
437cdf0e10cSrcweir             }
438cdf0e10cSrcweir         }
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
firePropertyChangeEvent()442cdf0e10cSrcweir void OPropertySet::firePropertyChangeEvent()
443cdf0e10cSrcweir {
444cdf0e10cSrcweir     // nothing in base class
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir // ____ XStyleSupplier ____
getStyle()448cdf0e10cSrcweir Reference< style::XStyle > SAL_CALL OPropertySet::getStyle()
449cdf0e10cSrcweir     throw (uno::RuntimeException)
450cdf0e10cSrcweir {
451cdf0e10cSrcweir     return m_pImplProperties->GetStyle();
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
setStyle(const Reference<style::XStyle> & xStyle)454cdf0e10cSrcweir void SAL_CALL OPropertySet::setStyle( const Reference< style::XStyle >& xStyle )
455cdf0e10cSrcweir     throw (lang::IllegalArgumentException,
456cdf0e10cSrcweir            uno::RuntimeException)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     if( ! m_pImplProperties->SetStyle( xStyle ))
459cdf0e10cSrcweir         throw lang::IllegalArgumentException(
460cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM( "Empty Style" )),
461cdf0e10cSrcweir             static_cast< beans::XPropertySet * >( this ),
462cdf0e10cSrcweir             0 );
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir // ____ XFastPropertyState ____
466cdf0e10cSrcweir // beans::PropertyState OPropertySet::SAL_CALL getFastPropertyState( sal_Int32 nHandle )
467cdf0e10cSrcweir //     throw (beans::UnknownPropertyException,
468cdf0e10cSrcweir //            uno::RuntimeException)
469cdf0e10cSrcweir // {
470cdf0e10cSrcweir //     return m_pImplProperties->GetPropertyStateByHandle( nHandle );
471cdf0e10cSrcweir // }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir // uno::Sequence< beans::PropertyState > OPropertySet::SAL_CALL getFastPropertyStates(
474cdf0e10cSrcweir //     const uno::Sequence< sal_Int32 >& aHandles )
475cdf0e10cSrcweir //     throw (beans::UnknownPropertyException,
476cdf0e10cSrcweir //            uno::RuntimeException)
477cdf0e10cSrcweir // {
478cdf0e10cSrcweir //     ::std::vector< sal_Int32 > aHandleVec(
479cdf0e10cSrcweir //         aHandles.getConstArray(),
480cdf0e10cSrcweir //         aHandles.getConstArray() + aHandles.getLength() );
481cdf0e10cSrcweir 
482cdf0e10cSrcweir //     return m_pImplProperties->GetPropertyStatesByHandle( aHandleVec );
483cdf0e10cSrcweir // }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir // void OPropertySet::SAL_CALL setFastPropertyToDefault( sal_Int32 nHandle )
486cdf0e10cSrcweir //     throw (beans::UnknownPropertyException,
487cdf0e10cSrcweir //            uno::RuntimeException)
488cdf0e10cSrcweir // {
489cdf0e10cSrcweir //     m_pImplProperties->SetPropertyToDefault( nHandle );
490cdf0e10cSrcweir // }
491cdf0e10cSrcweir 
492cdf0e10cSrcweir // uno::Any OPropertySet::SAL_CALL getFastPropertyDefault( sal_Int32 nHandle )
493cdf0e10cSrcweir //     throw (beans::UnknownPropertyException,
494cdf0e10cSrcweir //            lang::WrappedTargetException,
495cdf0e10cSrcweir //            uno::RuntimeException)
496cdf0e10cSrcweir // {
497cdf0e10cSrcweir //     return GetDefaultValue( nHandle );
498cdf0e10cSrcweir // }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir // ____ XMultiPropertySet ____
setPropertyValues(const Sequence<OUString> & PropertyNames,const Sequence<Any> & Values)501cdf0e10cSrcweir void SAL_CALL OPropertySet::setPropertyValues(
502cdf0e10cSrcweir     const Sequence< OUString >& PropertyNames, const Sequence< Any >& Values )
503cdf0e10cSrcweir     throw(beans::PropertyVetoException,
504cdf0e10cSrcweir           lang::IllegalArgumentException,
505cdf0e10cSrcweir           lang::WrappedTargetException,
506cdf0e10cSrcweir           uno::RuntimeException)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     ::cppu::OPropertySetHelper::setPropertyValues( PropertyNames, Values );
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     firePropertyChangeEvent();
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir // ____ XFastPropertySet ____
setFastPropertyValue(sal_Int32 nHandle,const Any & rValue)514cdf0e10cSrcweir void SAL_CALL OPropertySet::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
515cdf0e10cSrcweir     throw(beans::UnknownPropertyException,
516cdf0e10cSrcweir           beans::PropertyVetoException,
517cdf0e10cSrcweir           lang::IllegalArgumentException,
518cdf0e10cSrcweir           lang::WrappedTargetException, uno::RuntimeException)
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     ::cppu::OPropertySetHelper::setFastPropertyValue( nHandle, rValue );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     firePropertyChangeEvent();
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 
526cdf0e10cSrcweir } //  namespace property
527