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