xref: /trunk/main/slideshow/test/testview.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/b1drange.hxx>
35*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
36*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
37*cdf0e10cSrcweir #include <cppcanvas/spritecanvas.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "tests.hxx"
40*cdf0e10cSrcweir #include "view.hxx"
41*cdf0e10cSrcweir #include "unoview.hxx"
42*cdf0e10cSrcweir #include "com/sun/star/presentation/XSlideShowView.hpp"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <vector>
45*cdf0e10cSrcweir #include <exception>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir namespace target = slideshow::internal;
49*cdf0e10cSrcweir using namespace ::com::sun::star;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir // our test view subject
52*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1< presentation::XSlideShowView > ViewBase;
53*cdf0e10cSrcweir class ImplTestView : public TestView,
54*cdf0e10cSrcweir                      private cppu::BaseMutex,
55*cdf0e10cSrcweir                      public ViewBase
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     mutable std::vector<std::pair<basegfx::B2DVector,double> > maCreatedSprites;
58*cdf0e10cSrcweir     mutable std::vector<TestViewSharedPtr>                     maViewLayers;
59*cdf0e10cSrcweir     basegfx::B2DRange                                  maBounds;
60*cdf0e10cSrcweir     basegfx::B1DRange                                  maPriority;
61*cdf0e10cSrcweir     bool                                               mbIsClipSet;
62*cdf0e10cSrcweir     bool                                               mbIsClipEmptied;
63*cdf0e10cSrcweir     bool                                               mbIsClearCalled;
64*cdf0e10cSrcweir     bool                                               mbDisposed;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir public:
68*cdf0e10cSrcweir     ImplTestView() :
69*cdf0e10cSrcweir         ViewBase(m_aMutex),
70*cdf0e10cSrcweir         maCreatedSprites(),
71*cdf0e10cSrcweir         maViewLayers(),
72*cdf0e10cSrcweir         maBounds(),
73*cdf0e10cSrcweir         maPriority(),
74*cdf0e10cSrcweir         mbIsClipSet(false),
75*cdf0e10cSrcweir         mbIsClipEmptied(false),
76*cdf0e10cSrcweir         mbIsClearCalled(false),
77*cdf0e10cSrcweir         mbDisposed( false )
78*cdf0e10cSrcweir     {
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     virtual ~ImplTestView()
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     // XSlideShowView
86*cdf0e10cSrcweir     virtual uno::Reference< rendering::XSpriteCanvas > SAL_CALL getCanvas(  ) throw (uno::RuntimeException)
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         return uno::Reference< rendering::XSpriteCanvas >();
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     virtual void SAL_CALL clear(  ) throw (uno::RuntimeException)
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir     }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     virtual geometry::AffineMatrix2D SAL_CALL getTransformation(  ) throw (uno::RuntimeException)
96*cdf0e10cSrcweir     {
97*cdf0e10cSrcweir         return geometry::AffineMatrix2D();
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     virtual void SAL_CALL addTransformationChangedListener( const uno::Reference< util::XModifyListener >& ) throw (uno::RuntimeException)
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir     }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     virtual void SAL_CALL removeTransformationChangedListener( const uno::Reference< util::XModifyListener >& ) throw (uno::RuntimeException)
105*cdf0e10cSrcweir     {
106*cdf0e10cSrcweir     }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     virtual void SAL_CALL addPaintListener( const uno::Reference< awt::XPaintListener >& ) throw (uno::RuntimeException)
109*cdf0e10cSrcweir     {
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     virtual void SAL_CALL removePaintListener( const uno::Reference< awt::XPaintListener >& ) throw (uno::RuntimeException)
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     virtual void SAL_CALL addMouseListener( const uno::Reference< awt::XMouseListener >& ) throw (uno::RuntimeException)
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     virtual void SAL_CALL removeMouseListener( const uno::Reference< awt::XMouseListener >& ) throw (uno::RuntimeException)
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir     }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir     virtual void SAL_CALL addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& ) throw (uno::RuntimeException)
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir     }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     virtual void SAL_CALL removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& ) throw (uno::RuntimeException)
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     virtual void SAL_CALL setMouseCursor( ::sal_Int16 ) throw (uno::RuntimeException)
133*cdf0e10cSrcweir     {
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     // TestView
137*cdf0e10cSrcweir     virtual bool isClearCalled() const
138*cdf0e10cSrcweir     {
139*cdf0e10cSrcweir         return mbIsClearCalled;
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     virtual std::vector<std::pair<basegfx::B2DVector,double> > getCreatedSprites() const
143*cdf0e10cSrcweir     {
144*cdf0e10cSrcweir         return maCreatedSprites;
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     virtual basegfx::B1DRange getPriority() const
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir         return maPriority;
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     virtual bool wasClipSet() const
153*cdf0e10cSrcweir     {
154*cdf0e10cSrcweir         return mbIsClipEmptied;
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     virtual basegfx::B2DRange getBounds() const
158*cdf0e10cSrcweir     {
159*cdf0e10cSrcweir         return maBounds;
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     virtual std::vector<boost::shared_ptr<TestView> > getViewLayers() const
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         return maViewLayers;
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     // ViewLayer
168*cdf0e10cSrcweir     virtual bool isOnView(target::ViewSharedPtr const& /*rView*/) const
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         return true;
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     virtual ::cppcanvas::CanvasSharedPtr getCanvas() const
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         return ::cppcanvas::CanvasSharedPtr();
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     virtual ::cppcanvas::CustomSpriteSharedPtr createSprite( const ::basegfx::B2DSize& rSpriteSizePixel,
179*cdf0e10cSrcweir                                                              double                    nPriority ) const
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         maCreatedSprites.push_back( std::make_pair(rSpriteSizePixel,nPriority) );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         return ::cppcanvas::CustomSpriteSharedPtr();
184*cdf0e10cSrcweir     }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     virtual void setPriority( const basegfx::B1DRange& rRange )
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         maPriority = rRange;
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     virtual ::basegfx::B2DHomMatrix getTransformation() const
192*cdf0e10cSrcweir     {
193*cdf0e10cSrcweir         return ::basegfx::B2DHomMatrix();
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     virtual ::basegfx::B2DHomMatrix getSpriteTransformation() const
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         return ::basegfx::B2DHomMatrix();
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     virtual void setClip( const ::basegfx::B2DPolyPolygon& rClip )
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir         if( !mbIsClipSet )
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             if( rClip.count() > 0 )
206*cdf0e10cSrcweir                 mbIsClipSet = true;
207*cdf0e10cSrcweir         }
208*cdf0e10cSrcweir         else if( !mbIsClipEmptied )
209*cdf0e10cSrcweir         {
210*cdf0e10cSrcweir             if( rClip.count() == 0 )
211*cdf0e10cSrcweir                 mbIsClipEmptied = true;
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir         else if( rClip.count() > 0 )
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir             mbIsClipSet = true;
216*cdf0e10cSrcweir             mbIsClipEmptied = false;
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir         else
219*cdf0e10cSrcweir         {
220*cdf0e10cSrcweir             // unexpected call
221*cdf0e10cSrcweir             throw std::exception();
222*cdf0e10cSrcweir         }
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     virtual bool resize( const basegfx::B2DRange& rArea )
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         const bool bRet( maBounds != rArea );
228*cdf0e10cSrcweir         maBounds = rArea;
229*cdf0e10cSrcweir         return bRet;
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     virtual target::ViewLayerSharedPtr createViewLayer(
233*cdf0e10cSrcweir         const basegfx::B2DRange& rLayerBounds ) const
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         maViewLayers.push_back( TestViewSharedPtr(new ImplTestView()));
236*cdf0e10cSrcweir         maViewLayers.back()->resize( rLayerBounds );
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir         return maViewLayers.back();
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     virtual bool updateScreen() const
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         // misusing updateScreen for state reporting
244*cdf0e10cSrcweir         return !mbDisposed;
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     virtual bool paintScreen() const
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         // misusing updateScreen for state reporting
250*cdf0e10cSrcweir         return !mbDisposed;
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     virtual void clear() const
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir     }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     virtual void clearAll() const
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir     virtual void setViewSize( const ::basegfx::B2DSize& )
262*cdf0e10cSrcweir     {
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     virtual void setCursorShape( sal_Int16 /*nPointerShape*/ )
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir     }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     virtual uno::Reference< presentation::XSlideShowView > getUnoView() const
270*cdf0e10cSrcweir     {
271*cdf0e10cSrcweir         return uno::Reference< presentation::XSlideShowView >( const_cast<ImplTestView*>(this) );
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     virtual void _dispose()
275*cdf0e10cSrcweir     {
276*cdf0e10cSrcweir         mbDisposed = true;
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir };
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir TestViewSharedPtr createTestView()
282*cdf0e10cSrcweir {
283*cdf0e10cSrcweir     return TestViewSharedPtr(
284*cdf0e10cSrcweir         comphelper::make_shared_from_UNO(
285*cdf0e10cSrcweir             new ImplTestView()) );
286*cdf0e10cSrcweir }
287