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 .
20 #ifndef INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEBASE_HXX
21 #define INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEBASE_HXX
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/rendering/XCustomSprite.hpp>
25 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
26 #include <basegfx/point/b2dpoint.hxx>
27 #include <basegfx/vector/b2dvector.hxx>
28 #include <basegfx/range/b2drange.hxx>
29 #include <canvas/base/integerbitmapbase.hxx>
30 #include <canvas/base/sprite.hxx>
32 #include <boost/utility.hpp>
37 /** Helper template to handle XCustomSprite method forwarding to
38 CanvasCustomSpriteHelper
40 Use this helper to handle the XCustomSprite part of your
44 Base class to use, most probably one of the
45 WeakComponentImplHelperN templates with the appropriate
46 interfaces. At least XCustomSprite and Sprite should be among
47 them (why else would you use this template, then?). Base class
48 must have an Base( const Mutex& ) constructor (like the
49 WeakComponentImplHelperN templates have).
52 Sprite helper implementation for the backend in question
55 Canvas helper implementation for the backend in question
58 Lock strategy to use. Defaults to using the
59 OBaseMutex-provided lock. Every time one of the methods is
60 entered, an object of type Mutex is created with m_aMutex as
61 the sole parameter, and destroyed again when the method scope
65 Optional unambiguous base class for XInterface of Base. It's
66 sometimes necessary to specify this parameter, e.g. if Base
67 derives from multiple UNO interface (were each provides its
68 own version of XInterface, making the conversion ambiguous)
70 @see CanvasCustomSpriteHelper for further contractual
71 requirements towards the SpriteHelper type, and some examples.
76 class Mutex
=::osl::MutexGuard
,
77 class UnambiguousBase
=::com::sun::star::uno::XInterface
> class CanvasCustomSpriteBase
:
78 public IntegerBitmapBase
< BitmapCanvasBase2
<Base
, CanvasHelper
, Mutex
, UnambiguousBase
> >
81 typedef IntegerBitmapBase
< BitmapCanvasBase2
<Base
, CanvasHelper
, Mutex
, UnambiguousBase
> > BaseType
;
82 typedef SpriteHelper SpriteHelperType
;
84 CanvasCustomSpriteBase() :
89 /** Object is being disposed.
91 Called from the cppu helper base, to notify disposal of
92 this object. Already releases all internal references.
94 @derive when overriding this method in derived classes,
95 <em>always</em> call the base class' method!
97 virtual void disposeThis() SAL_OVERRIDE
99 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
101 maSpriteHelper
.disposing();
103 // pass on to base class
104 BaseType::disposeThis();
107 // XCanvas: selectively override base's methods here, for opacity tracking
108 virtual void SAL_CALL
clear() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
110 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
112 maSpriteHelper
.clearingContent( this );
114 // and forward to base class, which handles the actual rendering
115 return BaseType::clear();
118 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCachedPrimitive
> SAL_CALL
119 drawBitmap( const ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBitmap
>& xBitmap
,
120 const ::com::sun::star::rendering::ViewState
& viewState
,
121 const ::com::sun::star::rendering::RenderState
& renderState
) throw (::com::sun::star::lang::IllegalArgumentException
,
122 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
124 tools::verifyArgs(xBitmap
, viewState
, renderState
,
125 BOOST_CURRENT_FUNCTION
,
126 static_cast< typename
BaseType::UnambiguousBaseType
* >(this));
128 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
130 maSpriteHelper
.checkDrawBitmap( this, xBitmap
, viewState
, renderState
);
132 // and forward to base class, which handles the actual rendering
133 return BaseType::drawBitmap( xBitmap
,
138 // TODO(F3): If somebody uses the XIntegerBitmap methods to
139 // clear pixel (setting alpha != 1.0 there), or a compositing
140 // mode results in similar alpha, maSpriteHelper might
141 // errorneously report fully opaque sprites. Effectively, all
142 // render methods must be overridden here; or better,
143 // functionality provided at the baseclass.
146 virtual void SAL_CALL
setAlpha( double alpha
) throw (::com::sun::star::lang::IllegalArgumentException
,
147 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
149 tools::verifyRange( alpha
, 0.0, 1.0 );
151 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
153 maSpriteHelper
.setAlpha( this, alpha
);
156 virtual void SAL_CALL
move( const ::com::sun::star::geometry::RealPoint2D
& aNewPos
,
157 const ::com::sun::star::rendering::ViewState
& viewState
,
158 const ::com::sun::star::rendering::RenderState
& renderState
) throw (::com::sun::star::lang::IllegalArgumentException
,
159 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
161 tools::verifyArgs(aNewPos
, viewState
, renderState
,
162 BOOST_CURRENT_FUNCTION
,
163 static_cast< typename
BaseType::UnambiguousBaseType
* >(this));
165 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
167 maSpriteHelper
.move( this, aNewPos
, viewState
, renderState
);
170 virtual void SAL_CALL
transform( const ::com::sun::star::geometry::AffineMatrix2D
& aTransformation
) throw (::com::sun::star::lang::IllegalArgumentException
,
171 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
173 tools::verifyArgs(aTransformation
,
174 BOOST_CURRENT_FUNCTION
,
175 static_cast< typename
BaseType::UnambiguousBaseType
* >(this));
177 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
179 maSpriteHelper
.transform( this, aTransformation
);
182 virtual void SAL_CALL
clip( const ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XPolyPolygon2D
>& aClip
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
184 // NULL xClip explicitly allowed here (to clear clipping)
186 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
188 maSpriteHelper
.clip( this, aClip
);
191 virtual void SAL_CALL
setPriority( double nPriority
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
193 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
195 maSpriteHelper
.setPriority( this, nPriority
);
198 virtual void SAL_CALL
show() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
200 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
202 maSpriteHelper
.show( this );
205 virtual void SAL_CALL
hide() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
207 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
209 maSpriteHelper
.hide( this );
213 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XCanvas
> SAL_CALL
214 getContentCanvas() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
216 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
222 virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange
& rUpdateArea
) const SAL_OVERRIDE
224 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
226 return maSpriteHelper
.isAreaUpdateOpaque( rUpdateArea
);
229 virtual bool isContentChanged() const SAL_OVERRIDE
231 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
233 return BaseType::mbSurfaceDirty
;
236 virtual ::basegfx::B2DPoint
getPosPixel() const SAL_OVERRIDE
238 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
240 return maSpriteHelper
.getPosPixel();
243 virtual ::basegfx::B2DVector
getSizePixel() const SAL_OVERRIDE
245 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
247 return maSpriteHelper
.getSizePixel();
250 virtual ::basegfx::B2DRange
getUpdateArea() const SAL_OVERRIDE
252 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
254 return maSpriteHelper
.getUpdateArea();
257 virtual double getPriority() const SAL_OVERRIDE
259 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
261 return maSpriteHelper
.getPriority();
265 SpriteHelperType maSpriteHelper
;
269 #endif // INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEBASE_HXX
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */