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