xref: /aoo42x/main/slideshow/test/demoshow.cxx (revision d9ee14b8)
170f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
370f497fbSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
470f497fbSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
570f497fbSAndrew Rist  * distributed with this work for additional information
670f497fbSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
770f497fbSAndrew Rist  * to you under the Apache License, Version 2.0 (the
870f497fbSAndrew Rist  * "License"); you may not use this file except in compliance
970f497fbSAndrew Rist  * with the License.  You may obtain a copy of the License at
1070f497fbSAndrew Rist  *
1170f497fbSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1270f497fbSAndrew Rist  *
1370f497fbSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1470f497fbSAndrew Rist  * software distributed under the License is distributed on an
1570f497fbSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1670f497fbSAndrew Rist  * KIND, either express or implied.  See the License for the
1770f497fbSAndrew Rist  * specific language governing permissions and limitations
1870f497fbSAndrew Rist  * under the License.
1970f497fbSAndrew Rist  *
2070f497fbSAndrew Rist  *************************************************************/
2170f497fbSAndrew Rist 
2270f497fbSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <sal/main.h>
25cdf0e10cSrcweir #include <rtl/ref.hxx>
26cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
29cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
30cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
31cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
32cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
36cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
37cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
42cdf0e10cSrcweir #include <com/sun/star/rendering/XSpriteCanvas.hpp>
43cdf0e10cSrcweir #include <com/sun/star/presentation/XSlideShow.hpp>
44cdf0e10cSrcweir #include <com/sun/star/presentation/XSlideShowView.hpp>
45cdf0e10cSrcweir #include "com/sun/star/animations/TransitionType.hpp"
46cdf0e10cSrcweir #include "com/sun/star/animations/TransitionSubType.hpp"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
49cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx>
50cdf0e10cSrcweir 
51*d9ee14b8SDamjan Jovanovic #include <basegfx/matrix/b2dhommatrixtools.hxx>
52cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
53cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
54cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
55cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx>
58cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
59cdf0e10cSrcweir #include <cppcanvas/polypolygon.hxx>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include <canvas/canvastools.hxx>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <vcl/dialog.hxx>
64cdf0e10cSrcweir #include <vcl/timer.hxx>
65cdf0e10cSrcweir #include <vcl/window.hxx>
66cdf0e10cSrcweir #include <vcl/svapp.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <stdio.h>
69cdf0e10cSrcweir #include <unistd.h>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir using namespace ::com::sun::star;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir namespace {
75cdf0e10cSrcweir 
76cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1< presentation::XSlideShowView > ViewBase;
77cdf0e10cSrcweir class View : public ::comphelper::OBaseMutex,
78cdf0e10cSrcweir              public ViewBase
79cdf0e10cSrcweir {
80cdf0e10cSrcweir public:
81cdf0e10cSrcweir     explicit View( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) :
82cdf0e10cSrcweir         ViewBase( m_aMutex ),
83cdf0e10cSrcweir         mxCanvas( rCanvas ),
84cdf0e10cSrcweir         maPaintListeners( m_aMutex ),
85cdf0e10cSrcweir         maTransformationListeners( m_aMutex ),
86cdf0e10cSrcweir         maMouseListeners( m_aMutex ),
87cdf0e10cSrcweir         maMouseMotionListeners( m_aMutex ),
88cdf0e10cSrcweir         maTransform(),
89cdf0e10cSrcweir         maSize()
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     void resize( const ::Size& rNewSize )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         maSize = rNewSize;
96cdf0e10cSrcweir         const sal_Int32 nSize( std::min( rNewSize.Width(), rNewSize.Height() ) - 10);
97cdf0e10cSrcweir         maTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
98cdf0e10cSrcweir             nSize, nSize, (rNewSize.Width() - nSize) / 2, (rNewSize.Height() - nSize) / 2);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         lang::EventObject aEvent( *this );
101cdf0e10cSrcweir         maTransformationListeners.notifyEach( &util::XModifyListener::modified,
102cdf0e10cSrcweir                                               aEvent );
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     void repaint()
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         awt::PaintEvent aEvent( *this,
108cdf0e10cSrcweir                                 awt::Rectangle(),
109cdf0e10cSrcweir                                 0 );
110cdf0e10cSrcweir         maPaintListeners.notifyEach( &awt::XPaintListener::windowPaint,
111cdf0e10cSrcweir                                      aEvent );
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
114*d9ee14b8SDamjan Jovanovic     virtual ::com::sun::star::awt::Rectangle SAL_CALL getCanvasArea(  ) throw (::com::sun::star::uno::RuntimeException)
115*d9ee14b8SDamjan Jovanovic     {
116*d9ee14b8SDamjan Jovanovic         // FIXME:
117*d9ee14b8SDamjan Jovanovic         ::com::sun::star::awt::Rectangle r;
118*d9ee14b8SDamjan Jovanovic         r.X = 0;
119*d9ee14b8SDamjan Jovanovic         r.Y = 0;
120*d9ee14b8SDamjan Jovanovic         r.Width = 0;
121*d9ee14b8SDamjan Jovanovic         r.Height = 0;
122*d9ee14b8SDamjan Jovanovic         return r;
123*d9ee14b8SDamjan Jovanovic     }
124*d9ee14b8SDamjan Jovanovic 
125cdf0e10cSrcweir private:
126cdf0e10cSrcweir     virtual ~View() {}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     virtual uno::Reference< rendering::XSpriteCanvas > SAL_CALL getCanvas(  ) throw (uno::RuntimeException)
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         return mxCanvas;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     virtual void SAL_CALL clear(  ) throw (uno::RuntimeException)
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         ::basegfx::B2DPolygon aPoly( ::basegfx::tools::createPolygonFromRect(
136cdf0e10cSrcweir                                          ::basegfx::B2DRectangle(0.0,0.0,
137cdf0e10cSrcweir                                                                  maSize.Width(),
138cdf0e10cSrcweir                                                                  maSize.Height() )));
139cdf0e10cSrcweir         ::cppcanvas::SpriteCanvasSharedPtr pCanvas(
140cdf0e10cSrcweir             ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( mxCanvas ));
141cdf0e10cSrcweir         if( !pCanvas )
142cdf0e10cSrcweir             return;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
145cdf0e10cSrcweir             ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( pCanvas,
146cdf0e10cSrcweir                                                                           aPoly ) );
147cdf0e10cSrcweir         if( !pPolyPoly )
148cdf0e10cSrcweir             return;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         if( pPolyPoly )
151cdf0e10cSrcweir         {
152cdf0e10cSrcweir             pPolyPoly->setRGBAFillColor( 0x808080FFU );
153cdf0e10cSrcweir             pPolyPoly->draw();
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     virtual geometry::AffineMatrix2D SAL_CALL getTransformation(  ) throw (uno::RuntimeException)
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         geometry::AffineMatrix2D aRes;
160cdf0e10cSrcweir         return basegfx::unotools::affineMatrixFromHomMatrix( aRes,
161cdf0e10cSrcweir                                                              maTransform );
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     virtual void SAL_CALL addTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         maTransformationListeners.addInterface( xListener );
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     virtual void SAL_CALL removeTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         maTransformationListeners.removeInterface( xListener );
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     virtual void SAL_CALL addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         maPaintListeners.addInterface( xListener );
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     virtual void SAL_CALL removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         maPaintListeners.removeInterface( xListener );
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     virtual void SAL_CALL addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         maMouseListeners.addInterface( xListener );
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     virtual void SAL_CALL removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
190cdf0e10cSrcweir     {
191cdf0e10cSrcweir         maMouseListeners.removeInterface( xListener );
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     virtual void SAL_CALL addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         maMouseMotionListeners.addInterface( xListener );
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     virtual void SAL_CALL removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         maMouseMotionListeners.removeInterface( xListener );
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     virtual void SAL_CALL setMouseCursor( ::sal_Int16 /*nPointerShape*/ ) throw (uno::RuntimeException)
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     uno::Reference< rendering::XSpriteCanvas > mxCanvas;
209cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper          maPaintListeners;
210cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper          maTransformationListeners;
211cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper          maMouseListeners;
212cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper          maMouseMotionListeners;
213cdf0e10cSrcweir     basegfx::B2DHomMatrix                      maTransform;
214cdf0e10cSrcweir     Size                                       maSize;
215cdf0e10cSrcweir };
216cdf0e10cSrcweir 
217cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2< drawing::XDrawPage,
218cdf0e10cSrcweir                                           beans::XPropertySet > SlideBase;
219cdf0e10cSrcweir class DummySlide : public ::comphelper::OBaseMutex,
220cdf0e10cSrcweir                    public SlideBase
221cdf0e10cSrcweir {
222cdf0e10cSrcweir public:
223cdf0e10cSrcweir     DummySlide() : SlideBase( m_aMutex ) {}
224cdf0e10cSrcweir 
225cdf0e10cSrcweir private:
226cdf0e10cSrcweir     // XDrawPage
227cdf0e10cSrcweir     virtual void SAL_CALL add( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     virtual void SAL_CALL remove( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         return 0;
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         return uno::Any();
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         return uno::Type();
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         return false;
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     // XPropertySet
256cdf0e10cSrcweir     virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw (uno::RuntimeException)
257cdf0e10cSrcweir     {
258cdf0e10cSrcweir         return uno::Reference< beans::XPropertySetInfo >();
259cdf0e10cSrcweir     }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& /*aPropertyName*/,
262cdf0e10cSrcweir                                             const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     virtual uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         typedef ::canvas::tools::ValueMap< sal_Int16 > PropMapT;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         // fixed PropertyValue map
271cdf0e10cSrcweir         static PropMapT::MapEntry lcl_propertyMap[] =
272cdf0e10cSrcweir             {
273cdf0e10cSrcweir                 {"Height",               100},
274cdf0e10cSrcweir                 {"MinimalFrameNumber",   50},
275cdf0e10cSrcweir                 {"TransitionDuration",   10},
276cdf0e10cSrcweir                 {"TransitionSubtype",    animations::TransitionSubType::FROMTOPLEFT},
277cdf0e10cSrcweir                 {"TransitionType",       animations::TransitionType::PUSHWIPE},
278cdf0e10cSrcweir                 {"Width",                100}
279cdf0e10cSrcweir             };
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         static PropMapT aMap( lcl_propertyMap,
282cdf0e10cSrcweir                               sizeof(lcl_propertyMap)/sizeof(*lcl_propertyMap),
283cdf0e10cSrcweir                               true );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         sal_Int16 aRes;
286cdf0e10cSrcweir         if( !aMap.lookup( PropertyName, aRes ))
287cdf0e10cSrcweir             return uno::Any();
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         return uno::makeAny(aRes);
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/,
293cdf0e10cSrcweir                                                      const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
294cdf0e10cSrcweir     {
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/,
298cdf0e10cSrcweir                                                         const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
299cdf0e10cSrcweir     {
300cdf0e10cSrcweir     }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/,
303cdf0e10cSrcweir                                                      const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/,
308cdf0e10cSrcweir                                                         const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir };
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
314cdf0e10cSrcweir class DemoApp : public Application
315cdf0e10cSrcweir {
316cdf0e10cSrcweir public:
317cdf0e10cSrcweir 	virtual void Main();
318cdf0e10cSrcweir 	virtual sal_uInt16	Exception( sal_uInt16 nError );
319cdf0e10cSrcweir };
320cdf0e10cSrcweir 
321cdf0e10cSrcweir class ChildWindow : public Window
322cdf0e10cSrcweir {
323cdf0e10cSrcweir public:
324cdf0e10cSrcweir     ChildWindow( Window* pParent );
325cdf0e10cSrcweir     virtual ~ChildWindow();
326cdf0e10cSrcweir     virtual void Paint( const Rectangle& rRect );
327cdf0e10cSrcweir     virtual void Resize();
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     void setShow( const uno::Reference< presentation::XSlideShow >& rShow ) { mxShow = rShow; init(); }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir private:
332cdf0e10cSrcweir     void init();
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     rtl::Reference< View >                     mpView;
335cdf0e10cSrcweir     uno::Reference< presentation::XSlideShow > mxShow;
336cdf0e10cSrcweir };
337cdf0e10cSrcweir 
338cdf0e10cSrcweir ChildWindow::ChildWindow( Window* pParent ) :
339cdf0e10cSrcweir     Window(pParent, WB_CLIPCHILDREN | WB_BORDER| WB_3DLOOK ),
340cdf0e10cSrcweir     mpView(),
341cdf0e10cSrcweir     mxShow()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     EnablePaint( true );
344cdf0e10cSrcweir     Show();
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir ChildWindow::~ChildWindow()
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     if( mxShow.is() && mpView.is() )
350cdf0e10cSrcweir         mxShow->removeView( mpView.get() );
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir void ChildWindow::init()
354cdf0e10cSrcweir {
355cdf0e10cSrcweir 	try
356cdf0e10cSrcweir 	{
357cdf0e10cSrcweir         if( !mpView.is() )
358cdf0e10cSrcweir         {
359cdf0e10cSrcweir             uno::Reference< rendering::XCanvas > xCanvas( GetCanvas(),
360cdf0e10cSrcweir                                                           uno::UNO_QUERY_THROW );
361cdf0e10cSrcweir             uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
362cdf0e10cSrcweir                                                                       uno::UNO_QUERY_THROW );
363cdf0e10cSrcweir             mpView = new View( xSpriteCanvas );
364cdf0e10cSrcweir             mpView->resize( GetSizePixel() );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir             if( mxShow.is() )
367cdf0e10cSrcweir                 mxShow->addView( mpView.get() );
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir 	}
370cdf0e10cSrcweir 	catch (const uno::Exception &e)
371cdf0e10cSrcweir 	{
372cdf0e10cSrcweir 		OSL_TRACE( "Exception '%s' thrown\n" ,
373cdf0e10cSrcweir                    (const sal_Char*)::rtl::OUStringToOString( e.Message,
374cdf0e10cSrcweir                                                               RTL_TEXTENCODING_UTF8 ));
375cdf0e10cSrcweir 	}
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir void ChildWindow::Paint( const Rectangle& /*rRect*/ )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	try
381cdf0e10cSrcweir 	{
382cdf0e10cSrcweir 		if( mpView.is() )
383cdf0e10cSrcweir             mpView->repaint();
384cdf0e10cSrcweir 	}
385cdf0e10cSrcweir 	catch (const uno::Exception &e)
386cdf0e10cSrcweir 	{
387cdf0e10cSrcweir 		OSL_TRACE( "Exception '%s' thrown\n" ,
388cdf0e10cSrcweir                    (const sal_Char*)::rtl::OUStringToOString( e.Message,
389cdf0e10cSrcweir                                                               RTL_TEXTENCODING_UTF8 ));
390cdf0e10cSrcweir 	}
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir void ChildWindow::Resize()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir     if( mpView.is() )
396cdf0e10cSrcweir         mpView->resize( GetSizePixel() );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir class DemoWindow : public Dialog
400cdf0e10cSrcweir {
401cdf0e10cSrcweir public:
402cdf0e10cSrcweir     DemoWindow();
403cdf0e10cSrcweir     virtual void Paint( const Rectangle& rRect );
404cdf0e10cSrcweir     virtual void Resize();
405cdf0e10cSrcweir 
406cdf0e10cSrcweir private:
407cdf0e10cSrcweir     void init();
408cdf0e10cSrcweir 	DECL_LINK( updateHdl, Timer* );
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     ChildWindow                                maLeftChild;
411cdf0e10cSrcweir     ChildWindow                                maRightTopChild;
412cdf0e10cSrcweir     ChildWindow                                maRightBottomChild;
413cdf0e10cSrcweir     uno::Reference< presentation::XSlideShow > mxShow;
414cdf0e10cSrcweir 	AutoTimer                                  maUpdateTimer;
415cdf0e10cSrcweir     bool                                       mbSlideDisplayed;
416cdf0e10cSrcweir };
417cdf0e10cSrcweir 
418cdf0e10cSrcweir DemoWindow::DemoWindow() :
419cdf0e10cSrcweir     Dialog((Window*)NULL),
420cdf0e10cSrcweir     maLeftChild( this ),
421cdf0e10cSrcweir     maRightTopChild( this ),
422cdf0e10cSrcweir     maRightBottomChild( this ),
423cdf0e10cSrcweir     mxShow(),
424cdf0e10cSrcweir     maUpdateTimer(),
425cdf0e10cSrcweir     mbSlideDisplayed( false )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir     SetText( rtl::OUString::createFromAscii( "Slideshow Demo" ) );
428cdf0e10cSrcweir     SetSizePixel( Size( 640, 480 ) );
429cdf0e10cSrcweir     EnablePaint( true );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     maLeftChild.SetPosSizePixel( Point(), Size(320,480) );
432cdf0e10cSrcweir     maRightTopChild.SetPosSizePixel( Point(320,0), Size(320,240) );
433cdf0e10cSrcweir     maRightBottomChild.SetPosSizePixel( Point(320,240), Size(320,240) );
434cdf0e10cSrcweir     Show();
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	maUpdateTimer.SetTimeoutHdl(LINK(this, DemoWindow, updateHdl));
437cdf0e10cSrcweir 	maUpdateTimer.SetTimeout( (sal_uLong)30 );
438cdf0e10cSrcweir 	maUpdateTimer.Start();
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir void DemoWindow::init()
442cdf0e10cSrcweir {
443cdf0e10cSrcweir 	try
444cdf0e10cSrcweir 	{
445cdf0e10cSrcweir         if( !mxShow.is() )
446cdf0e10cSrcweir         {
447cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory > xFactory(
448cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory(),
449cdf0e10cSrcweir                 uno::UNO_QUERY_THROW );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir             uno::Reference< uno::XInterface > xInt( xFactory->createInstance(
452cdf0e10cSrcweir                                                         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SlideShow")) ));
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             mxShow.set( xInt,
455cdf0e10cSrcweir                         uno::UNO_QUERY_THROW );
456cdf0e10cSrcweir 
457cdf0e10cSrcweir             maLeftChild.setShow( mxShow );
458cdf0e10cSrcweir             maRightTopChild.setShow( mxShow );
459cdf0e10cSrcweir             maRightBottomChild.setShow( mxShow );
460cdf0e10cSrcweir         }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir         if( mxShow.is() && !mbSlideDisplayed )
463cdf0e10cSrcweir         {
464cdf0e10cSrcweir             uno::Reference< drawing::XDrawPage > xSlide( new DummySlide );
465cdf0e10cSrcweir             mxShow->displaySlide( xSlide,
466*d9ee14b8SDamjan Jovanovic                                   NULL,
467cdf0e10cSrcweir                                   uno::Reference< animations::XAnimationNode >(),
468cdf0e10cSrcweir                                   uno::Sequence< beans::PropertyValue >() );
469cdf0e10cSrcweir             mxShow->setProperty( beans::PropertyValue(
470cdf0e10cSrcweir                                      rtl::OUString::createFromAscii("RehearseTimings"),
471cdf0e10cSrcweir                                      0,
472cdf0e10cSrcweir                                      uno::makeAny( sal_True ),
473cdf0e10cSrcweir                                      beans::PropertyState_DIRECT_VALUE ));
474cdf0e10cSrcweir             mbSlideDisplayed = true;
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir 	catch (const uno::Exception &e)
478cdf0e10cSrcweir 	{
479cdf0e10cSrcweir 		OSL_TRACE( "Exception '%s' thrown\n" ,
480cdf0e10cSrcweir                    (const sal_Char*)::rtl::OUStringToOString( e.Message,
481cdf0e10cSrcweir                                                               RTL_TEXTENCODING_UTF8 ));
482cdf0e10cSrcweir 	}
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir IMPL_LINK( DemoWindow, updateHdl, Timer*, EMPTYARG )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir     init();
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     double nTimeout;
490cdf0e10cSrcweir     if( mxShow.is() )
491cdf0e10cSrcweir         mxShow->update(nTimeout);
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     return 0;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir void DemoWindow::Paint( const Rectangle& /*rRect*/ )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     init();
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir void DemoWindow::Resize()
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     // TODO
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir sal_uInt16 DemoApp::Exception( sal_uInt16 nError )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir 	switch( nError & EXC_MAJORTYPE )
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		case EXC_RSCNOTLOADED:
511cdf0e10cSrcweir 			Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
512cdf0e10cSrcweir 			break;
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir 	return 0;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir void DemoApp::Main()
518cdf0e10cSrcweir {
519cdf0e10cSrcweir 	bool bHelp = false;
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 	for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
522cdf0e10cSrcweir 	{
523cdf0e10cSrcweir 		::rtl::OUString aParam = GetCommandLineParam( i );
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 		if( aParam.equalsAscii( "--help" ) ||
526cdf0e10cSrcweir 			aParam.equalsAscii( "-h" ) )
527cdf0e10cSrcweir 				bHelp = true;
528cdf0e10cSrcweir 	}
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	if( bHelp )
531cdf0e10cSrcweir 	{
532cdf0e10cSrcweir         printf( "demoshow - life Slideshow testbed\n" );
533cdf0e10cSrcweir 		return;
534cdf0e10cSrcweir 	}
535cdf0e10cSrcweir 
536cdf0e10cSrcweir     // bootstrap UNO
537cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFactory;
538cdf0e10cSrcweir     try
539cdf0e10cSrcweir     {
540cdf0e10cSrcweir         uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
541cdf0e10cSrcweir         xFactory = uno::Reference< lang::XMultiServiceFactory >(  xCtx->getServiceManager(),
542cdf0e10cSrcweir                                                                   uno::UNO_QUERY );
543cdf0e10cSrcweir         if( xFactory.is() )
544cdf0e10cSrcweir             ::comphelper::setProcessServiceFactory( xFactory );
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir     catch( uno::RuntimeException& )
547cdf0e10cSrcweir     {
548cdf0e10cSrcweir         throw;
549cdf0e10cSrcweir     }
550cdf0e10cSrcweir     catch( uno::Exception& )
551cdf0e10cSrcweir     {
552cdf0e10cSrcweir         OSL_ENSURE( false,
553cdf0e10cSrcweir                     rtl::OUStringToOString(
554cdf0e10cSrcweir                         comphelper::anyToString( cppu::getCaughtException() ),
555cdf0e10cSrcweir                         RTL_TEXTENCODING_UTF8 ).getStr() );
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     if( !xFactory.is() )
559cdf0e10cSrcweir     {
560cdf0e10cSrcweir         OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
561cdf0e10cSrcweir         exit( 1 );
562cdf0e10cSrcweir     }
563cdf0e10cSrcweir 
564cdf0e10cSrcweir     // Create UCB.
565cdf0e10cSrcweir     uno::Sequence< uno::Any > aArgs( 2 );
566cdf0e10cSrcweir 	aArgs[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
567cdf0e10cSrcweir 	aArgs[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
568cdf0e10cSrcweir     ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 	DemoWindow pWindow;
571cdf0e10cSrcweir 	pWindow.Execute();
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     // clean up UCB
574cdf0e10cSrcweir 	::ucbhelper::ContentBroker::deinitialize();
575cdf0e10cSrcweir }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir DemoApp aApp;
579