fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / canvas / base / canvasbase.hxx
blobf7844fd219de8a157ab57af573184c53da5a98be
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_CANVAS_CANVASBASE_HXX
21 #define INCLUDED_CANVAS_CANVASBASE_HXX
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/rendering/XCanvas.hpp>
25 #include <com/sun/star/rendering/TextDirection.hpp>
26 #include <osl/mutex.hxx>
27 #include <canvas/verifyinput.hxx>
30 namespace canvas
32 /** Helper template to handle XCanvas method forwarding to CanvasHelper
34 Use this helper to handle the XCanvas part of your
35 implementation. In theory, we could have provided CanvasHelper
36 and CanvasBase as a single template, but that would duplicate
37 a lot of code now residing in CanvasHelper only.
39 This template basically interposes itself between the full
40 interface you implement (i.e. not restricted to XCanvas. The
41 problem with UNO partial interface implementation actually is,
42 that you cannot do it the plain way, since deriving from a
43 common base subclass always introduces the whole set of pure
44 virtuals, that your baseclass helper just overrided) and your
45 implementation class. You then only have to implement the
46 functionality <em>besides</em> XCanvas.
48 <pre>
49 Example:
50 typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::rendering::XSpriteCanvas,
51 ::com::sun::star::lang::XInitialization,
52 ::com::sun::star::lang::XServiceInfo,
53 ::com::sun::star::lang::XServiceName > CanvasBase_Base;
54 typedef ::canvas::internal::CanvasBase< CanvasBase_Base, CanvasHelper > ExampleCanvas_Base;
56 class ExampleCanvas : public ExampleCanvas_Base,
57 public SpriteSurface,
58 public RepaintTarget
61 </pre>
63 @tpl Base
64 Base class to use, most probably one of the
65 WeakComponentImplHelperN templates with the appropriate
66 interfaces. At least XCanvas should be among them (why else
67 would you use this template, then?). Base class must have an
68 Base( const Mutex& ) constructor (like the
69 WeakComponentImplHelperN templates have). As the very least,
70 the base class must be derived from uno::XInterface, as some
71 error reporting mechanisms rely on that.
73 @tpl CanvasHelper
74 Canvas helper implementation for the backend in question. This
75 object will be held as a member of this template class, and
76 basically gets forwarded all XCanvas API calls. Furthermore,
77 everytime the canvas API semantically changes the content of
78 the canvas, CanvasHelper::modifying() will get called
79 (<em>before</em> the actual modification takes place).
81 @tpl Mutex
82 Lock strategy to use. Defaults to using the
83 OBaseMutex-provided lock. Everytime one of the methods is
84 entered, an object of type Mutex is created with m_aMutex as
85 the sole parameter, and destroyed again when the method scope
86 is left.
88 @tpl UnambiguousBase
89 Optional unambiguous base class for XInterface of Base. It's
90 sometimes necessary to specify this parameter, e.g. if Base
91 derives from multiple UNO interface (were each provides its
92 own version of XInterface, making the conversion ambiguous)
94 template< class Base,
95 class CanvasHelper,
96 class Mutex=::osl::MutexGuard,
97 class UnambiguousBase=::com::sun::star::uno::XInterface > class CanvasBase :
98 public Base
100 public:
101 typedef Base BaseType;
102 typedef CanvasHelper HelperType;
103 typedef Mutex MutexType;
104 typedef UnambiguousBase UnambiguousBaseType;
106 /** Create CanvasBase
108 CanvasBase() :
109 maCanvasHelper(),
110 mbSurfaceDirty( true )
114 virtual void disposeThis()
116 MutexType aGuard( BaseType::m_aMutex );
118 maCanvasHelper.disposing();
120 // pass on to base class
121 BaseType::disposeThis();
124 // XCanvas
125 virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException)
127 MutexType aGuard( BaseType::m_aMutex );
129 mbSurfaceDirty = true;
130 maCanvasHelper.modifying();
132 maCanvasHelper.clear();
135 virtual void SAL_CALL drawPoint( const ::com::sun::star::geometry::RealPoint2D& aPoint,
136 const ::com::sun::star::rendering::ViewState& viewState,
137 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
138 ::com::sun::star::uno::RuntimeException)
140 tools::verifyArgs(aPoint, viewState, renderState,
141 BOOST_CURRENT_FUNCTION,
142 static_cast< UnambiguousBaseType* >(this));
144 MutexType aGuard( BaseType::m_aMutex );
146 mbSurfaceDirty = true;
147 maCanvasHelper.modifying();
149 maCanvasHelper.drawPoint( this, aPoint, viewState, renderState );
152 virtual void SAL_CALL drawLine( const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
153 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
154 const ::com::sun::star::rendering::ViewState& viewState,
155 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
156 ::com::sun::star::uno::RuntimeException)
158 tools::verifyArgs(aStartPoint, aEndPoint, viewState, renderState,
159 BOOST_CURRENT_FUNCTION,
160 static_cast< UnambiguousBaseType* >(this));
162 MutexType aGuard( BaseType::m_aMutex );
164 mbSurfaceDirty = true;
165 maCanvasHelper.modifying();
167 maCanvasHelper.drawLine( this, aStartPoint, aEndPoint, viewState, renderState );
170 virtual void SAL_CALL drawBezier( const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
171 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
172 const ::com::sun::star::rendering::ViewState& viewState,
173 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
174 ::com::sun::star::uno::RuntimeException)
176 tools::verifyArgs(aBezierSegment, aEndPoint, viewState, renderState,
177 BOOST_CURRENT_FUNCTION,
178 static_cast< UnambiguousBaseType* >(this));
180 MutexType aGuard( BaseType::m_aMutex );
182 mbSurfaceDirty = true;
183 maCanvasHelper.modifying();
185 maCanvasHelper.drawBezier( this, aBezierSegment, aEndPoint, viewState, renderState );
188 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
189 drawPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
190 const ::com::sun::star::rendering::ViewState& viewState,
191 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
192 ::com::sun::star::uno::RuntimeException)
194 tools::verifyArgs(xPolyPolygon, viewState, renderState,
195 BOOST_CURRENT_FUNCTION,
196 static_cast< UnambiguousBaseType* >(this));
198 MutexType aGuard( BaseType::m_aMutex );
200 mbSurfaceDirty = true;
201 maCanvasHelper.modifying();
203 return maCanvasHelper.drawPolyPolygon( this, xPolyPolygon, viewState, renderState );
206 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
207 strokePolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
208 const ::com::sun::star::rendering::ViewState& viewState,
209 const ::com::sun::star::rendering::RenderState& renderState,
210 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException,
211 ::com::sun::star::uno::RuntimeException)
213 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
214 BOOST_CURRENT_FUNCTION,
215 static_cast< UnambiguousBaseType* >(this));
217 MutexType aGuard( BaseType::m_aMutex );
219 mbSurfaceDirty = true;
220 maCanvasHelper.modifying();
222 return maCanvasHelper.strokePolyPolygon( this, xPolyPolygon, viewState, renderState, strokeAttributes );
225 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
226 strokeTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
227 const ::com::sun::star::rendering::ViewState& viewState,
228 const ::com::sun::star::rendering::RenderState& renderState,
229 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures,
230 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException,
231 ::com::sun::star::uno::RuntimeException)
233 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
234 BOOST_CURRENT_FUNCTION,
235 static_cast< UnambiguousBaseType* >(this));
237 MutexType aGuard( BaseType::m_aMutex );
239 mbSurfaceDirty = true;
240 maCanvasHelper.modifying();
242 return maCanvasHelper.strokeTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, strokeAttributes );
245 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
246 strokeTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
247 const ::com::sun::star::rendering::ViewState& viewState,
248 const ::com::sun::star::rendering::RenderState& renderState,
249 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures,
250 const ::com::sun::star::uno::Reference< ::com::sun::star::geometry::XMapping2D >& xMapping,
251 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException,
252 ::com::sun::star::uno::RuntimeException)
254 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes,
255 BOOST_CURRENT_FUNCTION,
256 static_cast< UnambiguousBaseType* >(this));
258 MutexType aGuard( BaseType::m_aMutex );
260 mbSurfaceDirty = true;
261 maCanvasHelper.modifying();
263 return maCanvasHelper.strokeTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes );
266 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL
267 queryStrokeShapes( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
268 const ::com::sun::star::rendering::ViewState& viewState,
269 const ::com::sun::star::rendering::RenderState& renderState,
270 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException,
271 ::com::sun::star::uno::RuntimeException)
273 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
274 BOOST_CURRENT_FUNCTION,
275 static_cast< UnambiguousBaseType* >(this));
277 MutexType aGuard( BaseType::m_aMutex );
279 mbSurfaceDirty = true;
280 maCanvasHelper.modifying();
282 return maCanvasHelper.queryStrokeShapes( this, xPolyPolygon, viewState, renderState, strokeAttributes );
285 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
286 fillPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
287 const ::com::sun::star::rendering::ViewState& viewState,
288 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
289 ::com::sun::star::uno::RuntimeException)
291 tools::verifyArgs(xPolyPolygon, viewState, renderState,
292 BOOST_CURRENT_FUNCTION,
293 static_cast< UnambiguousBaseType* >(this));
295 MutexType aGuard( BaseType::m_aMutex );
297 mbSurfaceDirty = true;
298 maCanvasHelper.modifying();
300 return maCanvasHelper.fillPolyPolygon( this, xPolyPolygon, viewState, renderState );
303 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
304 fillTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
305 const ::com::sun::star::rendering::ViewState& viewState,
306 const ::com::sun::star::rendering::RenderState& renderState,
307 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures ) throw (::com::sun::star::lang::IllegalArgumentException,
308 ::com::sun::star::uno::RuntimeException)
310 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures,
311 BOOST_CURRENT_FUNCTION,
312 static_cast< UnambiguousBaseType* >(this));
314 MutexType aGuard( BaseType::m_aMutex );
316 mbSurfaceDirty = true;
317 maCanvasHelper.modifying();
319 return maCanvasHelper.fillTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures );
322 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
323 fillTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
324 const ::com::sun::star::rendering::ViewState& viewState,
325 const ::com::sun::star::rendering::RenderState& renderState,
326 const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures,
327 const ::com::sun::star::uno::Reference< ::com::sun::star::geometry::XMapping2D >& xMapping ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
329 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping,
330 BOOST_CURRENT_FUNCTION,
331 static_cast< UnambiguousBaseType* >(this));
333 MutexType aGuard( BaseType::m_aMutex );
335 mbSurfaceDirty = true;
336 maCanvasHelper.modifying();
338 return maCanvasHelper.fillTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping );
342 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
343 createFont( const ::com::sun::star::rendering::FontRequest& fontRequest,
344 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& extraFontProperties,
345 const ::com::sun::star::geometry::Matrix2D& fontMatrix ) throw (::com::sun::star::lang::IllegalArgumentException,
346 ::com::sun::star::uno::RuntimeException)
348 tools::verifyArgs(fontRequest,
349 // dummy, to keep argPos in sync
350 fontRequest,
351 fontMatrix,
352 BOOST_CURRENT_FUNCTION,
353 static_cast< UnambiguousBaseType* >(this));
355 MutexType aGuard( BaseType::m_aMutex );
357 return maCanvasHelper.createFont( this, fontRequest, extraFontProperties, fontMatrix );
361 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo > SAL_CALL
362 queryAvailableFonts( const ::com::sun::star::rendering::FontInfo& aFilter,
363 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aFontProperties ) throw (::com::sun::star::lang::IllegalArgumentException,
364 ::com::sun::star::uno::RuntimeException)
366 tools::verifyArgs(aFilter,
367 BOOST_CURRENT_FUNCTION,
368 static_cast< UnambiguousBaseType* >(this));
370 MutexType aGuard( BaseType::m_aMutex );
372 return maCanvasHelper.queryAvailableFonts( this, aFilter, aFontProperties );
376 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
377 drawText( const ::com::sun::star::rendering::StringContext& text,
378 const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont >& xFont,
379 const ::com::sun::star::rendering::ViewState& viewState,
380 const ::com::sun::star::rendering::RenderState& renderState,
381 sal_Int8 textDirection ) throw (::com::sun::star::lang::IllegalArgumentException,
382 ::com::sun::star::uno::RuntimeException)
384 tools::verifyArgs(xFont, viewState, renderState,
385 BOOST_CURRENT_FUNCTION,
386 static_cast< UnambiguousBaseType* >(this));
387 tools::verifyRange( textDirection,
388 ::com::sun::star::rendering::TextDirection::WEAK_LEFT_TO_RIGHT,
389 ::com::sun::star::rendering::TextDirection::STRONG_RIGHT_TO_LEFT );
391 MutexType aGuard( BaseType::m_aMutex );
393 mbSurfaceDirty = true;
394 maCanvasHelper.modifying();
396 return maCanvasHelper.drawText( this, text, xFont, viewState, renderState, textDirection );
400 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
401 drawTextLayout( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XTextLayout >& layoutetText,
402 const ::com::sun::star::rendering::ViewState& viewState,
403 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
405 tools::verifyArgs(layoutetText, viewState, renderState,
406 BOOST_CURRENT_FUNCTION,
407 static_cast< UnambiguousBaseType* >(this));
409 MutexType aGuard( BaseType::m_aMutex );
411 mbSurfaceDirty = true;
412 maCanvasHelper.modifying();
414 return maCanvasHelper.drawTextLayout( this, layoutetText, viewState, renderState );
418 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
419 drawBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap,
420 const ::com::sun::star::rendering::ViewState& viewState,
421 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
423 tools::verifyArgs(xBitmap, viewState, renderState,
424 BOOST_CURRENT_FUNCTION,
425 static_cast< UnambiguousBaseType* >(this));
427 MutexType aGuard( BaseType::m_aMutex );
429 mbSurfaceDirty = true;
430 maCanvasHelper.modifying();
432 return maCanvasHelper.drawBitmap( this, xBitmap, viewState, renderState );
435 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
436 drawBitmapModulated( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap,
437 const ::com::sun::star::rendering::ViewState& viewState,
438 const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
440 tools::verifyArgs(xBitmap, viewState, renderState,
441 BOOST_CURRENT_FUNCTION,
442 static_cast< UnambiguousBaseType* >(this));
444 MutexType aGuard( BaseType::m_aMutex );
446 mbSurfaceDirty = true;
447 maCanvasHelper.modifying();
449 return maCanvasHelper.drawBitmapModulated( this, xBitmap, viewState, renderState );
452 virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > SAL_CALL
453 getDevice() throw (::com::sun::star::uno::RuntimeException)
455 MutexType aGuard( BaseType::m_aMutex );
457 return maCanvasHelper.getDevice();
460 protected:
461 ~CanvasBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
463 HelperType maCanvasHelper;
464 mutable bool mbSurfaceDirty;
466 private:
467 CanvasBase( const CanvasBase& );
468 CanvasBase& operator=( const CanvasBase& );
472 #endif /* INCLUDED_CANVAS_CANVASBASE_HXX */
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */