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