LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / canvas / inc / base / canvasbase.hxx
blob24737f784d5920899b8df39a4f1654cc3a70c71e
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 #pragma once
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/rendering/TextDirection.hpp>
25 #include <osl/mutex.hxx>
26 #include <verifyinput.hxx>
28 namespace com::sun::star::beans { struct PropertyValue; }
29 namespace com::sun::star::geometry { class XMapping2D; }
30 namespace com::sun::star::rendering { class XBitmap; }
31 namespace com::sun::star::rendering { class XCachedPrimitive; }
32 namespace com::sun::star::rendering { class XCanvasFont; }
33 namespace com::sun::star::rendering { class XGraphicDevice; }
34 namespace com::sun::star::rendering { class XPolyPolygon2D; }
35 namespace com::sun::star::rendering { class XTextLayout; }
36 namespace com::sun::star::rendering { struct FontInfo; }
37 namespace com::sun::star::rendering { struct StringContext; }
40 namespace canvas
42 /** Helper template to handle XCanvas method forwarding to CanvasHelper
44 Use this helper to handle the XCanvas part of your
45 implementation. In theory, we could have provided CanvasHelper
46 and CanvasBase as a single template, but that would duplicate
47 a lot of code now residing in CanvasHelper only.
49 This template basically interposes itself between the full
50 interface you implement (i.e. not restricted to XCanvas. The
51 problem with UNO partial interface implementation actually is,
52 that you cannot do it the plain way, since deriving from a
53 common base subclass always introduces the whole set of pure
54 virtuals, that your baseclass helper just overridden) and your
55 implementation class. You then only have to implement the
56 functionality <em>besides</em> XCanvas.
58 <pre>
59 Example:
60 typedef ::cppu::WeakComponentImplHelper < css::rendering::XSpriteCanvas,
61 css::lang::XInitialization,
62 css::lang::XServiceInfo,
63 css::lang::XServiceName > CanvasBase_Base;
64 typedef ::canvas::internal::CanvasBase< CanvasBase_Base, CanvasHelper > ExampleCanvas_Base;
66 class ExampleCanvas : public ExampleCanvas_Base,
67 public SpriteSurface,
68 public RepaintTarget
71 </pre>
73 @tpl Base
74 Base class to use, most probably the
75 WeakComponentImplHelper template with the appropriate
76 interfaces. At least XCanvas should be among them (why else
77 would you use this template, then?). Base class must have an
78 Base( const Mutex& ) constructor (like the
79 WeakComponentImplHelper template has). As the very least,
80 the base class must be derived from uno::XInterface, as some
81 error reporting mechanisms rely on that.
83 @tpl CanvasHelper
84 Canvas helper implementation for the backend in question. This
85 object will be held as a member of this template class, and
86 basically gets forwarded all XCanvas API calls. Furthermore,
87 every time the canvas API semantically changes the content of
88 the canvas, CanvasHelper::modifying() will get called
89 (<em>before</em> the actual modification takes place).
91 @tpl Mutex
92 Lock strategy to use. Defaults to using the
93 BaseMutex-provided lock. Every time one of the methods is
94 entered, an object of type Mutex is created with m_aMutex as
95 the sole parameter, and destroyed again when the method scope
96 is left.
98 @tpl UnambiguousBase
99 Optional unambiguous base class for XInterface of Base. It's
100 sometimes necessary to specify this parameter, e.g. if Base
101 derives from multiple UNO interface (were each provides its
102 own version of XInterface, making the conversion ambiguous)
104 template< class Base,
105 class CanvasHelper,
106 class Mutex=::osl::MutexGuard,
107 class UnambiguousBase=css::uno::XInterface > class CanvasBase :
108 public Base
110 public:
111 typedef Base BaseType;
112 typedef Mutex MutexType;
113 typedef UnambiguousBase UnambiguousBaseType;
115 /** Create CanvasBase
117 CanvasBase() :
118 maCanvasHelper(),
119 mbSurfaceDirty( true )
123 virtual void disposeThis() override
125 MutexType aGuard( BaseType::m_aMutex );
127 maCanvasHelper.disposing();
129 // pass on to base class
130 BaseType::disposeThis();
133 // XCanvas
134 virtual void SAL_CALL clear() override
136 MutexType aGuard( BaseType::m_aMutex );
138 mbSurfaceDirty = true;
140 maCanvasHelper.clear();
143 virtual void SAL_CALL drawPoint(const css::geometry::RealPoint2D& aPoint,
144 const css::rendering::ViewState& viewState,
145 const css::rendering::RenderState& renderState) override
147 tools::verifyArgs(aPoint, viewState, renderState,
148 __func__,
149 static_cast< UnambiguousBaseType* >(this));
151 MutexType aGuard( BaseType::m_aMutex );
153 mbSurfaceDirty = true;
156 virtual void SAL_CALL drawLine(const css::geometry::RealPoint2D& aStartPoint,
157 const css::geometry::RealPoint2D& aEndPoint,
158 const css::rendering::ViewState& viewState,
159 const css::rendering::RenderState& renderState) override
161 tools::verifyArgs(aStartPoint, aEndPoint, viewState, renderState,
162 __func__,
163 static_cast< UnambiguousBaseType* >(this));
165 MutexType aGuard( BaseType::m_aMutex );
167 mbSurfaceDirty = true;
169 maCanvasHelper.drawLine( this, aStartPoint, aEndPoint, viewState, renderState );
172 virtual void SAL_CALL drawBezier( const css::geometry::RealBezierSegment2D& aBezierSegment,
173 const css::geometry::RealPoint2D& aEndPoint,
174 const css::rendering::ViewState& viewState,
175 const css::rendering::RenderState& renderState ) override
177 tools::verifyArgs(aBezierSegment, aEndPoint, viewState, renderState,
178 __func__,
179 static_cast< UnambiguousBaseType* >(this));
181 MutexType aGuard( BaseType::m_aMutex );
183 mbSurfaceDirty = true;
185 maCanvasHelper.drawBezier( this, aBezierSegment, aEndPoint, viewState, renderState );
188 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
189 drawPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
190 const css::rendering::ViewState& viewState,
191 const css::rendering::RenderState& renderState) override
193 tools::verifyArgs(xPolyPolygon, viewState, renderState,
194 __func__,
195 static_cast< UnambiguousBaseType* >(this));
197 MutexType aGuard( BaseType::m_aMutex );
199 mbSurfaceDirty = true;
201 return maCanvasHelper.drawPolyPolygon( this, xPolyPolygon, viewState, renderState );
204 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
205 strokePolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
206 const css::rendering::ViewState& viewState,
207 const css::rendering::RenderState& renderState,
208 const css::rendering::StrokeAttributes& strokeAttributes) override
210 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
211 __func__,
212 static_cast< UnambiguousBaseType* >(this));
214 MutexType aGuard( BaseType::m_aMutex );
216 mbSurfaceDirty = true;
218 return maCanvasHelper.strokePolyPolygon( this, xPolyPolygon, viewState, renderState, strokeAttributes );
221 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
222 strokeTexturedPolyPolygon( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
223 const css::rendering::ViewState& viewState,
224 const css::rendering::RenderState& renderState,
225 const css::uno::Sequence< css::rendering::Texture >& textures,
226 const css::rendering::StrokeAttributes& strokeAttributes ) override
228 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
229 __func__,
230 static_cast< UnambiguousBaseType* >(this));
232 MutexType aGuard( BaseType::m_aMutex );
234 mbSurfaceDirty = true;
236 return maCanvasHelper.strokeTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, strokeAttributes );
239 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
240 strokeTextureMappedPolyPolygon( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
241 const css::rendering::ViewState& viewState,
242 const css::rendering::RenderState& renderState,
243 const css::uno::Sequence< css::rendering::Texture >& textures,
244 const css::uno::Reference< css::geometry::XMapping2D >& xMapping,
245 const css::rendering::StrokeAttributes& strokeAttributes ) override
247 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes,
248 __func__,
249 static_cast< UnambiguousBaseType* >(this));
251 MutexType aGuard( BaseType::m_aMutex );
253 mbSurfaceDirty = true;
255 return maCanvasHelper.strokeTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping, strokeAttributes );
258 virtual css::uno::Reference< css::rendering::XPolyPolygon2D > SAL_CALL
259 queryStrokeShapes( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
260 const css::rendering::ViewState& viewState,
261 const css::rendering::RenderState& renderState,
262 const css::rendering::StrokeAttributes& strokeAttributes ) override
264 tools::verifyArgs(xPolyPolygon, viewState, renderState, strokeAttributes,
265 __func__,
266 static_cast< UnambiguousBaseType* >(this));
268 MutexType aGuard( BaseType::m_aMutex );
270 mbSurfaceDirty = true;
272 return maCanvasHelper.queryStrokeShapes( this, xPolyPolygon, viewState, renderState, strokeAttributes );
275 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
276 fillPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
277 const css::rendering::ViewState& viewState,
278 const css::rendering::RenderState& renderState) override
280 tools::verifyArgs(xPolyPolygon, viewState, renderState,
281 __func__,
282 static_cast< UnambiguousBaseType* >(this));
284 MutexType aGuard( BaseType::m_aMutex );
286 mbSurfaceDirty = true;
288 return maCanvasHelper.fillPolyPolygon( this, xPolyPolygon, viewState, renderState );
291 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
292 fillTexturedPolyPolygon(const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
293 const css::rendering::ViewState& viewState,
294 const css::rendering::RenderState& renderState,
295 const css::uno::Sequence< css::rendering::Texture >& textures) override
297 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures,
298 __func__,
299 static_cast< UnambiguousBaseType* >(this));
301 MutexType aGuard( BaseType::m_aMutex );
303 mbSurfaceDirty = true;
305 return maCanvasHelper.fillTexturedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures );
308 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
309 fillTextureMappedPolyPolygon( const css::uno::Reference< css::rendering::XPolyPolygon2D >& xPolyPolygon,
310 const css::rendering::ViewState& viewState,
311 const css::rendering::RenderState& renderState,
312 const css::uno::Sequence< css::rendering::Texture >& textures,
313 const css::uno::Reference< css::geometry::XMapping2D >& xMapping ) override
315 tools::verifyArgs(xPolyPolygon, viewState, renderState, textures, xMapping,
316 __func__,
317 static_cast< UnambiguousBaseType* >(this));
319 MutexType aGuard( BaseType::m_aMutex );
321 mbSurfaceDirty = true;
323 return maCanvasHelper.fillTextureMappedPolyPolygon( this, xPolyPolygon, viewState, renderState, textures, xMapping );
327 virtual css::uno::Reference< css::rendering::XCanvasFont > SAL_CALL
328 createFont( const css::rendering::FontRequest& fontRequest,
329 const css::uno::Sequence< css::beans::PropertyValue >& extraFontProperties,
330 const css::geometry::Matrix2D& fontMatrix ) override
332 tools::verifyArgs(fontRequest,
333 // dummy, to keep argPos in sync
334 fontRequest,
335 fontMatrix,
336 __func__,
337 static_cast< UnambiguousBaseType* >(this));
339 MutexType aGuard( BaseType::m_aMutex );
341 return maCanvasHelper.createFont( this, fontRequest, extraFontProperties, fontMatrix );
345 virtual css::uno::Sequence< css::rendering::FontInfo > SAL_CALL
346 queryAvailableFonts( const css::rendering::FontInfo& aFilter,
347 const css::uno::Sequence< css::beans::PropertyValue >& aFontProperties ) override
349 tools::verifyArgs(aFilter,
350 __func__,
351 static_cast< UnambiguousBaseType* >(this));
353 MutexType aGuard( BaseType::m_aMutex );
355 return maCanvasHelper.queryAvailableFonts( this, aFilter, aFontProperties );
359 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
360 drawText(const css::rendering::StringContext& text,
361 const css::uno::Reference< css::rendering::XCanvasFont >& xFont,
362 const css::rendering::ViewState& viewState,
363 const css::rendering::RenderState& renderState,
364 sal_Int8 textDirection) override
366 tools::verifyArgs(xFont, viewState, renderState,
367 __func__,
368 static_cast< UnambiguousBaseType* >(this));
369 tools::verifyRange( textDirection,
370 css::rendering::TextDirection::WEAK_LEFT_TO_RIGHT,
371 css::rendering::TextDirection::STRONG_RIGHT_TO_LEFT );
373 MutexType aGuard( BaseType::m_aMutex );
375 mbSurfaceDirty = true;
377 return maCanvasHelper.drawText( this, text, xFont, viewState, renderState, textDirection );
381 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
382 drawTextLayout(const css::uno::Reference< css::rendering::XTextLayout >& laidOutText,
383 const css::rendering::ViewState& viewState,
384 const css::rendering::RenderState& renderState) override
386 tools::verifyArgs(laidOutText, viewState, renderState,
387 __func__,
388 static_cast< UnambiguousBaseType* >(this));
390 MutexType aGuard( BaseType::m_aMutex );
392 mbSurfaceDirty = true;
394 return maCanvasHelper.drawTextLayout( this, laidOutText, viewState, renderState );
398 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
399 drawBitmap( const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
400 const css::rendering::ViewState& viewState,
401 const css::rendering::RenderState& renderState ) override
403 tools::verifyArgs(xBitmap, viewState, renderState,
404 __func__,
405 static_cast< UnambiguousBaseType* >(this));
407 MutexType aGuard( BaseType::m_aMutex );
409 mbSurfaceDirty = true;
411 return maCanvasHelper.drawBitmap( this, xBitmap, viewState, renderState );
414 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
415 drawBitmapModulated( const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
416 const css::rendering::ViewState& viewState,
417 const css::rendering::RenderState& renderState ) override
419 tools::verifyArgs(xBitmap, viewState, renderState,
420 __func__,
421 static_cast< UnambiguousBaseType* >(this));
423 MutexType aGuard( BaseType::m_aMutex );
425 mbSurfaceDirty = true;
427 return maCanvasHelper.drawBitmapModulated( this, xBitmap, viewState, renderState );
430 virtual css::uno::Reference< css::rendering::XGraphicDevice > SAL_CALL
431 getDevice() override
433 MutexType aGuard( BaseType::m_aMutex );
435 return maCanvasHelper.getDevice();
438 protected:
439 ~CanvasBase() {} // we're a ref-counted UNO class. _We_ destroy ourselves.
441 CanvasHelper maCanvasHelper;
442 mutable bool mbSurfaceDirty;
444 private:
445 CanvasBase( const CanvasBase& ) = delete;
446 CanvasBase& operator=( const CanvasBase& ) = delete;
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */