update dev300-m58
[ooovba.git] / slideshow / test / testshape.cxx
blob5d4d5779ef1319e7adb163a670f961ee55714e0e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testshape.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <cppunit/simpleheader.hxx>
32 #include <cppuhelper/compbase1.hxx>
33 #include <cppuhelper/basemutex.hxx>
34 #include <comphelper/make_shared_from_uno.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/range/b2drange.hxx>
39 #include "shape.hxx"
40 #include "tests.hxx"
41 #include "com/sun/star/presentation/XSlideShowView.hpp"
43 #include <boost/bind.hpp>
45 namespace target = slideshow::internal;
46 using namespace ::com::sun::star;
48 // our test shape subject
49 typedef ::cppu::WeakComponentImplHelper1< drawing::XShape > ShapeBase;
50 class ImplTestShape : public TestShape,
51 private cppu::BaseMutex,
52 public ShapeBase
54 typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
55 ViewVector maViewLayers;
56 const basegfx::B2DRange maRect;
57 const double mnPrio;
58 sal_Int32 mnAnimated;
59 mutable sal_Int32 mnNumUpdates;
60 mutable sal_Int32 mnNumRenders;
62 public:
63 ImplTestShape( const basegfx::B2DRange& rRect,
64 double nPrio ) :
65 ShapeBase( m_aMutex ),
66 maViewLayers(),
67 maRect( rRect ),
68 mnPrio( nPrio ),
69 mnAnimated(0),
70 mnNumUpdates(0),
71 mnNumRenders(0)
75 private:
76 // TestShape
77 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const
79 return maViewLayers;
81 virtual sal_Int32 getNumUpdates() const
83 return mnNumUpdates;
85 virtual sal_Int32 getNumRenders() const
87 return mnNumRenders;
89 virtual sal_Int32 getAnimationCount() const
91 return mnAnimated;
95 // XShape
96 virtual ::rtl::OUString SAL_CALL getShapeType( ) throw (uno::RuntimeException)
98 CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
99 return ::rtl::OUString();
102 virtual awt::Point SAL_CALL getPosition( ) throw (uno::RuntimeException)
104 CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
105 return awt::Point();
108 virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException)
110 CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
113 virtual awt::Size SAL_CALL getSize( ) throw (uno::RuntimeException)
115 CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
116 return awt::Size();
119 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException)
121 CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
125 //////////////////////////////////////////////////////////////////////////
128 // Shape
129 virtual uno::Reference< drawing::XShape > getXShape() const
131 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
133 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
134 bool bRedrawLayer )
136 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
138 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
140 if( std::find_if(
141 maViewLayers.begin(),
142 maViewLayers.end(),
143 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
144 boost::cref( rNewLayer ),
145 boost::bind( std::select1st<ViewVector::value_type>(),
146 _1 ))) == maViewLayers.end() )
147 throw std::exception();
149 maViewLayers.erase(
150 std::remove_if(
151 maViewLayers.begin(),
152 maViewLayers.end(),
153 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
154 boost::cref( rNewLayer ),
155 boost::bind( std::select1st<ViewVector::value_type>(),
156 _1 ))));
157 return true;
159 virtual bool clearAllViewLayers()
161 maViewLayers.clear();
162 return true;
165 virtual bool update() const
167 ++mnNumUpdates;
168 return true;
170 virtual bool render() const
172 ++mnNumRenders;
173 return true;
175 virtual bool isContentChanged() const
177 return true;
179 virtual ::basegfx::B2DRectangle getBounds() const
181 return maRect;
183 virtual ::basegfx::B2DRectangle getDomBounds() const
185 return maRect;
187 virtual ::basegfx::B2DRectangle getUpdateArea() const
189 return maRect;
192 virtual bool isVisible() const
194 return true;
196 virtual double getPriority() const
198 return mnPrio;
200 virtual bool isBackgroundDetached() const
202 return mnAnimated != 0;
205 // AnimatableShape
206 virtual void enterAnimationMode()
208 ++mnAnimated;
211 virtual void leaveAnimationMode()
213 --mnAnimated;
218 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
219 double nPrio)
221 return TestShapeSharedPtr(
222 comphelper::make_shared_from_UNO(
223 new ImplTestShape(rRect,nPrio)) );