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