1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
[] =
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()),
64 StartListening( *pDoc
);
65 mpSet
= new SfxItemSet( pDoc
->GetPool(), XATTR_FILL_FIRST
, XATTR_FILL_LAST
);
72 SdUnoPageBackground::~SdUnoPageBackground() throw()
75 EndListening( *mpDoc
);
81 void SdUnoPageBackground::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
83 const SdrHint
* pSdrHint
= PTR_CAST( SdrHint
, &rHint
);
87 // delete item set if document is dying because then the pool
89 if( pSdrHint
->GetKind() == HINT_MODELCLEARED
)
99 void SdUnoPageBackground::fillItemSet( SdDrawDocument
* pDoc
, SfxItemSet
& rSet
) throw()
105 StartListening( *pDoc
);
108 mpSet
= new SfxItemSet( *rSet
.GetPool(), XATTR_FILL_FIRST
, XATTR_FILL_LAST
);
110 if( mpPropSet
->AreThereOwnUsrAnys() )
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
);
121 OUString
aPropertyName( aIt
->sName
);
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
);
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
);
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
);
170 setPropertyValue( aPropertyName
, *pAny
);
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
;
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
);
222 throw beans::UnknownPropertyException();
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
) );
237 throw lang::IllegalArgumentException();
240 SfxItemPool
& rPool
= *mpSet
->GetPool();
241 SfxItemSet
aSet( rPool
, pEntry
->nWID
, pEntry
->nWID
);
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
) )
250 if(!(aValue
>>= aName
))
251 throw lang::IllegalArgumentException();
253 SvxShape::SetFillAttribute( pEntry
->nWID
, aName
, aSet
);
257 SvxItemPropertySet_setPropertyValue( *mpPropSet
, pEntry
, aValue
, aSet
);
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
;
276 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry(PropertyName
);
280 throw beans::UnknownPropertyException();
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
;
298 aAny
<<= drawing::BitmapMode_NO_REPEAT
;
303 SfxItemPool
& rPool
= *mpSet
->GetPool();
304 SfxItemSet
aSet( rPool
, pEntry
->nWID
, pEntry
->nWID
);
308 aSet
.Put( rPool
.GetDefaultItem( pEntry
->nWID
) );
310 // get value from ItemSet
311 aAny
= SvxItemPropertySet_getPropertyValue( *mpPropSet
, pEntry
, aSet
);
316 if(pEntry
&& pEntry
->nWID
)
317 aAny
= mpPropSet
->getPropertyValue( pEntry
);
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
) {}
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
);
337 throw beans::UnknownPropertyException();
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
;
350 return beans::PropertyState_AMBIGUOUS_VALUE
;
354 switch( mpSet
->GetItemState( pEntry
->nWID
, sal_False
) )
356 case SFX_ITEM_READONLY
:
358 return beans::PropertyState_DIRECT_VALUE
;
359 case SFX_ITEM_DEFAULT
:
360 return beans::PropertyState_DEFAULT_VALUE
;
362 // case SFX_ITEM_DONTCARE:
363 // case SFX_ITEM_DISABLED:
364 return beans::PropertyState_AMBIGUOUS_VALUE
;
369 if( NULL
== mpPropSet
->GetUsrAnyForID(pEntry
->nWID
) )
370 return beans::PropertyState_DEFAULT_VALUE
;
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();
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
);
401 throw beans::UnknownPropertyException();
405 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
407 mpSet
->ClearItem( XATTR_FILLBMP_STRETCH
);
408 mpSet
->ClearItem( XATTR_FILLBMP_TILE
);
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();
429 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
431 aAny
<<= drawing::BitmapMode_REPEAT
;
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
);
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: */