bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / presenter / PresenterCanvas.hxx
blob606117caca4e681cdcdcf247e62bb9535190265c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "CanvasUpdateRequester.hxx"
24 #include <basegfx/range/b2drectangle.hxx>
25 #include <com/sun/star/awt/Point.hpp>
26 #include <com/sun/star/awt/XWindow.hpp>
27 #include <com/sun/star/awt/XWindowListener.hpp>
28 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
33 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
34 #include <com/sun/star/rendering/VolatileContentDestroyedException.hpp>
35 #include <cppuhelper/basemutex.hxx>
36 #include <cppuhelper/compbase.hxx>
37 #include <boost/noncopyable.hpp>
38 #include <boost/shared_ptr.hpp>
40 namespace sd { namespace presenter {
42 namespace {
43 typedef ::cppu::WeakComponentImplHelper <
44 css::rendering::XSpriteCanvas,
45 css::rendering::XBitmap,
46 css::awt::XWindowListener,
47 css::lang::XInitialization,
48 css::lang::XServiceInfo
49 > PresenterCanvasInterfaceBase;
52 /** Wrapper around a shared canvas that forwards most of its methods to the
53 shared canvas. Most notable differences are:
54 1. The transformation of the ViewState of forwarded calls is modified by adding
55 an offset.
56 2. The clip polygon of the ViewState of forwarded calls is intersected
57 with a clip rectangle that can be set via SetClip().
58 3. Calls to updateScreen() are collected. One call to the updateScreen()
59 method of the shared canvas is made asynchronously.
61 The canvas can use different canvases for sharing and for sprite
62 construction. This allows the shared canvas to be a canvas of sprite itself.
64 class PresenterCanvas
65 : private ::boost::noncopyable,
66 private ::cppu::BaseMutex,
67 public PresenterCanvasInterfaceBase
69 public:
70 /** This constructor is used when a PresenterCanvas object is created as
71 a service.
73 PresenterCanvas();
75 /** This constructor is used when a PresenterCanvas object is created
76 directly, typically by the PresenterCanvasFactory.
77 @param rxUpdateCanvas
78 This canvas is used to call updateScreen() at and to create
79 sprites. In the typical case this canvas is identical to the
80 rxSharedCanvas argument.
81 @param rxUpdateWindow
82 The window that belongs to the canvas given by the
83 rxUpdateCanvas argument.
84 @param rxSharedCanvas
85 The canvas that is wrapped by the new instance of this class.
86 Typically this is a regular XSpriteCanvas and then is identical
87 to the one given by the rxUpdateCanvas argument. It may be the
88 canvas of a sprite which does not support the XSpriteCanvas
89 interface. In that case the canvas that created the sprite can
90 be given as rxUpdateCanvas argument to allow to create further
91 sprites and to have proper calls to updateScreen().
92 @param rxSharedWindow
93 The window that belongs to the canvas given by the
94 rxSharedCanvas argument.
95 @param rxWindow
96 The window that is represented by the new PresenterCanvas
97 object. It is expected to be a direct descendant of
98 rxSharedWindow. Its position inside rxSharedWindow defines the
99 offset of the canvas implemented by the new PresenterCanvas
100 object and rxSharedCanvas.
102 PresenterCanvas (
103 const css::uno::Reference<css::rendering::XSpriteCanvas>& rxUpdateCanvas,
104 const css::uno::Reference<css::awt::XWindow>& rxUpdateWindow,
105 const css::uno::Reference<css::rendering::XCanvas>& rxSharedCanvas,
106 const css::uno::Reference<css::awt::XWindow>& rxSharedWindow,
107 const css::uno::Reference<css::awt::XWindow>& rxWindow);
108 virtual ~PresenterCanvas();
110 virtual void SAL_CALL disposing()
111 throw (css::uno::RuntimeException) SAL_OVERRIDE;
113 css::awt::Point GetOffset (const css::uno::Reference<css::awt::XWindow>& rxBaseWindow);
115 /** Merge the given view state with the view state that translates the
116 (virtual) child canvas to the shared canvas.
118 css::rendering::ViewState MergeViewState (
119 const css::rendering::ViewState& rViewState,
120 const css::awt::Point& raOffset);
122 css::uno::Reference<css::rendering::XCanvas> GetSharedCanvas() const;
124 /** This method is typically called by CanvasPane objects to set the
125 repaint rectangle of a windowPaint() call as clip rectangle. When
126 no or an empty rectangle is given then the window bounds are used
127 instead.
128 @param rClipRectangle
129 A valid rectangle is used to clip the view state clip polygon.
130 When an empty rectangle is given then the view state clip
131 polygons are clipped against the window bounds.
133 void SetClip (const css::awt::Rectangle& rClipRectangle);
135 /** Called by custom sprites to update their clip polygon so that they
136 are clipped at the borders of the canvas. This method has to be
137 called after each change of the sprite location so that the bounds
138 of the canvas can be transformed into the coordinate system of the
139 sprite.
141 css::uno::Reference<css::rendering::XPolyPolygon2D> UpdateSpriteClip (
142 const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxOriginalClip,
143 const css::geometry::RealPoint2D& rLocation,
144 const css::geometry::RealSize2D& rSize);
146 // XInitialization
148 virtual void SAL_CALL initialize (
149 const css::uno::Sequence<css::uno::Any>& rArguments)
150 throw(css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 OUString SAL_CALL getImplementationName()
153 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
156 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
159 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 // XCanvas
163 virtual void SAL_CALL clear()
164 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 virtual void SAL_CALL drawPoint (
167 const css::geometry::RealPoint2D& aPoint,
168 const css::rendering::ViewState& aViewState,
169 const css::rendering::RenderState& aRenderState)
170 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 virtual void SAL_CALL drawLine (
173 const css::geometry::RealPoint2D& aStartPoint,
174 const css::geometry::RealPoint2D& aEndPoint,
175 const css::rendering::ViewState& aViewState,
176 const css::rendering::RenderState& aRenderState)
177 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
179 virtual void SAL_CALL drawBezier (
180 const css::geometry::RealBezierSegment2D& aBezierSegment,
181 const css::geometry::RealPoint2D& aEndPoint,
182 const css::rendering::ViewState& aViewState,
183 const css::rendering::RenderState& aRenderState)
184 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
186 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL drawPolyPolygon (
187 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
188 const css::rendering::ViewState& aViewState,
189 const css::rendering::RenderState& aRenderState)
190 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
192 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL strokePolyPolygon (
193 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
194 const css::rendering::ViewState& aViewState,
195 const css::rendering::RenderState& aRenderState,
196 const css::rendering::StrokeAttributes& aStrokeAttributes)
197 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
199 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
200 strokeTexturedPolyPolygon (
201 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
202 const css::rendering::ViewState& aViewState,
203 const css::rendering::RenderState& aRenderState,
204 const css::uno::Sequence< css::rendering::Texture >& aTextures,
205 const css::rendering::StrokeAttributes& aStrokeAttributes)
206 throw (css::lang::IllegalArgumentException,
207 css::rendering::VolatileContentDestroyedException,
208 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
210 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
211 strokeTextureMappedPolyPolygon(
212 const css::uno::Reference<css::rendering::XPolyPolygon2D >& xPolyPolygon,
213 const css::rendering::ViewState& aViewState,
214 const css::rendering::RenderState& aRenderState,
215 const css::uno::Sequence<css::rendering::Texture>& aTextures,
216 const css::uno::Reference<css::geometry::XMapping2D>& xMapping,
217 const css::rendering::StrokeAttributes& aStrokeAttributes)
218 throw (css::lang::IllegalArgumentException,
219 css::rendering::VolatileContentDestroyedException,
220 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
222 virtual css::uno::Reference<css::rendering::XPolyPolygon2D> SAL_CALL
223 queryStrokeShapes(
224 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
225 const css::rendering::ViewState& aViewState,
226 const css::rendering::RenderState& aRenderState,
227 const css::rendering::StrokeAttributes& aStrokeAttributes)
228 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
230 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
231 fillPolyPolygon(
232 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
233 const css::rendering::ViewState& aViewState,
234 const css::rendering::RenderState& aRenderState)
235 throw (css::lang::IllegalArgumentException,
236 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
238 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
239 fillTexturedPolyPolygon(
240 const css::uno::Reference<css::rendering::XPolyPolygon2D>& xPolyPolygon,
241 const css::rendering::ViewState& aViewState,
242 const css::rendering::RenderState& aRenderState,
243 const css::uno::Sequence<css::rendering::Texture>& xTextures)
244 throw (css::lang::IllegalArgumentException,
245 css::rendering::VolatileContentDestroyedException,
246 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
248 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
249 fillTextureMappedPolyPolygon(
250 const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
251 const css::rendering::ViewState& aViewState,
252 const css::rendering::RenderState& aRenderState,
253 const css::uno::Sequence< css::rendering::Texture >& xTextures,
254 const css::uno::Reference< css::geometry::XMapping2D >& xMapping)
255 throw (css::lang::IllegalArgumentException,
256 css::rendering::VolatileContentDestroyedException,
257 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
259 virtual css::uno::Reference<css::rendering::XCanvasFont> SAL_CALL
260 createFont(
261 const css::rendering::FontRequest& aFontRequest,
262 const css::uno::Sequence< css::beans::PropertyValue >& aExtraFontProperties,
263 const css::geometry::Matrix2D& aFontMatrix)
264 throw (css::lang::IllegalArgumentException,
265 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
267 virtual css::uno::Sequence<css::rendering::FontInfo> SAL_CALL
268 queryAvailableFonts(
269 const css::rendering::FontInfo& aFilter,
270 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties)
271 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
273 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
274 drawText(
275 const css::rendering::StringContext& aText,
276 const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
277 const css::rendering::ViewState& aViewState,
278 const css::rendering::RenderState& aRenderState,
279 ::sal_Int8 nTextDirection)
280 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
282 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
283 drawTextLayout(
284 const css::uno::Reference< css::rendering::XTextLayout >& xLayoutetText,
285 const css::rendering::ViewState& aViewState,
286 const css::rendering::RenderState& aRenderState)
287 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
289 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
290 drawBitmap(
291 const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
292 const css::rendering::ViewState& aViewState,
293 const css::rendering::RenderState& aRenderState)
294 throw (css::lang::IllegalArgumentException,
295 css::rendering::VolatileContentDestroyedException,
296 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
298 virtual css::uno::Reference<css::rendering::XCachedPrimitive> SAL_CALL
299 drawBitmapModulated(
300 const css::uno::Reference< css::rendering::XBitmap>& xBitmap,
301 const css::rendering::ViewState& aViewState,
302 const css::rendering::RenderState& aRenderState)
303 throw (css::lang::IllegalArgumentException,
304 css::rendering::VolatileContentDestroyedException,
305 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
307 virtual css::uno::Reference<css::rendering::XGraphicDevice> SAL_CALL
308 getDevice()
309 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
311 // XSpriteCanvas
313 css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL
314 createSpriteFromAnimation (
315 const css::uno::Reference< css::rendering::XAnimation >& animation)
316 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
318 css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL
319 createSpriteFromBitmaps (
320 const css::uno::Sequence<
321 css::uno::Reference< css::rendering::XBitmap > >& animationBitmaps,
322 ::sal_Int8 interpolationMode)
323 throw (css::lang::IllegalArgumentException,
324 css::rendering::VolatileContentDestroyedException,
325 css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
327 css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL
328 createCustomSprite (
329 const css::geometry::RealSize2D& spriteSize)
330 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
332 css::uno::Reference< css::rendering::XSprite > SAL_CALL
333 createClonedSprite (
334 const css::uno::Reference< css::rendering::XSprite >& original)
335 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
337 sal_Bool SAL_CALL updateScreen (sal_Bool bUpdateAll)
338 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
340 // XEventListener
342 virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
343 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
345 // XWindowListener
347 virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
348 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
350 virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
351 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
353 virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
354 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
356 virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
357 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
359 // XBitmap
361 virtual css::geometry::IntegerSize2D SAL_CALL getSize()
362 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
364 virtual sal_Bool SAL_CALL hasAlpha()
365 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
367 virtual css::uno::Reference<css::rendering::XBitmap> SAL_CALL getScaledBitmap(
368 const css::geometry::RealSize2D& rNewSize,
369 sal_Bool bFast)
370 throw (css::uno::RuntimeException,
371 css::lang::IllegalArgumentException,
372 css::rendering::VolatileContentDestroyedException, std::exception) SAL_OVERRIDE;
374 private:
375 css::uno::Reference<css::rendering::XSpriteCanvas> mxUpdateCanvas;
376 css::uno::Reference<css::awt::XWindow> mxUpdateWindow;
377 css::uno::Reference<css::rendering::XCanvas> mxSharedCanvas;
378 css::uno::Reference<css::awt::XWindow> mxSharedWindow;
380 /** The window for which a canvas is emulated.
382 css::uno::Reference<css::awt::XWindow> mxWindow;
384 /** Offset of the emulated canvas with respect to the shared canvas.
386 css::awt::Point maOffset;
388 /** The UpdateRequester is used by updateScreen() to schedule
389 updateScreen() calls at the shared canvas.
391 ::boost::shared_ptr<CanvasUpdateRequester> mpUpdateRequester;
393 /** The clip rectangle as given to SetClip().
395 css::awt::Rectangle maClipRectangle;
397 /** When this flag is true (it is set to true after every call to
398 updateScreen()) then the next call to MergeViewState updates the
399 maOffset member. A possible optimization would set this flag only
400 to true when one of the windows between mxWindow and mxSharedWindow
401 changes its position.
403 bool mbOffsetUpdatePending;
405 ::basegfx::B2DRectangle GetClipRectangle (
406 const css::geometry::AffineMatrix2D& rViewTransform,
407 const css::awt::Point& rOffset);
409 css::rendering::ViewState MergeViewState (const css::rendering::ViewState& rViewState);
411 /** This method throws a DisposedException when the object has already been
412 disposed.
414 void ThrowIfDisposed()
415 throw (css::lang::DisposedException);
418 } } // end of namespace ::sd::presenter
420 #endif
422 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */