Bump version to 6.0-36
[LibreOffice.git] / slideshow / test / demoshow.cxx
blobcef4ab9b46b37032c612958e0f3d4b2b9ad507de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ref.hxx>
21 #include <rtl/bootstrap.hxx>
23 #include <cppuhelper/bootstrap.hxx>
24 #include <cppuhelper/servicefactory.hxx>
25 #include <cppuhelper/interfacecontainer.hxx>
26 #include <cppuhelper/compbase.hxx>
27 #include <cppuhelper/basemutex.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/anytostring.hxx>
31 #include <cppuhelper/exc_hlp.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
37 #include <com/sun/star/presentation/SlideShow.hpp>
38 #include <com/sun/star/presentation/XSlideShowView.hpp>
39 #include "com/sun/star/animations/TransitionType.hpp"
40 #include "com/sun/star/animations/TransitionSubType.hpp"
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include <basegfx/matrix/b2dhommatrixtools.hxx>
44 #include <basegfx/utils/canvastools.hxx>
45 #include <basegfx/range/b2drectangle.hxx>
46 #include <basegfx/polygon/b2dpolygon.hxx>
47 #include <basegfx/polygon/b2dpolygontools.hxx>
49 #include <cppcanvas/vclfactory.hxx>
50 #include <cppcanvas/basegfxfactory.hxx>
51 #include <cppcanvas/polypolygon.hxx>
53 #include <canvas/canvastools.hxx>
55 #include <vcl/dialog.hxx>
56 #include <vcl/timer.hxx>
57 #include <vcl/window.hxx>
58 #include <vcl/svapp.hxx>
60 #include <stdio.h>
61 #include <unistd.h>
64 using namespace ::com::sun::star;
66 namespace {
68 typedef ::cppu::WeakComponentImplHelper< presentation::XSlideShowView > ViewBase;
69 class View : public ::cppu::BaseMutex,
70 public ViewBase
72 public:
73 explicit View( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) :
74 ViewBase( m_aMutex ),
75 mxCanvas( rCanvas ),
76 maPaintListeners( m_aMutex ),
77 maTransformationListeners( m_aMutex ),
78 maMouseListeners( m_aMutex ),
79 maMouseMotionListeners( m_aMutex ),
80 maTransform(),
81 maSize()
85 void resize( const ::Size& rNewSize )
87 maSize = rNewSize;
88 const sal_Int32 nSize( std::min( rNewSize.Width(), rNewSize.Height() ) - 10);
89 maTransform = basegfx::utils::createScaleTranslateB2DHomMatrix(
90 nSize, nSize, (rNewSize.Width() - nSize) / 2, (rNewSize.Height() - nSize) / 2);
92 lang::EventObject aEvent( *this );
93 maTransformationListeners.notifyEach( &util::XModifyListener::modified,
94 aEvent );
97 void repaint()
99 awt::PaintEvent aEvent( *this,
100 awt::Rectangle(),
101 0 );
102 maPaintListeners.notifyEach( &awt::XPaintListener::windowPaint,
103 aEvent );
106 private:
107 virtual ~View() {}
109 virtual uno::Reference< rendering::XSpriteCanvas > SAL_CALL getCanvas( ) throw (uno::RuntimeException)
111 return mxCanvas;
114 virtual void SAL_CALL clear( ) throw (uno::RuntimeException)
116 ::basegfx::B2DPolygon aPoly( ::basegfx::utils::createPolygonFromRect(
117 ::basegfx::B2DRectangle(0.0,0.0,
118 maSize.Width(),
119 maSize.Height() )));
120 ::cppcanvas::SpriteCanvasSharedPtr pCanvas(
121 ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( mxCanvas ));
122 if( !pCanvas )
123 return;
125 ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
126 ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( pCanvas,
127 aPoly ) );
128 if( !pPolyPoly )
129 return;
131 if( pPolyPoly )
133 pPolyPoly->setRGBAFillColor( 0x808080FFU );
134 pPolyPoly->draw();
138 virtual geometry::AffineMatrix2D SAL_CALL getTransformation( ) throw (uno::RuntimeException)
140 geometry::AffineMatrix2D aRes;
141 return basegfx::unotools::affineMatrixFromHomMatrix( aRes,
142 maTransform );
145 virtual void SAL_CALL addTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
147 maTransformationListeners.addInterface( xListener );
150 virtual void SAL_CALL removeTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
152 maTransformationListeners.removeInterface( xListener );
155 virtual void SAL_CALL addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
157 maPaintListeners.addInterface( xListener );
160 virtual void SAL_CALL removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
162 maPaintListeners.removeInterface( xListener );
165 virtual void SAL_CALL addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
167 maMouseListeners.addInterface( xListener );
170 virtual void SAL_CALL removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
172 maMouseListeners.removeInterface( xListener );
175 virtual void SAL_CALL addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
177 maMouseMotionListeners.addInterface( xListener );
180 virtual void SAL_CALL removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
182 maMouseMotionListeners.removeInterface( xListener );
185 virtual void SAL_CALL setMouseCursor( ::sal_Int16 /*nPointerShape*/ ) throw (uno::RuntimeException)
189 virtual awt::Rectangle SAL_CALL getCanvasArea( ) throw (uno::RuntimeException)
191 return awt::Rectangle(0,0,maSize.Width(),maSize.Height());
194 uno::Reference< rendering::XSpriteCanvas > mxCanvas;
195 ::comphelper::OInterfaceContainerHelper2 maPaintListeners;
196 ::comphelper::OInterfaceContainerHelper2 maTransformationListeners;
197 ::comphelper::OInterfaceContainerHelper2 maMouseListeners;
198 ::comphelper::OInterfaceContainerHelper2 maMouseMotionListeners;
199 basegfx::B2DHomMatrix maTransform;
200 Size maSize;
203 typedef ::cppu::WeakComponentImplHelper< drawing::XDrawPage,
204 beans::XPropertySet > SlideBase;
205 class DummySlide : public ::cppu::BaseMutex,
206 public SlideBase
208 public:
209 DummySlide() : SlideBase( m_aMutex ) {}
211 private:
212 // XDrawPage
213 virtual void SAL_CALL add( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
217 virtual void SAL_CALL remove( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
221 virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
223 return 0;
226 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
228 return uno::Any();
231 virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
233 return uno::Type();
236 virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
238 return false;
241 // XPropertySet
242 virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (uno::RuntimeException)
244 return uno::Reference< beans::XPropertySetInfo >();
247 virtual void SAL_CALL setPropertyValue( const OUString& /*aPropertyName*/,
248 const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
252 virtual uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
254 typedef ::canvas::tools::ValueMap< sal_Int16 > PropMapT;
256 // fixed PropertyValue map
257 static const PropMapT::MapEntry lcl_propertyMap[] =
259 {"Height", 100},
260 {"MinimalFrameNumber", 50},
261 {"TransitionDuration", 10},
262 {"TransitionSubtype", animations::TransitionSubType::FROMTOPLEFT},
263 {"TransitionType", animations::TransitionType::PUSHWIPE},
264 {"Width", 100}
267 static const PropMapT aMap( lcl_propertyMap,
268 SAL_N_ELEMENTS(lcl_propertyMap),
269 true );
271 sal_Int16 aRes;
272 if( !aMap.lookup( PropertyName, aRes ))
273 return uno::Any();
275 return uno::makeAny(aRes);
278 virtual void SAL_CALL addPropertyChangeListener( const OUString& /*aPropertyName*/,
279 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
283 virtual void SAL_CALL removePropertyChangeListener( const OUString& /*aPropertyName*/,
284 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
288 virtual void SAL_CALL addVetoableChangeListener( const OUString& /*PropertyName*/,
289 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
293 virtual void SAL_CALL removeVetoableChangeListener( const OUString& /*PropertyName*/,
294 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
300 class DemoApp : public Application
302 public:
303 virtual void Main();
304 virtual void Exception( ExceptionCategory nCategory );
307 class ChildWindow : public vcl::Window
309 public:
310 explicit ChildWindow( vcl::Window* pParent );
311 virtual ~ChildWindow();
312 virtual void Paint( const Rectangle& rRect );
313 virtual void Resize();
315 void setShow( const uno::Reference< presentation::XSlideShow >& rShow ) { mxShow = rShow; init(); }
317 private:
318 void init();
320 rtl::Reference< View > mpView;
321 uno::Reference< presentation::XSlideShow > mxShow;
324 ChildWindow::ChildWindow( vcl::Window* pParent ) :
325 Window(pParent, WB_CLIPCHILDREN | WB_BORDER| WB_3DLOOK ),
326 mpView(),
327 mxShow()
329 EnablePaint( true );
330 Show();
333 ChildWindow::~ChildWindow()
335 if( mxShow.is() && mpView.is() )
336 mxShow->removeView( mpView.get() );
339 void ChildWindow::init()
343 if( !mpView.is() )
345 uno::Reference< rendering::XCanvas > xCanvas( GetCanvas(),
346 uno::UNO_QUERY_THROW );
347 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
348 uno::UNO_QUERY_THROW );
349 mpView = new View( xSpriteCanvas );
350 mpView->resize( GetSizePixel() );
352 if( mxShow.is() )
353 mxShow->addView( mpView.get() );
356 catch (const uno::Exception &e)
358 SAL_INFO("slideshow", e );
362 void ChildWindow::Paint( const Rectangle& /*rRect*/ )
366 if( mpView.is() )
367 mpView->repaint();
369 catch (const uno::Exception &e)
371 SAL_INFO("slideshow", e );
375 void ChildWindow::Resize()
377 if( mpView.is() )
378 mpView->resize( GetSizePixel() );
381 class DemoWindow : public Dialog
383 public:
384 DemoWindow();
385 virtual void Paint( const Rectangle& rRect );
386 virtual void Resize();
388 private:
389 void init();
390 DECL_LINK( updateHdl, Timer*, void );
392 ChildWindow maLeftChild;
393 ChildWindow maRightTopChild;
394 ChildWindow maRightBottomChild;
395 uno::Reference< presentation::XSlideShow > mxShow;
396 AutoTimer maUpdateTimer;
397 bool mbSlideDisplayed;
400 DemoWindow::DemoWindow() :
401 Dialog((vcl::Window*)NULL),
402 maLeftChild( this ),
403 maRightTopChild( this ),
404 maRightBottomChild( this ),
405 mxShow(),
406 maUpdateTimer(),
407 mbSlideDisplayed( false )
409 SetText( OUString("Slideshow Demo" ) );
410 SetSizePixel( Size( 640, 480 ) );
411 EnablePaint( true );
413 maLeftChild.SetPosSizePixel( Point(), Size(320,480) );
414 maRightTopChild.SetPosSizePixel( Point(320,0), Size(320,240) );
415 maRightBottomChild.SetPosSizePixel( Point(320,240), Size(320,240) );
416 Show();
418 maUpdateTimer.SetInvokeHandler(LINK(this, DemoWindow, updateHdl));
419 maUpdateTimer.SetTimeout( (sal_uLong)30 );
420 maUpdateTimer.Start();
423 void DemoWindow::init()
427 if( !mxShow.is() )
429 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
431 mxShow.set( presentation::SlideShow::create(xContext),
432 uno::UNO_QUERY_THROW );
434 maLeftChild.setShow( mxShow );
435 maRightTopChild.setShow( mxShow );
436 maRightBottomChild.setShow( mxShow );
439 if( mxShow.is() && !mbSlideDisplayed )
441 uno::Reference< drawing::XDrawPage > xSlide( new DummySlide );
442 uno::Reference< drawing::XDrawPages > xDrawPages;
443 mxShow->displaySlide( xSlide,
444 uno::Reference< drawing::XDrawPagesSupplier >(),
445 uno::Reference< animations::XAnimationNode >(),
446 uno::Sequence< beans::PropertyValue >() );
447 mxShow->setProperty( beans::PropertyValue(
448 OUString("RehearseTimings"),
450 uno::makeAny( sal_True ),
451 beans::PropertyState_DIRECT_VALUE ));
452 mbSlideDisplayed = true;
455 catch (const uno::Exception &e)
457 SAL_INFO("slideshow", e );
461 IMPL_LINK_NOARG(DemoWindow, updateHdl, Timer*, void)
463 init();
465 if( mxShow.is() )
466 mxShow->update(0);
469 void DemoWindow::Paint( const Rectangle& /*rRect*/ )
471 init();
474 void DemoWindow::Resize()
476 // TODO
479 void DemoApp::Exception( ExceptionCategory nCategory )
481 switch( nCategory )
483 case ExceptionCategory::ResourceNotLoaded:
484 Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
485 break;
489 void DemoApp::Main()
491 bool bHelp = false;
493 for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
495 OUString aParam = GetCommandLineParam( i );
497 if( aParam == "--help" || aParam == "-h" )
498 bHelp = true;
501 if( bHelp )
503 printf( "demoshow - life Slideshow testbed\n" );
504 return;
507 // bootstrap UNO
508 uno::Reference< lang::XMultiServiceFactory > xFactory;
511 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
512 xFactory.set( xCtx->getServiceManager(), uno::UNO_QUERY );
513 if( xFactory.is() )
514 ::comphelper::setProcessServiceFactory( xFactory );
516 catch( uno::RuntimeException& )
518 throw;
520 catch( uno::Exception& )
522 SAL_WARN( "slideshow", comphelper::anyToString( cppu::getCaughtException() ) );
525 if( !xFactory.is() )
527 SAL_INFO("slideshow", "Could not bootstrap UNO, installation must be in disorder. Exiting." );
528 exit( 1 );
531 DemoWindow pWindow;
532 pWindow.Execute();
536 DemoApp aApp;
538 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */