summaryrefslogtreecommitdiff
path: root/slideshow/source/inc/slide.hxx
blob: 1c48c5c49ff1701a9c97f162ee37a7aedb6f4390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: slide.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2005-10-11 08:54:29 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SLIDESHOW_SLIDE_HXX
#define _SLIDESHOW_SLIDE_HXX

#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HXX_
#include <com/sun/star/uno/XComponentContext.hpp>
#endif
#ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGE_HPP_
#include <com/sun/star/drawing/XDrawPage.hpp>
#endif

#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
#include <boost/shared_ptr.hpp>
#endif

#ifndef _CPPCANVAS_SPRITECANVAS_HXX
#include <cppcanvas/spritecanvas.hxx>
#endif

#ifndef _BGFX_VECTOR_B2ISIZE_HXX
#include <basegfx/vector/b2isize.hxx>
#endif

#include <vector>
#include <utility>

#include <unoview.hxx>
#include <event.hxx>
#include <layermanager.hxx>
#include <userpaintoverlay.hxx>
#include <slideanimations.hxx>
#include <slidebitmap.hxx>
#include <shapeeventbroadcaster.hxx>
#include "boost/optional.hpp"

/* Definition of Slide class */

namespace presentation
{
    namespace internal
    {
        class EventQueue;
        class ActivitiesQueue;
        class UserEventQueue;

        class Slide
        {
        public:
            /** Construct from XDrawPage

                Prefetches shapes from draw page, thus might take some
                time. The Slide object generally works in XDrawPage
                model coordinates, that is, the page will have the
                width and height as specified in the XDrawPage's
                property set. The top, left corner of the page will be
                rendered at (0,0) in the given canvas' view coordinate
                system.
             */
            Slide( const ::com::sun::star::uno::Reference<
                       ::com::sun::star::drawing::XDrawPage >&          xDrawPage,
                   const ::com::sun::star::uno::Reference<
                       ::com::sun::star::animations::XAnimationNode >&  xRootNode,
                   EventQueue&                                          rEventQueue,
                   ActivitiesQueue&                                     rActivitiesQueue,
                   EventMultiplexer&                                    rEventMultiplexer,
                   UserEventQueue&                                      rUserEventQueue,
                   const ::com::sun::star::uno::Reference<
                               ::com::sun::star::uno::XComponentContext >& xContext );

            ~Slide();

            /** Add a view to this slide
             */
            void addView( const UnoViewSharedPtr& rView );

            /** Remove a previously added a view from this slide

                @return true, if this view was successfully removed, false
                otherwise (e.g. if this view wasn't added in the first place)
            */
            bool removeView( const UnoViewSharedPtr& rView );

            /** Add the given listener for the given shape.

                This method implements the addShapeEventListener
                method of the XSlideShow interface. The given listener
                is called, whenever a user clicks on the shape. If the
                shape is not contained in this slide, this method does
                nothing.
             */
            void addShapeEventListener( const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::presentation::XShapeEventListener >&  xListener,
                                        const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::drawing::XShape >&                    xShape );

            /** Revoke the given listener for the given shape.

                This method implements the removeShapeEventListener
                method of the XSlideShow interface.
             */
            void removeShapeEventListener( const ::com::sun::star::uno::Reference<
                                                       ::com::sun::star::presentation::XShapeEventListener >&   xListener,
                                           const ::com::sun::star::uno::Reference<
                                                       ::com::sun::star::drawing::XShape >&                     xShape );

            /** Control intrinsic animation behaviour

                @param bImageAnimationsAllowed
                When true, GIF and drawing layer animations will be
                shown. When false, those shapes have no intrinsic
                animation.
             */
            void setImageAnimationsAllowed( bool bImageAnimationsAllowed );

            /** Set the mouse cursor for a given shape.

                This method implements the setShapeCursor method of
                the XSlideShow interface. Whenever the mouse hovers
                over the given shape, the specified mouse cursor will
                be shown. To reset the mouse cursor to the default,
                specify awt::SystemPointer::ARROW.
             */
            void setShapeCursor( const ::com::sun::star::uno::Reference<
                                         ::com::sun::star::drawing::XShape >&   xShape,
                                 sal_Int16                                      nPointerShape );

            /** Prepares to show slide.

                Call this method to reduce the timeout show(), and
                getInitialSlideBitmap() need to complete. If
                prefetchShow() is not called explicitely, the named
                methods will call it implicitely.
             */
            bool prefetchShow();

            /** Paint the slide on all registered views, without any effects
             */
            bool paint();

            /** Shows the slide on all registered views
             */
            bool show();

            /** Force-end the slide show.
             */
            void end();

            /** Query whether this slide is currently showing.

                @return true, if this slide is currently showing
                (i.e. show() was called more often than end()).
             */
            bool isShowing() const;

            /** Query whether the slide has animations at all

                If the slide doesn't have animations, show() is
                equivalent to paint(). If an event is registered with
                registerSlideEndEvent(), this event will be
                immediately activated at the end of the show() method.

                @return true, if this slide has animations, false
                otherwise
             */
            bool isAnimated();

            /** Request bitmap for current slide appearance.

                The bitmap returned by this method is dependent on the
                current state of the slide and the contained
                animations. A newly generated slide will return the
                initial slide content here (e.g. with all 'appear'
                effect shapes invisible), a slide whose effects are
                currently running will return a bitmap corresponding
                to the current position on the animation timeline, and
                a slide whose effects have all been run will generate
                a bitmap with the final slide appearance (e.g. with
                all 'hide' effect shapes invisible).

                @param rView
                View to retrieve bitmap for (note that the bitmap will
                have device-pixel equivalence to the content that
                would have been rendered onto the given view). Note
                that the view must have been added to this slide via
                addView() before, otherwise, this method will throw an
                exception.
             */
            // TODO(F2): Rework SlideBitmap to no longer be based on XBitmap,
            // but on canvas-independent basegfx bitmaps
            SlideBitmapSharedPtr getCurrentSlideBitmap( const UnoViewSharedPtr& rView );

