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_DRAWSHAPE_HXX
29 #define INCLUDED_SLIDESHOW_DRAWSHAPE_HXX
30 
31 #include <osl/diagnose.hxx>
32 #include <com/sun/star/drawing/XShape.hpp>
33 
34 #include "attributableshape.hxx"
35 #include "doctreenodesupplier.hxx"
36 #include "gdimtftools.hxx"
37 #include "viewshape.hxx"
38 #include "hyperlinkarea.hxx"
39 
40 #include <boost/optional.hpp>
41 #include <boost/shared_ptr.hpp>
42 #include <boost/weak_ptr.hpp>
43 #include <set>
44 #include <vector>
45 
46 class Graphic;
47 
48 namespace slideshow
49 {
50     namespace internal
51     {
52         class  Activity;
53         struct SlideShowContext;
54         class  DrawShapeSubsetting;
55         class  DrawShape;
56         typedef ::boost::shared_ptr< DrawShape > DrawShapeSharedPtr;
57 
58         /** This class is the representation of a draw document's
59             XShape, and implements the Shape, AnimatableShape, and
60             AttributableShape interfaces.
61 
62             @attention this class is to be treated 'final', i.e. one
63             should not derive from it.
64          */
65         class DrawShape : public AttributableShape,
66                           public DocTreeNodeSupplier,
67                           public HyperlinkArea,
68                           public ::osl::DebugBase<DrawShape>
69         {
70         public:
71             /** Create a shape for the given XShape
72 
73                 @param xShape
74                 The XShape to represent.
75 
76                 @param xContainingPage
77                 The page that contains this shape. Needed for proper
78                 import (currently, the UnoGraphicExporter needs this
79                 information).
80 
81                 @param nPrio
82                 Externally-determined shape priority (used e.g. for
83                 paint ordering). This number _must be_ unique!
84 
85                 @param bForeignSource
86                 When true, the source of the shape metafile might be a
87                 foreign application. The metafile is checked against
88                 unsupported content, and, if necessary, returned as a
89                 pre-rendererd bitmap.
90              */
91             static DrawShapeSharedPtr create(
92                 const ::com::sun::star::uno::Reference<
93                    ::com::sun::star::drawing::XShape >&    xShape,
94                 const ::com::sun::star::uno::Reference<
95                    ::com::sun::star::drawing::XDrawPage >& xContainingPage,
96                 double                                     nPrio,
97                 bool                                       bForeignSource,
98                 const SlideShowContext&                    rContext ); // throw ShapeLoadFailedException;
99 
100             /** Create a shape for the given XShape and graphic content
101 
102                 @param xShape
103                 The XShape to represent.
104 
105                 @param xContainingPage
106                 The page that contains this shape. Needed for proper
107                 import (currently, the UnoGraphicExporter needs this
108                 information).
109 
110                 @param nPrio
111                 Externally-determined shape priority (used e.g. for
112                 paint ordering). This number _must be_ unique!
113 
114                 @param rGraphic
115                 Graphic to display in the shape's bound rect. If this
116                 Graphic contains animatable content, the created
117                 DrawShape will register itself for intrinsic animation
118                 events.
119              */
120             static DrawShapeSharedPtr create(
121                 const ::com::sun::star::uno::Reference<
122                    ::com::sun::star::drawing::XShape >&    xShape,
123                 const ::com::sun::star::uno::Reference<
124                    ::com::sun::star::drawing::XDrawPage >& xContainingPage,
125                 double                                     nPrio,
126                 const Graphic&                             rGraphic,
127                 const SlideShowContext&                    rContext ); // throw ShapeLoadFailedException;
128 
129             virtual ::com::sun::star::uno::Reference<
130                 ::com::sun::star::drawing::XShape > getXShape() const;
131 
132             virtual ~DrawShape();
133 
134 
135             // View layer methods
136             //------------------------------------------------------------------
137 
138             virtual void addViewLayer( const ViewLayerSharedPtr&    rNewLayer,
139                                        bool                         bRedrawLayer );
140             virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer );
141             virtual bool clearAllViewLayers();
142 
143             // attribute methods
144             //------------------------------------------------------------------
145 
146             virtual ShapeAttributeLayerSharedPtr createAttributeLayer();
147             virtual bool revokeAttributeLayer( const ShapeAttributeLayerSharedPtr& rLayer );
148             virtual ShapeAttributeLayerSharedPtr getTopmostAttributeLayer() const;
149             virtual void setVisibility( bool bVisible );
150             virtual ::basegfx::B2DRectangle getBounds() const;
151             virtual ::basegfx::B2DRectangle getDomBounds() const;
152             virtual ::basegfx::B2DRectangle getUpdateArea() const;
153             virtual bool isVisible() const;
154             virtual double getPriority() const;
155 
156 
157             // animation methods
158             //------------------------------------------------------------------
159 
160             virtual void enterAnimationMode();
161             virtual void leaveAnimationMode();
162             virtual bool isBackgroundDetached() const;
163 
164             // render methods
165             //------------------------------------------------------------------
166 
167             virtual bool update() const;
168             virtual bool render() const;
169             virtual bool isContentChanged() const;
170 
171             // Sub item specialities
172             //------------------------------------------------------------------
173 
174             virtual const DocTreeNodeSupplier&  getTreeNodeSupplier() const;
175             virtual DocTreeNodeSupplier&        getTreeNodeSupplier();
176 
177             virtual DocTreeNode                 getSubsetNode() const;
178             virtual AttributableShapeSharedPtr  getSubset( const DocTreeNode& rTreeNode ) const;
179             virtual bool                        createSubset( AttributableShapeSharedPtr&   o_rSubset,
180                                                               const DocTreeNode&            rTreeNode );
181             virtual bool                        revokeSubset( const AttributableShapeSharedPtr& rShape );
182 
183 
184             // DocTreeNodeSupplier methods
185             //------------------------------------------------------------------
186 
187             virtual sal_Int32   getNumberOfTreeNodes        ( DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException;
188             virtual DocTreeNode getTreeNode                 ( sal_Int32             nNodeIndex,
189                                                               DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException;
190             virtual sal_Int32   getNumberOfSubsetTreeNodes  ( const DocTreeNode&    rParentNode,
191                                                               DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException;
192             virtual DocTreeNode getSubsetTreeNode           ( const DocTreeNode&    rParentNode,
193                                                               sal_Int32             nNodeIndex,
194                                                               DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException;
195 
196             // HyperlinkArea methods
197             //------------------------------------------------------------------
198 
199             virtual HyperlinkRegions getHyperlinkRegions() const;
200             virtual double getHyperlinkPriority() const;
201 
202 
203             // intrinsic animation methods
204             //------------------------------------------------------------------
205 
206             /** Display next frame of an intrinsic animation.
207 
208                 Used by IntrinsicAnimationActivity, to show the next
209                 animation frame.
210              */
211             bool setIntrinsicAnimationFrame( ::std::size_t nCurrFrame );
212 
213             /** forces the drawshape to load and return a specially
214                 crafted metafile, usable to display drawing layer text
215                 animations.
216             */
217             GDIMetaFileSharedPtr forceScrollTextMetaFile();
218 
219         private:
220             /** Create a shape for the given XShape
221 
222                 @param xShape
223                 The XShape to represent.
224 
225                 @param xContainingPage
226                 The page that contains this shape. Needed for proper
227                 import (currently, the UnoGraphicExporter needs this
228                 information).
229 
230                 @param nPrio
231                 Externally-determined shape priority (used e.g. for
232                 paint ordering). This number _must be_ unique!
233 
234                 @param bForeignSource
235                 When true, the source of the shape metafile might be a
236                 foreign application. The metafile is checked against
237                 unsupported content, and, if necessary, returned as a
238                 pre-rendererd bitmap.
239              */
240             DrawShape( const ::com::sun::star::uno::Reference<
241                             ::com::sun::star::drawing::XShape >&    xShape,
242                        const ::com::sun::star::uno::Reference<
243                             ::com::sun::star::drawing::XDrawPage >& xContainingPage,
244                        double                                       nPrio,
245                        bool                                         bForeignSource,
246                        const SlideShowContext&                      rContext ); // throw ShapeLoadFailedException;
247 
248             /** Create a shape for the given XShape and graphic content
249 
250                 @param xShape
251                 The XShape to represent.
252 
253                 @param xContainingPage
254                 The page that contains this shape. Needed for proper
255                 import (currently, the UnoGraphicExporter needs this
256                 information).
257 
258                 @param nPrio
259                 Externally-determined shape priority (used e.g. for
260                 paint ordering). This number _must be_ unique!
261 
262                 @param rGraphic
263                 Graphic to display in the shape's bound rect. If this
264                 Graphic contains animatable content, the created
265                 DrawShape will register itself for intrinsic animation
266                 events.
267              */
268             DrawShape( const ::com::sun::star::uno::Reference<
269                             ::com::sun::star::drawing::XShape >&    xShape,
270                        const ::com::sun::star::uno::Reference<
271                             ::com::sun::star::drawing::XDrawPage >& xContainingPage,
272                        double                                       nPrio,
273                        const Graphic&                               rGraphic,
274                        const SlideShowContext&                      rContext ); // throw ShapeLoadFailedException;
275 
276             /** Private copy constructor
277 
278                 Used to create subsetted shapes
279              */
280             DrawShape( const DrawShape&, const DocTreeNode& rTreeNode, double nPrio );
281 
282             int  getUpdateFlags() const;
283             bool implRender( int nUpdateFlags ) const;
284             void updateStateIds() const;
285 
286             ViewShape::RenderArgs   getViewRenderArgs() const;
287             ::basegfx::B2DRectangle getActualUnitShapeBounds() const;
288 
289             void ensureVerboseMtfComments() const;
290             bool hasIntrinsicAnimation() const;
291             bool hasHyperlinks() const;
292             void prepareHyperlinkIndices() const;
293 
294             /// The associated XShape
295             ::com::sun::star::uno::Reference<
296                     ::com::sun::star::drawing::XShape >                             mxShape;
297             ::com::sun::star::uno::Reference<
298                     ::com::sun::star::drawing::XDrawPage >                          mxPage;
299 
300             /** A vector of metafiles actually representing the Shape.
301 
302                 If this shape is not animated, only a single entry is
303                 available.
304              */
305             mutable VectorOfMtfAnimationFrames                                      maAnimationFrames;
306             ::std::size_t                                                           mnCurrFrame;
307 
308             /// Metafile of currently active frame (static for shapes w/o intrinsic animation)
309             mutable GDIMetaFileSharedPtr                                            mpCurrMtf;
310 
311             /// loadflags of current meta file
312             mutable int                                                             mnCurrMtfLoadFlags;
313 
314             /// Contains the current shape bounds, in unit rect space
315             mutable ::boost::optional<basegfx::B2DRectangle>                        maCurrentShapeUnitBounds;
316 
317             // The attributes of this Shape
318             const double                                                            mnPriority;
319             ::basegfx::B2DRectangle                                                 maBounds; // always needed for rendering.
320                                                                                               // for subset shapes, this member
321                                                                                               // might change when views are
322                                                                                               // added, as minimal bounds are
323                                                                                               // calculated
324 
325             // Pointer to modifiable shape attributes
326             ShapeAttributeLayerSharedPtr                                            mpAttributeLayer; // only created lazily
327 
328             // held here, to signal our destruction
329             boost::weak_ptr<Activity>                                               mpIntrinsicAnimationActivity;
330 
331             // The attribute states, to detect attribute changes,
332             // without buffering and querying each single attribute
333             mutable State::StateId                                                  mnAttributeTransformationState;
334             mutable State::StateId                                                  mnAttributeClipState;
335             mutable State::StateId                                                  mnAttributeAlphaState;
336             mutable State::StateId                                                  mnAttributePositionState;
337             mutable State::StateId                                                  mnAttributeContentState;
338             mutable State::StateId                                                  mnAttributeVisibilityState;
339 
340             /// the list of active view shapes (one for each registered view layer)
341             typedef ::std::vector< ViewShapeSharedPtr > ViewShapeVector;
342             ViewShapeVector                                                         maViewShapes;
343 
344             ::com::sun::star::uno::Reference<
345                 ::com::sun::star::uno::XComponentContext>                           mxComponentContext;
346 
347             /// hyperlink support
348             typedef ::std::pair<sal_Int32 /* mtf start */,
349                                 sal_Int32 /* mtf end */> HyperlinkIndexPair;
350             typedef ::std::vector<HyperlinkIndexPair> HyperlinkIndexPairVector;
351             mutable HyperlinkIndexPairVector                                        maHyperlinkIndices;
352             mutable HyperlinkRegions                                                maHyperlinkRegions;
353 
354             /// Delegated subset handling
355             mutable DrawShapeSubsetting                                             maSubsetting;
356 
357             /// Whether this shape is currently in animation mode (value != 0)
358             int                                                                     mnIsAnimatedCount;
359 
360             /// Number of times the bitmap animation shall loop
361             ::std::size_t                                                           mnAnimationLoopCount;
362 
363             /// Cycle mode for bitmap animation
364             CycleMode                                                               meCycleMode;
365 
366             /// Whether shape is visible (without attribute layers)
367             bool                                                                    mbIsVisible;
368 
369             /// Whether redraw is necessary, regardless of state ids
370             mutable bool                                                            mbForceUpdate;
371 
372             /// Whether attribute layer was revoked (making a redraw necessary)
373             mutable bool                                                            mbAttributeLayerRevoked;
374 
375             /// whether a drawing layer animation has to be performed
376             bool                                                                    mbDrawingLayerAnim;
377 
378         };
379     }
380 }
381 
382 #endif /* INCLUDED_SLIDESHOW_DRAWSHAPE_HXX */
383