1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: demoshow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <rtl/ref.hxx>
33 #include <rtl/bootstrap.hxx>
35 #include <cppuhelper/bootstrap.hxx>
36 #include <cppuhelper/servicefactory.hxx>
37 #include <cppuhelper/interfacecontainer.hxx>
38 #include <cppuhelper/compbase1.hxx>
39 #include <cppuhelper/compbase2.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <comphelper/broadcasthelper.hxx>
43 #include <comphelper/anytostring.hxx>
44 #include <cppuhelper/exc_hlp.hxx>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/rendering/XCanvas.hpp>
49 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
50 #include <com/sun/star/presentation/XSlideShow.hpp>
51 #include <com/sun/star/presentation/XSlideShowView.hpp>
52 #include "com/sun/star/animations/TransitionType.hpp"
53 #include "com/sun/star/animations/TransitionSubType.hpp"
55 #include <ucbhelper/contentbroker.hxx>
56 #include <ucbhelper/configurationkeys.hxx>
58 #include <basegfx/matrix/b2dhommatrix.hxx>
59 #include <basegfx/tools/canvastools.hxx>
60 #include <basegfx/range/b2drectangle.hxx>
61 #include <basegfx/polygon/b2dpolygon.hxx>
62 #include <basegfx/polygon/b2dpolygontools.hxx>
64 #include <cppcanvas/vclfactory.hxx>
65 #include <cppcanvas/basegfxfactory.hxx>
66 #include <cppcanvas/polypolygon.hxx>
68 #include <canvas/canvastools.hxx>
70 #include <vcl/dialog.hxx>
71 #include <vcl/timer.hxx>
72 #include <vcl/window.hxx>
73 #include <vcl/svapp.hxx>
79 using namespace ::com::sun::star
;
83 typedef ::cppu::WeakComponentImplHelper1
< presentation::XSlideShowView
> ViewBase
;
84 class View
: public ::comphelper::OBaseMutex
,
88 explicit View( const uno::Reference
< rendering::XSpriteCanvas
>& rCanvas
) :
91 maPaintListeners( m_aMutex
),
92 maTransformationListeners( m_aMutex
),
93 maMouseListeners( m_aMutex
),
94 maMouseMotionListeners( m_aMutex
),
100 void resize( const ::Size
& rNewSize
)
103 maTransform
.identity();
104 const sal_Int32
nSize( std::min( rNewSize
.Width(),
105 rNewSize
.Height() ) - 10 );
106 maTransform
.scale( nSize
, nSize
);
107 maTransform
.translate( (rNewSize
.Width() - nSize
) / 2,
108 (rNewSize
.Height() - nSize
) / 2 );
110 lang::EventObject
aEvent( *this );
111 maTransformationListeners
.notifyEach( &util::XModifyListener::modified
,
117 awt::PaintEvent
aEvent( *this,
120 maPaintListeners
.notifyEach( &awt::XPaintListener::windowPaint
,
127 virtual uno::Reference
< rendering::XSpriteCanvas
> SAL_CALL
getCanvas( ) throw (uno::RuntimeException
)
132 virtual void SAL_CALL
clear( ) throw (uno::RuntimeException
)
134 ::basegfx::B2DPolygon
aPoly( ::basegfx::tools::createPolygonFromRect(
135 ::basegfx::B2DRectangle(0.0,0.0,
138 ::cppcanvas::SpriteCanvasSharedPtr
pCanvas(
139 ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( mxCanvas
));
143 ::cppcanvas::PolyPolygonSharedPtr
pPolyPoly(
144 ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( pCanvas
,
151 pPolyPoly
->setRGBAFillColor( 0x808080FFU
);
156 virtual geometry::AffineMatrix2D SAL_CALL
getTransformation( ) throw (uno::RuntimeException
)
158 geometry::AffineMatrix2D aRes
;
159 return basegfx::unotools::affineMatrixFromHomMatrix( aRes
,
163 virtual void SAL_CALL
addTransformationChangedListener( const uno::Reference
< util::XModifyListener
>& xListener
) throw (uno::RuntimeException
)
165 maTransformationListeners
.addInterface( xListener
);
168 virtual void SAL_CALL
removeTransformationChangedListener( const uno::Reference
< util::XModifyListener
>& xListener
) throw (uno::RuntimeException
)
170 maTransformationListeners
.removeInterface( xListener
);
173 virtual void SAL_CALL
addPaintListener( const uno::Reference
< awt::XPaintListener
>& xListener
) throw (uno::RuntimeException
)
175 maPaintListeners
.addInterface( xListener
);
178 virtual void SAL_CALL
removePaintListener( const uno::Reference
< awt::XPaintListener
>& xListener
) throw (uno::RuntimeException
)
180 maPaintListeners
.removeInterface( xListener
);
183 virtual void SAL_CALL
addMouseListener( const uno::Reference
< awt::XMouseListener
>& xListener
) throw (uno::RuntimeException
)
185 maMouseListeners
.addInterface( xListener
);
188 virtual void SAL_CALL
removeMouseListener( const uno::Reference
< awt::XMouseListener
>& xListener
) throw (uno::RuntimeException
)
190 maMouseListeners
.removeInterface( xListener
);
193 virtual void SAL_CALL
addMouseMotionListener( const uno::Reference
< awt::XMouseMotionListener
>& xListener
) throw (uno::RuntimeException
)
195 maMouseMotionListeners
.addInterface( xListener
);
198 virtual void SAL_CALL
removeMouseMotionListener( const uno::Reference
< awt::XMouseMotionListener
>& xListener
) throw (uno::RuntimeException
)
200 maMouseMotionListeners
.removeInterface( xListener
);
203 virtual void SAL_CALL
setMouseCursor( ::sal_Int16
/*nPointerShape*/ ) throw (uno::RuntimeException
)
207 uno::Reference
< rendering::XSpriteCanvas
> mxCanvas
;
208 ::cppu::OInterfaceContainerHelper maPaintListeners
;
209 ::cppu::OInterfaceContainerHelper maTransformationListeners
;
210 ::cppu::OInterfaceContainerHelper maMouseListeners
;
211 ::cppu::OInterfaceContainerHelper maMouseMotionListeners
;
212 basegfx::B2DHomMatrix maTransform
;
216 typedef ::cppu::WeakComponentImplHelper2
< drawing::XDrawPage
,
217 beans::XPropertySet
> SlideBase
;
218 class DummySlide
: public ::comphelper::OBaseMutex
,
222 DummySlide() : SlideBase( m_aMutex
) {}
226 virtual void SAL_CALL
add( const uno::Reference
< drawing::XShape
>& /*xShape*/ ) throw (uno::RuntimeException
)
230 virtual void SAL_CALL
remove( const uno::Reference
< drawing::XShape
>& /*xShape*/ ) throw (uno::RuntimeException
)
234 virtual ::sal_Int32 SAL_CALL
getCount( ) throw (uno::RuntimeException
)
239 virtual uno::Any SAL_CALL
getByIndex( ::sal_Int32
/*Index*/ ) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
244 virtual uno::Type SAL_CALL
getElementType( ) throw (uno::RuntimeException
)
249 virtual ::sal_Bool SAL_CALL
hasElements( ) throw (uno::RuntimeException
)
255 virtual uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw (uno::RuntimeException
)
257 return uno::Reference
< beans::XPropertySetInfo
>();
260 virtual void SAL_CALL
setPropertyValue( const ::rtl::OUString
& /*aPropertyName*/,
261 const uno::Any
& /*aValue*/ ) throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
265 virtual uno::Any SAL_CALL
getPropertyValue( const ::rtl::OUString
& PropertyName
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
267 typedef ::canvas::tools::ValueMap
< sal_Int16
> PropMapT
;
269 // fixed PropertyValue map
270 static PropMapT::MapEntry lcl_propertyMap
[] =
273 {"MinimalFrameNumber", 50},
274 {"TransitionDuration", 10},
275 {"TransitionSubtype", animations::TransitionSubType::FROMTOPLEFT
},
276 {"TransitionType", animations::TransitionType::PUSHWIPE
},
280 static PropMapT
aMap( lcl_propertyMap
,
281 sizeof(lcl_propertyMap
)/sizeof(*lcl_propertyMap
),
285 if( !aMap
.lookup( PropertyName
, aRes
))
288 return uno::makeAny(aRes
);
291 virtual void SAL_CALL
addPropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/,
292 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ ) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
296 virtual void SAL_CALL
removePropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/,
297 const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ ) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
301 virtual void SAL_CALL
addVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/,
302 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ ) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
306 virtual void SAL_CALL
removeVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/,
307 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ ) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
313 class DemoApp
: public Application
317 virtual USHORT
Exception( USHORT nError
);
320 class ChildWindow
: public Window
323 ChildWindow( Window
* pParent
);
324 virtual ~ChildWindow();
325 virtual void Paint( const Rectangle
& rRect
);
326 virtual void Resize();
328 void setShow( const uno::Reference
< presentation::XSlideShow
>& rShow
) { mxShow
= rShow
; init(); }
333 rtl::Reference
< View
> mpView
;
334 uno::Reference
< presentation::XSlideShow
> mxShow
;
337 ChildWindow::ChildWindow( Window
* pParent
) :
338 Window(pParent
, WB_CLIPCHILDREN
| WB_BORDER
| WB_3DLOOK
),
346 ChildWindow::~ChildWindow()
348 if( mxShow
.is() && mpView
.is() )
349 mxShow
->removeView( mpView
.get() );
352 void ChildWindow::init()
358 uno::Reference
< rendering::XCanvas
> xCanvas( GetCanvas(),
359 uno::UNO_QUERY_THROW
);
360 uno::Reference
< rendering::XSpriteCanvas
> xSpriteCanvas( xCanvas
,
361 uno::UNO_QUERY_THROW
);
362 mpView
= new View( xSpriteCanvas
);
363 mpView
->resize( GetSizePixel() );
366 mxShow
->addView( mpView
.get() );
369 catch (const uno::Exception
&e
)
371 OSL_TRACE( "Exception '%s' thrown\n" ,
372 (const sal_Char
*)::rtl::OUStringToOString( e
.Message
,
373 RTL_TEXTENCODING_UTF8
));
377 void ChildWindow::Paint( const Rectangle
& /*rRect*/ )
384 catch (const uno::Exception
&e
)
386 OSL_TRACE( "Exception '%s' thrown\n" ,
387 (const sal_Char
*)::rtl::OUStringToOString( e
.Message
,
388 RTL_TEXTENCODING_UTF8
));
392 void ChildWindow::Resize()
395 mpView
->resize( GetSizePixel() );
398 class DemoWindow
: public Dialog
402 virtual void Paint( const Rectangle
& rRect
);
403 virtual void Resize();
407 DECL_LINK( updateHdl
, Timer
* );
409 ChildWindow maLeftChild
;
410 ChildWindow maRightTopChild
;
411 ChildWindow maRightBottomChild
;
412 uno::Reference
< presentation::XSlideShow
> mxShow
;
413 AutoTimer maUpdateTimer
;
414 bool mbSlideDisplayed
;
417 DemoWindow::DemoWindow() :
418 Dialog((Window
*)NULL
),
420 maRightTopChild( this ),
421 maRightBottomChild( this ),
424 mbSlideDisplayed( false )
426 SetText( rtl::OUString::createFromAscii( "Slideshow Demo" ) );
427 SetSizePixel( Size( 640, 480 ) );
430 maLeftChild
.SetPosSizePixel( Point(), Size(320,480) );
431 maRightTopChild
.SetPosSizePixel( Point(320,0), Size(320,240) );
432 maRightBottomChild
.SetPosSizePixel( Point(320,240), Size(320,240) );
435 maUpdateTimer
.SetTimeoutHdl(LINK(this, DemoWindow
, updateHdl
));
436 maUpdateTimer
.SetTimeout( (ULONG
)30 );
437 maUpdateTimer
.Start();
440 void DemoWindow::init()
446 uno::Reference
< lang::XMultiServiceFactory
> xFactory(
447 ::comphelper::getProcessServiceFactory(),
448 uno::UNO_QUERY_THROW
);
450 uno::Reference
< uno::XInterface
> xInt( xFactory
->createInstance(
451 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SlideShow")) ));
454 uno::UNO_QUERY_THROW
);
456 maLeftChild
.setShow( mxShow
);
457 maRightTopChild
.setShow( mxShow
);
458 maRightBottomChild
.setShow( mxShow
);
461 if( mxShow
.is() && !mbSlideDisplayed
)
463 uno::Reference
< drawing::XDrawPage
> xSlide( new DummySlide
);
464 mxShow
->displaySlide( xSlide
,
465 uno::Reference
< animations::XAnimationNode
>(),
466 uno::Sequence
< beans::PropertyValue
>() );
467 mxShow
->setProperty( beans::PropertyValue(
468 rtl::OUString::createFromAscii("RehearseTimings"),
470 uno::makeAny( sal_True
),
471 beans::PropertyState_DIRECT_VALUE
));
472 mbSlideDisplayed
= true;
475 catch (const uno::Exception
&e
)
477 OSL_TRACE( "Exception '%s' thrown\n" ,
478 (const sal_Char
*)::rtl::OUStringToOString( e
.Message
,
479 RTL_TEXTENCODING_UTF8
));
483 IMPL_LINK( DemoWindow
, updateHdl
, Timer
*, EMPTYARG
)
489 mxShow
->update(nTimeout
);
494 void DemoWindow::Paint( const Rectangle
& /*rRect*/ )
499 void DemoWindow::Resize()
504 USHORT
DemoApp::Exception( USHORT nError
)
506 switch( nError
& EXC_MAJORTYPE
)
508 case EXC_RSCNOTLOADED
:
509 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
519 for( USHORT i
= 0; i
< GetCommandLineParamCount(); i
++ )
521 ::rtl::OUString aParam
= GetCommandLineParam( i
);
523 if( aParam
.equalsAscii( "--help" ) ||
524 aParam
.equalsAscii( "-h" ) )
530 printf( "demoshow - life Slideshow testbed\n" );
535 uno::Reference
< lang::XMultiServiceFactory
> xFactory
;
538 uno::Reference
< uno::XComponentContext
> xCtx
= ::cppu::defaultBootstrap_InitialComponentContext();
539 xFactory
= uno::Reference
< lang::XMultiServiceFactory
>( xCtx
->getServiceManager(),
542 ::comphelper::setProcessServiceFactory( xFactory
);
544 catch( uno::RuntimeException
& )
548 catch( uno::Exception
& )
551 rtl::OUStringToOString(
552 comphelper::anyToString( cppu::getCaughtException() ),
553 RTL_TEXTENCODING_UTF8
).getStr() );
558 OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
563 uno::Sequence
< uno::Any
> aArgs( 2 );
564 aArgs
[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL
);
565 aArgs
[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE
);
566 ::ucbhelper::ContentBroker::initialize( xFactory
, aArgs
);
572 ::ucbhelper::ContentBroker::deinitialize();