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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_PRESENTER_PRESENTERCANVAS_HXX
21 #define INCLUDED_SD_SOURCE_UI_PRESENTER_PRESENTERCANVAS_HXX
23 #include <basegfx/range/b2drectangle.hxx>
24 #include <com/sun/star/awt/Point.hpp>
25 #include <com/sun/star/awt/XWindowListener.hpp>
26 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
27 #include <com/sun/star/rendering/XBitmap.hpp>
28 #include <cppuhelper/basemutex.hxx>
29 #include <cppuhelper/compbase.hxx>
32 namespace sd
{ namespace presenter
{ class CanvasUpdateRequester
; } }
33 namespace com
{ namespace sun
{ namespace star
{ namespace awt
{ class XWindow
; } } } }
34 namespace com
{ namespace sun
{ namespace star
{ namespace geometry
{ struct AffineMatrix2D
; } } } }
36 namespace sd
{ namespace presenter
{
38 typedef ::cppu::WeakComponentImplHelper
<
39 css::rendering::XSpriteCanvas
,
40 css::rendering::XBitmap
,
41 css::awt::XWindowListener
42 > PresenterCanvasInterfaceBase
;
44 /** Wrapper around a shared canvas that forwards most of its methods to the
45 shared canvas. Most notable differences are:
46 1. The transformation of the ViewState of forwarded calls is modified by adding
48 2. The clip polygon of the ViewState of forwarded calls is intersected
49 with a clip rectangle that can be set via SetClip().
50 3. Calls to updateScreen() are collected. One call to the updateScreen()
51 method of the shared canvas is made asynchronously.
53 The canvas can use different canvases for sharing and for sprite
54 construction. This allows the shared canvas to be a canvas of sprite itself.
57 : private ::cppu::BaseMutex
,
58 public PresenterCanvasInterfaceBase
61 /** This constructor is used when a PresenterCanvas object is created
62 directly, typically by the PresenterCanvasFactory.
64 This canvas is used to call updateScreen() at and to create
65 sprites. In the typical case this canvas is identical to the
66 rxSharedCanvas argument.
68 The window that belongs to the canvas given by the
69 rxUpdateCanvas argument.
71 The canvas that is wrapped by the new instance of this class.
72 Typically this is a regular XSpriteCanvas and then is identical
73 to the one given by the rxUpdateCanvas argument. It may be the
74 canvas of a sprite which does not support the XSpriteCanvas
75 interface. In that case the canvas that created the sprite can
76 be given as rxUpdateCanvas argument to allow to create further
77 sprites and to have proper calls to updateScreen().
79 The window that belongs to the canvas given by the
80 rxSharedCanvas argument.
82 The window that is represented by the new PresenterCanvas
83 object. It is expected to be a direct descendant of
84 rxSharedWindow. Its position inside rxSharedWindow defines the
85 offset of the canvas implemented by the new PresenterCanvas
86 object and rxSharedCanvas.
89 const css::uno::Reference
<css::rendering::XSpriteCanvas
>& rxUpdateCanvas
,
90 const css::uno::Reference
<css::awt::XWindow
>& rxUpdateWindow
,
91 const css::uno::Reference
<css::rendering::XCanvas
>& rxSharedCanvas
,
92 const css::uno::Reference
<css::awt::XWindow
>& rxSharedWindow
,
93 const css::uno::Reference
<css::awt::XWindow
>& rxWindow
);
94 virtual ~PresenterCanvas() override
;
95 PresenterCanvas(const PresenterCanvas
&) = delete;
96 PresenterCanvas
& operator=(const PresenterCanvas
&) = delete;
98 virtual void SAL_CALL
disposing() override
;
100 css::awt::Point
GetOffset (const css::uno::Reference
<css::awt::XWindow
>& rxBaseWindow
);
102 /** Merge the given view state with the view state that translates the
103 (virtual) child canvas to the shared canvas.
105 css::rendering::ViewState
MergeViewState (
106 const css::rendering::ViewState
& rViewState
,
107 const css::awt::Point
& raOffset
);
109 /** Called by custom sprites to update their clip polygon so that they
110 are clipped at the borders of the canvas. This method has to be
111 called after each change of the sprite location so that the bounds
112 of the canvas can be transformed into the coordinate system of the
115 css::uno::Reference
<css::rendering::XPolyPolygon2D
> UpdateSpriteClip (
116 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& rxOriginalClip
,
117 const css::geometry::RealPoint2D
& rLocation
);
121 virtual void SAL_CALL
clear() override
;
123 virtual void SAL_CALL
drawPoint (
124 const css::geometry::RealPoint2D
& aPoint
,
125 const css::rendering::ViewState
& aViewState
,
126 const css::rendering::RenderState
& aRenderState
) override
;
128 virtual void SAL_CALL
drawLine (
129 const css::geometry::RealPoint2D
& aStartPoint
,
130 const css::geometry::RealPoint2D
& aEndPoint
,
131 const css::rendering::ViewState
& aViewState
,
132 const css::rendering::RenderState
& aRenderState
) override
;
134 virtual void SAL_CALL
drawBezier (
135 const css::geometry::RealBezierSegment2D
& aBezierSegment
,
136 const css::geometry::RealPoint2D
& aEndPoint
,
137 const css::rendering::ViewState
& aViewState
,
138 const css::rendering::RenderState
& aRenderState
) override
;
140 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
drawPolyPolygon (
141 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
142 const css::rendering::ViewState
& aViewState
,
143 const css::rendering::RenderState
& aRenderState
) override
;
145 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
strokePolyPolygon (
146 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
147 const css::rendering::ViewState
& aViewState
,
148 const css::rendering::RenderState
& aRenderState
,
149 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
151 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
152 strokeTexturedPolyPolygon (
153 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
154 const css::rendering::ViewState
& aViewState
,
155 const css::rendering::RenderState
& aRenderState
,
156 const css::uno::Sequence
< css::rendering::Texture
>& aTextures
,
157 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
159 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
160 strokeTextureMappedPolyPolygon(
161 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
162 const css::rendering::ViewState
& aViewState
,
163 const css::rendering::RenderState
& aRenderState
,
164 const css::uno::Sequence
<css::rendering::Texture
>& aTextures
,
165 const css::uno::Reference
<css::geometry::XMapping2D
>& xMapping
,
166 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
168 virtual css::uno::Reference
<css::rendering::XPolyPolygon2D
> SAL_CALL
170 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
171 const css::rendering::ViewState
& aViewState
,
172 const css::rendering::RenderState
& aRenderState
,
173 const css::rendering::StrokeAttributes
& aStrokeAttributes
) override
;
175 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
177 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
178 const css::rendering::ViewState
& aViewState
,
179 const css::rendering::RenderState
& aRenderState
) override
;
181 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
182 fillTexturedPolyPolygon(
183 const css::uno::Reference
<css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
184 const css::rendering::ViewState
& aViewState
,
185 const css::rendering::RenderState
& aRenderState
,
186 const css::uno::Sequence
<css::rendering::Texture
>& xTextures
) override
;
188 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
189 fillTextureMappedPolyPolygon(
190 const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& xPolyPolygon
,
191 const css::rendering::ViewState
& aViewState
,
192 const css::rendering::RenderState
& aRenderState
,
193 const css::uno::Sequence
< css::rendering::Texture
>& xTextures
,
194 const css::uno::Reference
< css::geometry::XMapping2D
>& xMapping
) override
;
196 virtual css::uno::Reference
<css::rendering::XCanvasFont
> SAL_CALL
198 const css::rendering::FontRequest
& aFontRequest
,
199 const css::uno::Sequence
< css::beans::PropertyValue
>& aExtraFontProperties
,
200 const css::geometry::Matrix2D
& aFontMatrix
) override
;
202 virtual css::uno::Sequence
<css::rendering::FontInfo
> SAL_CALL
204 const css::rendering::FontInfo
& aFilter
,
205 const css::uno::Sequence
< css::beans::PropertyValue
>& aFontProperties
) override
;
207 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
209 const css::rendering::StringContext
& aText
,
210 const css::uno::Reference
< css::rendering::XCanvasFont
>& xFont
,
211 const css::rendering::ViewState
& aViewState
,
212 const css::rendering::RenderState
& aRenderState
,
213 ::sal_Int8 nTextDirection
) override
;
215 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
217 const css::uno::Reference
< css::rendering::XTextLayout
>& xLayoutetText
,
218 const css::rendering::ViewState
& aViewState
,
219 const css::rendering::RenderState
& aRenderState
) override
;
221 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
223 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
224 const css::rendering::ViewState
& aViewState
,
225 const css::rendering::RenderState
& aRenderState
) override
;
227 virtual css::uno::Reference
<css::rendering::XCachedPrimitive
> SAL_CALL
229 const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
230 const css::rendering::ViewState
& aViewState
,
231 const css::rendering::RenderState
& aRenderState
) override
;
233 virtual css::uno::Reference
<css::rendering::XGraphicDevice
> SAL_CALL
234 getDevice() override
;
238 css::uno::Reference
< css::rendering::XAnimatedSprite
> SAL_CALL
239 createSpriteFromAnimation (
240 const css::uno::Reference
< css::rendering::XAnimation
>& animation
) override
;
242 css::uno::Reference
< css::rendering::XAnimatedSprite
> SAL_CALL
243 createSpriteFromBitmaps (
244 const css::uno::Sequence
<
245 css::uno::Reference
< css::rendering::XBitmap
> >& animationBitmaps
,
246 ::sal_Int8 interpolationMode
) override
;
248 css::uno::Reference
< css::rendering::XCustomSprite
> SAL_CALL
250 const css::geometry::RealSize2D
& spriteSize
) override
;
252 css::uno::Reference
< css::rendering::XSprite
> SAL_CALL
254 const css::uno::Reference
< css::rendering::XSprite
>& original
) override
;
256 sal_Bool SAL_CALL
updateScreen (sal_Bool bUpdateAll
) override
;
260 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
) override
;
264 virtual void SAL_CALL
windowResized (const css::awt::WindowEvent
& rEvent
) override
;
266 virtual void SAL_CALL
windowMoved (const css::awt::WindowEvent
& rEvent
) override
;
268 virtual void SAL_CALL
windowShown (const css::lang::EventObject
& rEvent
) override
;
270 virtual void SAL_CALL
windowHidden (const css::lang::EventObject
& rEvent
) override
;
274 virtual css::geometry::IntegerSize2D SAL_CALL
getSize() override
;
276 virtual sal_Bool SAL_CALL
hasAlpha() override
;
278 virtual css::uno::Reference
<css::rendering::XBitmap
> SAL_CALL
getScaledBitmap(
279 const css::geometry::RealSize2D
& rNewSize
,
280 sal_Bool bFast
) override
;
283 css::uno::Reference
<css::rendering::XSpriteCanvas
> mxUpdateCanvas
;
284 css::uno::Reference
<css::awt::XWindow
> mxUpdateWindow
;
285 css::uno::Reference
<css::rendering::XCanvas
> mxSharedCanvas
;
286 css::uno::Reference
<css::awt::XWindow
> mxSharedWindow
;
288 /** The window for which a canvas is emulated.
290 css::uno::Reference
<css::awt::XWindow
> mxWindow
;
292 /** Offset of the emulated canvas with respect to the shared canvas.
294 css::awt::Point maOffset
;
296 /** The UpdateRequester is used by updateScreen() to schedule
297 updateScreen() calls at the shared canvas.
299 std::shared_ptr
<CanvasUpdateRequester
> m_pUpdateRequester
;
301 /** When this flag is true (it is set to true after every call to
302 updateScreen()) then the next call to MergeViewState updates the
303 maOffset member. A possible optimization would set this flag only
304 to true when one of the windows between mxWindow and mxSharedWindow
305 changes its position.
307 bool mbOffsetUpdatePending
;
309 ::basegfx::B2DRectangle
GetClipRectangle (
310 const css::geometry::AffineMatrix2D
& rViewTransform
,
311 const css::awt::Point
& rOffset
);
313 css::rendering::ViewState
MergeViewState (const css::rendering::ViewState
& rViewState
);
315 /** @throws css::lang::DisposedException when the object has already been
318 void ThrowIfDisposed();
321 } } // end of namespace ::sd::presenter
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */