1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <com/sun/star/rendering/XCanvas.hpp>
24 #include <basegfx/point/b2dpoint.hxx>
25 #include <basegfx/vector/b2dvector.hxx>
26 #include <basegfx/range/b2drange.hxx>
27 #include <base/integerbitmapbase.hxx>
28 #include <base/bitmapcanvasbase.hxx>
30 namespace com::sun::star::rendering
{ class XPolyPolygon2D
; }
34 /** Helper template to handle XCustomSprite method forwarding to
35 CanvasCustomSpriteHelper
37 Use this helper to handle the XCustomSprite part of your
41 Base class to use, most probably one of the
42 WeakComponentImplHelperN templates with the appropriate
43 interfaces. At least XCustomSprite and Sprite should be among
44 them (why else would you use this template, then?). Base class
45 must have a Base( const Mutex& ) constructor (like the
46 WeakComponentImplHelperN templates have).
49 Sprite helper implementation for the backend in question
52 Canvas helper implementation for the backend in question
55 Lock strategy to use. Defaults to using the
56 BaseMutex-provided lock. Every time one of the methods is
57 entered, an object of type Mutex is created with m_aMutex as
58 the sole parameter, and destroyed again when the method scope
62 Optional unambiguous base class for XInterface of Base. It's
63 sometimes necessary to specify this parameter, e.g. if Base
64 derives from multiple UNO interface (were each provides its
65 own version of XInterface, making the conversion ambiguous)
67 @see CanvasCustomSpriteHelper for further contractual
68 requirements towards the SpriteHelper type, and some examples.
73 class Mutex
=::osl::MutexGuard
,
74 class UnambiguousBase
= css::uno::XInterface
> class CanvasCustomSpriteBase
:
75 public IntegerBitmapBase
< BitmapCanvasBase2
<Base
, CanvasHelper
, Mutex
, UnambiguousBase
> >
78 typedef IntegerBitmapBase
< BitmapCanvasBase2
<Base
, CanvasHelper
, Mutex
, UnambiguousBase
> > BaseType
;
80 CanvasCustomSpriteBase() :
85 /** Object is being disposed.
87 Called from the cppu helper base, to notify disposal of
88 this object. Already releases all internal references.
90 @derive when overriding this method in derived classes,
91 <em>always</em> call the base class' method!
93 virtual void disposeThis() override
95 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
97 maSpriteHelper
.disposing();
99 // pass on to base class
100 BaseType::disposeThis();
103 // XCanvas: selectively override base's methods here, for opacity tracking
104 virtual void SAL_CALL
clear() override
106 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
108 maSpriteHelper
.clearingContent( this );
110 // and forward to base class, which handles the actual rendering
111 return BaseType::clear();
114 virtual css::uno::Reference
< css::rendering::XCachedPrimitive
> SAL_CALL
115 drawBitmap( const css::uno::Reference
< css::rendering::XBitmap
>& xBitmap
,
116 const css::rendering::ViewState
& viewState
,
117 const css::rendering::RenderState
& renderState
) override
119 tools::verifyArgs(xBitmap
, viewState
, renderState
,
121 static_cast< typename
BaseType::UnambiguousBaseType
* >(this));
123 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
125 maSpriteHelper
.checkDrawBitmap( this, xBitmap
, viewState
, renderState
);
127 // and forward to base class, which handles the actual rendering
128 return BaseType::drawBitmap( xBitmap
,
133 // TODO(F3): If somebody uses the XIntegerBitmap methods to
134 // clear pixel (setting alpha != 1.0 there), or a compositing
135 // mode results in similar alpha, maSpriteHelper might
136 // erroneously report fully opaque sprites. Effectively, all
137 // render methods must be overridden here; or better,
138 // functionality provided at the baseclass.
141 virtual void SAL_CALL
setAlpha( double alpha
) override
143 tools::verifyRange( alpha
, 0.0, 1.0 );
145 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
147 maSpriteHelper
.setAlpha( this, alpha
);
150 virtual void SAL_CALL
move( const css::geometry::RealPoint2D
& aNewPos
,
151 const css::rendering::ViewState
& viewState
,
152 const css::rendering::RenderState
& renderState
) override
154 tools::verifyArgs(aNewPos
, viewState
, renderState
,
156 static_cast< typename
BaseType::UnambiguousBaseType
* >(this));
158 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
160 maSpriteHelper
.move( this, aNewPos
, viewState
, renderState
);
163 virtual void SAL_CALL
transform( const css::geometry::AffineMatrix2D
& aTransformation
) override
165 tools::verifyArgs(aTransformation
,
167 static_cast< typename
BaseType::UnambiguousBaseType
* >(this));
169 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
171 maSpriteHelper
.transform( this, aTransformation
);
174 virtual void SAL_CALL
clip( const css::uno::Reference
< css::rendering::XPolyPolygon2D
>& aClip
) override
176 // NULL xClip explicitly allowed here (to clear clipping)
178 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
180 maSpriteHelper
.clip( this, aClip
);
183 virtual void SAL_CALL
setPriority( double nPriority
) override
185 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
187 maSpriteHelper
.setPriority( this, nPriority
);
190 virtual void SAL_CALL
show() override
192 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
194 maSpriteHelper
.show( this );
197 virtual void SAL_CALL
hide() override
199 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
201 maSpriteHelper
.hide( this );
205 virtual css::uno::Reference
< css::rendering::XCanvas
> SAL_CALL
206 getContentCanvas() override
208 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
214 virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange
& rUpdateArea
) const override
216 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
218 return maSpriteHelper
.isAreaUpdateOpaque( rUpdateArea
);
221 virtual bool isContentChanged() const override
223 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
225 return BaseType::mbSurfaceDirty
;
228 virtual ::basegfx::B2DPoint
getPosPixel() const override
230 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
232 return maSpriteHelper
.getPosPixel();
235 virtual ::basegfx::B2DVector
getSizePixel() const override
237 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
239 return maSpriteHelper
.getSizePixel();
242 virtual ::basegfx::B2DRange
getUpdateArea() const override
244 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
246 return maSpriteHelper
.getUpdateArea();
249 virtual double getPriority() const override
251 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
253 return maSpriteHelper
.getPriority();
257 SpriteHelper maSpriteHelper
;
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */