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 throw (css::uno::RuntimeException); 115 116 css::awt::Point GetOffset (const css::uno::Reference<css::awt::XWindow>& rxBaseWindow); 117 118 /** Merge the given view state with the view state that translates the 119 (virtual) child canvas to the shared canvas. 120 */ 121 css::rendering::ViewState MergeViewState ( 122 const css::rendering::ViewState& rViewState, 123 const css::awt::Point& raOffset); 124 125 css::uno::Reference<css::rendering::XCanvas> GetSharedCanvas (void) const; 126 127 /** This method is typically called by CanvasPane objects to set the 128 repaint rectangle of a windowPaint() call as clip rectangle. When 129 no or an empty rectangle is given then the window bounds are used 130 instead. 131 @param rClipRectangle 132 A valid rectangle is used to clip the view state clip polygon. 133 When an empty rectangle is given then the view state clip 134 polygons are clipped against the window bounds. 135 */ 136 void SetClip (const css::awt::Rectangle& rClipRectangle); 137 138 /** Called by custom sprites to update their clip polygon so that they 139 are clipped at the borders of the canvas. This method has to be 140 called after each change of the sprite location so that the bounds 141 of the canvas can be transformed into the coordinate system of the 142 sprite. 143 */ 144 css::uno::Reference<css::rendering::XPolyPolygon2D> UpdateSpriteClip ( 145 const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxOriginalClip, 146 const css::geometry::RealPoint2D& rLocation, 147 const css::geometry::RealSize2D& rSize); 148 149 150 // XInitialization 151 152 virtual void SAL_CALL initialize ( 153 const css::uno::Sequence<css::uno::Any>& rArguments) 154 throw(css::uno::Exception, css::uno::RuntimeException); 155 156 157 // XCanvas 158 159 virtual void SAL_CALL clear (void) 160 throw (css::uno::RuntimeException); 161 162 virtual void SAL_CALL drawPoint ( 163 const css::geometry::RealPoint2D& aPoint, 164 const css::rendering::ViewState& aViewState, 165 const css::rendering::RenderState& aRenderState) 166 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 167 168 virtual void SAL_CALL drawLine ( 169 const css::geometry::RealPoint2D& aStartPoint, 170 const css::geometry::RealPoint2D& aEndPoint, 171 const css::rendering::ViewState& aViewState, 172 const css::rendering::RenderState& aRenderState) 173 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 174 175 virtual void SAL_CALL drawBezier ( 176 const css::geometry::RealBezierSegment2D& aBezierSegment, 177 const css::geometry::RealPoint2D& aEndPoint, 178 const css::rendering::ViewState& aViewState, 179 const css::rendering::RenderState& aRenderState) 180 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 181 182 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL drawPolyPolygon ( 183 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 184 const css::rendering::ViewState& aViewState, 185 const css::rendering::RenderState& aRenderState) 186 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 187 188 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL strokePolyPolygon ( 189 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 190 const css::rendering::ViewState& aViewState, 191 const css::rendering::RenderState& aRenderState, 192 const css::rendering::StrokeAttributes& aStrokeAttributes) 193 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 194 195 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 196 strokeTexturedPolyPolygon ( 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::rendering::StrokeAttributes& aStrokeAttributes) 202 throw (css::lang::IllegalArgumentException, 203 css::rendering::VolatileContentDestroyedException, 204 css::uno::RuntimeException); 205 206 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 207 strokeTextureMappedPolyPolygon( 208 const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon, 209 const css::rendering::ViewState& aViewState, 210 const css::rendering::RenderState& aRenderState, 211 const css::uno::Sequence<css::rendering::Texture>& aTextures, 212 const css::uno::Reference<css::geometry::XMapping2D>& xMapping, 213 const css::rendering::StrokeAttributes& aStrokeAttributes) 214 throw (css::lang::IllegalArgumentException, 215 css::rendering::VolatileContentDestroyedException, 216 css::uno::RuntimeException); 217 218 virtual css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL 219 queryStrokeShapes( 220 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon, 221 const css::rendering::ViewState& aViewState, 222 const css::rendering::RenderState& aRenderState, 223 const css::rendering::StrokeAttributes& aStrokeAttributes) 224 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 225 226 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 227 fillPolyPolygon( 228 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon, 229 const css::rendering::ViewState& aViewState, 230 const css::rendering::RenderState& aRenderState) 231 throw (css::lang::IllegalArgumentException, 232 css::uno::RuntimeException); 233 234 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 235 fillTexturedPolyPolygon( 236 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon, 237 const css::rendering::ViewState& aViewState, 238 const css::rendering::RenderState& aRenderState, 239 const css::uno::Sequence<css::rendering::Texture>& xTextures) 240 throw (css::lang::IllegalArgumentException, 241 css::rendering::VolatileContentDestroyedException, 242 css::uno::RuntimeException); 243 244 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 245 fillTextureMappedPolyPolygon( 246 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon, 247 const css::rendering::ViewState& aViewState, 248 const css::rendering::RenderState& aRenderState, 249 const css::uno::Sequence< css::rendering::Texture >& xTextures, 250 const css::uno::Reference< css::geometry::XMapping2D >& xMapping) 251 throw (css::lang::IllegalArgumentException, 252 css::rendering::VolatileContentDestroyedException, 253 css::uno::RuntimeException); 254 255 virtual css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL 256 createFont( 257 const css::rendering::FontRequest& aFontRequest, 258 const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties, 259 const css::geometry::Matrix2D& aFontMatrix) 260 throw (css::lang::IllegalArgumentException, 261 css::uno::RuntimeException); 262 263 virtual css::uno::Sequence<css::rendering::FontInfo> SAL_CALL 264 queryAvailableFonts( 265 const css::rendering::FontInfo& aFilter, 266 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties) 267 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 268 269 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 270 drawText( 271 const css::rendering::StringContext& aText, 272 const css::uno::Reference< css::rendering::XCanvasFont >& xFont, 273 const css::rendering::ViewState& aViewState, 274 const css::rendering::RenderState& aRenderState, 275 ::sal_Int8 nTextDirection) 276 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 277 278 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 279 drawTextLayout( 280 const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText, 281 const css::rendering::ViewState& aViewState, 282 const css::rendering::RenderState& aRenderState) 283 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 284 285 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 286 drawBitmap( 287 const css::uno::Reference< css::rendering::XBitmap >& xBitmap, 288 const css::rendering::ViewState& aViewState, 289 const css::rendering::RenderState& aRenderState) 290 throw (css::lang::IllegalArgumentException, 291 css::rendering::VolatileContentDestroyedException, 292 css::uno::RuntimeException); 293 294 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL 295 drawBitmapModulated( 296 const css::uno::Reference< css::rendering::XBitmap>& xBitmap, 297 const css::rendering::ViewState& aViewState, 298 const css::rendering::RenderState& aRenderState) 299 throw (css::lang::IllegalArgumentException, 300 css::rendering::VolatileContentDestroyedException, 301 css::uno::RuntimeException); 302 303 virtual css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL 304 getDevice (void) 305 throw (css::uno::RuntimeException); 306 307 308 // XBitmapCanvas 309 310 void SAL_CALL copyRect( 311 const css::uno::Reference< css::rendering::XBitmapCanvas >& sourceCanvas, 312 const css::geometry::RealRectangle2D& sourceRect, 313 const css::rendering::ViewState& sourceViewState, 314 const css::rendering::RenderState& sourceRenderState, 315 const css::geometry::RealRectangle2D& destRect, 316 const css::rendering::ViewState& destViewState, 317 const css::rendering::RenderState& destRenderState) 318 throw (css::lang::IllegalArgumentException, 319 css::rendering::VolatileContentDestroyedException, 320 css::uno::RuntimeException); 321 322 323 // XSpriteCanvas 324 325 css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL 326 createSpriteFromAnimation ( 327 const css::uno::Reference< css::rendering::XAnimation >& animation) 328 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 329 330 css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL 331 createSpriteFromBitmaps ( 332 const css::uno::Sequence< 333 css::uno::Reference< css::rendering::XBitmap > >& animationBitmaps, 334 ::sal_Int8 interpolationMode) 335 throw (css::lang::IllegalArgumentException, 336 css::rendering::VolatileContentDestroyedException, 337 css::uno::RuntimeException); 338 339 css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL 340 createCustomSprite ( 341 const css::geometry::RealSize2D& spriteSize) 342 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 343 344 css::uno::Reference< css::rendering::XSprite > SAL_CALL 345 createClonedSprite ( 346 const css::uno::Reference< css::rendering::XSprite >& original) 347 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); 348 349 ::sal_Bool SAL_CALL updateScreen (::sal_Bool bUpdateAll) 350 throw (css::uno::RuntimeException); 351 352 353 // XEventListener 354 355 virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) 356 throw (css::uno::RuntimeException); 357 358 359 // XWindowListener 360 361 virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent) 362 throw (css::uno::RuntimeException); 363 364 virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent) 365 throw (css::uno::RuntimeException); 366 367 virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent) 368 throw (css::uno::RuntimeException); 369 370 virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent) 371 throw (css::uno::RuntimeException); 372 373 374 // XBitmap 375 376 virtual css::geometry::IntegerSize2D SAL_CALL getSize (void) 377 throw (css::uno::RuntimeException); 378 379 virtual sal_Bool SAL_CALL hasAlpha (void) 380 throw (css::uno::RuntimeException); 381 382 virtual css::uno::Reference<css::rendering::XBitmapCanvas> SAL_CALL queryBitmapCanvas (void) 383 throw (css::uno::RuntimeException); 384 385 virtual css::uno::Reference<css::rendering::XBitmap> SAL_CALL getScaledBitmap( 386 const css::geometry::RealSize2D& rNewSize, 387 sal_Bool bFast) 388 throw (css::uno::RuntimeException, 389 css::lang::IllegalArgumentException, 390 css::rendering::VolatileContentDestroyedException); 391 392 private: 393 css::uno::Reference<css::rendering::XSpriteCanvas> mxUpdateCanvas; 394 css::uno::Reference<css::awt::XWindow> mxUpdateWindow; 395 css::uno::Reference<css::rendering::XCanvas> mxSharedCanvas; 396 css::uno::Reference<css::awt::XWindow> mxSharedWindow; 397 398 /** The window for which a canvas is emulated. 399 */ 400 css::uno::Reference<css::awt::XWindow> mxWindow; 401 402 /** Offset of the emulated canvas with respect to the shared canvas. 403 */ 404 css::awt::Point maOffset; 405 406 /** The UpdateRequester is used by updateScreen() to schedule 407 updateScreen() calls at the shared canvas. 408 */ 409 ::boost::shared_ptr<CanvasUpdateRequester> mpUpdateRequester; 410 411 /** The clip rectangle as given to SetClip(). 412 */ 413 css::awt::Rectangle maClipRectangle; 414 415 /** When this flag is true (it is set to true after every call to 416 updateScreen()) then the next call to MergeViewState updates the 417 maOffset member. A possible optimization would set this flag only 418 to true when one of the windows between mxWindow and mxSharedWindow 419 changes its position. 420 */ 421 bool mbOffsetUpdatePending; 422 423 ::basegfx::B2DRectangle GetClipRectangle ( 424 const css::geometry::AffineMatrix2D& rViewTransform, 425 const css::awt::Point& rOffset); 426 427 css::rendering::ViewState MergeViewState (const css::rendering::ViewState& rViewState); 428 429 /** This method throws a DisposedException when the object has already been 430 disposed. 431 */ 432 void ThrowIfDisposed (void) 433 throw (css::lang::DisposedException); 434 }; 435 436 437 438 } } // end of namespace ::sd::presenter 439 440 #endif 441