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