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_DRAWSHAPE_HXX 25 #define INCLUDED_SLIDESHOW_DRAWSHAPE_HXX 26 27 #include <osl/diagnose.hxx> 28 #include <com/sun/star/drawing/XShape.hpp> 29 30 #include "attributableshape.hxx" 31 #include "doctreenodesupplier.hxx" 32 #include "gdimtftools.hxx" 33 #include "viewshape.hxx" 34 #include "hyperlinkarea.hxx" 35 36 #include <boost/optional.hpp> 37 #include <boost/shared_ptr.hpp> 38 #include <boost/weak_ptr.hpp> 39 #include <set> 40 #include <vector> 41 42 class Graphic; 43 44 namespace slideshow 45 { 46 namespace internal 47 { 48 class Activity; 49 struct SlideShowContext; 50 class DrawShapeSubsetting; 51 class DrawShape; 52 typedef ::boost::shared_ptr< DrawShape > DrawShapeSharedPtr; 53 54 /** This class is the representation of a draw document's 55 XShape, and implements the Shape, AnimatableShape, and 56 AttributableShape interfaces. 57 58 @attention this class is to be treated 'final', i.e. one 59 should not derive from it. 60 */ 61 class DrawShape : public AttributableShape, 62 public DocTreeNodeSupplier, 63 public HyperlinkArea, 64 public ::osl::DebugBase<DrawShape> 65 { 66 public: 67 /** Create a shape for the given XShape 68 69 @param xShape 70 The XShape to represent. 71 72 @param xContainingPage 73 The page that contains this shape. Needed for proper 74 import (currently, the UnoGraphicExporter needs this 75 information). 76 77 @param nPrio 78 Externally-determined shape priority (used e.g. for 79 paint ordering). This number _must be_ unique! 80 81 @param bForeignSource 82 When true, the source of the shape metafile might be a 83 foreign application. The metafile is checked against 84 unsupported content, and, if necessary, returned as a 85 pre-rendererd bitmap. 86 */ 87 static DrawShapeSharedPtr create( 88 const ::com::sun::star::uno::Reference< 89 ::com::sun::star::drawing::XShape >& xShape, 90 const ::com::sun::star::uno::Reference< 91 ::com::sun::star::drawing::XDrawPage >& xContainingPage, 92 double nPrio, 93 bool bForeignSource, 94 const SlideShowContext& rContext ); // throw ShapeLoadFailedException; 95 96 /** Create a shape for the given XShape and graphic content 97 98 @param xShape 99 The XShape to represent. 100 101 @param xContainingPage 102 The page that contains this shape. Needed for proper 103 import (currently, the UnoGraphicExporter needs this 104 information). 105 106 @param nPrio 107 Externally-determined shape priority (used e.g. for 108 paint ordering). This number _must be_ unique! 109 110 @param rGraphic 111 Graphic to display in the shape's bound rect. If this 112 Graphic contains animatable content, the created 113 DrawShape will register itself for intrinsic animation 114 events. 115 */ 116 static DrawShapeSharedPtr create( 117 const ::com::sun::star::uno::Reference< 118 ::com::sun::star::drawing::XShape >& xShape, 119 const ::com::sun::star::uno::Reference< 120 ::com::sun::star::drawing::XDrawPage >& xContainingPage, 121 double nPrio, 122 const Graphic& rGraphic, 123 const SlideShowContext& rContext ); // throw ShapeLoadFailedException; 124 125 virtual ::com::sun::star::uno::Reference< 126 ::com::sun::star::drawing::XShape > getXShape() const; 127 128 virtual ~DrawShape(); 129 130 131 // View layer methods 132 //------------------------------------------------------------------ 133 134 virtual void addViewLayer( const ViewLayerSharedPtr& rNewLayer, 135 bool bRedrawLayer ); 136 virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ); 137 virtual bool clearAllViewLayers(); 138 139 // attribute methods 140 //------------------------------------------------------------------ 141 142 virtual ShapeAttributeLayerSharedPtr createAttributeLayer(); 143 virtual bool revokeAttributeLayer( const ShapeAttributeLayerSharedPtr& rLayer ); 144 virtual ShapeAttributeLayerSharedPtr getTopmostAttributeLayer() const; 145 virtual void setVisibility( bool bVisible ); 146 virtual ::basegfx::B2DRectangle getBounds() const; 147 virtual ::basegfx::B2DRectangle getDomBounds() const; 148 virtual ::basegfx::B2DRectangle getUpdateArea() const; 149 virtual bool isVisible() const; 150 virtual double getPriority() const; 151 152 153 // animation methods 154 //------------------------------------------------------------------ 155 156 virtual void enterAnimationMode(); 157 virtual void leaveAnimationMode(); 158 virtual bool isBackgroundDetached() const; 159 160 // render methods 161 //------------------------------------------------------------------ 162 163 virtual bool update() const; 164 virtual bool render() const; 165 virtual bool isContentChanged() const; 166 167 // Sub item specialities 168 //------------------------------------------------------------------ 169 170 virtual const DocTreeNodeSupplier& getTreeNodeSupplier() const; 171 virtual DocTreeNodeSupplier& getTreeNodeSupplier(); 172 173 virtual DocTreeNode getSubsetNode() const; 174 virtual AttributableShapeSharedPtr getSubset( const DocTreeNode& rTreeNode ) const; 175 virtual bool createSubset( AttributableShapeSharedPtr& o_rSubset, 176 const DocTreeNode& rTreeNode ); 177 virtual bool revokeSubset( const AttributableShapeSharedPtr& rShape ); 178 179 180 // DocTreeNodeSupplier methods 181 //------------------------------------------------------------------ 182 183 virtual sal_Int32 getNumberOfTreeNodes ( DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException; 184 virtual DocTreeNode getTreeNode ( sal_Int32 nNodeIndex, 185 DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException; 186 virtual sal_Int32 getNumberOfSubsetTreeNodes ( const DocTreeNode& rParentNode, 187 DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException; 188 virtual DocTreeNode getSubsetTreeNode ( const DocTreeNode& rParentNode, 189 sal_Int32 nNodeIndex, 190 DocTreeNode::NodeType eNodeType ) const; // throw ShapeLoadFailedException; 191 192 // HyperlinkArea methods 193 //------------------------------------------------------------------ 194 195 virtual HyperlinkRegions getHyperlinkRegions() const; 196 virtual double getHyperlinkPriority() const; 197 198 199 // intrinsic animation methods 200 //------------------------------------------------------------------ 201 202 /** Display next frame of an intrinsic animation. 203 204 Used by IntrinsicAnimationActivity, to show the next 205 animation frame. 206 */ 207 bool setIntrinsicAnimationFrame( ::std::size_t nCurrFrame ); 208 209 /** forces the drawshape to load and return a specially 210 crafted metafile, usable to display drawing layer text 211 animations. 212 */ 213 GDIMetaFileSharedPtr forceScrollTextMetaFile(); 214 215 private: 216 /** Create a shape for the given XShape 217 218 @param xShape 219 The XShape to represent. 220 221 @param xContainingPage 222 The page that contains this shape. Needed for proper 223 import (currently, the UnoGraphicExporter needs this 224 information). 225 226 @param nPrio 227 Externally-determined shape priority (used e.g. for 228 paint ordering). This number _must be_ unique! 229 230 @param bForeignSource 231 When true, the source of the shape metafile might be a 232 foreign application. The metafile is checked against 233 unsupported content, and, if necessary, returned as a 234 pre-rendererd bitmap. 235 */ 236 DrawShape( const ::com::sun::star::uno::Reference< 237 ::com::sun::star::drawing::XShape >& xShape, 238 const ::com::sun::star::uno::Reference< 239 ::com::sun::star::drawing::XDrawPage >& xContainingPage, 240 double nPrio, 241 bool bForeignSource, 242 const SlideShowContext& rContext ); // throw ShapeLoadFailedException; 243 244 /** Create a shape for the given XShape and graphic content 245 246 @param xShape 247 The XShape to represent. 248 249 @param xContainingPage 250 The page that contains this shape. Needed for proper 251 import (currently, the UnoGraphicExporter needs this 252 information). 253 254 @param nPrio 255 Externally-determined shape priority (used e.g. for 256 paint ordering). This number _must be_ unique! 257 258 @param rGraphic 259 Graphic to display in the shape's bound rect. If this 260 Graphic contains animatable content, the created 261 DrawShape will register itself for intrinsic animation 262 events. 263 */ 264 DrawShape( const ::com::sun::star::uno::Reference< 265 ::com::sun::star::drawing::XShape >& xShape, 266 const ::com::sun::star::uno::Reference< 267 ::com::sun::star::drawing::XDrawPage >& xContainingPage, 268 double nPrio, 269 const Graphic& rGraphic, 270 const SlideShowContext& rContext ); // throw ShapeLoadFailedException; 271 272 /** Private copy constructor 273 274 Used to create subsetted shapes 275 */ 276 DrawShape( const DrawShape&, const DocTreeNode& rTreeNode, double nPrio ); 277 278 int getUpdateFlags() const; 279 bool implRender( int nUpdateFlags ) const; 280 void updateStateIds() const; 281 282 ViewShape::RenderArgs getViewRenderArgs() const; 283 ::basegfx::B2DRectangle getActualUnitShapeBounds() const; 284 285 void ensureVerboseMtfComments() const; 286 bool hasIntrinsicAnimation() const; 287 bool hasHyperlinks() const; 288 void prepareHyperlinkIndices() const; 289 290 /// The associated XShape 291 ::com::sun::star::uno::Reference< 292 ::com::sun::star::drawing::XShape > mxShape; 293 ::com::sun::star::uno::Reference< 294 ::com::sun::star::drawing::XDrawPage > mxPage; 295 296 /** A vector of metafiles actually representing the Shape. 297 298 If this shape is not animated, only a single entry is 299 available. 300 */ 301 mutable VectorOfMtfAnimationFrames maAnimationFrames; 302 ::std::size_t mnCurrFrame; 303 304 /// Metafile of currently active frame (static for shapes w/o intrinsic animation) 305 mutable GDIMetaFileSharedPtr mpCurrMtf; 306 307 /// loadflags of current meta file 308 mutable int mnCurrMtfLoadFlags; 309 310 /// Contains the current shape bounds, in unit rect space 311 mutable ::boost::optional<basegfx::B2DRectangle> maCurrentShapeUnitBounds; 312 313 // The attributes of this Shape 314 const double mnPriority; 315 ::basegfx::B2DRectangle maBounds; // always needed for rendering. 316 // for subset shapes, this member 317 // might change when views are 318 // added, as minimal bounds are 319 // calculated 320 321 // Pointer to modifiable shape attributes 322 ShapeAttributeLayerSharedPtr mpAttributeLayer; // only created lazily 323 324 // held here, to signal our destruction 325 boost::weak_ptr<Activity> mpIntrinsicAnimationActivity; 326 327 // The attribute states, to detect attribute changes, 328 // without buffering and querying each single attribute 329 mutable State::StateId mnAttributeTransformationState; 330 mutable State::StateId mnAttributeClipState; 331 mutable State::StateId mnAttributeAlphaState; 332 mutable State::StateId mnAttributePositionState; 333 mutable State::StateId mnAttributeContentState; 334 mutable State::StateId mnAttributeVisibilityState; 335 336 /// the list of active view shapes (one for each registered view layer) 337 typedef ::std::vector< ViewShapeSharedPtr > ViewShapeVector; 338 ViewShapeVector maViewShapes; 339 340 ::com::sun::star::uno::Reference< 341 ::com::sun::star::uno::XComponentContext> mxComponentContext; 342 343 /// hyperlink support 344 typedef ::std::pair<sal_Int32 /* mtf start */, 345 sal_Int32 /* mtf end */> HyperlinkIndexPair; 346 typedef ::std::vector<HyperlinkIndexPair> HyperlinkIndexPairVector; 347 mutable HyperlinkIndexPairVector maHyperlinkIndices; 348 mutable HyperlinkRegions maHyperlinkRegions; 349 350 /// Delegated subset handling 351 mutable DrawShapeSubsetting maSubsetting; 352 353 /// Whether this shape is currently in animation mode (value != 0) 354 int mnIsAnimatedCount; 355 356 /// Number of times the bitmap animation shall loop 357 ::std::size_t mnAnimationLoopCount; 358 359 /// Cycle mode for bitmap animation 360 CycleMode meCycleMode; 361 362 /// Whether shape is visible (without attribute layers) 363 bool mbIsVisible; 364 365 /// Whether redraw is necessary, regardless of state ids 366 mutable bool mbForceUpdate; 367 368 /// Whether attribute layer was revoked (making a redraw necessary) 369 mutable bool mbAttributeLayerRevoked; 370 371 /// whether a drawing layer animation has to be performed 372 bool mbDrawingLayerAnim; 373 374 }; 375 } 376 } 377 378 #endif /* INCLUDED_SLIDESHOW_DRAWSHAPE_HXX */ 379