1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <basegfx/range/b2drectangle.hxx>
23 #include <com/sun/star/awt/Point.hpp>
24 #include <com/sun/star/awt/XWindowListener.hpp>
25 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
26 #include <com/sun/star/rendering/XBitmap.hpp>
27 #include <comphelper/compbase.hxx>
30 namespace sd::presenter
{ class CanvasUpdateRequester
; }
31 namespace com::sun::star::awt
{ class XWindow
; }
32 namespace com::sun::star::geometry
{ struct AffineMatrix2D
; }
34 namespace sd::presenter
{
36 typedef comphelper::WeakComponentImplHelper
<
37 css::rendering::XSpriteCanvas
,
38 css::rendering::XBitmap
,
39 css::awt::XWindowListener
40 > PresenterCanvasInterfaceBase
;
42 /** Wrapper around a shared canvas that forwards most of its methods to the
43 shared canvas. Most notable differences are:
44 1. The transformation of the ViewState of forwarded calls is modified by adding
46 2. The clip polygon of the ViewState of forwarded calls is intersected
47 with a clip rectangle that can be set via SetClip().
48 3. Calls to updateScreen() are collected. One call to the updateScreen()
49 method of the shared canvas is made asynchronously.
51 The canvas can use different canvases for sharing and for sprite
52 construction. This allows the shared canvas to be a canvas of sprite itself.
55 : public PresenterCanvasInterfaceBase
58 /** This constructor is used when a PresenterCanvas object is created
59 directly, typically by the PresenterCanvasFactory.
61 This canvas is used to call updateScreen() at and to create
62 sprites. In the typical case this canvas is identical to the
63 rxSharedCanvas argument.
65 The window that belongs to the canvas given by the
66 rxUpdateCanvas argument.
68 The canvas that is wrapped by the new instance of this class.
69 Typically this is a regular XSpriteCanvas and then is identical
70 to the one given by the rxUpdateCanvas argument. It may be the
71 canvas of a sprite which does not support the XSpriteCanvas
72 interface. In that case the canvas that created the sprite can
73 be given as rxUpdateCanvas argument to allow to create further
74 sprites and to have proper calls to updateScreen().
76 The window that belongs to the canvas given by the
77 rxSharedCanvas argument.
79 The window that is represented by the new PresenterCanvas
80 object. It is expected to be a direct descendant of
81 rxSharedWindow. Its position inside rxSharedWindow defines the
82 offset of the canvas implemented by the new PresenterCanvas
83 object and rxSharedCanvas.
86 const css::uno::Reference
<css::rendering::XSpriteCanvas
>& rxUpdateCanvas
,
87 const css::uno::Reference
<css::awt::XWindow
>& rxUpdateWindow
,
88 const css::uno::Reference
<css::rendering::XCanvas
>& rxSharedCanvas
,
89 const css::uno::Reference
<css::awt::XWindow
>& rxSharedWindow
,
90 const css::uno::Reference
<css::awt::XWindow
>& rxWindow
);
91 virtual ~PresenterCanvas() override
;
92 PresenterCanvas(const PresenterCanvas
&) = delete;
93 PresenterCanvas
& operator=(const PresenterCanvas
&) = delete;
95 virtual void disposing(std::unique_lock
<std::mutex
>&) override
;
97 css::awt::Point
GetOffset (const css::uno::Reference
<css::awt::XWindow
>& rxBaseWindow
);
99 /** Merge the given view state with the view state that translates the
100 (virtual) child canvas to the shared canvas.
102 css::rendering::ViewState
MergeViewState (
103 const css::rendering::ViewState
& rViewState
,
104 const css::awt::Point
& raOffset
);
106 /** Called by custom sprites to update their clip polygon so that they
107 are clipped at the borders of the canvas. This method has to be
108 called after each change of the sprite location so that the bounds
109 of the canvas can be transformed into the coordinate system of the
112 css::uno::Reference
<css::rendering::XPolyPolygon2D
> UpdateSpriteClip (
113 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& rxOriginalClip
,
114 const css::geometry::RealPoint2D
& rLocation
);
118 virtual void SAL_CALL
clear() override
;
120 virtual void SAL_CALL
drawPoint (
121 const css::geometry::RealPoint2D
& aPoint
,
122 const css::rendering::ViewState
& aViewState
,
123 const css::rendering::RenderState
& aRenderState
) override
;
125 virtual void SAL_CALL
drawLine (
126 const css::geometry::RealPoint2D
& aStartPoint
,
127 const css::geometry::RealPoint2D
& aEndPoint
,
128 const css::rendering::ViewState
& aViewState
,
129 const css::rendering::RenderState
& aRenderState
) override
;
131 virtual void SAL_CALL
drawBezier (
132 const css::geometry::RealBezierSegment2D
& aBezierSegment
,
133 const css::geometry::RealPoint2D
& aEndPoint
,
134 const css::rendering::ViewState
& aViewState
,
135 const css::rendering::RenderState
& aRenderState
) override
;
137 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
drawPolyPolygon (
138 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
139 const css::rendering::ViewState
& aViewState
,
140 const css::rendering::RenderState
& aRenderState
) override
;
142 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
strokePolyPolygon (
143 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
144 const css::rendering::ViewState
& aViewState
,
145 const css::rendering::RenderState
& aRenderState
,
146 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
148 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
149 strokeTexturedPolyPolygon (
150 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
151 const css::rendering::ViewState
& aViewState
,
152 const css::rendering::RenderState
& aRenderState
,
153 const css::uno::Sequence
< css::rendering::Texture
>& aTextures
,
154 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
156 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
157 strokeTextureMappedPolyPolygon(
158 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
159 const css::rendering::ViewState
& aViewState
,
160 const css::rendering::RenderState
& aRenderState
,
161 const css::uno::Sequence
<css::rendering::Texture
>& aTextures
,
162 const css::uno::Reference
<css::geometry::XMapping2D
>& xMapping
,
163 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
165 virtual css::uno::Reference
<css::rendering::XPolyPolygon2D
> SAL_CALL
167 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
168 const css::rendering::ViewState
& aViewState
,
169 const css::rendering::RenderState
& aRenderState
,
170 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
172 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
174 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
175 const css::rendering::ViewState
& aViewState
,
176 const css::rendering::RenderState
& aRenderState
) override
;
178 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
179 fillTexturedPolyPolygon(
180 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
181 const css::rendering::ViewState
& aViewState
,
182 const css::rendering::RenderState
& aRenderState
,
183 const css::uno::Sequence
<css::rendering::Texture
>& xTextures
) override
;
185 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
186 fillTextureMappedPolyPolygon(
187 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
188 const css::rendering::ViewState
& aViewState
,
189 const css::rendering::RenderState
& aRenderState
,
190 const css::uno::Sequence
< css::rendering::Texture
>& xTextures
,
191 const css::uno::Reference
< css::geometry::XMapping2D
>& xMapping
) override
;
193 virtual css::uno::Reference
<css::rendering::XCanvasFont
> SAL_CALL
195 const css::rendering::FontRequest
& aFontRequest
,
196 const css::uno::Sequence
< css::beans::PropertyValue
>& aExtraFontProperties
,
197 const css::geometry::Matrix2D
& aFontMatrix
) override
;
199 virtual css::uno::Sequence
<css::rendering::FontInfo
> SAL_CALL
201 const css::rendering::FontInfo
& aFilter
,
202 const css::uno::Sequence
< css::beans::PropertyValue
>& aFontProperties
) override
;
204 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
206 const css::rendering::StringContext
& aText
,
207 const css::uno::Reference
< css::rendering::XCanvasFont
>& xFont
,
208 const css::rendering::ViewState
& aViewState
,
209 const css::rendering::RenderState
& aRenderState
,
210 ::sal_Int8 nTextDirection
) override
;
212 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
214 const css::uno::Reference
< css::rendering::XTextLayout
>& xLayoutetText
,
215 const css::rendering::ViewState
& aViewState
,
216 const css::rendering::RenderState
& aRenderState
) override
;
218 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
220 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
221 const css::rendering::ViewState
& aViewState
,
222 const css::rendering::RenderState
& aRenderState
) override
;
224 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
226 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
227 const css::rendering::ViewState
& aViewState
,
228 const css::rendering::RenderState
& aRenderState
) override
;
230 virtual css::uno::Reference
<css::rendering::XGraphicDevice
> SAL_CALL
231 getDevice() override
;
235 css::uno::Reference
< css::rendering::XAnimatedSprite
> SAL_CALL
236 createSpriteFromAnimation (
237 const css::uno::Reference
< css::rendering::XAnimation
>& animation
) override
;
239 css::uno::Reference
< css::rendering::XAnimatedSprite
> SAL_CALL
240 createSpriteFromBitmaps (
241 const css::uno::Sequence
<
242 css::uno::Reference
< css::rendering::XBitmap
> >& animationBitmaps
,
243 ::sal_Int8 interpolationMode
) override
;
245 css::uno::Reference
< css::rendering::XCustomSprite
> SAL_CALL
247 const css::geometry::RealSize2D
& spriteSize
) override
;
249 css::uno::Reference
< css::rendering::XSprite
> SAL_CALL
251 const css::uno::Reference
< css::rendering::XSprite
>& original
) override
;
253 sal_Bool SAL_CALL
updateScreen (sal_Bool bUpdateAll
) override
;
257 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
) override
;
261 virtual void SAL_CALL
windowResized (const css::awt::WindowEvent
& rEvent
) override
;
263 virtual void SAL_CALL
windowMoved (const css::awt::WindowEvent
& rEvent
) override
;
265 virtual void SAL_CALL
windowShown (const css::lang::EventObject
& rEvent
) override
;
267 virtual void SAL_CALL
windowHidden (const css::lang::EventObject
& rEvent
) override
;
271 virtual css::geometry::IntegerSize2D SAL_CALL
getSize() override
;
273 virtual sal_Bool SAL_CALL
hasAlpha() override
;
275 virtual css::uno::Reference
<css::rendering::XBitmap
> SAL_CALL
getScaledBitmap(
276 const css::geometry::RealSize2D
& rNewSize
,
277 sal_Bool bFast
) override
;
280 css::uno::Reference
<css::rendering::XSpriteCanvas
> mxUpdateCanvas
;
281 css::uno::Reference
<css::awt::XWindow
> mxUpdateWindow
;
282 css::uno::Reference
<css::rendering::XCanvas
> mxSharedCanvas
;
283 css::uno::Reference
<css::awt::XWindow
> mxSharedWindow
;
285 /** The window for which a canvas is emulated.
287 css::uno::Reference
<css::awt::XWindow
> mxWindow
;
289 /** Offset of the emulated canvas with respect to the shared canvas.
291 css::awt::Point maOffset
;
293 /** The UpdateRequester is used by updateScreen() to schedule
294 updateScreen() calls at the shared canvas.
296 std::shared_ptr
<CanvasUpdateRequester
> m_pUpdateRequester
;
298 /** When this flag is true (it is set to true after every call to
299 updateScreen()) then the next call to MergeViewState updates the
300 maOffset member. A possible optimization would set this flag only
301 to true when one of the windows between mxWindow and mxSharedWindow
302 changes its position.
304 bool mbOffsetUpdatePending
;
306 ::basegfx::B2DRectangle
GetClipRectangle (
307 const css::geometry::AffineMatrix2D
& rViewTransform
,
308 const css::awt::Point
& rOffset
);
310 css::rendering::ViewState
MergeViewState (const css::rendering::ViewState
& rViewState
);
312 /** @throws css::lang::DisposedException when the object has already been
315 void ThrowIfDisposed();
318 } // end of namespace ::sd::presenter
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */