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