bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / unoidl / unopback.cxx
blob5ee16950eeb76730363b7c3c3a41f0e8b8869534
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/drawing/BitmapMode.hpp>
21 #include <osl/mutex.hxx>
22 #include <vcl/svapp.hxx>
23 #include <svl/itemset.hxx>
24 #include <svx/svdpool.hxx>
25 #include <comphelper/extract.hxx>
26 #include <svx/xflbstit.hxx>
27 #include <svx/xflbmtit.hxx>
28 #include <svx/svdobj.hxx>
29 #include <svx/unoprov.hxx>
30 #include <svx/unoshape.hxx>
31 #include <comphelper/serviceinfohelper.hxx>
33 #include "unopback.hxx"
34 #include "unohelp.hxx"
35 #include "drawdoc.hxx"
36 #include "unokywds.hxx"
38 using namespace ::rtl;
39 using namespace ::com::sun::star;
41 const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
43 static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
45 FILL_PROPERTIES
46 {0,0,0,0,0,0}
49 static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
50 return &aPageBackgroundPropertySet_Impl;
53 UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground );
55 SdUnoPageBackground::SdUnoPageBackground(
56 SdDrawDocument* pDoc /* = NULL */,
57 const SfxItemSet* pSet /* = NULL */) throw()
58 : mpPropSet(ImplGetPageBackgroundPropertySet()),
59 mpSet(NULL),
60 mpDoc(pDoc)
62 if( pDoc )
64 StartListening( *pDoc );
65 mpSet = new SfxItemSet( pDoc->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
67 if( pSet )
68 mpSet->Put(*pSet);
72 SdUnoPageBackground::~SdUnoPageBackground() throw()
74 if( mpDoc )
75 EndListening( *mpDoc );
77 if( mpSet )
78 delete mpSet;
81 void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
83 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
85 if( pSdrHint )
87 // delete item set if document is dying because then the pool
88 // will also die
89 if( pSdrHint->GetKind() == HINT_MODELCLEARED )
91 delete mpSet;
92 mpSet = NULL;
93 mpDoc = NULL;
99 void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) throw()
101 rSet.ClearItem();
103 if( mpSet == NULL )
105 StartListening( *pDoc );
106 mpDoc = pDoc;
108 mpSet = new SfxItemSet( *rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST );
110 if( mpPropSet->AreThereOwnUsrAnys() )
112 uno::Any* pAny;
113 PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap()->getPropertyEntries();
114 PropertyEntryVector_t::const_iterator aIt = aProperties.begin();
116 while( aIt != aProperties.end() )
118 pAny = mpPropSet->GetUsrAnyForID( aIt->nWID );
119 if( pAny )
121 OUString aPropertyName( aIt->sName );
122 switch( aIt->nWID )
124 case XATTR_FILLFLOATTRANSPARENCE :
125 case XATTR_FILLGRADIENT :
127 if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::awt::Gradient*)0) )
128 && ( aIt->nMemberId == MID_FILLGRADIENT ) )
130 setPropertyValue( aPropertyName, *pAny );
132 else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
133 ( aIt->nMemberId == MID_NAME ) )
135 setPropertyValue( aPropertyName, *pAny );
138 break;
139 case XATTR_FILLHATCH :
141 if ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::drawing::Hatch*)0) )
142 && ( aIt->nMemberId == MID_FILLHATCH ) )
144 setPropertyValue( aPropertyName, *pAny );
146 else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
147 ( aIt->nMemberId == MID_NAME ) )
149 setPropertyValue( aPropertyName, *pAny );
152 break;
153 case XATTR_FILLBITMAP :
155 if ( ( ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >*)0) ) ||
156 ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >*)0) ) ) &&
157 ( aIt->nMemberId == MID_BITMAP ) )
159 setPropertyValue( aPropertyName, *pAny );
161 else if ( ( pAny->getValueType() == ::getCppuType((const OUString*)0) ) &&
162 ( ( aIt->nMemberId == MID_NAME ) || ( aIt->nMemberId == MID_GRAFURL ) ) )
164 setPropertyValue( aPropertyName, *pAny );
167 break;
169 default:
170 setPropertyValue( aPropertyName, *pAny );
173 ++aIt;
178 rSet.Put( *mpSet );
181 // XServiceInfo
182 OUString SAL_CALL SdUnoPageBackground::getImplementationName()
183 throw(uno::RuntimeException)
185 return OUString::createFromAscii( sUNO_SdUnoPageBackground );
188 sal_Bool SAL_CALL SdUnoPageBackground::supportsService( const OUString& ServiceName )
189 throw(uno::RuntimeException)
191 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
194 uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
195 throw(uno::RuntimeException)
197 uno::Sequence< OUString > aNameSequence( 2 );
198 OUString* pStrings = aNameSequence.getArray();
200 *pStrings++ = OUString( sUNO_Service_PageBackground );
201 *pStrings = OUString( sUNO_Service_FillProperties );
203 return aNameSequence;
206 // XPropertySet
207 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
208 throw(uno::RuntimeException)
210 return mpPropSet->getPropertySetInfo();
213 void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
214 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
216 SolarMutexGuard aGuard;
218 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry( aPropertyName );
220 if( pEntry == NULL )
222 throw beans::UnknownPropertyException();
224 else
226 if( mpSet )
228 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
230 drawing::BitmapMode eMode;
231 if( aValue >>= eMode )
233 mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
234 mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
235 return;
237 throw lang::IllegalArgumentException();
240 SfxItemPool& rPool = *mpSet->GetPool();
241 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
242 aSet.Put( *mpSet );
244 if( !aSet.Count() )
245 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
247 if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
249 OUString aName;
250 if(!(aValue >>= aName ))
251 throw lang::IllegalArgumentException();
253 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
255 else
257 SvxItemPropertySet_setPropertyValue( *mpPropSet, pEntry, aValue, aSet );
260 mpSet->Put( aSet );
262 else
264 if(pEntry && pEntry->nWID)
265 mpPropSet->setPropertyValue( pEntry, aValue );
270 uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
271 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
273 SolarMutexGuard aGuard;
275 uno::Any aAny;
276 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
278 if( pEntry == NULL )
280 throw beans::UnknownPropertyException();
282 else
284 if( mpSet )
286 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
288 XFillBmpStretchItem* pStretchItem = (XFillBmpStretchItem*)mpSet->GetItem(XATTR_FILLBMP_STRETCH);
289 XFillBmpTileItem* pTileItem = (XFillBmpTileItem*)mpSet->GetItem(XATTR_FILLBMP_TILE);
291 if( pStretchItem && pTileItem )
293 if( pTileItem->GetValue() )
294 aAny <<= drawing::BitmapMode_REPEAT;
295 else if( pStretchItem->GetValue() )
296 aAny <<= drawing::BitmapMode_STRETCH;
297 else
298 aAny <<= drawing::BitmapMode_NO_REPEAT;
301 else
303 SfxItemPool& rPool = *mpSet->GetPool();
304 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
305 aSet.Put( *mpSet );
307 if( !aSet.Count() )
308 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
310 // get value from ItemSet
311 aAny = SvxItemPropertySet_getPropertyValue( *mpPropSet, pEntry, aSet );
314 else
316 if(pEntry && pEntry->nWID)
317 aAny = mpPropSet->getPropertyValue( pEntry );
320 return aAny;
323 void SAL_CALL SdUnoPageBackground::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
324 void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
325 void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
326 void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
328 // XPropertyState
329 beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
330 throw(beans::UnknownPropertyException, uno::RuntimeException)
332 SolarMutexGuard aGuard;
334 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
336 if( pEntry == NULL )
337 throw beans::UnknownPropertyException();
339 if( mpSet )
341 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
343 if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET ||
344 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET )
346 return beans::PropertyState_DIRECT_VALUE;
348 else
350 return beans::PropertyState_AMBIGUOUS_VALUE;
354 switch( mpSet->GetItemState( pEntry->nWID, sal_False ) )
356 case SFX_ITEM_READONLY:
357 case SFX_ITEM_SET:
358 return beans::PropertyState_DIRECT_VALUE;
359 case SFX_ITEM_DEFAULT:
360 return beans::PropertyState_DEFAULT_VALUE;
361 default:
362 // case SFX_ITEM_DONTCARE:
363 // case SFX_ITEM_DISABLED:
364 return beans::PropertyState_AMBIGUOUS_VALUE;
367 else
369 if( NULL == mpPropSet->GetUsrAnyForID(pEntry->nWID) )
370 return beans::PropertyState_DEFAULT_VALUE;
371 else
372 return beans::PropertyState_DIRECT_VALUE;
376 uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
377 throw(beans::UnknownPropertyException, uno::RuntimeException)
379 SolarMutexGuard aGuard;
381 sal_Int32 nCount = aPropertyName.getLength();
382 const OUString* pNames = aPropertyName.getConstArray();
384 uno::Sequence< beans::PropertyState > aPropertyStateSequence( nCount );
385 beans::PropertyState* pState = aPropertyStateSequence.getArray();
387 while( nCount-- )
388 *pState++ = getPropertyState( *pNames++ );
390 return aPropertyStateSequence;
393 void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
394 throw(beans::UnknownPropertyException, uno::RuntimeException)
396 SolarMutexGuard aGuard;
398 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(PropertyName);
400 if( pEntry == NULL )
401 throw beans::UnknownPropertyException();
403 if( mpSet )
405 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
407 mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
408 mpSet->ClearItem( XATTR_FILLBMP_TILE );
410 else
412 mpSet->ClearItem( pEntry->nWID );
417 uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
418 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
420 SolarMutexGuard aGuard;
422 const SfxItemPropertySimpleEntry* pEntry = getPropertyMapEntry(aPropertyName);
423 if( pEntry == NULL || mpSet == NULL )
424 throw beans::UnknownPropertyException();
426 uno::Any aAny;
427 if( mpSet )
429 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
431 aAny <<= drawing::BitmapMode_REPEAT;
433 else
435 SfxItemPool& rPool = *mpSet->GetPool();
436 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
437 aSet.Put( rPool.GetDefaultItem( pEntry->nWID ) );
439 aAny = SvxItemPropertySet_getPropertyValue( *mpPropSet, pEntry, aSet );
442 return aAny;
445 /** this is used because our property map is not sorted yet */
446 const SfxItemPropertySimpleEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const throw()
448 return mpPropSet->getPropertyMap()->getByName(rPropertyName);
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */