1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterCanvas.hxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef SD_PRESENTER_PRESENTER_CANVAS_HXX
33 #define SD_PRESENTER_PRESENTER_CANVAS_HXX
35 #include "CanvasUpdateRequester.hxx"
36 #include <basegfx/range/b2drectangle.hxx>
37 #include <com/sun/star/awt/Point.hpp>
38 #include <com/sun/star/awt/XWindow.hpp>
39 #include <com/sun/star/awt/XWindowListener.hpp>
40 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
41 #include <com/sun/star/lang/XInitialization.hpp>
42 #include <com/sun/star/lang/IllegalArgumentException.hpp>
43 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
44 #include <com/sun/star/rendering/VolatileContentDestroyedException.hpp>
45 #include <cppuhelper/basemutex.hxx>
46 #include <cppuhelper/compbase4.hxx>
47 #include <boost/noncopyable.hpp>
48 #include <boost/shared_ptr.hpp>
50 namespace css
= ::com::sun::star
;
52 namespace sd
{ namespace presenter
{
55 typedef ::cppu::WeakComponentImplHelper4
<
56 css::rendering::XSpriteCanvas
,
57 css::rendering::XBitmap
,
58 css::awt::XWindowListener
,
59 css::lang::XInitialization
60 > PresenterCanvasInterfaceBase
;
63 /** Wrapper around a shared canvas that forwards most of its methods to the
64 shared canvas. Most notable differences are:
65 1. The transformation of the ViewState of forwarded calls is modified by adding
67 2. The clip polygon of the ViewState of forwarded calls is intersected
68 with a clip rectangle that can be set via SetClip().
69 3. Calls to updateScreen() are collected. One call to the updateScreen()
70 method of the shared canvas is made asynchronously.
72 The canvas can use different canvases for sharing and for sprite
73 construction. This allows the shared canvas to be a canvas of sprite itself.
76 : private ::boost::noncopyable
,
77 private ::cppu::BaseMutex
,
78 public PresenterCanvasInterfaceBase
81 /** This constructor is used when a PresenterCanvas object is created as
84 PresenterCanvas (void);
86 /** This constructor is used when a PresenterCanvas object is created
87 directly, typically by the PresenterCanvasFactory.
89 This canvas is used to call updateScreen() at and to create
90 sprites. In the typical case this canvas is identical to the
91 rxSharedCanvas argument.
93 The window that belongs to the canvas given by the
94 rxUpdateCanvas argument.
96 The canvas that is wrapped by the new instance of this class.
97 Typically this is a regular XSpriteCanvas and then is identical
98 to the one given by the rxUpdateCanvas argument. It may be the
99 canvas of a sprite which does not support the XSpriteCanvas
100 interface. In that case the canvas that created the sprite can
101 be given as rxUpdateCanvas argument to allow to create further
102 sprites and to have proper calls to updateScreen().
103 @param rxSharedWindow
104 The window that belongs to the canvas given by the
105 rxSharedCanvas argument.
107 The window that is represented by the new PresenterCanvas
108 object. It is expected to be a direct decendent of
109 rxSharedWindow. Its position inside rxSharedWindow defines the
110 offset of the canvas implemented by the new PresenterCanvas
111 object and rxSharedCanvas.
114 const css::uno::Reference
<css::rendering::XSpriteCanvas
>& rxUpdateCanvas
,
115 const css::uno::Reference
<css::awt::XWindow
>& rxUpdateWindow
,
116 const css::uno::Reference
<css::rendering::XCanvas
>& rxSharedCanvas
,
117 const css::uno::Reference
<css::awt::XWindow
>& rxSharedWindow
,
118 const css::uno::Reference
<css::awt::XWindow
>& rxWindow
);
119 virtual ~PresenterCanvas (void);
121 virtual void SAL_CALL
disposing (void)
122 throw (css::uno::RuntimeException
);
124 css::awt::Point
GetOffset (const css::uno::Reference
<css::awt::XWindow
>& rxBaseWindow
);
126 /** Merge the given view state with the view state that translates the
127 (virtual) child canvas to the shared canvas.
129 css::rendering::ViewState
MergeViewState (
130 const css::rendering::ViewState
& rViewState
,
131 const css::awt::Point
& raOffset
);
133 css::uno::Reference
<css::rendering::XCanvas
> GetSharedCanvas (void) const;
135 /** This method is typically called by CanvasPane objects to set the
136 repaint rectangle of a windowPaint() call as clip rectangle. When
137 no or an empty rectangle is given then the window bounds are used
139 @param rClipRectangle
140 A valid rectangle is used to clip the view state clip polygon.
141 When an empty rectangle is given then the view state clip
142 polygons are clipped against the window bounds.
144 void SetClip (const css::awt::Rectangle
& rClipRectangle
);
146 /** Called by custom sprites to update their clip polygon so that they
147 are clipped at the borders of the canvas. This method has to be
148 called after each change of the sprite location so that the bounds
149 of the canvas can be transformed into the coordinate system of the
152 css::uno::Reference
<css::rendering::XPolyPolygon2D
> UpdateSpriteClip (
153 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& rxOriginalClip
,
154 const css::geometry::RealPoint2D
& rLocation
,
155 const css::geometry::RealSize2D
& rSize
);
160 virtual void SAL_CALL
initialize (
161 const css::uno::Sequence
<css::uno::Any
>& rArguments
)
162 throw(css::uno::Exception
, css::uno::RuntimeException
);
167 virtual void SAL_CALL
clear (void)
168 throw (css::uno::RuntimeException
);
170 virtual void SAL_CALL
drawPoint (
171 const css::geometry::RealPoint2D
& aPoint
,
172 const css::rendering::ViewState
& aViewState
,
173 const css::rendering::RenderState
& aRenderState
)
174 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
176 virtual void SAL_CALL
drawLine (
177 const css::geometry::RealPoint2D
& aStartPoint
,
178 const css::geometry::RealPoint2D
& aEndPoint
,
179 const css::rendering::ViewState
& aViewState
,
180 const css::rendering::RenderState
& aRenderState
)
181 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
183 virtual void SAL_CALL
drawBezier (
184 const css::geometry::RealBezierSegment2D
& aBezierSegment
,
185 const css::geometry::RealPoint2D
& aEndPoint
,
186 const css::rendering::ViewState
& aViewState
,
187 const css::rendering::RenderState
& aRenderState
)
188 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
190 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
drawPolyPolygon (
191 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
192 const css::rendering::ViewState
& aViewState
,
193 const css::rendering::RenderState
& aRenderState
)
194 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
196 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
strokePolyPolygon (
197 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
198 const css::rendering::ViewState
& aViewState
,
199 const css::rendering::RenderState
& aRenderState
,
200 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
201 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
203 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
204 strokeTexturedPolyPolygon (
205 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
206 const css::rendering::ViewState
& aViewState
,
207 const css::rendering::RenderState
& aRenderState
,
208 const css::uno::Sequence
< css::rendering::Texture
>& aTextures
,
209 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
210 throw (css::lang::IllegalArgumentException
,
211 css::rendering::VolatileContentDestroyedException
,
212 css::uno::RuntimeException
);
214 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
215 strokeTextureMappedPolyPolygon(
216 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
217 const css::rendering::ViewState
& aViewState
,
218 const css::rendering::RenderState
& aRenderState
,
219 const css::uno::Sequence
<css::rendering::Texture
>& aTextures
,
220 const css::uno::Reference
<css::geometry::XMapping2D
>& xMapping
,
221 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
222 throw (css::lang::IllegalArgumentException
,
223 css::rendering::VolatileContentDestroyedException
,
224 css::uno::RuntimeException
);
226 virtual css::uno::Reference
<css::rendering::XPolyPolygon2D
> SAL_CALL
228 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
229 const css::rendering::ViewState
& aViewState
,
230 const css::rendering::RenderState
& aRenderState
,
231 const css::rendering::StrokeAttributes
& aStrokeAttributes
)
232 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
234 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
236 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
237 const css::rendering::ViewState
& aViewState
,
238 const css::rendering::RenderState
& aRenderState
)
239 throw (css::lang::IllegalArgumentException
,
240 css::uno::RuntimeException
);
242 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
243 fillTexturedPolyPolygon(
244 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
245 const css::rendering::ViewState
& aViewState
,
246 const css::rendering::RenderState
& aRenderState
,
247 const css::uno::Sequence
<css::rendering::Texture
>& xTextures
)
248 throw (css::lang::IllegalArgumentException
,
249 css::rendering::VolatileContentDestroyedException
,
250 css::uno::RuntimeException
);
252 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
253 fillTextureMappedPolyPolygon(
254 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
255 const css::rendering::ViewState
& aViewState
,
256 const css::rendering::RenderState
& aRenderState
,
257 const css::uno::Sequence
< css::rendering::Texture
>& xTextures
,
258 const css::uno::Reference
< css::geometry::XMapping2D
>& xMapping
)
259 throw (css::lang::IllegalArgumentException
,
260 css::rendering::VolatileContentDestroyedException
,
261 css::uno::RuntimeException
);
263 virtual css::uno::Reference
<css::rendering::XCanvasFont
> SAL_CALL
265 const css::rendering::FontRequest
& aFontRequest
,
266 const css::uno::Sequence
< css::beans::PropertyValue
>& aExtraFontProperties
,
267 const css::geometry::Matrix2D
& aFontMatrix
)
268 throw (css::lang::IllegalArgumentException
,
269 css::uno::RuntimeException
);
271 virtual css::uno::Sequence
<css::rendering::FontInfo
> SAL_CALL
273 const css::rendering::FontInfo
& aFilter
,
274 const css::uno::Sequence
< css::beans::PropertyValue
>& aFontProperties
)
275 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
277 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
279 const css::rendering::StringContext
& aText
,
280 const css::uno::Reference
< css::rendering::XCanvasFont
>& xFont
,
281 const css::rendering::ViewState
& aViewState
,
282 const css::rendering::RenderState
& aRenderState
,
283 ::sal_Int8 nTextDirection
)
284 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
286 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
288 const css::uno::Reference
< css::rendering::XTextLayout
>& xLayoutetText
,
289 const css::rendering::ViewState
& aViewState
,
290 const css::rendering::RenderState
& aRenderState
)
291 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
293 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
295 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
296 const css::rendering::ViewState
& aViewState
,
297 const css::rendering::RenderState
& aRenderState
)
298 throw (css::lang::IllegalArgumentException
,
299 css::rendering::VolatileContentDestroyedException
,
300 css::uno::RuntimeException
);
302 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
304 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
305 const css::rendering::ViewState
& aViewState
,
306 const css::rendering::RenderState
& aRenderState
)
307 throw (css::lang::IllegalArgumentException
,
308 css::rendering::VolatileContentDestroyedException
,
309 css::uno::RuntimeException
);
311 virtual css::uno::Reference
<css::rendering::XGraphicDevice
> SAL_CALL
313 throw (css::uno::RuntimeException
);
318 void SAL_CALL
copyRect(
319 const css::uno::Reference
< css::rendering::XBitmapCanvas
>& sourceCanvas
,
320 const css::geometry::RealRectangle2D
& sourceRect
,
321 const css::rendering::ViewState
& sourceViewState
,
322 const css::rendering::RenderState
& sourceRenderState
,
323 const css::geometry::RealRectangle2D
& destRect
,
324 const css::rendering::ViewState
& destViewState
,
325 const css::rendering::RenderState
& destRenderState
)
326 throw (css::lang::IllegalArgumentException
,
327 css::rendering::VolatileContentDestroyedException
,
328 css::uno::RuntimeException
);
333 css::uno::Reference
< css::rendering::XAnimatedSprite
> SAL_CALL
334 createSpriteFromAnimation (
335 const css::uno::Reference
< css::rendering::XAnimation
>& animation
)
336 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
338 css::uno::Reference
< css::rendering::XAnimatedSprite
> SAL_CALL
339 createSpriteFromBitmaps (
340 const css::uno::Sequence
<
341 css::uno::Reference
< css::rendering::XBitmap
> >& animationBitmaps
,
342 ::sal_Int8 interpolationMode
)
343 throw (css::lang::IllegalArgumentException
,
344 css::rendering::VolatileContentDestroyedException
,
345 css::uno::RuntimeException
);
347 css::uno::Reference
< css::rendering::XCustomSprite
> SAL_CALL
349 const css::geometry::RealSize2D
& spriteSize
)
350 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
352 css::uno::Reference
< css::rendering::XSprite
> SAL_CALL
354 const css::uno::Reference
< css::rendering::XSprite
>& original
)
355 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
357 ::sal_Bool SAL_CALL
updateScreen (::sal_Bool bUpdateAll
)
358 throw (css::uno::RuntimeException
);
363 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
)
364 throw (css::uno::RuntimeException
);
369 virtual void SAL_CALL
windowResized (const css::awt::WindowEvent
& rEvent
)
370 throw (css::uno::RuntimeException
);
372 virtual void SAL_CALL
windowMoved (const css::awt::WindowEvent
& rEvent
)
373 throw (css::uno::RuntimeException
);
375 virtual void SAL_CALL
windowShown (const css::lang::EventObject
& rEvent
)
376 throw (css::uno::RuntimeException
);
378 virtual void SAL_CALL
windowHidden (const css::lang::EventObject
& rEvent
)
379 throw (css::uno::RuntimeException
);
384 virtual css::geometry::IntegerSize2D SAL_CALL
getSize (void)
385 throw (css::uno::RuntimeException
);
387 virtual sal_Bool SAL_CALL
hasAlpha (void)
388 throw (css::uno::RuntimeException
);
390 virtual css::uno::Reference
<css::rendering::XBitmapCanvas
> SAL_CALL
queryBitmapCanvas (void)
391 throw (css::uno::RuntimeException
);
393 virtual css::uno::Reference
<css::rendering::XBitmap
> SAL_CALL
getScaledBitmap(
394 const css::geometry::RealSize2D
& rNewSize
,
396 throw (css::uno::RuntimeException
,
397 css::lang::IllegalArgumentException
,
398 css::rendering::VolatileContentDestroyedException
);
401 css::uno::Reference
<css::rendering::XSpriteCanvas
> mxUpdateCanvas
;
402 css::uno::Reference
<css::awt::XWindow
> mxUpdateWindow
;
403 css::uno::Reference
<css::rendering::XCanvas
> mxSharedCanvas
;
404 css::uno::Reference
<css::awt::XWindow
> mxSharedWindow
;
406 /** The window for which a canvas is emulated.
408 css::uno::Reference
<css::awt::XWindow
> mxWindow
;
410 /** Offset of the emulated canvas with respect to the shared canvas.
412 css::awt::Point maOffset
;
414 /** The UpdateRequester is used by updateScreen() to schedule
415 updateScreen() calls at the shared canvas.
417 ::boost::shared_ptr
<CanvasUpdateRequester
> mpUpdateRequester
;
419 /** The clip rectangle as given to SetClip().
421 css::awt::Rectangle maClipRectangle
;
423 /** When this flag is true (it is set to true after every call to
424 updateScreen()) then the next call to MergeViewState updates the
425 maOffset member. A possible optimization would set this flag only
426 to true when one of the windows between mxWindow and mxSharedWindow
427 changes its position.
429 bool mbOffsetUpdatePending
;
431 ::basegfx::B2DRectangle
GetClipRectangle (
432 const css::geometry::AffineMatrix2D
& rViewTransform
,
433 const css::awt::Point
& rOffset
);
435 css::rendering::ViewState
MergeViewState (const css::rendering::ViewState
& rViewState
);
437 /** This method throws a DisposedException when the object has already been
440 void ThrowIfDisposed (void)
441 throw (css::lang::DisposedException
);
446 } } // end of namespace ::sd::presenter