cid#1640468 Dereference after null check
[LibreOffice.git] / sd / source / ui / func / fuoaprms.cxx
blobd6f356d257f39a7079ee99e7724045ea9b32f539
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 <fuoaprms.hxx>
21 #include <sdattr.hrc>
23 #include <editeng/colritem.hxx>
24 #include <svx/svdundo.hxx>
25 #include <sfx2/objsh.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/sfxdlg.hxx>
29 #include <svl/intitem.hxx>
30 #include <svl/stritem.hxx>
31 #include <svx/svdopath.hxx>
32 #include <tools/debug.hxx>
34 #include <strings.hrc>
35 #include <drawdoc.hxx>
36 #include <ViewShell.hxx>
37 #include <ViewShellBase.hxx>
38 #include <anminfo.hxx>
39 #include <unoaprms.hxx>
40 #include <sdundogr.hxx>
41 #include <View.hxx>
42 #include <sdabstdlg.hxx>
43 #include <sdresid.hxx>
44 #include <tools/helpers.hxx>
45 #include <tpaction.hxx>
46 #include <basegfx/polygon/b2dpolygon.hxx>
47 #include <memory>
49 using namespace ::com::sun::star;
51 namespace sd {
54 #define ATTR_MISSING 0 ///< Attribute missing
55 #define ATTR_MIXED 1 ///< Attribute ambiguous (on multi-selection)
56 #define ATTR_SET 2 ///< Attribute unique
58 FuObjectAnimationParameters::FuObjectAnimationParameters (
59 ViewShell* pViewSh,
60 ::sd::Window* pWin,
61 ::sd::View* pView,
62 SdDrawDocument* pDoc,
63 SfxRequest& rReq)
64 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
68 rtl::Reference<FuPoor> FuObjectAnimationParameters::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
70 rtl::Reference<FuPoor> xFunc( new FuObjectAnimationParameters( pViewSh, pWin, pView, pDoc, rReq ) );
71 xFunc->DoExecute(rReq);
72 return xFunc;
75 void FuObjectAnimationParameters::DoExecute( SfxRequest& rReq )
77 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
78 const size_t nCount = rMarkList.GetMarkCount();
80 short nAnimationSet = ATTR_MISSING;
81 short nEffectSet = ATTR_MISSING;
82 short nTextEffectSet = ATTR_MISSING;
83 short nSpeedSet = ATTR_MISSING;
84 short nFadeColorSet = ATTR_MISSING;
85 short nFadeOutSet = ATTR_MISSING;
86 short nInvisibleSet = ATTR_MISSING;
87 short nSoundOnSet = ATTR_MISSING;
88 short nSoundFileSet = ATTR_MISSING;
89 short nPlayFullSet = ATTR_MISSING;
90 short nClickActionSet = ATTR_MISSING;
91 short nBookmarkSet = ATTR_MISSING;
93 short nSecondEffectSet = ATTR_MISSING;
94 short nSecondSpeedSet = ATTR_MISSING;
95 short nSecondSoundOnSet = ATTR_MISSING;
96 short nSecondPlayFullSet = ATTR_MISSING;
98 // defaults (for Undo-Action)
99 presentation::AnimationEffect eEffect = presentation::AnimationEffect_NONE;
100 presentation::AnimationEffect eTextEffect = presentation::AnimationEffect_NONE;
101 presentation::AnimationSpeed eSpeed = presentation::AnimationSpeed_MEDIUM;
102 bool bActive = false;
103 bool bFadeOut = false;
104 Color aFadeColor = COL_LIGHTGRAY;
105 bool bInvisible = false;
106 bool bSoundOn = false;
107 OUString aSound;
108 bool bPlayFull = false;
109 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
110 OUString aBookmark;
112 presentation::AnimationEffect eSecondEffect = presentation::AnimationEffect_NONE;
113 presentation::AnimationSpeed eSecondSpeed = presentation::AnimationSpeed_MEDIUM;
114 bool bSecondSoundOn = false;
115 bool bSecondPlayFull = false;
117 SdAnimationInfo* pInfo;
118 SdrMark* pMark;
120 // inspect first object
121 pMark = rMarkList.GetMark(0);
122 pInfo = SdDrawDocument::GetAnimationInfo(pMark->GetMarkedSdrObj());
123 if( pInfo )
125 bActive = pInfo->mbActive;
126 nAnimationSet = ATTR_SET;
128 eEffect = pInfo->meEffect;
129 nEffectSet = ATTR_SET;
131 eTextEffect = pInfo->meTextEffect;
132 nTextEffectSet = ATTR_SET;
134 eSpeed = pInfo->meSpeed;
135 nSpeedSet = ATTR_SET;
137 bFadeOut = pInfo->mbDimPrevious;
138 nFadeOutSet = ATTR_SET;
140 aFadeColor = pInfo->maDimColor;
141 nFadeColorSet = ATTR_SET;
143 bInvisible = pInfo->mbDimHide;
144 nInvisibleSet = ATTR_SET;
146 bSoundOn = pInfo->mbSoundOn;
147 nSoundOnSet = ATTR_SET;
149 aSound = pInfo->maSoundFile;
150 nSoundFileSet = ATTR_SET;
152 bPlayFull = pInfo->mbPlayFull;
153 nPlayFullSet = ATTR_SET;
155 eClickAction = pInfo->meClickAction;
156 nClickActionSet = ATTR_SET;
158 aBookmark = pInfo->GetBookmark();
159 nBookmarkSet = ATTR_SET;
161 eSecondEffect = pInfo->meSecondEffect;
162 nSecondEffectSet = ATTR_SET;
164 eSecondSpeed = pInfo->meSecondSpeed;
165 nSecondSpeedSet = ATTR_SET;
167 bSecondSoundOn = pInfo->mbSecondSoundOn;
168 nSecondSoundOnSet = ATTR_SET;
170 bSecondPlayFull = pInfo->mbSecondPlayFull;
171 nSecondPlayFullSet = ATTR_SET;
174 // if necessary, inspect more objects
175 for( size_t nObject = 1; nObject < nCount; ++nObject )
177 pMark = rMarkList.GetMark( nObject );
178 SdrObject* pObject = pMark->GetMarkedSdrObj();
179 pInfo = SdDrawDocument::GetAnimationInfo(pObject);
180 if( pInfo )
182 if( bActive != pInfo->mbActive )
183 nAnimationSet = ATTR_MIXED;
185 if( eEffect != pInfo->meEffect )
186 nEffectSet = ATTR_MIXED;
188 if( eTextEffect != pInfo->meTextEffect )
189 nTextEffectSet = ATTR_MIXED;
191 if( eSpeed != pInfo->meSpeed )
192 nSpeedSet = ATTR_MIXED;
194 if( bFadeOut != pInfo->mbDimPrevious )
195 nFadeOutSet = ATTR_MIXED;
197 if( aFadeColor != pInfo->maDimColor )
198 nFadeColorSet = ATTR_MIXED;
200 if( bInvisible != pInfo->mbDimHide )
201 nInvisibleSet = ATTR_MIXED;
203 if( bSoundOn != pInfo->mbSoundOn )
204 nSoundOnSet = ATTR_MIXED;
206 if( aSound != pInfo->maSoundFile )
207 nSoundFileSet = ATTR_MIXED;
209 if( bPlayFull != pInfo->mbPlayFull )
210 nPlayFullSet = ATTR_MIXED;
212 if( eClickAction != pInfo->meClickAction )
213 nClickActionSet = ATTR_MIXED;
215 if( aBookmark != pInfo->GetBookmark() )
216 nBookmarkSet = ATTR_MIXED;
218 if( eSecondEffect != pInfo->meSecondEffect )
219 nSecondEffectSet = ATTR_MIXED;
221 if( eSecondSpeed != pInfo->meSecondSpeed )
222 nSecondSpeedSet = ATTR_MIXED;
224 if( bSecondSoundOn != pInfo->mbSecondSoundOn )
225 nSecondSoundOnSet = ATTR_MIXED;
227 if( bSecondPlayFull != pInfo->mbSecondPlayFull )
228 nSecondPlayFullSet = ATTR_MIXED;
230 else
232 if (nAnimationSet == ATTR_SET && bActive)
233 nAnimationSet = ATTR_MIXED;
235 if (nEffectSet == ATTR_SET && eEffect != presentation::AnimationEffect_NONE)
236 nEffectSet = ATTR_MIXED;
238 if (nTextEffectSet == ATTR_SET && eTextEffect != presentation::AnimationEffect_NONE)
239 nTextEffectSet = ATTR_MIXED;
241 if (nSpeedSet == ATTR_SET)
242 nSpeedSet = ATTR_MIXED;
244 if (nFadeOutSet == ATTR_SET && bFadeOut)
245 nFadeOutSet = ATTR_MIXED;
247 if (nFadeColorSet == ATTR_SET)
248 nFadeColorSet = ATTR_MIXED;
250 if (nInvisibleSet == ATTR_SET && bInvisible)
251 nInvisibleSet = ATTR_MIXED;
253 if (nSoundOnSet == ATTR_SET && bSoundOn)
254 nSoundOnSet = ATTR_MIXED;
256 if (nSoundFileSet == ATTR_SET)
257 nSoundFileSet = ATTR_MIXED;
259 if (nPlayFullSet == ATTR_SET && bPlayFull)
260 nPlayFullSet = ATTR_MIXED;
262 if (nClickActionSet == ATTR_SET && eClickAction != presentation::ClickAction_NONE)
263 nClickActionSet = ATTR_MIXED;
265 if (nBookmarkSet == ATTR_SET)
266 nBookmarkSet = ATTR_MIXED;
268 if (nSecondEffectSet == ATTR_SET && eSecondEffect != presentation::AnimationEffect_NONE)
269 nSecondEffectSet = ATTR_MIXED;
271 if (nSecondSpeedSet == ATTR_SET)
272 nSecondSpeedSet = ATTR_MIXED;
274 if (nSecondSoundOnSet == ATTR_SET && bSecondSoundOn)
275 nSecondSoundOnSet = ATTR_MIXED;
277 if (nSecondPlayFullSet == ATTR_SET && bSecondPlayFull)
278 nSecondPlayFullSet = ATTR_MIXED;
282 /* Exactly two objects with path effect?
283 Then, only the animation info at the moved object is valid. */
284 if (nCount == 2)
286 SdrObject* pObject1 = rMarkList.GetMark(0)->GetMarkedSdrObj();
287 SdrObject* pObject2 = rMarkList.GetMark(1)->GetMarkedSdrObj();
288 SdrObjKind eKind1 = pObject1->GetObjIdentifier();
289 SdrObjKind eKind2 = pObject2->GetObjIdentifier();
290 SdAnimationInfo* pInfo1 = SdDrawDocument::GetAnimationInfo(pObject1);
291 SdAnimationInfo* pInfo2 = SdDrawDocument::GetAnimationInfo(pObject2);
292 pInfo = nullptr;
294 if (pObject1->GetObjInventor() == SdrInventor::Default &&
295 ((eKind1 == SdrObjKind::Line) || // 2 point line
296 (eKind1 == SdrObjKind::PolyLine) || // Polygon
297 (eKind1 == SdrObjKind::PathLine)) && // Bezier curve
298 (pInfo2 && pInfo2->meEffect == presentation::AnimationEffect_PATH))
300 pInfo = pInfo2;
303 if (pObject2->GetObjInventor() == SdrInventor::Default &&
304 ((eKind2 == SdrObjKind::Line) || // 2 point line
305 (eKind2 == SdrObjKind::PolyLine) || // Polygon
306 (eKind2 == SdrObjKind::PathLine)) && // Bezier curve
307 (pInfo1 && pInfo1->meEffect == presentation::AnimationEffect_PATH))
309 pInfo = pInfo1;
312 if (pInfo)
314 bActive = pInfo->mbActive; nAnimationSet = ATTR_SET;
315 eEffect = pInfo->meEffect; nEffectSet = ATTR_SET;
316 eTextEffect = pInfo->meTextEffect; nTextEffectSet = ATTR_SET;
317 eSpeed = pInfo->meSpeed; nSpeedSet = ATTR_SET;
318 bFadeOut = pInfo->mbDimPrevious; nFadeOutSet = ATTR_SET;
319 aFadeColor = pInfo->maDimColor; nFadeColorSet = ATTR_SET;
320 bInvisible = pInfo->mbDimHide; nInvisibleSet = ATTR_SET;
321 bSoundOn = pInfo->mbSoundOn; nSoundOnSet = ATTR_SET;
322 aSound = pInfo->maSoundFile; nSoundFileSet = ATTR_SET;
323 bPlayFull = pInfo->mbPlayFull; nPlayFullSet = ATTR_SET;
324 eClickAction = pInfo->meClickAction; nClickActionSet = ATTR_SET;
325 aBookmark = pInfo->GetBookmark(); nBookmarkSet = ATTR_SET;
326 eSecondEffect = pInfo->meSecondEffect; nSecondEffectSet = ATTR_SET;
327 eSecondSpeed = pInfo->meSecondSpeed; nSecondSpeedSet = ATTR_SET;
328 bSecondSoundOn = pInfo->mbSecondSoundOn; nSecondSoundOnSet = ATTR_SET;
329 bSecondPlayFull = pInfo->mbSecondPlayFull; nSecondPlayFullSet = ATTR_SET;
333 const SfxItemSet* pArgs = rReq.GetArgs();
335 if(!pArgs)
337 // fill ItemSet for dialog
338 std::shared_ptr<SfxItemSet> aSet = std::make_shared<SfxItemSetFixed<ATTR_ANIMATION_START, ATTR_ACTION_END>>(mpDoc->GetPool());
340 // fill the set
341 if (nAnimationSet == ATTR_SET)
342 aSet->Put( SfxBoolItem( ATTR_ANIMATION_ACTIVE, bActive));
343 else if (nAnimationSet == ATTR_MIXED)
344 aSet->InvalidateItem(ATTR_ANIMATION_ACTIVE);
345 else
346 aSet->Put(SfxBoolItem(ATTR_ANIMATION_ACTIVE, false));
348 if (nEffectSet == ATTR_SET)
349 aSet->Put(SfxUInt16Item(ATTR_ANIMATION_EFFECT, static_cast<sal_uInt16>(eEffect)));
350 else if (nEffectSet == ATTR_MIXED)
351 aSet->InvalidateItem( ATTR_ANIMATION_EFFECT );
352 else
353 aSet->Put(SfxUInt16Item(ATTR_ANIMATION_EFFECT, sal_uInt16(presentation::AnimationEffect_NONE)));
355 if (nTextEffectSet == ATTR_SET)
356 aSet->Put(SfxUInt16Item(ATTR_ANIMATION_TEXTEFFECT, static_cast<sal_uInt16>(eTextEffect)));
357 else if (nTextEffectSet == ATTR_MIXED)
358 aSet->InvalidateItem( ATTR_ANIMATION_TEXTEFFECT );
359 else
360 aSet->Put(SfxUInt16Item(ATTR_ANIMATION_TEXTEFFECT, sal_uInt16(presentation::AnimationEffect_NONE)));
362 if (nSpeedSet == ATTR_SET)
363 aSet->Put(SfxUInt16Item(ATTR_ANIMATION_SPEED, static_cast<sal_uInt16>(eSpeed)));
364 else
365 aSet->InvalidateItem(ATTR_ANIMATION_SPEED);
367 if (nFadeOutSet == ATTR_SET)
368 aSet->Put(SfxBoolItem(ATTR_ANIMATION_FADEOUT, bFadeOut));
369 else if (nFadeOutSet == ATTR_MIXED)
370 aSet->InvalidateItem(ATTR_ANIMATION_FADEOUT);
371 else
372 aSet->Put(SfxBoolItem(ATTR_ANIMATION_FADEOUT, false));
374 if (nFadeColorSet == ATTR_SET)
375 aSet->Put(SvxColorItem(aFadeColor, ATTR_ANIMATION_COLOR));
376 else if (nFadeColorSet == ATTR_MIXED)
377 aSet->InvalidateItem(ATTR_ANIMATION_COLOR);
378 else
379 aSet->Put(SvxColorItem(COL_LIGHTGRAY, ATTR_ANIMATION_COLOR));
381 if (nInvisibleSet == ATTR_SET)
382 aSet->Put(SfxBoolItem(ATTR_ANIMATION_INVISIBLE, bInvisible));
383 else if (nInvisibleSet == ATTR_MIXED)
384 aSet->InvalidateItem(ATTR_ANIMATION_INVISIBLE);
385 else
386 aSet->Put(SfxBoolItem(ATTR_ANIMATION_INVISIBLE, false));
388 if (nSoundOnSet == ATTR_SET)
389 aSet->Put(SfxBoolItem(ATTR_ANIMATION_SOUNDON, bSoundOn));
390 else if (nSoundOnSet == ATTR_MIXED)
391 aSet->InvalidateItem(ATTR_ANIMATION_SOUNDON);
392 else
393 aSet->Put(SfxBoolItem(ATTR_ANIMATION_SOUNDON, false));
395 if (nSoundFileSet == ATTR_SET)
396 aSet->Put(SfxStringItem(ATTR_ANIMATION_SOUNDFILE, aSound));
397 else
398 aSet->InvalidateItem(ATTR_ANIMATION_SOUNDFILE);
400 if (nPlayFullSet == ATTR_SET)
401 aSet->Put(SfxBoolItem(ATTR_ANIMATION_PLAYFULL, bPlayFull));
402 else if (nPlayFullSet == ATTR_MIXED)
403 aSet->InvalidateItem(ATTR_ANIMATION_PLAYFULL);
404 else
405 aSet->Put(SfxBoolItem(ATTR_ANIMATION_PLAYFULL, false));
407 if (nClickActionSet == ATTR_SET)
408 aSet->Put(SfxUInt16Item(ATTR_ACTION, static_cast<sal_uInt16>(eClickAction)));
409 else if (nClickActionSet == ATTR_MIXED)
410 aSet->InvalidateItem(ATTR_ACTION);
411 else
412 aSet->Put(SfxUInt16Item(ATTR_ACTION, sal_uInt16(presentation::ClickAction_NONE)));
414 if (nBookmarkSet == ATTR_SET)
415 aSet->Put(SfxStringItem(ATTR_ACTION_FILENAME, aBookmark));
416 else
417 aSet->InvalidateItem(ATTR_ACTION_FILENAME);
419 if (nSecondEffectSet == ATTR_SET)
420 aSet->Put(SfxUInt16Item(ATTR_ACTION_EFFECT, static_cast<sal_uInt16>(eSecondEffect)));
421 else if (nSecondEffectSet == ATTR_MIXED)
422 aSet->InvalidateItem( ATTR_ACTION_EFFECT );
423 else
424 aSet->Put(SfxUInt16Item(ATTR_ACTION_EFFECT, sal_uInt16(presentation::AnimationEffect_NONE)));
426 if (nSecondSpeedSet == ATTR_SET)
427 aSet->Put(SfxUInt16Item(ATTR_ACTION_EFFECTSPEED, static_cast<sal_uInt16>(eSecondSpeed)));
428 else
429 aSet->InvalidateItem(ATTR_ACTION_EFFECTSPEED);
431 if (nSecondSoundOnSet == ATTR_SET)
432 aSet->Put(SfxBoolItem(ATTR_ACTION_SOUNDON, bSecondSoundOn));
433 else if (nSecondSoundOnSet == ATTR_MIXED)
434 aSet->InvalidateItem(ATTR_ACTION_SOUNDON);
435 else
436 aSet->Put(SfxBoolItem(ATTR_ACTION_SOUNDON, false));
438 if (nSecondPlayFullSet == ATTR_SET)
439 aSet->Put(SfxBoolItem(ATTR_ACTION_PLAYFULL, bSecondPlayFull));
440 else if (nSecondPlayFullSet == ATTR_MIXED)
441 aSet->InvalidateItem(ATTR_ACTION_PLAYFULL);
442 else
443 aSet->Put(SfxBoolItem(ATTR_ACTION_PLAYFULL, false));
445 std::shared_ptr<SfxRequest> xRequest = std::make_shared<SfxRequest>(rReq);
446 rReq.Ignore(); // the 'old' request is not relevant any more
448 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
449 VclPtr<SfxAbstractDialog> pDlg( pFact->CreatSdActionDialog(mpViewShell->GetFrameWeld(), *aSet, mpView) );
450 rtl::Reference<FuObjectAnimationParameters> xThis( this ); // avoid destruction within async processing
451 pDlg->StartExecuteAsync([pDlg, xThis, xRequest=std::move(xRequest), aSet=std::move(aSet)](sal_Int32 nResult){
452 if (nResult == RET_OK) {
453 xThis->Finish(xRequest, pDlg);
455 pDlg->disposeOnce();
460 void FuObjectAnimationParameters::Finish( const std::shared_ptr<SfxRequest>& xRequest, const VclPtr<SfxAbstractDialog>& pDlg )
462 SfxUndoManager* pUndoMgr = mpViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager();
464 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
465 const size_t nCount = rMarkList.GetMarkCount();
467 short nAnimationSet = ATTR_MISSING;
468 short nEffectSet = ATTR_MISSING;
469 short nTextEffectSet = ATTR_MISSING;
470 short nSpeedSet = ATTR_MISSING;
471 short nFadeColorSet = ATTR_MISSING;
472 short nFadeOutSet = ATTR_MISSING;
473 short nInvisibleSet = ATTR_MISSING;
474 short nSoundOnSet = ATTR_MISSING;
475 short nSoundFileSet = ATTR_MISSING;
476 short nPlayFullSet = ATTR_MISSING;
477 short nClickActionSet = ATTR_MISSING;
478 short nBookmarkSet = ATTR_MISSING;
480 short nSecondEffectSet = ATTR_MISSING;
481 short nSecondSpeedSet = ATTR_MISSING;
482 short nSecondSoundOnSet = ATTR_MISSING;
483 short nSecondPlayFullSet = ATTR_MISSING;
485 presentation::AnimationEffect eEffect = presentation::AnimationEffect_NONE;
486 presentation::AnimationEffect eTextEffect = presentation::AnimationEffect_NONE;
487 presentation::AnimationSpeed eSpeed = presentation::AnimationSpeed_MEDIUM;
488 bool bActive = false;
489 bool bFadeOut = false;
490 Color aFadeColor = COL_LIGHTGRAY;
491 bool bInvisible = false;
492 bool bSoundOn = false;
493 OUString aSound;
494 bool bPlayFull = false;
495 presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
496 OUString aBookmark;
498 presentation::AnimationEffect eSecondEffect = presentation::AnimationEffect_NONE;
499 presentation::AnimationSpeed eSecondSpeed = presentation::AnimationSpeed_MEDIUM;
500 bool bSecondSoundOn = false;
501 bool bSecondPlayFull = false;
503 SdAnimationInfo* pInfo;
505 xRequest->Done( *( pDlg->GetOutputItemSet() ) );
506 auto pArgs = xRequest->GetArgs();
508 // evaluation of the ItemSets
509 if (pArgs->GetItemState(ATTR_ANIMATION_ACTIVE) == SfxItemState::SET)
511 bActive = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ANIMATION_ACTIVE)).GetValue();
512 nAnimationSet = ATTR_SET;
514 else
515 nAnimationSet = ATTR_MISSING;
517 if (pArgs->GetItemState(ATTR_ANIMATION_EFFECT) == SfxItemState::SET)
519 eEffect = static_cast<presentation::AnimationEffect>( pArgs->
520 Get(ATTR_ANIMATION_EFFECT).GetValue());
521 nEffectSet = ATTR_SET;
523 else
524 nEffectSet = ATTR_MISSING;
526 if (pArgs->GetItemState(ATTR_ANIMATION_TEXTEFFECT) == SfxItemState::SET)
528 eTextEffect = static_cast<presentation::AnimationEffect>(static_cast<const SfxUInt16Item&>( pArgs->
529 Get(ATTR_ANIMATION_TEXTEFFECT)).GetValue());
530 nTextEffectSet = ATTR_SET;
532 else
533 nTextEffectSet = ATTR_MISSING;
535 if (pArgs->GetItemState(ATTR_ANIMATION_SPEED) == SfxItemState::SET)
537 eSpeed = static_cast<presentation::AnimationSpeed>( pArgs->
538 Get(ATTR_ANIMATION_SPEED).GetValue());
539 nSpeedSet = ATTR_SET;
541 else
542 nSpeedSet = ATTR_MISSING;
544 if (pArgs->GetItemState(ATTR_ANIMATION_FADEOUT) == SfxItemState::SET)
546 bFadeOut = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ANIMATION_FADEOUT)).GetValue();
547 nFadeOutSet = ATTR_SET;
549 else
550 nFadeOutSet = ATTR_MISSING;
552 if (pArgs->GetItemState(ATTR_ANIMATION_INVISIBLE) == SfxItemState::SET)
554 bInvisible = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ANIMATION_INVISIBLE)).GetValue();
555 nInvisibleSet = ATTR_SET;
557 else
558 nInvisibleSet = ATTR_MISSING;
560 if (pArgs->GetItemState(ATTR_ANIMATION_SOUNDON) == SfxItemState::SET)
562 bSoundOn = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ANIMATION_SOUNDON)).GetValue();
563 nSoundOnSet = ATTR_SET;
565 else
566 nSoundOnSet = ATTR_MISSING;
568 if (pArgs->GetItemState(ATTR_ANIMATION_SOUNDFILE) == SfxItemState::SET)
570 aSound = pArgs->Get(ATTR_ANIMATION_SOUNDFILE).GetValue();
571 nSoundFileSet = ATTR_SET;
573 else
574 nSoundFileSet = ATTR_MISSING;
576 if (pArgs->GetItemState(ATTR_ANIMATION_COLOR) == SfxItemState::SET)
578 aFadeColor = static_cast<const SvxColorItem&>(pArgs->Get(ATTR_ANIMATION_COLOR)).GetValue();
579 nFadeColorSet = ATTR_SET;
581 else
582 nFadeColorSet = ATTR_MISSING;
584 if (pArgs->GetItemState(ATTR_ANIMATION_PLAYFULL) == SfxItemState::SET)
586 bPlayFull = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ANIMATION_PLAYFULL)).GetValue();
587 nPlayFullSet = ATTR_SET;
589 else
590 nPlayFullSet = ATTR_MISSING;
592 if (pArgs->GetItemState(ATTR_ACTION) == SfxItemState::SET)
594 eClickAction = static_cast<presentation::ClickAction>(pArgs->
595 Get(ATTR_ACTION).GetValue());
596 nClickActionSet = ATTR_SET;
598 else
599 nClickActionSet = ATTR_MISSING;
601 if (pArgs->GetItemState(ATTR_ACTION_FILENAME) == SfxItemState::SET)
603 aBookmark = pArgs->Get(ATTR_ACTION_FILENAME).GetValue();
604 nBookmarkSet = ATTR_SET;
606 else
607 nBookmarkSet = ATTR_MISSING;
609 if (pArgs->GetItemState(ATTR_ACTION_EFFECT) == SfxItemState::SET)
611 eSecondEffect = static_cast<presentation::AnimationEffect>( pArgs->
612 Get(ATTR_ACTION_EFFECT).GetValue());
613 nSecondEffectSet = ATTR_SET;
615 else
616 nSecondEffectSet = ATTR_MISSING;
618 if (pArgs->GetItemState(ATTR_ACTION_EFFECTSPEED) == SfxItemState::SET)
620 eSecondSpeed = static_cast<presentation::AnimationSpeed>( pArgs->
621 Get(ATTR_ACTION_EFFECTSPEED).GetValue());
622 nSecondSpeedSet = ATTR_SET;
624 else
625 nSecondSpeedSet = ATTR_MISSING;
627 if (pArgs->GetItemState(ATTR_ACTION_SOUNDON) == SfxItemState::SET)
629 bSecondSoundOn = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ACTION_SOUNDON)).GetValue();
630 nSecondSoundOnSet = ATTR_SET;
632 else
633 nSecondSoundOnSet = ATTR_MISSING;
635 if (pArgs->GetItemState(ATTR_ACTION_PLAYFULL) == SfxItemState::SET)
637 bSecondPlayFull = static_cast<const SfxBoolItem&>(pArgs->Get(ATTR_ACTION_PLAYFULL)).GetValue();
638 nSecondPlayFullSet = ATTR_SET;
640 else
641 nSecondPlayFullSet = ATTR_MISSING;
643 // if any attribute is chosen
644 if (!(nEffectSet == ATTR_SET ||
645 nTextEffectSet == ATTR_SET ||
646 nSpeedSet == ATTR_SET ||
647 nAnimationSet == ATTR_SET ||
648 nFadeOutSet == ATTR_SET ||
649 nFadeColorSet == ATTR_SET ||
650 nInvisibleSet == ATTR_SET ||
651 nSoundOnSet == ATTR_SET ||
652 nSoundFileSet == ATTR_SET ||
653 nPlayFullSet == ATTR_SET ||
654 nClickActionSet == ATTR_SET ||
655 nBookmarkSet == ATTR_SET ||
656 nSecondEffectSet == ATTR_SET ||
657 nSecondSpeedSet == ATTR_SET ||
658 nSecondSoundOnSet == ATTR_SET ||
659 nSecondPlayFullSet == ATTR_SET))
660 return;
662 // String for undo-group and list-action
663 OUString aComment(SdResId(STR_UNDO_ANIMATION));
665 // with 'following curves', we have an additional UndoAction
666 // therefore cling? here
667 pUndoMgr->EnterListAction(aComment, aComment, 0, mpViewShell->GetViewShellBase().GetViewShellId());
669 // create undo group
670 std::unique_ptr<SdUndoGroup> pUndoGroup(new SdUndoGroup(mpDoc));
671 pUndoGroup->SetComment(aComment);
673 // for the path effect, remember some stuff
674 SdrPathObj* pPath = nullptr;
675 if (eEffect == presentation::AnimationEffect_PATH && nEffectSet == ATTR_SET)
677 DBG_ASSERT(nCount == 2, "This effect expects two selected objects");
678 SdrObject* pObject1 = rMarkList.GetMark(0)->GetMarkedSdrObj();
679 SdrObject* pObject2 = rMarkList.GetMark(1)->GetMarkedSdrObj();
680 SdrObjKind eKind1 = pObject1->GetObjIdentifier();
681 SdrObjKind eKind2 = pObject2->GetObjIdentifier();
682 SdrObject* pRunningObj = nullptr;
684 if (pObject1->GetObjInventor() == SdrInventor::Default &&
685 ((eKind1 == SdrObjKind::Line) || // 2 point line
686 (eKind1 == SdrObjKind::PolyLine) || // Polygon
687 (eKind1 == SdrObjKind::PathLine))) // Bezier curve
689 pPath = static_cast<SdrPathObj*>(pObject1);
690 pRunningObj = pObject2;
693 if (pObject2->GetObjInventor() == SdrInventor::Default &&
694 ((eKind2 == SdrObjKind::Line) || // 2 point line
695 (eKind2 == SdrObjKind::PolyLine) || // Polygon
696 (eKind2 == SdrObjKind::PathLine))) // Bezier curve
698 pPath = static_cast<SdrPathObj*>(pObject2);
699 pRunningObj = pObject1;
702 assert(pRunningObj && pPath && "no curve found");
704 // push the running object to the end of the curve
705 if (pRunningObj)
707 ::tools::Rectangle aCurRect(pRunningObj->GetLogicRect());
708 Point aCurCenter(aCurRect.Center());
709 const ::basegfx::B2DPolyPolygon& rPolyPolygon = pPath->GetPathPoly();
710 sal_uInt32 nNoOfPolygons(rPolyPolygon.count());
711 const ::basegfx::B2DPolygon& aPolygon(rPolyPolygon.getB2DPolygon(nNoOfPolygons - 1));
712 sal_uInt32 nPoints(aPolygon.count());
713 const ::basegfx::B2DPoint aNewB2DCenter(aPolygon.getB2DPoint(nPoints - 1));
714 const Point aNewCenter(basegfx::fround<::tools::Long>(aNewB2DCenter.getX()),
715 basegfx::fround<::tools::Long>(aNewB2DCenter.getY()));
716 Size aDistance(aNewCenter.X() - aCurCenter.X(), aNewCenter.Y() - aCurCenter.Y());
717 pRunningObj->Move(aDistance);
719 pUndoMgr->AddUndoAction(mpDoc->GetSdrUndoFactory().CreateUndoMoveObject( *pRunningObj, aDistance));
723 for (size_t nObject = 0; nObject < nCount; ++nObject)
725 SdrObject* pObject = rMarkList.GetMark(nObject)->GetMarkedSdrObj();
727 pInfo = SdDrawDocument::GetAnimationInfo(pObject);
729 bool bCreated = false;
730 if( !pInfo )
732 pInfo = SdDrawDocument::GetShapeUserData(*pObject,true);
733 bCreated = true;
736 // path object for 'following curves'?
737 if (eEffect == presentation::AnimationEffect_PATH && pObject == pPath)
739 SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction
740 (mpDoc, pObject, bCreated);
741 pAction->SetActive(pInfo->mbActive, pInfo->mbActive);
742 pAction->SetEffect(pInfo->meEffect, pInfo->meEffect);
743 pAction->SetTextEffect(pInfo->meTextEffect, pInfo->meTextEffect);
744 pAction->SetSpeed(pInfo->meSpeed, pInfo->meSpeed);
745 pAction->SetDim(pInfo->mbDimPrevious, pInfo->mbDimPrevious);
746 pAction->SetDimColor(pInfo->maDimColor, pInfo->maDimColor);
747 pAction->SetDimHide(pInfo->mbDimHide, pInfo->mbDimHide);
748 pAction->SetSoundOn(pInfo->mbSoundOn, pInfo->mbSoundOn);
749 pAction->SetSound(pInfo->maSoundFile, pInfo->maSoundFile);
750 pAction->SetPlayFull(pInfo->mbPlayFull, pInfo->mbPlayFull);
751 pAction->SetClickAction(pInfo->meClickAction, pInfo->meClickAction);
752 pAction->SetBookmark(pInfo->GetBookmark(), pInfo->GetBookmark());
753 pAction->SetVerb(pInfo->mnVerb, pInfo->mnVerb);
754 pAction->SetSecondEffect(pInfo->meSecondEffect, pInfo->meSecondEffect);
755 pAction->SetSecondSpeed(pInfo->meSecondSpeed, pInfo->meSecondSpeed);
756 pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, pInfo->mbSecondSoundOn);
757 pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull, pInfo->mbSecondPlayFull);
758 pUndoGroup->AddAction(pAction);
761 else
764 // create undo action with old and new sizes
765 SdAnimationPrmsUndoAction* pAction = new SdAnimationPrmsUndoAction
766 (mpDoc, pObject, bCreated);
767 pAction->SetActive(pInfo->mbActive, bActive);
768 pAction->SetEffect(pInfo->meEffect, eEffect);
769 pAction->SetTextEffect(pInfo->meTextEffect, eTextEffect);
770 pAction->SetSpeed(pInfo->meSpeed, eSpeed);
771 pAction->SetDim(pInfo->mbDimPrevious, bFadeOut);
772 pAction->SetDimColor(pInfo->maDimColor, aFadeColor);
773 pAction->SetDimHide(pInfo->mbDimHide, bInvisible);
774 pAction->SetSoundOn(pInfo->mbSoundOn, bSoundOn);
775 pAction->SetSound(pInfo->maSoundFile, aSound);
776 pAction->SetPlayFull(pInfo->mbPlayFull, bPlayFull);
777 pAction->SetClickAction(pInfo->meClickAction, eClickAction);
778 pAction->SetBookmark(pInfo->GetBookmark(), aBookmark);
779 pAction->SetVerb(pInfo->mnVerb, static_cast<sal_uInt16>(pInfo->GetBookmark().toInt32()) );
780 pAction->SetSecondEffect(pInfo->meSecondEffect, eSecondEffect);
781 pAction->SetSecondSpeed(pInfo->meSecondSpeed, eSecondSpeed);
782 pAction->SetSecondSoundOn(pInfo->mbSecondSoundOn, bSecondSoundOn);
783 pAction->SetSecondPlayFull(pInfo->mbSecondPlayFull,bSecondPlayFull);
784 pUndoGroup->AddAction(pAction);
786 // insert new values at info block of the object
787 if (nAnimationSet == ATTR_SET)
788 pInfo->mbActive = bActive;
790 if (nEffectSet == ATTR_SET)
791 pInfo->meEffect = eEffect;
793 if (nTextEffectSet == ATTR_SET)
794 pInfo->meTextEffect = eTextEffect;
796 if (nSpeedSet == ATTR_SET)
797 pInfo->meSpeed = eSpeed;
799 if (nFadeOutSet == ATTR_SET)
800 pInfo->mbDimPrevious = bFadeOut;
802 if (nFadeColorSet == ATTR_SET)
803 pInfo->maDimColor = aFadeColor;
805 if (nInvisibleSet == ATTR_SET)
806 pInfo->mbDimHide = bInvisible;
808 if (nSoundOnSet == ATTR_SET)
809 pInfo->mbSoundOn = bSoundOn;
811 if (nSoundFileSet == ATTR_SET)
812 pInfo->maSoundFile = aSound;
814 if (nPlayFullSet == ATTR_SET)
815 pInfo->mbPlayFull = bPlayFull;
817 if (nClickActionSet == ATTR_SET)
818 pInfo->meClickAction = eClickAction;
820 if (nBookmarkSet == ATTR_SET)
821 pInfo->SetBookmark( aBookmark );
823 if (nSecondEffectSet == ATTR_SET)
824 pInfo->meSecondEffect = eSecondEffect;
826 if (nSecondSpeedSet == ATTR_SET)
827 pInfo->meSecondSpeed = eSecondSpeed;
829 if (nSecondSoundOnSet == ATTR_SET)
830 pInfo->mbSecondSoundOn = bSecondSoundOn;
832 if (nSecondPlayFullSet == ATTR_SET)
833 pInfo->mbSecondPlayFull = bSecondPlayFull;
835 if (eClickAction == presentation::ClickAction_VERB)
836 pInfo->mnVerb = static_cast<sal_uInt16>(aBookmark.toInt32());
839 // Set the Undo Group in of the Undo Manager
840 pUndoMgr->AddUndoAction(std::move(pUndoGroup));
841 pUndoMgr->LeaveListAction();
843 // Model changed
844 mpDoc->SetChanged();
845 // not seen, therefore we do not need to invalidate at the bindings
848 } // end of namespace sd
850 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */