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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppcanvas.hxx"
26 
27 #include <basegfx/polygon/b2dpolypolygon.hxx>
28 
29 #include "implcustomsprite.hxx"
30 #include "implcanvas.hxx"
31 
32 using namespace ::com::sun::star;
33 
34 namespace cppcanvas
35 {
36     namespace internal
37     {
ImplCustomSprite(const uno::Reference<rendering::XSpriteCanvas> & rParentCanvas,const uno::Reference<rendering::XCustomSprite> & rSprite,const ImplSpriteCanvas::TransformationArbiterSharedPtr & rTransformArbiter)38         ImplCustomSprite::ImplCustomSprite( const uno::Reference< rendering::XSpriteCanvas >& 		rParentCanvas,
39                                             const uno::Reference< rendering::XCustomSprite >& 		rSprite,
40                                             const ImplSpriteCanvas::TransformationArbiterSharedPtr&	rTransformArbiter ) :
41             ImplSprite( rParentCanvas,
42                         uno::Reference< rendering::XSprite >(rSprite,
43                                                              uno::UNO_QUERY),
44                         rTransformArbiter ),
45             mpLastCanvas(),
46             mxCustomSprite( rSprite )
47         {
48             OSL_ENSURE( rParentCanvas.is(), "ImplCustomSprite::ImplCustomSprite(): Invalid canvas" );
49             OSL_ENSURE( mxCustomSprite.is(), "ImplCustomSprite::ImplCustomSprite(): Invalid sprite" );
50         }
51 
~ImplCustomSprite()52         ImplCustomSprite::~ImplCustomSprite()
53         {
54         }
55 
getContentCanvas() const56         CanvasSharedPtr ImplCustomSprite::getContentCanvas() const
57         {
58             OSL_ENSURE( mxCustomSprite.is(), "ImplCustomSprite::getContentCanvas(): Invalid sprite" );
59 
60             if( !mxCustomSprite.is() )
61                 return CanvasSharedPtr();
62 
63             uno::Reference< rendering::XCanvas > xCanvas( mxCustomSprite->getContentCanvas() );
64 
65             if( !xCanvas.is() )
66                 return CanvasSharedPtr();
67 
68             // cache content canvas C++ wrapper
69             if( mpLastCanvas.get() == NULL ||
70                 mpLastCanvas->getUNOCanvas() != xCanvas )
71             {
72                 mpLastCanvas = CanvasSharedPtr( new ImplCanvas( xCanvas ) );
73             }
74 
75             return mpLastCanvas;
76         }
77     }
78 }
79