            /** Query the slide, whether next slide should appear
                automatically.

                @return true, if next slide should be displayed
                automatically. When false is returned, the user is
                required to click to have the next slide shown.
             */
            bool hasAutomaticNextSlide() const;

            /** Query the slide for the timeout, until the next slide
                is automatically shown.

                This value is undefined, should
                hasAutomaticNextSlide() return false.

                @return a timeout in seconds, for which to delay the
                display of the next slide.
             */
            double getAutomaticNextSlideTimeout() const;

            /** Control the user paint mode.

                The user paint mode lets the user paint on this slide
                with the given color, when pressing down the
                mousebutton.
             */
            void setUserPaintColor( boost::optional<RGBColor> const& rColor );

            /// Query the XDrawPage's size
            basegfx::B2ISize getSlideSize() const;

            /// Get size of the slide in device coordinates for given view
            ::basegfx::B2ISize getSlideSizePixel(
                UnoViewSharedPtr const & pView ) const;

            /// Gets the underlying API page
            ::com::sun::star::uno::Reference<
                ::com::sun::star::drawing::XDrawPage > const&
            getXDrawPage() const { return mxDrawPage; }

            /// Gets the animation node.
            ::com::sun::star::uno::Reference<
                ::com::sun::star::animations::XAnimationNode > const&
            getXAnimationNode() const { return mxRootNode; }

        private:
            // default: disabled copy/assignment
            Slide(const Slide&);
            Slide& operator=( const Slide& );

            void enablePaintOverlay();
            void disablePaintOverlay();

            /// Set all Shapes to their initial attributes for slideshow
            bool applyInitialShapeAttributes( const ::com::sun::star::uno::Reference<
                                                  ::com::sun::star::animations::XAnimationNode >& xRootAnimationNode );

            /// Renders current slide content to bitmap
            SlideBitmapSharedPtr createCurrentSlideBitmap(
                const UnoViewSharedPtr& rView,
                ::basegfx::B2ISize const & rSlideSize );

            /// Prefetch all shapes (not the animations)
            bool prefetchShapes();

            /// Prefetch show, but don't call applyInitialShapeAttributes()
            bool implPrefetchShow();

            /// Query the rectangle covered by the slide
            ::basegfx::B2DRectangle getSlideRect() const;

            /// Start GIF and other intrinsic shape animations
            void endIntrinsicAnimations();

            /// End GIF and other intrinsic shape animations
            void startIntrinsicAnimations();


            // Types
            // =====

            enum SlideAnimationState
            {
                CONSTRUCTING_STATE=0,
                INITIAL_STATE=1,
                SHOWING_STATE=2,
                FINAL_STATE=3,
                SlideAnimationState_NUM_ENTRIES=4
            };

            /** Vector of slide bitmaps.

                Since the bitmap content is sensitive to animation
                effects, we have an inner vector containing a distinct
                bitmap for each of the SlideAnimationStates.
             */
            typedef ::std::vector< ::std::vector< SlideBitmapSharedPtr > > VectorOfSlideBitmaps;


            // Member variables
            // ================

            /// The page model object
            ::com::sun::star::uno::Reference<
                ::com::sun::star::drawing::XDrawPage > const mxDrawPage;
            ::com::sun::star::uno::Reference<
                ::com::sun::star::animations::XAnimationNode > const mxRootNode;

            /// Contains common objects needed throughout the slideshow
            SlideShowContext                                    maContext;

            ::boost::shared_ptr<ShapeEventBroadcaster> mpEventBroadcaster;

            /// Handles the animation and event generation for us
            SlideAnimations                                     maAnimations;

            /// All added views
            UnoViewVector                                       maViews;

            ::boost::optional<RGBColor>                         maUserPaintColor;
            UserPaintOverlaySharedPtr                           mpPaintOverlay;

            /// Bitmap with initial slide content
            VectorOfSlideBitmaps                                maSlideBitmaps;

            /// Timeout for automatic next slide display
            double                                              mnNextSlideTimeout;

            SlideAnimationState                                 meAnimationState;

            /// True, when intrinsic shape animations are allowed
            bool                                                mbImageAnimationsAllowed;

            /// True, if initial load of all page shapes succeeded
            bool                                                mbShapesLoaded;

            /// True, if initial load of all animation info succeeded
            bool                                                mbShowLoaded;

            /** True, if this slide is not static.

                If this slide has animated content, this variable wiil
                be true, and false otherwise.
             */
            bool                                                mbHaveAnimations;

            /** True, if this slide has a main animation sequence.

                If this slide has animation content, which in turn has
                a main animation sequence (which must be fully run
                before EventMultiplexer::notifySlideAnimationsEnd() is
                called), this member is true.
             */
            bool                                                mbMainSequenceFound;

            /** When true, next slide should display without further
                user interaction.
             */
            bool                                                mbHasAutomaticNextSlide;

            struct ShapesIterationFunc;  friend struct ShapesIterationFunc;
        };

        typedef ::boost::shared_ptr< ::presentation::internal::Slide > SlideSharedPtr;

    }
}

#endif /* _SLIDESHOW_SLIDE_HXX */