bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / slideshow / slideshow.cxx
blob5213724c0cdcf35a1aefde8692c7d11a7bf31b71
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 .
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
23 #include <com/sun/star/container/XIndexAccess.hpp>
24 #include <comphelper/serviceinfohelper.hxx>
25 #include <com/sun/star/frame/XDispatchProvider.hpp>
26 #include <com/sun/star/util/URL.hpp>
28 #include <cppuhelper/bootstrap.hxx>
30 #include <comphelper/processfactory.hxx>
31 #include <osl/mutex.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/wrkwin.hxx>
35 #include <svx/svdpool.hxx>
36 #include <svl/itemprop.hxx>
38 #include <sfx2/viewfrm.hxx>
40 #include <toolkit/unohlp.hxx>
41 #include <svx/unoprov.hxx>
43 #include "framework/FrameworkHelper.hxx"
45 #include "FrameView.hxx"
46 #include "unomodel.hxx"
47 #include "slideshow.hxx"
48 #include "slideshowimpl.hxx"
49 #include "sdattr.hrc"
50 #include "FactoryIds.hxx"
51 #include "ViewShell.hxx"
52 #include "SlideShowRestarter.hxx"
53 #include "DrawController.hxx"
54 #include "customshowlist.hxx"
55 #include <boost/bind.hpp>
57 using ::com::sun::star::presentation::XSlideShowController;
58 using ::com::sun::star::container::XIndexAccess;
59 using ::sd::framework::FrameworkHelper;
60 using ::com::sun::star::awt::XWindow;
61 using namespace ::sd;
62 using namespace ::cppu;
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::drawing;
66 using namespace ::com::sun::star::beans;
67 using namespace ::com::sun::star::lang;
68 using namespace ::com::sun::star::animations;
69 using namespace ::com::sun::star::drawing::framework;
71 extern String getUiNameFromPageApiNameImpl( const OUString& rApiName );
74 namespace {
75 /** This local version of the work window overloads DataChanged() so that it
76 can restart the slide show when a display is added or removed.
78 class FullScreenWorkWindow : public WorkWindow
80 public:
81 FullScreenWorkWindow (
82 const ::rtl::Reference<SlideShow>& rpSlideShow,
83 ViewShellBase* pViewShellBase)
84 : WorkWindow(NULL, WB_HIDE | WB_CLIPCHILDREN),
85 mpRestarter(new SlideShowRestarter(rpSlideShow, pViewShellBase))
88 void Restart(bool bForce)
90 mpRestarter->Restart(bForce);
93 virtual void DataChanged (const DataChangedEvent& rEvent)
95 if (rEvent.GetType() == DATACHANGED_DISPLAY)
96 Restart(false);
99 private:
100 ::boost::shared_ptr<SlideShowRestarter> mpRestarter;
105 //////////////////////////////////////////////////////////////////////////////
106 // --------------------------------------------------------------------
108 const SfxItemPropertyMapEntry* ImplGetPresentationPropertyMap()
110 // NOTE: First member must be sorted
111 static const SfxItemPropertyMapEntry aPresentationPropertyMap_Impl[] =
113 { MAP_CHAR_LEN("AllowAnimations"), ATTR_PRESENT_ANIMATION_ALLOWED, &::getBooleanCppuType(), 0, 0 },
114 { MAP_CHAR_LEN("CustomShow"), ATTR_PRESENT_CUSTOMSHOW, &::getCppuType((const OUString*)0), 0, 0 },
115 { MAP_CHAR_LEN("Display"), ATTR_PRESENT_DISPLAY, &::getCppuType((const sal_Int32*)0), 0, 0 },
116 { MAP_CHAR_LEN("FirstPage"), ATTR_PRESENT_DIANAME, &::getCppuType((const OUString*)0), 0, 0 },
117 { MAP_CHAR_LEN("IsAlwaysOnTop"), ATTR_PRESENT_ALWAYS_ON_TOP, &::getBooleanCppuType(), 0, 0 },
118 { MAP_CHAR_LEN("IsAutomatic"), ATTR_PRESENT_MANUEL, &::getBooleanCppuType(), 0, 0 },
119 { MAP_CHAR_LEN("IsEndless"), ATTR_PRESENT_ENDLESS, &::getBooleanCppuType(), 0, 0 },
120 { MAP_CHAR_LEN("IsFullScreen"), ATTR_PRESENT_FULLSCREEN, &::getBooleanCppuType(), 0, 0 },
121 { MAP_CHAR_LEN("IsShowAll"), ATTR_PRESENT_ALL, &::getBooleanCppuType(), 0, 0 },
122 { MAP_CHAR_LEN("IsMouseVisible"), ATTR_PRESENT_MOUSE, &::getBooleanCppuType(), 0, 0 },
123 { MAP_CHAR_LEN("IsShowLogo"), ATTR_PRESENT_SHOW_PAUSELOGO, &::getBooleanCppuType(), 0, 0 },
124 { MAP_CHAR_LEN("IsTransitionOnClick"), ATTR_PRESENT_CHANGE_PAGE, &::getBooleanCppuType(), 0, 0 },
125 { MAP_CHAR_LEN("Pause"), ATTR_PRESENT_PAUSE_TIMEOUT, &::getCppuType((const sal_Int32*)0), 0, 0 },
126 { MAP_CHAR_LEN("StartWithNavigator"), ATTR_PRESENT_NAVIGATOR, &::getBooleanCppuType(), 0, 0 },
127 { MAP_CHAR_LEN("UsePen"), ATTR_PRESENT_PEN, &::getBooleanCppuType(), 0, 0 },
128 { 0,0,0,0,0,0}
131 return aPresentationPropertyMap_Impl;
134 // --------------------------------------------------------------------
135 // class SlideShow
136 // --------------------------------------------------------------------
138 SlideShow::SlideShow( SdDrawDocument* pDoc )
139 : SlideshowBase( m_aMutex )
140 , maPropSet(ImplGetPresentationPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool())
141 , mbIsInStartup(false)
142 , mpDoc( pDoc )
143 , mpCurrentViewShellBase( 0 )
144 , mpFullScreenViewShellBase( 0 )
145 , mpFullScreenFrameView( 0 )
146 , mnInPlaceConfigEvent( 0 )
150 // --------------------------------------------------------------------
152 void SlideShow::ThrowIfDisposed() throw (RuntimeException)
154 if( mpDoc == 0 )
155 throw DisposedException();
158 // --------------------------------------------------------------------
160 /// used by the model to create a slideshow for it
161 rtl::Reference< SlideShow > SlideShow::Create( SdDrawDocument* pDoc )
163 return new SlideShow( pDoc );
166 // --------------------------------------------------------------------
168 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument* pDocument )
170 rtl::Reference< SlideShow > xRet;
172 if( pDocument )
173 xRet = GetSlideShow( *pDocument );
175 return xRet;
178 // --------------------------------------------------------------------
180 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument& rDocument )
182 return rtl::Reference< SlideShow >(
183 dynamic_cast< SlideShow* >( rDocument.getPresentation().get() ) );
186 // --------------------------------------------------------------------
188 rtl::Reference< SlideShow > SlideShow::GetSlideShow( ViewShellBase& rBase )
190 return GetSlideShow( rBase.GetDocument() );
193 // --------------------------------------------------------------------
195 ::com::sun::star::uno::Reference< ::com::sun::star::presentation::XSlideShowController > SlideShow::GetSlideShowController(ViewShellBase& rBase )
197 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
199 Reference< XSlideShowController > xRet;
200 if( xSlideShow.is() )
201 xRet = xSlideShow->getController();
203 return xRet;
206 // --------------------------------------------------------------------
208 bool SlideShow::StartPreview( ViewShellBase& rBase,
209 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xDrawPage,
210 const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xAnimationNode,
211 ::Window* pParent /* = 0 */ )
213 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
214 if( xSlideShow.is() )
215 return xSlideShow->startPreview( xDrawPage, xAnimationNode, pParent );
217 return false;
220 // --------------------------------------------------------------------
222 void SlideShow::Stop( ViewShellBase& rBase )
224 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
225 if( xSlideShow.is() )
226 xSlideShow->end();
229 // --------------------------------------------------------------------
231 bool SlideShow::IsRunning( ViewShellBase& rBase )
233 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
234 return xSlideShow.is() && xSlideShow->isRunning();
237 // --------------------------------------------------------------------
239 bool SlideShow::IsRunning( ViewShell& rViewShell )
241 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rViewShell.GetViewShellBase() ) );
242 return xSlideShow.is() && xSlideShow->isRunning() && (xSlideShow->mxController->getViewShell() == &rViewShell);
245 // --------------------------------------------------------------------
247 void SlideShow::CreateController( ViewShell* pViewSh, ::sd::View* pView, ::Window* pParentWindow )
249 DBG_ASSERT( !mxController.is(), "sd::SlideShow::CreateController(), clean up old controller first!" );
251 Reference< XPresentation2 > xThis( this );
253 rtl::Reference<SlideshowImpl> xController (
254 new SlideshowImpl(xThis, pViewSh, pView, mpDoc, pParentWindow));
256 // Reset mbIsInStartup. From here mxController.is() is used to prevent
257 // multiple slide show instances for one document.
258 mxController = xController;
259 mbIsInStartup = false;
263 // --------------------------------------------------------------------
264 // XServiceInfo
265 // --------------------------------------------------------------------
267 OUString SAL_CALL SlideShow::getImplementationName( ) throw(RuntimeException)
269 return OUString( "com.sun.star.comp.sd.SlideShow" );
272 // --------------------------------------------------------------------
274 sal_Bool SAL_CALL SlideShow::supportsService( const OUString& ServiceName ) throw(RuntimeException)
276 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames( ) );
279 // --------------------------------------------------------------------
281 Sequence< OUString > SAL_CALL SlideShow::getSupportedServiceNames( ) throw(RuntimeException)
283 OUString aService( "com.sun.star.presentation.Presentation" );
284 Sequence< OUString > aSeq( &aService, 1 );
285 return aSeq;
288 // --------------------------------------------------------------------
289 // XPropertySet
290 // --------------------------------------------------------------------
292 Reference< XPropertySetInfo > SAL_CALL SlideShow::getPropertySetInfo() throw(RuntimeException)
294 SolarMutexGuard aGuard;
295 static Reference< XPropertySetInfo > xInfo = maPropSet.getPropertySetInfo();
296 return xInfo;
299 // --------------------------------------------------------------------
301 void SAL_CALL SlideShow::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
303 SolarMutexGuard aGuard;
304 ThrowIfDisposed();
306 sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
308 const SfxItemPropertySimpleEntry* pEntry = maPropSet.getPropertyMapEntry(aPropertyName);
310 if( pEntry && ((pEntry->nFlags & PropertyAttribute::READONLY) != 0) )
311 throw PropertyVetoException();
313 bool bValuesChanged = false;
314 bool bIllegalArgument = true;
316 switch( pEntry ? pEntry->nWID : -1 )
318 case ATTR_PRESENT_ALL:
320 sal_Bool bVal = sal_False;
322 if( aValue >>= bVal )
324 bIllegalArgument = false;
326 if( rPresSettings.mbAll != bVal )
328 rPresSettings.mbAll = bVal;
329 bValuesChanged = true;
330 if( bVal )
331 rPresSettings.mbCustomShow = sal_False;
334 break;
336 case ATTR_PRESENT_CHANGE_PAGE:
338 sal_Bool bVal = sal_False;
340 if( aValue >>= bVal )
342 bIllegalArgument = false;
344 if( bVal == rPresSettings.mbLockedPages )
346 bValuesChanged = true;
347 rPresSettings.mbLockedPages = !bVal;
350 break;
353 case ATTR_PRESENT_ANIMATION_ALLOWED:
355 sal_Bool bVal = sal_False;
357 if( aValue >>= bVal )
359 bIllegalArgument = false;
361 if(rPresSettings.mbAnimationAllowed != bVal)
363 bValuesChanged = true;
364 rPresSettings.mbAnimationAllowed = bVal;
367 break;
369 case ATTR_PRESENT_CUSTOMSHOW:
371 OUString aShow;
372 if( aValue >>= aShow )
374 bIllegalArgument = false;
376 const String aShowName( aShow );
378 SdCustomShowList* pCustomShowList = mpDoc->GetCustomShowList(sal_False);
379 if(pCustomShowList)
381 SdCustomShow* pCustomShow;
382 for( pCustomShow = pCustomShowList->First(); pCustomShow != NULL; pCustomShow = pCustomShowList->Next() )
384 if( pCustomShow->GetName() == aShowName )
385 break;
388 rPresSettings.mbCustomShow = sal_True;
389 bValuesChanged = true;
392 break;
394 case ATTR_PRESENT_ENDLESS:
396 sal_Bool bVal = sal_False;
398 if( aValue >>= bVal )
400 bIllegalArgument = false;
402 if( rPresSettings.mbEndless != bVal)
404 bValuesChanged = true;
405 rPresSettings.mbEndless = bVal;
408 break;
410 case ATTR_PRESENT_FULLSCREEN:
412 sal_Bool bVal = sal_False;
414 if( aValue >>= bVal )
416 bIllegalArgument = false;
417 if( rPresSettings.mbFullScreen != bVal)
419 bValuesChanged = true;
420 rPresSettings.mbFullScreen = bVal;
423 break;
425 case ATTR_PRESENT_DIANAME:
427 OUString aPresPage;
428 aValue >>= aPresPage;
429 bIllegalArgument = false;
430 if( (rPresSettings.maPresPage != aPresPage) || !rPresSettings.mbCustomShow || !rPresSettings.mbAll )
432 bValuesChanged = true;
433 rPresSettings.maPresPage = getUiNameFromPageApiNameImpl(aPresPage);
434 rPresSettings.mbCustomShow = sal_False;
435 rPresSettings.mbAll = sal_False;
437 break;
439 case ATTR_PRESENT_MANUEL:
441 sal_Bool bVal = sal_False;
443 if( aValue >>= bVal )
445 bIllegalArgument = false;
447 if( rPresSettings.mbManual != bVal)
449 bValuesChanged = true;
450 rPresSettings.mbManual = bVal;
453 break;
455 case ATTR_PRESENT_MOUSE:
457 sal_Bool bVal = sal_False;
459 if( aValue >>= bVal )
461 bIllegalArgument = false;
462 if( rPresSettings.mbMouseVisible != bVal)
464 bValuesChanged = true;
465 rPresSettings.mbMouseVisible = bVal;
468 break;
470 case ATTR_PRESENT_ALWAYS_ON_TOP:
472 sal_Bool bVal = sal_False;
474 if( aValue >>= bVal )
476 bIllegalArgument = false;
478 if( rPresSettings.mbAlwaysOnTop != bVal)
480 bValuesChanged = true;
481 rPresSettings.mbAlwaysOnTop = bVal;
484 break;
486 case ATTR_PRESENT_NAVIGATOR:
488 sal_Bool bVal = sal_False;
490 if( aValue >>= bVal )
492 bIllegalArgument = false;
494 if( rPresSettings.mbStartWithNavigator != bVal)
496 bValuesChanged = true;
497 rPresSettings.mbStartWithNavigator = bVal;
500 break;
502 case ATTR_PRESENT_PEN:
504 sal_Bool bVal = sal_False;
506 if( aValue >>= bVal )
508 bIllegalArgument = false;
510 if(rPresSettings.mbMouseAsPen != bVal)
512 bValuesChanged = true;
513 rPresSettings.mbMouseAsPen = bVal;
516 break;
518 case ATTR_PRESENT_PAUSE_TIMEOUT:
520 sal_Int32 nValue = 0;
521 if( (aValue >>= nValue) && (nValue >= 0) )
523 bIllegalArgument = false;
524 if( rPresSettings.mnPauseTimeout != nValue )
526 bValuesChanged = true;
527 rPresSettings.mnPauseTimeout = nValue;
530 break;
532 case ATTR_PRESENT_SHOW_PAUSELOGO:
534 sal_Bool bVal = sal_False;
536 if( aValue >>= bVal )
538 bIllegalArgument = false;
540 if( rPresSettings.mbShowPauseLogo != bVal )
542 bValuesChanged = true;
543 rPresSettings.mbShowPauseLogo = bVal;
546 break;
548 case ATTR_PRESENT_DISPLAY:
550 sal_Int32 nDisplay = 0;
551 if( aValue >>= nDisplay )
553 bIllegalArgument = false;
555 SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
556 pOptions->SetDisplay( nDisplay );
558 FullScreenWorkWindow *pWin = dynamic_cast<FullScreenWorkWindow *>(GetWorkWindow());
559 if( !pWin )
560 return;
561 pWin->Restart(true);
563 break;
566 default:
567 throw UnknownPropertyException();
570 if( bIllegalArgument )
571 throw IllegalArgumentException();
573 if( bValuesChanged )
574 mpDoc->SetChanged( true );
577 // --------------------------------------------------------------------
579 Any SAL_CALL SlideShow::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
581 SolarMutexGuard aGuard;
582 ThrowIfDisposed();
584 const sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
586 const SfxItemPropertySimpleEntry* pEntry = maPropSet.getPropertyMapEntry(PropertyName);
588 switch( pEntry ? pEntry->nWID : -1 )
590 case ATTR_PRESENT_ALL:
591 return Any( (sal_Bool) ( !rPresSettings.mbCustomShow && rPresSettings.mbAll ) );
592 case ATTR_PRESENT_CHANGE_PAGE:
593 return Any( (sal_Bool) !rPresSettings.mbLockedPages );
594 case ATTR_PRESENT_ANIMATION_ALLOWED:
595 return Any( rPresSettings.mbAnimationAllowed );
596 case ATTR_PRESENT_CUSTOMSHOW:
598 SdCustomShowList* pList = mpDoc->GetCustomShowList(sal_False);
599 SdCustomShow* pShow = (pList && rPresSettings.mbCustomShow) ? pList->GetCurObject() : NULL;
600 OUString aShowName;
602 if(pShow)
603 aShowName = pShow->GetName();
605 return Any( aShowName );
607 case ATTR_PRESENT_ENDLESS:
608 return Any( rPresSettings.mbEndless );
609 case ATTR_PRESENT_FULLSCREEN:
610 return Any( rPresSettings.mbFullScreen );
611 case ATTR_PRESENT_DIANAME:
613 OUString aSlideName;
615 if( !rPresSettings.mbCustomShow && !rPresSettings.mbAll )
616 aSlideName = getPageApiNameFromUiName( rPresSettings.maPresPage );
618 return Any( aSlideName );
620 case ATTR_PRESENT_MANUEL:
621 return Any( rPresSettings.mbManual );
622 case ATTR_PRESENT_MOUSE:
623 return Any( rPresSettings.mbMouseVisible );
624 case ATTR_PRESENT_ALWAYS_ON_TOP:
625 return Any( rPresSettings.mbAlwaysOnTop );
626 case ATTR_PRESENT_NAVIGATOR:
627 return Any( rPresSettings.mbStartWithNavigator );
628 case ATTR_PRESENT_PEN:
629 return Any( rPresSettings.mbMouseAsPen );
630 case ATTR_PRESENT_PAUSE_TIMEOUT:
631 return Any( rPresSettings.mnPauseTimeout );
632 case ATTR_PRESENT_SHOW_PAUSELOGO:
633 return Any( rPresSettings.mbShowPauseLogo );
634 case ATTR_PRESENT_DISPLAY:
636 SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
637 return Any(pOptions->GetDisplay());
640 default:
641 throw UnknownPropertyException();
645 // --------------------------------------------------------------------
647 void SAL_CALL SlideShow::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
651 // --------------------------------------------------------------------
653 void SAL_CALL SlideShow::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
657 // --------------------------------------------------------------------
659 void SAL_CALL SlideShow::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
663 // --------------------------------------------------------------------
665 void SAL_CALL SlideShow::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
669 // --------------------------------------------------------------------
670 // XPresentation
671 // --------------------------------------------------------------------
673 void SAL_CALL SlideShow::start() throw(RuntimeException)
675 const Sequence< PropertyValue > aArguments;
676 startWithArguments( aArguments );
679 // --------------------------------------------------------------------
681 WorkWindow *SlideShow::GetWorkWindow()
683 if( !mpFullScreenViewShellBase )
684 return NULL;
686 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(mpFullScreenViewShellBase->GetMainViewShell().get());
688 if( !pShell || !pShell->GetViewFrame() )
689 return NULL;
691 return dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetTopFrame().GetWindow().GetParent());
694 void SAL_CALL SlideShow::end() throw(RuntimeException)
696 SolarMutexGuard aGuard;
698 // The mbIsInStartup flag should have been reset during the start of the
699 // slide show. Reset it here just in case that something has horribly
700 // gone wrong.
701 OSL_ASSERT(!mbIsInStartup);
702 mbIsInStartup = false;
704 rtl::Reference< SlideshowImpl > xController( mxController );
705 if( xController.is() )
707 mxController.clear();
709 if( mpFullScreenFrameView )
711 delete mpFullScreenFrameView;
712 mpFullScreenFrameView = 0;
715 ViewShellBase* pFullScreenViewShellBase = mpFullScreenViewShellBase;
716 mpFullScreenViewShellBase = 0;
718 // dispose before fullscreen window changes screens
719 // (potentially). If this needs to be moved behind
720 // pWorkWindow->StartPresentationMode() again, read issue
721 // pWorkWindow->i94007 & implement the solution outlined
722 // there.
723 xController->dispose();
725 if( pFullScreenViewShellBase )
727 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(pFullScreenViewShellBase->GetMainViewShell().get());
729 if( pShell && pShell->GetViewFrame() )
731 WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetTopFrame().GetWindow().GetParent());
732 if( pWorkWindow )
734 pWorkWindow->StartPresentationMode( sal_False, isAlwaysOnTop() );
739 if( pFullScreenViewShellBase )
741 PresentationViewShell* pShell = NULL;
743 // Get the shell pointer in its own scope to be sure that
744 // the shared_ptr to the shell is released before DoClose()
745 // is called.
746 ::boost::shared_ptr<ViewShell> pSharedView (pFullScreenViewShellBase->GetMainViewShell());
747 pShell = dynamic_cast<PresentationViewShell*>(pSharedView.get());
749 if( pShell && pShell->GetViewFrame() )
750 pShell->GetViewFrame()->DoClose();
752 else if( mpCurrentViewShellBase )
754 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
756 if( pViewShell )
758 FrameView* pFrameView = pViewShell->GetFrameView();
760 if( pFrameView && (pFrameView->GetPresentationViewShellId() != SID_VIEWSHELL0) )
762 ViewShell::ShellType ePreviousType (pFrameView->GetPreviousViewShellType());
763 pFrameView->SetPreviousViewShellType(ViewShell::ST_NONE);
765 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL0);
766 pFrameView->SetSlotId(SID_OBJECT_SELECT);
767 pFrameView->SetPreviousViewShellType(pViewShell->GetShellType());
769 framework::FrameworkHelper::Instance(*mpCurrentViewShellBase)->RequestView(
770 framework::FrameworkHelper::GetViewURL(ePreviousType),
771 framework::FrameworkHelper::msCenterPaneURL);
773 pViewShell->GetViewFrame()->GetBindings().InvalidateAll( sal_True );
778 if( mpCurrentViewShellBase )
780 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
781 if( pViewShell )
783 // invalidate the view shell so the presentation slot will be re-enabled
784 // and the rehersing will be updated
785 pViewShell->Invalidate();
787 if( xController->meAnimationMode ==ANIMATIONMODE_SHOW )
789 // switch to the previously visible Slide
790 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>( pViewShell );
791 if( pDrawViewShell )
792 pDrawViewShell->SwitchPage( (sal_uInt16)xController->getRestoreSlide() );
793 else
795 Reference<XDrawView> xDrawView (
796 Reference<XWeak>(&mpCurrentViewShellBase->GetDrawController()), UNO_QUERY);
797 if (xDrawView.is())
798 xDrawView->setCurrentPage(
799 Reference<XDrawPage>(
800 mpDoc->GetSdPage(xController->getRestoreSlide(), PK_STANDARD)->getUnoPage(),
801 UNO_QUERY));
805 if( pViewShell->GetDoc()->IsExitAfterPresenting() )
807 pViewShell->GetDoc()->SetExitAfterPresenting( false );
809 Reference<frame::XDispatchProvider> xProvider(pViewShell->GetViewShellBase().GetController()->getFrame(),
810 UNO_QUERY);
811 if( xProvider.is() )
813 util::URL aURL;
814 aURL.Complete = ".uno:CloseFrame";
816 uno::Reference< frame::XDispatch > xDispatch(
817 xProvider->queryDispatch(
818 aURL, OUString(), 0));
819 if( xDispatch.is() )
821 xDispatch->dispatch(aURL,
822 uno::Sequence< beans::PropertyValue >());
828 mpCurrentViewShellBase = 0;
832 // --------------------------------------------------------------------
834 void SAL_CALL SlideShow::rehearseTimings() throw(RuntimeException)
836 Sequence< PropertyValue > aArguments(1);
837 aArguments[0].Name = "RehearseTimings";
838 aArguments[0].Value <<= sal_True;
839 startWithArguments( aArguments );
842 // --------------------------------------------------------------------
843 // XPresentation2
844 // --------------------------------------------------------------------
846 void SAL_CALL SlideShow::startWithArguments( const Sequence< PropertyValue >& rArguments ) throw (RuntimeException)
848 SolarMutexGuard aGuard;
849 ThrowIfDisposed();
851 // Stop a running show before starting a new one.
852 if( mxController.is() )
854 OSL_ASSERT(!mbIsInStartup);
855 end();
857 else if (mbIsInStartup)
859 // We are already somewhere in process of starting a slide show but
860 // have not yet got to the point where mxController is set. There
861 // is not yet a slide show to end so return silently.
862 return;
865 // Prevent multiple instance of the SlideShow class for one document.
866 mbIsInStartup = true;
868 mxCurrentSettings.reset( new PresentationSettingsEx( mpDoc->getPresentationSettings() ) );
869 mxCurrentSettings->SetArguments( rArguments );
871 // if there is no view shell base set, use the current one or the first using this document
872 if( mpCurrentViewShellBase == 0 )
874 // first check current
875 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::Current() );
876 if( pBase && pBase->GetDocument() == mpDoc )
878 mpCurrentViewShellBase = pBase;
880 else
882 // current is not ours, so get first from ours
883 mpCurrentViewShellBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::GetFirst( mpDoc->GetDocSh() ) );
887 // #i118456# make sure TextEdit changes get pushed to model.
888 // mpDrawView is tested against NULL above already.
889 if(mpCurrentViewShellBase)
891 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
893 if(pViewShell && pViewShell->GetView())
895 pViewShell->GetView()->SdrEndTextEdit();
899 // Start either a full-screen or an in-place show.
900 if(mxCurrentSettings->mbFullScreen && !mxCurrentSettings->mbPreview)
901 StartFullscreenPresentation();
902 else
903 StartInPlacePresentation();
907 // --------------------------------------------------------------------
909 ::sal_Bool SAL_CALL SlideShow::isRunning( ) throw (RuntimeException)
911 SolarMutexGuard aGuard;
912 return mxController.is() && mxController->isRunning();
915 // --------------------------------------------------------------------
917 Reference< XSlideShowController > SAL_CALL SlideShow::getController( ) throw (RuntimeException)
919 ThrowIfDisposed();
921 Reference< XSlideShowController > xController( mxController.get() );
922 return xController;
925 // --------------------------------------------------------------------
926 // XComponent
927 // --------------------------------------------------------------------
929 void SAL_CALL SlideShow::disposing (void)
931 SolarMutexGuard aGuard;
933 if( mnInPlaceConfigEvent )
935 Application::RemoveUserEvent( mnInPlaceConfigEvent );
936 mnInPlaceConfigEvent = 0;
939 if( mxController.is() )
941 mxController->dispose();
942 mxController.clear();
945 mpCurrentViewShellBase = 0;
946 mpFullScreenViewShellBase = 0;
947 mpDoc = 0;
950 // ---------------------------------------------------------
952 bool SlideShow::startPreview( const Reference< XDrawPage >& xDrawPage, const Reference< XAnimationNode >& xAnimationNode, ::Window* pParent )
954 Sequence< PropertyValue > aArguments(4);
956 aArguments[0].Name = "Preview";
957 aArguments[0].Value <<= sal_True;
959 aArguments[1].Name = "FirstPage";
960 aArguments[1].Value <<= xDrawPage;
962 aArguments[2].Name = "AnimationNode";
963 aArguments[2].Value <<= xAnimationNode;
965 Reference< XWindow > xParentWindow;
966 if( pParent )
967 xParentWindow = VCLUnoHelper::GetInterface( pParent );
969 aArguments[3].Name = "ParentWindow";
970 aArguments[3].Value <<= xParentWindow;
972 startWithArguments( aArguments );
974 return true;
977 // ---------------------------------------------------------
979 ShowWindow* SlideShow::getShowWindow()
981 return mxController.is() ? mxController->mpShowWindow : 0;
984 // ---------------------------------------------------------
986 int SlideShow::getAnimationMode()
988 return mxController.is() ? mxController->meAnimationMode : ANIMATIONMODE_SHOW;
991 // ---------------------------------------------------------
993 void SlideShow::jumpToPageIndex( sal_Int32 nPageIndex )
995 if( mxController.is() )
996 mxController->displaySlideIndex( nPageIndex );
999 // ---------------------------------------------------------
1001 void SlideShow::jumpToPageNumber( sal_Int32 nPageNumber )
1003 if( mxController.is() )
1004 mxController->displaySlideNumber( nPageNumber );
1007 // ---------------------------------------------------------
1009 sal_Int32 SlideShow::getCurrentPageNumber()
1011 return mxController.is() ? mxController->getCurrentSlideNumber() : 0;
1014 // ---------------------------------------------------------
1016 void SlideShow::jumpToBookmark( const OUString& sBookmark )
1018 if( mxController.is() )
1019 mxController->jumpToBookmark( sBookmark );
1022 // ---------------------------------------------------------
1024 bool SlideShow::isFullScreen()
1026 return mxController.is() ? mxController->maPresSettings.mbFullScreen : false;
1029 // ---------------------------------------------------------
1031 void SlideShow::resize( const Size &rSize )
1033 if( mxController.is() )
1034 mxController->resize( rSize );
1037 // ---------------------------------------------------------
1039 void SlideShow::activate( ViewShellBase& rBase )
1041 if( (mpFullScreenViewShellBase == &rBase) && !mxController.is() )
1043 ::boost::shared_ptr<PresentationViewShell> pShell = ::boost::dynamic_pointer_cast<PresentationViewShell>(rBase.GetMainViewShell());
1044 if(pShell.get() != NULL)
1046 pShell->FinishInitialization( mpFullScreenFrameView );
1047 mpFullScreenFrameView = 0;
1049 CreateController( pShell.get(), pShell->GetView(), rBase.GetViewWindow() );
1051 if( mxController->startShow(mxCurrentSettings.get()) )
1053 pShell->Resize();
1055 else
1057 end();
1058 return;
1063 if( mxController.is() )
1064 mxController->activate();
1068 // ---------------------------------------------------------
1070 void SlideShow::deactivate( ViewShellBase& /*rBase*/ )
1072 mxController->deactivate();
1075 // ---------------------------------------------------------
1077 bool SlideShow::keyInput(const KeyEvent& rKEvt)
1079 return mxController.is() ? mxController->keyInput(rKEvt) : false;
1082 // ---------------------------------------------------------
1084 void SlideShow::paint( const Rectangle& rRect )
1086 if( mxController.is() )
1087 mxController->paint( rRect );
1090 // ---------------------------------------------------------
1092 bool SlideShow::isAlwaysOnTop()
1094 return mxController.is() ? mxController->maPresSettings.mbAlwaysOnTop : false;
1097 // ---------------------------------------------------------
1099 bool SlideShow::pause( bool bPause )
1101 if( mxController.is() )
1103 if( bPause )
1104 mxController->pause();
1105 else
1106 mxController->resume();
1108 return true;
1111 // ---------------------------------------------------------
1113 void SlideShow::receiveRequest(SfxRequest& rReq)
1115 if( mxController.is() )
1116 mxController->receiveRequest( rReq );
1119 // ---------------------------------------------------------
1121 sal_Int32 SlideShow::getFirstPageNumber()
1123 return mxController.is() ? mxController->getFirstSlideNumber() : 0;
1126 // ---------------------------------------------------------
1128 sal_Int32 SlideShow::getLastPageNumber()
1130 return mxController.is() ? mxController->getLastSlideNumber() : 0;
1133 // ---------------------------------------------------------
1135 bool SlideShow::isEndless()
1137 return mxController.is() ? mxController->isEndless() : false;
1140 // ---------------------------------------------------------
1142 bool SlideShow::isDrawingPossible()
1144 return mxController.is() ? mxController->getUsePen() : false;
1147 // ---------------------------------------------------------
1149 void SlideShow::StartInPlacePresentationConfigurationCallback()
1151 if( mnInPlaceConfigEvent != 0 )
1152 Application::RemoveUserEvent( mnInPlaceConfigEvent );
1154 mnInPlaceConfigEvent = Application::PostUserEvent( LINK( this, SlideShow, StartInPlacePresentationConfigurationHdl ) );
1157 // ---------------------------------------------------------
1159 IMPL_LINK_NOARG(SlideShow, StartInPlacePresentationConfigurationHdl)
1161 mnInPlaceConfigEvent = 0;
1162 StartInPlacePresentation();
1163 return 0;
1166 // ---------------------------------------------------------
1168 void SlideShow::StartInPlacePresentation()
1170 if( mpCurrentViewShellBase )
1172 // Save the current view shell type so that it can be restored after the
1173 // show has ended. If there already is a saved shell type then that is
1174 // not overwritten.
1176 ViewShell::ShellType eShell = ViewShell::ST_NONE;
1178 ::boost::shared_ptr<FrameworkHelper> pHelper(FrameworkHelper::Instance(*mpCurrentViewShellBase));
1179 ::boost::shared_ptr<ViewShell> pMainViewShell(pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL));
1181 if( pMainViewShell.get() )
1182 eShell = pMainViewShell->GetShellType();
1184 if( eShell != ViewShell::ST_IMPRESS )
1186 // Switch temporary to a DrawViewShell which supports the in-place presentation.
1188 if( pMainViewShell.get() )
1190 FrameView* pFrameView = pMainViewShell->GetFrameView();
1191 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL1);
1192 pFrameView->SetPreviousViewShellType (pMainViewShell->GetShellType());
1193 pFrameView->SetPageKind (PK_STANDARD);
1196 pHelper->RequestView( FrameworkHelper::msImpressViewURL, FrameworkHelper::msCenterPaneURL );
1197 pHelper->RunOnConfigurationEvent( FrameworkHelper::msConfigurationUpdateEndEvent, ::boost::bind(&SlideShow::StartInPlacePresentationConfigurationCallback, this) );
1198 return;
1200 else
1202 ::Window* pParentWindow = mxCurrentSettings->mpParentWindow;
1203 if( pParentWindow == 0 )
1204 pParentWindow = mpCurrentViewShellBase->GetViewWindow();
1206 CreateController( pMainViewShell.get(), pMainViewShell->GetView(), pParentWindow );
1209 else if( mxCurrentSettings->mpParentWindow )
1211 // no current view shell, but parent window
1212 CreateController( 0, 0, mxCurrentSettings->mpParentWindow );
1215 if( mxController.is() )
1217 sal_Bool bSuccess = sal_False;
1218 if( mxCurrentSettings.get() && mxCurrentSettings->mbPreview )
1220 bSuccess = mxController->startPreview(mxCurrentSettings->mxStartPage, mxCurrentSettings->mxAnimationNode, mxCurrentSettings->mpParentWindow );
1222 else
1224 bSuccess = mxController->startShow(mxCurrentSettings.get());
1227 if( !bSuccess )
1228 end();
1232 // ---------------------------------------------------------
1234 void SlideShow::StartFullscreenPresentation( )
1236 // Create the top level window in which the PresentationViewShell(Base)
1237 // will be created. This is done here explicitly so that we can make it
1238 // fullscreen.
1239 const sal_Int32 nDisplay (GetDisplay());
1240 WorkWindow* pWorkWindow = new FullScreenWorkWindow(this, mpCurrentViewShellBase);
1241 pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
1242 pWorkWindow->StartPresentationMode( sal_True, mpDoc->getPresentationSettings().mbAlwaysOnTop ? PRESENTATION_HIDEALLAPPS : 0, nDisplay);
1243 // pWorkWindow->ShowFullScreenMode(sal_False, nDisplay);
1245 if (pWorkWindow->IsVisible())
1247 // Initialize the new presentation view shell with a copy of the
1248 // frame view of the current view shell. This avoids that
1249 // changes made by the presentation have an effect on the other
1250 // view shells.
1251 FrameView* pOriginalFrameView = mpCurrentViewShellBase ? mpCurrentViewShellBase->GetMainViewShell()->GetFrameView() : 0;
1253 if( mpFullScreenFrameView )
1254 delete mpFullScreenFrameView;
1255 mpFullScreenFrameView = new FrameView(mpDoc, pOriginalFrameView);
1257 // The new frame is created hidden. To make it visible and activate the
1258 // new view shell--a prerequisite to process slot calls and initialize
1259 // its panes--a GrabFocus() has to be called later on.
1260 SfxFrame* pNewFrame = SfxFrame::Create( *mpDoc->GetDocSh(), *pWorkWindow, PRESENTATION_FACTORY_ID, true );
1261 pNewFrame->SetPresentationMode(sal_True);
1263 mpFullScreenViewShellBase = static_cast<ViewShellBase*>(pNewFrame->GetCurrentViewFrame()->GetViewShell());
1264 if(mpFullScreenViewShellBase != NULL)
1266 // The following GrabFocus() is responsible for activating the
1267 // new view shell. Without it the screen remains blank (under
1268 // Windows and some Linux variants.)
1269 mpFullScreenViewShellBase->GetWindow()->GrabFocus();
1274 // ---------------------------------------------------------
1276 /// convert configuration setting display concept to real screens
1277 sal_Int32 SlideShow::GetDisplay()
1279 sal_Int32 nDisplay = 0;
1281 SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
1282 if( pOptions )
1283 nDisplay = pOptions->GetDisplay();
1285 if( nDisplay < 0 )
1286 nDisplay = -1;
1287 else if( nDisplay == 0)
1288 nDisplay = (sal_Int32)Application::GetDisplayExternalScreen();
1289 else
1290 nDisplay--;
1292 SAL_INFO("sd", "Presenting on real screen " << nDisplay);
1294 return nDisplay;
1297 // ---------------------------------------------------------
1300 bool SlideShow::dependsOn( ViewShellBase* pViewShellBase )
1302 return mxController.is() && (pViewShellBase == mpCurrentViewShellBase) && mpFullScreenViewShellBase;
1305 // ---------------------------------------------------------
1307 Reference< presentation::XPresentation2 > CreatePresentation( const SdDrawDocument& rDocument )
1309 return Reference< presentation::XPresentation2 >( SlideShow::Create( const_cast< SdDrawDocument* >( &rDocument ) ).get() );
1312 // ---------------------------------------------------------
1314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */