1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <rtl/ref.hxx>
30 #include <rtl/bootstrap.hxx>
32 #include <cppuhelper/bootstrap.hxx>
33 #include <cppuhelper/servicefactory.hxx>
34 #include <cppuhelper/interfacecontainer.hxx>
35 #include <cppuhelper/compbase1.hxx>
36 #include <cppuhelper/compbase2.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <comphelper/broadcasthelper.hxx>
40 #include <comphelper/anytostring.hxx>
41 #include <cppuhelper/exc_hlp.hxx>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/rendering/XCanvas.hpp>
46 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
47 #include <com/sun/star/presentation/XSlideShow.hpp>
48 #include <com/sun/star/presentation/XSlideShowView.hpp>
49 #include "com/sun/star/animations/TransitionType.hpp"
50 #include "com/sun/star/animations/TransitionSubType.hpp"
52 #include <ucbhelper/contentbroker.hxx>
53 #include <ucbhelper/configurationkeys.hxx>
55 #include <basegfx/matrix/b2dhommatrix.hxx>
56 #include <basegfx/matrix/b2dhommatrixtools.hxx>
57 #include <basegfx/tools/canvastools.hxx>
58 #include <basegfx/range/b2drectangle.hxx>
59 #include <basegfx/polygon/b2dpolygon.hxx>
60 #include <basegfx/polygon/b2dpolygontools.hxx>
62 #include <cppcanvas/vclfactory.hxx>
63 #include <cppcanvas/basegfxfactory.hxx>
64 #include <cppcanvas/polypolygon.hxx>
66 #include <canvas/canvastools.hxx>
68 #include <vcl/dialog.hxx>
69 #include <vcl/timer.hxx>
70 #include <vcl/window.hxx>
71 #include <vcl/svapp.hxx>
77 using namespace ::com::sun::star
;
81 typedef ::cppu::WeakComponentImplHelper1
< presentation::XSlideShowView
> ViewBase
;
82 class View
: public ::comphelper::OBaseMutex
,
86 explicit View( const uno::Reference
< rendering::XSpriteCanvas
>& rCanvas
) :
89 maPaintListeners( m_aMutex
),
90 maTransformationListeners( m_aMutex
),
91 maMouseListeners( m_aMutex
),
92 maMouseMotionListeners( m_aMutex
),
98 void resize( const ::Size
& rNewSize
)
101 const sal_Int32
nSize( std::min( rNewSize
.Width(), rNewSize
.Height() ) - 10);
102 maTransform
= basegfx::tools::createScaleTranslateB2DHomMatrix(
103 nSize
, nSize
, (rNewSize
.Width() - nSize
) / 2, (rNewSize
.Height() - nSize
) / 2);
105 lang::EventObject
aEvent( *this );
106 maTransformationListeners
.notifyEach( &util::XModifyListener::modified
,
112 awt::PaintEvent
aEvent( *this,
115 maPaintListeners
.notifyEach( &awt::XPaintListener::windowPaint
,
122 virtual uno::Reference
< rendering::XSpriteCanvas
> SAL_CALL
getCanvas( ) throw (uno::RuntimeException
)
127 virtual void SAL_CALL
clear( ) throw (uno::RuntimeException
)
129 ::basegfx::B2DPolygon
aPoly( ::basegfx::tools::createPolygonFromRect(
130 ::basegfx::B2DRectangle(0.0,0.0,
133 ::cppcanvas::SpriteCanvasSharedPtr
pCanvas(
134 ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( mxCanvas
));
138 ::cppcanvas::PolyPolygonSharedPtr
pPolyPoly(
139 ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( pCanvas
,
146 pPolyPoly
->setRGBAFillColor( 0x808080FFU
);
151 virtual geometry::AffineMatrix2D SAL_CALL
getTransformation( ) throw (uno::RuntimeException
)
153 geometry::AffineMatrix2D aRes
;
154 return basegfx::unotools::affineMatrixFromHomMatrix( aRes
,
158 virtual void SAL_CALL
addTransformationChangedListener( const uno::Reference
< util::XModifyListener
>& xListener
) throw (uno::RuntimeException
)
160 maTransformationListeners
.addInterface( xListener
);
163 virtual void SAL_CALL
removeTransformationChangedListener( const uno::Reference
< util::XModifyListener
>& xListener
) throw (uno::RuntimeException
)
165 maTransformationListeners
.removeInterface( xListener
);
168 virtual void SAL_CALL
addPaintListener( const uno::Reference
< awt::XPaintListener
>& xListener
) throw (uno::RuntimeException
)
170 maPaintListeners
.addInterface( xListener
);
173 virtual void SAL_CALL
removePaintListener( const uno::Reference
< awt::XPaintListener
>& xListener
) throw (uno::RuntimeException
)
175 maPaintListeners
.removeInterface( xListener
);
178 virtual void SAL_CALL
addMouseListener( const uno::Reference
< awt::XMouseListener
>& xListener
) throw (uno::RuntimeException
)
180 maMouseListeners
.addInterface( xListener
);
183 virtual void SAL_CALL
removeMouseListener( const uno::Reference
< awt::XMouseListener
>& xListener
) throw (uno::RuntimeException
)
185 maMouseListeners
.removeInterface( xListener
);
188 virtual void SAL_CALL
addMouseMotionListener( const uno::Reference
< awt::XMouseMotionListener
>& xListener
) throw (uno::RuntimeException
)
190 maMouseMotionListeners
.addInterface( xListener
);
193 virtual void SAL_CALL
removeMouseMotionListener( const uno::Reference
< awt::XMouseMotionListener
>& xListener
) throw (uno::RuntimeException
)
195 maMouseMotionListeners
.removeInterface( xListener
);
198 virtual void SAL_CALL
setMouseCursor( ::sal_Int16
/*nPointerShape*/ ) throw (uno::RuntimeException
)
202 virtual awt::Rectangle SAL_CALL
getCanvasArea( ) throw (uno::RuntimeException
)
204 return awt::Rectangle(0,0,maSize
.Width(),maSize
.Height());
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 sal_uInt16
Exception( sal_uInt16 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 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
376 void ChildWindow::Paint( const Rectangle
& /*rRect*/ )
383 catch (const uno::Exception
&e
)
385 OSL_TRACE( "Exception '%s' thrown\n" ,
386 ::rtl::OUStringToOString( e
.Message
,
387 RTL_TEXTENCODING_UTF8
).getStr() );
391 void ChildWindow::Resize()
394 mpView
->resize( GetSizePixel() );
397 class DemoWindow
: public Dialog
401 virtual void Paint( const Rectangle
& rRect
);
402 virtual void Resize();
406 DECL_LINK( updateHdl
, Timer
* );
408 ChildWindow maLeftChild
;
409 ChildWindow maRightTopChild
;
410 ChildWindow maRightBottomChild
;
411 uno::Reference
< presentation::XSlideShow
> mxShow
;
412 AutoTimer maUpdateTimer
;
413 bool mbSlideDisplayed
;
416 DemoWindow::DemoWindow() :
417 Dialog((Window
*)NULL
),
419 maRightTopChild( this ),
420 maRightBottomChild( this ),
423 mbSlideDisplayed( false )
425 SetText( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Slideshow Demo" )) );
426 SetSizePixel( Size( 640, 480 ) );
429 maLeftChild
.SetPosSizePixel( Point(), Size(320,480) );
430 maRightTopChild
.SetPosSizePixel( Point(320,0), Size(320,240) );
431 maRightBottomChild
.SetPosSizePixel( Point(320,240), Size(320,240) );
434 maUpdateTimer
.SetTimeoutHdl(LINK(this, DemoWindow
, updateHdl
));
435 maUpdateTimer
.SetTimeout( (sal_uLong
)30 );
436 maUpdateTimer
.Start();
439 void DemoWindow::init()
445 uno::Reference
< lang::XMultiServiceFactory
> xFactory(
446 ::comphelper::getProcessServiceFactory(),
447 uno::UNO_QUERY_THROW
);
449 uno::Reference
< uno::XInterface
> xInt( xFactory
->createInstance(
450 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SlideShow")) ));
453 uno::UNO_QUERY_THROW
);
455 maLeftChild
.setShow( mxShow
);
456 maRightTopChild
.setShow( mxShow
);
457 maRightBottomChild
.setShow( mxShow
);
460 if( mxShow
.is() && !mbSlideDisplayed
)
462 uno::Reference
< drawing::XDrawPage
> xSlide( new DummySlide
);
463 uno::Reference
< drawing::XDrawPages
> xDrawPages
;
464 mxShow
->displaySlide( xSlide
,
465 uno::Reference
< drawing::XDrawPagesSupplier
>(),
466 uno::Reference
< animations::XAnimationNode
>(),
467 uno::Sequence
< beans::PropertyValue
>() );
468 mxShow
->setProperty( beans::PropertyValue(
469 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RehearseTimings")),
471 uno::makeAny( sal_True
),
472 beans::PropertyState_DIRECT_VALUE
));
473 mbSlideDisplayed
= true;
476 catch (const uno::Exception
&e
)
478 OSL_TRACE( "Exception '%s' thrown\n" ,
479 ::rtl::OUStringToOString( e
.Message
,
480 RTL_TEXTENCODING_UTF8
).getStr() );
484 IMPL_LINK( DemoWindow
, updateHdl
, Timer
*, EMPTYARG
)
491 mxShow
->update(nTimeout
);
496 void DemoWindow::Paint( const Rectangle
& /*rRect*/ )
501 void DemoWindow::Resize()
506 sal_uInt16
DemoApp::Exception( sal_uInt16 nError
)
508 switch( nError
& EXC_MAJORTYPE
)
510 case EXC_RSCNOTLOADED
:
511 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
521 for( sal_uInt16 i
= 0; i
< GetCommandLineParamCount(); i
++ )
523 ::rtl::OUString aParam
= GetCommandLineParam( i
);
525 if( aParam
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--help" ) ) ||
526 aParam
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ) ) )
532 printf( "demoshow - life Slideshow testbed\n" );
537 uno::Reference
< lang::XMultiServiceFactory
> xFactory
;
540 uno::Reference
< uno::XComponentContext
> xCtx
= ::cppu::defaultBootstrap_InitialComponentContext();
541 xFactory
= uno::Reference
< lang::XMultiServiceFactory
>( xCtx
->getServiceManager(),
544 ::comphelper::setProcessServiceFactory( xFactory
);
546 catch( uno::RuntimeException
& )
550 catch( uno::Exception
& )
552 OSL_FAIL( rtl::OUStringToOString(
553 comphelper::anyToString( cppu::getCaughtException() ),
554 RTL_TEXTENCODING_UTF8
).getStr() );
559 OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting." );
564 uno::Sequence
< uno::Any
> aArgs( 2 );
565 aArgs
[ 0 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UCB_CONFIGURATION_KEY1_LOCAL
));
566 aArgs
[ 1 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UCB_CONFIGURATION_KEY2_OFFICE
));
567 ::ucbhelper::ContentBroker::initialize( xFactory
, aArgs
);
573 ::ucbhelper::ContentBroker::deinitialize();
579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */