fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / test / demoshow.cxx
blobdd4ee48c7330ff4be6205a8645979acd3b7aafd9
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/compbase1.hxx>
27 #include <cppuhelper/compbase2.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/broadcasthelper.hxx>
31 #include <comphelper/anytostring.hxx>
32 #include <cppuhelper/exc_hlp.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/rendering/XCanvas.hpp>
37 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
38 #include <com/sun/star/presentation/SlideShow.hpp>
39 #include <com/sun/star/presentation/XSlideShowView.hpp>
40 #include "com/sun/star/animations/TransitionType.hpp"
41 #include "com/sun/star/animations/TransitionSubType.hpp"
43 #include <basegfx/matrix/b2dhommatrix.hxx>
44 #include <basegfx/matrix/b2dhommatrixtools.hxx>
45 #include <basegfx/tools/canvastools.hxx>
46 #include <basegfx/range/b2drectangle.hxx>
47 #include <basegfx/polygon/b2dpolygon.hxx>
48 #include <basegfx/polygon/b2dpolygontools.hxx>
50 #include <cppcanvas/vclfactory.hxx>
51 #include <cppcanvas/basegfxfactory.hxx>
52 #include <cppcanvas/polypolygon.hxx>
54 #include <canvas/canvastools.hxx>
56 #include <vcl/dialog.hxx>
57 #include <vcl/timer.hxx>
58 #include <vcl/window.hxx>
59 #include <vcl/svapp.hxx>
61 #include <stdio.h>
62 #include <unistd.h>
65 using namespace ::com::sun::star;
67 namespace {
69 typedef ::cppu::WeakComponentImplHelper1< presentation::XSlideShowView > ViewBase;
70 class View : public ::comphelper::OBaseMutex,
71 public ViewBase
73 public:
74 explicit View( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) :
75 ViewBase( m_aMutex ),
76 mxCanvas( rCanvas ),
77 maPaintListeners( m_aMutex ),
78 maTransformationListeners( m_aMutex ),
79 maMouseListeners( m_aMutex ),
80 maMouseMotionListeners( m_aMutex ),
81 maTransform(),
82 maSize()
86 void resize( const ::Size& rNewSize )
88 maSize = rNewSize;
89 const sal_Int32 nSize( std::min( rNewSize.Width(), rNewSize.Height() ) - 10);
90 maTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
91 nSize, nSize, (rNewSize.Width() - nSize) / 2, (rNewSize.Height() - nSize) / 2);
93 lang::EventObject aEvent( *this );
94 maTransformationListeners.notifyEach( &util::XModifyListener::modified,
95 aEvent );
98 void repaint()
100 awt::PaintEvent aEvent( *this,
101 awt::Rectangle(),
102 0 );
103 maPaintListeners.notifyEach( &awt::XPaintListener::windowPaint,
104 aEvent );
107 private:
108 virtual ~View() {}
110 virtual uno::Reference< rendering::XSpriteCanvas > SAL_CALL getCanvas( ) throw (uno::RuntimeException)
112 return mxCanvas;
115 virtual void SAL_CALL clear( ) throw (uno::RuntimeException)
117 ::basegfx::B2DPolygon aPoly( ::basegfx::tools::createPolygonFromRect(
118 ::basegfx::B2DRectangle(0.0,0.0,
119 maSize.Width(),
120 maSize.Height() )));
121 ::cppcanvas::SpriteCanvasSharedPtr pCanvas(
122 ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( mxCanvas ));
123 if( !pCanvas )
124 return;
126 ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
127 ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( pCanvas,
128 aPoly ) );
129 if( !pPolyPoly )
130 return;
132 if( pPolyPoly )
134 pPolyPoly->setRGBAFillColor( 0x808080FFU );
135 pPolyPoly->draw();
139 virtual geometry::AffineMatrix2D SAL_CALL getTransformation( ) throw (uno::RuntimeException)
141 geometry::AffineMatrix2D aRes;
142 return basegfx::unotools::affineMatrixFromHomMatrix( aRes,
143 maTransform );
146 virtual void SAL_CALL addTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
148 maTransformationListeners.addInterface( xListener );
151 virtual void SAL_CALL removeTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
153 maTransformationListeners.removeInterface( xListener );
156 virtual void SAL_CALL addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
158 maPaintListeners.addInterface( xListener );
161 virtual void SAL_CALL removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
163 maPaintListeners.removeInterface( xListener );
166 virtual void SAL_CALL addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
168 maMouseListeners.addInterface( xListener );
171 virtual void SAL_CALL removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
173 maMouseListeners.removeInterface( xListener );
176 virtual void SAL_CALL addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
178 maMouseMotionListeners.addInterface( xListener );
181 virtual void SAL_CALL removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
183 maMouseMotionListeners.removeInterface( xListener );
186 virtual void SAL_CALL setMouseCursor( ::sal_Int16 /*nPointerShape*/ ) throw (uno::RuntimeException)
190 virtual awt::Rectangle SAL_CALL getCanvasArea( ) throw (uno::RuntimeException)
192 return awt::Rectangle(0,0,maSize.Width(),maSize.Height());
195 uno::Reference< rendering::XSpriteCanvas > mxCanvas;
196 ::cppu::OInterfaceContainerHelper maPaintListeners;
197 ::cppu::OInterfaceContainerHelper maTransformationListeners;
198 ::cppu::OInterfaceContainerHelper maMouseListeners;
199 ::cppu::OInterfaceContainerHelper maMouseMotionListeners;
200 basegfx::B2DHomMatrix maTransform;
201 Size maSize;
204 typedef ::cppu::WeakComponentImplHelper2< drawing::XDrawPage,
205 beans::XPropertySet > SlideBase;
206 class DummySlide : public ::comphelper::OBaseMutex,
207 public SlideBase
209 public:
210 DummySlide() : SlideBase( m_aMutex ) {}
212 private:
213 // XDrawPage
214 virtual void SAL_CALL add( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
218 virtual void SAL_CALL remove( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
222 virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
224 return 0;
227 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
229 return uno::Any();
232 virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
234 return uno::Type();
237 virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
239 return false;
242 // XPropertySet
243 virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (uno::RuntimeException)
245 return uno::Reference< beans::XPropertySetInfo >();
248 virtual void SAL_CALL setPropertyValue( const OUString& /*aPropertyName*/,
249 const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
253 virtual uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
255 typedef ::canvas::tools::ValueMap< sal_Int16 > PropMapT;
257 // fixed PropertyValue map
258 static const PropMapT::MapEntry lcl_propertyMap[] =
260 {"Height", 100},
261 {"MinimalFrameNumber", 50},
262 {"TransitionDuration", 10},
263 {"TransitionSubtype", animations::TransitionSubType::FROMTOPLEFT},
264 {"TransitionType", animations::TransitionType::PUSHWIPE},
265 {"Width", 100}
268 static const PropMapT aMap( lcl_propertyMap,
269 SAL_N_ELEMENTS(lcl_propertyMap),
270 true );
272 sal_Int16 aRes;
273 if( !aMap.lookup( PropertyName, aRes ))
274 return uno::Any();
276 return uno::makeAny(aRes);
279 virtual void SAL_CALL addPropertyChangeListener( const OUString& /*aPropertyName*/,
280 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
284 virtual void SAL_CALL removePropertyChangeListener( const OUString& /*aPropertyName*/,
285 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
289 virtual void SAL_CALL addVetoableChangeListener( const OUString& /*PropertyName*/,
290 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
294 virtual void SAL_CALL removeVetoableChangeListener( const OUString& /*PropertyName*/,
295 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
301 class DemoApp : public Application
303 public:
304 virtual void Main();
305 virtual sal_uInt16 Exception( sal_uInt16 nError );
308 class ChildWindow : public vcl::Window
310 public:
311 ChildWindow( vcl::Window* pParent );
312 virtual ~ChildWindow();
313 virtual void Paint( const Rectangle& rRect );
314 virtual void Resize();
316 void setShow( const uno::Reference< presentation::XSlideShow >& rShow ) { mxShow = rShow; init(); }
318 private:
319 void init();
321 rtl::Reference< View > mpView;
322 uno::Reference< presentation::XSlideShow > mxShow;
325 ChildWindow::ChildWindow( vcl::Window* pParent ) :
326 Window(pParent, WB_CLIPCHILDREN | WB_BORDER| WB_3DLOOK ),
327 mpView(),
328 mxShow()
330 EnablePaint( true );
331 Show();
334 ChildWindow::~ChildWindow()
336 if( mxShow.is() && mpView.is() )
337 mxShow->removeView( mpView.get() );
340 void ChildWindow::init()
344 if( !mpView.is() )
346 uno::Reference< rendering::XCanvas > xCanvas( GetCanvas(),
347 uno::UNO_QUERY_THROW );
348 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
349 uno::UNO_QUERY_THROW );
350 mpView = new View( xSpriteCanvas );
351 mpView->resize( GetSizePixel() );
353 if( mxShow.is() )
354 mxShow->addView( mpView.get() );
357 catch (const uno::Exception &e)
359 OSL_TRACE( "Exception '%s' thrown\n" ,
360 OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
364 void ChildWindow::Paint( const Rectangle& /*rRect*/ )
368 if( mpView.is() )
369 mpView->repaint();
371 catch (const uno::Exception &e)
373 OSL_TRACE( "Exception '%s' thrown\n" ,
374 OUStringToOString( e.Message,
375 RTL_TEXTENCODING_UTF8 ).getStr() );
379 void ChildWindow::Resize()
381 if( mpView.is() )
382 mpView->resize( GetSizePixel() );
385 class DemoWindow : public Dialog
387 public:
388 DemoWindow();
389 virtual void Paint( const Rectangle& rRect );
390 virtual void Resize();
392 private:
393 void init();
394 DECL_LINK( updateHdl, Timer* );
396 ChildWindow maLeftChild;
397 ChildWindow maRightTopChild;
398 ChildWindow maRightBottomChild;
399 uno::Reference< presentation::XSlideShow > mxShow;
400 AutoTimer maUpdateTimer;
401 bool mbSlideDisplayed;
404 DemoWindow::DemoWindow() :
405 Dialog((vcl::Window*)NULL),
406 maLeftChild( this ),
407 maRightTopChild( this ),
408 maRightBottomChild( this ),
409 mxShow(),
410 maUpdateTimer(),
411 mbSlideDisplayed( false )
413 SetText( OUString("Slideshow Demo" ) );
414 SetSizePixel( Size( 640, 480 ) );
415 EnablePaint( true );
417 maLeftChild.SetPosSizePixel( Point(), Size(320,480) );
418 maRightTopChild.SetPosSizePixel( Point(320,0), Size(320,240) );
419 maRightBottomChild.SetPosSizePixel( Point(320,240), Size(320,240) );
420 Show();
422 maUpdateTimer.SetTimeoutHdl(LINK(this, DemoWindow, updateHdl));
423 maUpdateTimer.SetTimeout( (sal_uLong)30 );
424 maUpdateTimer.Start();
427 void DemoWindow::init()
431 if( !mxShow.is() )
433 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
435 mxShow.set( presentation::SlideShow::create(xContext),
436 uno::UNO_QUERY_THROW );
438 maLeftChild.setShow( mxShow );
439 maRightTopChild.setShow( mxShow );
440 maRightBottomChild.setShow( mxShow );
443 if( mxShow.is() && !mbSlideDisplayed )
445 uno::Reference< drawing::XDrawPage > xSlide( new DummySlide );
446 uno::Reference< drawing::XDrawPages > xDrawPages;
447 mxShow->displaySlide( xSlide,
448 uno::Reference< drawing::XDrawPagesSupplier >(),
449 uno::Reference< animations::XAnimationNode >(),
450 uno::Sequence< beans::PropertyValue >() );
451 mxShow->setProperty( beans::PropertyValue(
452 OUString("RehearseTimings"),
454 uno::makeAny( sal_True ),
455 beans::PropertyState_DIRECT_VALUE ));
456 mbSlideDisplayed = true;
459 catch (const uno::Exception &e)
461 OSL_TRACE( "Exception '%s' thrown\n" ,
462 OUStringToOString( e.Message,
463 RTL_TEXTENCODING_UTF8 ).getStr() );
467 IMPL_LINK_NOARG(DemoWindow, updateHdl)
469 init();
471 if( mxShow.is() )
472 mxShow->update(0);
473 return 0;
476 void DemoWindow::Paint( const Rectangle& /*rRect*/ )
478 init();
481 void DemoWindow::Resize()
483 // TODO
486 sal_uInt16 DemoApp::Exception( sal_uInt16 nError )
488 switch( nError & EXC_MAJORTYPE )
490 case EXC_RSCNOTLOADED:
491 Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
492 break;
494 return 0;
497 void DemoApp::Main()
499 bool bHelp = false;
501 for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
503 OUString aParam = GetCommandLineParam( i );
505 if( aParam == "--help" || aParam == "-h" )
506 bHelp = true;
509 if( bHelp )
511 printf( "demoshow - life Slideshow testbed\n" );
512 return;
515 // bootstrap UNO
516 uno::Reference< lang::XMultiServiceFactory > xFactory;
519 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
520 xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
521 uno::UNO_QUERY );
522 if( xFactory.is() )
523 ::comphelper::setProcessServiceFactory( xFactory );
525 catch( uno::RuntimeException& )
527 throw;
529 catch( uno::Exception& )
531 OSL_FAIL( OUStringToOString(
532 comphelper::anyToString( cppu::getCaughtException() ),
533 RTL_TEXTENCODING_UTF8 ).getStr() );
536 if( !xFactory.is() )
538 OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting." );
539 exit( 1 );
542 DemoWindow pWindow;
543 pWindow.Execute();
547 DemoApp aApp;
549 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */