xref: /AOO41X/main/slideshow/test/testshape.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
29*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
30*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
31*cdf0e10cSrcweir #include <comphelper/make_shared_from_uno.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
34*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "shape.hxx"
37*cdf0e10cSrcweir #include "tests.hxx"
38*cdf0e10cSrcweir #include "com/sun/star/presentation/XSlideShowView.hpp"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <boost/bind.hpp>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace target = slideshow::internal;
43*cdf0e10cSrcweir using namespace ::com::sun::star;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir // our test shape subject
46*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1< drawing::XShape > ShapeBase;
47*cdf0e10cSrcweir class ImplTestShape : public TestShape,
48*cdf0e10cSrcweir                       private cppu::BaseMutex,
49*cdf0e10cSrcweir                       public ShapeBase
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir     typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
52*cdf0e10cSrcweir     ViewVector               maViewLayers;
53*cdf0e10cSrcweir     const basegfx::B2DRange  maRect;
54*cdf0e10cSrcweir     const double             mnPrio;
55*cdf0e10cSrcweir     sal_Int32                mnAnimated;
56*cdf0e10cSrcweir     mutable sal_Int32        mnNumUpdates;
57*cdf0e10cSrcweir     mutable sal_Int32        mnNumRenders;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir public:
60*cdf0e10cSrcweir     ImplTestShape( const basegfx::B2DRange& rRect,
61*cdf0e10cSrcweir                    double                   nPrio ) :
62*cdf0e10cSrcweir         ShapeBase( m_aMutex ),
63*cdf0e10cSrcweir         maViewLayers(),
64*cdf0e10cSrcweir         maRect( rRect ),
65*cdf0e10cSrcweir         mnPrio( nPrio ),
66*cdf0e10cSrcweir         mnAnimated(0),
67*cdf0e10cSrcweir         mnNumUpdates(0),
68*cdf0e10cSrcweir         mnNumRenders(0)
69*cdf0e10cSrcweir     {}
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir private:
73*cdf0e10cSrcweir     // TestShape
74*cdf0e10cSrcweir     virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         return maViewLayers;
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir     virtual sal_Int32 getNumUpdates() const
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         return mnNumUpdates;
81*cdf0e10cSrcweir     }
82*cdf0e10cSrcweir     virtual sal_Int32 getNumRenders() const
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         return mnNumRenders;
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir     virtual sal_Int32 getAnimationCount() const
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         return mnAnimated;
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     // XShape
93*cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getShapeType(  ) throw (uno::RuntimeException)
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
96*cdf0e10cSrcweir         return ::rtl::OUString();
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     virtual awt::Point SAL_CALL getPosition(  ) throw (uno::RuntimeException)
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
102*cdf0e10cSrcweir         return awt::Point();
103*cdf0e10cSrcweir     }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException)
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
108*cdf0e10cSrcweir     }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     virtual awt::Size SAL_CALL getSize(  ) throw (uno::RuntimeException)
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
113*cdf0e10cSrcweir         return awt::Size();
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException)
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////////
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     // Shape
126*cdf0e10cSrcweir     virtual uno::Reference< drawing::XShape > getXShape() const
127*cdf0e10cSrcweir     {
128*cdf0e10cSrcweir         return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir     virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
131*cdf0e10cSrcweir                                bool                              bRedrawLayer )
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir     virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         if( std::find_if(
138*cdf0e10cSrcweir                 maViewLayers.begin(),
139*cdf0e10cSrcweir                 maViewLayers.end(),
140*cdf0e10cSrcweir                 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
141*cdf0e10cSrcweir                              boost::cref( rNewLayer ),
142*cdf0e10cSrcweir                              boost::bind( std::select1st<ViewVector::value_type>(),
143*cdf0e10cSrcweir                                           _1 ))) == maViewLayers.end() )
144*cdf0e10cSrcweir             throw std::exception();
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         maViewLayers.erase(
147*cdf0e10cSrcweir             std::remove_if(
148*cdf0e10cSrcweir                 maViewLayers.begin(),
149*cdf0e10cSrcweir                 maViewLayers.end(),
150*cdf0e10cSrcweir                 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
151*cdf0e10cSrcweir                              boost::cref( rNewLayer ),
152*cdf0e10cSrcweir                              boost::bind( std::select1st<ViewVector::value_type>(),
153*cdf0e10cSrcweir                                           _1 ))));
154*cdf0e10cSrcweir         return true;
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir     virtual bool clearAllViewLayers()
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         maViewLayers.clear();
159*cdf0e10cSrcweir         return true;
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     virtual bool update() const
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         ++mnNumUpdates;
165*cdf0e10cSrcweir         return true;
166*cdf0e10cSrcweir     }
167*cdf0e10cSrcweir     virtual bool render() const
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         ++mnNumRenders;
170*cdf0e10cSrcweir         return true;
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir     virtual bool isContentChanged() const
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         return true;
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir     virtual ::basegfx::B2DRectangle getBounds() const
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         return maRect;
179*cdf0e10cSrcweir     }
180*cdf0e10cSrcweir     virtual ::basegfx::B2DRectangle getDomBounds() const
181*cdf0e10cSrcweir     {
182*cdf0e10cSrcweir         return maRect;
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir     virtual ::basegfx::B2DRectangle getUpdateArea() const
185*cdf0e10cSrcweir     {
186*cdf0e10cSrcweir         return maRect;
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     virtual bool isVisible() const
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir         return true;
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir     virtual double getPriority() const
194*cdf0e10cSrcweir     {
195*cdf0e10cSrcweir         return mnPrio;
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir     virtual bool isBackgroundDetached() const
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         return mnAnimated != 0;
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     // AnimatableShape
203*cdf0e10cSrcweir     virtual void enterAnimationMode()
204*cdf0e10cSrcweir     {
205*cdf0e10cSrcweir         ++mnAnimated;
206*cdf0e10cSrcweir     }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     virtual void leaveAnimationMode()
209*cdf0e10cSrcweir     {
210*cdf0e10cSrcweir         --mnAnimated;
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir };
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
216*cdf0e10cSrcweir                                    double                   nPrio)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     return TestShapeSharedPtr(
219*cdf0e10cSrcweir         comphelper::make_shared_from_UNO(
220*cdf0e10cSrcweir             new ImplTestShape(rRect,nPrio)) );
221*cdf0e10cSrcweir }
222