1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_TRANSITIONS_SLIDECHANGEBASE_HXX
29*cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_TRANSITIONS_SLIDECHANGEBASE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <osl/mutex.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "unoview.hxx"
34*cdf0e10cSrcweir #include "vieweventhandler.hxx"
35*cdf0e10cSrcweir #include "numberanimation.hxx"
36*cdf0e10cSrcweir #include "slide.hxx"
37*cdf0e10cSrcweir #include "screenupdater.hxx"
38*cdf0e10cSrcweir #include "soundplayer.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <boost/enable_shared_from_this.hpp>
41*cdf0e10cSrcweir #include <boost/noncopyable.hpp>
42*cdf0e10cSrcweir #include <boost/optional.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace cppcanvas
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir     class Canvas;
47*cdf0e10cSrcweir     class CustomSprite;
48*cdf0e10cSrcweir }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace slideshow {
51*cdf0e10cSrcweir namespace internal {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir /** Base class for all slide change effects.
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     This class provides the basic sprite and view handling
56*cdf0e10cSrcweir     functionality.  Derived classes should normally only need to
57*cdf0e10cSrcweir     implement the perform() method.
58*cdf0e10cSrcweir */
59*cdf0e10cSrcweir class SlideChangeBase : public ViewEventHandler,
60*cdf0e10cSrcweir                         public NumberAnimation,
61*cdf0e10cSrcweir                         public boost::enable_shared_from_this<SlideChangeBase>,
62*cdf0e10cSrcweir                         private ::boost::noncopyable
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir public:
65*cdf0e10cSrcweir     // NumberAnimation
66*cdf0e10cSrcweir     virtual bool operator()( double x );
67*cdf0e10cSrcweir     virtual double getUnderlyingValue() const;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     // Animation
70*cdf0e10cSrcweir     virtual void prefetch( const AnimatableShapeSharedPtr&,
71*cdf0e10cSrcweir                            const ShapeAttributeLayerSharedPtr& );
72*cdf0e10cSrcweir     virtual void start( const AnimatableShapeSharedPtr&,
73*cdf0e10cSrcweir                         const ShapeAttributeLayerSharedPtr& );
74*cdf0e10cSrcweir     virtual void end();
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     // ViewEventHandler
77*cdf0e10cSrcweir     virtual void viewAdded( const UnoViewSharedPtr& rView );
78*cdf0e10cSrcweir     virtual void viewRemoved( const UnoViewSharedPtr& rView );
79*cdf0e10cSrcweir     virtual void viewChanged( const UnoViewSharedPtr& rView );
80*cdf0e10cSrcweir     virtual void viewsChanged();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir protected:
83*cdf0e10cSrcweir     /** Create a new SlideChanger, for the given leaving and
84*cdf0e10cSrcweir         entering slides.
85*cdf0e10cSrcweir     */
86*cdf0e10cSrcweir     SlideChangeBase(
87*cdf0e10cSrcweir         ::boost::optional<SlideSharedPtr> const & leavingSlide,
88*cdf0e10cSrcweir         const SlideSharedPtr&                     pEnteringSlide,
89*cdf0e10cSrcweir         const SoundPlayerSharedPtr&               pSoundPlayer,
90*cdf0e10cSrcweir         const UnoViewContainer&                   rViewContainer,
91*cdf0e10cSrcweir         ScreenUpdater&                            rScreenUpdater,
92*cdf0e10cSrcweir         EventMultiplexer&                         rEventMultiplexer,
93*cdf0e10cSrcweir         bool                                      bCreateLeavingSprites = true,
94*cdf0e10cSrcweir         bool                                      bCreateEnteringSprites = true );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     /// Info on a per-view basis
97*cdf0e10cSrcweir     struct ViewEntry
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         ViewEntry() {}
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir         explicit ViewEntry( const UnoViewSharedPtr& rView ) :
102*cdf0e10cSrcweir             mpView( rView )
103*cdf0e10cSrcweir         {
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         /// The view this entry is for
107*cdf0e10cSrcweir         UnoViewSharedPtr                              mpView;
108*cdf0e10cSrcweir         /// outgoing slide sprite
109*cdf0e10cSrcweir         boost::shared_ptr<cppcanvas::CustomSprite>    mpOutSprite;
110*cdf0e10cSrcweir         /// incoming slide sprite
111*cdf0e10cSrcweir         boost::shared_ptr<cppcanvas::CustomSprite>    mpInSprite;
112*cdf0e10cSrcweir         /// outgoing slide bitmap
113*cdf0e10cSrcweir         mutable SlideBitmapSharedPtr                  mpLeavingBitmap;
114*cdf0e10cSrcweir         /// incoming slide bitmap
115*cdf0e10cSrcweir         mutable SlideBitmapSharedPtr                  mpEnteringBitmap;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         // for algo access
118*cdf0e10cSrcweir         const UnoViewSharedPtr& getView() const { return mpView; }
119*cdf0e10cSrcweir     };
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     typedef ::std::vector<ViewEntry> ViewsVecT;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     ViewsVecT::const_iterator beginViews() { return maViewData.begin(); }
124*cdf0e10cSrcweir     ViewsVecT::const_iterator endViews() { return maViewData.end(); }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     SlideBitmapSharedPtr getLeavingBitmap( const ViewEntry& rViewEntry ) const;
127*cdf0e10cSrcweir     SlideBitmapSharedPtr getEnteringBitmap( const ViewEntry& rViewEntry ) const;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     SlideBitmapSharedPtr createBitmap( const UnoViewSharedPtr&                pView,
130*cdf0e10cSrcweir                                        const boost::optional<SlideSharedPtr>& rSlide_ ) const;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     ::basegfx::B2ISize getEnteringSlideSizePixel( const UnoViewSharedPtr& pView ) const;
133*cdf0e10cSrcweir     ::basegfx::B2ISize getLeavingSlideSizePixel( const UnoViewSharedPtr& pView ) const;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     void renderBitmap( SlideBitmapSharedPtr const&                 pSlideBitmap,
136*cdf0e10cSrcweir                        boost::shared_ptr<cppcanvas::Canvas> const& pCanvas );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     /** Called on derived classes to implement actual slide change.
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         This method is called with the sprite of the slide coming 'in'
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         @param rSprite
143*cdf0e10cSrcweir         Current sprite to operate on. This is the sprite of the
144*cdf0e10cSrcweir         'entering' slide
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         @param t
147*cdf0e10cSrcweir         Current parameter value
148*cdf0e10cSrcweir     */
149*cdf0e10cSrcweir     virtual void performIn(
150*cdf0e10cSrcweir         const boost::shared_ptr<cppcanvas::CustomSprite>&   rSprite,
151*cdf0e10cSrcweir         const ViewEntry&                                    rViewEntry,
152*cdf0e10cSrcweir         const boost::shared_ptr<cppcanvas::Canvas>&         rDestinationCanvas,
153*cdf0e10cSrcweir         double                                              t );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     /** Called on derived classes to implement actual slide change.
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir         This method is called with the sprite of the slide moving 'out'
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         @param rSprite
160*cdf0e10cSrcweir         Current sprite to operate on. This is the sprite of the
161*cdf0e10cSrcweir         'leaving' slide
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir         @param t
164*cdf0e10cSrcweir         Current parameter value
165*cdf0e10cSrcweir     */
166*cdf0e10cSrcweir     virtual void performOut(
167*cdf0e10cSrcweir         const boost::shared_ptr<cppcanvas::CustomSprite>& rSprite,
168*cdf0e10cSrcweir         const ViewEntry&                                  rViewEntry,
169*cdf0e10cSrcweir         const boost::shared_ptr<cppcanvas::Canvas>&       rDestinationCanvas,
170*cdf0e10cSrcweir         double                                            t );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     ScreenUpdater& getScreenUpdater() const { return mrScreenUpdater; }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir private:
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     boost::shared_ptr<cppcanvas::CustomSprite> createSprite(
177*cdf0e10cSrcweir         UnoViewSharedPtr const &   pView,
178*cdf0e10cSrcweir         ::basegfx::B2DSize const & rSpriteSize,
179*cdf0e10cSrcweir         double                     nPrio ) const;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     void addSprites( ViewEntry& rEntry );
182*cdf0e10cSrcweir     void clearViewEntry( ViewEntry& rEntry );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     ViewsVecT::iterator lookupView( UnoViewSharedPtr const & pView );
185*cdf0e10cSrcweir     ViewsVecT::const_iterator lookupView( UnoViewSharedPtr const & pView ) const;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     SoundPlayerSharedPtr                mpSoundPlayer;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     EventMultiplexer&                   mrEventMultiplexer;
190*cdf0e10cSrcweir     ScreenUpdater&                      mrScreenUpdater;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     ::boost::optional<SlideSharedPtr>   maLeavingSlide;
193*cdf0e10cSrcweir     SlideSharedPtr                      mpEnteringSlide;
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     ViewsVecT                           maViewData;
196*cdf0e10cSrcweir     const UnoViewContainer&             mrViewContainer;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     const bool                          mbCreateLeavingSprites;
199*cdf0e10cSrcweir     const bool                          mbCreateEnteringSprites;
200*cdf0e10cSrcweir     bool                                mbSpritesVisible;
201*cdf0e10cSrcweir     bool                                mbFinished;
202*cdf0e10cSrcweir     bool                                mbPrefetched;
203*cdf0e10cSrcweir };
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir } // namespace internal
206*cdf0e10cSrcweir } // namespace presentation
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_TRANSITIONS_SLIDECHANGEBASE_HXX */
209