xref: /aoo4110/main/slideshow/test/testshape.cxx (revision b1cdbd2c)
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 #include <testshl/simpleheader.hxx>
25 #include <cppuhelper/compbase1.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <comphelper/make_shared_from_uno.hxx>
28 
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/range/b2drange.hxx>
31 
32 #include "shape.hxx"
33 #include "tests.hxx"
34 #include "com/sun/star/presentation/XSlideShowView.hpp"
35 
36 #include <boost/bind.hpp>
37 
38 namespace target = slideshow::internal;
39 using namespace ::com::sun::star;
40 
41 // our test shape subject
42 typedef ::cppu::WeakComponentImplHelper1< drawing::XShape > ShapeBase;
43 class ImplTestShape : public TestShape,
44                       private cppu::BaseMutex,
45                       public ShapeBase
46 {
47     typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
48     ViewVector               maViewLayers;
49     const basegfx::B2DRange  maRect;
50     const double             mnPrio;
51     sal_Int32                mnAnimated;
52     mutable sal_Int32        mnNumUpdates;
53     mutable sal_Int32        mnNumRenders;
54 
55 public:
ImplTestShape(const basegfx::B2DRange & rRect,double nPrio)56     ImplTestShape( const basegfx::B2DRange& rRect,
57                    double                   nPrio ) :
58         ShapeBase( m_aMutex ),
59         maViewLayers(),
60         maRect( rRect ),
61         mnPrio( nPrio ),
62         mnAnimated(0),
63         mnNumUpdates(0),
64         mnNumRenders(0)
65     {}
66 
67 
68 private:
69     // TestShape
getViewLayers() const70     virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const
71     {
72         return maViewLayers;
73     }
getNumUpdates() const74     virtual sal_Int32 getNumUpdates() const
75     {
76         return mnNumUpdates;
77     }
getNumRenders() const78     virtual sal_Int32 getNumRenders() const
79     {
80         return mnNumRenders;
81     }
getAnimationCount() const82     virtual sal_Int32 getAnimationCount() const
83     {
84         return mnAnimated;
85     }
86 
87 
88     // XShape
getShapeType()89     virtual ::rtl::OUString SAL_CALL getShapeType(  ) throw (uno::RuntimeException)
90     {
91         CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
92         return ::rtl::OUString();
93     }
94 
getPosition()95     virtual awt::Point SAL_CALL getPosition(  ) throw (uno::RuntimeException)
96     {
97         CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
98         return awt::Point();
99     }
100 
setPosition(const awt::Point &)101     virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException)
102     {
103         CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
104     }
105 
getSize()106     virtual awt::Size SAL_CALL getSize(  ) throw (uno::RuntimeException)
107     {
108         CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
109         return awt::Size();
110     }
111 
setSize(const awt::Size &)112     virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException)
113     {
114         CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
115     }
116 
117 
118     //////////////////////////////////////////////////////////////////////////
119 
120 
121     // Shape
getXShape() const122     virtual uno::Reference< drawing::XShape > getXShape() const
123     {
124         return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
125     }
addViewLayer(const target::ViewLayerSharedPtr & rNewLayer,bool bRedrawLayer)126     virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
127                                bool                              bRedrawLayer )
128     {
129         maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
130     }
removeViewLayer(const target::ViewLayerSharedPtr & rNewLayer)131     virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
132     {
133         if( std::find_if(
134                 maViewLayers.begin(),
135                 maViewLayers.end(),
136                 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
137                              boost::cref( rNewLayer ),
138                              boost::bind( std::select1st<ViewVector::value_type>(),
139                                           _1 ))) == maViewLayers.end() )
140             throw std::exception();
141 
142         maViewLayers.erase(
143             std::remove_if(
144                 maViewLayers.begin(),
145                 maViewLayers.end(),
146                 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
147                              boost::cref( rNewLayer ),
148                              boost::bind( std::select1st<ViewVector::value_type>(),
149                                           _1 ))));
150         return true;
151     }
clearAllViewLayers()152     virtual bool clearAllViewLayers()
153     {
154         maViewLayers.clear();
155         return true;
156     }
157 
update() const158     virtual bool update() const
159     {
160         ++mnNumUpdates;
161         return true;
162     }
render() const163     virtual bool render() const
164     {
165         ++mnNumRenders;
166         return true;
167     }
isContentChanged() const168     virtual bool isContentChanged() const
169     {
170         return true;
171     }
getBounds() const172     virtual ::basegfx::B2DRectangle getBounds() const
173     {
174         return maRect;
175     }
getDomBounds() const176     virtual ::basegfx::B2DRectangle getDomBounds() const
177     {
178         return maRect;
179     }
getUpdateArea() const180     virtual ::basegfx::B2DRectangle getUpdateArea() const
181     {
182         return maRect;
183     }
184 
isVisible() const185     virtual bool isVisible() const
186     {
187         return true;
188     }
getPriority() const189     virtual double getPriority() const
190     {
191         return mnPrio;
192     }
isBackgroundDetached() const193     virtual bool isBackgroundDetached() const
194     {
195         return mnAnimated != 0;
196     }
197 
198     // AnimatableShape
enterAnimationMode()199     virtual void enterAnimationMode()
200     {
201         ++mnAnimated;
202     }
203 
leaveAnimationMode()204     virtual void leaveAnimationMode()
205     {
206         --mnAnimated;
207     }
208 };
209 
210 
createTestShape(const basegfx::B2DRange & rRect,double nPrio)211 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
212                                    double                   nPrio)
213 {
214     return TestShapeSharedPtr(
215         comphelper::make_shared_from_UNO(
216             new ImplTestShape(rRect,nPrio)) );
217 }
218