Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_CANVAS_BASE_CANVASBASE_HXX
21 : #define INCLUDED_CANVAS_BASE_CANVASBASE_HXX
22 :
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>
28 :
29 :
30 : namespace canvas
31 : {
32 : /** Helper template to handle XCanvas method forwarding to CanvasHelper
33 :
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.
38 :
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.
47 :
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;
55 :
56 : class ExampleCanvas : public ExampleCanvas_Base,
57 : public SpriteSurface,
58 : public RepaintTarget
59 : {
60 : };
61 : </pre>
62 :
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.
72 :
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 : every time 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).
80 :
81 : @tpl Mutex
82 : Lock strategy to use. Defaults to using the
83 : OBaseMutex-provided lock. Every time 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.
87 :
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)
93 : */
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
99 : {
100 : public:
101 : typedef Base BaseType;
102 : typedef CanvasHelper HelperType;
103 : typedef Mutex MutexType;
104 : typedef UnambiguousBase UnambiguousBaseType;
105 :
106 : /** Create CanvasBase
107 : */
108 5 : CanvasBase() :
109 : maCanvasHelper(),
110 5 : mbSurfaceDirty( true )
111 : {
112 5 : }
113 :
114 5 : virtual void disposeThis() SAL_OVERRIDE
115 : {
116 5 : MutexType aGuard( BaseType::m_aMutex );
117 :
118 5 : maCanvasHelper.disposing();
119 :
120 : // pass on to base class
121 5 : BaseType::disposeThis();
122 5 : }
123 :
124 : // XCanvas
125 2 : virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
126 : {
127 2 : MutexType aGuard( BaseType::m_aMutex );
128 :
129 2 : mbSurfaceDirty = true;
130 :
131 2 : maCanvasHelper.clear();
132 2 : }
133 :
134 0 : virtual void SAL_CALL drawPoint(const css::geometry::RealPoint2D& aPoint,
135 : const css::rendering::ViewState& viewState,
136 : const css::rendering::RenderState& renderState)
137 : throw (css::lang::IllegalArgumentException,
138 : css::uno::RuntimeException,
139 : std::exception) SAL_OVERRIDE
140 : {
141 0 : tools::verifyArgs(aPoint, viewState, renderState,
142 : BOOST_CURRENT_FUNCTION,
143 0 : static_cast< UnambiguousBaseType* >(this));
144 :
145 0 : MutexType aGuard( BaseType::m_aMutex );
146 :
147 0 : mbSurfaceDirty = true;
148 0 : }
149 :
150 0 : virtual void SAL_CALL drawLine(const css::geometry::RealPoint2D& aStartPoint,
151 : const css::geometry::RealPoint2D& aEndPoint,
152 : const css::rendering::ViewState& viewState,
153 : const css::rendering::RenderState& renderState)
154 : throw (css::lang::IllegalArgumentException,
155 : css::uno::RuntimeException,
156 : std::exception) SAL_OVERRIDE
157 : {
158 0 : tools::verifyArgs(aStartPoint, aEndPoint, viewState, renderState,
159 : BOOST_CURRENT_FUNCTION,
160 0 : static_cast< UnambiguousBaseType* >(this));
161 :
162 0 : MutexType aGuard( BaseType::m_aMutex );
163 :
164 0 : mbSurfaceDirty = true;
165 :
166 0 : maCanvasHelper.drawLine( this, aStartPoint, aEndPoint, viewState, renderState );
167 0 : }
168 :
169 0 : virtual void SAL_CALL drawBezier( const css::geometry::RealBezierSegment2D& aBezierSegment,
170 : const css::geometry::RealPoint2D& aEndPoint,
171 : const css::rendering::ViewState& viewState,
172 : const css::rendering::RenderState& renderState )
173 : throw (css::lang::IllegalArgumentException,
174 : css::uno::RuntimeException,
175 : std::exception) SAL_OVERRIDE
176 : {
177 0 : tools::verifyArgs(aBezierSegment, aEndPoint, viewState, renderState,
178 : BOOST_CURRENT_FUNCTION,
179 0 : static_cast< UnambiguousBaseType* >(this));
180 :
181 0 : MutexType aGuard( BaseType::m_aMutex );
182 :
183 0 : mbSurfaceDirty = true;
184 :
185 0 : maCanvasHelper.drawBezier( this, aBezierSegment, aEndPoint, viewState, renderState );
186 0 : }
187 :
188 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
189 0 : drawPolyPolygon(const css::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
190 : const css::rendering::ViewState& viewState,
191 : const css::rendering::RenderState& renderState)
192 : throw (css::lang::IllegalArgumentException,
193 : css::uno::RuntimeException,
194 : std::exception) SAL_OVERRIDE
195 : {
196 0 : tools::verifyArgs(xPolyPolygon, viewState, renderState,
197 : BOOST_CURRENT_FUNCTION,
198 0 : static_cast< UnambiguousBaseType* >(this));
199 :
200 0 : MutexType aGuard( BaseType::m_aMutex );
201 :
202 0 : mbSurfaceDirty = true;
203 :
204 0 : return maCanvasHelper.drawPolyPolygon( this, xPolyPolygon, viewState, renderState );
205 : }
206 :
207 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
208 4 : strokePolyPolygon(const css::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
209 : const css::rendering::ViewState& viewState,
210 : const css::rendering::RenderState& renderState,
211 : const css::rendering::StrokeAttributes& strokeAttributes)
212 : throw (css::lang::IllegalArgumentException,
213 : css::uno::RuntimeException,
214 : std::exception) SAL_OVERRIDE
215 : {
216 4 : tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
217 : BOOST_CURRENT_FUNCTION,
218 8 : static_cast< UnambiguousBaseType* >(this));
219 :
220 4 : MutexType aGuard( BaseType::m_aMutex );
221 :
222 4 : mbSurfaceDirty = true;
223 :
224 4 : return maCanvasHelper.strokePolyPolygon( this, xPolyPolygon, viewState, renderState, strokeAttributes );
225 : }
226 :
227 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
228 0 : strokeTexturedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
229 : const ::com::sun::star::rendering::ViewState& viewState,
230 : const ::com::sun::star::rendering::RenderState& renderState,
231 : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures,
232 : const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException,
233 : ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
234 : {
235 0 : tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
236 : BOOST_CURRENT_FUNCTION,
237 0 : static_cast< UnambiguousBaseType* >(this));
238 :
239 0 : MutexType aGuard( BaseType::m_aMutex );
240 :
241 0 : mbSurfaceDirty = true;
242 :
243 0 : return maCanvasHelper.strokeTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, strokeAttributes );
244 : }
245 :
246 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
247 0 : strokeTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
248 : const ::com::sun::star::rendering::ViewState& viewState,
249 : const ::com::sun::star::rendering::RenderState& renderState,
250 : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures,
251 : const ::com::sun::star::uno::Reference< ::com::sun::star::geometry::XMapping2D >& xMapping,
252 : const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes ) throw (::com::sun::star::lang::IllegalArgumentException,
253 : ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
254 : {
255 0 : tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes,
256 : BOOST_CURRENT_FUNCTION,
257 0 : static_cast< UnambiguousBaseType* >(this));
258 :
259 0 : MutexType aGuard( BaseType::m_aMutex );
260 :
261 0 : mbSurfaceDirty = true;
262 :
263 0 : return maCanvasHelper.strokeTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes );
264 : }
265 :
266 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D > SAL_CALL
267 0 : 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) SAL_OVERRIDE
272 : {
273 0 : tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
274 : BOOST_CURRENT_FUNCTION,
275 0 : static_cast< UnambiguousBaseType* >(this));
276 :
277 0 : MutexType aGuard( BaseType::m_aMutex );
278 :
279 0 : mbSurfaceDirty = true;
280 :
281 0 : return maCanvasHelper.queryStrokeShapes( this, xPolyPolygon, viewState, renderState, strokeAttributes );
282 : }
283 :
284 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
285 6 : fillPolyPolygon(const css::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
286 : const css::rendering::ViewState& viewState,
287 : const css::rendering::RenderState& renderState)
288 : throw (css::lang::IllegalArgumentException,
289 : css::uno::RuntimeException,
290 : std::exception) SAL_OVERRIDE
291 : {
292 6 : tools::verifyArgs(xPolyPolygon, viewState, renderState,
293 : BOOST_CURRENT_FUNCTION,
294 12 : static_cast< UnambiguousBaseType* >(this));
295 :
296 6 : MutexType aGuard( BaseType::m_aMutex );
297 :
298 6 : mbSurfaceDirty = true;
299 :
300 6 : return maCanvasHelper.fillPolyPolygon( this, xPolyPolygon, viewState, renderState );
301 : }
302 :
303 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
304 0 : fillTexturedPolyPolygon(const css::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
305 : const css::rendering::ViewState& viewState,
306 : const css::rendering::RenderState& renderState,
307 : const css::uno::Sequence< ::com::sun::star::rendering::Texture >& textures)
308 : throw (css::lang::IllegalArgumentException,
309 : css::uno::RuntimeException,
310 : std::exception) SAL_OVERRIDE
311 : {
312 0 : tools::verifyArgs(xPolyPolygon, viewState, renderState, textures,
313 : BOOST_CURRENT_FUNCTION,
314 0 : static_cast< UnambiguousBaseType* >(this));
315 :
316 0 : MutexType aGuard( BaseType::m_aMutex );
317 :
318 0 : mbSurfaceDirty = true;
319 :
320 0 : return maCanvasHelper.fillTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures );
321 : }
322 :
323 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
324 0 : fillTextureMappedPolyPolygon( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
325 : const ::com::sun::star::rendering::ViewState& viewState,
326 : const ::com::sun::star::rendering::RenderState& renderState,
327 : const ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::Texture >& textures,
328 : const ::com::sun::star::uno::Reference< ::com::sun::star::geometry::XMapping2D >& xMapping ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
329 : {
330 0 : tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping,
331 : BOOST_CURRENT_FUNCTION,
332 0 : static_cast< UnambiguousBaseType* >(this));
333 :
334 0 : MutexType aGuard( BaseType::m_aMutex );
335 :
336 0 : mbSurfaceDirty = true;
337 :
338 0 : return maCanvasHelper.fillTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping );
339 : }
340 :
341 :
342 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvasFont > SAL_CALL
343 0 : 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) SAL_OVERRIDE
347 : {
348 0 : tools::verifyArgs(fontRequest,
349 : // dummy, to keep argPos in sync
350 : fontRequest,
351 : fontMatrix,
352 : BOOST_CURRENT_FUNCTION,
353 0 : static_cast< UnambiguousBaseType* >(this));
354 :
355 0 : MutexType aGuard( BaseType::m_aMutex );
356 :
357 0 : return maCanvasHelper.createFont( this, fontRequest, extraFontProperties, fontMatrix );
358 : }
359 :
360 :
361 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::rendering::FontInfo > SAL_CALL
362 0 : 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) SAL_OVERRIDE
365 : {
366 0 : tools::verifyArgs(aFilter,
367 : BOOST_CURRENT_FUNCTION,
368 0 : static_cast< UnambiguousBaseType* >(this));
369 :
370 0 : MutexType aGuard( BaseType::m_aMutex );
371 :
372 0 : return maCanvasHelper.queryAvailableFonts( this, aFilter, aFontProperties );
373 : }
374 :
375 :
376 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
377 0 : drawText(const css::rendering::StringContext& text,
378 : const css::uno::Reference< ::com::sun::star::rendering::XCanvasFont >& xFont,
379 : const css::rendering::ViewState& viewState,
380 : const css::rendering::RenderState& renderState,
381 : sal_Int8 textDirection)
382 : throw (css::lang::IllegalArgumentException,
383 : css::uno::RuntimeException,
384 : std::exception) SAL_OVERRIDE
385 : {
386 0 : tools::verifyArgs(xFont, viewState, renderState,
387 : BOOST_CURRENT_FUNCTION,
388 0 : static_cast< UnambiguousBaseType* >(this));
389 0 : tools::verifyRange( textDirection,
390 : ::com::sun::star::rendering::TextDirection::WEAK_LEFT_TO_RIGHT,
391 0 : ::com::sun::star::rendering::TextDirection::STRONG_RIGHT_TO_LEFT );
392 :
393 0 : MutexType aGuard( BaseType::m_aMutex );
394 :
395 0 : mbSurfaceDirty = true;
396 :
397 0 : return maCanvasHelper.drawText( this, text, xFont, viewState, renderState, textDirection );
398 : }
399 :
400 :
401 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
402 0 : drawTextLayout(const css::uno::Reference< ::com::sun::star::rendering::XTextLayout >& laidOutText,
403 : const css::rendering::ViewState& viewState,
404 : const css::rendering::RenderState& renderState)
405 : throw (css::lang::IllegalArgumentException,
406 : css::uno::RuntimeException,
407 : std::exception) SAL_OVERRIDE
408 : {
409 0 : tools::verifyArgs(laidOutText, viewState, renderState,
410 : BOOST_CURRENT_FUNCTION,
411 0 : static_cast< UnambiguousBaseType* >(this));
412 :
413 0 : MutexType aGuard( BaseType::m_aMutex );
414 :
415 0 : mbSurfaceDirty = true;
416 :
417 0 : return maCanvasHelper.drawTextLayout( this, laidOutText, viewState, renderState );
418 : }
419 :
420 :
421 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
422 2 : drawBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap,
423 : const ::com::sun::star::rendering::ViewState& viewState,
424 : const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
425 : {
426 2 : tools::verifyArgs(xBitmap, viewState, renderState,
427 : BOOST_CURRENT_FUNCTION,
428 4 : static_cast< UnambiguousBaseType* >(this));
429 :
430 2 : MutexType aGuard( BaseType::m_aMutex );
431 :
432 2 : mbSurfaceDirty = true;
433 :
434 2 : return maCanvasHelper.drawBitmap( this, xBitmap, viewState, renderState );
435 : }
436 :
437 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
438 0 : drawBitmapModulated( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap,
439 : const ::com::sun::star::rendering::ViewState& viewState,
440 : const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
441 : {
442 0 : tools::verifyArgs(xBitmap, viewState, renderState,
443 : BOOST_CURRENT_FUNCTION,
444 0 : static_cast< UnambiguousBaseType* >(this));
445 :
446 0 : MutexType aGuard( BaseType::m_aMutex );
447 :
448 0 : mbSurfaceDirty = true;
449 :
450 0 : return maCanvasHelper.drawBitmapModulated( this, xBitmap, viewState, renderState );
451 : }
452 :
453 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XGraphicDevice > SAL_CALL
454 36 : getDevice() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
455 : {
456 36 : MutexType aGuard( BaseType::m_aMutex );
457 :
458 36 : return maCanvasHelper.getDevice();
459 : }
460 :
461 : protected:
462 5 : ~CanvasBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
463 :
464 : HelperType maCanvasHelper;
465 : mutable bool mbSurfaceDirty;
466 :
467 : private:
468 : CanvasBase( const CanvasBase& ) SAL_DELETED_FUNCTION;
469 : CanvasBase& operator=( const CanvasBase& ) SAL_DELETED_FUNCTION;
470 : };
471 : }
472 :
473 : #endif // INCLUDED_CANVAS_BASE_CANVASBASE_HXX
474 :
475 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|