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