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