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