bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / unodraw / unopool.cxx
blob48dd8b4a36ac430b4f1b8677c23d67de206b32f3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/lang/XServiceInfo.hpp>
21 #include <com/sun/star/beans/PropertyState.hpp>
23 #include <comphelper/propertysetinfo.hxx>
24 #include <comphelper/servicehelper.hxx>
25 #include <osl/mutex.hxx>
26 #include <vcl/svapp.hxx>
27 #include "svx/unopool.hxx"
28 #include <svx/svdmodel.hxx>
29 #include <svx/svdpool.hxx>
30 #include <svx/unoprov.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/unoshprp.hxx>
33 #include <svx/xflbstit.hxx>
34 #include <svx/xflbmtit.hxx>
35 #include <svx/unopage.hxx>
36 #include <svx/svdetc.hxx>
37 #include <editeng/editeng.hxx>
39 #include "svx/unoapi.hxx"
40 #include <memory>
42 using namespace ::com::sun::star;
43 using namespace ::rtl;
44 using namespace ::cppu;
46 SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel, sal_Int32 nServiceId ) throw()
47 : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( nServiceId ) ), mpModel( pModel )
49 init();
52 /* deprecated */
53 SvxUnoDrawPool::SvxUnoDrawPool( SdrModel* pModel ) throw()
54 : PropertySetHelper( SvxPropertySetInfoPool::getOrCreate( SVXUNO_SERVICEID_COM_SUN_STAR_DRAWING_DEFAULTS ) ), mpModel( pModel )
56 init();
59 SvxUnoDrawPool::~SvxUnoDrawPool() throw()
61 if (mpDefaultsPool)
63 SfxItemPool* pOutlPool = mpDefaultsPool->GetSecondaryPool();
64 SfxItemPool::Free(mpDefaultsPool);
65 SfxItemPool::Free(pOutlPool);
69 void SvxUnoDrawPool::init()
71 mpDefaultsPool = new SdrItemPool();
72 SfxItemPool* pOutlPool=EditEngine::CreatePool();
73 mpDefaultsPool->SetSecondaryPool(pOutlPool);
75 SdrModel::SetTextDefaults( mpDefaultsPool, SdrEngineDefaults::GetFontHeight() );
76 mpDefaultsPool->SetDefaultMetric((SfxMapUnit)SdrEngineDefaults::GetMapUnit());
77 mpDefaultsPool->FreezeIdRanges();
80 SfxItemPool* SvxUnoDrawPool::getModelPool( sal_Bool bReadOnly ) throw()
82 if( mpModel )
84 return &mpModel->GetItemPool();
86 else
88 if( bReadOnly )
89 return mpDefaultsPool;
90 else
91 return NULL;
95 void SvxUnoDrawPool::getAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, uno::Any& rValue )
96 throw(beans::UnknownPropertyException)
98 switch( pEntry->mnHandle )
100 case OWN_ATTR_FILLBMP_MODE:
102 XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_STRETCH);
103 XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)&pPool->GetDefaultItem(XATTR_FILLBMP_TILE);
104 if( pTileItem && pTileItem->GetValue() )
106 rValue <<= drawing::BitmapMode_REPEAT;
108 else if( pStretchItem && pStretchItem->GetValue() )
110 rValue <<= drawing::BitmapMode_STRETCH;
112 else
114 rValue <<= drawing::BitmapMode_NO_REPEAT;
116 break;
118 default:
120 const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pEntry->mnHandle) : SFX_MAPUNIT_100TH_MM;
122 sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
123 if( eMapUnit == SFX_MAPUNIT_100TH_MM )
124 nMemberId &= (~CONVERT_TWIPS);
126 // DVO, OD 10.10.2003 #i18732#
127 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
128 // Thus, convert handle to Which-ID.
129 pPool->GetDefaultItem( pPool->GetWhich( (sal_uInt16)pEntry->mnHandle ) ).QueryValue( rValue, nMemberId );
134 // check for needed metric translation
135 const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
136 if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
138 SvxUnoConvertToMM( eMapUnit, rValue );
140 // convert int32 to correct enum type if needed
141 else if ( pEntry->mpType->getTypeClass() == uno::TypeClass_ENUM && rValue.getValueType() == ::getCppuType((const sal_Int32*)0) )
143 sal_Int32 nEnum;
144 rValue >>= nEnum;
146 rValue.setValue( &nEnum, *pEntry->mpType );
150 void SvxUnoDrawPool::putAny( SfxItemPool* pPool, const comphelper::PropertyMapEntry* pEntry, const uno::Any& rValue )
151 throw(beans::UnknownPropertyException, lang::IllegalArgumentException)
153 uno::Any aValue( rValue );
155 const SfxMapUnit eMapUnit = pPool->GetMetric((sal_uInt16)pEntry->mnHandle);
156 if(pEntry->mnMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM)
158 SvxUnoConvertFromMM( eMapUnit, aValue );
161 // DVO, OD 10.10.2003 #i18732#
162 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
163 // Thus, convert handle to Which-ID.
164 const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
165 switch( nWhich )
167 case OWN_ATTR_FILLBMP_MODE:
170 drawing::BitmapMode eMode;
171 if(!(aValue >>= eMode) )
173 sal_Int32 nMode = 0;
174 if(!(aValue >>= nMode))
175 throw lang::IllegalArgumentException();
177 eMode = (drawing::BitmapMode)nMode;
180 pPool->SetPoolDefaultItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
181 pPool->SetPoolDefaultItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
182 return;
184 while(0);
186 default:
188 ::std::auto_ptr<SfxPoolItem> pNewItem( pPool->GetDefaultItem( nWhich ).Clone() );
189 sal_uInt8 nMemberId = pEntry->mnMemberId & (~SFX_METRIC_ITEM);
190 if( !pPool || (pPool->GetMetric(nWhich) == SFX_MAPUNIT_100TH_MM) )
191 nMemberId &= (~CONVERT_TWIPS);
193 if( !pNewItem->PutValue( aValue, nMemberId ) )
194 throw lang::IllegalArgumentException();
196 pPool->SetPoolDefaultItem( *pNewItem );
201 void SvxUnoDrawPool::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
202 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException )
204 SolarMutexGuard aGuard;
206 SfxItemPool* pPool = getModelPool( sal_False );
208 DBG_ASSERT( pPool, "I need a SfxItemPool!" );
209 if( NULL == pPool )
210 throw beans::UnknownPropertyException();
212 while( *ppEntries )
213 putAny( pPool, *ppEntries++, *pValues++ );
216 void SvxUnoDrawPool::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
217 throw(beans::UnknownPropertyException, lang::WrappedTargetException )
219 SolarMutexGuard aGuard;
221 SfxItemPool* pPool = getModelPool( sal_True );
223 DBG_ASSERT( pPool, "I need a SfxItemPool!" );
224 if( NULL == pPool )
225 throw beans::UnknownPropertyException();
227 while( *ppEntries )
228 getAny( pPool, *ppEntries++, *pValue++ );
231 void SvxUnoDrawPool::_getPropertyStates( const comphelper::PropertyMapEntry** ppEntries, beans::PropertyState* pStates )
232 throw(beans::UnknownPropertyException )
234 SolarMutexGuard aGuard;
236 SfxItemPool* pPool = getModelPool( sal_True );
238 if( pPool && pPool != mpDefaultsPool )
240 while( *ppEntries )
242 // OD 13.10.2003 #i18732#
243 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
244 // Thus, convert handle to Which-ID.
245 const sal_uInt16 nWhich = pPool->GetWhich( ((sal_uInt16)(*ppEntries)->mnHandle) );
247 switch( nWhich )
249 case OWN_ATTR_FILLBMP_MODE:
251 // use method <IsStaticDefaultItem(..)> instead of using
252 // probably incompatible item pool <mpDefaultPool>.
253 if ( IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_STRETCH )) ) ||
254 IsStaticDefaultItem( &(pPool->GetDefaultItem( XATTR_FILLBMP_TILE )) ) )
256 *pStates = beans::PropertyState_DEFAULT_VALUE;
258 else
260 *pStates = beans::PropertyState_DIRECT_VALUE;
263 break;
264 default:
265 // OD 13.10.2003 #i18732# - correction:
266 // use method <IsStaticDefaultItem(..)> instead of using probably
267 // incompatible item pool <mpDefaultPool>.
268 const SfxPoolItem& r1 = pPool->GetDefaultItem( nWhich );
269 //const SfxPoolItem& r2 = mpDefaultPool->GetDefaultItem( nWhich );
271 if ( IsStaticDefaultItem( &r1 ) )
273 *pStates = beans::PropertyState_DEFAULT_VALUE;
275 else
277 *pStates = beans::PropertyState_DIRECT_VALUE;
281 pStates++;
282 ppEntries++;
285 else
287 // as long as we have no model, all properties are default
288 while( *ppEntries++ )
289 *pStates++ = beans::PropertyState_DEFAULT_VALUE;
290 return;
294 void SvxUnoDrawPool::_setPropertyToDefault( const comphelper::PropertyMapEntry* pEntry )
295 throw(beans::UnknownPropertyException )
297 SolarMutexGuard aGuard;
299 SfxItemPool* pPool = getModelPool( sal_True );
301 // OD 10.10.2003 #i18732#
302 // Assure, that ID is a Which-ID (it could be a Slot-ID.)
303 // Thus, convert handle to Which-ID.
304 const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
305 if ( pPool && pPool != mpDefaultsPool )
307 // OD 13.10.2003 #i18732# - use method <ResetPoolDefaultItem(..)>
308 // instead of using probably incompatible item pool <mpDefaultsPool>.
309 pPool->ResetPoolDefaultItem( nWhich );
313 uno::Any SvxUnoDrawPool::_getPropertyDefault( const comphelper::PropertyMapEntry* pEntry )
314 throw(beans::UnknownPropertyException, lang::WrappedTargetException )
316 SolarMutexGuard aGuard;
318 // OD 13.10.2003 #i18732# - use method <GetPoolDefaultItem(..)> instead of
319 // using probably incompatible item pool <mpDefaultsPool>
320 uno::Any aAny;
321 SfxItemPool* pPool = getModelPool( sal_True );
322 const sal_uInt16 nWhich = pPool->GetWhich( (sal_uInt16)pEntry->mnHandle );
323 const SfxPoolItem *pItem = pPool->GetPoolDefaultItem ( nWhich );
324 pItem->QueryValue( aAny, pEntry->mnMemberId );
326 return aAny;
329 // XInterface
331 uno::Any SAL_CALL SvxUnoDrawPool::queryInterface( const uno::Type & rType )
332 throw( uno::RuntimeException )
334 return OWeakAggObject::queryInterface( rType );
337 uno::Any SAL_CALL SvxUnoDrawPool::queryAggregation( const uno::Type & rType )
338 throw(uno::RuntimeException)
340 uno::Any aAny;
342 if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
343 aAny <<= uno::Reference< lang::XServiceInfo >(this);
344 else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
345 aAny <<= uno::Reference< lang::XTypeProvider >(this);
346 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
347 aAny <<= uno::Reference< beans::XPropertySet >(this);
348 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
349 aAny <<= uno::Reference< beans::XPropertyState >(this);
350 else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
351 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
352 else
353 aAny <<= OWeakAggObject::queryAggregation( rType );
355 return aAny;
358 void SAL_CALL SvxUnoDrawPool::acquire() throw ( )
360 OWeakAggObject::acquire();
363 void SAL_CALL SvxUnoDrawPool::release() throw ( )
365 OWeakAggObject::release();
368 uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawPool::getTypes()
369 throw (uno::RuntimeException)
371 uno::Sequence< uno::Type > aTypes( 6 );
372 uno::Type* pTypes = aTypes.getArray();
374 *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
375 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
376 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
377 *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
378 *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
379 *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
381 return aTypes;
384 namespace
386 class theSvxUnoDrawPoolImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoDrawPoolImplementationId > {};
389 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawPool::getImplementationId()
390 throw (uno::RuntimeException)
392 return theSvxUnoDrawPoolImplementationId::get().getSeq();
395 // XServiceInfo
397 sal_Bool SAL_CALL SvxUnoDrawPool::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
399 uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
400 const OUString * pArray = aSNL.getConstArray();
402 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
403 if( pArray[i] == ServiceName )
404 return sal_True;
406 return sal_False;
409 OUString SAL_CALL SvxUnoDrawPool::getImplementationName() throw( uno::RuntimeException )
411 return OUString("SvxUnoDrawPool");
414 uno::Sequence< OUString > SAL_CALL SvxUnoDrawPool::getSupportedServiceNames( )
415 throw( uno::RuntimeException )
417 uno::Sequence< OUString > aSNS( 1 );
418 aSNS.getArray()[0] = OUString("com.sun.star.drawing.Defaults" );
419 return aSNS;
422 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */