summaryrefslogtreecommitdiff
path: root/sd/source/ui/presenter/PresenterCanvas.hxx
blob: 606117caca4e681cdcdcf247e62bb9535190265c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SD_SOURCE_UI_PRESENTER_PRESENTERCANVAS_HXX
#define INCLUDED_SD_SOURCE_UI_PRESENTER_PRESENTERCANVAS_HXX

#include "CanvasUpdateRequester.hxx"
#include <basegfx/range/b2drectangle.hxx>
#include <com/sun/star/awt/Point.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XWindowListener.hpp>
#include <com/sun/star/geometry/AffineMatrix2D.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/rendering/XSpriteCanvas.hpp>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/VolatileContentDestroyedException.hpp>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>

namespace sd { namespace presenter {

namespace {
    typedef ::cppu::WeakComponentImplHelper <
        css::rendering::XSpriteCanvas,
        css::rendering::XBitmap,
        css::awt::XWindowListener,
        css::lang::XInitialization,
        css::lang::XServiceInfo
    > PresenterCanvasInterfaceBase;
}

/** Wrapper around a shared canvas that forwards most of its methods to the
    shared canvas.  Most notable differences are:
    1. The transformation  of the ViewState of forwarded calls is modified by adding
    an offset.
    2. The clip polygon of the ViewState of forwarded calls is intersected
    with a clip rectangle that can be set via SetClip().
    3. Calls to updateScreen() are collected.  One call to the updateScreen()
    method of the shared canvas is made asynchronously.

    The canvas can use different canvases for sharing and for sprite
    construction.  This allows the shared canvas to be a canvas of sprite itself.
*/
class PresenterCanvas
    : private ::boost::noncopyable,
      private ::cppu::BaseMutex,
      public PresenterCanvasInterfaceBase
{
public:
    /** This constructor is used when a PresenterCanvas object is created as
        a service.
    */
    PresenterCanvas();

    /** This constructor is used when a PresenterCanvas object is created
        directly, typically by the PresenterCanvasFactory.
        @param rxUpdateCanvas
            This canvas is used to call updateScreen() at and to create
            sprites.  In the typical case this canvas is identical to the
            rxSharedCanvas argument.
        @param rxUpdateWindow
            The window that belongs to the canvas given by the
            rxUpdateCanvas argument.
        @param rxSharedCanvas
            The canvas that is wrapped by the new instance of this class.
            Typically this is a regular XSpriteCanvas and then is identical
            to the one given by the rxUpdateCanvas argument.  It may be the
            canvas of a sprite which does not support the XSpriteCanvas
            interface.  In that case the canvas that created the sprite can
            be given as rxUpdateCanvas argument to allow to create further
            sprites and to have proper calls to updateScreen().
        @param rxSharedWindow
            The window that belongs to the canvas given by the
            rxSharedCanvas argument.
        @param rxWindow
            The window that is represented by the new PresenterCanvas
            object.  It is expected to be a direct descendant of
            rxSharedWindow.  Its position inside rxSharedWindow defines the
            offset of the canvas implemented by the new PresenterCanvas
            object and rxSharedCanvas.
    */
    PresenterCanvas (
        const css::uno::Reference<css::rendering::XSpriteCanvas>& rxUpdateCanvas,
        const css::uno::Reference<css::awt::XWindow>& rxUpdateWindow,
        const css::uno::Reference<css::rendering::XCanvas>& rxSharedCanvas,
        const css::uno::Reference<css::awt::XWindow>& rxSharedWindow,
        const css::uno::Reference<css::awt::XWindow>& rxWindow);
    virtual ~PresenterCanvas();

    virtual void SAL_CALL disposing()
        throw (css::uno::RuntimeException) SAL_OVERRIDE;

    css::awt::Point GetOffset (const css::uno::Reference<css::awt::XWindow>& rxBaseWindow);

    /** Merge the given view state with the view state that translates the
        (virtual) child canvas to the shared canvas.
    */
    css::rendering::ViewState MergeViewState (
        const css::rendering::ViewState& rViewState,
        const css::awt::Point& raOffset);

    css::uno::Reference<css::rendering::XCanvas> GetSharedCanvas() const;

    /** This method is typically called by CanvasPane objects to set the
        repaint rectangle of a windowPaint() call as clip rectangle.  When
        no or an empty rectangle is given then the window bounds are used
        instead.
        @param rClipRectangle
            A valid rectangle is used to clip the view state clip polygon.
            When an empty rectangle is given then the view state clip
            polygons are clipped against the window bounds.
    */
    void SetClip (const css::awt::Rectangle& rClipRectangle);

    /** Called by custom sprites to update their clip polygon so that they
        are clipped at the borders of the canvas.  This method has to be
        called after each change of the sprite location so that the bounds
        of the canvas can be transformed into the coordinate system of the
        sprite.
    */
    css::uno::Reference<css::rendering::XPolyPolygon2D> UpdateSpriteClip (
        const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxOriginalClip,
        const css::geometry::RealPoint2D& rLocation,
        const css::geometry::RealSize2D& rSize);

    // XInitialization

    virtual void SAL_CALL initialize (
        const css::uno::Sequence<css::uno::Any>& rArguments)
        throw(css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    OUString SAL_CALL getImplementationName()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    // XCanvas

    virtual void SAL_CALL clear()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual void SAL_CALL drawPoint (
        const css::geometry::RealPoint2D& aPoint,
        const css::rendering::ViewState& aViewState,
        const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual void SAL_CALL drawLine (
        const css::geometry::RealPoint2D& aStartPoint,
        const css::geometry::RealPoint2D& aEndPoint,
        const css::rendering::ViewState& aViewState,
        const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual void SAL_CALL drawBezier (
        const css::geometry::RealBezierSegment2D& aBezierSegment,
        const css::geometry::RealPoint2D& aEndPoint,
        const css::rendering::ViewState& aViewState,
        const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL drawPolyPolygon (
        const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
        const css::rendering::ViewState& aViewState,
        const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL strokePolyPolygon (
        const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
        const css::rendering::ViewState& aViewState,
        const css::rendering::RenderState& aRenderState,
        const css::rendering::StrokeAttributes& aStrokeAttributes)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        strokeTexturedPolyPolygon (
            const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState,
            const css::uno::Sequence< css::rendering::Texture >& aTextures,
            const css::rendering::StrokeAttributes& aStrokeAttributes)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        strokeTextureMappedPolyPolygon(
            const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState,
            const css::uno::Sequence<css::rendering::Texture>& aTextures,
            const css::uno::Reference<css::geometry::XMapping2D>& xMapping,
            const css::rendering::StrokeAttributes& aStrokeAttributes)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL
        queryStrokeShapes(
            const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState,
            const css::rendering::StrokeAttributes& aStrokeAttributes)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        fillPolyPolygon(
            const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        fillTexturedPolyPolygon(
            const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState,
            const css::uno::Sequence<css::rendering::Texture>& xTextures)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        fillTextureMappedPolyPolygon(
            const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState,
            const css::uno::Sequence< css::rendering::Texture >& xTextures,
            const css::uno::Reference< css::geometry::XMapping2D >& xMapping)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL
        createFont(
            const css::rendering::FontRequest& aFontRequest,
            const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties,
            const css::geometry::Matrix2D& aFontMatrix)
        throw (css::lang::IllegalArgumentException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Sequence<css::rendering::FontInfo> SAL_CALL
        queryAvailableFonts(
            const css::rendering::FontInfo& aFilter,
            const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        drawText(
            const css::rendering::StringContext& aText,
            const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState,
            ::sal_Int8 nTextDirection)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        drawTextLayout(
            const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        drawBitmap(
            const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
        drawBitmapModulated(
            const css::uno::Reference< css::rendering::XBitmap>& xBitmap,
            const css::rendering::ViewState& aViewState,
            const css::rendering::RenderState& aRenderState)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL
        getDevice()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    // XSpriteCanvas

    css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL
        createSpriteFromAnimation (
            const css::uno::Reference< css::rendering::XAnimation >& animation)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL
        createSpriteFromBitmaps (
            const css::uno::Sequence<
                css::uno::Reference< css::rendering::XBitmap > >& animationBitmaps,
            ::sal_Int8 interpolationMode)
        throw (css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException,
            css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL
        createCustomSprite (
            const css::geometry::RealSize2D& spriteSize)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    css::uno::Reference< css::rendering::XSprite > SAL_CALL
        createClonedSprite (
            const css::uno::Reference< css::rendering::XSprite >& original)
        throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    sal_Bool SAL_CALL updateScreen (sal_Bool bUpdateAll)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    // XEventListener

    virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    // XWindowListener

    virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    // XBitmap

    virtual css::geometry::IntegerSize2D SAL_CALL getSize()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual sal_Bool SAL_CALL hasAlpha()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

    virtual css::uno::Reference<css::rendering::XBitmap> SAL_CALL getScaledBitmap(
        const css::geometry::RealSize2D& rNewSize,
        sal_Bool bFast)
        throw (css::uno::RuntimeException,
            css::lang::IllegalArgumentException,
            css::rendering::VolatileContentDestroyedException, std::exception) SAL_OVERRIDE;

private:
    css::uno::Reference<css::rendering::XSpriteCanvas> mxUpdateCanvas;
    css::uno::Reference<css::awt::XWindow> mxUpdateWindow;
    css::uno::Reference<css::rendering::XCanvas> mxSharedCanvas;
    css::uno::Reference<css::awt::XWindow> mxSharedWindow;

    /** The window for which a canvas is emulated.
    */
    css::uno::Reference<css::awt::XWindow> mxWindow;

    /** Offset of the emulated canvas with respect to the shared canvas.
    */
    css::awt::Point maOffset;

    /** The UpdateRequester is used by updateScreen() to schedule
        updateScreen() calls at the shared canvas.
    */
    ::boost::shared_ptr<CanvasUpdateRequester> mpUpdateRequester;

    /** The clip rectangle as given to SetClip().
    */
    css::awt::Rectangle maClipRectangle;

    /** When this flag is true (it is set to true after every call to
        updateScreen()) then the next call to MergeViewState updates the
        maOffset member.  A possible optimization would set this flag only
        to true when one of the windows between mxWindow and mxSharedWindow
        changes its position.
    */
    bool mbOffsetUpdatePending;

    ::basegfx::B2DRectangle GetClipRectangle (
        const css::geometry::AffineMatrix2D& rViewTransform,
        const css::awt::Point& rOffset);

    css::rendering::ViewState MergeViewState (const css::rendering::ViewState& rViewState);

    /** This method throws a DisposedException when the object has already been
        disposed.
    */
    void ThrowIfDisposed()
        throw (css::lang::DisposedException);
};

} } // end of namespace ::sd::presenter

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */