update dev300-m58
[ooovba.git] / sd / source / ui / unoidl / unopback.cxx
blobd30ba6898ff390bc2aafc0f9355d429cced8038e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unopback.cxx,v $
10 * $Revision: 1.17 $
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_sd.hxx"
33 #include <com/sun/star/drawing/BitmapMode.hpp>
34 #include <vos/mutex.hxx>
35 #include <vcl/svapp.hxx>
36 #include <svtools/itemset.hxx>
38 #include <comphelper/extract.hxx>
39 #include <rtl/uuid.h>
40 #include <rtl/memory.h>
41 #include <svx/xflbstit.hxx>
42 #include <svx/xflbmtit.hxx>
43 #include <svx/svdobj.hxx>
44 #include <svx/unoprov.hxx>
45 #include <svx/unoshape.hxx>
47 #include "unopback.hxx"
48 #include "unohelp.hxx"
49 #include "drawdoc.hxx"
50 #include "unokywds.hxx"
52 using namespace ::rtl;
53 using namespace ::vos;
54 using namespace ::com::sun::star;
56 const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
58 static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
60 FILL_PROPERTIES
61 {0,0,0,0,0,0}
64 static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl );
65 return &aPageBackgroundPropertySet_Impl;
68 UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
70 SdUnoPageBackground::SdUnoPageBackground( SdDrawDocument* pDoc /* = NULL */, SdrObject* pObj /* = NULL */ ) throw()
71 : mpPropSet( ImplGetPageBackgroundPropertySet() ), mpSet( NULL ), mpDoc( pDoc )
73 if( pDoc )
75 StartListening( *pDoc );
76 mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
78 if( pObj )
79 mpSet->Put(pObj->GetMergedItemSet());
83 SdUnoPageBackground::SdUnoPageBackground( SdDrawDocument* pDoc, const SfxItemSet* pSet ) throw()
84 : mpPropSet( ImplGetPageBackgroundPropertySet() ), mpSet( NULL ), mpDoc( pDoc )
86 if( pDoc )
88 StartListening( *pDoc );
89 mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
91 if( pSet )
92 mpSet->Put(*pSet);
96 SdUnoPageBackground::~SdUnoPageBackground() throw()
98 if( mpDoc )
99 EndListening( *mpDoc );
101 if( mpSet )
102 delete mpSet;
105 void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
107 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
109 if( pSdrHint )
111 // delete item set if document is dying because then the pool
112 // will also die
113 if( pSdrHint->GetKind() == HINT_MODELCLEARED )
115 delete mpSet;
116 mpSet = NULL;
117 mpDoc = NULL;
123 void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
125 rSet.ClearItem();
127 if( mpSet == NULL )
129 StartListening( *pDoc );
130 mpDoc = pDoc;
132 mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
134 if( mpPropSet->AreThereOwnUsrAnys() )
136 uno::Any* pAny;
137 PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap()->getPropertyEntries();
138 PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
140 while( aIt != aProperties.end() )
142 pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
143 if( pAny )
145 OUString aPropertyName( aIt->sName );
146 switch( aIt->nWID )
148 case XATTR_FILLFLOATTRANSPARENCE :
149 case XATTR_FILLGRADIENT :
151 if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::awt::Gradient*)0) )
152 && ( aIt->nMemberId == MID_FILLGRADIENT ) )
154 setPropertyValue( aPropertyName, *pAny );
156 else if ( ( pAny->getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) &&
157 ( aIt->nMemberId == MID_NAME ) )
159 setPropertyValue( aPropertyName, *pAny );
162 break;
163 case XATTR_FILLHATCH :
165 if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::drawing::Hatch*)0) )
166 && ( aIt->nMemberId == MID_FILLHATCH ) )
168 setPropertyValue( aPropertyName, *pAny );
170 else if ( ( pAny->getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) &&
171 ( aIt->nMemberId == MID_NAME ) )
173 setPropertyValue( aPropertyName, *pAny );
176 break;
177 case XATTR_FILLBITMAP :
179 if ( ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >*)0) ) ||
180 ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >*)0) ) ) &&
181 ( aIt->nMemberId == MID_BITMAP ) )
183 setPropertyValue( aPropertyName, *pAny );
185 else if ( ( pAny->getValueType() == ::getCppuType((const ::rtl::OUString*)0) ) &&
186 ( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
188 setPropertyValue( aPropertyName, *pAny );
191 break;
193 default:
194 setPropertyValue( aPropertyName, *pAny );
197 ++aIt;
202 rSet.Put( *mpSet );
205 // XServiceInfo
206 OUString SAL_CALL SdUnoPageBackground::getImplementationName()
207 throw(uno::RuntimeException)
209 return OUString::createFromAscii( sUNO_SdUnoPageBackground );
212 sal_Bool SAL_CALL SdUnoPageBackground::supportsService( const OUString& ServiceName )
213 throw(uno::RuntimeException)
215 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
218 uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
219 throw(uno::RuntimeException)
221 uno::Sequence< OUString > aNameSequence( 2 );
222 OUString* pStrings = aNameSequence.getArray();
224 *pStrings++ = OUString( RTL_CONSTASCII_USTRINGPARAM( sUNO_Service_PageBackground ) );
225 *pStrings = OUString( RTL_CONSTASCII_USTRINGPARAM( sUNO_Service_FillProperties ) );
227 return aNameSequence;
230 // XPropertySet
231 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
232 throw(uno::RuntimeException)
234 return mpPropSet->getPropertySetInfo();
237 void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
238 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
240 OGuard aGuard( Application::GetSolarMutex() );
242 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
244 if( pEntry == NULL )
246 throw beans::UnknownPropertyException();
248 else
250 if( mpSet )
252 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
254 drawing::BitmapMode eMode;
255 if( aValue >>= eMode )
257 mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
258 mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
259 return;
261 throw lang::IllegalArgumentException();
264 SfxItemPool& rPool = *mpSet->GetPool();
265 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
266 aSet.Put( *mpSet );
268 if( !aSet.Count() )
269 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
271 if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
273 OUString aName;
274 if(!(aValue >>= aName ))
275 throw lang::IllegalArgumentException();
277 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
279 else
281 mpPropSet->setPropertyValue( pEntry, aValue, aSet );
284 mpSet->Put( aSet );
286 else
288 if(pEntry && pEntry->nWID)
289 mpPropSet->setPropertyValue( pEntry, aValue );
294 uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
295 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
297 OGuard aGuard( Application::GetSolarMutex() );
299 uno::Any aAny;
300 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
302 if( pEntry == NULL )
304 throw beans::UnknownPropertyException();
306 else
308 if( mpSet )
310 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
312 XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)mpSet->GetItem(XATTR_FILLBMP_STRETCH);
313 XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)mpSet->GetItem(XATTR_FILLBMP_TILE);
315 if( pStretchItem && pTileItem )
317 if( pTileItem->GetValue() )
318 aAny <<= drawing::BitmapMode_REPEAT;
319 else if( pStretchItem->GetValue() )
320 aAny <<= drawing::BitmapMode_STRETCH;
321 else
322 aAny <<= drawing::BitmapMode_NO_REPEAT;
325 else
327 SfxItemPool& rPool = *mpSet->GetPool();
328 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
329 aSet.Put( *mpSet );
331 if( !aSet.Count() )
332 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
334 // Hole Wert aus ItemSet
335 aAny = mpPropSet->getPropertyValue( pEntry, aSet );
338 else
340 if(pEntry && pEntry->nWID)
341 aAny = mpPropSet->getPropertyValue( pEntry );
344 return aAny;
347 void SAL_CALL SdUnoPageBackground::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
348 void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
349 void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
350 void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
352 // XPropertyState
353 beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
354 throw(beans::UnknownPropertyException, uno::RuntimeException)
356 OGuard aGuard( Application::GetSolarMutex() );
358 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
360 if( pEntry == NULL )
361 throw beans::UnknownPropertyException();
363 if( mpSet )
365 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
367 if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
368 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
370 return beans::PropertyState_DIRECT_VALUE;
372 else
374 return beans::PropertyState_AMBIGUOUS_VALUE;
378 switch( mpSet->GetItemState( pEntry->nWID, sal_False ) )
380 case SFX_ITEM_READONLY:
381 case SFX_ITEM_SET:
382 return beans::PropertyState_DIRECT_VALUE;
383 case SFX_ITEM_DEFAULT:
384 return beans::PropertyState_DEFAULT_VALUE;
385 default:
386 // case SFX_ITEM_DONTCARE:
387 // case SFX_ITEM_DISABLED:
388 return beans::PropertyState_AMBIGUOUS_VALUE;
391 else
393 if( NULL == mpPropSet->GetUsrAnyForID(pEntry->nWID) )
394 return beans::PropertyState_DEFAULT_VALUE;
395 else
396 return beans::PropertyState_DIRECT_VALUE;
400 uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
401 throw(beans::UnknownPropertyException, uno::RuntimeException)
403 OGuard aGuard( Application::GetSolarMutex() );
405 sal_Int32 nCount = aPropertyName.getLength();
406 const OUString* pNames = aPropertyName.getConstArray();
408 uno::Sequence< beans::PropertyState > aPropertyStateSequence( nCount );
409 beans::PropertyState* pState = aPropertyStateSequence.getArray();
411 while( nCount-- )
412 *pState++ = getPropertyState( *pNames++ );
414 return aPropertyStateSequence;
417 void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
418 throw(beans::UnknownPropertyException, uno::RuntimeException)
420 OGuard aGuard( Application::GetSolarMutex() );
422 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
424 if( pEntry == NULL )
425 throw beans::UnknownPropertyException();
427 if( mpSet )
429 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
431 mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
432 mpSet->ClearItem( XATTR_FILLBMP_TILE );
434 else
436 mpSet->ClearItem( pEntry->nWID );
441 uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
442 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
444 OGuard aGuard( Application::GetSolarMutex() );
446 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(aPropertyName);
447 if( pEntry == NULL || mpSet == NULL )
448 throw beans::UnknownPropertyException();
450 uno::Any aAny;
451 if( mpSet )
453 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
455 aAny <<= drawing::BitmapMode_REPEAT;
457 else
459 SfxItemPool& rPool = *mpSet->GetPool();
460 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
461 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
463 aAny = mpPropSet->getPropertyValue( pEntry, aSet );
466 return aAny;
469 /** this is used because our property map is not sorted yet */
470 const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
472 return mpPropSet->getPropertyMap()->getByName(rPropertyName);