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 
23 
24 #ifndef _CPPCANVAS_CACHEDPRIMITIVEBASE_HXX
25 #define _CPPCANVAS_CACHEDPRIMITIVEBASE_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/rendering/XCanvas.hpp>
29 
30 #include <cppcanvas/canvas.hxx>
31 #include <boost/utility.hpp>
32 
33 #include "action.hxx"
34 
35 namespace basegfx { class B2DHomMatrix; }
36 
37 
38 /* Definition of internal::CachedPrimitiveBase class */
39 
40 namespace cppcanvas
41 {
42     namespace internal
43     {
44         /** Base class providing cached re-rendering, if XCanvas
45             returns XCachedPrimitive
46 
47             Derive from this class and implement private render()
48             method to perform the actual primitive rendering. Return
49             cached primitive into given reference. Next time this
50             class' public render() method gets called, the cached
51             representation is taken.
52          */
53         class CachedPrimitiveBase : public Action,
54                                     private ::boost::noncopyable
55         {
56         public:
57             /** Constructor
58 
59                 @param rCanvas
60                 Canvas on which this primitive is to appear
61 
62                 @param bOnlyRedrawWithSameTransform
63                 When true, this class only reuses the cached
64                 primitive, if the overall transformation stays the
65                 same. Otherwise, repaints are always performed via the
66                 cached primitive.
67              */
68             CachedPrimitiveBase( const CanvasSharedPtr& rCanvas,
69                                  bool                   bOnlyRedrawWithSameTransform );
~CachedPrimitiveBase()70             virtual ~CachedPrimitiveBase() {}
71 
72             virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const;
73 
74         protected:
75             using Action::render;
76 
77         private:
78             virtual bool render( ::com::sun::star::uno::Reference<
79                                      ::com::sun::star::rendering::XCachedPrimitive >& rCachedPrimitive,
80                                  const ::basegfx::B2DHomMatrix&                       rTransformation ) const = 0;
81 
82             CanvasSharedPtr                                             mpCanvas;
83             mutable ::com::sun::star::uno::Reference<
84                     ::com::sun::star::rendering::XCachedPrimitive > 	mxCachedPrimitive;
85             mutable ::basegfx::B2DHomMatrix                             maLastTransformation;
86             const bool                                                  mbOnlyRedrawWithSameTransform;
87         };
88     }
89 }
90 
91 #endif /*_CPPCANVAS_CACHEDPRIMITIVEBASE_HXX */
92