xref: /trunk/main/canvas/inc/canvas/base/bitmapcanvasbase.hxx (revision 537d918930a77db9c28916ebc25c79ea73c289a1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef INCLUDED_CANVAS_BITMAPCANVASBASE_HXX
23 #define INCLUDED_CANVAS_BITMAPCANVASBASE_HXX
24 
25 #include <canvas/base/canvasbase.hxx>
26 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
27 
28 namespace canvas
29 {
30     /** Helper template to handle XBitmapCanvas method forwarding to
31         BitmapCanvasHelper
32 
33         Use this helper to handle the XBitmapCanvas part of your
34         implementation.
35 
36         @tpl Base
37         Base class to use, most probably one of the
38         WeakComponentImplHelperN templates with the appropriate
39         interfaces. At least XBitmapCanvas should be among them (why
40         else would you use this template, then?). Base class must have
41         an Base( const Mutex& ) constructor (like the
42         WeakComponentImplHelperN templates have).
43 
44         @tpl CanvasHelper
45         Canvas helper implementation for the backend in question
46 
47         @tpl Mutex
48         Lock strategy to use. Defaults to using the
49         OBaseMutex-provided lock.  Every time one of the methods is
50         entered, an object of type Mutex is created with m_aMutex as
51         the sole parameter, and destroyed again when the method scope
52         is left.
53 
54         @tpl UnambiguousBase
55         Optional unambiguous base class for XInterface of Base. It's
56         sometimes necessary to specify this parameter, e.g. if Base
57         derives from multiple UNO interface (were each provides its
58         own version of XInterface, making the conversion ambiguous)
59 
60         @see CanvasBase for further contractual requirements towards
61         the CanvasHelper type, and some examples.
62      */
63     template< class Base,
64               class CanvasHelper,
65               class Mutex=::osl::MutexGuard,
66               class UnambiguousBase=::com::sun::star::uno::XInterface > class BitmapCanvasBase :
67         public CanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase >
68     {
69     public:
70         typedef CanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase >    BaseType;
71 
72         // XBitmapCanvas
copyRect(const::com::sun::star::uno::Reference<::com::sun::star::rendering::XBitmapCanvas> & sourceCanvas,const::com::sun::star::geometry::RealRectangle2D & sourceRect,const::com::sun::star::rendering::ViewState & sourceViewState,const::com::sun::star::rendering::RenderState & sourceRenderState,const::com::sun::star::geometry::RealRectangle2D & destRect,const::com::sun::star::rendering::ViewState & destViewState,const::com::sun::star::rendering::RenderState & destRenderState)73         virtual void SAL_CALL copyRect( const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmapCanvas >&   sourceCanvas,
74                                         const ::com::sun::star::geometry::RealRectangle2D&                                      sourceRect,
75                                         const ::com::sun::star::rendering::ViewState&                                           sourceViewState,
76                                         const ::com::sun::star::rendering::RenderState&                                         sourceRenderState,
77                                         const ::com::sun::star::geometry::RealRectangle2D&                                      destRect,
78                                         const ::com::sun::star::rendering::ViewState&                                           destViewState,
79                                         const ::com::sun::star::rendering::RenderState&                                         destRenderState ) throw (::com::sun::star::lang::IllegalArgumentException,
80                                                                                                                                                          ::com::sun::star::uno::RuntimeException)
81         {
82             tools::verifyArgs(sourceCanvas, sourceRect, sourceViewState, sourceRenderState,
83                               destRect, destViewState, destRenderState,
84                               BOOST_CURRENT_FUNCTION,
85                               static_cast< typename BaseType::UnambiguousBaseType* >(this));
86 
87             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
88 
89             BaseType::mbSurfaceDirty = true;
90             BaseType::maCanvasHelper.modifying();
91 
92             BaseType::maCanvasHelper.copyRect( this,
93                                                sourceCanvas,
94                                                sourceRect,
95                                                sourceViewState,
96                                                sourceRenderState,
97                                                destRect,
98                                                destViewState,
99                                                destRenderState );
100         }
101 
102         // XBitmap
getSize()103         virtual ::com::sun::star::geometry::IntegerSize2D SAL_CALL getSize(  ) throw (::com::sun::star::uno::RuntimeException)
104         {
105             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
106 
107             return BaseType::maCanvasHelper.getSize();
108         }
109 
hasAlpha()110         virtual ::sal_Bool SAL_CALL hasAlpha(  ) throw (::com::sun::star::uno::RuntimeException)
111         {
112             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
113 
114             return BaseType::maCanvasHelper.hasAlpha();
115         }
116 
getScaledBitmap(const::com::sun::star::geometry::RealSize2D & newSize,sal_Bool beFast)117         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap > SAL_CALL getScaledBitmap( const ::com::sun::star::geometry::RealSize2D& newSize,
118                                                                                                                    sal_Bool                                      beFast ) throw (::com::sun::star::uno::RuntimeException)
119         {
120             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
121 
122             return BaseType::maCanvasHelper.getScaledBitmap( newSize, beFast );
123         }
124 
125     };
126 }
127 
128 #endif /* INCLUDED_CANVAS_BITMAPCANVASBASE_HXX */
129 
130 /* vim: set noet sw=4 ts=4: */
131