1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterPaneAnimator.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterPaneAnimator.hxx"
37 #include "PresenterAnimation.hxx"
38 #include "PresenterAnimator.hxx"
39 #include "PresenterCanvasHelper.hxx"
40 #include "PresenterController.hxx"
41 #include "PresenterGeometryHelper.hxx"
42 #include "PresenterPaintManager.hxx"
43 #include "PresenterPaneContainer.hxx"
44 #include "PresenterPaneFactory.hxx"
45 #include "PresenterSprite.hxx"
46 #include "PresenterSpritePane.hxx"
47 #include "PresenterWindowManager.hxx"
49 #include <com/sun/star/awt/PosSize.hpp>
50 #include <com/sun/star/awt/XWindowPeer.hpp>
51 #include <com/sun/star/rendering/CompositeOperation.hpp>
52 #include <boost/bind.hpp>
53 #include <boost/bind/protect.hpp>
54 #include <boost/enable_shared_from_this.hpp>
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::drawing::framework
;
59 using ::rtl::OUString
;
62 namespace sdext
{ namespace presenter
{
68 class PresenterPaneAnimatorBase
69 : public ::boost::enable_shared_from_this
<PresenterPaneAnimatorBase
>,
70 public PresenterPaneAnimator
73 PresenterPaneAnimatorBase (
74 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
75 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
77 const EndActions
& rShowEndActions
,
78 const EndActions
& rEndEndActions
);
79 virtual ~PresenterPaneAnimatorBase (void);
81 typedef ::std::vector
< ::boost::function
<void()> > EndOperators
;
83 void ActivatePanes (void);
85 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
);
86 void RestoreFrozenWindows (void);
87 void FreezePanes (const Reference
<rendering::XSpriteCanvas
>& rxCanvas
);
90 ::rtl::Reference
<PresenterController
> mpPresenterController
;
91 ::rtl::Reference
<PresenterPaneContainer
> mpPaneContainer
;
92 ::rtl::Reference
<PresenterWindowManager
> mpWindowManager
;
93 ::std::vector
< ::boost::shared_ptr
<PaneGroup
> > maPaneGroups
;
94 css::uno::Reference
<css::drawing::framework::XResourceId
> mxCenterPaneId
;
96 EndActions maShowEndActions
;
97 EndActions maHideEndActions
;
99 void DeactivatePanes (void);
101 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
102 const geometry::RealRectangle2D
& rBox
);
103 void DeactivatePane (
104 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
);
108 class UnfoldInCenterAnimator
: public PresenterPaneAnimatorBase
111 UnfoldInCenterAnimator (
112 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
113 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
115 const EndActions
& rShowEndActions
,
116 const EndActions
& rEndEndActions
);
118 virtual ~UnfoldInCenterAnimator (void);
120 virtual void ShowPane (void);
122 virtual void HidePane (void);
125 geometry::RealRectangle2D maCenterPaneBox
;
127 void SetupPaneGroups (void);
128 geometry::RealRectangle2D
MovePanesAway (
129 const css::geometry::RealRectangle2D
& rFreeCenterArea
);
133 class MoveInFromBottomAnimator
: public PresenterPaneAnimatorBase
136 MoveInFromBottomAnimator(
137 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
138 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
140 const EndActions
& rShowEndActions
,
141 const EndActions
& rEndEndActions
);
142 virtual ~MoveInFromBottomAnimator (void);
144 virtual void ShowPane (void);
145 virtual void HidePane (void);
148 ::boost::shared_ptr
<PresenterSprite
> maNewPaneSprite
;
149 geometry::RealRectangle2D maCenterPaneBox
;
151 void CreateShowAnimation (
152 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
153 const EndOperators
& rpEndOperators
,
154 const css::uno::Reference
<css::rendering::XSpriteCanvas
>& rxSpriteCanvas
,
156 const css::geometry::RealPoint2D
& rStartLocation
,
157 const css::geometry::RealPoint2D
& rEndLocation
);
161 class TransparentOverlayAnimator
: public PresenterPaneAnimatorBase
164 TransparentOverlayAnimator(
165 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
166 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
168 const EndActions
& rShowEndActions
,
169 const EndActions
& rEndEndActions
);
170 virtual ~TransparentOverlayAnimator (void);
172 virtual void ShowPane (void);
173 virtual void HidePane (void);
176 PresenterSprite maBackgroundSprite
;
177 void CreateBackgroundSprite (void);
184 PresenterPaneContainer::SharedPaneDescriptor mpPaneDescriptor
;
186 PaneDescriptor (const PresenterPaneContainer::SharedPaneDescriptor
& rpDescriptor
);
187 void Restore (void) const;
195 class MultiAnimation
: public PresenterAnimation
198 typedef ::boost::function
<void(double)> Animation
;
199 MultiAnimation (const sal_uInt32 nDuration
);
200 void AddAnimation (const Animation
& rAnimation
);
201 virtual void Run (const double nProgress
, const sal_uInt64 nCurrentTime
);
203 vector
<Animation
> maAnimations
;
212 void AddPane (const PresenterPaneContainer::SharedPaneDescriptor
& rpPane
);
213 void CreateSubstitution (const Reference
<rendering::XSpriteCanvas
>& rxCanvas
);
214 void ThawPanes (void);
216 ::boost::shared_ptr
<PresenterSprite
> GetSubstitution (void);
217 css::geometry::RealRectangle2D
GetOriginalBoundingBox (void) const;
218 css::geometry::RealRectangle2D
GetCurrentBoundingBox (void) const;
220 const double nXOffset
,
221 const double nYOffset
,
222 const ::rtl::Reference
<PresenterWindowManager
>& rpWindowManager
);
223 void ActivatePanes (void);
224 void DeactivatePanes (void);
225 void HidePanes (void);
226 void ShowPanes (void);
229 vector
<PaneDescriptor
> maPanes
;
230 awt::Rectangle maOriginalBoundingBox
;
231 css::geometry::RealRectangle2D maCurrentBoundingBox
;
232 ::boost::shared_ptr
<PresenterSprite
> mpSubstitution
;
235 typedef ::boost::shared_ptr
<PaneGroup
> SharedPaneGroup
;
237 void InterpolatePosition (
238 const ::boost::function
<void(geometry::RealPoint2D
)>& rSetter
,
240 const geometry::RealPoint2D rInitialBox
,
241 const geometry::RealPoint2D rFinalBox
);
244 void InterpolateValue (
245 const ::boost::function
<void(T
)>& rSetter
,
247 const T aInitialValue
,
248 const T aFinalValue
);
250 void SpriteTransform(
251 const rtl::Reference
<PresenterPaneContainer
>& rpPaneContainer
,
252 const Reference
<XResourceId
>& rxPaneId
,
253 const Reference
<awt::XWindow
>& rxSpriteOwnerWindow
,
254 const ::boost::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
257 const double nInitialTop
,
258 const double nFinalTop
,
261 void SpritePaneMove (
262 const rtl::Reference
<PresenterPaneContainer
>& rpPaneContainer
,
263 const Reference
<XResourceId
>& rxPaneId
,
264 const geometry::RealPoint2D
& rLocation
);
266 geometry::RealPoint2D
GetLocation (const geometry::RealRectangle2D
& rBox
);
267 geometry::RealSize2D
GetSize (const geometry::RealRectangle2D
& rBox
);
270 } // end of anonymous namespace
275 //=============================================================================
278 ::boost::shared_ptr
<PresenterPaneAnimator
> CreateUnfoldInCenterAnimator (
279 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
280 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
282 const EndActions
& rShowEndActions
,
283 const EndActions
& rEndEndActions
)
285 return ::boost::shared_ptr
<PresenterPaneAnimator
>(
286 new UnfoldInCenterAnimator(rxPaneId
, rpPresenterController
, bAnimate
,
287 rShowEndActions
, rEndEndActions
));
293 ::boost::shared_ptr
<PresenterPaneAnimator
> CreateMoveInFromBottomAnimator (
294 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
295 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
297 const EndActions
& rShowEndActions
,
298 const EndActions
& rEndEndActions
)
300 return ::boost::shared_ptr
<PresenterPaneAnimator
>(
301 new MoveInFromBottomAnimator(rxPaneId
, rpPresenterController
, bAnimate
,
302 rShowEndActions
, rEndEndActions
));
308 ::boost::shared_ptr
<PresenterPaneAnimator
> CreateTransparentOverlay (
309 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
310 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
312 const EndActions
& rShowEndActions
,
313 const EndActions
& rEndEndActions
)
315 return ::boost::shared_ptr
<PresenterPaneAnimator
>(
316 new TransparentOverlayAnimator(rxPaneId
, rpPresenterController
, bAnimate
,
317 rShowEndActions
, rEndEndActions
));
323 //===== PresenterPaneAnimator =================================================
327 PresenterPaneAnimatorBase::PresenterPaneAnimatorBase (
328 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
329 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
331 const EndActions
& rShowEndActions
,
332 const EndActions
& rHideEndActions
)
333 : mpPresenterController(rpPresenterController
),
334 mpPaneContainer(rpPresenterController
->GetPaneContainer()),
335 mpWindowManager(rpPresenterController
->GetWindowManager()),
337 mxCenterPaneId(rxPaneId
),
338 mbDoAnimation(bAnimate
),
339 maShowEndActions(rShowEndActions
),
340 maHideEndActions(rHideEndActions
)
347 PresenterPaneAnimatorBase::~PresenterPaneAnimatorBase (void)
354 void PresenterPaneAnimatorBase::FreezePanes (const Reference
<rendering::XSpriteCanvas
>& rxCanvas
)
356 ::std::vector
<SharedPaneGroup
>::const_iterator iGroup
;
357 for (iGroup
=maPaneGroups
.begin(); iGroup
!=maPaneGroups
.end(); ++iGroup
)
359 (*iGroup
)->CreateSubstitution(rxCanvas
);
360 (*iGroup
)->GetSubstitution()->MoveTo(GetLocation((*iGroup
)->GetOriginalBoundingBox()));
367 void PresenterPaneAnimatorBase::ActivatePanes (void)
369 ActivatePane(mxCenterPaneId
);
371 ::std::vector
<SharedPaneGroup
>::const_iterator iGroup
;
372 for (iGroup
=maPaneGroups
.begin(); iGroup
!=maPaneGroups
.end(); ++iGroup
)
374 (*iGroup
)->ShowPanes();
375 (*iGroup
)->ActivatePanes();
376 (*iGroup
)->GetSubstitution()->Hide();
379 mpWindowManager
->Update();
385 void PresenterPaneAnimatorBase::DeactivatePanes (void)
387 ::std::vector
<SharedPaneGroup
>::const_iterator iGroup
;
388 for (iGroup
=maPaneGroups
.begin(); iGroup
!=maPaneGroups
.end(); ++iGroup
)
390 (*iGroup
)->GetSubstitution()->Show();
391 (*iGroup
)->DeactivatePanes();
392 (*iGroup
)->HidePanes();
395 mpWindowManager
->Update();
401 void PresenterPaneAnimatorBase::ResizePane (
402 const Reference
<drawing::framework::XResourceId
>& rxPaneId
,
403 const geometry::RealRectangle2D
& rBox
)
405 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
406 mpPaneContainer
->FindPaneId(rxPaneId
));
407 if (pDescriptor
.get() != NULL
)
409 mpWindowManager
->SetPanePosSizeAbsolute (
410 rxPaneId
->getResourceURL(),
415 mpWindowManager
->Layout();
416 if ( ! pDescriptor
->maSpriteProvider
.empty())
418 pDescriptor
->maSpriteProvider()->Resize(GetSize(rBox
));
426 void PresenterPaneAnimatorBase::RestoreFrozenWindows (void)
428 ::std::vector
<SharedPaneGroup
>::const_iterator iGroup
;
429 for (iGroup
=maPaneGroups
.begin(); iGroup
!=maPaneGroups
.end(); ++iGroup
)
431 (*iGroup
)->Restore();
432 (*iGroup
)->ShowPanes();
433 (*iGroup
)->ActivatePanes();
434 (*iGroup
)->GetSubstitution()->Hide();
436 maPaneGroups
.clear();
438 ActivatePane(mxCenterPaneId
);
440 mpWindowManager
->Update();
446 void PresenterPaneAnimatorBase::ActivatePane (
447 const Reference
<drawing::framework::XResourceId
>& rxPaneId
)
449 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
450 mpPaneContainer
->FindPaneId(rxPaneId
));
451 if (pDescriptor
.get() != NULL
)
452 pDescriptor
->SetActivationState(true);
458 void PresenterPaneAnimatorBase::DeactivatePane (
459 const Reference
<drawing::framework::XResourceId
>& rxPaneId
)
461 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
462 mpPaneContainer
->FindPaneId(rxPaneId
));
463 if (pDescriptor
.get() != NULL
)
464 pDescriptor
->SetActivationState(false);
470 //===== UnfoldInCenterAnimator ================================================
472 UnfoldInCenterAnimator::UnfoldInCenterAnimator (
473 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
474 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
476 const EndActions
& rShowEndActions
,
477 const EndActions
& rEndEndActions
)
478 : PresenterPaneAnimatorBase(rxPaneId
, rpPresenterController
, bAnimate
,
479 rShowEndActions
, rEndEndActions
)
486 UnfoldInCenterAnimator::~UnfoldInCenterAnimator (void)
493 void UnfoldInCenterAnimator::ShowPane (void)
495 OSL_ASSERT(mpWindowManager
.get()!=NULL
);
497 Reference
<awt::XWindow
> xParentWindow (mpWindowManager
->GetParentWindow(), UNO_QUERY
);
498 if ( ! xParentWindow
.is())
501 Reference
<rendering::XSpriteCanvas
> xCanvas (mpWindowManager
->GetParentCanvas(), UNO_QUERY
);
505 Reference
<rendering::XBitmap
> xParentBitmap (xCanvas
, UNO_QUERY
);
506 if ( ! xParentBitmap
.is())
509 Reference
<rendering::XGraphicDevice
> xDevice(xCanvas
->getDevice());
513 awt::Rectangle
aWindowBox (xParentWindow
->getPosSize());
515 // Create two pane groups that will be moved together. One contains the
516 // notes view, the other group contains all other panes.
519 // Setup the places where the two pane groups are moved to.
521 = MovePanesAway(geometry::RealRectangle2D(0,200,aWindowBox
.Width
, aWindowBox
.Height
-200));
523 // Setup the final size of the new pane so that it fits into the space
524 // between the two pane groups.
525 ResizePane(mxCenterPaneId
, maCenterPaneBox
);
527 // Avoid that the center pane updates its previews while being animated.
528 DeactivatePane(mxCenterPaneId
);
530 // Replace the pane groups with sprites that look like the panes but can
531 // be moved around much faster.
532 FreezePanes(xCanvas
);
534 // The vertical center of the new pane.
535 const double nY0 ((maPaneGroups
[0]->GetOriginalBoundingBox().Y2
536 + maPaneGroups
[1]->GetOriginalBoundingBox().Y1
) / 2);
538 // Make sure that the new pane is painted once before the animation starts.
543 mpPresenterController
->GetPaintManager(),
549 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
550 mpPaneContainer
->FindPaneId(mxCenterPaneId
));
551 if (pDescriptor
.get() != NULL
)
553 mpPresenterController
->GetPaintManager()->Invalidate(
554 pDescriptor
->mxBorderWindow
,
558 // Animate the upper and lower window bitmaps.
559 ::boost::shared_ptr
<MultiAnimation
> pMultiAnimation (
560 new MultiAnimation(mbDoAnimation
? 500 : 0));
562 // Animate the pane group sprites to be moved up or down.
563 vector
<SharedPaneGroup
>::const_iterator iGroup
;
564 for (iGroup
=maPaneGroups
.begin(); iGroup
!=maPaneGroups
.end(); ++iGroup
)
566 pMultiAnimation
->AddAnimation(
569 ::boost::protect(::boost::bind(
570 &PresenterSprite::MoveTo
, (*iGroup
)->GetSubstitution(), _1
)),
572 GetLocation((*iGroup
)->GetOriginalBoundingBox()),
573 GetLocation((*iGroup
)->GetCurrentBoundingBox())));
576 // Animate the new center pane to expand.
577 pMultiAnimation
->AddAnimation(
583 mpPresenterController
->GetPaintManager(),
590 // Call updateScreen after each animation step.
592 pMultiAnimation
->AddAnimation(
593 ::boost::bind(&rendering::XSpriteCanvas::updateScreen
, xCanvas
, sal_False
));
595 // Activate the panes when the animation is over.
596 pMultiAnimation
->AddEndCallback(
597 ::boost::bind(&PresenterPaneAnimatorBase::ActivatePanes
, shared_from_this()));
598 EndActions::const_iterator iAction
;
599 for (iAction
=maShowEndActions
.begin(); iAction
!=maShowEndActions
.end(); ++iAction
)
600 pMultiAnimation
->AddEndCallback(*iAction
);
602 // Start the animation.
603 ::boost::shared_ptr
<PresenterAnimator
> pAnimator (mpPresenterController
->GetAnimator());
604 OSL_ASSERT(pAnimator
.get()!=NULL
);
605 pAnimator
->AddAnimation(SharedPresenterAnimation(pMultiAnimation
));
607 mpWindowManager
->Update();
613 void UnfoldInCenterAnimator::HidePane (void)
615 OSL_ASSERT(mpWindowManager
.get()!=NULL
);
617 Reference
<awt::XWindow
> xParentWindow (mpWindowManager
->GetParentWindow(), UNO_QUERY
);
618 if ( ! xParentWindow
.is())
622 DeactivatePane(mxCenterPaneId
);
624 ::boost::shared_ptr
<PresenterAnimator
> pAnimator (mpPresenterController
->GetAnimator());
625 const awt::Rectangle
aWindowBox (xParentWindow
->getPosSize());
626 const rendering::ViewState
aViewState (
627 geometry::AffineMatrix2D(1,0,0, 0,1,0),
629 const rendering::RenderState
aRenderState (
630 geometry::AffineMatrix2D(1,0,0, 0,1,0),
633 rendering::CompositeOperation::SOURCE
);
635 // Animate the uppder and lower window bitmaps.
636 Reference
<rendering::XSpriteCanvas
> xSpriteCanvas (mpWindowManager
->GetParentCanvas(), UNO_QUERY
);
637 ::boost::shared_ptr
<MultiAnimation
> pMultiAnimation (new MultiAnimation(mbDoAnimation
? 500 : 1));
639 vector
<SharedPaneGroup
>::const_iterator iGroup
;
640 for (iGroup
=maPaneGroups
.begin(); iGroup
!=maPaneGroups
.end(); ++iGroup
)
642 pMultiAnimation
->AddAnimation(
645 ::boost::protect(::boost::bind(
646 &PresenterSprite::MoveTo
, (*iGroup
)->GetSubstitution(), _1
)),
648 GetLocation((*iGroup
)->GetCurrentBoundingBox()),
649 GetLocation((*iGroup
)->GetOriginalBoundingBox())));
652 // Animate the new center pane to collapse.
653 const double nY0 ((maPaneGroups
[0]->GetOriginalBoundingBox().Y2
654 + maPaneGroups
[1]->GetOriginalBoundingBox().Y1
) / 2);
655 pMultiAnimation
->AddAnimation(
661 mpPresenterController
->GetPaintManager(),
670 pMultiAnimation
->AddAnimation(
671 ::boost::bind(&rendering::XSpriteCanvas::updateScreen
, xSpriteCanvas
, sal_False
));
673 pMultiAnimation
->AddEndCallback(
674 ::boost::bind(&PresenterPaneAnimatorBase::RestoreFrozenWindows
, shared_from_this()));
675 EndActions::const_iterator iAction
;
676 for (iAction
=maHideEndActions
.begin(); iAction
!=maHideEndActions
.end(); ++iAction
)
677 pMultiAnimation
->AddEndCallback(*iAction
);
679 pAnimator
->AddAnimation(SharedPresenterAnimation(pMultiAnimation
));
685 void UnfoldInCenterAnimator::SetupPaneGroups (void)
687 maPaneGroups
.clear();
689 // Setup the upper pane group.
690 SharedPaneGroup
pUpperPanes (new PaneGroup());
691 pUpperPanes
->AddPane(mpPaneContainer
->FindPaneURL(
692 PresenterPaneFactory::msCurrentSlidePreviewPaneURL
));
693 pUpperPanes
->AddPane(mpPaneContainer
->FindPaneURL(
694 PresenterPaneFactory::msNextSlidePreviewPaneURL
));
695 pUpperPanes
->AddPane(mpPaneContainer
->FindPaneURL(
696 PresenterPaneFactory::msToolBarPaneURL
));
697 pUpperPanes
->AddPane(mpPaneContainer
->FindPaneURL(
698 PresenterPaneFactory::msHelpPaneURL
));
699 maPaneGroups
.push_back(pUpperPanes
);
701 // Setup the lower pane group.
702 SharedPaneGroup
pLowerPanes (new PaneGroup());
703 pLowerPanes
->AddPane(mpPaneContainer
->FindPaneURL(
704 PresenterPaneFactory::msNotesPaneURL
));
705 maPaneGroups
.push_back(pLowerPanes
);
711 geometry::RealRectangle2D
UnfoldInCenterAnimator::MovePanesAway (
712 const geometry::RealRectangle2D
& rFreeCenterArea
)
714 SharedPaneGroup aUpperPanes
= maPaneGroups
[0];
715 SharedPaneGroup aLowerPanes
= maPaneGroups
[1];
717 // Move upper pane group out of the way.
718 const double nTop (rFreeCenterArea
.Y1
);
719 const double nUpperVerticalOffset (nTop
- aUpperPanes
->GetOriginalBoundingBox().Y2
);
720 aUpperPanes
->MovePanes(0, nUpperVerticalOffset
, mpWindowManager
);
722 // Move lower pane group out of the way.
723 const double nBottom (rFreeCenterArea
.Y2
);
724 const double nLowerVerticalOffset (nBottom
- aLowerPanes
->GetOriginalBoundingBox().Y1
);
725 aLowerPanes
->MovePanes(0, nLowerVerticalOffset
, mpWindowManager
);
727 return geometry::RealRectangle2D(
729 aUpperPanes
->GetOriginalBoundingBox().X1
,
730 aLowerPanes
->GetOriginalBoundingBox().X1
),
733 aUpperPanes
->GetOriginalBoundingBox().X2
,
734 aLowerPanes
->GetOriginalBoundingBox().X2
),
741 //===== MoveInFromBottomAnimator ==============================================
743 MoveInFromBottomAnimator::MoveInFromBottomAnimator (
744 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
745 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
747 const EndActions
& rShowEndActions
,
748 const EndActions
& rEndEndActions
)
749 : PresenterPaneAnimatorBase(rxPaneId
, rpPresenterController
, bAnimate
,
750 rShowEndActions
, rEndEndActions
),
758 MoveInFromBottomAnimator::~MoveInFromBottomAnimator (void)
765 void MoveInFromBottomAnimator::ShowPane (void)
767 OSL_ASSERT(mpWindowManager
.get()!=NULL
);
769 Reference
<awt::XWindow
> xParentWindow (mpWindowManager
->GetParentWindow(), UNO_QUERY
);
770 if ( ! xParentWindow
.is())
773 Reference
<rendering::XSpriteCanvas
> xCanvas (mpWindowManager
->GetParentCanvas(), UNO_QUERY
);
777 Reference
<rendering::XBitmap
> xParentBitmap (xCanvas
, UNO_QUERY
);
778 if ( ! xParentBitmap
.is())
781 Reference
<rendering::XGraphicDevice
> xDevice(xCanvas
->getDevice());
785 awt::Rectangle
aWindowBox (xParentWindow
->getPosSize());
787 // Create a pane group that just contains the notes view.
788 SharedPaneGroup
pLowerPanes (new PaneGroup());
789 pLowerPanes
->AddPane(mpPaneContainer
->FindPaneURL(
790 PresenterPaneFactory::msNotesPaneURL
));
791 maPaneGroups
.push_back(pLowerPanes
);
793 // Deactivate the panes that will take place in the animation.
794 pLowerPanes
->DeactivatePanes();
795 DeactivatePane(mxCenterPaneId
);
797 // Set the size of the new pane.
798 maCenterPaneBox
= pLowerPanes
->GetOriginalBoundingBox();
799 ResizePane(mxCenterPaneId
, maCenterPaneBox
);
801 geometry::RealPoint2D
aStartLocation (maCenterPaneBox
.X1
, aWindowBox
.Height
);
802 geometry::RealPoint2D
aEndLocation (maCenterPaneBox
.X1
, maCenterPaneBox
.Y1
);
804 // Get the sprite of the new pane, make it visible and move it to the
806 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
807 mpPaneContainer
->FindPaneId(mxCenterPaneId
));
808 if (pDescriptor
.get() != NULL
)
810 if (pDescriptor
->mxBorderWindow
.is())
811 pDescriptor
->mxBorderWindow
->setVisible(sal_True
);
813 maNewPaneSprite
= pDescriptor
->maSpriteProvider();
814 if (maNewPaneSprite
.get() != NULL
)
816 maNewPaneSprite
->MoveTo(aStartLocation
);
817 maNewPaneSprite
->Show();
819 xCanvas
->updateScreen(sal_False
);
830 mpWindowManager
->Update();
836 void MoveInFromBottomAnimator::HidePane (void)
838 OSL_ASSERT(mpWindowManager
.get()!=NULL
);
840 Reference
<awt::XWindow
> xParentWindow (mpWindowManager
->GetParentWindow(), UNO_QUERY
);
841 if ( ! xParentWindow
.is())
844 Reference
<rendering::XSpriteCanvas
> xCanvas (mpWindowManager
->GetParentCanvas(), UNO_QUERY
);
849 DeactivatePane(mxCenterPaneId
);
851 SharedPaneGroup
aPanes (maPaneGroups
[0]);
855 ::boost::shared_ptr
<MultiAnimation
> pMultiAnimation (
856 new MultiAnimation(mbDoAnimation
? 500 : 0));
857 awt::Rectangle
aWindowBox (xParentWindow
->getPosSize());
859 // Animate the new center pane to collapse.
860 pMultiAnimation
->AddAnimation(
863 ::boost::protect(::boost::bind(&SpritePaneMove
, mpPaneContainer
, mxCenterPaneId
, _1
)),
865 geometry::RealPoint2D(maCenterPaneBox
.X1
, maCenterPaneBox
.Y1
),
866 geometry::RealPoint2D(maCenterPaneBox
.X1
, aWindowBox
.Height
)));
870 pMultiAnimation
->AddAnimation(
871 ::boost::bind(&rendering::XSpriteCanvas::updateScreen
, xCanvas
, sal_False
));
873 pMultiAnimation
->AddEndCallback(
874 ::boost::bind(&PresenterPaneAnimatorBase::RestoreFrozenWindows
, shared_from_this()));
875 EndActions::const_iterator iAction
;
876 for (iAction
=maHideEndActions
.begin(); iAction
!=maHideEndActions
.end(); ++iAction
)
877 pMultiAnimation
->AddEndCallback(*iAction
);
879 ::boost::shared_ptr
<PresenterAnimator
> pAnimator (mpPresenterController
->GetAnimator());
880 pAnimator
->AddAnimation(SharedPresenterAnimation(pMultiAnimation
));
886 void MoveInFromBottomAnimator::CreateShowAnimation (
887 const Reference
<drawing::framework::XResourceId
>& rxPaneId
,
888 const EndOperators
& rEndOperators
,
889 const Reference
<rendering::XSpriteCanvas
>& rxSpriteCanvas
,
891 const geometry::RealPoint2D
& rStartLocation
,
892 const geometry::RealPoint2D
& rEndLocation
)
894 // Animate the uppder and lower window bitmaps.
895 ::boost::shared_ptr
<MultiAnimation
> pMultiAnimation (new MultiAnimation(bAnimate
? 500 : 0));
897 // Animate new pane to move in from the buttom.
898 pMultiAnimation
->AddAnimation(
901 ::boost::protect(::boost::bind(&SpritePaneMove
, mpPaneContainer
, rxPaneId
, _1
)),
906 // Call updateScreen after each animation step.
907 if (rxSpriteCanvas
.is())
908 pMultiAnimation
->AddAnimation(
909 ::boost::bind(&rendering::XSpriteCanvas::updateScreen
, rxSpriteCanvas
, sal_False
));
911 // Activate the panes when the animation is over.
912 pMultiAnimation
->AddEndCallback(
913 ::boost::bind(&PaneGroup::HidePanes
, maPaneGroups
[0]));
914 pMultiAnimation
->AddEndCallback(
915 ::boost::bind(&PresenterPaneAnimatorBase::ActivatePane
, shared_from_this(), mxCenterPaneId
));
916 EndActions::const_iterator iAction
;
917 for (iAction
=rEndOperators
.begin(); iAction
!=rEndOperators
.end(); ++iAction
)
918 pMultiAnimation
->AddEndCallback(*iAction
);
920 // Start the animation.
921 ::boost::shared_ptr
<PresenterAnimator
> pAnimator (mpPresenterController
->GetAnimator());
922 OSL_ASSERT(pAnimator
.get()!=NULL
);
923 pAnimator
->AddAnimation(SharedPresenterAnimation(pMultiAnimation
));
930 //===== TransparentOverlayAnimator ============================================
932 TransparentOverlayAnimator::TransparentOverlayAnimator (
933 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneId
,
934 const ::rtl::Reference
<PresenterController
>& rpPresenterController
,
936 const EndActions
& rShowEndActions
,
937 const EndActions
& rEndEndActions
)
938 : PresenterPaneAnimatorBase(
940 rpPresenterController
,
951 TransparentOverlayAnimator::~TransparentOverlayAnimator (void)
958 void TransparentOverlayAnimator::ShowPane (void)
960 EndActions::const_iterator iAction
;
961 for (iAction
=maShowEndActions
.begin(); iAction
!=maShowEndActions
.end(); ++iAction
)
964 CreateBackgroundSprite();
966 Reference
<awt::XWindow
> xParentWindow (mpWindowManager
->GetParentWindow(), UNO_QUERY
);
967 if (xParentWindow
.is())
969 const awt::Rectangle
aWindowBox (xParentWindow
->getPosSize());
970 SharedPaneGroup
pAllPanes (new PaneGroup());
971 pAllPanes
->AddPane(mpPaneContainer
->FindPaneURL(
972 PresenterPaneFactory::msCurrentSlidePreviewPaneURL
));
973 pAllPanes
->AddPane(mpPaneContainer
->FindPaneURL(
974 PresenterPaneFactory::msNextSlidePreviewPaneURL
));
975 pAllPanes
->AddPane(mpPaneContainer
->FindPaneURL(
976 PresenterPaneFactory::msToolBarPaneURL
));
977 pAllPanes
->AddPane(mpPaneContainer
->FindPaneURL(
978 PresenterPaneFactory::msHelpPaneURL
));
979 pAllPanes
->AddPane(mpPaneContainer
->FindPaneURL(
980 PresenterPaneFactory::msNotesPaneURL
));
981 maPaneGroups
.push_back(pAllPanes
);
982 pAllPanes
->DeactivatePanes();
983 mpWindowManager
->Update();
986 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
987 mpPaneContainer
->FindPaneId(mxCenterPaneId
));
988 if (pDescriptor
.get() != NULL
)
990 PresenterSpritePane
* pPane
= dynamic_cast<PresenterSpritePane
*>(
991 pDescriptor
->mxPane
.get());
993 pPane
->ShowTransparentBorder();
995 pDescriptor
->SetActivationState(true);
996 if (pDescriptor
->mxBorderWindow
.is())
997 pDescriptor
->mxBorderWindow
->setVisible(sal_True
);
1004 void TransparentOverlayAnimator::HidePane (void)
1006 maPaneGroups
[0]->ActivatePanes();
1007 EndActions::const_iterator iAction
;
1008 for (iAction
=maHideEndActions
.begin(); iAction
!=maHideEndActions
.end(); ++iAction
)
1010 mpWindowManager
->Update();
1016 void TransparentOverlayAnimator::CreateBackgroundSprite (void)
1018 Reference
<awt::XWindow
> xParentWindow (mpWindowManager
->GetParentWindow(), UNO_QUERY
);
1019 Reference
<rendering::XSpriteCanvas
> xParentCanvas (mpWindowManager
->GetParentCanvas(), UNO_QUERY
);
1020 if (xParentWindow
.is() && xParentCanvas
.is())
1022 const awt::Rectangle
aWindowBox (xParentWindow
->getPosSize());
1023 maBackgroundSprite
.SetFactory(xParentCanvas
);
1024 maBackgroundSprite
.Resize(
1025 geometry::RealSize2D(aWindowBox
.Width
, aWindowBox
.Height
));
1026 maBackgroundSprite
.MoveTo(
1027 geometry::RealPoint2D(aWindowBox
.X
, aWindowBox
.Y
));
1028 maBackgroundSprite
.SetAlpha(0.5);
1029 maBackgroundSprite
.Show();
1031 Reference
<rendering::XCanvas
> xCanvas (maBackgroundSprite
.GetCanvas());
1035 rendering::ViewState
aViewState(
1036 geometry::AffineMatrix2D(1,0,0, 0,1,0),
1039 rendering::RenderState
aRenderState(
1040 geometry::AffineMatrix2D(1,0,0, 0,1,0),
1042 Sequence
<double>(4),
1043 rendering::CompositeOperation::SOURCE
);
1044 PresenterCanvasHelper::SetDeviceColor(aRenderState
, util::Color(0x80808080));
1046 Reference
<rendering::XPolyPolygon2D
> xPolygon (
1047 PresenterGeometryHelper::CreatePolygon(aWindowBox
, xCanvas
->getDevice()));
1049 xCanvas
->fillPolyPolygon(
1060 //===== PaneGroup =============================================================
1062 PaneGroup::PaneGroup (void)
1064 maOriginalBoundingBox(),
1065 maCurrentBoundingBox(),
1066 mpSubstitution(new PresenterSprite())
1073 PaneGroup::~PaneGroup (void)
1075 mpSubstitution
.reset();
1081 void PaneGroup::AddPane (const PresenterPaneContainer::SharedPaneDescriptor
& rpPane
)
1083 OSL_ASSERT(rpPane
.get() != NULL
);
1085 if (rpPane
->mxBorderWindow
.is())
1087 PaneDescriptor
aDescriptor (rpPane
);
1088 maPanes
.push_back(aDescriptor
);
1089 maOriginalBoundingBox
= PresenterGeometryHelper::Union(
1090 maOriginalBoundingBox
,
1091 rpPane
->mxBorderWindow
->getPosSize());
1098 void PaneGroup::CreateSubstitution (const Reference
<rendering::XSpriteCanvas
>& rxCanvas
)
1100 // Get the bitmap of the background.
1101 Reference
<rendering::XBitmap
> xBackgroundBitmap (rxCanvas
, UNO_QUERY
);
1102 if ( ! xBackgroundBitmap
.is())
1105 // Create the sprite.
1106 mpSubstitution
->SetFactory(rxCanvas
);
1107 mpSubstitution
->Resize(
1108 geometry::RealSize2D(maOriginalBoundingBox
.Width
, maOriginalBoundingBox
.Height
));
1110 // Fill it with the background inside the bounding box.
1111 const rendering::ViewState
aViewState (
1112 geometry::AffineMatrix2D(1,0,0, 0,1,0),
1114 const rendering::RenderState
aRenderState (
1115 geometry::AffineMatrix2D(1,0,-maOriginalBoundingBox
.X
, 0,1,-maOriginalBoundingBox
.Y
),
1117 Sequence
<double>(4),
1118 rendering::CompositeOperation::SOURCE
);
1120 Reference
<rendering::XCanvas
> xSpriteCanvas (mpSubstitution
->GetCanvas());
1121 if (xSpriteCanvas
.is())
1122 xSpriteCanvas
->drawBitmap(xBackgroundBitmap
, aViewState
, aRenderState
);
1128 void PaneGroup::Restore (void)
1130 vector
<PaneDescriptor
>::iterator iPane
;
1131 for (iPane
=maPanes
.begin(); iPane
!=maPanes
.end(); ++iPane
)
1140 ::boost::shared_ptr
<PresenterSprite
> PaneGroup::GetSubstitution (void)
1142 return mpSubstitution
;
1148 geometry::RealRectangle2D
PaneGroup::GetOriginalBoundingBox (void) const
1150 return geometry::RealRectangle2D(
1151 maOriginalBoundingBox
.X
,
1152 maOriginalBoundingBox
.Y
,
1153 maOriginalBoundingBox
.X
+ maOriginalBoundingBox
.Width
,
1154 maOriginalBoundingBox
.Y
+ maOriginalBoundingBox
.Height
);
1160 geometry::RealRectangle2D
PaneGroup::GetCurrentBoundingBox (void) const
1162 return maCurrentBoundingBox
;
1168 void PaneGroup::MovePanes (
1169 const double nXOffset
,
1170 const double nYOffset
,
1171 const ::rtl::Reference
<PresenterWindowManager
>& rpWindowManager
1174 awt::Rectangle aBBox
;
1175 vector
<PaneDescriptor
>::iterator iPane
;
1176 for (iPane
=maPanes
.begin(); iPane
!=maPanes
.end(); ++iPane
)
1178 awt::Rectangle
aBox (iPane
->mpPaneDescriptor
->mxBorderWindow
->getPosSize());
1179 aBox
.X
+= sal_Int32(nXOffset
);
1180 aBox
.Y
+= sal_Int32(nYOffset
);
1181 rpWindowManager
->SetPanePosSizeAbsolute(
1182 iPane
->mpPaneDescriptor
->mxPaneId
->getResourceURL(),
1187 aBBox
= PresenterGeometryHelper::Union(aBBox
, aBox
);
1189 maCurrentBoundingBox
= geometry::RealRectangle2D(
1190 aBBox
.X
, aBBox
.Y
, aBBox
.X
+aBBox
.Width
, aBBox
.Y
+aBBox
.Height
);
1196 void PaneGroup::ActivatePanes (void)
1198 vector
<PaneDescriptor
>::iterator iPane
;
1199 for (iPane
=maPanes
.begin(); iPane
!=maPanes
.end(); ++iPane
)
1201 iPane
->mpPaneDescriptor
->SetActivationState(true);
1208 void PaneGroup::DeactivatePanes (void)
1210 vector
<PaneDescriptor
>::iterator iPane
;
1211 for (iPane
=maPanes
.begin(); iPane
!=maPanes
.end(); ++iPane
)
1213 iPane
->mpPaneDescriptor
->SetActivationState(false);
1220 void PaneGroup::ShowPanes (void)
1222 vector
<PaneDescriptor
>::iterator iPane
;
1223 for (iPane
=maPanes
.begin(); iPane
!=maPanes
.end(); ++iPane
)
1225 iPane
->mpPaneDescriptor
->mxBorderWindow
->setVisible(sal_True
);
1226 iPane
->mpPaneDescriptor
->mxContentWindow
->setVisible(sal_True
);
1233 void PaneGroup::HidePanes (void)
1235 vector
<PaneDescriptor
>::iterator iPane
;
1236 for (iPane
=maPanes
.begin(); iPane
!=maPanes
.end(); ++iPane
)
1238 iPane
->mpPaneDescriptor
->mxBorderWindow
->setVisible(sal_False
);
1239 iPane
->mpPaneDescriptor
->mxContentWindow
->setVisible(sal_False
);
1246 //===== PaneDescriptor ========================================================
1248 PaneDescriptor::PaneDescriptor (const PresenterPaneContainer::SharedPaneDescriptor
& rpDescriptor
)
1249 : mpPaneDescriptor(rpDescriptor
),
1250 mnLeft(rpDescriptor
->mnLeft
),
1251 mnTop(rpDescriptor
->mnTop
),
1252 mnRight(rpDescriptor
->mnRight
),
1253 mnBottom(rpDescriptor
->mnBottom
)
1260 void PaneDescriptor::Restore (void) const
1262 mpPaneDescriptor
->mnLeft
= mnLeft
;
1263 mpPaneDescriptor
->mnTop
= mnTop
;
1264 mpPaneDescriptor
->mnRight
= mnRight
;
1265 mpPaneDescriptor
->mnBottom
= mnBottom
;
1271 //===== MultiAnimation ========================================================
1273 MultiAnimation::MultiAnimation (const sal_uInt32 nDuration
)
1274 : PresenterAnimation(0, nDuration
, 1000/50),
1282 void MultiAnimation::AddAnimation (const Animation
& rAnimation
)
1284 maAnimations
.push_back(rAnimation
);
1290 void MultiAnimation::Run (const double nProgress
, const sal_uInt64 nCurrentTime
)
1293 vector
<Animation
>::const_iterator
iAnimation (maAnimations
.begin());
1294 vector
<Animation
>::const_iterator
iEnd (maAnimations
.end());
1295 for ( ; iAnimation
!=iEnd
; ++iAnimation
)
1296 (*iAnimation
)(nProgress
);
1302 //===== functors ==============================================================
1304 void InterpolatePosition (
1305 const ::boost::function
<void(geometry::RealPoint2D
)>& rSetter
,
1307 const geometry::RealPoint2D rInitialBox
,
1308 const geometry::RealPoint2D rFinalBox
)
1310 const double nQ (1 - nP
);
1312 OSL_TRACE("InterpolatePosition %f\n", nP
);
1314 geometry::RealPoint2D(
1315 nQ
* rInitialBox
.X
+ nP
* rFinalBox
.X
,
1316 nQ
* rInitialBox
.Y
+ nP
* rFinalBox
.Y
));
1322 template<typename T
>
1323 void InterpolateValue (
1324 const ::boost::function
<void(T
)>& rSetter
,
1326 const T aInitialValue
,
1327 const T aFinalValue
)
1329 const double nQ (1 - nP
);
1331 rSetter(T(nQ
* aInitialValue
+ nP
* aFinalValue
));
1337 void SpriteTransform(
1338 const rtl::Reference
<PresenterPaneContainer
>& rpPaneContainer
,
1339 const Reference
<XResourceId
>& rxPaneId
,
1340 const Reference
<awt::XWindow
>& rxSpriteOwnerWindow
,
1341 const ::boost::shared_ptr
<PresenterPaintManager
>& rpPaintManager
,
1344 const double nInitialTop
,
1345 const double nFinalTop
,
1348 OSL_ASSERT(rpPaintManager
.get()!=NULL
);
1350 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
1351 rpPaneContainer
->FindPaneId(rxPaneId
));
1352 if (pDescriptor
.get() != NULL
1353 && ! pDescriptor
->maSpriteProvider
.empty()
1354 && pDescriptor
->mxBorderWindow
.is())
1356 ::boost::shared_ptr
<PresenterSprite
> pSprite (pDescriptor
->maSpriteProvider());
1359 // There seems to be a problem with sprites not correctly
1360 // invalidating the background when being transformed. As a
1361 // workaround invalidate the background in the bounding box of
1362 // the sprite before the transformation.
1363 rpPaintManager
->Invalidate(
1364 rxSpriteOwnerWindow
,
1366 sal::static_int_cast
<sal_Int32
>(pSprite
->GetLocation().X
),
1367 sal::static_int_cast
<sal_Int32
>(pSprite
->GetLocation().Y
),
1368 sal::static_int_cast
<sal_Int32
>(pSprite
->GetSize().Width
),
1369 sal::static_int_cast
<sal_Int32
>(pSprite
->GetSize().Height
)));
1371 const double nYScale (bAppear
? nP
: 1-nP
);
1372 pSprite
->Transform(geometry::AffineMatrix2D(
1376 geometry::RealPoint2D(nX
, nYScale
*nFinalTop
+ (1-nYScale
)*nInitialTop
));
1379 pDescriptor
->mxBorderWindow
->setVisible(sal_True
);
1387 void SpritePaneMove (
1388 const rtl::Reference
<PresenterPaneContainer
>& rpPaneContainer
,
1389 const Reference
<XResourceId
>& rxPaneId
,
1390 const geometry::RealPoint2D
& rLocation
)
1392 PresenterPaneContainer::SharedPaneDescriptor
pDescriptor (
1393 rpPaneContainer
->FindPaneId(rxPaneId
));
1394 if (pDescriptor
.get() != NULL
1395 && ! pDescriptor
->maSpriteProvider
.empty()
1396 && pDescriptor
->mxBorderWindow
.is())
1398 ::boost::shared_ptr
<PresenterSprite
> pSprite (pDescriptor
->maSpriteProvider());
1399 if (pSprite
.get() != NULL
)
1401 pDescriptor
->mxBorderWindow
->setVisible(sal_True
);
1402 pSprite
->MoveTo(rLocation
);
1410 geometry::RealPoint2D
GetLocation (const geometry::RealRectangle2D
& rBox
)
1412 return geometry::RealPoint2D(rBox
.X1
, rBox
.Y1
);
1418 geometry::RealSize2D
GetSize (const geometry::RealRectangle2D
& rBox
)
1420 return geometry::RealSize2D(rBox
.X2
-rBox
.X1
, rBox
.Y2
-rBox
.Y1
);
1423 } // end of anonymous namespace
1428 } } // end of namespace ::sdext::presenter