tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / unoidl / unoobj.cxx
blob49633f61bc301acf79b1bc6e6462837df7a0eb67
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 <sal/config.h>
22 #include <memory>
23 #include <string_view>
24 #include <utility>
26 #include <com/sun/star/style/XStyle.hpp>
27 #include <com/sun/star/presentation/ClickAction.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/beans/PropertyState.hpp>
30 #include <rtl/ustrbuf.hxx>
31 #include <svl/itemprop.hxx>
32 #include <svl/style.hxx>
33 #include <svx/svdpool.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/app.hxx>
36 #include <svtools/unoimap.hxx>
37 #include <svtools/unoevent.hxx>
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/event.hxx>
40 #include <sfx2/sfxsids.hrc>
41 #include <comphelper/extract.hxx>
42 #include <cppuhelper/implbase.hxx>
43 #include <cppuhelper/supportsservice.hxx>
44 #include <svx/unoshape.hxx>
45 #include <svx/svdotext.hxx>
46 #include <svx/svdopath.hxx>
47 #include <svx/svdoole2.hxx>
48 #include <svx/svdograf.hxx>
49 #include <svx/ImageMapInfo.hxx>
50 #include <filter/msfilter/msdffimp.hxx>
51 #include <svl/instrm.hxx>
52 #include <editeng/outlobj.hxx>
53 #include <Outliner.hxx>
54 #include <comphelper/sequence.hxx>
55 #include <svx/svdogrp.hxx>
56 #include <o3tl/typed_flags_set.hxx>
57 #include <vcl/svapp.hxx>
58 #include <tools/debug.hxx>
60 #include <anminfo.hxx>
61 #include "unoobj.hxx"
62 #include <unoprnms.hxx>
63 #include <unomodel.hxx>
64 #include <drawdoc.hxx>
65 #include <sdmod.hxx>
66 #include <sdpage.hxx>
67 #include <ViewShell.hxx>
68 #include <unopage.hxx>
69 #include <DrawDocShell.hxx>
70 #include <EffectMigration.hxx>
72 using namespace ::sd;
73 using namespace ::com::sun::star;
74 using namespace ::com::sun::star::presentation;
75 using namespace ::com::sun::star::animations;
77 using ::com::sun::star::uno::Any;
78 using ::com::sun::star::drawing::XShape;
80 #define WID_EFFECT 1
81 #define WID_SPEED 2
82 #define WID_TEXTEFFECT 3
83 #define WID_BOOKMARK 4
84 #define WID_CLICKACTION 5
85 #define WID_PLAYFULL 6
86 #define WID_SOUNDFILE 7
87 #define WID_SOUNDON 8
88 #define WID_BLUESCREEN 9
89 #define WID_VERB 10
90 #define WID_DIMCOLOR 11
91 #define WID_DIMHIDE 12
92 #define WID_DIMPREV 13
93 #define WID_PRESORDER 14
94 #define WID_STYLE 15
95 #define WID_ANIMPATH 16
96 #define WID_IMAGEMAP 17
97 #define WID_ISANIMATION 18
99 #define WID_ISEMPTYPRESOBJ 20
100 #define WID_ISPRESOBJ 21
101 #define WID_MASTERDEPEND 22
103 #define WID_NAVORDER 23
104 #define WID_PLACEHOLDERTEXT 24
105 #define WID_LEGACYFRAGMENT 25
107 #define IMPRESS_MAP_ENTRIES \
108 { u"" UNO_NAME_OBJ_LEGACYFRAGMENT ""_ustr,WID_LEGACYFRAGMENT, cppu::UnoType<drawing::XShape>::get(), 0, 0},\
109 { u"" UNO_NAME_OBJ_ANIMATIONPATH ""_ustr, WID_ANIMPATH, cppu::UnoType<drawing::XShape>::get(), 0, 0},\
110 { u"" UNO_NAME_OBJ_BOOKMARK ""_ustr, WID_BOOKMARK, cppu::UnoType<OUString>::get(), 0, 0},\
111 { u"" UNO_NAME_OBJ_DIMCOLOR ""_ustr, WID_DIMCOLOR, cppu::UnoType<sal_Int32>::get(), 0, 0},\
112 { u"" UNO_NAME_OBJ_DIMHIDE ""_ustr, WID_DIMHIDE, cppu::UnoType<bool>::get(), 0, 0},\
113 { u"" UNO_NAME_OBJ_DIMPREV ""_ustr, WID_DIMPREV, cppu::UnoType<bool>::get(), 0, 0},\
114 { u"" UNO_NAME_OBJ_EFFECT ""_ustr, WID_EFFECT, cppu::UnoType<presentation::AnimationEffect>::get(), 0, 0},\
115 { u"" UNO_NAME_OBJ_ISEMPTYPRESOBJ_SD ""_ustr,WID_ISEMPTYPRESOBJ, cppu::UnoType<bool>::get(), 0, 0},\
116 { u"" UNO_NAME_OBJ_ISPRESOBJ ""_ustr, WID_ISPRESOBJ, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY, 0},\
117 { u"" UNO_NAME_OBJ_MASTERDEPENDENT ""_ustr,WID_MASTERDEPEND, cppu::UnoType<bool>::get(), 0, 0},\
118 { u"" UNO_NAME_OBJ_CLICKACTION ""_ustr, WID_CLICKACTION, cppu::UnoType<presentation::ClickAction>::get(), 0, 0},\
119 { u"" UNO_NAME_OBJ_PLAYFULL ""_ustr, WID_PLAYFULL, cppu::UnoType<bool>::get(), 0, 0},\
120 { u"" UNO_NAME_OBJ_PRESORDER ""_ustr, WID_PRESORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
121 { u"" UNO_NAME_OBJ_STYLE ""_ustr, WID_STYLE, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},\
122 { u"" UNO_NAME_OBJ_SOUNDFILE ""_ustr, WID_SOUNDFILE, cppu::UnoType<OUString>::get(), 0, 0},\
123 { u"" UNO_NAME_OBJ_SOUNDON ""_ustr, WID_SOUNDON, cppu::UnoType<bool>::get(), 0, 0},\
124 { u"" UNO_NAME_OBJ_SPEED ""_ustr, WID_SPEED, cppu::UnoType<presentation::AnimationSpeed>::get(), 0, 0},\
125 { u"" UNO_NAME_OBJ_TEXTEFFECT ""_ustr, WID_TEXTEFFECT, cppu::UnoType<presentation::AnimationEffect>::get(), 0, 0},\
126 { u"" UNO_NAME_OBJ_BLUESCREEN ""_ustr, WID_BLUESCREEN, cppu::UnoType<sal_Int32>::get(), 0, 0},\
127 { u"" UNO_NAME_OBJ_VERB ""_ustr, WID_VERB, cppu::UnoType<sal_Int32>::get(), 0, 0},\
128 { u"IsAnimation"_ustr, WID_ISANIMATION, cppu::UnoType<bool>::get(), 0, 0},\
129 { u"NavigationOrder"_ustr, WID_NAVORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
130 { u"PlaceholderText"_ustr, WID_PLACEHOLDERTEXT, cppu::UnoType<OUString>::get(), 0, 0},\
132 static std::span<const SfxItemPropertyMapEntry> lcl_GetImpress_SdXShapePropertyGraphicMap_Impl()
134 static const SfxItemPropertyMapEntry aImpress_SdXShapePropertyGraphicMap_Impl[] =
136 { u"ImageMap"_ustr, WID_IMAGEMAP, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
137 IMPRESS_MAP_ENTRIES
139 return aImpress_SdXShapePropertyGraphicMap_Impl;
142 static std::span<const SfxItemPropertyMapEntry> lcl_GetImpress_SdXShapePropertySimpleMap_Impl()
144 static const SfxItemPropertyMapEntry aImpress_SdXShapePropertySimpleMap_Impl[] =
146 IMPRESS_MAP_ENTRIES
148 return aImpress_SdXShapePropertySimpleMap_Impl;
151 #define DRAW_MAP_ENTRIES\
152 { u"" UNO_NAME_OBJ_BOOKMARK ""_ustr, WID_BOOKMARK, cppu::UnoType<OUString>::get(), 0, 0},\
153 { u"" UNO_NAME_OBJ_CLICKACTION ""_ustr, WID_CLICKACTION, cppu::UnoType<presentation::ClickAction>::get(),0, 0},\
154 { u"" UNO_NAME_OBJ_STYLE ""_ustr, WID_STYLE, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},\
155 { u"NavigationOrder"_ustr, WID_NAVORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
157 static std::span<const SfxItemPropertyMapEntry> lcl_GetDraw_SdXShapePropertySimpleMap_Impl()
159 static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyMap_Impl[] =
161 DRAW_MAP_ENTRIES
163 return aDraw_SdXShapePropertyMap_Impl;
165 static std::span<const SfxItemPropertyMapEntry> lcl_GetDraw_SdXShapePropertyGraphicMap_Impl()
167 static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyGraphicMap_Impl[] =
169 { u"ImageMap"_ustr, WID_IMAGEMAP, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
170 DRAW_MAP_ENTRIES
172 return aDraw_SdXShapePropertyGraphicMap_Impl;
174 static std::span<const SfxItemPropertyMapEntry> lcl_ImplGetShapePropertyMap( bool bImpress, bool bGraphicObj )
176 std::span<const SfxItemPropertyMapEntry> pRet;
177 if( bImpress )
179 if( bGraphicObj )
180 pRet = lcl_GetImpress_SdXShapePropertyGraphicMap_Impl();
181 else
182 pRet = lcl_GetImpress_SdXShapePropertySimpleMap_Impl();
184 else
186 if( bGraphicObj )
187 pRet = lcl_GetDraw_SdXShapePropertyGraphicMap_Impl();
188 else
189 pRet = lcl_GetDraw_SdXShapePropertySimpleMap_Impl();
191 return pRet;
194 static const SvxItemPropertySet* lcl_ImplGetShapePropertySet( bool bImpress, bool bGraphicObj )
196 const SvxItemPropertySet* pRet = nullptr;
197 if( bImpress )
199 if( bGraphicObj )
201 static SvxItemPropertySet aImpress_SdXShapePropertyGraphicSet_Impl( lcl_GetImpress_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
202 pRet = &aImpress_SdXShapePropertyGraphicSet_Impl;
204 else
206 static SvxItemPropertySet aImpress_SdXShapePropertySet_Impl(lcl_GetImpress_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
207 pRet = &aImpress_SdXShapePropertySet_Impl;
210 else
212 if( bGraphicObj )
214 static SvxItemPropertySet aDraw_SdXShapePropertyGraphicSet_Impl(lcl_GetDraw_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
215 pRet = &aDraw_SdXShapePropertyGraphicSet_Impl;
217 else
219 static SvxItemPropertySet aDraw_SdXShapePropertySet_Impl( lcl_GetDraw_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
220 pRet = &aDraw_SdXShapePropertySet_Impl;
223 return pRet;
225 static std::span<const SfxItemPropertyMapEntry> lcl_GetEmpty_SdXShapePropertyMap_Impl()
227 return {};
230 static const SvxItemPropertySet* lcl_GetEmpty_SdXShapePropertySet_Impl()
232 static SvxItemPropertySet aEmptyPropSet( lcl_GetEmpty_SdXShapePropertyMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool() );
233 return &aEmptyPropSet;
235 const SvEventDescription* ImplGetSupportedMacroItems()
237 static const SvEventDescription aMacroDescriptionsImpl[] =
239 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
240 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
241 { SvMacroItemId::NONE, nullptr }
244 return aMacroDescriptionsImpl;
247 SdXShape::SdXShape(SvxShape* pShape, SdXImpressDocument* pModel)
248 : mpShape( pShape ),
249 mpPropSet( pModel?
250 lcl_ImplGetShapePropertySet(pModel->IsImpressDocument(), pShape->getShapeKind() == SdrObjKind::Graphic )
251 : lcl_GetEmpty_SdXShapePropertySet_Impl() ),
252 mpMap( pModel?
253 lcl_ImplGetShapePropertyMap(pModel->IsImpressDocument(), pShape->getShapeKind() == SdrObjKind::Graphic )
254 : lcl_GetEmpty_SdXShapePropertyMap_Impl() ),
255 mpModel(pModel)
258 pShape->setMaster( this );
261 SdXShape::~SdXShape() noexcept
265 void SdXShape::dispose()
267 mpShape->setMaster( nullptr );
268 delete this;
271 uno::Any SAL_CALL SdXShape::queryInterface( const uno::Type & rType )
273 return mpShape->queryInterface( rType );
276 void SAL_CALL SdXShape::acquire() noexcept
278 mpShape->acquire();
281 void SAL_CALL SdXShape::release() noexcept
283 mpShape->release();
286 bool SdXShape::queryAggregation( const css::uno::Type & rType, css::uno::Any& aAny )
288 if( mpModel && mpModel ->IsImpressDocument() )
290 if( rType == cppu::UnoType<document::XEventsSupplier>::get())
292 aAny <<= uno::Reference< document::XEventsSupplier >(this);
293 return true;
297 return false;
300 uno::Sequence< uno::Type > SAL_CALL SdXShape::getTypes()
302 if( mpModel && !mpModel->IsImpressDocument() )
304 return mpShape->_getTypes();
306 else
308 SdrObjKind nObjId = mpShape->getShapeKind();
309 uno::Sequence< uno::Type > aTypes;
310 SdTypesCache& gImplTypesCache = SdModule::get()->gImplTypesCache;
311 SdTypesCache::iterator aIter( gImplTypesCache.find( nObjId ) );
312 if( aIter == gImplTypesCache.end() )
314 aTypes = mpShape->_getTypes();
315 sal_uInt32 nCount = aTypes.getLength();
316 aTypes.realloc( nCount+1 );
317 aTypes.getArray()[nCount] = cppu::UnoType<lang::XTypeProvider>::get();
319 gImplTypesCache.insert(std::make_pair(nObjId, aTypes));
321 else
323 // use the already computed implementation id
324 aTypes = (*aIter).second;
326 return aTypes;
330 // XPropertyState
331 beans::PropertyState SAL_CALL SdXShape::getPropertyState( const OUString& PropertyName )
333 SolarMutexGuard aGuard;
335 if( mpPropSet->getPropertyMapEntry(PropertyName) )
337 return beans::PropertyState_DIRECT_VALUE;
339 else
341 SdrObject* pObj = mpShape->GetSdrObject();
342 if( pObj == nullptr || ( pObj->getSdrPageFromSdrObject()->IsMasterPage() && pObj->IsEmptyPresObj() ) )
343 return beans::PropertyState_DEFAULT_VALUE;
345 return mpShape->_getPropertyState( PropertyName );
349 void SAL_CALL SdXShape::setPropertyToDefault( const OUString& PropertyName )
351 SolarMutexGuard aGuard;
353 if( mpPropSet->getPropertyMapEntry(PropertyName) )
355 return;
357 else
359 mpShape->_setPropertyToDefault(PropertyName);
363 uno::Any SAL_CALL SdXShape::getPropertyDefault( const OUString& aPropertyName )
365 SolarMutexGuard aGuard;
367 if( mpPropSet->getPropertyMapEntry(aPropertyName) )
369 return getPropertyValue( aPropertyName );
371 else
373 uno::Any aRet( mpShape->_getPropertyDefault(aPropertyName) );
374 return aRet;
378 //XPropertySet
379 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL SdXShape::getPropertySetInfo()
381 std::span<SfxItemPropertyMapEntry const> nObjId = mpShape->getPropertyMapEntries();
382 css::uno::Reference<css::beans::XPropertySetInfo> pInfo;
384 SdExtPropertySetInfoCache& rCache = (mpModel && mpModel->IsImpressDocument()) ?
385 SdModule::get()->gImplImpressPropertySetInfoCache : SdModule::get()->gImplDrawPropertySetInfoCache;
387 SdExtPropertySetInfoCache::iterator aIter( rCache.find( nObjId ) );
388 if( aIter == rCache.end() )
390 uno::Reference< beans::XPropertySetInfo > xInfo( mpShape->_getPropertySetInfo() );
391 pInfo = new SfxExtItemPropertySetInfo( mpMap, xInfo->getProperties() );
393 rCache.insert(std::make_pair(nObjId, pInfo));
395 else
397 // use the already computed implementation id
398 pInfo = (*aIter).second;
401 return pInfo;
404 void SAL_CALL SdXShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue )
406 SolarMutexGuard aGuard;
408 const SfxItemPropertyMapEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);
410 if( pEntry )
412 SdrObject* pObj = mpShape->GetSdrObject();
413 if( pObj )
415 switch(pEntry->nWID)
417 case WID_NAVORDER:
419 sal_Int32 nNavOrder = 0;
420 if(!(aValue >>= nNavOrder))
421 throw lang::IllegalArgumentException();
423 SdrObjList* pObjList = pObj->getParentSdrObjListFromSdrObject();
424 if( pObjList )
425 pObjList->SetObjectNavigationPosition( *pObj, (nNavOrder < 0) ? SAL_MAX_UINT32 : static_cast< sal_uInt32 >( nNavOrder ) );
426 break;
429 case WID_EFFECT:
431 AnimationEffect eEffect;
432 if(!(aValue >>= eEffect))
433 throw lang::IllegalArgumentException();
435 EffectMigration::SetAnimationEffect( mpShape, eEffect );
436 break;
438 case WID_TEXTEFFECT:
440 AnimationEffect eEffect;
441 if(!(aValue >>= eEffect))
442 throw lang::IllegalArgumentException();
444 EffectMigration::SetTextAnimationEffect( mpShape, eEffect );
445 break;
447 case WID_SPEED:
449 AnimationSpeed eSpeed;
450 if(!(aValue>>=eSpeed))
451 throw lang::IllegalArgumentException();
453 EffectMigration::SetAnimationSpeed( mpShape, eSpeed );
454 break;
456 case WID_ISANIMATION:
458 bool bIsAnimation(false);
460 if(!(aValue >>= bIsAnimation))
462 throw lang::IllegalArgumentException();
465 if(bIsAnimation)
467 SdrObjGroup* pGroup = dynamic_cast< SdrObjGroup* >(pObj);
468 SdPage* pPage = pGroup ? dynamic_cast< SdPage* >(pGroup->getSdrPageFromSdrObject()) : nullptr;
470 if (pPage)
472 // #i42894# Animated Group object, migrate that effect
473 EffectMigration::CreateAnimatedGroup(*pGroup, *pPage);
475 // #i42894# unfortunately when doing this all group members have to
476 // be moved to the page as direct members, else the currently
477 // available forms of animation do not work. If it succeeds,
478 // the group is empty and can be removed and deleted
479 if(!pGroup->GetSubList()->GetObjCount())
481 pPage->NbcRemoveObject(pGroup->GetOrdNum());
485 //pInfo->mbIsMovie = bIsAnimation;
486 break;
488 case WID_BOOKMARK:
490 OUString aString;
491 if(!(aValue >>= aString))
492 throw lang::IllegalArgumentException();
494 SdAnimationInfo* pInfo = GetAnimationInfo(true);
495 pInfo->SetBookmark( SdDrawPage::getUiNameFromPageApiName( aString ) );
496 break;
498 case WID_CLICKACTION:
500 SdAnimationInfo* pInfo = GetAnimationInfo(true);
501 ::cppu::any2enum< presentation::ClickAction >( pInfo->meClickAction, aValue);
502 break;
504 // TODO: WID_PLAYFULL:
505 case WID_SOUNDFILE:
507 OUString aString;
508 if(!(aValue >>= aString))
509 throw lang::IllegalArgumentException();
510 SdAnimationInfo* pInfo = GetAnimationInfo(true);
511 pInfo->maSoundFile = aString;
512 EffectMigration::UpdateSoundEffect( mpShape, pInfo );
513 break;
516 case WID_SOUNDON:
518 SdAnimationInfo* pInfo = GetAnimationInfo(true);
519 if( !(aValue >>= pInfo->mbSoundOn) )
520 throw lang::IllegalArgumentException();
521 EffectMigration::UpdateSoundEffect( mpShape, pInfo );
522 break;
524 case WID_VERB:
526 sal_Int32 nVerb = 0;
527 if(!(aValue >>= nVerb))
528 throw lang::IllegalArgumentException();
530 SdAnimationInfo* pInfo = GetAnimationInfo(true);
531 pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
532 break;
534 case WID_DIMCOLOR:
536 sal_Int32 nColor = 0;
538 if( !(aValue >>= nColor) )
539 throw lang::IllegalArgumentException();
541 EffectMigration::SetDimColor( mpShape, nColor );
542 break;
544 case WID_DIMHIDE:
546 bool bDimHide = false;
547 if( !(aValue >>= bDimHide) )
548 throw lang::IllegalArgumentException();
550 EffectMigration::SetDimHide( mpShape, bDimHide );
551 break;
553 case WID_DIMPREV:
555 bool bDimPrevious = false;
556 if( !(aValue >>= bDimPrevious) )
557 throw lang::IllegalArgumentException();
559 EffectMigration::SetDimPrevious( mpShape, bDimPrevious );
560 break;
562 case WID_PRESORDER:
564 sal_Int32 nNewPos = 0;
565 if( !(aValue >>= nNewPos) )
566 throw lang::IllegalArgumentException();
568 EffectMigration::SetPresentationOrder( mpShape, nNewPos );
569 break;
571 case WID_STYLE:
572 SetStyleSheet( aValue );
573 break;
574 case WID_ISEMPTYPRESOBJ:
575 SetEmptyPresObj( ::cppu::any2bool(aValue) );
576 break;
577 case WID_MASTERDEPEND:
578 SetMasterDepend( ::cppu::any2bool(aValue) );
579 break;
581 case WID_LEGACYFRAGMENT:
583 uno::Reference< io::XInputStream > xInputStream;
584 aValue >>= xInputStream;
585 if( xInputStream.is() )
587 SvInputStream aStream( xInputStream );
588 SdrObject* pObject = mpShape->GetSdrObject();
589 SvxMSDffManager::ReadObjText( aStream, pObject );
592 break;
594 case WID_ANIMPATH:
596 uno::Reference< drawing::XShape > xShape( aValue, uno::UNO_QUERY );
597 SdrPathObj* pObj2 = xShape.is() ? dynamic_cast<SdrPathObj*>(SdrObject::getSdrObjectFromXShape(xShape)) : nullptr;
599 if( pObj2 == nullptr )
600 throw lang::IllegalArgumentException();
602 EffectMigration::SetAnimationPath( mpShape, pObj2 );
603 break;
605 case WID_IMAGEMAP:
607 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
608 if( pDoc )
610 ImageMap aImageMap;
611 uno::Reference< uno::XInterface > xImageMap;
612 aValue >>= xImageMap;
614 if( !xImageMap.is() || !SvUnoImageMap_fillImageMap( xImageMap, aImageMap ) )
615 throw lang::IllegalArgumentException();
617 SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(pObj);
618 if( pIMapInfo )
620 // replace existing image map
621 pIMapInfo->SetImageMap( aImageMap );
623 else
625 // insert new user data with image map
626 pObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(aImageMap) ));
630 break;
634 else
636 mpShape->_setPropertyValue(aPropertyName, aValue);
639 if( mpModel )
640 mpModel->SetModified();
643 css::uno::Any SAL_CALL SdXShape::getPropertyValue( const OUString& PropertyName )
645 SolarMutexGuard aGuard;
647 uno::Any aRet;
649 const SfxItemPropertyMapEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);
651 if( pEntry && mpShape->GetSdrObject() )
653 SdAnimationInfo* pInfo = GetAnimationInfo();
655 switch(pEntry->nWID)
657 case WID_NAVORDER:
659 const sal_uInt32 nNavOrder = mpShape->GetSdrObject()->GetNavigationPosition();
660 aRet <<= nNavOrder == SAL_MAX_UINT32 ? static_cast<sal_Int32>(-1) : static_cast< sal_Int32 >(nNavOrder);
662 break;
663 case WID_EFFECT:
664 aRet <<= EffectMigration::GetAnimationEffect( mpShape );
665 break;
666 case WID_TEXTEFFECT:
667 aRet <<= EffectMigration::GetTextAnimationEffect( mpShape );
668 break;
669 case WID_ISPRESOBJ:
670 aRet <<= IsPresObj();
671 break;
672 case WID_ISEMPTYPRESOBJ:
673 aRet <<= IsEmptyPresObj();
674 break;
675 case WID_MASTERDEPEND:
676 aRet <<= IsMasterDepend();
677 break;
678 case WID_SPEED:
679 aRet <<= EffectMigration::GetAnimationSpeed( mpShape );
680 break;
681 case WID_ISANIMATION:
682 aRet <<= (pInfo && pInfo->mbIsMovie);
683 break;
684 case WID_PLACEHOLDERTEXT:
685 aRet <<= GetPlaceholderText();
686 break;
687 case WID_BOOKMARK:
689 OUString aString;
690 SdDrawDocument* pDoc = mpModel ? mpModel->GetDoc() : nullptr;
691 if (pInfo && pDoc)
693 // is the bookmark a page?
694 bool bIsMasterPage;
695 if(pDoc->GetPageByName( pInfo->GetBookmark(), bIsMasterPage ) != SDRPAGE_NOTFOUND)
697 aString = SdDrawPage::getPageApiNameFromUiName( pInfo->GetBookmark() );
699 else
701 aString = pInfo->GetBookmark() ;
702 sal_Int32 nPos = aString.lastIndexOf( '#' );
703 if( nPos >= 0 )
705 OUString aURL( aString.copy( 0, nPos+1 ) );
706 OUString aName( aString.copy( nPos+1 ) );
707 if(pDoc->GetPageByName( aName, bIsMasterPage ) != SDRPAGE_NOTFOUND)
709 aURL += SdDrawPage::getPageApiNameFromUiName( aName );
710 aString = aURL;
716 aRet <<= aString;
717 break;
719 case WID_CLICKACTION:
720 aRet <<= ( pInfo?pInfo->meClickAction:presentation::ClickAction_NONE );
721 break;
722 case WID_PLAYFULL:
723 aRet <<= ( pInfo && pInfo->mbPlayFull );
724 break;
725 case WID_SOUNDFILE:
726 aRet <<= EffectMigration::GetSoundFile( mpShape );
727 break;
728 case WID_SOUNDON:
729 aRet <<= EffectMigration::GetSoundOn( mpShape );
730 break;
731 case WID_BLUESCREEN:
732 aRet <<= pInfo ? pInfo->maBlueScreen : Color(0x00ffffff);
733 break;
734 case WID_VERB:
735 aRet <<= static_cast<sal_Int32>( pInfo?pInfo->mnVerb:0 );
736 break;
737 case WID_DIMCOLOR:
738 aRet <<= EffectMigration::GetDimColor( mpShape );
739 break;
740 case WID_DIMHIDE:
741 aRet <<= EffectMigration::GetDimHide( mpShape );
742 break;
743 case WID_DIMPREV:
744 aRet <<= EffectMigration::GetDimPrevious( mpShape );
745 break;
746 case WID_PRESORDER:
747 aRet <<= EffectMigration::GetPresentationOrder( mpShape );
748 break;
749 case WID_STYLE:
750 aRet = GetStyleSheet();
751 break;
752 case WID_IMAGEMAP:
754 uno::Reference< uno::XInterface > xImageMap;
756 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
757 if( pDoc )
760 SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(mpShape->GetSdrObject());
761 if( pIMapInfo )
763 const ImageMap& rIMap = pIMapInfo->GetImageMap();
764 xImageMap = SvUnoImageMap_createInstance( rIMap, ImplGetSupportedMacroItems() );
766 else
768 xImageMap = SvUnoImageMap_createInstance();
772 aRet <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
773 break;
777 else
779 aRet = mpShape->_getPropertyValue(PropertyName);
782 return aRet;
785 /** */
786 SdAnimationInfo* SdXShape::GetAnimationInfo( bool bCreate ) const
788 SdAnimationInfo* pInfo = nullptr;
790 SdrObject* pObj = mpShape->GetSdrObject();
791 if(pObj)
792 pInfo = SdDrawDocument::GetShapeUserData(*pObj, bCreate);
794 return pInfo;
797 uno::Sequence< OUString > SAL_CALL SdXShape::getSupportedServiceNames()
799 std::vector<std::u16string_view> aAdd{ u"com.sun.star.presentation.Shape",
800 u"com.sun.star.document.LinkTarget" };
802 SdrObject* pObj = mpShape->GetSdrObject();
803 if(pObj && pObj->GetObjInventor() == SdrInventor::Default )
805 SdrObjKind nInventor = pObj->GetObjIdentifier();
806 switch( nInventor )
808 case SdrObjKind::TitleText:
809 aAdd.emplace_back(u"com.sun.star.presentation.TitleTextShape");
810 break;
811 case SdrObjKind::OutlineText:
812 aAdd.emplace_back(u"com.sun.star.presentation.OutlinerShape");
813 break;
814 default: ;
817 return comphelper::concatSequences(mpShape->_getSupportedServiceNames(), aAdd);
820 /** checks if this is a presentation object
822 bool SdXShape::IsPresObj() const
824 SdrObject* pObj = mpShape->GetSdrObject();
825 if(pObj)
827 SdPage* pPage = dynamic_cast<SdPage* >(pObj->getSdrPageFromSdrObject());
828 if(pPage)
829 return pPage->GetPresObjKind(pObj) != PresObjKind::NONE;
831 return false;
834 /** checks if this presentation object is empty
836 bool SdXShape::IsEmptyPresObj() const
838 SdrObject* pObj = mpShape->GetSdrObject();
839 if( (pObj != nullptr) && pObj->IsEmptyPresObj() )
841 // check if the object is in edit, then if it's temporarily not empty
842 SdrTextObj* pTextObj = DynCastSdrTextObj( pObj );
843 if( pTextObj == nullptr )
844 return true;
846 return !pTextObj->CanCreateEditOutlinerParaObject();
849 return false;
852 OUString SdXShape::GetPlaceholderText() const
854 // only possible if this actually *is* a presentation object
855 if( !IsPresObj() )
856 return OUString();
858 SdrObject* pObj = mpShape->GetSdrObject();
859 if( pObj == nullptr )
860 return OUString();
862 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
863 DBG_ASSERT( pPage, "no page?" );
864 if( pPage == nullptr )
865 return OUString();
867 return pPage->GetPresObjText( pPage->GetPresObjKind(pObj) );
870 /** sets/reset the empty status of a presentation object
872 void SdXShape::SetEmptyPresObj(bool bEmpty)
874 // only possible if this actually *is* a presentation object
875 if( !IsPresObj() )
876 return;
878 SdrObject* pObj = mpShape->GetSdrObject();
879 if( pObj == nullptr )
880 return;
882 if( pObj->IsEmptyPresObj() == bEmpty )
883 return;
885 if(!bEmpty)
887 OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
888 const bool bVertical = pOutlinerParaObject && pOutlinerParaObject->IsEffectivelyVertical();
890 // really delete SdrOutlinerObj at pObj
891 pObj->NbcSetOutlinerParaObject(std::nullopt);
892 if( bVertical )
893 if (auto pTextObj = DynCastSdrTextObj( pObj ) )
894 pTextObj->SetVerticalWriting( true );
896 SdrGrafObj* pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj );
897 if( pGraphicObj )
899 Graphic aEmpty;
900 pGraphicObj->SetGraphic(aEmpty);
902 else
904 SdrOle2Obj* pOleObj = dynamic_cast< SdrOle2Obj* >( pObj );
905 if( pOleObj )
907 pOleObj->ClearGraphic();
911 else
913 // now set an empty OutlinerParaObject at pObj without
914 // any content but with the style of the old OutlinerParaObjects
915 // first paragraph
918 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
919 DBG_ASSERT( pDoc, "no document?" );
920 if( pDoc == nullptr)
921 break;
923 SdOutliner* pOutliner = pDoc->GetInternalOutliner();
924 DBG_ASSERT( pOutliner, "no outliner?" );
925 if( pOutliner == nullptr )
926 break;
928 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
929 DBG_ASSERT( pPage, "no page?" );
930 if( pPage == nullptr )
931 break;
933 OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
934 pOutliner->SetText( *pOutlinerParaObject );
935 const bool bVertical = pOutliner->IsVertical();
937 pOutliner->Clear();
938 pOutliner->SetVertical( bVertical );
939 pOutliner->SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(pDoc->GetStyleSheetPool()) );
940 pOutliner->SetStyleSheet( 0, pPage->GetTextStyleSheetForObject( pObj ) );
941 pOutliner->Insert( pPage->GetPresObjText( pPage->GetPresObjKind(pObj) ) );
942 pObj->SetOutlinerParaObject( pOutliner->CreateParaObject() );
943 pOutliner->Clear();
945 while(false);
948 pObj->SetEmptyPresObj(bEmpty);
951 bool SdXShape::IsMasterDepend() const noexcept
953 SdrObject* pObj = mpShape->GetSdrObject();
954 return pObj && pObj->GetUserCall() != nullptr;
957 void SdXShape::SetMasterDepend( bool bDepend ) noexcept
959 if( IsMasterDepend() == bDepend )
960 return;
962 SdrObject* pObj = mpShape->GetSdrObject();
963 if( pObj )
965 if( bDepend )
967 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
968 pObj->SetUserCall( pPage );
970 else
972 pObj->SetUserCall( nullptr );
977 void SdXShape::SetStyleSheet( const uno::Any& rAny )
979 SdrObject* pObj = mpShape->GetSdrObject();
980 if( pObj == nullptr )
981 throw beans::UnknownPropertyException();
983 uno::Reference< style::XStyle > xStyle( rAny, uno::UNO_QUERY );
984 SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle );
986 const SfxStyleSheet* pOldStyleSheet = pObj->GetStyleSheet();
987 if( pOldStyleSheet == pStyleSheet )
988 return;
990 if( pStyleSheet == nullptr || (pStyleSheet->GetFamily() != SfxStyleFamily::Para && pStyleSheet->GetFamily() != SfxStyleFamily::Page) )
991 throw lang::IllegalArgumentException();
993 pObj->SetStyleSheet( pStyleSheet, false );
995 SdDrawDocument* pDoc = mpModel? mpModel->GetDoc() : nullptr;
996 if( pDoc )
998 ::sd::DrawDocShell* pDocSh = pDoc->GetDocSh();
999 ::sd::ViewShell* pViewSh = pDocSh ? pDocSh->GetViewShell() : nullptr;
1001 if( pViewSh )
1002 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2 );
1006 uno::Any SdXShape::GetStyleSheet() const
1008 SdrObject* pObj = mpShape->GetSdrObject();
1009 if( pObj == nullptr )
1010 throw beans::UnknownPropertyException();
1012 SfxStyleSheet* pStyleSheet = pObj->GetStyleSheet();
1013 // it is possible for shapes inside a draw to have a presentation style
1014 // but we don't want this for the api
1015 if( (pStyleSheet == nullptr) || ((pStyleSheet->GetFamily() != SfxStyleFamily::Para) && !mpModel->IsImpressDocument()) )
1016 return Any();
1018 return Any( uno::Reference< style::XStyle >( dynamic_cast< SfxUnoStyleSheet* >( pStyleSheet ) ) );
1021 class SdUnoEventsAccess : public cppu::WeakImplHelper< css::container::XNameReplace, css::lang::XServiceInfo >
1023 private:
1024 SdXShape* mpShape;
1026 public:
1027 explicit SdUnoEventsAccess(SdXShape* pShape) noexcept;
1029 // XNameReplace
1030 virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
1032 // XNameAccess
1033 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
1034 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
1035 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
1037 // XElementAccess
1038 virtual css::uno::Type SAL_CALL getElementType( ) override;
1039 virtual sal_Bool SAL_CALL hasElements( ) override;
1041 // XServiceInfo
1042 virtual OUString SAL_CALL getImplementationName( ) override;
1043 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1044 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
1047 // XEventsSupplier
1048 uno::Reference< container::XNameReplace > SAL_CALL SdXShape::getEvents( )
1050 return new SdUnoEventsAccess( this );
1053 constexpr OUString gaStrOnClick( u"OnClick"_ustr );
1054 constexpr OUString gaStrServiceName( u"com.sun.star.documents.Events"_ustr );
1055 constexpr OUString gaStrEventType( u"EventType"_ustr );
1056 constexpr OUString gaStrPresentation( u"Presentation"_ustr );
1057 constexpr OUString gaStrLibrary(u"Library"_ustr);
1058 constexpr OUString gaStrMacroName(u"MacroName"_ustr);
1059 constexpr OUString gaStrClickAction( u"ClickAction"_ustr );
1060 constexpr OUString gaStrBookmark( u"Bookmark"_ustr );
1061 constexpr OUString gaStrEffect( u"Effect"_ustr );
1062 constexpr OUString gaStrPlayFull( u"PlayFull"_ustr );
1063 constexpr OUString gaStrVerb( u"Verb"_ustr );
1064 constexpr OUString gaStrSoundURL( u"SoundURL"_ustr );
1065 constexpr OUString gaStrSpeed( u"Speed"_ustr );
1066 constexpr OUStringLiteral gaStrStarBasic( u"StarBasic" );
1067 constexpr OUString gaStrScript( u"Script"_ustr );
1069 SdUnoEventsAccess::SdUnoEventsAccess( SdXShape* pShape ) noexcept
1070 : mpShape( pShape )
1074 namespace {
1076 enum class FoundFlags {
1077 NONE = 0x0000,
1078 ClickAction = 0x0001,
1079 Bookmark = 0x0002,
1080 Effect = 0x0004,
1081 PlayFull = 0x0008,
1082 Verb = 0x0010,
1083 SoundUrl = 0x0020,
1084 Speed = 0x0040,
1085 EventType = 0x0080,
1086 Macro = 0x0100,
1087 Library = 0x0200,
1092 namespace o3tl {
1093 template<> struct typed_flags<FoundFlags> : is_typed_flags<FoundFlags, 0x03ff> {};
1096 static void clearEventsInAnimationInfo( SdAnimationInfo* pInfo )
1098 pInfo->SetBookmark( u""_ustr );
1099 pInfo->mbSecondSoundOn = false;
1100 pInfo->mbSecondPlayFull = false;
1101 pInfo->meClickAction = presentation::ClickAction_NONE;
1102 pInfo->meSecondEffect = presentation::AnimationEffect_NONE;
1103 pInfo->meSecondSpeed = presentation::AnimationSpeed_MEDIUM;
1104 pInfo->mnVerb = 0;
1107 // XNameReplace
1108 void SAL_CALL SdUnoEventsAccess::replaceByName( const OUString& aName, const uno::Any& aElement )
1110 if( mpShape == nullptr || aName != gaStrOnClick )
1111 throw container::NoSuchElementException();
1113 uno::Sequence< beans::PropertyValue > aProperties;
1114 if( !aElement.hasValue() || aElement.getValueType() != getElementType() || !(aElement >>= aProperties) )
1115 throw lang::IllegalArgumentException();
1117 FoundFlags nFound = FoundFlags::NONE;
1119 OUString aStrEventType;
1120 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
1121 presentation::AnimationEffect eEffect = presentation::AnimationEffect_NONE;
1122 presentation::AnimationSpeed eSpeed = presentation::AnimationSpeed_MEDIUM;
1123 OUString aStrSoundURL;
1124 bool bPlayFull = false;
1125 sal_Int32 nVerb = 0;
1126 OUString aStrMacro;
1127 OUString aStrLibrary;
1128 OUString aStrBookmark;
1130 for (const beans::PropertyValue& rProperty : aProperties)
1132 if( !( nFound & FoundFlags::EventType ) && rProperty.Name == gaStrEventType )
1134 if( rProperty.Value >>= aStrEventType )
1136 nFound |= FoundFlags::EventType;
1137 continue;
1140 else if( !( nFound & FoundFlags::ClickAction ) && rProperty.Name == gaStrClickAction )
1142 if( rProperty.Value >>= eClickAction )
1144 nFound |= FoundFlags::ClickAction;
1145 continue;
1148 else if( !( nFound & FoundFlags::Macro ) && ( rProperty.Name == gaStrMacroName || rProperty.Name == gaStrScript ) )
1150 if( rProperty.Value >>= aStrMacro )
1152 nFound |= FoundFlags::Macro;
1153 continue;
1156 else if( !( nFound & FoundFlags::Library ) && rProperty.Name == gaStrLibrary )
1158 if( rProperty.Value >>= aStrLibrary )
1160 nFound |= FoundFlags::Library;
1161 continue;
1164 else if( !( nFound & FoundFlags::Effect ) && rProperty.Name == gaStrEffect )
1166 if( rProperty.Value >>= eEffect )
1168 nFound |= FoundFlags::Effect;
1169 continue;
1172 else if( !( nFound & FoundFlags::Bookmark ) && rProperty.Name == gaStrBookmark )
1174 if( rProperty.Value >>= aStrBookmark )
1176 nFound |= FoundFlags::Bookmark;
1177 continue;
1180 else if( !( nFound & FoundFlags::Speed ) && rProperty.Name == gaStrSpeed )
1182 if( rProperty.Value >>= eSpeed )
1184 nFound |= FoundFlags::Speed;
1185 continue;
1188 else if( !( nFound & FoundFlags::SoundUrl ) && rProperty.Name == gaStrSoundURL )
1190 if( rProperty.Value >>= aStrSoundURL )
1192 nFound |= FoundFlags::SoundUrl;
1193 continue;
1196 else if( !( nFound & FoundFlags::PlayFull ) && rProperty.Name == gaStrPlayFull )
1198 if( rProperty.Value >>= bPlayFull )
1200 nFound |= FoundFlags::PlayFull;
1201 continue;
1204 else if( !( nFound & FoundFlags::Verb ) && rProperty.Name == gaStrVerb )
1206 if( rProperty.Value >>= nVerb )
1208 nFound |= FoundFlags::Verb;
1209 continue;
1213 throw lang::IllegalArgumentException();
1216 bool bOk = false;
1219 if( !( nFound & FoundFlags::EventType ) )
1220 break;
1222 if( aStrEventType == gaStrPresentation )
1224 if( !( nFound & FoundFlags::ClickAction ) )
1225 break;
1227 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
1228 if( presentation::ClickAction_NONE == eClickAction && nullptr == pInfo )
1230 bOk = true;
1231 break;
1234 if( nullptr == pInfo )
1235 pInfo = mpShape->GetAnimationInfo( true );
1237 DBG_ASSERT( pInfo, "shape animation info could not be created!" );
1238 if( nullptr == pInfo )
1239 break;
1241 clearEventsInAnimationInfo( pInfo );
1242 pInfo->meClickAction = eClickAction;
1244 switch( eClickAction )
1246 case presentation::ClickAction_NONE:
1247 case presentation::ClickAction_PREVPAGE:
1248 case presentation::ClickAction_NEXTPAGE:
1249 case presentation::ClickAction_FIRSTPAGE:
1250 case presentation::ClickAction_LASTPAGE:
1251 case presentation::ClickAction_INVISIBLE:
1252 case presentation::ClickAction_STOPPRESENTATION:
1254 bOk = true;
1256 break;
1258 case presentation::ClickAction_PROGRAM:
1259 case presentation::ClickAction_BOOKMARK:
1260 case presentation::ClickAction_DOCUMENT:
1261 if( nFound & FoundFlags::Bookmark )
1263 if( eClickAction == presentation::ClickAction_BOOKMARK )
1265 aStrBookmark = getUiNameFromPageApiNameImpl( aStrBookmark );
1267 else if( eClickAction == presentation::ClickAction_DOCUMENT )
1269 sal_Int32 nPos = aStrBookmark.lastIndexOf( '#' );
1270 if( nPos >= 0 )
1272 aStrBookmark = aStrBookmark.subView( 0, nPos+1 )
1273 + getUiNameFromPageApiNameImpl( aStrBookmark.copy( nPos+1 ) );
1277 pInfo->SetBookmark( aStrBookmark );
1278 bOk = true;
1280 break;
1282 case presentation::ClickAction_MACRO:
1283 if( nFound & FoundFlags::Macro )
1285 pInfo->SetBookmark( aStrMacro );
1286 bOk = true;
1288 break;
1290 case presentation::ClickAction_VERB:
1291 if( nFound & FoundFlags::Verb )
1293 pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
1294 bOk = true;
1296 break;
1298 case presentation::ClickAction_VANISH:
1299 if( !( nFound & FoundFlags::Effect ) )
1300 break;
1302 pInfo->meSecondEffect = eEffect;
1303 pInfo->meSecondSpeed = nFound & FoundFlags::Speed ? eSpeed : presentation::AnimationSpeed_MEDIUM;
1305 bOk = true;
1307 [[fallthrough]];
1309 case presentation::ClickAction_SOUND:
1310 if( nFound & FoundFlags::SoundUrl )
1312 pInfo->SetBookmark( aStrSoundURL );
1313 if( eClickAction != presentation::ClickAction_SOUND )
1314 pInfo->mbSecondSoundOn = !aStrSoundURL.isEmpty();
1315 pInfo->mbSecondPlayFull = (nFound & FoundFlags::PlayFull) && bPlayFull;
1317 bOk = true;
1319 break;
1320 default:
1321 break;
1324 else
1326 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo( true );
1328 DBG_ASSERT( pInfo, "shape animation info could not be created!" );
1329 if( nullptr == pInfo )
1330 break;
1332 clearEventsInAnimationInfo( pInfo );
1333 pInfo->meClickAction = presentation::ClickAction_MACRO;
1335 if ( SfxApplication::IsXScriptURL( aStrMacro ) )
1337 pInfo->SetBookmark( aStrMacro );
1339 else
1341 sal_Int32 nIdx{ 0 };
1342 const std::u16string_view aLibName = o3tl::getToken(aStrMacro, 0, '.', nIdx);
1343 const std::u16string_view aModulName = o3tl::getToken(aStrMacro, 0, '.', nIdx);
1344 const std::u16string_view aMacroName = o3tl::getToken(aStrMacro, 0, '.', nIdx);
1346 OUStringBuffer sBuffer(
1347 OUString::Concat(aMacroName) + OUStringChar('.') + aModulName + OUStringChar('.') + aLibName + OUStringChar('.') );
1349 if ( aStrLibrary == "StarOffice" )
1351 sBuffer.append( "BASIC" );
1353 else
1355 sBuffer.append( aStrLibrary );
1358 pInfo->SetBookmark( sBuffer.makeStringAndClear() );
1360 bOk = true;
1363 while(false);
1365 if( !bOk )
1366 throw lang::IllegalArgumentException();
1369 // XNameAccess
1370 uno::Any SAL_CALL SdUnoEventsAccess::getByName( const OUString& aName )
1372 if( mpShape == nullptr || aName != gaStrOnClick )
1373 throw container::NoSuchElementException();
1375 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
1377 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
1378 if( pInfo )
1379 eClickAction = pInfo->meClickAction;
1381 sal_Int32 nPropertyCount = 2;
1382 switch( eClickAction )
1384 case presentation::ClickAction_NONE:
1385 case presentation::ClickAction_PREVPAGE:
1386 case presentation::ClickAction_NEXTPAGE:
1387 case presentation::ClickAction_FIRSTPAGE:
1388 case presentation::ClickAction_LASTPAGE:
1389 case presentation::ClickAction_INVISIBLE:
1390 case presentation::ClickAction_STOPPRESENTATION:
1391 break;
1392 case presentation::ClickAction_PROGRAM:
1393 case presentation::ClickAction_VERB:
1394 case presentation::ClickAction_BOOKMARK:
1395 case presentation::ClickAction_DOCUMENT:
1396 case presentation::ClickAction_MACRO:
1397 if ( !SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
1398 nPropertyCount += 1;
1399 break;
1401 case presentation::ClickAction_SOUND:
1402 nPropertyCount += 2;
1403 break;
1405 case presentation::ClickAction_VANISH:
1406 nPropertyCount += 4;
1407 break;
1408 default:
1409 break;
1412 uno::Sequence< beans::PropertyValue > aProperties( nPropertyCount );
1413 beans::PropertyValue* pProperties = aProperties.getArray();
1415 uno::Any aAny;
1417 if( eClickAction == presentation::ClickAction_MACRO )
1419 if ( SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
1421 // Scripting Framework URL
1422 aAny <<= gaStrScript;
1423 pProperties->Name = gaStrEventType;
1424 pProperties->Handle = -1;
1425 pProperties->Value = aAny;
1426 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1427 pProperties++;
1429 aAny <<= pInfo->GetBookmark();
1430 pProperties->Name = gaStrScript;
1431 pProperties->Handle = -1;
1432 pProperties->Value = aAny;
1433 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1434 pProperties++;
1436 else
1438 // Old Basic macro URL
1439 aAny <<= OUString(gaStrStarBasic);
1440 pProperties->Name = gaStrEventType;
1441 pProperties->Handle = -1;
1442 pProperties->Value = aAny;
1443 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1444 pProperties++;
1446 OUString aMacro = pInfo->GetBookmark();
1448 // aMacro has got following format:
1449 // "Macroname.Modulname.Libname.Documentname" or
1450 // "Macroname.Modulname.Libname.Applicationname"
1451 sal_Int32 nIdx{ 0 };
1452 const std::u16string_view aMacroName = o3tl::getToken(aMacro, 0, '.', nIdx);
1453 const std::u16string_view aModulName = o3tl::getToken(aMacro, 0, '.', nIdx);
1454 const std::u16string_view aLibName = o3tl::getToken(aMacro, 0, '.', nIdx);
1456 OUString sBuffer = OUString::Concat(aLibName) +
1457 "." +
1458 aModulName +
1459 "." +
1460 aMacroName;
1462 aAny <<= sBuffer;
1463 pProperties->Name = gaStrMacroName;
1464 pProperties->Handle = -1;
1465 pProperties->Value = aAny;
1466 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1467 pProperties++;
1469 aAny <<= u"StarOffice"_ustr;
1470 pProperties->Name = gaStrLibrary;
1471 pProperties->Handle = -1;
1472 pProperties->Value = aAny;
1473 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1476 else
1478 aAny <<= gaStrPresentation;
1479 pProperties->Name = gaStrEventType;
1480 pProperties->Handle = -1;
1481 pProperties->Value = aAny;
1482 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1483 pProperties++;
1485 aAny <<= eClickAction;
1486 pProperties->Name = gaStrClickAction;
1487 pProperties->Handle = -1;
1488 pProperties->Value = aAny;
1489 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1490 pProperties++;
1492 switch( eClickAction )
1494 case presentation::ClickAction_NONE:
1495 case presentation::ClickAction_PREVPAGE:
1496 case presentation::ClickAction_NEXTPAGE:
1497 case presentation::ClickAction_FIRSTPAGE:
1498 case presentation::ClickAction_LASTPAGE:
1499 case presentation::ClickAction_INVISIBLE:
1500 case presentation::ClickAction_STOPPRESENTATION:
1501 break;
1502 case presentation::ClickAction_BOOKMARK:
1504 const OUString aStrBookmark( getPageApiNameFromUiName( pInfo->GetBookmark()) );
1505 pProperties->Name = gaStrBookmark;
1506 pProperties->Handle = -1;
1507 pProperties->Value <<= aStrBookmark;
1508 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1510 break;
1512 case presentation::ClickAction_DOCUMENT:
1513 case presentation::ClickAction_PROGRAM:
1515 OUString aString( pInfo->GetBookmark());
1516 sal_Int32 nPos = aString.lastIndexOf( '#' );
1517 if( nPos >= 0 )
1519 aString = aString.subView( 0, nPos+1 ) +
1520 getPageApiNameFromUiName( aString.copy( nPos+1 ) );
1522 pProperties->Name = gaStrBookmark;
1523 pProperties->Handle = -1;
1524 pProperties->Value <<= aString;
1525 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1527 break;
1529 case presentation::ClickAction_VANISH:
1530 aAny <<= pInfo->meSecondEffect;
1531 pProperties->Name = gaStrEffect;
1532 pProperties->Handle = -1;
1533 pProperties->Value = aAny;
1534 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1535 pProperties++;
1537 aAny <<= pInfo->meSecondSpeed;
1538 pProperties->Name = gaStrSpeed;
1539 pProperties->Handle = -1;
1540 pProperties->Value = aAny;
1541 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1542 pProperties++;
1544 [[fallthrough]];
1546 case presentation::ClickAction_SOUND:
1547 if( eClickAction == presentation::ClickAction_SOUND || pInfo->mbSecondSoundOn )
1549 aAny <<= pInfo->GetBookmark();
1550 pProperties->Name = gaStrSoundURL;
1551 pProperties->Handle = -1;
1552 pProperties->Value = aAny;
1553 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1554 pProperties++;
1556 pProperties->Name = gaStrPlayFull;
1557 pProperties->Handle = -1;
1558 pProperties->Value <<= pInfo->mbSecondPlayFull;
1559 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1561 break;
1563 case presentation::ClickAction_VERB:
1564 aAny <<= static_cast<sal_Int32>(pInfo->mnVerb);
1565 pProperties->Name = gaStrVerb;
1566 pProperties->Handle = -1;
1567 pProperties->Value = aAny;
1568 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1569 break;
1570 default:
1571 break;
1575 aAny <<= aProperties;
1576 return aAny;
1579 uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getElementNames( )
1581 return { gaStrOnClick };
1584 sal_Bool SAL_CALL SdUnoEventsAccess::hasByName( const OUString& aName )
1586 return aName == gaStrOnClick;
1589 // XElementAccess
1590 uno::Type SAL_CALL SdUnoEventsAccess::getElementType( )
1592 return cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get();
1595 sal_Bool SAL_CALL SdUnoEventsAccess::hasElements( )
1597 return true;
1600 // XServiceInfo
1601 OUString SAL_CALL SdUnoEventsAccess::getImplementationName( )
1603 return u"SdUnoEventsAccess"_ustr;
1606 sal_Bool SAL_CALL SdUnoEventsAccess::supportsService( const OUString& ServiceName )
1608 return cppu::supportsService(this, ServiceName);
1611 uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getSupportedServiceNames( )
1613 return { gaStrServiceName };
1616 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */