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