1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CPPCANVAS_CACHEDPRIMITIVEBASE_HXX
29 #define _CPPCANVAS_CACHEDPRIMITIVEBASE_HXX
30 
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/rendering/XCanvas.hpp>
33 
34 #include <cppcanvas/canvas.hxx>
35 #include <boost/utility.hpp>
36 
37 #include "action.hxx"
38 
39 namespace basegfx { class B2DHomMatrix; }
40 
41 
42 /* Definition of internal::CachedPrimitiveBase class */
43 
44 namespace cppcanvas
45 {
46     namespace internal
47     {
48         /** Base class providing cached re-rendering, if XCanvas
49             returns XCachedPrimitive
50 
51             Derive from this class and implement private render()
52             method to perform the actual primitive rendering. Return
53             cached primitive into given reference. Next time this
54             class' public render() method gets called, the cached
55             representation is taken.
56          */
57         class CachedPrimitiveBase : public Action,
58                                     private ::boost::noncopyable
59         {
60         public:
61             /** Constructor
62 
63                 @param rCanvas
64                 Canvas on which this primitive is to appear
65 
66                 @param bOnlyRedrawWithSameTransform
67                 When true, this class only reuses the cached
68                 primitive, if the overall transformation stays the
69                 same. Otherwise, repaints are always performed via the
70                 cached primitive.
71              */
72             CachedPrimitiveBase( const CanvasSharedPtr& rCanvas,
73                                  bool                   bOnlyRedrawWithSameTransform );
74             virtual ~CachedPrimitiveBase() {}
75 
76             virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const;
77 
78         protected:
79             using Action::render;
80 
81         private:
82             virtual bool render( ::com::sun::star::uno::Reference<
83                                      ::com::sun::star::rendering::XCachedPrimitive >& rCachedPrimitive,
84                                  const ::basegfx::B2DHomMatrix&                       rTransformation ) const = 0;
85 
86             CanvasSharedPtr                                             mpCanvas;
87             mutable ::com::sun::star::uno::Reference<
88                     ::com::sun::star::rendering::XCachedPrimitive > 	mxCachedPrimitive;
89             mutable ::basegfx::B2DHomMatrix                             maLastTransformation;
90             const bool                                                  mbOnlyRedrawWithSameTransform;
91         };
92     }
93 }
94 
95 #endif /*_CPPCANVAS_CACHEDPRIMITIVEBASE_HXX */
96