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