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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppcanvas.hxx"
30 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <basegfx/tools/canvastools.hxx>
32 #include <basegfx/polygon/b2dpolypolygon.hxx>
33 #include <com/sun/star/rendering/InterpolationMode.hpp>
34 
35 #include <implspritecanvas.hxx>
36 #include <implcustomsprite.hxx>
37 
38 
39 using namespace ::com::sun::star;
40 
41 namespace cppcanvas
42 {
43     namespace internal
44     {
45         ImplSpriteCanvas::TransformationArbiter::TransformationArbiter() :
46             maTransformation()
47         {
48         }
49 
50         void ImplSpriteCanvas::TransformationArbiter::setTransformation( const ::basegfx::B2DHomMatrix& rViewTransform )
51         {
52             maTransformation = rViewTransform;
53         }
54 
55         ::basegfx::B2DHomMatrix ImplSpriteCanvas::TransformationArbiter::getTransformation() const
56         {
57             return maTransformation;
58         }
59 
60 
61         ImplSpriteCanvas::ImplSpriteCanvas( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) :
62             ImplCanvas( uno::Reference< rendering::XCanvas >(rCanvas,
63                                                              uno::UNO_QUERY) ),
64             ImplBitmapCanvas( uno::Reference< rendering::XBitmapCanvas >(rCanvas,
65                                                                          uno::UNO_QUERY) ),
66             mxSpriteCanvas( rCanvas ),
67             mpTransformArbiter( new TransformationArbiter() )
68         {
69             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas(): Invalid canvas" );
70         }
71 
72         ImplSpriteCanvas::ImplSpriteCanvas(const ImplSpriteCanvas& rOrig) :
73             Canvas(),
74             BitmapCanvas(),
75             SpriteCanvas(),
76             ImplCanvas( rOrig ),
77             ImplBitmapCanvas( rOrig ),
78             mxSpriteCanvas( rOrig.getUNOSpriteCanvas() ),
79             mpTransformArbiter( new TransformationArbiter() )
80         {
81             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::ImplSpriteCanvas( const ImplSpriteCanvas& ): Invalid canvas" );
82 
83             mpTransformArbiter->setTransformation( getTransformation() );
84         }
85 
86         ImplSpriteCanvas::~ImplSpriteCanvas()
87         {
88         }
89 
90         void ImplSpriteCanvas::setTransformation( const ::basegfx::B2DHomMatrix& rMatrix )
91         {
92             mpTransformArbiter->setTransformation( rMatrix );
93 
94             ImplCanvas::setTransformation( rMatrix );
95         }
96 
97         bool ImplSpriteCanvas::updateScreen( bool bUpdateAll ) const
98         {
99             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::updateScreen(): Invalid canvas" );
100 
101             if( !mxSpriteCanvas.is() )
102                 return false;
103 
104             return mxSpriteCanvas->updateScreen( bUpdateAll );
105         }
106 
107         CustomSpriteSharedPtr ImplSpriteCanvas::createCustomSprite( const ::basegfx::B2DSize& rSize ) const
108         {
109             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" );
110 
111             if( !mxSpriteCanvas.is() )
112                 return CustomSpriteSharedPtr();
113 
114             return CustomSpriteSharedPtr(
115                 new ImplCustomSprite( mxSpriteCanvas,
116                                       mxSpriteCanvas->createCustomSprite( ::basegfx::unotools::size2DFromB2DSize(rSize) ),
117                                       mpTransformArbiter ) );
118         }
119 
120         SpriteSharedPtr ImplSpriteCanvas::createClonedSprite( const SpriteSharedPtr& rSprite ) const
121         {
122             OSL_ENSURE( mxSpriteCanvas.is(), "ImplSpriteCanvas::createCustomSprite(): Invalid canvas" );
123             OSL_ENSURE( rSprite.get() != NULL && rSprite->getUNOSprite().is(),
124                         "ImplSpriteCanvas::createCustomSprite(): Invalid sprite" );
125 
126             if( !mxSpriteCanvas.is() ||
127                 rSprite.get() == NULL ||
128                 !rSprite->getUNOSprite().is() )
129             {
130                 return SpriteSharedPtr();
131             }
132 
133             return SpriteSharedPtr(
134                 new ImplSprite( mxSpriteCanvas,
135                                 mxSpriteCanvas->createClonedSprite( rSprite->getUNOSprite() ),
136                                 mpTransformArbiter ) );
137         }
138 
139         SpriteSharedPtr ImplSpriteCanvas::createSpriteFromBitmaps( const uno::Sequence< uno::Reference< rendering::XBitmap > >& rAnimationBitmaps,
140                                                                    sal_Int8 													nInterpolationMode )
141         {
142             return SpriteSharedPtr( new internal::ImplSprite( mxSpriteCanvas,
143                                                               mxSpriteCanvas->createSpriteFromBitmaps( rAnimationBitmaps,
144                                                                                                        nInterpolationMode ),
145                                                               mpTransformArbiter ) );
146         }
147 
148         CanvasSharedPtr ImplSpriteCanvas::clone() const
149         {
150             return SpriteCanvasSharedPtr( new ImplSpriteCanvas( *this ) );
151         }
152 
153         uno::Reference< rendering::XSpriteCanvas > ImplSpriteCanvas::getUNOSpriteCanvas() const
154         {
155             return mxSpriteCanvas;
156         }
157 
158     }
159 }
160