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: drawshape.hxx,v $
10 * $Revision: 1.4.12.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_DRAWSHAPE_HXX
32 #define INCLUDED_SLIDESHOW_DRAWSHAPE_HXX
34 #include <osl/diagnose.hxx>
35 #include <com/sun/star/drawing/XShape.hpp>
37 #include "attributableshape.hxx"
38 #include "doctreenodesupplier.hxx"
39 #include "gdimtftools.hxx"
40 #include "viewshape.hxx"
41 #include "hyperlinkarea.hxx"
43 #include <boost/optional.hpp>
44 #include <boost/shared_ptr.hpp>
45 #include <boost/weak_ptr.hpp>
56 struct SlideShowContext
;
57 class DrawShapeSubsetting
;
59 typedef ::boost::shared_ptr
< DrawShape
> DrawShapeSharedPtr
;
61 /** This class is the representation of a draw document's
62 XShape, and implements the Shape, AnimatableShape, and
63 AttributableShape interfaces.
65 @attention this class is to be treated 'final', i.e. one
66 should not derive from it.
68 class DrawShape
: public AttributableShape
,
69 public DocTreeNodeSupplier
,
71 protected ::osl::DebugBase
<DrawShape
>
74 /** Create a shape for the given XShape
77 The XShape to represent.
79 @param xContainingPage
80 The page that contains this shape. Needed for proper
81 import (currently, the UnoGraphicExporter needs this
85 Externally-determined shape priority (used e.g. for
86 paint ordering). This number _must be_ unique!
89 When true, the source of the shape metafile might be a
90 foreign application. The metafile is checked against
91 unsupported content, and, if necessary, returned as a
94 static DrawShapeSharedPtr
create(
95 const ::com::sun::star::uno::Reference
<
96 ::com::sun::star::drawing::XShape
>& xShape
,
97 const ::com::sun::star::uno::Reference
<
98 ::com::sun::star::drawing::XDrawPage
>& xContainingPage
,
101 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
103 /** Create a shape for the given XShape and graphic content
106 The XShape to represent.
108 @param xContainingPage
109 The page that contains this shape. Needed for proper
110 import (currently, the UnoGraphicExporter needs this
114 Externally-determined shape priority (used e.g. for
115 paint ordering). This number _must be_ unique!
118 Graphic to display in the shape's bound rect. If this
119 Graphic contains animatable content, the created
120 DrawShape will register itself for intrinsic animation
123 static DrawShapeSharedPtr
create(
124 const ::com::sun::star::uno::Reference
<
125 ::com::sun::star::drawing::XShape
>& xShape
,
126 const ::com::sun::star::uno::Reference
<
127 ::com::sun::star::drawing::XDrawPage
>& xContainingPage
,
129 const Graphic
& rGraphic
,
130 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
132 virtual ::com::sun::star::uno::Reference
<
133 ::com::sun::star::drawing::XShape
> getXShape() const;
135 virtual ~DrawShape();
138 // View layer methods
139 //------------------------------------------------------------------
141 virtual void addViewLayer( const ViewLayerSharedPtr
& rNewLayer
,
143 virtual bool removeViewLayer( const ViewLayerSharedPtr
& rNewLayer
);
144 virtual bool clearAllViewLayers();
147 //------------------------------------------------------------------
149 virtual ShapeAttributeLayerSharedPtr
createAttributeLayer();
150 virtual bool revokeAttributeLayer( const ShapeAttributeLayerSharedPtr
& rLayer
);
151 virtual ShapeAttributeLayerSharedPtr
getTopmostAttributeLayer() const;
152 virtual void setVisibility( bool bVisible
);
153 virtual ::basegfx::B2DRectangle
getBounds() const;
154 virtual ::basegfx::B2DRectangle
getDomBounds() const;
155 virtual ::basegfx::B2DRectangle
getUpdateArea() const;
156 virtual bool isVisible() const;
157 virtual double getPriority() const;
161 //------------------------------------------------------------------
163 virtual void enterAnimationMode();
164 virtual void leaveAnimationMode();
165 virtual bool isBackgroundDetached() const;
168 //------------------------------------------------------------------
170 virtual bool update() const;
171 virtual bool render() const;
172 virtual bool isContentChanged() const;
174 // Sub item specialities
175 //------------------------------------------------------------------
177 virtual const DocTreeNodeSupplier
& getTreeNodeSupplier() const;
178 virtual DocTreeNodeSupplier
& getTreeNodeSupplier();
180 virtual DocTreeNode
getSubsetNode() const;
181 virtual AttributableShapeSharedPtr
getSubset( const DocTreeNode
& rTreeNode
) const;
182 virtual bool createSubset( AttributableShapeSharedPtr
& o_rSubset
,
183 const DocTreeNode
& rTreeNode
);
184 virtual bool revokeSubset( const AttributableShapeSharedPtr
& rShape
);
187 // DocTreeNodeSupplier methods
188 //------------------------------------------------------------------
190 virtual sal_Int32
getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType
) const; // throw ShapeLoadFailedException;
191 virtual DocTreeNode
getTreeNode ( sal_Int32 nNodeIndex
,
192 DocTreeNode::NodeType eNodeType
) const; // throw ShapeLoadFailedException;
193 virtual sal_Int32
getNumberOfSubsetTreeNodes ( const DocTreeNode
& rParentNode
,
194 DocTreeNode::NodeType eNodeType
) const; // throw ShapeLoadFailedException;
195 virtual DocTreeNode
getSubsetTreeNode ( const DocTreeNode
& rParentNode
,
196 sal_Int32 nNodeIndex
,
197 DocTreeNode::NodeType eNodeType
) const; // throw ShapeLoadFailedException;
199 // HyperlinkArea methods
200 //------------------------------------------------------------------
202 virtual HyperlinkRegions
getHyperlinkRegions() const;
203 virtual double getHyperlinkPriority() const;
206 // intrinsic animation methods
207 //------------------------------------------------------------------
209 /** Display next frame of an intrinsic animation.
211 Used by IntrinsicAnimationActivity, to show the next
214 bool setIntrinsicAnimationFrame( ::std::size_t nCurrFrame
);
216 /** forces the drawshape to load and return a specially
217 crafted metafile, usable to display drawing layer text
220 GDIMetaFileSharedPtr
forceScrollTextMetaFile();
223 /** Create a shape for the given XShape
226 The XShape to represent.
228 @param xContainingPage
229 The page that contains this shape. Needed for proper
230 import (currently, the UnoGraphicExporter needs this
234 Externally-determined shape priority (used e.g. for
235 paint ordering). This number _must be_ unique!
237 @param bForeignSource
238 When true, the source of the shape metafile might be a
239 foreign application. The metafile is checked against
240 unsupported content, and, if necessary, returned as a
241 pre-rendererd bitmap.
243 DrawShape( const ::com::sun::star::uno::Reference
<
244 ::com::sun::star::drawing::XShape
>& xShape
,
245 const ::com::sun::star::uno::Reference
<
246 ::com::sun::star::drawing::XDrawPage
>& xContainingPage
,
249 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
251 /** Create a shape for the given XShape and graphic content
254 The XShape to represent.
256 @param xContainingPage
257 The page that contains this shape. Needed for proper
258 import (currently, the UnoGraphicExporter needs this
262 Externally-determined shape priority (used e.g. for
263 paint ordering). This number _must be_ unique!
266 Graphic to display in the shape's bound rect. If this
267 Graphic contains animatable content, the created
268 DrawShape will register itself for intrinsic animation
271 DrawShape( const ::com::sun::star::uno::Reference
<
272 ::com::sun::star::drawing::XShape
>& xShape
,
273 const ::com::sun::star::uno::Reference
<
274 ::com::sun::star::drawing::XDrawPage
>& xContainingPage
,
276 const Graphic
& rGraphic
,
277 const SlideShowContext
& rContext
); // throw ShapeLoadFailedException;
279 /** Private copy constructor
281 Used to create subsetted shapes
283 DrawShape( const DrawShape
&, const DocTreeNode
& rTreeNode
, double nPrio
);
285 int getUpdateFlags() const;
286 bool implRender( int nUpdateFlags
) const;
287 void updateStateIds() const;
289 ViewShape::RenderArgs
getViewRenderArgs() const;
290 ::basegfx::B2DRectangle
getActualUnitShapeBounds() const;
292 void ensureVerboseMtfComments() const;
293 bool hasIntrinsicAnimation() const;
294 bool hasHyperlinks() const;
295 void prepareHyperlinkIndices() const;
297 /// The associated XShape
298 ::com::sun::star::uno::Reference
<
299 ::com::sun::star::drawing::XShape
> mxShape
;
300 ::com::sun::star::uno::Reference
<
301 ::com::sun::star::drawing::XDrawPage
> mxPage
;
303 /** A vector of metafiles actually representing the Shape.
305 If this shape is not animated, only a single entry is
308 mutable VectorOfMtfAnimationFrames maAnimationFrames
;
309 ::std::size_t mnCurrFrame
;
311 /// Metafile of currently active frame (static for shapes w/o intrinsic animation)
312 mutable GDIMetaFileSharedPtr mpCurrMtf
;
314 /// loadflags of current meta file
315 mutable int mnCurrMtfLoadFlags
;
317 /// Contains the current shape bounds, in unit rect space
318 mutable ::boost::optional
<basegfx::B2DRectangle
> maCurrentShapeUnitBounds
;
320 // The attributes of this Shape
321 const double mnPriority
;
322 ::basegfx::B2DRectangle maBounds
; // always needed for rendering.
323 // for subset shapes, this member
324 // might change when views are
325 // added, as minimal bounds are
328 // Pointer to modifiable shape attributes
329 ShapeAttributeLayerSharedPtr mpAttributeLayer
; // only created lazily
331 // held here, to signal our destruction
332 boost::weak_ptr
<Activity
> mpIntrinsicAnimationActivity
;
334 // The attribute states, to detect attribute changes,
335 // without buffering and querying each single attribute
336 mutable State::StateId mnAttributeTransformationState
;
337 mutable State::StateId mnAttributeClipState
;
338 mutable State::StateId mnAttributeAlphaState
;
339 mutable State::StateId mnAttributePositionState
;
340 mutable State::StateId mnAttributeContentState
;
341 mutable State::StateId mnAttributeVisibilityState
;
343 /// the list of active view shapes (one for each registered view layer)
344 typedef ::std::vector
< ViewShapeSharedPtr
> ViewShapeVector
;
345 ViewShapeVector maViewShapes
;
347 ::com::sun::star::uno::Reference
<
348 ::com::sun::star::uno::XComponentContext
> mxComponentContext
;
350 /// hyperlink support
351 typedef ::std::pair
<sal_Int32
/* mtf start */,
352 sal_Int32
/* mtf end */> HyperlinkIndexPair
;
353 typedef ::std::vector
<HyperlinkIndexPair
> HyperlinkIndexPairVector
;
354 mutable HyperlinkIndexPairVector maHyperlinkIndices
;
355 mutable HyperlinkRegions maHyperlinkRegions
;
357 /// Delegated subset handling
358 mutable DrawShapeSubsetting maSubsetting
;
360 /// Whether this shape is currently in animation mode (value != 0)
361 int mnIsAnimatedCount
;
363 /// Number of times the bitmap animation shall loop
364 ::std::size_t mnAnimationLoopCount
;
366 /// Cycle mode for bitmap animation
367 CycleMode meCycleMode
;
369 /// Whether shape is visible (without attribute layers)
372 /// Whether redraw is necessary, regardless of state ids
373 mutable bool mbForceUpdate
;
375 /// Whether attribute layer was revoked (making a redraw necessary)
376 mutable bool mbAttributeLayerRevoked
;
378 /// whether a drawing layer animation has to be performed
379 bool mbDrawingLayerAnim
;
385 #endif /* INCLUDED_SLIDESHOW_DRAWSHAPE_HXX */