xref: /aoo42x/main/slideshow/source/inc/shape.hxx (revision cdf0e10c)
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_SHAPE_HXX
29 #define INCLUDED_SLIDESHOW_SHAPE_HXX
30 
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/drawing/XShape.hpp>
33 #include <com/sun/star/drawing/XDrawPage.hpp>
34 
35 #include <basegfx/range/b2drectangle.hxx>
36 
37 #include "viewlayer.hxx"
38 
39 #include <boost/shared_ptr.hpp>
40 #include <boost/noncopyable.hpp>
41 #include <set>
42 #include <vector>
43 
44 namespace basegfx {
45     class B2DRange;
46 }
47 
48 namespace slideshow
49 {
50     namespace internal
51     {
52         // forward declaration necessary, because methods use ShapeSharedPtr
53         class Shape;
54 
55         typedef ::boost::shared_ptr< Shape > ShapeSharedPtr;
56 
57         /** Represents a slide's shape object.
58 
59             This interface represents the view-independent aspects of a
60             slide's shape, providing bound rect, underlying XShape and
61             basic paint methods.
62          */
63         class Shape : private boost::noncopyable
64         {
65         public:
66             virtual ~Shape() {}
67 
68             /** Get the associated XShape of this shape.
69 
70             	@return the associated XShape. If this method returns
71             	an empty reference, this object might be one of the
72             	special-purpose shapes of a slide, which have no
73             	direct corresponding XShape (the background comes to
74             	mind here).
75              */
76             virtual ::com::sun::star::uno::Reference<
77                 ::com::sun::star::drawing::XShape > getXShape() const = 0;
78 
79 
80             // View layer methods
81             //------------------------------------------------------------------
82 
83             /** Add a new view layer.
84 
85             	This method adds a new view layer, this shape shall
86             	show itself on.
87 
88                 @param rNewLayer
89                 New layer to show on
90 
91                 @param bRedrawLayer
92                 Redraw shape on given layer
93              */
94             virtual void addViewLayer( const ViewLayerSharedPtr& 	rNewLayer,
95                                        bool							bRedrawLayer ) = 0;
96 
97             /** Withdraw the shape from a view layer
98 
99             	This method removes the shape from the given view
100             	layer.
101 
102                 @return true, if the shape was successfully removed
103              */
104             virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) = 0;
105 
106             /** Withdraw all view layers at once
107 
108                 This method will be faster than repeated
109                 removeViewLayer() calls.
110              */
111             virtual bool clearAllViewLayers() = 0;
112 
113             // render methods
114             //------------------------------------------------------------------
115 
116             /** Update the shape
117 
118 				This method updates the Shape on all registered view
119 				layers, but only if shape content has actually
120 				changed.
121 
122 	            @return whether the update finished successfully.
123             */
124             virtual bool update() const = 0;
125 
126             /** Render the shape.
127 
128 				This method renders the shape on all registered view
129 				layers, regardless of whether shape content has
130 				changed or not.
131 
132 	            @return whether the rendering finished successfully.
133             */
134             virtual bool render() const = 0;
135 
136             /** Query whether shape content changed
137 
138             	This method returns true, if shape content changed
139             	since the last rendering (i.e. the shape needs an
140             	update to reflect that changed content on the views).
141              */
142             virtual bool isContentChanged() const = 0;
143 
144 
145             // Shape attributes
146             //------------------------------------------------------------------
147 
148             /** Get the current shape position and size.
149 
150             	This method yields the currently effective shape
151             	bounds (which might change over time, for animated
152             	shapes). Please note that possibly shape rotations
153             	from its original document state must not be taken
154             	into account here: if you need the screen bounding
155             	box, use getUpdateArea() instead. Note further that
156             	shape rotations, which are already contained in the
157             	shape as displayed in the original document
158             	<em>are</em> included herein (we currently take the
159             	shape as-is from the document, assuming a rotation
160             	angle of 0).
161              */
162             virtual ::basegfx::B2DRange getBounds() const = 0;
163 
164             /** Get the DOM position and size of the shape.
165 
166             	This method yields the underlying DOM shape bounds,
167             	i.e. the original shape bounds from the document
168             	model. This value is <em>always</em> unaffected by any
169             	animation activity. Note that shape rotations, which
170             	are already contained in the shape as displayed in the
171             	original document are already included herein (we
172             	currently take the shape as-is from the document,
173             	assuming a rotation angle of 0).
174              */
175             virtual ::basegfx::B2DRange getDomBounds() const = 0;
176 
177             /** Get the current shape update area.
178 
179             	This method yields the currently effective update area
180             	for the shape, i.e. the area that needs to be updated,
181             	should the shape be painted. Normally, this will be
182             	the (possibly rotated and sheared) area returned by
183             	getBounds().
184              */
185             virtual ::basegfx::B2DRange getUpdateArea() const = 0;
186 
187             /** Query whether the shape is visible at all.
188 
189             	@return true, if this shape is visible, false
190             	otherwise.
191              */
192             virtual bool isVisible() const = 0;
193 
194             /** Get the shape priority.
195 
196 				The shape priority defines the relative order of the
197 				shapes on the slide.
198 
199                 @return the priority. Will be in the [0,+infty) range.
200              */
201             virtual double getPriority() const = 0;
202 
203             /** Query whether the Shape is currently detached from the
204                 background.
205 
206 				This method checks whether the Shape is currently
207 				detached from the slide background, i.e. whether shape
208 				updates affect the underlying slide background or
209 				not. A shape that returnes true here must not alter
210 				slide content in any way when called render() or
211 				update() (this is normally achieved by making this
212 				shape a sprite).
213              */
214             virtual bool isBackgroundDetached() const = 0;
215 
216             // Misc
217             //------------------------------------------------------------------
218 
219             /** Functor struct, for shape ordering
220 
221             	This defines a strict weak ordering of shapes, primary
222             	sort key is the shape priority, and secondy sort key
223             	the object ptr value. Most typical use is for
224             	associative containers holding shapes (and which also
225             	have to maintain something like a paint order).
226              */
227             struct lessThanShape
228             {
229                 // make functor adaptable (to boost::bind)
230                 typedef bool result_type;
231 
232                 // since the ZOrder property on the XShape has somewhat
233                 // peculiar attributes (it's basically the index of the shapes
234                 // in the drawing layer's SdrObjList - which means, it starts
235                 // from 0 for children of group objects), we cannot use it to determine
236                 // drawing order. Thus, we rely on importer-provided order values here,
237                 // which is basically a running counter during shape import (i.e. denotes
238                 // the order of shape import). This is the correct order, at least for the
239                 // current drawing core.
240                 //
241                 // If, someday, the above proposition is no longer true, one directly use
242                 // the shape's ZOrder property
243                 //
244                 static bool compare(const Shape* pLHS, const Shape* pRHS)
245                 {
246                     const double nPrioL( pLHS->getPriority() );
247                     const double nPrioR( pRHS->getPriority() );
248 
249                     // if prios are equal, tie-break on ptr value
250                     return nPrioL == nPrioR ? pLHS < pRHS : nPrioL < nPrioR;
251                 }
252 
253                 bool operator()(const ShapeSharedPtr& rLHS, const ShapeSharedPtr& rRHS) const
254                 {
255                     return compare(rLHS.get(),rRHS.get());
256                 }
257 
258                 bool operator()(const Shape* pLHS, const Shape* pRHS) const
259                 {
260                     return compare(pLHS, pRHS);
261                 }
262             };
263         };
264 
265         typedef ::boost::shared_ptr< Shape > ShapeSharedPtr;
266 
267         /** A set which contains all shapes in an ordered fashion.
268          */
269         typedef ::std::set< ShapeSharedPtr, Shape::lessThanShape > 	ShapeSet;
270     }
271 }
272 
273 #endif /* INCLUDED_SLIDESHOW_SHAPE_HXX */
274