bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / unoidl / unoobj.cxx
blobe0dab445c5c60a30580ddccc12291127bbe4c1c8
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 <utility>
25 #include <com/sun/star/style/XStyle.hpp>
26 #include <com/sun/star/presentation/ClickAction.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/beans/PropertyState.hpp>
29 #include <rtl/ustrbuf.hxx>
30 #include <svl/itemprop.hxx>
31 #include <svl/style.hxx>
32 #include <svx/svdpool.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/app.hxx>
35 #include <svtools/unoimap.hxx>
36 #include <svtools/unoevent.hxx>
37 #include <sfx2/bindings.hxx>
38 #include <sfx2/event.hxx>
39 #include <sfx2/sfxsids.hrc>
40 #include <comphelper/extract.hxx>
41 #include <cppuhelper/implbase.hxx>
42 #include <cppuhelper/supportsservice.hxx>
43 #include <svx/unoshape.hxx>
44 #include <svx/svdotext.hxx>
45 #include <svx/unoapi.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/serviceinfohelper.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::makeAny;
78 using ::com::sun::star::uno::Any;
79 using ::com::sun::star::drawing::XShape;
81 #define WID_EFFECT 1
82 #define WID_SPEED 2
83 #define WID_TEXTEFFECT 3
84 #define WID_BOOKMARK 4
85 #define WID_CLICKACTION 5
86 #define WID_PLAYFULL 6
87 #define WID_SOUNDFILE 7
88 #define WID_SOUNDON 8
89 #define WID_BLUESCREEN 9
90 #define WID_VERB 10
91 #define WID_DIMCOLOR 11
92 #define WID_DIMHIDE 12
93 #define WID_DIMPREV 13
94 #define WID_PRESORDER 14
95 #define WID_STYLE 15
96 #define WID_ANIMPATH 16
97 #define WID_IMAGEMAP 17
98 #define WID_ISANIMATION 18
99 #define WID_THAT_NEED_ANIMINFO 19
101 #define WID_ISEMPTYPRESOBJ 20
102 #define WID_ISPRESOBJ 21
103 #define WID_MASTERDEPEND 22
105 #define WID_NAVORDER 23
106 #define WID_PLACEHOLDERTEXT 24
107 #define WID_LEGACYFRAGMENT 25
109 #define IMPRESS_MAP_ENTRIES \
110 { OUString(UNO_NAME_OBJ_LEGACYFRAGMENT),WID_LEGACYFRAGMENT, cppu::UnoType<drawing::XShape>::get(), 0, 0},\
111 { OUString(UNO_NAME_OBJ_ANIMATIONPATH), WID_ANIMPATH, cppu::UnoType<drawing::XShape>::get(), 0, 0},\
112 { OUString(UNO_NAME_OBJ_BOOKMARK), WID_BOOKMARK, cppu::UnoType<OUString>::get(), 0, 0},\
113 { OUString(UNO_NAME_OBJ_DIMCOLOR), WID_DIMCOLOR, cppu::UnoType<sal_Int32>::get(), 0, 0},\
114 { OUString(UNO_NAME_OBJ_DIMHIDE), WID_DIMHIDE, cppu::UnoType<bool>::get(), 0, 0},\
115 { OUString(UNO_NAME_OBJ_DIMPREV), WID_DIMPREV, cppu::UnoType<bool>::get(), 0, 0},\
116 { OUString(UNO_NAME_OBJ_EFFECT), WID_EFFECT, cppu::UnoType<presentation::AnimationEffect>::get(), 0, 0},\
117 { OUString(UNO_NAME_OBJ_ISEMPTYPRESOBJ),WID_ISEMPTYPRESOBJ, cppu::UnoType<bool>::get(), 0, 0},\
118 { OUString(UNO_NAME_OBJ_ISPRESOBJ), WID_ISPRESOBJ, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY, 0},\
119 { OUString(UNO_NAME_OBJ_MASTERDEPENDENT),WID_MASTERDEPEND, cppu::UnoType<bool>::get(), 0, 0},\
120 { OUString(UNO_NAME_OBJ_CLICKACTION), WID_CLICKACTION, cppu::UnoType<presentation::ClickAction>::get(), 0, 0},\
121 { OUString(UNO_NAME_OBJ_PLAYFULL), WID_PLAYFULL, cppu::UnoType<bool>::get(), 0, 0},\
122 { OUString(UNO_NAME_OBJ_PRESORDER), WID_PRESORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
123 { OUString(UNO_NAME_OBJ_STYLE), WID_STYLE, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},\
124 { OUString(UNO_NAME_OBJ_SOUNDFILE), WID_SOUNDFILE, cppu::UnoType<OUString>::get(), 0, 0},\
125 { OUString(UNO_NAME_OBJ_SOUNDON), WID_SOUNDON, cppu::UnoType<bool>::get(), 0, 0},\
126 { OUString(UNO_NAME_OBJ_SPEED), WID_SPEED, cppu::UnoType<presentation::AnimationSpeed>::get(), 0, 0},\
127 { OUString(UNO_NAME_OBJ_TEXTEFFECT), WID_TEXTEFFECT, cppu::UnoType<presentation::AnimationEffect>::get(), 0, 0},\
128 { OUString(UNO_NAME_OBJ_BLUESCREEN), WID_BLUESCREEN, cppu::UnoType<sal_Int32>::get(), 0, 0},\
129 { OUString(UNO_NAME_OBJ_VERB), WID_VERB, cppu::UnoType<sal_Int32>::get(), 0, 0},\
130 { OUString("IsAnimation"), WID_ISANIMATION, cppu::UnoType<bool>::get(), 0, 0},\
131 { OUString("NavigationOrder"), WID_NAVORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
132 { OUString("PlaceholderText"), WID_PLACEHOLDERTEXT, cppu::UnoType<OUString>::get(), 0, 0},\
133 { OUString(), 0, css::uno::Type(), 0, 0 }
135 static const SfxItemPropertyMapEntry* lcl_GetImpress_SdXShapePropertyGraphicMap_Impl()
138 static const SfxItemPropertyMapEntry aImpress_SdXShapePropertyGraphicMap_Impl[] =
140 { OUString("ImageMap"), WID_IMAGEMAP, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
141 IMPRESS_MAP_ENTRIES
143 return aImpress_SdXShapePropertyGraphicMap_Impl;
146 static const SfxItemPropertyMapEntry* lcl_GetImpress_SdXShapePropertySimpleMap_Impl()
149 static const SfxItemPropertyMapEntry aImpress_SdXShapePropertySimpleMap_Impl[] =
151 IMPRESS_MAP_ENTRIES
153 return aImpress_SdXShapePropertySimpleMap_Impl;
156 #define DRAW_MAP_ENTRIES\
157 { OUString(UNO_NAME_OBJ_BOOKMARK), WID_BOOKMARK, cppu::UnoType<OUString>::get(), 0, 0},\
158 { OUString(UNO_NAME_OBJ_CLICKACTION), WID_CLICKACTION, cppu::UnoType<presentation::ClickAction>::get(),0, 0},\
159 { OUString(UNO_NAME_OBJ_STYLE), WID_STYLE, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},\
160 { OUString("NavigationOrder"), WID_NAVORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
161 { OUString(), 0, css::uno::Type(), 0, 0 }
163 static const SfxItemPropertyMapEntry* lcl_GetDraw_SdXShapePropertySimpleMap_Impl()
165 static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyMap_Impl[] =
167 DRAW_MAP_ENTRIES
169 return aDraw_SdXShapePropertyMap_Impl;
171 static const SfxItemPropertyMapEntry* lcl_GetDraw_SdXShapePropertyGraphicMap_Impl()
173 static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyGraphicMap_Impl[] =
175 { OUString("ImageMap"), WID_IMAGEMAP, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
176 DRAW_MAP_ENTRIES
178 return aDraw_SdXShapePropertyGraphicMap_Impl;
180 static const SfxItemPropertyMapEntry* lcl_ImplGetShapePropertyMap( bool bImpress, bool bGraphicObj )
182 const SfxItemPropertyMapEntry* pRet = nullptr;
183 if( bImpress )
185 if( bGraphicObj )
186 pRet = lcl_GetImpress_SdXShapePropertyGraphicMap_Impl();
187 else
188 pRet = lcl_GetImpress_SdXShapePropertySimpleMap_Impl();
190 else
192 if( bGraphicObj )
193 pRet = lcl_GetDraw_SdXShapePropertyGraphicMap_Impl();
194 else
195 pRet = lcl_GetDraw_SdXShapePropertySimpleMap_Impl();
197 return pRet;
200 static const SvxItemPropertySet* lcl_ImplGetShapePropertySet( bool bImpress, bool bGraphicObj )
202 const SvxItemPropertySet* pRet = nullptr;
203 if( bImpress )
205 if( bGraphicObj )
207 static SvxItemPropertySet aImpress_SdXShapePropertyGraphicSet_Impl( lcl_GetImpress_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
208 pRet = &aImpress_SdXShapePropertyGraphicSet_Impl;
210 else
212 static SvxItemPropertySet aImpress_SdXShapePropertySet_Impl(lcl_GetImpress_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
213 pRet = &aImpress_SdXShapePropertySet_Impl;
216 else
218 if( bGraphicObj )
220 static SvxItemPropertySet aDraw_SdXShapePropertyGraphicSet_Impl(lcl_GetDraw_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
221 pRet = &aDraw_SdXShapePropertyGraphicSet_Impl;
223 else
225 static SvxItemPropertySet aDraw_SdXShapePropertySet_Impl( lcl_GetDraw_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
226 pRet = &aDraw_SdXShapePropertySet_Impl;
229 return pRet;
231 static const SfxItemPropertyMapEntry* lcl_GetEmpty_SdXShapePropertyMap_Impl()
233 static const SfxItemPropertyMapEntry aEmpty_SdXShapePropertyMap_Impl[] =
235 { OUString(), 0, css::uno::Type(), 0, 0 }
237 return aEmpty_SdXShapePropertyMap_Impl;
240 static const SvxItemPropertySet* lcl_GetEmpty_SdXShapePropertySet_Impl()
242 static SvxItemPropertySet aEmptyPropSet( lcl_GetEmpty_SdXShapePropertyMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool() );
243 return &aEmptyPropSet;
245 const SvEventDescription* ImplGetSupportedMacroItems()
247 static const SvEventDescription aMacroDescriptionsImpl[] =
249 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
250 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
251 { SvMacroItemId::NONE, nullptr }
254 return aMacroDescriptionsImpl;
257 SdXShape::SdXShape(SvxShape* pShape, SdXImpressDocument* pModel)
258 : mpShape( pShape ),
259 mpPropSet( pModel?
260 lcl_ImplGetShapePropertySet(pModel->IsImpressDocument(), pShape->getShapeKind() == OBJ_GRAF )
261 : lcl_GetEmpty_SdXShapePropertySet_Impl() ),
262 mpMap( pModel?
263 lcl_ImplGetShapePropertyMap(pModel->IsImpressDocument(), pShape->getShapeKind() == OBJ_GRAF )
264 : lcl_GetEmpty_SdXShapePropertyMap_Impl() ),
265 mpModel(pModel)
268 pShape->setMaster( this );
271 SdXShape::~SdXShape() throw()
275 void SdXShape::dispose()
277 mpShape->setMaster( nullptr );
278 delete this;
281 uno::Any SAL_CALL SdXShape::queryInterface( const uno::Type & rType )
283 return mpShape->queryInterface( rType );
286 void SAL_CALL SdXShape::acquire() throw()
288 mpShape->acquire();
291 void SAL_CALL SdXShape::release() throw()
293 mpShape->release();
296 bool SdXShape::queryAggregation( const css::uno::Type & rType, css::uno::Any& aAny )
298 if( mpModel && mpModel ->IsImpressDocument() )
300 if( rType == cppu::UnoType<document::XEventsSupplier>::get())
302 aAny <<= uno::Reference< document::XEventsSupplier >(this);
303 return true;
307 return false;
310 uno::Sequence< uno::Type > SAL_CALL SdXShape::getTypes()
312 if( mpModel && !mpModel->IsImpressDocument() )
314 return mpShape->_getTypes();
316 else
318 sal_uInt32 nObjId = mpShape->getShapeKind();
319 uno::Sequence< uno::Type > aTypes;
320 SdTypesCache& gImplTypesCache = SD_MOD()->gImplTypesCache;
321 SdTypesCache::iterator aIter( gImplTypesCache.find( nObjId ) );
322 if( aIter == gImplTypesCache.end() )
324 aTypes = mpShape->_getTypes();
325 sal_uInt32 nCount = aTypes.getLength();
326 aTypes.realloc( nCount+1 );
327 aTypes[nCount] = cppu::UnoType<lang::XTypeProvider>::get();
329 gImplTypesCache.insert(std::make_pair(nObjId, aTypes));
331 else
333 // use the already computed implementation id
334 aTypes = (*aIter).second;
336 return aTypes;
340 // XPropertyState
341 beans::PropertyState SAL_CALL SdXShape::getPropertyState( const OUString& PropertyName )
343 SolarMutexGuard aGuard;
345 if( mpPropSet->getPropertyMapEntry(PropertyName) )
347 return beans::PropertyState_DIRECT_VALUE;
349 else
351 SdrObject* pObj = mpShape->GetSdrObject();
352 if( pObj == nullptr || ( pObj->getSdrPageFromSdrObject()->IsMasterPage() && pObj->IsEmptyPresObj() ) )
353 return beans::PropertyState_DEFAULT_VALUE;
355 return mpShape->_getPropertyState( PropertyName );
359 void SAL_CALL SdXShape::setPropertyToDefault( const OUString& PropertyName )
361 SolarMutexGuard aGuard;
363 if( mpPropSet->getPropertyMapEntry(PropertyName) )
365 return;
367 else
369 mpShape->_setPropertyToDefault(PropertyName);
373 uno::Any SAL_CALL SdXShape::getPropertyDefault( const OUString& aPropertyName )
375 SolarMutexGuard aGuard;
377 if( mpPropSet->getPropertyMapEntry(aPropertyName) )
379 return getPropertyValue( aPropertyName );
381 else
383 uno::Any aRet( mpShape->_getPropertyDefault(aPropertyName) );
384 return aRet;
388 //XPropertySet
389 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL SdXShape::getPropertySetInfo()
391 SfxItemPropertyMapEntry const * nObjId = mpShape->getPropertyMapEntries();
392 css::uno::Reference<css::beans::XPropertySetInfo> pInfo;
394 SdExtPropertySetInfoCache& rCache = (mpModel && mpModel->IsImpressDocument()) ?
395 SD_MOD()->gImplImpressPropertySetInfoCache : SD_MOD()->gImplDrawPropertySetInfoCache;
397 SdExtPropertySetInfoCache::iterator aIter( rCache.find( nObjId ) );
398 if( aIter == rCache.end() )
400 uno::Reference< beans::XPropertySetInfo > xInfo( mpShape->_getPropertySetInfo() );
401 pInfo = new SfxExtItemPropertySetInfo( mpMap, xInfo->getProperties() );
403 rCache.insert(std::make_pair(nObjId, pInfo));
405 else
407 // use the already computed implementation id
408 pInfo = (*aIter).second;
411 return pInfo;
414 void SAL_CALL SdXShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue )
416 SolarMutexGuard aGuard;
418 const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);
420 if( pEntry )
422 SdrObject* pObj = mpShape->GetSdrObject();
423 if( pObj )
425 SdAnimationInfo* pInfo = GetAnimationInfo(pEntry->nWID <= WID_THAT_NEED_ANIMINFO);
427 switch(pEntry->nWID)
429 case WID_NAVORDER:
431 sal_Int32 nNavOrder = 0;
432 if(!(aValue >>= nNavOrder))
433 throw lang::IllegalArgumentException();
435 SdrObjList* pObjList = pObj->getParentSdrObjListFromSdrObject();
436 if( pObjList )
437 pObjList->SetObjectNavigationPosition( *pObj, (nNavOrder < 0) ? SAL_MAX_UINT32 : static_cast< sal_uInt32 >( nNavOrder ) );
438 break;
441 case WID_EFFECT:
443 AnimationEffect eEffect;
444 if(!(aValue >>= eEffect))
445 throw lang::IllegalArgumentException();
447 EffectMigration::SetAnimationEffect( mpShape, eEffect );
448 break;
450 case WID_TEXTEFFECT:
452 AnimationEffect eEffect;
453 if(!(aValue >>= eEffect))
454 throw lang::IllegalArgumentException();
456 EffectMigration::SetTextAnimationEffect( mpShape, eEffect );
457 break;
459 case WID_SPEED:
461 AnimationSpeed eSpeed;
462 if(!(aValue>>=eSpeed))
463 throw lang::IllegalArgumentException();
465 EffectMigration::SetAnimationSpeed( mpShape, eSpeed );
466 break;
468 case WID_ISANIMATION:
470 bool bIsAnimation(false);
472 if(!(aValue >>= bIsAnimation))
474 throw lang::IllegalArgumentException();
477 if(bIsAnimation)
479 SdrObjGroup* pGroup = dynamic_cast< SdrObjGroup* >(pObj);
480 SdPage* pPage = pGroup ? dynamic_cast< SdPage* >(pGroup->getSdrPageFromSdrObject()) : nullptr;
482 if (pPage)
484 // #i42894# Animated Group object, migrate that effect
485 EffectMigration::CreateAnimatedGroup(*pGroup, *pPage);
487 // #i42894# unfortunately when doing this all group members have to
488 // be moved to the page as direct members, else the currently
489 // available forms of animation do not work. If it succeeds,
490 // the group is empty and can be removed and deleted
491 if(!pGroup->GetSubList()->GetObjCount())
493 pPage->NbcRemoveObject(pGroup->GetOrdNum());
495 // always use SdrObject::Free(...) for SdrObjects (!)
496 SdrObject* pTemp(pGroup);
497 SdrObject::Free(pTemp);
501 //pInfo->mbIsMovie = bIsAnimation;
502 break;
504 case WID_BOOKMARK:
506 OUString aString;
507 if(!(aValue >>= aString))
508 throw lang::IllegalArgumentException();
510 pInfo->SetBookmark( SdDrawPage::getUiNameFromPageApiName( aString ) );
511 break;
513 case WID_CLICKACTION:
514 ::cppu::any2enum< presentation::ClickAction >( pInfo->meClickAction, aValue);
515 break;
517 // TODO: WID_PLAYFULL:
518 case WID_SOUNDFILE:
520 OUString aString;
521 if(!(aValue >>= aString))
522 throw lang::IllegalArgumentException();
523 pInfo->maSoundFile = aString;
524 EffectMigration::UpdateSoundEffect( mpShape, pInfo );
525 break;
528 case WID_SOUNDON:
530 if( !(aValue >>= pInfo->mbSoundOn) )
531 throw lang::IllegalArgumentException();
532 EffectMigration::UpdateSoundEffect( mpShape, pInfo );
533 break;
535 case WID_VERB:
537 sal_Int32 nVerb = 0;
538 if(!(aValue >>= nVerb))
539 throw lang::IllegalArgumentException();
541 pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
542 break;
544 case WID_DIMCOLOR:
546 sal_Int32 nColor = 0;
548 if( !(aValue >>= nColor) )
549 throw lang::IllegalArgumentException();
551 EffectMigration::SetDimColor( mpShape, nColor );
552 break;
554 case WID_DIMHIDE:
556 bool bDimHide = false;
557 if( !(aValue >>= bDimHide) )
558 throw lang::IllegalArgumentException();
560 EffectMigration::SetDimHide( mpShape, bDimHide );
561 break;
563 case WID_DIMPREV:
565 bool bDimPrevious = false;
566 if( !(aValue >>= bDimPrevious) )
567 throw lang::IllegalArgumentException();
569 EffectMigration::SetDimPrevious( mpShape, bDimPrevious );
570 break;
572 case WID_PRESORDER:
574 sal_Int32 nNewPos = 0;
575 if( !(aValue >>= nNewPos) )
576 throw lang::IllegalArgumentException();
578 EffectMigration::SetPresentationOrder( mpShape, nNewPos );
579 break;
581 case WID_STYLE:
582 SetStyleSheet( aValue );
583 break;
584 case WID_ISEMPTYPRESOBJ:
585 SetEmptyPresObj( ::cppu::any2bool(aValue) );
586 break;
587 case WID_MASTERDEPEND:
588 SetMasterDepend( ::cppu::any2bool(aValue) );
589 break;
591 case WID_LEGACYFRAGMENT:
593 uno::Reference< io::XInputStream > xInputStream;
594 aValue >>= xInputStream;
595 if( xInputStream.is() )
597 SvInputStream aStream( xInputStream );
598 SdrObject* pObject = mpShape->GetSdrObject();
599 SvxMSDffManager::ReadObjText( aStream, pObject );
602 break;
604 case WID_ANIMPATH:
606 uno::Reference< drawing::XShape > xShape( aValue, uno::UNO_QUERY );
607 SdrPathObj* pObj2 = xShape.is() ? dynamic_cast< SdrPathObj* >( GetSdrObjectFromXShape( xShape ) ) : nullptr;
609 if( pObj2 == nullptr )
610 throw lang::IllegalArgumentException();
612 EffectMigration::SetAnimationPath( mpShape, pObj2 );
613 break;
615 case WID_IMAGEMAP:
617 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
618 if( pDoc )
620 ImageMap aImageMap;
621 uno::Reference< uno::XInterface > xImageMap;
622 aValue >>= xImageMap;
624 if( !xImageMap.is() || !SvUnoImageMap_fillImageMap( xImageMap, aImageMap ) )
625 throw lang::IllegalArgumentException();
627 SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(pObj);
628 if( pIMapInfo )
630 // replace existing image map
631 pIMapInfo->SetImageMap( aImageMap );
633 else
635 // insert new user data with image map
636 pObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(aImageMap) ));
640 break;
644 else
646 mpShape->_setPropertyValue(aPropertyName, aValue);
649 if( mpModel )
650 mpModel->SetModified();
653 css::uno::Any SAL_CALL SdXShape::getPropertyValue( const OUString& PropertyName )
655 SolarMutexGuard aGuard;
657 uno::Any aRet;
659 const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);
661 if( pEntry && mpShape->GetSdrObject() )
663 SdAnimationInfo* pInfo = GetAnimationInfo();
665 switch(pEntry->nWID)
667 case WID_NAVORDER:
669 const sal_uInt32 nNavOrder = mpShape->GetSdrObject()->GetNavigationPosition();
670 aRet <<= nNavOrder == SAL_MAX_UINT32 ? static_cast<sal_Int32>(-1) : static_cast< sal_Int32 >(nNavOrder);
672 break;
673 case WID_EFFECT:
674 aRet <<= EffectMigration::GetAnimationEffect( mpShape );
675 break;
676 case WID_TEXTEFFECT:
677 aRet <<= EffectMigration::GetTextAnimationEffect( mpShape );
678 break;
679 case WID_ISPRESOBJ:
680 aRet <<= IsPresObj();
681 break;
682 case WID_ISEMPTYPRESOBJ:
683 aRet <<= IsEmptyPresObj();
684 break;
685 case WID_MASTERDEPEND:
686 aRet <<= IsMasterDepend();
687 break;
688 case WID_SPEED:
689 aRet <<= EffectMigration::GetAnimationSpeed( mpShape );
690 break;
691 case WID_ISANIMATION:
692 aRet <<= (pInfo && pInfo->mbIsMovie);
693 break;
694 case WID_PLACEHOLDERTEXT:
695 aRet <<= GetPlaceholderText();
696 break;
697 case WID_BOOKMARK:
699 OUString aString;
700 SdDrawDocument* pDoc = mpModel ? mpModel->GetDoc() : nullptr;
701 if (pInfo && pDoc)
703 // is the bookmark a page?
704 bool bIsMasterPage;
705 if(pDoc->GetPageByName( pInfo->GetBookmark(), bIsMasterPage ) != SDRPAGE_NOTFOUND)
707 aString = SdDrawPage::getPageApiNameFromUiName( pInfo->GetBookmark() );
709 else
711 aString = pInfo->GetBookmark() ;
712 sal_Int32 nPos = aString.lastIndexOf( '#' );
713 if( nPos >= 0 )
715 OUString aURL( aString.copy( 0, nPos+1 ) );
716 OUString aName( aString.copy( nPos+1 ) );
717 if(pDoc->GetPageByName( aName, bIsMasterPage ) != SDRPAGE_NOTFOUND)
719 aURL += SdDrawPage::getPageApiNameFromUiName( aName );
720 aString = aURL;
726 aRet <<= aString;
727 break;
729 case WID_CLICKACTION:
730 aRet <<= ( pInfo?pInfo->meClickAction:presentation::ClickAction_NONE );
731 break;
732 case WID_PLAYFULL:
733 aRet <<= ( pInfo && pInfo->mbPlayFull );
734 break;
735 case WID_SOUNDFILE:
736 aRet <<= EffectMigration::GetSoundFile( mpShape );
737 break;
738 case WID_SOUNDON:
739 aRet <<= EffectMigration::GetSoundOn( mpShape );
740 break;
741 case WID_BLUESCREEN:
742 aRet <<= pInfo ? pInfo->maBlueScreen : Color(0x00ffffff);
743 break;
744 case WID_VERB:
745 aRet <<= static_cast<sal_Int32>( pInfo?pInfo->mnVerb:0 );
746 break;
747 case WID_DIMCOLOR:
748 aRet <<= EffectMigration::GetDimColor( mpShape );
749 break;
750 case WID_DIMHIDE:
751 aRet <<= EffectMigration::GetDimHide( mpShape );
752 break;
753 case WID_DIMPREV:
754 aRet <<= EffectMigration::GetDimPrevious( mpShape );
755 break;
756 case WID_PRESORDER:
757 aRet <<= EffectMigration::GetPresentationOrder( mpShape );
758 break;
759 case WID_STYLE:
760 aRet = GetStyleSheet();
761 break;
762 case WID_IMAGEMAP:
764 uno::Reference< uno::XInterface > xImageMap;
766 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
767 if( pDoc )
770 SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(mpShape->GetSdrObject());
771 if( pIMapInfo )
773 const ImageMap& rIMap = pIMapInfo->GetImageMap();
774 xImageMap = SvUnoImageMap_createInstance( rIMap, ImplGetSupportedMacroItems() );
776 else
778 xImageMap = SvUnoImageMap_createInstance();
782 aRet <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
783 break;
787 else
789 aRet = mpShape->_getPropertyValue(PropertyName);
792 return aRet;
795 /** */
796 SdAnimationInfo* SdXShape::GetAnimationInfo( bool bCreate ) const
798 SdAnimationInfo* pInfo = nullptr;
800 SdrObject* pObj = mpShape->GetSdrObject();
801 if(pObj)
802 pInfo = SdDrawDocument::GetShapeUserData(*pObj, bCreate);
804 return pInfo;
807 uno::Sequence< OUString > SAL_CALL SdXShape::getSupportedServiceNames()
809 uno::Sequence< OUString > aSeq( mpShape->_getSupportedServiceNames() );
811 comphelper::ServiceInfoHelper::addToSequence( aSeq, {"com.sun.star.presentation.Shape",
812 "com.sun.star.document.LinkTarget"} );
814 SdrObject* pObj = mpShape->GetSdrObject();
815 if(pObj && pObj->GetObjInventor() == SdrInventor::Default )
817 sal_uInt32 nInventor = pObj->GetObjIdentifier();
818 switch( nInventor )
820 case OBJ_TITLETEXT:
821 comphelper::ServiceInfoHelper::addToSequence( aSeq, {"com.sun.star.presentation.TitleTextShape"} );
822 break;
823 case OBJ_OUTLINETEXT:
824 comphelper::ServiceInfoHelper::addToSequence( aSeq, {"com.sun.star.presentation.OutlinerShape"} );
825 break;
828 return aSeq;
831 /** checks if this is a presentation object
833 bool SdXShape::IsPresObj() const
835 SdrObject* pObj = mpShape->GetSdrObject();
836 if(pObj)
838 SdPage* pPage = dynamic_cast<SdPage* >(pObj->getSdrPageFromSdrObject());
839 if(pPage)
840 return pPage->GetPresObjKind(pObj) != PRESOBJ_NONE;
842 return false;
845 /** checks if this presentation object is empty
847 bool SdXShape::IsEmptyPresObj() const
849 SdrObject* pObj = mpShape->GetSdrObject();
850 if( (pObj != nullptr) && pObj->IsEmptyPresObj() )
852 // check if the object is in edit, then if it's temporarily not empty
853 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
854 if( pTextObj == nullptr )
855 return true;
857 return !pTextObj->CanCreateEditOutlinerParaObject();
860 return false;
863 OUString SdXShape::GetPlaceholderText() const
865 // only possible if this actually *is* a presentation object
866 if( !IsPresObj() )
867 return OUString();
869 SdrObject* pObj = mpShape->GetSdrObject();
870 if( pObj == nullptr )
871 return OUString();
873 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
874 DBG_ASSERT( pPage, "no page?" );
875 if( pPage == nullptr )
876 return OUString();
878 return pPage->GetPresObjText( pPage->GetPresObjKind(pObj) );
881 /** sets/reset the empty status of a presentation object
883 void SdXShape::SetEmptyPresObj(bool bEmpty)
885 // only possible if this actually *is* a presentation object
886 if( !IsPresObj() )
887 return;
889 SdrObject* pObj = mpShape->GetSdrObject();
890 if( pObj == nullptr )
891 return;
893 if( pObj->IsEmptyPresObj() == bEmpty )
894 return;
896 if(!bEmpty)
898 OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
899 const bool bVertical = pOutlinerParaObject && pOutlinerParaObject->IsVertical();
901 // really delete SdrOutlinerObj at pObj
902 pObj->NbcSetOutlinerParaObject(nullptr);
903 if( bVertical && dynamic_cast<SdrTextObj*>( pObj ) )
904 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );
906 SdrGrafObj* pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj );
907 if( pGraphicObj )
909 Graphic aEmpty;
910 pGraphicObj->SetGraphic(aEmpty);
912 else
914 SdrOle2Obj* pOleObj = dynamic_cast< SdrOle2Obj* >( pObj );
915 if( pOleObj )
917 pOleObj->ClearGraphic();
921 else
923 // now set an empty OutlinerParaObject at pObj without
924 // any content but with the style of the old OutlinerParaObjects
925 // first paragraph
928 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
929 DBG_ASSERT( pDoc, "no document?" );
930 if( pDoc == nullptr)
931 break;
933 SdOutliner* pOutliner = pDoc->GetInternalOutliner();
934 DBG_ASSERT( pOutliner, "no outliner?" );
935 if( pOutliner == nullptr )
936 break;
938 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
939 DBG_ASSERT( pPage, "no page?" );
940 if( pPage == nullptr )
941 break;
943 OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
944 pOutliner->SetText( *pOutlinerParaObject );
945 const bool bVertical = pOutliner->IsVertical();
947 pOutliner->Clear();
948 pOutliner->SetVertical( bVertical );
949 pOutliner->SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(pDoc->GetStyleSheetPool()) );
950 pOutliner->SetStyleSheet( 0, pPage->GetTextStyleSheetForObject( pObj ) );
951 pOutliner->Insert( pPage->GetPresObjText( pPage->GetPresObjKind(pObj) ) );
952 pObj->SetOutlinerParaObject( pOutliner->CreateParaObject() );
953 pOutliner->Clear();
955 while(false);
958 pObj->SetEmptyPresObj(bEmpty);
961 bool SdXShape::IsMasterDepend() const throw()
963 SdrObject* pObj = mpShape->GetSdrObject();
964 return pObj && pObj->GetUserCall() != nullptr;
967 void SdXShape::SetMasterDepend( bool bDepend ) throw()
969 if( IsMasterDepend() == bDepend )
970 return;
972 SdrObject* pObj = mpShape->GetSdrObject();
973 if( pObj )
975 if( bDepend )
977 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
978 pObj->SetUserCall( pPage );
980 else
982 pObj->SetUserCall( nullptr );
987 void SdXShape::SetStyleSheet( const uno::Any& rAny )
989 SdrObject* pObj = mpShape->GetSdrObject();
990 if( pObj == nullptr )
991 throw beans::UnknownPropertyException();
993 uno::Reference< style::XStyle > xStyle( rAny, uno::UNO_QUERY );
994 SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle );
996 const SfxStyleSheet* pOldStyleSheet = pObj->GetStyleSheet();
997 if( pOldStyleSheet == pStyleSheet )
998 return;
1000 if( pStyleSheet == nullptr || (pStyleSheet->GetFamily() != SfxStyleFamily::Para && pStyleSheet->GetFamily() != SfxStyleFamily::Page) )
1001 throw lang::IllegalArgumentException();
1003 pObj->SetStyleSheet( pStyleSheet, false );
1005 SdDrawDocument* pDoc = mpModel? mpModel->GetDoc() : nullptr;
1006 if( pDoc )
1008 ::sd::DrawDocShell* pDocSh = pDoc->GetDocSh();
1009 ::sd::ViewShell* pViewSh = pDocSh ? pDocSh->GetViewShell() : nullptr;
1011 if( pViewSh )
1012 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2 );
1016 uno::Any SdXShape::GetStyleSheet() const
1018 SdrObject* pObj = mpShape->GetSdrObject();
1019 if( pObj == nullptr )
1020 throw beans::UnknownPropertyException();
1022 SfxStyleSheet* pStyleSheet = pObj->GetStyleSheet();
1023 // it is possible for shapes inside a draw to have a presentation style
1024 // but we don't want this for the api
1025 if( (pStyleSheet == nullptr) || ((pStyleSheet->GetFamily() != SfxStyleFamily::Para) && !mpModel->IsImpressDocument()) )
1026 return Any();
1028 return Any( uno::Reference< style::XStyle >( dynamic_cast< SfxUnoStyleSheet* >( pStyleSheet ) ) );
1031 class SdUnoEventsAccess : public cppu::WeakImplHelper< css::container::XNameReplace, css::lang::XServiceInfo >
1033 private:
1034 SdXShape* const mpShape;
1036 public:
1037 explicit SdUnoEventsAccess(SdXShape* pShape) throw();
1039 // XNameReplace
1040 virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
1042 // XNameAccess
1043 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
1044 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
1045 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
1047 // XElementAccess
1048 virtual css::uno::Type SAL_CALL getElementType( ) override;
1049 virtual sal_Bool SAL_CALL hasElements( ) override;
1051 // XServiceInfo
1052 virtual OUString SAL_CALL getImplementationName( ) override;
1053 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1054 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
1057 // XEventsSupplier
1058 uno::Reference< container::XNameReplace > SAL_CALL SdXShape::getEvents( )
1060 return new SdUnoEventsAccess( this );
1063 static const OUStringLiteral gaStrOnClick( "OnClick" );
1064 static const OUStringLiteral gaStrServiceName( "com.sun.star.documents.Events" );
1065 static const OUStringLiteral gaStrEventType( "EventType" );
1066 static const OUStringLiteral gaStrPresentation( "Presentation" );
1067 static const OUStringLiteral gaStrLibrary("Library");
1068 static const OUStringLiteral gaStrMacroName("MacroName");
1069 static const OUStringLiteral gaStrClickAction( "ClickAction" );
1070 static const OUStringLiteral gaStrBookmark( "Bookmark" );
1071 static const OUStringLiteral gaStrEffect( "Effect" );
1072 static const OUStringLiteral gaStrPlayFull( "PlayFull" );
1073 static const OUStringLiteral gaStrVerb( "Verb" );
1074 static const OUStringLiteral gaStrSoundURL( "SoundURL" );
1075 static const OUStringLiteral gaStrSpeed( "Speed" );
1076 static const OUStringLiteral gaStrStarBasic( "StarBasic" );
1077 static const OUStringLiteral gaStrScript( "Script" );
1079 SdUnoEventsAccess::SdUnoEventsAccess( SdXShape* pShape ) throw()
1080 : mpShape( pShape )
1084 enum class FoundFlags {
1085 NONE = 0x0000,
1086 ClickAction = 0x0001,
1087 Bookmark = 0x0002,
1088 Effect = 0x0004,
1089 PlayFull = 0x0008,
1090 Verb = 0x0010,
1091 SoundUrl = 0x0020,
1092 Speed = 0x0040,
1093 EventType = 0x0080,
1094 Macro = 0x0100,
1095 Library = 0x0200,
1097 namespace o3tl {
1098 template<> struct typed_flags<FoundFlags> : is_typed_flags<FoundFlags, 0x03ff> {};
1101 static void clearEventsInAnimationInfo( SdAnimationInfo* pInfo )
1103 pInfo->SetBookmark( "" );
1104 pInfo->mbSecondSoundOn = false;
1105 pInfo->mbSecondPlayFull = false;
1106 pInfo->meClickAction = presentation::ClickAction_NONE;
1107 pInfo->meSecondEffect = presentation::AnimationEffect_NONE;
1108 pInfo->meSecondSpeed = presentation::AnimationSpeed_MEDIUM;
1109 pInfo->mnVerb = 0;
1112 // XNameReplace
1113 void SAL_CALL SdUnoEventsAccess::replaceByName( const OUString& aName, const uno::Any& aElement )
1115 if( mpShape == nullptr || aName != gaStrOnClick )
1116 throw container::NoSuchElementException();
1118 uno::Sequence< beans::PropertyValue > aProperties;
1119 if( !aElement.hasValue() || aElement.getValueType() != getElementType() || !(aElement >>= aProperties) )
1120 throw lang::IllegalArgumentException();
1122 FoundFlags nFound = FoundFlags::NONE;
1124 OUString aStrEventType;
1125 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
1126 presentation::AnimationEffect eEffect = presentation::AnimationEffect_NONE;
1127 presentation::AnimationSpeed eSpeed = presentation::AnimationSpeed_MEDIUM;
1128 OUString aStrSoundURL;
1129 bool bPlayFull = false;
1130 sal_Int32 nVerb = 0;
1131 OUString aStrMacro;
1132 OUString aStrLibrary;
1133 OUString aStrBookmark;
1135 for( const beans::PropertyValue& rProperty : std::as_const(aProperties) )
1137 if( !( nFound & FoundFlags::EventType ) && rProperty.Name == gaStrEventType )
1139 if( rProperty.Value >>= aStrEventType )
1141 nFound |= FoundFlags::EventType;
1142 continue;
1145 else if( !( nFound & FoundFlags::ClickAction ) && rProperty.Name == gaStrClickAction )
1147 if( rProperty.Value >>= eClickAction )
1149 nFound |= FoundFlags::ClickAction;
1150 continue;
1153 else if( !( nFound & FoundFlags::Macro ) && ( rProperty.Name == gaStrMacroName || rProperty.Name == gaStrScript ) )
1155 if( rProperty.Value >>= aStrMacro )
1157 nFound |= FoundFlags::Macro;
1158 continue;
1161 else if( !( nFound & FoundFlags::Library ) && rProperty.Name == gaStrLibrary )
1163 if( rProperty.Value >>= aStrLibrary )
1165 nFound |= FoundFlags::Library;
1166 continue;
1169 else if( !( nFound & FoundFlags::Effect ) && rProperty.Name == gaStrEffect )
1171 if( rProperty.Value >>= eEffect )
1173 nFound |= FoundFlags::Effect;
1174 continue;
1177 else if( !( nFound & FoundFlags::Bookmark ) && rProperty.Name == gaStrBookmark )
1179 if( rProperty.Value >>= aStrBookmark )
1181 nFound |= FoundFlags::Bookmark;
1182 continue;
1185 else if( !( nFound & FoundFlags::Speed ) && rProperty.Name == gaStrSpeed )
1187 if( rProperty.Value >>= eSpeed )
1189 nFound |= FoundFlags::Speed;
1190 continue;
1193 else if( !( nFound & FoundFlags::SoundUrl ) && rProperty.Name == gaStrSoundURL )
1195 if( rProperty.Value >>= aStrSoundURL )
1197 nFound |= FoundFlags::SoundUrl;
1198 continue;
1201 else if( !( nFound & FoundFlags::PlayFull ) && rProperty.Name == gaStrPlayFull )
1203 if( rProperty.Value >>= bPlayFull )
1205 nFound |= FoundFlags::PlayFull;
1206 continue;
1209 else if( !( nFound & FoundFlags::Verb ) && rProperty.Name == gaStrVerb )
1211 if( rProperty.Value >>= nVerb )
1213 nFound |= FoundFlags::Verb;
1214 continue;
1218 throw lang::IllegalArgumentException();
1221 bool bOk = false;
1224 if( !( nFound & FoundFlags::EventType ) )
1225 break;
1227 if( aStrEventType == gaStrPresentation )
1229 if( !( nFound & FoundFlags::ClickAction ) )
1230 break;
1232 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
1233 if( presentation::ClickAction_NONE == eClickAction && nullptr == pInfo )
1235 bOk = true;
1236 break;
1239 if( nullptr == pInfo )
1240 pInfo = mpShape->GetAnimationInfo( true );
1242 DBG_ASSERT( pInfo, "shape animation info could not be created!" );
1243 if( nullptr == pInfo )
1244 break;
1246 clearEventsInAnimationInfo( pInfo );
1247 pInfo->meClickAction = eClickAction;
1249 switch( eClickAction )
1251 case presentation::ClickAction_NONE:
1252 case presentation::ClickAction_PREVPAGE:
1253 case presentation::ClickAction_NEXTPAGE:
1254 case presentation::ClickAction_FIRSTPAGE:
1255 case presentation::ClickAction_LASTPAGE:
1256 case presentation::ClickAction_INVISIBLE:
1257 case presentation::ClickAction_STOPPRESENTATION:
1259 bOk = true;
1261 break;
1263 case presentation::ClickAction_PROGRAM:
1264 case presentation::ClickAction_BOOKMARK:
1265 case presentation::ClickAction_DOCUMENT:
1266 if( nFound & FoundFlags::Bookmark )
1268 if( eClickAction == presentation::ClickAction_BOOKMARK )
1270 aStrBookmark = getUiNameFromPageApiNameImpl( aStrBookmark );
1272 else if( eClickAction == presentation::ClickAction_DOCUMENT )
1274 sal_Int32 nPos = aStrBookmark.lastIndexOf( '#' );
1275 if( nPos >= 0 )
1277 OUString aURL( aStrBookmark.copy( 0, nPos+1 ) );
1278 aURL += getUiNameFromPageApiNameImpl( aStrBookmark.copy( nPos+1 ) );
1279 aStrBookmark = aURL;
1283 pInfo->SetBookmark( aStrBookmark );
1284 bOk = true;
1286 break;
1288 case presentation::ClickAction_MACRO:
1289 if( nFound & FoundFlags::Macro )
1291 pInfo->SetBookmark( aStrMacro );
1292 bOk = true;
1294 break;
1296 case presentation::ClickAction_VERB:
1297 if( nFound & FoundFlags::Verb )
1299 pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
1300 bOk = true;
1302 break;
1304 case presentation::ClickAction_VANISH:
1305 if( !( nFound & FoundFlags::Effect ) )
1306 break;
1308 pInfo->meSecondEffect = eEffect;
1309 pInfo->meSecondSpeed = nFound & FoundFlags::Speed ? eSpeed : presentation::AnimationSpeed_MEDIUM;
1311 bOk = true;
1313 [[fallthrough]];
1315 case presentation::ClickAction_SOUND:
1316 if( nFound & FoundFlags::SoundUrl )
1318 pInfo->SetBookmark( aStrSoundURL );
1319 if( eClickAction != presentation::ClickAction_SOUND )
1320 pInfo->mbSecondSoundOn = !aStrSoundURL.isEmpty();
1321 pInfo->mbSecondPlayFull = (nFound & FoundFlags::PlayFull) && bPlayFull;
1323 bOk = true;
1325 break;
1326 default:
1327 break;
1330 else
1332 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo( true );
1334 DBG_ASSERT( pInfo, "shape animation info could not be created!" );
1335 if( nullptr == pInfo )
1336 break;
1338 clearEventsInAnimationInfo( pInfo );
1339 pInfo->meClickAction = presentation::ClickAction_MACRO;
1341 if ( SfxApplication::IsXScriptURL( aStrMacro ) )
1343 pInfo->SetBookmark( aStrMacro );
1345 else
1347 sal_Int32 nIdx{ 0 };
1348 const OUString aLibName = aStrMacro.getToken(0, '.', nIdx);
1349 const OUString aModulName = aStrMacro.getToken(0, '.', nIdx);
1350 const OUString aMacroName = aStrMacro.getToken(0, '.', nIdx);
1352 OUStringBuffer sBuffer;
1353 sBuffer.append( aMacroName );
1354 sBuffer.append( '.' );
1355 sBuffer.append( aModulName );
1356 sBuffer.append( '.' );
1357 sBuffer.append( aLibName );
1358 sBuffer.append( '.' );
1360 if ( aStrLibrary == "StarOffice" )
1362 sBuffer.append( "BASIC" );
1364 else
1366 sBuffer.append( aStrLibrary );
1369 pInfo->SetBookmark( sBuffer.makeStringAndClear() );
1371 bOk = true;
1374 while(false);
1376 if( !bOk )
1377 throw lang::IllegalArgumentException();
1380 // XNameAccess
1381 uno::Any SAL_CALL SdUnoEventsAccess::getByName( const OUString& aName )
1383 if( mpShape == nullptr || aName != gaStrOnClick )
1384 throw container::NoSuchElementException();
1386 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
1388 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
1389 if( pInfo )
1390 eClickAction = pInfo->meClickAction;
1392 sal_Int32 nPropertyCount = 2;
1393 switch( eClickAction )
1395 case presentation::ClickAction_NONE:
1396 case presentation::ClickAction_PREVPAGE:
1397 case presentation::ClickAction_NEXTPAGE:
1398 case presentation::ClickAction_FIRSTPAGE:
1399 case presentation::ClickAction_LASTPAGE:
1400 case presentation::ClickAction_INVISIBLE:
1401 case presentation::ClickAction_STOPPRESENTATION:
1402 break;
1403 case presentation::ClickAction_PROGRAM:
1404 case presentation::ClickAction_VERB:
1405 case presentation::ClickAction_BOOKMARK:
1406 case presentation::ClickAction_DOCUMENT:
1407 case presentation::ClickAction_MACRO:
1408 if ( !SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
1409 nPropertyCount += 1;
1410 break;
1412 case presentation::ClickAction_SOUND:
1413 nPropertyCount += 2;
1414 break;
1416 case presentation::ClickAction_VANISH:
1417 nPropertyCount += 4;
1418 break;
1419 default:
1420 break;
1423 uno::Sequence< beans::PropertyValue > aProperties( nPropertyCount );
1424 beans::PropertyValue* pProperties = aProperties.getArray();
1426 uno::Any aAny;
1428 if( eClickAction == presentation::ClickAction_MACRO )
1430 if ( SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
1432 // Scripting Framework URL
1433 aAny <<= OUString(gaStrScript);
1434 pProperties->Name = gaStrEventType;
1435 pProperties->Handle = -1;
1436 pProperties->Value = aAny;
1437 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1438 pProperties++;
1440 aAny <<= pInfo->GetBookmark();
1441 pProperties->Name = gaStrScript;
1442 pProperties->Handle = -1;
1443 pProperties->Value = aAny;
1444 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1445 pProperties++;
1447 else
1449 // Old Basic macro URL
1450 aAny <<= OUString(gaStrStarBasic);
1451 pProperties->Name = gaStrEventType;
1452 pProperties->Handle = -1;
1453 pProperties->Value = aAny;
1454 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1455 pProperties++;
1457 OUString aMacro = pInfo->GetBookmark();
1459 // aMacro has got following format:
1460 // "Macroname.Modulname.Libname.Documentname" or
1461 // "Macroname.Modulname.Libname.Applicationname"
1462 sal_Int32 nIdx{ 0 };
1463 const OUString aMacroName = aMacro.getToken(0, '.', nIdx);
1464 const OUString aModulName = aMacro.getToken(0, '.', nIdx);
1465 const OUString aLibName = aMacro.getToken(0, '.', nIdx);
1467 OUString sBuffer = aLibName +
1468 "." +
1469 aModulName +
1470 "." +
1471 aMacroName;
1473 aAny <<= sBuffer;
1474 pProperties->Name = gaStrMacroName;
1475 pProperties->Handle = -1;
1476 pProperties->Value = aAny;
1477 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1478 pProperties++;
1480 aAny <<= OUString( "StarOffice" );
1481 pProperties->Name = gaStrLibrary;
1482 pProperties->Handle = -1;
1483 pProperties->Value = aAny;
1484 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1487 else
1489 aAny <<= OUString(gaStrPresentation);
1490 pProperties->Name = gaStrEventType;
1491 pProperties->Handle = -1;
1492 pProperties->Value = aAny;
1493 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1494 pProperties++;
1496 aAny <<= eClickAction;
1497 pProperties->Name = gaStrClickAction;
1498 pProperties->Handle = -1;
1499 pProperties->Value = aAny;
1500 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1501 pProperties++;
1503 switch( eClickAction )
1505 case presentation::ClickAction_NONE:
1506 case presentation::ClickAction_PREVPAGE:
1507 case presentation::ClickAction_NEXTPAGE:
1508 case presentation::ClickAction_FIRSTPAGE:
1509 case presentation::ClickAction_LASTPAGE:
1510 case presentation::ClickAction_INVISIBLE:
1511 case presentation::ClickAction_STOPPRESENTATION:
1512 break;
1513 case presentation::ClickAction_BOOKMARK:
1515 const OUString aStrBookmark( getPageApiNameFromUiName( pInfo->GetBookmark()) );
1516 pProperties->Name = gaStrBookmark;
1517 pProperties->Handle = -1;
1518 pProperties->Value <<= aStrBookmark;
1519 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1521 break;
1523 case presentation::ClickAction_DOCUMENT:
1524 case presentation::ClickAction_PROGRAM:
1526 OUString aString( pInfo->GetBookmark());
1527 sal_Int32 nPos = aString.lastIndexOf( '#' );
1528 if( nPos >= 0 )
1530 OUString aURL( aString.copy( 0, nPos+1 ) );
1531 aURL += getPageApiNameFromUiName( aString.copy( nPos+1 ) );
1532 aString = aURL;
1534 pProperties->Name = gaStrBookmark;
1535 pProperties->Handle = -1;
1536 pProperties->Value <<= aString;
1537 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1539 break;
1541 case presentation::ClickAction_VANISH:
1542 aAny <<= pInfo->meSecondEffect;
1543 pProperties->Name = gaStrEffect;
1544 pProperties->Handle = -1;
1545 pProperties->Value = aAny;
1546 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1547 pProperties++;
1549 aAny <<= pInfo->meSecondSpeed;
1550 pProperties->Name = gaStrSpeed;
1551 pProperties->Handle = -1;
1552 pProperties->Value = aAny;
1553 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1554 pProperties++;
1556 [[fallthrough]];
1558 case presentation::ClickAction_SOUND:
1559 if( eClickAction == presentation::ClickAction_SOUND || pInfo->mbSecondSoundOn )
1561 aAny <<= pInfo->GetBookmark();
1562 pProperties->Name = gaStrSoundURL;
1563 pProperties->Handle = -1;
1564 pProperties->Value = aAny;
1565 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1566 pProperties++;
1568 pProperties->Name = gaStrPlayFull;
1569 pProperties->Handle = -1;
1570 pProperties->Value <<= pInfo->mbSecondPlayFull;
1571 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1573 break;
1575 case presentation::ClickAction_VERB:
1576 aAny <<= static_cast<sal_Int32>(pInfo->mnVerb);
1577 pProperties->Name = gaStrVerb;
1578 pProperties->Handle = -1;
1579 pProperties->Value = aAny;
1580 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1581 break;
1582 default:
1583 break;
1587 aAny <<= aProperties;
1588 return aAny;
1591 uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getElementNames( )
1593 return { gaStrOnClick };
1596 sal_Bool SAL_CALL SdUnoEventsAccess::hasByName( const OUString& aName )
1598 return aName == gaStrOnClick;
1601 // XElementAccess
1602 uno::Type SAL_CALL SdUnoEventsAccess::getElementType( )
1604 return cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get();
1607 sal_Bool SAL_CALL SdUnoEventsAccess::hasElements( )
1609 return true;
1612 // XServiceInfo
1613 OUString SAL_CALL SdUnoEventsAccess::getImplementationName( )
1615 return "SdUnoEventsAccess";
1618 sal_Bool SAL_CALL SdUnoEventsAccess::supportsService( const OUString& ServiceName )
1620 return cppu::supportsService(this, ServiceName);
1623 uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getSupportedServiceNames( )
1625 return { gaStrServiceName };
1628 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */