tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / unoidl / unopback.cxx
blobc4fc95421dc43721c14c6b22bf250f7fb2ca1ee5
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 <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/unoshape.hxx>
29 #include <svx/unoshprp.hxx>
31 #include "unopback.hxx"
32 #include <drawdoc.hxx>
33 #include <unokywds.hxx>
35 using namespace ::com::sun::star;
37 const SvxItemPropertySet* ImplGetPageBackgroundPropertySet()
39 static const SfxItemPropertyMapEntry aPageBackgroundPropertyMap_Impl[] =
41 FILL_PROPERTIES
44 static SvxItemPropertySet aPageBackgroundPropertySet_Impl( aPageBackgroundPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
45 return &aPageBackgroundPropertySet_Impl;
48 SdUnoPageBackground::SdUnoPageBackground(
49 SdDrawDocument* pDoc /* = NULL */,
50 const SfxItemSet* pSet /* = NULL */)
51 : mpPropSet(ImplGetPageBackgroundPropertySet()),
52 mpDoc(pDoc)
54 if( pDoc )
56 StartListening( *pDoc );
57 mpSet = std::make_unique<SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST>>( pDoc->GetPool() );
59 if( pSet )
60 mpSet->Put(*pSet);
64 SdUnoPageBackground::~SdUnoPageBackground() noexcept
66 SolarMutexGuard g;
68 if( mpDoc )
69 EndListening( *mpDoc );
72 void SdUnoPageBackground::Notify( SfxBroadcaster&, const SfxHint& rHint )
74 if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
75 return;
76 const SdrHint* pSdrHint = static_cast<const SdrHint*>( &rHint );
78 // delete item set if document is dying because then the pool
79 // will also die
80 if( pSdrHint->GetKind() == SdrHintKind::ModelCleared )
82 mpSet.reset();
83 mpDoc = nullptr;
87 void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet )
89 rSet.ClearItem();
91 if( mpSet == nullptr )
93 StartListening( *pDoc );
94 mpDoc = pDoc;
96 mpSet = std::make_unique<SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST>>( *rSet.GetPool() );
98 if( maUsrAnys.AreThereOwnUsrAnys() )
100 for( const auto & rPair : mpPropSet->getPropertyMap().getPropertyEntries() )
102 const SfxItemPropertyMapEntry* pProp = rPair.second;
103 uno::Any* pAny = maUsrAnys.GetUsrAnyForID( *pProp );
104 if( pAny )
106 const OUString & aPropertyName = pProp->aName;
107 switch( pProp->nWID )
109 case XATTR_FILLFLOATTRANSPARENCE :
110 case XATTR_FILLGRADIENT :
112 if ( ( pAny->getValueType() == ::cppu::UnoType< css::awt::Gradient>::get() )
113 && ( pProp->nMemberId == MID_FILLGRADIENT ) )
115 setPropertyValue( aPropertyName, *pAny );
117 else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
118 ( pProp->nMemberId == MID_NAME ) )
120 setPropertyValue( aPropertyName, *pAny );
123 break;
124 case XATTR_FILLHATCH :
126 if ( ( pAny->getValueType() == ::cppu::UnoType< css::drawing::Hatch>::get() )
127 && ( pProp->nMemberId == MID_FILLHATCH ) )
129 setPropertyValue( aPropertyName, *pAny );
131 else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) &&
132 ( pProp->nMemberId == MID_NAME ) )
134 setPropertyValue( aPropertyName, *pAny );
137 break;
138 case XATTR_FILLBITMAP :
140 if (pProp->nMemberId == MID_BITMAP &&
141 (pAny->getValueTypeClass() == css::uno::TypeClass_INTERFACE))
143 setPropertyValue( aPropertyName, *pAny );
145 else if (pAny->getValueType() == ::cppu::UnoType<OUString>::get() && pProp->nMemberId == MID_NAME)
147 setPropertyValue( aPropertyName, *pAny );
150 break;
152 default:
153 setPropertyValue( aPropertyName, *pAny );
160 rSet.Put( *mpSet );
163 // XServiceInfo
164 OUString SAL_CALL SdUnoPageBackground::getImplementationName()
166 return u"SdUnoPageBackground"_ustr;
169 sal_Bool SAL_CALL SdUnoPageBackground::supportsService( const OUString& ServiceName )
171 return cppu::supportsService( this, ServiceName );
174 uno::Sequence< OUString > SAL_CALL SdUnoPageBackground::getSupportedServiceNames()
176 return { sUNO_Service_PageBackground, sUNO_Service_FillProperties };
179 // XPropertySet
180 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdUnoPageBackground::getPropertySetInfo()
182 return mpPropSet->getPropertySetInfo();
185 void SAL_CALL SdUnoPageBackground::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
187 SolarMutexGuard aGuard;
189 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry( aPropertyName );
191 if( pEntry == nullptr )
193 throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));
196 if( mpSet )
198 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
200 drawing::BitmapMode eMode;
201 if( aValue >>= eMode )
203 mpSet->Put( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
204 mpSet->Put( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
205 return;
207 throw lang::IllegalArgumentException();
210 SfxItemPool& rPool = *mpSet->GetPool();
211 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
212 aSet.Put( *mpSet );
214 if( !aSet.Count() )
215 aSet.Put( rPool.GetUserOrPoolDefaultItem( pEntry->nWID ) );
217 if( pEntry->nMemberId == MID_NAME && ( pEntry->nWID == XATTR_FILLBITMAP || pEntry->nWID == XATTR_FILLGRADIENT || pEntry->nWID == XATTR_FILLHATCH || pEntry->nWID == XATTR_FILLFLOATTRANSPARENCE ) )
219 OUString aName;
220 if(!(aValue >>= aName ))
221 throw lang::IllegalArgumentException();
223 SvxShape::SetFillAttribute( pEntry->nWID, aName, aSet );
225 else
227 SvxItemPropertySet_setPropertyValue( pEntry, aValue, aSet );
230 mpSet->Put( aSet );
232 else
234 if(pEntry->nWID)
235 SvxItemPropertySet::setPropertyValue( pEntry, aValue, maUsrAnys );
239 uno::Any SAL_CALL SdUnoPageBackground::getPropertyValue( const OUString& PropertyName )
241 SolarMutexGuard aGuard;
243 uno::Any aAny;
244 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(PropertyName);
246 if( pEntry == nullptr )
248 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
251 if( mpSet )
253 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
255 const XFillBmpStretchItem* pStretchItem = mpSet->GetItem<XFillBmpStretchItem>(XATTR_FILLBMP_STRETCH);
256 const XFillBmpTileItem* pTileItem = mpSet->GetItem<XFillBmpTileItem>(XATTR_FILLBMP_TILE);
258 if( pStretchItem && pTileItem )
260 if( pTileItem->GetValue() )
261 aAny <<= drawing::BitmapMode_REPEAT;
262 else if( pStretchItem->GetValue() )
263 aAny <<= drawing::BitmapMode_STRETCH;
264 else
265 aAny <<= drawing::BitmapMode_NO_REPEAT;
268 else
270 SfxItemPool& rPool = *mpSet->GetPool();
271 SfxItemSet aSet( rPool, pEntry->nWID, pEntry->nWID);
272 aSet.Put( *mpSet );
274 if( !aSet.Count() )
275 aSet.Put( rPool.GetUserOrPoolDefaultItem( pEntry->nWID ) );
277 // get value from ItemSet
278 aAny = SvxItemPropertySet_getPropertyValue( pEntry, aSet );
281 else
283 if(pEntry->nWID)
284 aAny = mpPropSet->getPropertyValue( pEntry, maUsrAnys );
286 return aAny;
289 void SAL_CALL SdUnoPageBackground::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
290 void SAL_CALL SdUnoPageBackground::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
291 void SAL_CALL SdUnoPageBackground::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
292 void SAL_CALL SdUnoPageBackground::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
294 // XPropertyState
295 beans::PropertyState SAL_CALL SdUnoPageBackground::getPropertyState( const OUString& PropertyName )
297 SolarMutexGuard aGuard;
299 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(PropertyName);
301 if( pEntry == nullptr )
302 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
304 if( mpSet )
306 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
308 if( mpSet->GetItemState( XATTR_FILLBMP_STRETCH, false ) == SfxItemState::SET ||
309 mpSet->GetItemState( XATTR_FILLBMP_TILE, false ) == SfxItemState::SET )
311 return beans::PropertyState_DIRECT_VALUE;
313 else
315 return beans::PropertyState_AMBIGUOUS_VALUE;
319 switch( mpSet->GetItemState( pEntry->nWID, false ) )
321 case SfxItemState::SET:
322 return beans::PropertyState_DIRECT_VALUE;
323 case SfxItemState::DEFAULT:
324 return beans::PropertyState_DEFAULT_VALUE;
325 default:
326 // case SfxItemState::INVALID:
327 // case SfxItemState::DISABLED:
328 return beans::PropertyState_AMBIGUOUS_VALUE;
331 else
333 if( nullptr == maUsrAnys.GetUsrAnyForID(*pEntry) )
334 return beans::PropertyState_DEFAULT_VALUE;
335 else
336 return beans::PropertyState_DIRECT_VALUE;
340 uno::Sequence< beans::PropertyState > SAL_CALL SdUnoPageBackground::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
342 SolarMutexGuard aGuard;
344 sal_Int32 nCount = aPropertyName.getLength();
346 uno::Sequence< beans::PropertyState > aPropertyStateSequence( nCount );
348 std::transform(aPropertyName.begin(), aPropertyName.end(), aPropertyStateSequence.getArray(),
349 [this](const OUString& rName) -> beans::PropertyState { return getPropertyState(rName); });
351 return aPropertyStateSequence;
354 void SAL_CALL SdUnoPageBackground::setPropertyToDefault( const OUString& PropertyName )
356 SolarMutexGuard aGuard;
358 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(PropertyName);
360 if( pEntry == nullptr )
361 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
363 if( mpSet )
365 if( pEntry->nWID == OWN_ATTR_FILLBMP_MODE )
367 mpSet->ClearItem( XATTR_FILLBMP_STRETCH );
368 mpSet->ClearItem( XATTR_FILLBMP_TILE );
370 else
372 mpSet->ClearItem( pEntry->nWID );
377 uno::Any SAL_CALL SdUnoPageBackground::getPropertyDefault( const OUString& aPropertyName )
379 SolarMutexGuard aGuard;
381 const SfxItemPropertyMapEntry* pEntry = getPropertyMapEntry(aPropertyName);
382 if( pEntry == nullptr || mpSet == nullptr )
383 throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));
385 uno::Any aAny;
386 if (pEntry->nWID == OWN_ATTR_FILLBMP_MODE)
388 aAny <<= drawing::BitmapMode_REPEAT;
390 else
392 SfxItemPool& rPool = *mpSet->GetPool();
393 SfxItemSet aSet(rPool, pEntry->nWID, pEntry->nWID);
394 aSet.Put(rPool.GetUserOrPoolDefaultItem(pEntry->nWID));
396 aAny = SvxItemPropertySet_getPropertyValue(pEntry, aSet);
398 return aAny;
401 /** this is used because our property map is not sorted yet */
402 const SfxItemPropertyMapEntry* SdUnoPageBackground::getPropertyMapEntry( const OUString& rPropertyName ) const noexcept
404 return mpPropSet->getPropertyMap().getByName(rPropertyName);
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */