bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / unoidl / unoobj.cxx
blob4ee7abb1e7499957e74621ffcbb467d2544dbd84
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/text/XText.hpp>
29 #include <com/sun/star/beans/PropertyState.hpp>
30 #include <com/sun/star/beans/PropertyValues.hpp>
31 #include <rtl/ustrbuf.hxx>
32 #include <svl/itemprop.hxx>
33 #include <svl/style.hxx>
34 #include <svx/svdpool.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/app.hxx>
37 #include <svtools/unoimap.hxx>
38 #include <svtools/unoevent.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/event.hxx>
41 #include <sfx2/sfxsids.hrc>
42 #include <comphelper/extract.hxx>
43 #include <cppuhelper/implbase.hxx>
44 #include <cppuhelper/supportsservice.hxx>
45 #include <svx/unoprov.hxx>
46 #include <svx/unoshape.hxx>
47 #include <svx/svditer.hxx>
48 #include <svx/svdotext.hxx>
49 #include <svx/unoapi.hxx>
50 #include <svx/svdopath.hxx>
51 #include <svx/svdoole2.hxx>
52 #include <svx/svdograf.hxx>
53 #include <filter/msfilter/msdffimp.hxx>
54 #include <svl/instrm.hxx>
55 #include <editeng/outlobj.hxx>
56 #include <CustomAnimationPreset.hxx>
57 #include <Outliner.hxx>
58 #include <comphelper/serviceinfohelper.hxx>
59 #include <svx/svdogrp.hxx>
60 #include <o3tl/typed_flags_set.hxx>
61 #include <vcl/svapp.hxx>
62 #include <tools/debug.hxx>
64 #include <anminfo.hxx>
65 #include "unoobj.hxx"
66 #include <unoprnms.hxx>
67 #include <unomodel.hxx>
68 #include <drawdoc.hxx>
69 #include <sdmod.hxx>
70 #include <sdpage.hxx>
71 #include <ViewShell.hxx>
72 #include <unokywds.hxx>
73 #include <unopage.hxx>
74 #include <DrawDocShell.hxx>
75 #include <glob.hxx>
76 #include "unolayer.hxx"
77 #include <imapinfo.hxx>
78 #include <EffectMigration.hxx>
80 using namespace ::sd;
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::presentation;
83 using namespace ::com::sun::star::animations;
85 using ::com::sun::star::uno::makeAny;
86 using ::com::sun::star::uno::Any;
87 using ::com::sun::star::drawing::XShape;
89 #define WID_EFFECT 1
90 #define WID_SPEED 2
91 #define WID_TEXTEFFECT 3
92 #define WID_BOOKMARK 4
93 #define WID_CLICKACTION 5
94 #define WID_PLAYFULL 6
95 #define WID_SOUNDFILE 7
96 #define WID_SOUNDON 8
97 #define WID_BLUESCREEN 9
98 #define WID_VERB 10
99 #define WID_DIMCOLOR 11
100 #define WID_DIMHIDE 12
101 #define WID_DIMPREV 13
102 #define WID_PRESORDER 14
103 #define WID_STYLE 15
104 #define WID_ANIMPATH 16
105 #define WID_IMAGEMAP 17
106 #define WID_ISANIMATION 18
107 #define WID_THAT_NEED_ANIMINFO 19
109 #define WID_ISEMPTYPRESOBJ 20
110 #define WID_ISPRESOBJ 21
111 #define WID_MASTERDEPEND 22
113 #define WID_NAVORDER 23
114 #define WID_PLACEHOLDERTEXT 24
115 #define WID_LEGACYFRAGMENT 25
117 #define IMPRESS_MAP_ENTRIES \
118 { OUString(UNO_NAME_OBJ_LEGACYFRAGMENT),WID_LEGACYFRAGMENT, cppu::UnoType<drawing::XShape>::get(), 0, 0},\
119 { OUString(UNO_NAME_OBJ_ANIMATIONPATH), WID_ANIMPATH, cppu::UnoType<drawing::XShape>::get(), 0, 0},\
120 { OUString(UNO_NAME_OBJ_BOOKMARK), WID_BOOKMARK, cppu::UnoType<OUString>::get(), 0, 0},\
121 { OUString(UNO_NAME_OBJ_DIMCOLOR), WID_DIMCOLOR, cppu::UnoType<sal_Int32>::get(), 0, 0},\
122 { OUString(UNO_NAME_OBJ_DIMHIDE), WID_DIMHIDE, cppu::UnoType<bool>::get(), 0, 0},\
123 { OUString(UNO_NAME_OBJ_DIMPREV), WID_DIMPREV, cppu::UnoType<bool>::get(), 0, 0},\
124 { OUString(UNO_NAME_OBJ_EFFECT), WID_EFFECT, cppu::UnoType<presentation::AnimationEffect>::get(), 0, 0},\
125 { OUString(UNO_NAME_OBJ_ISEMPTYPRESOBJ),WID_ISEMPTYPRESOBJ, cppu::UnoType<bool>::get(), 0, 0},\
126 { OUString(UNO_NAME_OBJ_ISPRESOBJ), WID_ISPRESOBJ, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY, 0},\
127 { OUString(UNO_NAME_OBJ_MASTERDEPENDENT),WID_MASTERDEPEND, cppu::UnoType<bool>::get(), 0, 0},\
128 { OUString(UNO_NAME_OBJ_CLICKACTION), WID_CLICKACTION, cppu::UnoType<presentation::ClickAction>::get(), 0, 0},\
129 { OUString(UNO_NAME_OBJ_PLAYFULL), WID_PLAYFULL, cppu::UnoType<bool>::get(), 0, 0},\
130 { OUString(UNO_NAME_OBJ_PRESORDER), WID_PRESORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
131 { OUString(UNO_NAME_OBJ_STYLE), WID_STYLE, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},\
132 { OUString(UNO_NAME_OBJ_SOUNDFILE), WID_SOUNDFILE, cppu::UnoType<OUString>::get(), 0, 0},\
133 { OUString(UNO_NAME_OBJ_SOUNDON), WID_SOUNDON, cppu::UnoType<bool>::get(), 0, 0},\
134 { OUString(UNO_NAME_OBJ_SPEED), WID_SPEED, cppu::UnoType<presentation::AnimationSpeed>::get(), 0, 0},\
135 { OUString(UNO_NAME_OBJ_TEXTEFFECT), WID_TEXTEFFECT, cppu::UnoType<presentation::AnimationEffect>::get(), 0, 0},\
136 { OUString(UNO_NAME_OBJ_BLUESCREEN), WID_BLUESCREEN, cppu::UnoType<sal_Int32>::get(), 0, 0},\
137 { OUString(UNO_NAME_OBJ_VERB), WID_VERB, cppu::UnoType<sal_Int32>::get(), 0, 0},\
138 { OUString("IsAnimation"), WID_ISANIMATION, cppu::UnoType<bool>::get(), 0, 0},\
139 { OUString("NavigationOrder"), WID_NAVORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
140 { OUString("PlaceholderText"), WID_PLACEHOLDERTEXT, cppu::UnoType<OUString>::get(), 0, 0},\
141 { OUString(), 0, css::uno::Type(), 0, 0 }
143 static const SfxItemPropertyMapEntry* lcl_GetImpress_SdXShapePropertyGraphicMap_Impl()
146 static const SfxItemPropertyMapEntry aImpress_SdXShapePropertyGraphicMap_Impl[] =
148 { OUString("ImageMap"), WID_IMAGEMAP, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
149 IMPRESS_MAP_ENTRIES
151 return aImpress_SdXShapePropertyGraphicMap_Impl;
154 static const SfxItemPropertyMapEntry* lcl_GetImpress_SdXShapePropertySimpleMap_Impl()
157 static const SfxItemPropertyMapEntry aImpress_SdXShapePropertySimpleMap_Impl[] =
159 IMPRESS_MAP_ENTRIES
161 return aImpress_SdXShapePropertySimpleMap_Impl;
164 #define DRAW_MAP_ENTRIES\
165 { OUString(UNO_NAME_OBJ_BOOKMARK), WID_BOOKMARK, cppu::UnoType<OUString>::get(), 0, 0},\
166 { OUString(UNO_NAME_OBJ_CLICKACTION), WID_CLICKACTION, cppu::UnoType<presentation::ClickAction>::get(),0, 0},\
167 { OUString(UNO_NAME_OBJ_STYLE), WID_STYLE, cppu::UnoType<style::XStyle>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},\
168 { OUString("NavigationOrder"), WID_NAVORDER, cppu::UnoType<sal_Int32>::get(), 0, 0},\
169 { OUString(), 0, css::uno::Type(), 0, 0 }
171 static const SfxItemPropertyMapEntry* lcl_GetDraw_SdXShapePropertySimpleMap_Impl()
173 static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyMap_Impl[] =
175 DRAW_MAP_ENTRIES
177 return aDraw_SdXShapePropertyMap_Impl;
179 static const SfxItemPropertyMapEntry* lcl_GetDraw_SdXShapePropertyGraphicMap_Impl()
181 static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyGraphicMap_Impl[] =
183 { OUString("ImageMap"), WID_IMAGEMAP, cppu::UnoType<container::XIndexContainer>::get(), 0, 0 },
184 DRAW_MAP_ENTRIES
186 return aDraw_SdXShapePropertyGraphicMap_Impl;
188 static const SfxItemPropertyMapEntry* lcl_ImplGetShapePropertyMap( bool bImpress, bool bGraphicObj )
190 const SfxItemPropertyMapEntry* pRet = nullptr;
191 if( bImpress )
193 if( bGraphicObj )
194 pRet = lcl_GetImpress_SdXShapePropertyGraphicMap_Impl();
195 else
196 pRet = lcl_GetImpress_SdXShapePropertySimpleMap_Impl();
198 else
200 if( bGraphicObj )
201 pRet = lcl_GetDraw_SdXShapePropertyGraphicMap_Impl();
202 else
203 pRet = lcl_GetDraw_SdXShapePropertySimpleMap_Impl();
205 return pRet;
208 static const SvxItemPropertySet* lcl_ImplGetShapePropertySet( bool bImpress, bool bGraphicObj )
210 const SvxItemPropertySet* pRet = nullptr;
211 if( bImpress )
213 if( bGraphicObj )
215 static SvxItemPropertySet aImpress_SdXShapePropertyGraphicSet_Impl( lcl_GetImpress_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
216 pRet = &aImpress_SdXShapePropertyGraphicSet_Impl;
218 else
220 static SvxItemPropertySet aImpress_SdXShapePropertySet_Impl(lcl_GetImpress_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
221 pRet = &aImpress_SdXShapePropertySet_Impl;
224 else
226 if( bGraphicObj )
228 static SvxItemPropertySet aDraw_SdXShapePropertyGraphicSet_Impl(lcl_GetDraw_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
229 pRet = &aDraw_SdXShapePropertyGraphicSet_Impl;
231 else
233 static SvxItemPropertySet aDraw_SdXShapePropertySet_Impl( lcl_GetDraw_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
234 pRet = &aDraw_SdXShapePropertySet_Impl;
237 return pRet;
239 static const SfxItemPropertyMapEntry* lcl_GetEmpty_SdXShapePropertyMap_Impl()
241 static const SfxItemPropertyMapEntry aEmpty_SdXShapePropertyMap_Impl[] =
243 { OUString(), 0, css::uno::Type(), 0, 0 }
245 return aEmpty_SdXShapePropertyMap_Impl;
248 static const SvxItemPropertySet* lcl_GetEmpty_SdXShapePropertySet_Impl()
250 static SvxItemPropertySet aEmptyPropSet( lcl_GetEmpty_SdXShapePropertyMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool() );
251 return &aEmptyPropSet;
253 const SvEventDescription* ImplGetSupportedMacroItems()
255 static const SvEventDescription aMacroDescriptionsImpl[] =
257 { SvMacroItemId::OnMouseOver, "OnMouseOver" },
258 { SvMacroItemId::OnMouseOut, "OnMouseOut" },
259 { SvMacroItemId::NONE, nullptr }
262 return aMacroDescriptionsImpl;
265 SdXShape::SdXShape(SvxShape* pShape, SdXImpressDocument* pModel)
266 : mpShape( pShape ),
267 mpPropSet( pModel?
268 lcl_ImplGetShapePropertySet(pModel->IsImpressDocument(), pShape->getShapeKind() == OBJ_GRAF )
269 : lcl_GetEmpty_SdXShapePropertySet_Impl() ),
270 mpMap( pModel?
271 lcl_ImplGetShapePropertyMap(pModel->IsImpressDocument(), pShape->getShapeKind() == OBJ_GRAF )
272 : lcl_GetEmpty_SdXShapePropertyMap_Impl() ),
273 mpModel(pModel)
276 pShape->setMaster( this );
279 SdXShape::~SdXShape() throw()
283 void SdXShape::dispose()
285 mpShape->setMaster( nullptr );
286 delete this;
289 uno::Any SAL_CALL SdXShape::queryInterface( const uno::Type & rType )
291 return mpShape->queryInterface( rType );
294 void SAL_CALL SdXShape::acquire() throw()
296 mpShape->acquire();
299 void SAL_CALL SdXShape::release() throw()
301 mpShape->release();
304 bool SdXShape::queryAggregation( const css::uno::Type & rType, css::uno::Any& aAny )
306 if( mpModel && mpModel ->IsImpressDocument() )
308 if( rType == cppu::UnoType<document::XEventsSupplier>::get())
310 aAny <<= uno::Reference< document::XEventsSupplier >(this);
311 return true;
315 return false;
318 uno::Sequence< uno::Type > SAL_CALL SdXShape::getTypes()
320 if( mpModel && !mpModel->IsImpressDocument() )
322 return mpShape->_getTypes();
324 else
326 sal_uInt32 nObjId = mpShape->getShapeKind();
327 uno::Sequence< uno::Type > aTypes;
328 SdTypesCache& gImplTypesCache = SD_MOD()->gImplTypesCache;
329 SdTypesCache::iterator aIter( gImplTypesCache.find( nObjId ) );
330 if( aIter == gImplTypesCache.end() )
332 aTypes = mpShape->_getTypes();
333 sal_uInt32 nCount = aTypes.getLength();
334 aTypes.realloc( nCount+1 );
335 aTypes[nCount] = cppu::UnoType<lang::XTypeProvider>::get();
337 gImplTypesCache.insert(std::make_pair(nObjId, aTypes));
339 else
341 // use the already computed implementation id
342 aTypes = (*aIter).second;
344 return aTypes;
348 // XPropertyState
349 beans::PropertyState SAL_CALL SdXShape::getPropertyState( const OUString& PropertyName )
351 SolarMutexGuard aGuard;
353 if( mpPropSet->getPropertyMapEntry(PropertyName) )
355 return beans::PropertyState_DIRECT_VALUE;
357 else
359 SdrObject* pObj = mpShape->GetSdrObject();
360 if( pObj == nullptr || ( pObj->getSdrPageFromSdrObject()->IsMasterPage() && pObj->IsEmptyPresObj() ) )
361 return beans::PropertyState_DEFAULT_VALUE;
363 return mpShape->_getPropertyState( PropertyName );
367 void SAL_CALL SdXShape::setPropertyToDefault( const OUString& PropertyName )
369 SolarMutexGuard aGuard;
371 if( mpPropSet->getPropertyMapEntry(PropertyName) )
373 return;
375 else
377 mpShape->_setPropertyToDefault(PropertyName);
381 uno::Any SAL_CALL SdXShape::getPropertyDefault( const OUString& aPropertyName )
383 SolarMutexGuard aGuard;
385 if( mpPropSet->getPropertyMapEntry(aPropertyName) )
387 return getPropertyValue( aPropertyName );
389 else
391 uno::Any aRet( mpShape->_getPropertyDefault(aPropertyName) );
392 return aRet;
396 //XPropertySet
397 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL SdXShape::getPropertySetInfo()
399 SfxItemPropertyMapEntry const * nObjId = mpShape->getPropertyMapEntries();
400 css::uno::Reference<css::beans::XPropertySetInfo> pInfo;
402 SdExtPropertySetInfoCache& rCache = (mpModel && mpModel->IsImpressDocument()) ?
403 SD_MOD()->gImplImpressPropertySetInfoCache : SD_MOD()->gImplDrawPropertySetInfoCache;
405 SdExtPropertySetInfoCache::iterator aIter( rCache.find( nObjId ) );
406 if( aIter == rCache.end() )
408 uno::Reference< beans::XPropertySetInfo > xInfo( mpShape->_getPropertySetInfo() );
409 pInfo = new SfxExtItemPropertySetInfo( mpMap, xInfo->getProperties() );
411 rCache.insert(std::make_pair(nObjId, pInfo));
413 else
415 // use the already computed implementation id
416 pInfo = (*aIter).second;
419 return pInfo;
422 void SAL_CALL SdXShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue )
424 SolarMutexGuard aGuard;
426 const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);
428 if( pEntry )
430 SdrObject* pObj = mpShape->GetSdrObject();
431 if( pObj )
433 SdAnimationInfo* pInfo = GetAnimationInfo(pEntry->nWID <= WID_THAT_NEED_ANIMINFO);
435 switch(pEntry->nWID)
437 case WID_NAVORDER:
439 sal_Int32 nNavOrder = 0;
440 if(!(aValue >>= nNavOrder))
441 throw lang::IllegalArgumentException();
443 SdrObjList* pObjList = pObj->getParentSdrObjListFromSdrObject();
444 if( pObjList )
445 pObjList->SetObjectNavigationPosition( *pObj, (nNavOrder < 0) ? SAL_MAX_UINT32 : static_cast< sal_uInt32 >( nNavOrder ) );
446 break;
449 case WID_EFFECT:
451 AnimationEffect eEffect;
452 if(!(aValue >>= eEffect))
453 throw lang::IllegalArgumentException();
455 EffectMigration::SetAnimationEffect( mpShape, eEffect );
456 break;
458 case WID_TEXTEFFECT:
460 AnimationEffect eEffect;
461 if(!(aValue >>= eEffect))
462 throw lang::IllegalArgumentException();
464 EffectMigration::SetTextAnimationEffect( mpShape, eEffect );
465 break;
467 case WID_SPEED:
469 AnimationSpeed eSpeed;
470 if(!(aValue>>=eSpeed))
471 throw lang::IllegalArgumentException();
473 EffectMigration::SetAnimationSpeed( mpShape, eSpeed );
474 break;
476 case WID_ISANIMATION:
478 bool bIsAnimation(false);
480 if(!(aValue >>= bIsAnimation))
482 throw lang::IllegalArgumentException();
485 if(bIsAnimation)
487 SdrObjGroup* pGroup = dynamic_cast< SdrObjGroup* >(pObj);
488 SdPage* pPage = pGroup ? dynamic_cast< SdPage* >(pGroup->getSdrPageFromSdrObject()) : nullptr;
490 if (pPage)
492 // #i42894# Animated Group object, migrate that effect
493 EffectMigration::CreateAnimatedGroup(*pGroup, *pPage);
495 // #i42894# unfortunately when doing this all group members have to
496 // be moved to the page as direct members, else the currently
497 // available forms of animation do not work. If it succeeds,
498 // the group is empty and can be removed and deleted
499 if(!pGroup->GetSubList()->GetObjCount())
501 pPage->NbcRemoveObject(pGroup->GetOrdNum());
503 // always use SdrObject::Free(...) for SdrObjects (!)
504 SdrObject* pTemp(pGroup);
505 SdrObject::Free(pTemp);
509 //pInfo->mbIsMovie = bIsAnimation;
510 break;
512 case WID_BOOKMARK:
514 OUString aString;
515 if(!(aValue >>= aString))
516 throw lang::IllegalArgumentException();
518 pInfo->SetBookmark( SdDrawPage::getUiNameFromPageApiName( aString ) );
519 break;
521 case WID_CLICKACTION:
522 ::cppu::any2enum< presentation::ClickAction >( pInfo->meClickAction, aValue);
523 break;
525 // TODO: WID_PLAYFULL:
526 case WID_SOUNDFILE:
528 OUString aString;
529 if(!(aValue >>= aString))
530 throw lang::IllegalArgumentException();
531 pInfo->maSoundFile = aString;
532 EffectMigration::UpdateSoundEffect( mpShape, pInfo );
533 break;
536 case WID_SOUNDON:
538 if( !(aValue >>= pInfo->mbSoundOn) )
539 throw lang::IllegalArgumentException();
540 EffectMigration::UpdateSoundEffect( mpShape, pInfo );
541 break;
543 case WID_VERB:
545 sal_Int32 nVerb = 0;
546 if(!(aValue >>= nVerb))
547 throw lang::IllegalArgumentException();
549 pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
550 break;
552 case WID_DIMCOLOR:
554 sal_Int32 nColor = 0;
556 if( !(aValue >>= nColor) )
557 throw lang::IllegalArgumentException();
559 EffectMigration::SetDimColor( mpShape, nColor );
560 break;
562 case WID_DIMHIDE:
564 bool bDimHide = false;
565 if( !(aValue >>= bDimHide) )
566 throw lang::IllegalArgumentException();
568 EffectMigration::SetDimHide( mpShape, bDimHide );
569 break;
571 case WID_DIMPREV:
573 bool bDimPrevious = false;
574 if( !(aValue >>= bDimPrevious) )
575 throw lang::IllegalArgumentException();
577 EffectMigration::SetDimPrevious( mpShape, bDimPrevious );
578 break;
580 case WID_PRESORDER:
582 sal_Int32 nNewPos = 0;
583 if( !(aValue >>= nNewPos) )
584 throw lang::IllegalArgumentException();
586 EffectMigration::SetPresentationOrder( mpShape, nNewPos );
587 break;
589 case WID_STYLE:
590 SetStyleSheet( aValue );
591 break;
592 case WID_ISEMPTYPRESOBJ:
593 SetEmptyPresObj( ::cppu::any2bool(aValue) );
594 break;
595 case WID_MASTERDEPEND:
596 SetMasterDepend( ::cppu::any2bool(aValue) );
597 break;
599 case WID_LEGACYFRAGMENT:
601 uno::Reference< io::XInputStream > xInputStream;
602 aValue >>= xInputStream;
603 if( xInputStream.is() )
605 SvInputStream aStream( xInputStream );
606 SdrObject* pObject = mpShape->GetSdrObject();
607 SvxMSDffManager::ReadObjText( aStream, pObject );
610 break;
612 case WID_ANIMPATH:
614 uno::Reference< drawing::XShape > xShape( aValue, uno::UNO_QUERY );
615 SdrPathObj* pObj2 = xShape.is() ? dynamic_cast< SdrPathObj* >( GetSdrObjectFromXShape( xShape ) ) : nullptr;
617 if( pObj2 == nullptr )
618 throw lang::IllegalArgumentException();
620 EffectMigration::SetAnimationPath( mpShape, pObj2 );
621 break;
623 case WID_IMAGEMAP:
625 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
626 if( pDoc )
628 ImageMap aImageMap;
629 uno::Reference< uno::XInterface > xImageMap;
630 aValue >>= xImageMap;
632 if( !xImageMap.is() || !SvUnoImageMap_fillImageMap( xImageMap, aImageMap ) )
633 throw lang::IllegalArgumentException();
635 SdIMapInfo* pIMapInfo = SdDrawDocument::GetIMapInfo(pObj);
636 if( pIMapInfo )
638 // replace existing image map
639 pIMapInfo->SetImageMap( aImageMap );
641 else
643 // insert new user data with image map
644 pObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SdIMapInfo(aImageMap) ));
648 break;
652 else
654 mpShape->_setPropertyValue(aPropertyName, aValue);
657 if( mpModel )
658 mpModel->SetModified();
661 css::uno::Any SAL_CALL SdXShape::getPropertyValue( const OUString& PropertyName )
663 SolarMutexGuard aGuard;
665 uno::Any aRet;
667 const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);
669 if( pEntry && mpShape->GetSdrObject() )
671 SdAnimationInfo* pInfo = GetAnimationInfo();
673 switch(pEntry->nWID)
675 case WID_NAVORDER:
677 const sal_uInt32 nNavOrder = mpShape->GetSdrObject()->GetNavigationPosition();
678 aRet <<= nNavOrder == SAL_MAX_UINT32 ? static_cast<sal_Int32>(-1) : static_cast< sal_Int32 >(nNavOrder);
680 break;
681 case WID_EFFECT:
682 aRet <<= EffectMigration::GetAnimationEffect( mpShape );
683 break;
684 case WID_TEXTEFFECT:
685 aRet <<= EffectMigration::GetTextAnimationEffect( mpShape );
686 break;
687 case WID_ISPRESOBJ:
688 aRet <<= IsPresObj();
689 break;
690 case WID_ISEMPTYPRESOBJ:
691 aRet <<= IsEmptyPresObj();
692 break;
693 case WID_MASTERDEPEND:
694 aRet <<= IsMasterDepend();
695 break;
696 case WID_SPEED:
697 aRet <<= EffectMigration::GetAnimationSpeed( mpShape );
698 break;
699 case WID_ISANIMATION:
700 aRet <<= (pInfo && pInfo->mbIsMovie);
701 break;
702 case WID_PLACEHOLDERTEXT:
703 aRet <<= GetPlaceholderText();
704 break;
705 case WID_BOOKMARK:
707 OUString aString;
708 SdDrawDocument* pDoc = mpModel ? mpModel->GetDoc() : nullptr;
709 if (pInfo && pDoc)
711 // is the bookmark a page?
712 bool bIsMasterPage;
713 if(pDoc->GetPageByName( pInfo->GetBookmark(), bIsMasterPage ) != SDRPAGE_NOTFOUND)
715 aString = SdDrawPage::getPageApiNameFromUiName( pInfo->GetBookmark() );
717 else
719 aString = pInfo->GetBookmark() ;
720 sal_Int32 nPos = aString.lastIndexOf( '#' );
721 if( nPos >= 0 )
723 OUString aURL( aString.copy( 0, nPos+1 ) );
724 OUString aName( aString.copy( nPos+1 ) );
725 if(pDoc->GetPageByName( aName, bIsMasterPage ) != SDRPAGE_NOTFOUND)
727 aURL += SdDrawPage::getPageApiNameFromUiName( aName );
728 aString = aURL;
734 aRet <<= aString;
735 break;
737 case WID_CLICKACTION:
738 aRet <<= ( pInfo?pInfo->meClickAction:presentation::ClickAction_NONE );
739 break;
740 case WID_PLAYFULL:
741 aRet <<= ( pInfo && pInfo->mbPlayFull );
742 break;
743 case WID_SOUNDFILE:
744 aRet <<= EffectMigration::GetSoundFile( mpShape );
745 break;
746 case WID_SOUNDON:
747 aRet <<= EffectMigration::GetSoundOn( mpShape );
748 break;
749 case WID_BLUESCREEN:
750 aRet <<= pInfo ? pInfo->maBlueScreen : Color(0x00ffffff);
751 break;
752 case WID_VERB:
753 aRet <<= static_cast<sal_Int32>( pInfo?pInfo->mnVerb:0 );
754 break;
755 case WID_DIMCOLOR:
756 aRet <<= EffectMigration::GetDimColor( mpShape );
757 break;
758 case WID_DIMHIDE:
759 aRet <<= EffectMigration::GetDimHide( mpShape );
760 break;
761 case WID_DIMPREV:
762 aRet <<= EffectMigration::GetDimPrevious( mpShape );
763 break;
764 case WID_PRESORDER:
765 aRet <<= EffectMigration::GetPresentationOrder( mpShape );
766 break;
767 case WID_STYLE:
768 aRet = GetStyleSheet();
769 break;
770 case WID_IMAGEMAP:
772 uno::Reference< uno::XInterface > xImageMap;
774 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
775 if( pDoc )
778 SdIMapInfo* pIMapInfo = SdDrawDocument::GetIMapInfo(mpShape->GetSdrObject());
779 if( pIMapInfo )
781 const ImageMap& rIMap = pIMapInfo->GetImageMap();
782 xImageMap = SvUnoImageMap_createInstance( rIMap, ImplGetSupportedMacroItems() );
784 else
786 xImageMap = SvUnoImageMap_createInstance();
790 aRet <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
791 break;
795 else
797 aRet = mpShape->_getPropertyValue(PropertyName);
800 return aRet;
803 /** */
804 SdAnimationInfo* SdXShape::GetAnimationInfo( bool bCreate ) const
806 SdAnimationInfo* pInfo = nullptr;
808 SdrObject* pObj = mpShape->GetSdrObject();
809 if(pObj)
810 pInfo = SdDrawDocument::GetShapeUserData(*pObj, bCreate);
812 return pInfo;
815 uno::Sequence< OUString > SAL_CALL SdXShape::getSupportedServiceNames()
817 uno::Sequence< OUString > aSeq( mpShape->_getSupportedServiceNames() );
819 comphelper::ServiceInfoHelper::addToSequence( aSeq, {"com.sun.star.presentation.Shape",
820 "com.sun.star.document.LinkTarget"} );
822 SdrObject* pObj = mpShape->GetSdrObject();
823 if(pObj && pObj->GetObjInventor() == SdrInventor::Default )
825 sal_uInt32 nInventor = pObj->GetObjIdentifier();
826 switch( nInventor )
828 case OBJ_TITLETEXT:
829 comphelper::ServiceInfoHelper::addToSequence( aSeq, {"com.sun.star.presentation.TitleTextShape"} );
830 break;
831 case OBJ_OUTLINETEXT:
832 comphelper::ServiceInfoHelper::addToSequence( aSeq, {"com.sun.star.presentation.OutlinerShape"} );
833 break;
836 return aSeq;
839 /** checks if this is a presentation object
841 bool SdXShape::IsPresObj() const
843 SdrObject* pObj = mpShape->GetSdrObject();
844 if(pObj)
846 SdPage* pPage = dynamic_cast<SdPage* >(pObj->getSdrPageFromSdrObject());
847 if(pPage)
848 return pPage->GetPresObjKind(pObj) != PRESOBJ_NONE;
850 return false;
853 /** checks if this presentation object is empty
855 bool SdXShape::IsEmptyPresObj() const
857 SdrObject* pObj = mpShape->GetSdrObject();
858 if( (pObj != nullptr) && pObj->IsEmptyPresObj() )
860 // check if the object is in edit, than its temporarily not empty
861 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
862 if( pTextObj == nullptr )
863 return true;
865 const std::unique_ptr<OutlinerParaObject> pParaObj(pTextObj->GetEditOutlinerParaObject());
866 return !pParaObj;
869 return false;
872 OUString SdXShape::GetPlaceholderText() const
874 // only possible if this actually *is* a presentation object
875 if( !IsPresObj() )
876 return OUString();
878 SdrObject* pObj = mpShape->GetSdrObject();
879 if( pObj == nullptr )
880 return OUString();
882 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
883 DBG_ASSERT( pPage, "no page?" );
884 if( pPage == nullptr )
885 return OUString();
887 return pPage->GetPresObjText( pPage->GetPresObjKind(pObj) );
890 /** sets/reset the empty status of a presentation object
892 void SdXShape::SetEmptyPresObj(bool bEmpty)
894 // only possible if this actually *is* a presentation object
895 if( !IsPresObj() )
896 return;
898 SdrObject* pObj = mpShape->GetSdrObject();
899 if( pObj == nullptr )
900 return;
902 if( pObj->IsEmptyPresObj() == bEmpty )
903 return;
905 if(!bEmpty)
907 OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
908 const bool bVertical = pOutlinerParaObject && pOutlinerParaObject->IsVertical();
910 // really delete SdrOutlinerObj at pObj
911 pObj->NbcSetOutlinerParaObject(nullptr);
912 if( bVertical && dynamic_cast<SdrTextObj*>( pObj ) )
913 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );
915 SdrGrafObj* pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj );
916 if( pGraphicObj )
918 Graphic aEmpty;
919 pGraphicObj->SetGraphic(aEmpty);
921 else
923 SdrOle2Obj* pOleObj = dynamic_cast< SdrOle2Obj* >( pObj );
924 if( pOleObj )
926 pOleObj->ClearGraphic();
930 else
932 // now set an empty OutlinerParaObject at pObj without
933 // any content but with the style of the old OutlinerParaObjects
934 // first paragraph
937 SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
938 DBG_ASSERT( pDoc, "no document?" );
939 if( pDoc == nullptr)
940 break;
942 SdOutliner* pOutliner = pDoc->GetInternalOutliner();
943 DBG_ASSERT( pOutliner, "no outliner?" );
944 if( pOutliner == nullptr )
945 break;
947 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
948 DBG_ASSERT( pPage, "no page?" );
949 if( pPage == nullptr )
950 break;
952 OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
953 pOutliner->SetText( *pOutlinerParaObject );
954 const bool bVertical = pOutliner->IsVertical();
956 pOutliner->Clear();
957 pOutliner->SetVertical( bVertical );
958 pOutliner->SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(pDoc->GetStyleSheetPool()) );
959 pOutliner->SetStyleSheet( 0, pPage->GetTextStyleSheetForObject( pObj ) );
960 pOutliner->Insert( pPage->GetPresObjText( pPage->GetPresObjKind(pObj) ) );
961 pObj->SetOutlinerParaObject( pOutliner->CreateParaObject() );
962 pOutliner->Clear();
964 while(false);
967 pObj->SetEmptyPresObj(bEmpty);
970 bool SdXShape::IsMasterDepend() const throw()
972 SdrObject* pObj = mpShape->GetSdrObject();
973 return pObj && pObj->GetUserCall() != nullptr;
976 void SdXShape::SetMasterDepend( bool bDepend ) throw()
978 if( IsMasterDepend() == bDepend )
979 return;
981 SdrObject* pObj = mpShape->GetSdrObject();
982 if( pObj )
984 if( bDepend )
986 SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
987 pObj->SetUserCall( pPage );
989 else
991 pObj->SetUserCall( nullptr );
996 void SdXShape::SetStyleSheet( const uno::Any& rAny )
998 SdrObject* pObj = mpShape->GetSdrObject();
999 if( pObj == nullptr )
1000 throw beans::UnknownPropertyException();
1002 uno::Reference< style::XStyle > xStyle( rAny, uno::UNO_QUERY );
1003 SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle );
1005 const SfxStyleSheet* pOldStyleSheet = pObj->GetStyleSheet();
1006 if( pOldStyleSheet == pStyleSheet )
1007 return;
1009 if( pStyleSheet == nullptr || (pStyleSheet->GetFamily() != SfxStyleFamily::Para && pStyleSheet->GetFamily() != SfxStyleFamily::Page) )
1010 throw lang::IllegalArgumentException();
1012 pObj->SetStyleSheet( pStyleSheet, false );
1014 SdDrawDocument* pDoc = mpModel? mpModel->GetDoc() : nullptr;
1015 if( pDoc )
1017 ::sd::DrawDocShell* pDocSh = pDoc->GetDocSh();
1018 ::sd::ViewShell* pViewSh = pDocSh ? pDocSh->GetViewShell() : nullptr;
1020 if( pViewSh )
1021 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2 );
1025 uno::Any SdXShape::GetStyleSheet() const
1027 SdrObject* pObj = mpShape->GetSdrObject();
1028 if( pObj == nullptr )
1029 throw beans::UnknownPropertyException();
1031 SfxStyleSheet* pStyleSheet = pObj->GetStyleSheet();
1032 // it is possible for shapes inside a draw to have a presentation style
1033 // but we don't want this for the api
1034 if( (pStyleSheet == nullptr) || ((pStyleSheet->GetFamily() != SfxStyleFamily::Para) && !mpModel->IsImpressDocument()) )
1035 return Any();
1037 return Any( uno::Reference< style::XStyle >( dynamic_cast< SfxUnoStyleSheet* >( pStyleSheet ) ) );
1040 class SdUnoEventsAccess : public cppu::WeakImplHelper< css::container::XNameReplace, css::lang::XServiceInfo >
1042 private:
1043 SdXShape* const mpShape;
1045 public:
1046 explicit SdUnoEventsAccess(SdXShape* pShape) throw();
1048 // XNameReplace
1049 virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
1051 // XNameAccess
1052 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
1053 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
1054 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
1056 // XElementAccess
1057 virtual css::uno::Type SAL_CALL getElementType( ) override;
1058 virtual sal_Bool SAL_CALL hasElements( ) override;
1060 // XServiceInfo
1061 virtual OUString SAL_CALL getImplementationName( ) override;
1062 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1063 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
1066 // XEventsSupplier
1067 uno::Reference< container::XNameReplace > SAL_CALL SdXShape::getEvents( )
1069 return new SdUnoEventsAccess( this );
1072 static const OUStringLiteral gaStrOnClick( "OnClick" );
1073 static const OUStringLiteral gaStrServiceName( "com.sun.star.documents.Events" );
1074 static const OUStringLiteral gaStrEventType( "EventType" );
1075 static const OUStringLiteral gaStrPresentation( "Presentation" );
1076 static const OUStringLiteral gaStrLibrary("Library");
1077 static const OUStringLiteral gaStrMacroName("MacroName");
1078 static const OUStringLiteral gaStrClickAction( "ClickAction" );
1079 static const OUStringLiteral gaStrBookmark( "Bookmark" );
1080 static const OUStringLiteral gaStrEffect( "Effect" );
1081 static const OUStringLiteral gaStrPlayFull( "PlayFull" );
1082 static const OUStringLiteral gaStrVerb( "Verb" );
1083 static const OUStringLiteral gaStrSoundURL( "SoundURL" );
1084 static const OUStringLiteral gaStrSpeed( "Speed" );
1085 static const OUStringLiteral gaStrStarBasic( "StarBasic" );
1086 static const OUStringLiteral gaStrScript( "Script" );
1088 SdUnoEventsAccess::SdUnoEventsAccess( SdXShape* pShape ) throw()
1089 : mpShape( pShape )
1093 enum class FoundFlags {
1094 NONE = 0x0000,
1095 ClickAction = 0x0001,
1096 Bookmark = 0x0002,
1097 Effect = 0x0004,
1098 PlayFull = 0x0008,
1099 Verb = 0x0010,
1100 SoundUrl = 0x0020,
1101 Speed = 0x0040,
1102 EventType = 0x0080,
1103 Macro = 0x0100,
1104 Library = 0x0200,
1106 namespace o3tl {
1107 template<> struct typed_flags<FoundFlags> : is_typed_flags<FoundFlags, 0x03ff> {};
1110 static void clearEventsInAnimationInfo( SdAnimationInfo* pInfo )
1112 pInfo->SetBookmark( "" );
1113 pInfo->mbSecondSoundOn = false;
1114 pInfo->mbSecondPlayFull = false;
1115 pInfo->meClickAction = presentation::ClickAction_NONE;
1116 pInfo->meSecondEffect = presentation::AnimationEffect_NONE;
1117 pInfo->meSecondSpeed = presentation::AnimationSpeed_MEDIUM;
1118 pInfo->mnVerb = 0;
1121 // XNameReplace
1122 void SAL_CALL SdUnoEventsAccess::replaceByName( const OUString& aName, const uno::Any& aElement )
1124 if( mpShape == nullptr || aName != gaStrOnClick )
1125 throw container::NoSuchElementException();
1127 uno::Sequence< beans::PropertyValue > aProperties;
1128 if( !aElement.hasValue() || aElement.getValueType() != getElementType() || !(aElement >>= aProperties) )
1129 throw lang::IllegalArgumentException();
1131 FoundFlags nFound = FoundFlags::NONE;
1132 const beans::PropertyValue* pProperties = aProperties.getConstArray();
1134 OUString aStrEventType;
1135 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
1136 presentation::AnimationEffect eEffect = presentation::AnimationEffect_NONE;
1137 presentation::AnimationSpeed eSpeed = presentation::AnimationSpeed_MEDIUM;
1138 OUString aStrSoundURL;
1139 bool bPlayFull = false;
1140 sal_Int32 nVerb = 0;
1141 OUString aStrMacro;
1142 OUString aStrLibrary;
1143 OUString aStrBookmark;
1145 const sal_Int32 nCount = aProperties.getLength();
1146 sal_Int32 nIndex;
1147 for( nIndex = 0; nIndex < nCount; nIndex++, pProperties++ )
1149 if( !( nFound & FoundFlags::EventType ) && pProperties->Name == gaStrEventType )
1151 if( pProperties->Value >>= aStrEventType )
1153 nFound |= FoundFlags::EventType;
1154 continue;
1157 else if( !( nFound & FoundFlags::ClickAction ) && pProperties->Name == gaStrClickAction )
1159 if( pProperties->Value >>= eClickAction )
1161 nFound |= FoundFlags::ClickAction;
1162 continue;
1165 else if( !( nFound & FoundFlags::Macro ) && ( pProperties->Name == gaStrMacroName || pProperties->Name == gaStrScript ) )
1167 if( pProperties->Value >>= aStrMacro )
1169 nFound |= FoundFlags::Macro;
1170 continue;
1173 else if( !( nFound & FoundFlags::Library ) && pProperties->Name == gaStrLibrary )
1175 if( pProperties->Value >>= aStrLibrary )
1177 nFound |= FoundFlags::Library;
1178 continue;
1181 else if( !( nFound & FoundFlags::Effect ) && pProperties->Name == gaStrEffect )
1183 if( pProperties->Value >>= eEffect )
1185 nFound |= FoundFlags::Effect;
1186 continue;
1189 else if( !( nFound & FoundFlags::Bookmark ) && pProperties->Name == gaStrBookmark )
1191 if( pProperties->Value >>= aStrBookmark )
1193 nFound |= FoundFlags::Bookmark;
1194 continue;
1197 else if( !( nFound & FoundFlags::Speed ) && pProperties->Name == gaStrSpeed )
1199 if( pProperties->Value >>= eSpeed )
1201 nFound |= FoundFlags::Speed;
1202 continue;
1205 else if( !( nFound & FoundFlags::SoundUrl ) && pProperties->Name == gaStrSoundURL )
1207 if( pProperties->Value >>= aStrSoundURL )
1209 nFound |= FoundFlags::SoundUrl;
1210 continue;
1213 else if( !( nFound & FoundFlags::PlayFull ) && pProperties->Name == gaStrPlayFull )
1215 if( pProperties->Value >>= bPlayFull )
1217 nFound |= FoundFlags::PlayFull;
1218 continue;
1221 else if( !( nFound & FoundFlags::Verb ) && pProperties->Name == gaStrVerb )
1223 if( pProperties->Value >>= nVerb )
1225 nFound |= FoundFlags::Verb;
1226 continue;
1230 throw lang::IllegalArgumentException();
1233 bool bOk = false;
1236 if( !( nFound & FoundFlags::EventType ) )
1237 break;
1239 if( aStrEventType == gaStrPresentation )
1241 if( !( nFound & FoundFlags::ClickAction ) )
1242 break;
1244 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
1245 if( presentation::ClickAction_NONE == eClickAction && nullptr == pInfo )
1247 bOk = true;
1248 break;
1251 if( nullptr == pInfo )
1252 pInfo = mpShape->GetAnimationInfo( true );
1254 DBG_ASSERT( pInfo, "shape animation info could not be created!" );
1255 if( nullptr == pInfo )
1256 break;
1258 clearEventsInAnimationInfo( pInfo );
1259 pInfo->meClickAction = eClickAction;
1261 switch( eClickAction )
1263 case presentation::ClickAction_NONE:
1264 case presentation::ClickAction_PREVPAGE:
1265 case presentation::ClickAction_NEXTPAGE:
1266 case presentation::ClickAction_FIRSTPAGE:
1267 case presentation::ClickAction_LASTPAGE:
1268 case presentation::ClickAction_INVISIBLE:
1269 case presentation::ClickAction_STOPPRESENTATION:
1271 bOk = true;
1273 break;
1275 case presentation::ClickAction_PROGRAM:
1276 case presentation::ClickAction_BOOKMARK:
1277 case presentation::ClickAction_DOCUMENT:
1278 if( nFound & FoundFlags::Bookmark )
1280 if( eClickAction == presentation::ClickAction_BOOKMARK )
1282 aStrBookmark = getUiNameFromPageApiNameImpl( aStrBookmark );
1284 else if( eClickAction == presentation::ClickAction_DOCUMENT )
1286 sal_Int32 nPos = aStrBookmark.lastIndexOf( '#' );
1287 if( nPos >= 0 )
1289 OUString aURL( aStrBookmark.copy( 0, nPos+1 ) );
1290 aURL += getUiNameFromPageApiNameImpl( aStrBookmark.copy( nPos+1 ) );
1291 aStrBookmark = aURL;
1295 pInfo->SetBookmark( aStrBookmark );
1296 bOk = true;
1298 break;
1300 case presentation::ClickAction_MACRO:
1301 if( nFound & FoundFlags::Macro )
1303 pInfo->SetBookmark( aStrMacro );
1304 bOk = true;
1306 break;
1308 case presentation::ClickAction_VERB:
1309 if( nFound & FoundFlags::Verb )
1311 pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
1312 bOk = true;
1314 break;
1316 case presentation::ClickAction_VANISH:
1317 if( !( nFound & FoundFlags::Effect ) )
1318 break;
1320 pInfo->meSecondEffect = eEffect;
1321 pInfo->meSecondSpeed = nFound & FoundFlags::Speed ? eSpeed : presentation::AnimationSpeed_MEDIUM;
1323 bOk = true;
1325 [[fallthrough]];
1327 case presentation::ClickAction_SOUND:
1328 if( nFound & FoundFlags::SoundUrl )
1330 pInfo->SetBookmark( aStrSoundURL );
1331 if( eClickAction != presentation::ClickAction_SOUND )
1332 pInfo->mbSecondSoundOn = !aStrSoundURL.isEmpty();
1333 pInfo->mbSecondPlayFull = (nFound & FoundFlags::PlayFull) && bPlayFull;
1335 bOk = true;
1337 break;
1338 default:
1339 break;
1342 else
1344 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo( true );
1346 DBG_ASSERT( pInfo, "shape animation info could not be created!" );
1347 if( nullptr == pInfo )
1348 break;
1350 clearEventsInAnimationInfo( pInfo );
1351 pInfo->meClickAction = presentation::ClickAction_MACRO;
1353 if ( SfxApplication::IsXScriptURL( aStrMacro ) )
1355 pInfo->SetBookmark( aStrMacro );
1357 else
1359 sal_Int32 nIdx{ 0 };
1360 const OUString aLibName = aStrMacro.getToken(0, '.', nIdx);
1361 const OUString aModulName = aStrMacro.getToken(0, '.', nIdx);
1362 const OUString aMacroName = aStrMacro.getToken(0, '.', nIdx);
1364 OUStringBuffer sBuffer;
1365 sBuffer.append( aMacroName );
1366 sBuffer.append( '.' );
1367 sBuffer.append( aModulName );
1368 sBuffer.append( '.' );
1369 sBuffer.append( aLibName );
1370 sBuffer.append( '.' );
1372 if ( aStrLibrary == "StarOffice" )
1374 sBuffer.append( "BASIC" );
1376 else
1378 sBuffer.append( aStrLibrary );
1381 pInfo->SetBookmark( sBuffer.makeStringAndClear() );
1383 bOk = true;
1386 while(false);
1388 if( !bOk )
1389 throw lang::IllegalArgumentException();
1392 // XNameAccess
1393 uno::Any SAL_CALL SdUnoEventsAccess::getByName( const OUString& aName )
1395 if( mpShape == nullptr || aName != gaStrOnClick )
1396 throw container::NoSuchElementException();
1398 SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
1400 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
1401 if( pInfo )
1402 eClickAction = pInfo->meClickAction;
1404 sal_Int32 nPropertyCount = 2;
1405 switch( eClickAction )
1407 case presentation::ClickAction_NONE:
1408 case presentation::ClickAction_PREVPAGE:
1409 case presentation::ClickAction_NEXTPAGE:
1410 case presentation::ClickAction_FIRSTPAGE:
1411 case presentation::ClickAction_LASTPAGE:
1412 case presentation::ClickAction_INVISIBLE:
1413 case presentation::ClickAction_STOPPRESENTATION:
1414 break;
1415 case presentation::ClickAction_PROGRAM:
1416 case presentation::ClickAction_VERB:
1417 case presentation::ClickAction_BOOKMARK:
1418 case presentation::ClickAction_DOCUMENT:
1419 case presentation::ClickAction_MACRO:
1420 if ( !SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
1421 nPropertyCount += 1;
1422 break;
1424 case presentation::ClickAction_SOUND:
1425 nPropertyCount += 2;
1426 break;
1428 case presentation::ClickAction_VANISH:
1429 nPropertyCount += 4;
1430 break;
1431 default:
1432 break;
1435 uno::Sequence< beans::PropertyValue > aProperties( nPropertyCount );
1436 beans::PropertyValue* pProperties = aProperties.getArray();
1438 uno::Any aAny;
1440 if( eClickAction == presentation::ClickAction_MACRO )
1442 if ( SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
1444 // Scripting Framework URL
1445 aAny <<= OUString(gaStrScript);
1446 pProperties->Name = gaStrEventType;
1447 pProperties->Handle = -1;
1448 pProperties->Value = aAny;
1449 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1450 pProperties++;
1452 aAny <<= pInfo->GetBookmark();
1453 pProperties->Name = gaStrScript;
1454 pProperties->Handle = -1;
1455 pProperties->Value = aAny;
1456 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1457 pProperties++;
1459 else
1461 // Old Basic macro URL
1462 aAny <<= OUString(gaStrStarBasic);
1463 pProperties->Name = gaStrEventType;
1464 pProperties->Handle = -1;
1465 pProperties->Value = aAny;
1466 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1467 pProperties++;
1469 OUString aMacro = pInfo->GetBookmark();
1471 // aMacro has got following format:
1472 // "Macroname.Modulname.Libname.Documentname" or
1473 // "Macroname.Modulname.Libname.Applicationname"
1474 sal_Int32 nIdx{ 0 };
1475 const OUString aMacroName = aMacro.getToken(0, '.', nIdx);
1476 const OUString aModulName = aMacro.getToken(0, '.', nIdx);
1477 const OUString aLibName = aMacro.getToken(0, '.', nIdx);
1479 OUStringBuffer sBuffer;
1480 sBuffer.append( aLibName );
1481 sBuffer.append( '.' );
1482 sBuffer.append( aModulName );
1483 sBuffer.append( '.' );
1484 sBuffer.append( aMacroName );
1486 aAny <<= sBuffer.makeStringAndClear();
1487 pProperties->Name = gaStrMacroName;
1488 pProperties->Handle = -1;
1489 pProperties->Value = aAny;
1490 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1491 pProperties++;
1493 aAny <<= OUString( "StarOffice" );
1494 pProperties->Name = gaStrLibrary;
1495 pProperties->Handle = -1;
1496 pProperties->Value = aAny;
1497 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1500 else
1502 aAny <<= OUString(gaStrPresentation);
1503 pProperties->Name = gaStrEventType;
1504 pProperties->Handle = -1;
1505 pProperties->Value = aAny;
1506 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1507 pProperties++;
1509 aAny <<= eClickAction;
1510 pProperties->Name = gaStrClickAction;
1511 pProperties->Handle = -1;
1512 pProperties->Value = aAny;
1513 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1514 pProperties++;
1516 switch( eClickAction )
1518 case presentation::ClickAction_NONE:
1519 case presentation::ClickAction_PREVPAGE:
1520 case presentation::ClickAction_NEXTPAGE:
1521 case presentation::ClickAction_FIRSTPAGE:
1522 case presentation::ClickAction_LASTPAGE:
1523 case presentation::ClickAction_INVISIBLE:
1524 case presentation::ClickAction_STOPPRESENTATION:
1525 break;
1526 case presentation::ClickAction_BOOKMARK:
1528 const OUString aStrBookmark( getPageApiNameFromUiName( pInfo->GetBookmark()) );
1529 pProperties->Name = gaStrBookmark;
1530 pProperties->Handle = -1;
1531 pProperties->Value <<= aStrBookmark;
1532 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1534 break;
1536 case presentation::ClickAction_DOCUMENT:
1537 case presentation::ClickAction_PROGRAM:
1539 OUString aString( pInfo->GetBookmark());
1540 sal_Int32 nPos = aString.lastIndexOf( '#' );
1541 if( nPos >= 0 )
1543 OUString aURL( aString.copy( 0, nPos+1 ) );
1544 aURL += getPageApiNameFromUiName( aString.copy( nPos+1 ) );
1545 aString = aURL;
1547 pProperties->Name = gaStrBookmark;
1548 pProperties->Handle = -1;
1549 pProperties->Value <<= aString;
1550 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1552 break;
1554 case presentation::ClickAction_VANISH:
1555 aAny <<= pInfo->meSecondEffect;
1556 pProperties->Name = gaStrEffect;
1557 pProperties->Handle = -1;
1558 pProperties->Value = aAny;
1559 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1560 pProperties++;
1562 aAny <<= pInfo->meSecondSpeed;
1563 pProperties->Name = gaStrSpeed;
1564 pProperties->Handle = -1;
1565 pProperties->Value = aAny;
1566 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1567 pProperties++;
1569 [[fallthrough]];
1571 case presentation::ClickAction_SOUND:
1572 if( eClickAction == presentation::ClickAction_SOUND || pInfo->mbSecondSoundOn )
1574 aAny <<= pInfo->GetBookmark();
1575 pProperties->Name = gaStrSoundURL;
1576 pProperties->Handle = -1;
1577 pProperties->Value = aAny;
1578 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1579 pProperties++;
1581 pProperties->Name = gaStrPlayFull;
1582 pProperties->Handle = -1;
1583 pProperties->Value <<= pInfo->mbSecondPlayFull;
1584 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1586 break;
1588 case presentation::ClickAction_VERB:
1589 aAny <<= static_cast<sal_Int32>(pInfo->mnVerb);
1590 pProperties->Name = gaStrVerb;
1591 pProperties->Handle = -1;
1592 pProperties->Value = aAny;
1593 pProperties->State = beans::PropertyState_DIRECT_VALUE;
1594 break;
1595 default:
1596 break;
1600 aAny <<= aProperties;
1601 return aAny;
1604 uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getElementNames( )
1606 return { gaStrOnClick };
1609 sal_Bool SAL_CALL SdUnoEventsAccess::hasByName( const OUString& aName )
1611 return aName == gaStrOnClick;
1614 // XElementAccess
1615 uno::Type SAL_CALL SdUnoEventsAccess::getElementType( )
1617 return cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get();
1620 sal_Bool SAL_CALL SdUnoEventsAccess::hasElements( )
1622 return true;
1625 // XServiceInfo
1626 OUString SAL_CALL SdUnoEventsAccess::getImplementationName( )
1628 return OUString( "SdUnoEventsAccess" );
1631 sal_Bool SAL_CALL SdUnoEventsAccess::supportsService( const OUString& ServiceName )
1633 return cppu::supportsService(this, ServiceName);
1636 uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getSupportedServiceNames( )
1638 return { gaStrServiceName };
1641 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */