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 SD_PRESENTER_PRESENTER_CANVAS_HXX 25 #define SD_PRESENTER_PRESENTER_CANVAS_HXX 26 27 #include "CanvasUpdateRequester.hxx" 28 #include <basegfx/range/b2drectangle.hxx> 29 #include <com/sun/star/awt/Point.hpp> 30 #include <com/sun/star/awt/XWindow.hpp> 31 #include <com/sun/star/awt/XWindowListener.hpp> 32 #include <com/sun/star/geometry/AffineMatrix2D.hpp> 33 #include <com/sun/star/lang/XInitialization.hpp> 34 #include <com/sun/star/lang/IllegalArgumentException.hpp> 35 #include <com/sun/star/rendering/XSpriteCanvas.hpp> 36 #include <com/sun/star/rendering/VolatileContentDestroyedException.hpp> 37 #include <cppuhelper/basemutex.hxx> 38 #include <cppuhelper/compbase4.hxx> 39 #include <boost/noncopyable.hpp> 40 #include <boost/shared_ptr.hpp> 41 42 namespace css = ::com::sun::star; 43 44 namespace sd { namespace presenter { 45 46 namespace { 47 typedef ::cppu::WeakComponentImplHelper4 < 48 css::rendering::XSpriteCanvas, 49 css::rendering::XBitmap, 50 css::awt::XWindowListener, 51 css::lang::XInitialization 52 > PresenterCanvasInterfaceBase; 53 } 54 55 /** Wrapper around a shared canvas that forwards most of its methods to the 56 shared canvas. Most notable differences are: 57 1. The transformation of the ViewState of forwarded calls is modified by adding 58 an offset. 59 2. The clip polygon of the ViewState of forwarded calls is intersected 60 with a clip rectangle that can be set via SetClip(). 61 3. Calls to updateScreen() are collected. One call to the updateScreen() 62 method of the shared canvas is made asynchronously. 63 64 The canvas can use different canvases for sharing and for sprite 65 construction. This allows the shared canvas to be a canvas of sprite itself. 66 */ 67 class PresenterCanvas 68 : private ::boost::noncopyable, 69 private ::cppu::BaseMutex, 70 public PresenterCanvasInterfaceBase 71 { 72 public: 73 /** This constructor is used when a PresenterCanvas object is created as 74 a service. 75 */ 76 PresenterCanvas (void); 77 78 /** This constructor is used when a PresenterCanvas object is created 79 directly, typically by the PresenterCanvasFactory. 80 @param rxUpdateCanvas 81 This canvas is used to call updateScreen() at and to create 82 sprites. In the typical case this canvas is identical to the 83 rxSharedCanvas argument. 84 @param rxUpdateWindow 85 The window that belongs to the canvas given by the 86 rxUpdateCanvas argument. 87 @param rxSharedCanvas 88 The canvas that is wrapped by the new instance of this class. 89 Typically this is a regular XSpriteCanvas and then is identical 90 to the one given by the rxUpdateCanvas argument. It may be the 91 canvas of a sprite which does not support the XSpriteCanvas 92 interface. In that case the canvas that created the sprite can 93 be given as rxUpdateCanvas argument to allow to create further 94 sprites and to have proper calls to updateScreen(). 95 @param rxSharedWindow 96 The window that belongs to the canvas given by the 97 rxSharedCanvas argument. 98 @param rxWindow 99 The window that is represented by the new PresenterCanvas 100 object. It is expected to be a direct descendant of 101 rxSharedWindow. Its position inside rxSharedWindow defines the 102 offset of the canvas implemented by the new PresenterCanvas 103 object and rxSharedCanvas. 104 */ 105 PresenterCanvas ( 106 const css::uno::Reference<css::rendering::XSpriteCanvas>& rxUpdateCanvas, 107 const css::uno::Reference<css::awt::XWindow>& rxUpdateWindow, 108 const css::uno::Reference<css::rendering::XCanvas>& rxSharedCanvas, 109 const css::uno::Reference<css::awt::XWindow>& rxSharedWindow, 110 const css::uno::Reference<css::awt::XWindow>& rxWindow); 111 virtual ~PresenterCanvas (void); 112 113 virtual void SAL_CALL disposing (void); 114 115 css::awt::Point GetOffset (const css::uno::Reference<css::awt::XWindow>& rxBaseWindow); 116 117 /** Merge the given view state with the view state that translates the 118 (virtual) child canvas to the shared canvas. 119 */ 120 css::rendering::ViewState MergeViewState ( 121 const css::rendering::ViewState& rViewState, 122 const css::awt::Point& raOffset); 123 124 css::uno::Reference<css::rendering::XCanvas> GetSharedCanvas (void) const; 125 126 /** This method is typically called by CanvasPane objects to set the 127 repaint rectangle of a windowPaint() call as clip rectangle. When 128 no or an empty rectangle is given then the window bounds are used 129 instead. 130 @param rClipRectangle 131 A valid rectangle is used to clip the view state clip polygon. 132 When an empty rectangle is given then the view state clip 133 polygons are clipped against the window bounds. 134 */ 135 void SetClip (const css::awt::Rectangle& rClipRectangle); 136 137 /** Called by custom sprites to update their clip polygon so that they 138 are clipped at the borders of the canvas. This method has to be 139 called after each change of the sprite location so that the bounds 140 of the canvas can be transformed into the coordinate system of the 141 sprite. 142 */ 143 css::uno::Reference<css::rendering::XPolyPolygon2D> UpdateSpriteClip ( 144 const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxOriginalClip, 145 const css::geometry::RealPoint2D& rLocation, 146 const css::geometry::RealSize2D& rSize); 147 148 149 // XInitialization 150 151 virtual void SAL_CALL initialize ( 152 const css::uno::Sequence<css::uno::Any>& rArguments); 153 154 155 // XCanvas 156 157 virtual void SAL_CALL clear (void); 158 159 virtual void SAL_CALL drawPoint ( 160 const css::geometry::RealPoint2D& aPoint, 161 const css::rendering::ViewState& aViewState, 162 const css::rendering::RenderState& aRenderState); 163 164 virtual void SAL_CALL drawLine ( 165 const css::geometry::RealPoint2D& aStartPoint, 166 const css::geometry::RealPoint2D& aEndPoint, 167 const css::rendering::ViewState& aViewState, 168 const css::rendering::RenderState& aRenderState); 169 170 virtual void SAL_CALL drawBezier ( 171 const css::geometry::RealBezierSegment2D& aBezierSegment, 172 const css::geometry::RealPoint2D& aEndPoint, 173 const css::rendering::ViewState& aViewState, 174 const css::rendering::RenderState& aRenderState); 175 176 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL drawPolyPolygon ( 177 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 178 const css::rendering::ViewState& aViewState, 179 const css::rendering::RenderState& aRenderState); 180 181 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL strokePolyPolygon ( 182 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 183 const css::rendering::ViewState& aViewState, 184 const css::rendering::RenderState& aRenderState, 185 const css::rendering::StrokeAttributes& aStrokeAttributes); 186 187 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 188 strokeTexturedPolyPolygon ( 189 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 190 const css::rendering::ViewState& aViewState, 191 const css::rendering::RenderState& aRenderState, 192 const css::uno::Sequence< css::rendering::Texture >& aTextures, 193 const css::rendering::StrokeAttributes& aStrokeAttributes); 194 195 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 196 strokeTextureMappedPolyPolygon( 197 const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon, 198 const css::rendering::ViewState& aViewState, 199 const css::rendering::RenderState& aRenderState, 200 const css::uno::Sequence<css::rendering::Texture>& aTextures, 201 const css::uno::Reference<css::geometry::XMapping2D>& xMapping, 202 const css::rendering::StrokeAttributes& aStrokeAttributes); 203 204 virtual css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL 205 queryStrokeShapes( 206 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon, 207 const css::rendering::ViewState& aViewState, 208 const css::rendering::RenderState& aRenderState, 209 const css::rendering::StrokeAttributes& aStrokeAttributes); 210 211 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 212 fillPolyPolygon( 213 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon, 214 const css::rendering::ViewState& aViewState, 215 const css::rendering::RenderState& aRenderState); 216 217 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 218 fillTexturedPolyPolygon( 219 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon, 220 const css::rendering::ViewState& aViewState, 221 const css::rendering::RenderState& aRenderState, 222 const css::uno::Sequence<css::rendering::Texture>& xTextures); 223 224 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 225 fillTextureMappedPolyPolygon( 226 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 227 const css::rendering::ViewState& aViewState, 228 const css::rendering::RenderState& aRenderState, 229 const css::uno::Sequence< css::rendering::Texture >& xTextures, 230 const css::uno::Reference< css::geometry::XMapping2D >& xMapping); 231 232 virtual css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL 233 createFont( 234 const css::rendering::FontRequest& aFontRequest, 235 const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties, 236 const css::geometry::Matrix2D& aFontMatrix); 237 238 virtual css::uno::Sequence<css::rendering::FontInfo> SAL_CALL 239 queryAvailableFonts( 240 const css::rendering::FontInfo& aFilter, 241 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties); 242 243 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 244 drawText( 245 const css::rendering::StringContext& aText, 246 const css::uno::Reference< css::rendering::XCanvasFont >& xFont, 247 const css::rendering::ViewState& aViewState, 248 const css::rendering::RenderState& aRenderState, 249 ::sal_Int8 nTextDirection); 250 251 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 252 drawTextLayout( 253 const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText, 254 const css::rendering::ViewState& aViewState, 255 const css::rendering::RenderState& aRenderState); 256 257 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 258 drawBitmap( 259 const css::uno::Reference< css::rendering::XBitmap >& xBitmap, 260 const css::rendering::ViewState& aViewState, 261 const css::rendering::RenderState& aRenderState); 262 263 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 264 drawBitmapModulated( 265 const css::uno::Reference< css::rendering::XBitmap>& xBitmap, 266 const css::rendering::ViewState& aViewState, 267 const css::rendering::RenderState& aRenderState); 268 269 virtual css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL 270 getDevice (void); 271 272 273 // XBitmapCanvas 274 275 void SAL_CALL copyRect( 276 const css::uno::Reference< css::rendering::XBitmapCanvas >& sourceCanvas, 277 const css::geometry::RealRectangle2D& sourceRect, 278 const css::rendering::ViewState& sourceViewState, 279 const css::rendering::RenderState& sourceRenderState, 280 const css::geometry::RealRectangle2D& destRect, 281 const css::rendering::ViewState& destViewState, 282 const css::rendering::RenderState& destRenderState); 283 284 285 // XSpriteCanvas 286 287 css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL 288 createSpriteFromAnimation ( 289 const css::uno::Reference< css::rendering::XAnimation >& animation); 290 291 css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL 292 createSpriteFromBitmaps ( 293 const css::uno::Sequence< 294 css::uno::Reference< css::rendering::XBitmap > >& animationBitmaps, 295 ::sal_Int8 interpolationMode); 296 297 css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL 298 createCustomSprite ( 299 const css::geometry::RealSize2D& spriteSize); 300 301 css::uno::Reference< css::rendering::XSprite > SAL_CALL 302 createClonedSprite ( 303 const css::uno::Reference< css::rendering::XSprite >& original); 304 305 ::sal_Bool SAL_CALL updateScreen (::sal_Bool bUpdateAll); 306 307 308 // XEventListener 309 310 virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent); 311 312 313 // XWindowListener 314 315 virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent); 316 317 virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent); 318 319 virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent); 320 321 virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent); 322 323 324 // XBitmap 325 326 virtual css::geometry::IntegerSize2D SAL_CALL getSize (void); 327 328 virtual sal_Bool SAL_CALL hasAlpha (void); 329 330 virtual css::uno::Reference<css::rendering::XBitmapCanvas> SAL_CALL queryBitmapCanvas (void); 331 332 virtual css::uno::Reference<css::rendering::XBitmap> SAL_CALL getScaledBitmap( 333 const css::geometry::RealSize2D& rNewSize, 334 sal_Bool bFast); 335 336 private: 337 css::uno::Reference<css::rendering::XSpriteCanvas> mxUpdateCanvas; 338 css::uno::Reference<css::awt::XWindow> mxUpdateWindow; 339 css::uno::Reference<css::rendering::XCanvas> mxSharedCanvas; 340 css::uno::Reference<css::awt::XWindow> mxSharedWindow; 341 342 /** The window for which a canvas is emulated. 343 */ 344 css::uno::Reference<css::awt::XWindow> mxWindow; 345 346 /** Offset of the emulated canvas with respect to the shared canvas. 347 */ 348 css::awt::Point maOffset; 349 350 /** The UpdateRequester is used by updateScreen() to schedule 351 updateScreen() calls at the shared canvas. 352 */ 353 ::boost::shared_ptr<CanvasUpdateRequester> mpUpdateRequester; 354 355 /** The clip rectangle as given to SetClip(). 356 */ 357 css::awt::Rectangle maClipRectangle; 358 359 /** When this flag is true (it is set to true after every call to 360 updateScreen()) then the next call to MergeViewState updates the 361 maOffset member. A possible optimization would set this flag only 362 to true when one of the windows between mxWindow and mxSharedWindow 363 changes its position. 364 */ 365 bool mbOffsetUpdatePending; 366 367 ::basegfx::B2DRectangle GetClipRectangle ( 368 const css::geometry::AffineMatrix2D& rViewTransform, 369 const css::awt::Point& rOffset); 370 371 css::rendering::ViewState MergeViewState (const css::rendering::ViewState& rViewState); 372 373 /** This method throws a DisposedException when the object has already been 374 disposed. 375 */ 376 void ThrowIfDisposed (void); 377 }; 378 379 380 381 } } // end of namespace ::sd::presenter 382 383 #endif 384