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: unopback.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_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>
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
[] =
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
)
75 StartListening( *pDoc
);
76 mpSet
= new SfxItemSet( pDoc
->GetPool(), XATTR_FILL_FIRST
, XATTR_FILL_LAST
);
79 mpSet
->Put(pObj
->GetMergedItemSet());
83 SdUnoPageBackground::SdUnoPageBackground( SdDrawDocument
* pDoc
, const SfxItemSet
* pSet
) throw()
84 : mpPropSet( ImplGetPageBackgroundPropertySet() ), mpSet( NULL
), mpDoc( pDoc
)
88 StartListening( *pDoc
);
89 mpSet
= new SfxItemSet( pDoc
->GetPool(), XATTR_FILL_FIRST
, XATTR_FILL_LAST
);
96 SdUnoPageBackground::~SdUnoPageBackground() throw()
99 EndListening( *mpDoc
);
105 void SdUnoPageBackground::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
107 const SdrHint
* pSdrHint
= PTR_CAST( SdrHint
, &rHint
);
111 // delete item set if document is dying because then the pool
113 if( pSdrHint
->GetKind() == HINT_MODELCLEARED
)
123 void SdUnoPageBackground::fillItemSet( SdDrawDocument
* pDoc
, SfxItemSet
& rSet
) throw()
129 StartListening( *pDoc
);
132 mpSet
= new SfxItemSet( *rSet
.GetPool(), XATTR_FILL_FIRST
, XATTR_FILL_LAST
);
134 if( mpPropSet
->AreThereOwnUsrAnys() )
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
);
145 OUString
aPropertyName( aIt
->sName
);
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
);
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
);
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
);
194 setPropertyValue( aPropertyName
, *pAny
);
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
;
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
);
246 throw beans::UnknownPropertyException();
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
) );
261 throw lang::IllegalArgumentException();
264 SfxItemPool
& rPool
= *mpSet
->GetPool();
265 SfxItemSet
aSet( rPool
, pEntry
->nWID
, pEntry
->nWID
);
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
) )
274 if(!(aValue
>>= aName
))
275 throw lang::IllegalArgumentException();
277 SvxShape::SetFillAttribute( pEntry
->nWID
, aName
, aSet
);
281 mpPropSet
->setPropertyValue( pEntry
, aValue
, aSet
);
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() );
300 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry(PropertyName
);
304 throw beans::UnknownPropertyException();
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
;
322 aAny
<<= drawing::BitmapMode_NO_REPEAT
;
327 SfxItemPool
& rPool
= *mpSet
->GetPool();
328 SfxItemSet
aSet( rPool
, pEntry
->nWID
, pEntry
->nWID
);
332 aSet
.Put( rPool
.GetDefaultItem( pEntry
->nWID
) );
334 // Hole Wert aus ItemSet
335 aAny
= mpPropSet
->getPropertyValue( pEntry
, aSet
);
340 if(pEntry
&& pEntry
->nWID
)
341 aAny
= mpPropSet
->getPropertyValue( pEntry
);
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
) {}
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
);
361 throw beans::UnknownPropertyException();
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
;
374 return beans::PropertyState_AMBIGUOUS_VALUE
;
378 switch( mpSet
->GetItemState( pEntry
->nWID
, sal_False
) )
380 case SFX_ITEM_READONLY
:
382 return beans::PropertyState_DIRECT_VALUE
;
383 case SFX_ITEM_DEFAULT
:
384 return beans::PropertyState_DEFAULT_VALUE
;
386 // case SFX_ITEM_DONTCARE:
387 // case SFX_ITEM_DISABLED:
388 return beans::PropertyState_AMBIGUOUS_VALUE
;
393 if( NULL
== mpPropSet
->GetUsrAnyForID(pEntry
->nWID
) )
394 return beans::PropertyState_DEFAULT_VALUE
;
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();
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
);
425 throw beans::UnknownPropertyException();
429 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
431 mpSet
->ClearItem( XATTR_FILLBMP_STRETCH
);
432 mpSet
->ClearItem( XATTR_FILLBMP_TILE
);
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();
453 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
455 aAny
<<= drawing::BitmapMode_REPEAT
;
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
);
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
);