1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unopool.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HDL_
35 #include <com/sun/star/beans/PropertyState.hpp>
38 #include <comphelper/propertysetinfo.hxx>
40 #include <vos/mutex.hxx>
41 #include <vcl/svapp.hxx>
42 #include "unopool.hxx"
43 #include <svx/svdmodel.hxx>
44 #include <svx/svdpool.hxx>
45 #include <svx/unoprov.hxx>
46 #include <svx/svdobj.hxx>
47 #include <svx/unoshprp.hxx>
48 #include <svx/xflbstit.hxx>
49 #include <svx/xflbmtit.hxx>
50 #include <svx/unopage.hxx>
51 #include <svx/svdetc.hxx>
52 #include <svx/editeng.hxx>
57 using namespace ::com::sun::star
;
58 using namespace ::rtl
;
59 using namespace ::cppu
;
61 SvxUnoDrawPool::SvxUnoDrawPool( SdrModel
* pModel
, sal_Int32 nServiceId
) throw()
62 : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId
) ), mpModel( pModel
)
68 SvxUnoDrawPool::SvxUnoDrawPool( SdrModel
* pModel
) throw()
69 : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS
) ), mpModel( pModel
)
74 SvxUnoDrawPool::~SvxUnoDrawPool() throw()
76 SfxItemPool::Free(mpDefaultsPool
);
79 void SvxUnoDrawPool::init()
81 mpDefaultsPool
= new SdrItemPool();
82 SfxItemPool
* pOutlPool
=EditEngine::CreatePool();
83 mpDefaultsPool
->SetSecondaryPool(pOutlPool
);
85 SdrModel::SetTextDefaults( mpDefaultsPool
, SdrEngineDefaults::GetFontHeight() );
86 mpDefaultsPool
->SetDefaultMetric((SfxMapUnit
)SdrEngineDefaults::GetMapUnit());
87 mpDefaultsPool
->FreezeIdRanges();
90 SfxItemPool
* SvxUnoDrawPool::getModelPool( sal_Bool bReadOnly
) throw()
94 return &mpModel
->GetItemPool();
99 return mpDefaultsPool
;
105 void SvxUnoDrawPool::getAny( SfxItemPool
* pPool
, const comphelper::PropertyMapEntry
* pEntry
, uno::Any
& rValue
)
106 throw(beans::UnknownPropertyException
)
108 switch( pEntry
->mnHandle
)
110 case OWN_ATTR_FILLBMP_MODE
:
112 XFillBmpStretchItem
* pStretchItem
= (XFillBmpStretchItem
*)&pPool
->GetDefaultItem(XATTR_FILLBMP_STRETCH
);
113 XFillBmpTileItem
* pTileItem
= (XFillBmpTileItem
*)&pPool
->GetDefaultItem(XATTR_FILLBMP_TILE
);
114 if( pTileItem
&& pTileItem
->GetValue() )
116 rValue
<<= drawing::BitmapMode_REPEAT
;
118 else if( pStretchItem
&& pStretchItem
->GetValue() )
120 rValue
<<= drawing::BitmapMode_STRETCH
;
124 rValue
<<= drawing::BitmapMode_NO_REPEAT
;
130 const SfxMapUnit eMapUnit
= pPool
? pPool
->GetMetric((USHORT
)pEntry
->mnHandle
) : SFX_MAPUNIT_100TH_MM
;
132 BYTE nMemberId
= pEntry
->mnMemberId
& (~SFX_METRIC_ITEM
);
133 if( eMapUnit
== SFX_MAPUNIT_100TH_MM
)
134 nMemberId
&= (~CONVERT_TWIPS
);
136 // DVO, OD 10.10.2003 #i18732#
137 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
138 // Thus, convert handle to Which-ID.
139 pPool
->GetDefaultItem( pPool
->GetWhich( (USHORT
)pEntry
->mnHandle
) ).QueryValue( rValue
, nMemberId
);
144 // check for needed metric translation
145 const SfxMapUnit eMapUnit
= pPool
->GetMetric((USHORT
)pEntry
->mnHandle
);
146 if(pEntry
->mnMemberId
& SFX_METRIC_ITEM
&& eMapUnit
!= SFX_MAPUNIT_100TH_MM
)
148 SvxUnoConvertToMM( eMapUnit
, rValue
);
150 // convert int32 to correct enum type if needed
151 else if ( pEntry
->mpType
->getTypeClass() == uno::TypeClass_ENUM
&& rValue
.getValueType() == ::getCppuType((const sal_Int32
*)0) )
156 rValue
.setValue( &nEnum
, *pEntry
->mpType
);
160 void SvxUnoDrawPool::putAny( SfxItemPool
* pPool
, const comphelper::PropertyMapEntry
* pEntry
, const uno::Any
& rValue
)
161 throw(beans::UnknownPropertyException
, lang::IllegalArgumentException
)
163 uno::Any
aValue( rValue
);
165 const SfxMapUnit eMapUnit
= pPool
->GetMetric((USHORT
)pEntry
->mnHandle
);
166 if(pEntry
->mnMemberId
& SFX_METRIC_ITEM
&& eMapUnit
!= SFX_MAPUNIT_100TH_MM
)
168 SvxUnoConvertFromMM( eMapUnit
, aValue
);
171 // DVO, OD 10.10.2003 #i18732#
172 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
173 // Thus, convert handle to Which-ID.
174 const sal_uInt16 nWhich
= pPool
->GetWhich( (sal_uInt16
)pEntry
->mnHandle
);
177 case OWN_ATTR_FILLBMP_MODE
:
180 drawing::BitmapMode eMode
;
181 if(!(aValue
>>= eMode
) )
184 if(!(aValue
>>= nMode
))
185 throw lang::IllegalArgumentException();
187 eMode
= (drawing::BitmapMode
)nMode
;
190 pPool
->SetPoolDefaultItem( XFillBmpStretchItem( eMode
== drawing::BitmapMode_STRETCH
) );
191 pPool
->SetPoolDefaultItem( XFillBmpTileItem( eMode
== drawing::BitmapMode_REPEAT
) );
198 ::std::auto_ptr
<SfxPoolItem
> pNewItem( pPool
->GetDefaultItem( nWhich
).Clone() );
199 BYTE nMemberId
= pEntry
->mnMemberId
& (~SFX_METRIC_ITEM
);
200 if( !pPool
|| (pPool
->GetMetric(nWhich
) == SFX_MAPUNIT_100TH_MM
) )
201 nMemberId
&= (~CONVERT_TWIPS
);
203 if( !pNewItem
->PutValue( aValue
, nMemberId
) )
204 throw lang::IllegalArgumentException();
206 pPool
->SetPoolDefaultItem( *pNewItem
);
211 void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
212 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
)
214 vos::OGuard
aGuard( Application::GetSolarMutex() );
216 SfxItemPool
* pPool
= getModelPool( sal_False
);
218 DBG_ASSERT( pPool
, "I need a SfxItemPool!" );
220 throw beans::UnknownPropertyException();
223 putAny( pPool
, *ppEntries
++, *pValues
++ );
226 void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
227 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
)
229 vos::OGuard
aGuard( Application::GetSolarMutex() );
231 SfxItemPool
* pPool
= getModelPool( sal_True
);
233 DBG_ASSERT( pPool
, "I need a SfxItemPool!" );
235 throw beans::UnknownPropertyException();
238 getAny( pPool
, *ppEntries
++, *pValue
++ );
241 void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry
** ppEntries
, beans::PropertyState
* pStates
)
242 throw(beans::UnknownPropertyException
)
244 vos::OGuard
aGuard( Application::GetSolarMutex() );
246 SfxItemPool
* pPool
= getModelPool( sal_True
);
248 if( pPool
&& pPool
!= mpDefaultsPool
)
252 // OD 13.10.2003 #i18732#
253 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
254 // Thus, convert handle to Which-ID.
255 const sal_uInt16 nWhich
= pPool
->GetWhich( ((sal_uInt16
)(*ppEntries
)->mnHandle
) );
259 case OWN_ATTR_FILLBMP_MODE
:
261 // use method <IsStaticDefaultItem(..)> instead of using
262 // probably incompatible item pool <mpDefaultPool>.
263 if ( IsStaticDefaultItem( &(pPool
->GetDefaultItem( XATTR_FILLBMP_STRETCH
)) ) ||
264 IsStaticDefaultItem( &(pPool
->GetDefaultItem( XATTR_FILLBMP_TILE
)) ) )
266 *pStates
= beans::PropertyState_DEFAULT_VALUE
;
270 *pStates
= beans::PropertyState_DIRECT_VALUE
;
275 // OD 13.10.2003 #i18732# - correction:
276 // use method <IsStaticDefaultItem(..)> instead of using probably
277 // incompatible item pool <mpDefaultPool>.
278 const SfxPoolItem
& r1
= pPool
->GetDefaultItem( nWhich
);
279 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
281 if ( IsStaticDefaultItem( &r1
) )
283 *pStates
= beans::PropertyState_DEFAULT_VALUE
;
287 *pStates
= beans::PropertyState_DIRECT_VALUE
;
297 // as long as we have no model, all properties are default
298 while( *ppEntries
++ )
299 *pStates
++ = beans::PropertyState_DEFAULT_VALUE
;
304 void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry
* pEntry
)
305 throw(beans::UnknownPropertyException
)
307 vos::OGuard
aGuard( Application::GetSolarMutex() );
309 SfxItemPool
* pPool
= getModelPool( sal_True
);
311 // OD 10.10.2003 #i18732#
312 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
313 // Thus, convert handle to Which-ID.
314 const sal_uInt16 nWhich
= pPool
->GetWhich( (USHORT
)pEntry
->mnHandle
);
315 if ( pPool
&& pPool
!= mpDefaultsPool
)
317 // OD 13.10.2003 #i18732# - use method <ResetPoolDefaultItem(..)>
318 // instead of using probably incompatible item pool <mpDefaultsPool>.
319 pPool
->ResetPoolDefaultItem( nWhich
);
323 uno::Any
SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry
* pEntry
)
324 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
)
326 vos::OGuard
aGuard( Application::GetSolarMutex() );
328 // OD 13.10.2003 #i18732# - use method <GetPoolDefaultItem(..)> instead of
329 // using probably incompatible item pool <mpDefaultsPool>
331 SfxItemPool
* pPool
= getModelPool( sal_True
);
332 const sal_uInt16 nWhich
= pPool
->GetWhich( (USHORT
)pEntry
->mnHandle
);
333 const SfxPoolItem
*pItem
= pPool
->GetPoolDefaultItem ( nWhich
);
334 pItem
->QueryValue( aAny
, pEntry
->mnMemberId
);
341 uno::Any SAL_CALL
SvxUnoDrawPool::queryInterface( const uno::Type
& rType
)
342 throw( uno::RuntimeException
)
344 return OWeakAggObject::queryInterface( rType
);
347 uno::Any SAL_CALL
SvxUnoDrawPool::queryAggregation( const uno::Type
& rType
)
348 throw(uno::RuntimeException
)
352 if( rType
== ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0) )
353 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
354 else if( rType
== ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0) )
355 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
356 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0) )
357 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
358 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0) )
359 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
360 else if( rType
== ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0) )
361 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
363 aAny
<<= OWeakAggObject::queryAggregation( rType
);
368 void SAL_CALL
SvxUnoDrawPool::acquire() throw ( )
370 OWeakAggObject::acquire();
373 void SAL_CALL
SvxUnoDrawPool::release() throw ( )
375 OWeakAggObject::release();
378 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoDrawPool::getTypes()
379 throw (uno::RuntimeException
)
381 uno::Sequence
< uno::Type
> aTypes( 6 );
382 uno::Type
* pTypes
= aTypes
.getArray();
384 *pTypes
++ = ::getCppuType((const uno::Reference
< uno::XAggregation
>*)0);
385 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0);
386 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0);
387 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
388 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0);
389 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0);
394 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoDrawPool::getImplementationId()
395 throw (uno::RuntimeException
)
397 vos::OGuard
aGuard( Application::GetSolarMutex() );
399 static uno::Sequence
< sal_Int8
> aId
;
400 if( aId
.getLength() == 0 )
403 rtl_createUuid( (sal_uInt8
*)aId
.getArray(), 0, sal_True
);
410 sal_Bool SAL_CALL
SvxUnoDrawPool::supportsService( const OUString
& ServiceName
) throw(uno::RuntimeException
)
412 uno::Sequence
< OUString
> aSNL( getSupportedServiceNames() );
413 const OUString
* pArray
= aSNL
.getConstArray();
415 for( INT32 i
= 0; i
< aSNL
.getLength(); i
++ )
416 if( pArray
[i
] == ServiceName
)
422 OUString SAL_CALL
SvxUnoDrawPool::getImplementationName() throw( uno::RuntimeException
)
424 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoDrawPool") );
427 uno::Sequence
< OUString
> SAL_CALL
SvxUnoDrawPool::getSupportedServiceNames( )
428 throw( uno::RuntimeException
)
430 uno::Sequence
< OUString
> aSNS( 1 );
431 aSNS
.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Defaults" ));