Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef INCLUDED_CANVAS_CANVASCUSTOMSPRITEBASE_HXX
30 : : #define INCLUDED_CANVAS_CANVASCUSTOMSPRITEBASE_HXX
31 : :
32 : : #include <com/sun/star/lang/XServiceInfo.hpp>
33 : : #include <com/sun/star/rendering/XCustomSprite.hpp>
34 : : #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
35 : : #include <basegfx/point/b2dpoint.hxx>
36 : : #include <basegfx/vector/b2dvector.hxx>
37 : : #include <basegfx/range/b2drange.hxx>
38 : : #include <canvas/base/integerbitmapbase.hxx>
39 : : #include <canvas/base/sprite.hxx>
40 : :
41 : : #include <boost/utility.hpp>
42 : :
43 : :
44 : : namespace canvas
45 : : {
46 : : /** Helper template to handle XCustomSprite method forwarding to
47 : : CanvasCustomSpriteHelper
48 : :
49 : : Use this helper to handle the XCustomSprite part of your
50 : : implementation.
51 : :
52 : : @tpl Base
53 : : Base class to use, most probably one of the
54 : : WeakComponentImplHelperN templates with the appropriate
55 : : interfaces. At least XCustomSprite and Sprite should be among
56 : : them (why else would you use this template, then?). Base class
57 : : must have an Base( const Mutex& ) constructor (like the
58 : : WeakComponentImplHelperN templates have).
59 : :
60 : : @tpl SpriteHelper
61 : : Sprite helper implementation for the backend in question
62 : :
63 : : @tpl CanvasHelper
64 : : Canvas helper implementation for the backend in question
65 : :
66 : : @tpl Mutex
67 : : Lock strategy to use. Defaults to using the
68 : : OBaseMutex-provided lock. Everytime one of the methods is
69 : : entered, an object of type Mutex is created with m_aMutex as
70 : : the sole parameter, and destroyed again when the method scope
71 : : is left.
72 : :
73 : : @tpl UnambiguousBase
74 : : Optional unambiguous base class for XInterface of Base. It's
75 : : sometimes necessary to specify this parameter, e.g. if Base
76 : : derives from multiple UNO interface (were each provides its
77 : : own version of XInterface, making the conversion ambiguous)
78 : :
79 : : @see CanvasCustomSpriteHelper for further contractual
80 : : requirements towards the SpriteHelper type, and some examples.
81 : : */
82 : : template< class Base,
83 : : class SpriteHelper,
84 : : class CanvasHelper,
85 : : class Mutex=::osl::MutexGuard,
86 : 0 : class UnambiguousBase=::com::sun::star::uno::XInterface > class CanvasCustomSpriteBase :
87 : : public IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase >
88 : : {
89 : : public:
90 : : typedef IntegerBitmapBase< Base, CanvasHelper, Mutex, UnambiguousBase > BaseType;
91 : : typedef SpriteHelper SpriteHelperType;
92 : :
93 : 0 : CanvasCustomSpriteBase() :
94 : 0 : maSpriteHelper()
95 : : {
96 : 0 : }
97 : :
98 : : /** Object is being disposed.
99 : :
100 : : Called from the cppu helper base, to notify disposal of
101 : : this object. Already releases all internal references.
102 : :
103 : : @derive when overriding this method in derived classes,
104 : : <em>always</em> call the base class' method!
105 : : */
106 : 0 : virtual void disposeThis()
107 : : {
108 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
109 : :
110 : 0 : maSpriteHelper.disposing();
111 : :
112 : : // pass on to base class
113 : 0 : BaseType::disposeThis();
114 : 0 : }
115 : :
116 : : // XCanvas: selectively override base's methods here, for opacity tracking
117 : 0 : virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException)
118 : : {
119 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
120 : :
121 : 0 : maSpriteHelper.clearingContent( this );
122 : :
123 : : // and forward to base class, which handles the actual rendering
124 : 0 : return BaseType::clear();
125 : : }
126 : :
127 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL
128 : 0 : drawBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >& xBitmap,
129 : : const ::com::sun::star::rendering::ViewState& viewState,
130 : : const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
131 : : ::com::sun::star::uno::RuntimeException)
132 : : {
133 : 0 : tools::verifyArgs(xBitmap, viewState, renderState,
134 : : BOOST_CURRENT_FUNCTION,
135 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
136 : :
137 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
138 : :
139 : 0 : maSpriteHelper.checkDrawBitmap( this, xBitmap, viewState, renderState );
140 : :
141 : : // and forward to base class, which handles the actual rendering
142 : : return BaseType::drawBitmap( xBitmap,
143 : : viewState,
144 : 0 : renderState );
145 : : }
146 : :
147 : : // TODO(F3): If somebody uses the XIntegerBitmap methods to
148 : : // clear pixel (setting alpha != 1.0 there), or a compositing
149 : : // mode results in similar alpha, maSpriteHelper might
150 : : // errorneously report fully opaque sprites. Effectively, all
151 : : // render methods must be overridden here; or better,
152 : : // functionality provided at the baseclass.
153 : :
154 : : // XSprite
155 : 0 : virtual void SAL_CALL setAlpha( double alpha ) throw (::com::sun::star::lang::IllegalArgumentException,
156 : : ::com::sun::star::uno::RuntimeException)
157 : : {
158 : 0 : tools::verifyRange( alpha, 0.0, 1.0 );
159 : :
160 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
161 : :
162 : 0 : maSpriteHelper.setAlpha( this, alpha );
163 : 0 : }
164 : :
165 : 0 : virtual void SAL_CALL move( const ::com::sun::star::geometry::RealPoint2D& aNewPos,
166 : : const ::com::sun::star::rendering::ViewState& viewState,
167 : : const ::com::sun::star::rendering::RenderState& renderState ) throw (::com::sun::star::lang::IllegalArgumentException,
168 : : ::com::sun::star::uno::RuntimeException)
169 : : {
170 : 0 : tools::verifyArgs(aNewPos, viewState, renderState,
171 : : BOOST_CURRENT_FUNCTION,
172 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
173 : :
174 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
175 : :
176 : 0 : maSpriteHelper.move( this, aNewPos, viewState, renderState );
177 : 0 : }
178 : :
179 : 0 : virtual void SAL_CALL transform( const ::com::sun::star::geometry::AffineMatrix2D& aTransformation ) throw (::com::sun::star::lang::IllegalArgumentException,
180 : : ::com::sun::star::uno::RuntimeException)
181 : : {
182 : 0 : tools::verifyArgs(aTransformation,
183 : : BOOST_CURRENT_FUNCTION,
184 : : static_cast< typename BaseType::UnambiguousBaseType* >(this));
185 : :
186 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
187 : :
188 : 0 : maSpriteHelper.transform( this, aTransformation );
189 : 0 : }
190 : :
191 : 0 : virtual void SAL_CALL clip( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& aClip ) throw (::com::sun::star::uno::RuntimeException)
192 : : {
193 : : // NULL xClip explicitly allowed here (to clear clipping)
194 : :
195 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
196 : :
197 : 0 : maSpriteHelper.clip( this, aClip );
198 : 0 : }
199 : :
200 : 0 : virtual void SAL_CALL setPriority( double nPriority ) throw (::com::sun::star::uno::RuntimeException)
201 : : {
202 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
203 : :
204 : 0 : maSpriteHelper.setPriority( this, nPriority );
205 : 0 : }
206 : :
207 : 0 : virtual void SAL_CALL show() throw (::com::sun::star::uno::RuntimeException)
208 : : {
209 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
210 : :
211 : 0 : maSpriteHelper.show( this );
212 : 0 : }
213 : :
214 : 0 : virtual void SAL_CALL hide() throw (::com::sun::star::uno::RuntimeException)
215 : : {
216 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
217 : :
218 : 0 : maSpriteHelper.hide( this );
219 : 0 : }
220 : :
221 : : // XCustomSprite
222 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCanvas > SAL_CALL
223 : 0 : getContentCanvas() throw (::com::sun::star::uno::RuntimeException)
224 : : {
225 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
226 : :
227 : 0 : return this;
228 : : }
229 : :
230 : : // Sprite
231 : 0 : virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const
232 : : {
233 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
234 : :
235 : 0 : return maSpriteHelper.isAreaUpdateOpaque( rUpdateArea );
236 : : }
237 : :
238 : 0 : virtual bool isContentChanged() const
239 : : {
240 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
241 : :
242 : 0 : return BaseType::mbSurfaceDirty;
243 : : }
244 : :
245 : 0 : virtual ::basegfx::B2DPoint getPosPixel() const
246 : : {
247 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
248 : :
249 : 0 : return maSpriteHelper.getPosPixel();
250 : : }
251 : :
252 : 0 : virtual ::basegfx::B2DVector getSizePixel() const
253 : : {
254 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
255 : :
256 : 0 : return maSpriteHelper.getSizePixel();
257 : : }
258 : :
259 : 0 : virtual ::basegfx::B2DRange getUpdateArea() const
260 : : {
261 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
262 : :
263 : 0 : return maSpriteHelper.getUpdateArea();
264 : : }
265 : :
266 : 0 : virtual double getPriority() const
267 : : {
268 : 0 : typename BaseType::MutexType aGuard( BaseType::m_aMutex );
269 : :
270 : 0 : return maSpriteHelper.getPriority();
271 : : }
272 : :
273 : : protected:
274 : : SpriteHelperType maSpriteHelper;
275 : : };
276 : : }
277 : :
278 : : #endif /* INCLUDED_CANVAS_CANVASCUSTOMSPRITEBASE_HXX */
279 : :
280 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|