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 <vcl/svapp.hxx>
22 #include <svl/itemset.hxx>
23 #include <svx/svdpool.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <svx/xflbstit.hxx>
26 #include <svx/xflbmtit.hxx>
27 #include <svx/svdobj.hxx>
28 #include <svx/unoprov.hxx>
29 #include <svx/unoshape.hxx>
30 #include <svx/unoshprp.hxx>
32 #include "unopback.hxx"
33 #include <drawdoc.hxx>
34 #include <unokywds.hxx>
36 using namespace ::com::sun::star
;
38 const SvxItemPropertySet
* ImplGetPageBackgroundPropertySet()
40 static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl
[] =
43 { OUString(), 0, css::uno::Type(), 0, 0 }
46 static SvxItemPropertySet
aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl
, SdrObject::GetGlobalDrawObjectItemPool() );
47 return &aPageBackgroundPropertySet_Impl
;
50 UNO3_GETIMPLEMENTATION_IMPL( SdUnoPageBackground
);
52 SdUnoPageBackground::SdUnoPageBackground(
53 SdDrawDocument
* pDoc
/* = NULL */,
54 const SfxItemSet
* pSet
/* = NULL */)
55 : mpPropSet(ImplGetPageBackgroundPropertySet()),
60 StartListening( *pDoc
);
61 mpSet
= std::make_unique
<SfxItemSet
>( pDoc
->GetPool(), svl::Items
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
>{} );
68 SdUnoPageBackground::~SdUnoPageBackground() throw()
73 EndListening( *mpDoc
);
76 void SdUnoPageBackground::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
78 if (rHint
.GetId() != SfxHintId::ThisIsAnSdrHint
)
80 const SdrHint
* pSdrHint
= static_cast<const SdrHint
*>( &rHint
);
82 // delete item set if document is dying because then the pool
84 if( pSdrHint
->GetKind() == SdrHintKind::ModelCleared
)
91 void SdUnoPageBackground::fillItemSet( SdDrawDocument
* pDoc
, SfxItemSet
& rSet
) throw()
95 if( mpSet
== nullptr )
97 StartListening( *pDoc
);
100 mpSet
= std::make_unique
<SfxItemSet
>( *rSet
.GetPool(), svl::Items
<XATTR_FILL_FIRST
, XATTR_FILL_LAST
>{} );
102 if( mpPropSet
->AreThereOwnUsrAnys() )
104 PropertyEntryVector_t aProperties
= mpPropSet
->getPropertyMap().getPropertyEntries();
106 for( const auto& rProp
: aProperties
)
108 uno::Any
* pAny
= mpPropSet
->GetUsrAnyForID( rProp
.nWID
);
111 OUString
aPropertyName( rProp
.sName
);
114 case XATTR_FILLFLOATTRANSPARENCE
:
115 case XATTR_FILLGRADIENT
:
117 if ( ( pAny
->getValueType() == ::cppu::UnoType
< css::awt::Gradient
>::get() )
118 && ( rProp
.nMemberId
== MID_FILLGRADIENT
) )
120 setPropertyValue( aPropertyName
, *pAny
);
122 else if ( ( pAny
->getValueType() == ::cppu::UnoType
<OUString
>::get() ) &&
123 ( rProp
.nMemberId
== MID_NAME
) )
125 setPropertyValue( aPropertyName
, *pAny
);
129 case XATTR_FILLHATCH
:
131 if ( ( pAny
->getValueType() == ::cppu::UnoType
< css::drawing::Hatch
>::get() )
132 && ( rProp
.nMemberId
== MID_FILLHATCH
) )
134 setPropertyValue( aPropertyName
, *pAny
);
136 else if ( ( pAny
->getValueType() == ::cppu::UnoType
<OUString
>::get() ) &&
137 ( rProp
.nMemberId
== MID_NAME
) )
139 setPropertyValue( aPropertyName
, *pAny
);
143 case XATTR_FILLBITMAP
:
145 if (rProp
.nMemberId
== MID_BITMAP
&&
146 (pAny
->getValueType() == cppu::UnoType
<css::awt::XBitmap
>::get() ||
147 pAny
->getValueType() == cppu::UnoType
<css::graphic::XGraphic
>::get()))
149 setPropertyValue( aPropertyName
, *pAny
);
151 else if (pAny
->getValueType() == ::cppu::UnoType
<OUString
>::get() && rProp
.nMemberId
== MID_NAME
)
153 setPropertyValue( aPropertyName
, *pAny
);
159 setPropertyValue( aPropertyName
, *pAny
);
170 OUString SAL_CALL
SdUnoPageBackground::getImplementationName()
172 return OUString("SdUnoPageBackground");
175 sal_Bool SAL_CALL
SdUnoPageBackground::supportsService( const OUString
& ServiceName
)
177 return cppu::supportsService( this, ServiceName
);
180 uno::Sequence
< OUString
> SAL_CALL
SdUnoPageBackground::getSupportedServiceNames()
182 uno::Sequence
< OUString
> aNameSequence( 2 );
183 OUString
* pStrings
= aNameSequence
.getArray();
185 *pStrings
++ = sUNO_Service_PageBackground
;
186 *pStrings
= sUNO_Service_FillProperties
;
188 return aNameSequence
;
192 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
SdUnoPageBackground::getPropertySetInfo()
194 return mpPropSet
->getPropertySetInfo();
197 void SAL_CALL
SdUnoPageBackground::setPropertyValue( const OUString
& aPropertyName
, const uno::Any
& aValue
)
199 SolarMutexGuard aGuard
;
201 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry( aPropertyName
);
203 if( pEntry
== nullptr )
205 throw beans::UnknownPropertyException( aPropertyName
, static_cast<cppu::OWeakObject
*>(this));
210 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
212 drawing::BitmapMode eMode
;
213 if( aValue
>>= eMode
)
215 mpSet
->Put( XFillBmpStretchItem( eMode
== drawing::BitmapMode_STRETCH
) );
216 mpSet
->Put( XFillBmpTileItem( eMode
== drawing::BitmapMode_REPEAT
) );
219 throw lang::IllegalArgumentException();
222 SfxItemPool
& rPool
= *mpSet
->GetPool();
223 SfxItemSet
aSet( rPool
, {{pEntry
->nWID
, pEntry
->nWID
}});
227 aSet
.Put( rPool
.GetDefaultItem( pEntry
->nWID
) );
229 if( pEntry
->nMemberId
== MID_NAME
&& ( pEntry
->nWID
== XATTR_FILLBITMAP
|| pEntry
->nWID
== XATTR_FILLGRADIENT
|| pEntry
->nWID
== XATTR_FILLHATCH
|| pEntry
->nWID
== XATTR_FILLFLOATTRANSPARENCE
) )
232 if(!(aValue
>>= aName
))
233 throw lang::IllegalArgumentException();
235 SvxShape::SetFillAttribute( pEntry
->nWID
, aName
, aSet
);
239 SvxItemPropertySet_setPropertyValue( pEntry
, aValue
, aSet
);
247 mpPropSet
->setPropertyValue( pEntry
, aValue
);
251 uno::Any SAL_CALL
SdUnoPageBackground::getPropertyValue( const OUString
& PropertyName
)
253 SolarMutexGuard aGuard
;
256 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry(PropertyName
);
258 if( pEntry
== nullptr )
260 throw beans::UnknownPropertyException( PropertyName
, static_cast<cppu::OWeakObject
*>(this));
265 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
267 const XFillBmpStretchItem
* pStretchItem
= mpSet
->GetItem
<XFillBmpStretchItem
>(XATTR_FILLBMP_STRETCH
);
268 const XFillBmpTileItem
* pTileItem
= mpSet
->GetItem
<XFillBmpTileItem
>(XATTR_FILLBMP_TILE
);
270 if( pStretchItem
&& pTileItem
)
272 if( pTileItem
->GetValue() )
273 aAny
<<= drawing::BitmapMode_REPEAT
;
274 else if( pStretchItem
->GetValue() )
275 aAny
<<= drawing::BitmapMode_STRETCH
;
277 aAny
<<= drawing::BitmapMode_NO_REPEAT
;
282 SfxItemPool
& rPool
= *mpSet
->GetPool();
283 SfxItemSet
aSet( rPool
, {{pEntry
->nWID
, pEntry
->nWID
}});
287 aSet
.Put( rPool
.GetDefaultItem( pEntry
->nWID
) );
289 // get value from ItemSet
290 aAny
= SvxItemPropertySet_getPropertyValue( pEntry
, aSet
);
296 aAny
= mpPropSet
->getPropertyValue( pEntry
);
301 void SAL_CALL
SdUnoPageBackground::addPropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) {}
302 void SAL_CALL
SdUnoPageBackground::removePropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) {}
303 void SAL_CALL
SdUnoPageBackground::addVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) {}
304 void SAL_CALL
SdUnoPageBackground::removeVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) {}
307 beans::PropertyState SAL_CALL
SdUnoPageBackground::getPropertyState( const OUString
& PropertyName
)
309 SolarMutexGuard aGuard
;
311 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry(PropertyName
);
313 if( pEntry
== nullptr )
314 throw beans::UnknownPropertyException( PropertyName
, static_cast<cppu::OWeakObject
*>(this));
318 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
320 if( mpSet
->GetItemState( XATTR_FILLBMP_STRETCH
, false ) == SfxItemState::SET
||
321 mpSet
->GetItemState( XATTR_FILLBMP_TILE
, false ) == SfxItemState::SET
)
323 return beans::PropertyState_DIRECT_VALUE
;
327 return beans::PropertyState_AMBIGUOUS_VALUE
;
331 switch( mpSet
->GetItemState( pEntry
->nWID
, false ) )
333 case SfxItemState::READONLY
:
334 case SfxItemState::SET
:
335 return beans::PropertyState_DIRECT_VALUE
;
336 case SfxItemState::DEFAULT
:
337 return beans::PropertyState_DEFAULT_VALUE
;
339 // case SfxItemState::DONTCARE:
340 // case SfxItemState::DISABLED:
341 return beans::PropertyState_AMBIGUOUS_VALUE
;
346 if( nullptr == mpPropSet
->GetUsrAnyForID(pEntry
->nWID
) )
347 return beans::PropertyState_DEFAULT_VALUE
;
349 return beans::PropertyState_DIRECT_VALUE
;
353 uno::Sequence
< beans::PropertyState
> SAL_CALL
SdUnoPageBackground::getPropertyStates( const uno::Sequence
< OUString
>& aPropertyName
)
355 SolarMutexGuard aGuard
;
357 sal_Int32 nCount
= aPropertyName
.getLength();
358 const OUString
* pNames
= aPropertyName
.getConstArray();
360 uno::Sequence
< beans::PropertyState
> aPropertyStateSequence( nCount
);
361 beans::PropertyState
* pState
= aPropertyStateSequence
.getArray();
364 *pState
++ = getPropertyState( *pNames
++ );
366 return aPropertyStateSequence
;
369 void SAL_CALL
SdUnoPageBackground::setPropertyToDefault( const OUString
& PropertyName
)
371 SolarMutexGuard aGuard
;
373 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry(PropertyName
);
375 if( pEntry
== nullptr )
376 throw beans::UnknownPropertyException( PropertyName
, static_cast<cppu::OWeakObject
*>(this));
380 if( pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
382 mpSet
->ClearItem( XATTR_FILLBMP_STRETCH
);
383 mpSet
->ClearItem( XATTR_FILLBMP_TILE
);
387 mpSet
->ClearItem( pEntry
->nWID
);
392 uno::Any SAL_CALL
SdUnoPageBackground::getPropertyDefault( const OUString
& aPropertyName
)
394 SolarMutexGuard aGuard
;
396 const SfxItemPropertySimpleEntry
* pEntry
= getPropertyMapEntry(aPropertyName
);
397 if( pEntry
== nullptr || mpSet
== nullptr )
398 throw beans::UnknownPropertyException( aPropertyName
, static_cast<cppu::OWeakObject
*>(this));
401 if (pEntry
->nWID
== OWN_ATTR_FILLBMP_MODE
)
403 aAny
<<= drawing::BitmapMode_REPEAT
;
407 SfxItemPool
& rPool
= *mpSet
->GetPool();
408 SfxItemSet
aSet(rPool
, { { pEntry
->nWID
, pEntry
->nWID
} });
409 aSet
.Put(rPool
.GetDefaultItem(pEntry
->nWID
));
411 aAny
= SvxItemPropertySet_getPropertyValue(pEntry
, aSet
);
416 /** this is used because our property map is not sorted yet */
417 const SfxItemPropertySimpleEntry
* SdUnoPageBackground::getPropertyMapEntry( const OUString
& rPropertyName
) const throw()
419 return mpPropSet
->getPropertyMap().getByName(rPropertyName
);
422 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */