android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / slideshow / slideshow.cxx
blob348bc606b80025dd6c49fca5e891b885eeb0094e
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 <com/sun/star/beans/PropertyAttribute.hpp>
21 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
22 #include <com/sun/star/frame/XDispatchProvider.hpp>
23 #include <com/sun/star/util/URL.hpp>
25 #include <comphelper/propertyvalue.hxx>
26 #include <cppuhelper/supportsservice.hxx>
28 #include <sal/log.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/wrkwin.hxx>
31 #include <svx/svdpool.hxx>
32 #include <svx/svdlayer.hxx>
33 #include <svl/itemprop.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/sfxsids.hrc>
39 #include <framework/FrameworkHelper.hxx>
40 #include <comphelper/extract.hxx>
42 #include <FrameView.hxx>
43 #include <createpresentation.hxx>
44 #include <unomodel.hxx>
45 #include <slideshow.hxx>
46 #include "slideshowimpl.hxx"
47 #include <sdattr.hrc>
48 #include <sdmod.hxx>
49 #include <FactoryIds.hxx>
50 #include <DrawDocShell.hxx>
51 #include <ViewShell.hxx>
52 #include <ViewShellBase.hxx>
53 #include "SlideShowRestarter.hxx"
54 #include <DrawController.hxx>
55 #include <PresentationViewShell.hxx>
56 #include <customshowlist.hxx>
57 #include <unopage.hxx>
58 #include <sdpage.hxx>
59 #include <cusshow.hxx>
60 #include <optsitem.hxx>
61 #include <strings.hrc>
62 #include <sdresid.hxx>
64 using ::com::sun::star::presentation::XSlideShowController;
65 using ::sd::framework::FrameworkHelper;
66 using ::com::sun::star::awt::XWindow;
67 using namespace ::sd;
68 using namespace ::cppu;
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::drawing;
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::animations;
75 using namespace ::com::sun::star::drawing::framework;
77 namespace {
78 /** This local version of the work window overrides DataChanged() so that it
79 can restart the slide show when a display is added or removed.
81 class FullScreenWorkWindow : public WorkWindow
83 public:
84 FullScreenWorkWindow (
85 const ::rtl::Reference<SlideShow>& rpSlideShow,
86 ViewShellBase* pViewShellBase)
87 : WorkWindow(nullptr, WB_HIDE | WB_CLIPCHILDREN),
88 mpRestarter(std::make_shared<SlideShowRestarter>(rpSlideShow, pViewShellBase))
91 void Restart(bool bForce)
93 mpRestarter->Restart(bForce);
96 virtual void DataChanged (const DataChangedEvent& rEvent) override
98 if (rEvent.GetType() == DataChangedEventType::DISPLAY)
99 Restart(false);
102 private:
103 ::std::shared_ptr<SlideShowRestarter> mpRestarter;
107 static o3tl::span<const SfxItemPropertyMapEntry> ImplGetPresentationPropertyMap()
109 // NOTE: First member must be sorted
110 static const SfxItemPropertyMapEntry aPresentationPropertyMap_Impl[] =
112 { u"AllowAnimations", ATTR_PRESENT_ANIMATION_ALLOWED, cppu::UnoType<bool>::get(), 0, 0 },
113 { u"CustomShow", ATTR_PRESENT_CUSTOMSHOW, ::cppu::UnoType<OUString>::get(), 0, 0 },
114 { u"Display", ATTR_PRESENT_DISPLAY, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
115 { u"FirstPage", ATTR_PRESENT_DIANAME, ::cppu::UnoType<OUString>::get(), 0, 0 },
116 { u"IsAlwaysOnTop", ATTR_PRESENT_ALWAYS_ON_TOP, cppu::UnoType<bool>::get(), 0, 0 },
117 { u"IsShowNavigationButtons", ATTR_PRESENT_SHOW_NAVIGATION_BUTTONS, cppu::UnoType<bool>::get(), 0, 0 },
118 { u"IsAutomatic", ATTR_PRESENT_MANUEL, cppu::UnoType<bool>::get(), 0, 0 },
119 { u"IsEndless", ATTR_PRESENT_ENDLESS, cppu::UnoType<bool>::get(), 0, 0 },
120 { u"IsFullScreen", ATTR_PRESENT_FULLSCREEN, cppu::UnoType<bool>::get(), 0, 0 },
121 { u"IsShowAll", ATTR_PRESENT_ALL, cppu::UnoType<bool>::get(), 0, 0 },
122 { u"IsMouseVisible", ATTR_PRESENT_MOUSE, cppu::UnoType<bool>::get(), 0, 0 },
123 { u"IsShowLogo", ATTR_PRESENT_SHOW_PAUSELOGO, cppu::UnoType<bool>::get(), 0, 0 },
124 { u"IsTransitionOnClick", ATTR_PRESENT_CHANGE_PAGE, cppu::UnoType<bool>::get(), 0, 0 },
125 { u"Pause", ATTR_PRESENT_PAUSE_TIMEOUT, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
126 { u"StartWithNavigator", ATTR_PRESENT_NAVIGATOR, cppu::UnoType<bool>::get(), 0, 0 },
127 { u"UsePen", ATTR_PRESENT_PEN, cppu::UnoType<bool>::get(), 0, 0 },
130 return aPresentationPropertyMap_Impl;
134 SlideShow::SlideShow( SdDrawDocument* pDoc )
135 : maPropSet(ImplGetPresentationPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool())
136 , mbIsInStartup(false)
137 , mpDoc( pDoc )
138 , mpCurrentViewShellBase( nullptr )
139 , mpFullScreenViewShellBase( nullptr )
140 , mpFullScreenFrameView( nullptr )
141 , mnInPlaceConfigEvent( nullptr )
145 void SlideShow::ThrowIfDisposed() const
147 if( mpDoc == nullptr )
148 throw DisposedException();
151 /// used by the model to create a slideshow for it
152 rtl::Reference< SlideShow > SlideShow::Create( SdDrawDocument* pDoc )
154 return new SlideShow( pDoc );
157 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument const * pDocument )
159 rtl::Reference< SlideShow > xRet;
161 if( pDocument )
162 xRet = GetSlideShow( *pDocument );
164 return xRet;
167 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument const & rDocument )
169 return rtl::Reference< SlideShow >(
170 dynamic_cast< SlideShow* >( rDocument.getPresentation().get() ) );
173 rtl::Reference< SlideShow > SlideShow::GetSlideShow( ViewShellBase const & rBase )
175 return GetSlideShow( rBase.GetDocument() );
178 css::uno::Reference< css::presentation::XSlideShowController > SlideShow::GetSlideShowController(ViewShellBase const & rBase )
180 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
182 Reference< XSlideShowController > xRet;
183 if( xSlideShow.is() )
184 xRet = xSlideShow->getController();
186 return xRet;
189 bool SlideShow::StartPreview( ViewShellBase const & rBase,
190 const css::uno::Reference< css::drawing::XDrawPage >& xDrawPage,
191 const css::uno::Reference< css::animations::XAnimationNode >& xAnimationNode )
193 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
194 if( !xSlideShow.is() )
195 return false;
197 xSlideShow->startPreview( xDrawPage, xAnimationNode );
198 return true;
201 void SlideShow::Stop( ViewShellBase const & rBase )
203 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
204 if( xSlideShow.is() )
205 xSlideShow->end();
208 bool SlideShow::IsRunning( ViewShellBase const & rBase )
210 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
211 return xSlideShow.is() && xSlideShow->isRunning();
214 bool SlideShow::IsRunning( const ViewShell& rViewShell )
216 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rViewShell.GetViewShellBase() ) );
217 return xSlideShow.is() && xSlideShow->isRunning() && (xSlideShow->mxController->getViewShell() == &rViewShell);
220 void SlideShow::CreateController( ViewShell* pViewSh, ::sd::View* pView, vcl::Window* pParentWindow )
222 SAL_INFO_IF( !mxController.is(), "sd.slideshow", "sd::SlideShow::CreateController(), clean up old controller first!" );
224 Reference< XPresentation2 > xThis( this );
226 rtl::Reference<SlideshowImpl> xController (
227 new SlideshowImpl(xThis, pViewSh, pView, mpDoc, pParentWindow));
229 // Reset mbIsInStartup. From here mxController.is() is used to prevent
230 // multiple slide show instances for one document.
231 mxController = xController;
232 mbIsInStartup = false;
236 // XServiceInfo
237 OUString SAL_CALL SlideShow::getImplementationName( )
239 return "com.sun.star.comp.sd.SlideShow";
242 sal_Bool SAL_CALL SlideShow::supportsService( const OUString& ServiceName )
244 return cppu::supportsService( this, ServiceName );
247 Sequence< OUString > SAL_CALL SlideShow::getSupportedServiceNames( )
249 return { "com.sun.star.presentation.Presentation" };
252 // XPropertySet
253 Reference< XPropertySetInfo > SAL_CALL SlideShow::getPropertySetInfo()
255 SolarMutexGuard aGuard;
256 static Reference< XPropertySetInfo > xInfo = maPropSet.getPropertySetInfo();
257 return xInfo;
260 void SAL_CALL SlideShow::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
262 SolarMutexGuard aGuard;
263 ThrowIfDisposed();
265 sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
267 const SfxItemPropertyMapEntry* pEntry = maPropSet.getPropertyMapEntry(aPropertyName);
269 if( pEntry && ((pEntry->nFlags & PropertyAttribute::READONLY) != 0) )
270 throw PropertyVetoException();
272 bool bValuesChanged = false;
273 bool bIllegalArgument = true;
275 switch( pEntry ? pEntry->nWID : -1 )
277 case ATTR_PRESENT_ALL:
279 bool bVal = false;
281 if( aValue >>= bVal )
283 bIllegalArgument = false;
285 if( rPresSettings.mbAll != bVal )
287 rPresSettings.mbAll = bVal;
288 bValuesChanged = true;
289 if( bVal )
290 rPresSettings.mbCustomShow = false;
293 break;
295 case ATTR_PRESENT_CHANGE_PAGE:
297 bool bVal = false;
299 if( aValue >>= bVal )
301 bIllegalArgument = false;
303 if( bVal == rPresSettings.mbLockedPages )
305 bValuesChanged = true;
306 rPresSettings.mbLockedPages = !bVal;
309 break;
312 case ATTR_PRESENT_ANIMATION_ALLOWED:
314 bool bVal = false;
316 if( aValue >>= bVal )
318 bIllegalArgument = false;
320 if(rPresSettings.mbAnimationAllowed != bVal)
322 bValuesChanged = true;
323 rPresSettings.mbAnimationAllowed = bVal;
326 break;
328 case ATTR_PRESENT_CUSTOMSHOW:
330 OUString aShowName;
331 if( aValue >>= aShowName )
333 bIllegalArgument = false;
335 SdCustomShowList* pCustomShowList = mpDoc->GetCustomShowList();
336 if(pCustomShowList)
338 SdCustomShow* pCustomShow;
339 for( pCustomShow = pCustomShowList->First(); pCustomShow != nullptr; pCustomShow = pCustomShowList->Next() )
341 if( pCustomShow->GetName() == aShowName )
342 break;
345 rPresSettings.mbCustomShow = true;
346 bValuesChanged = true;
349 break;
351 case ATTR_PRESENT_ENDLESS:
353 bool bVal = false;
355 if( aValue >>= bVal )
357 bIllegalArgument = false;
359 if( rPresSettings.mbEndless != bVal)
361 bValuesChanged = true;
362 rPresSettings.mbEndless = bVal;
365 break;
367 case ATTR_PRESENT_FULLSCREEN:
369 bool bVal = false;
371 if( aValue >>= bVal )
373 bIllegalArgument = false;
374 if( rPresSettings.mbFullScreen != bVal)
376 bValuesChanged = true;
377 rPresSettings.mbFullScreen = bVal;
380 break;
382 case ATTR_PRESENT_DIANAME:
384 OUString aPresPage;
385 aValue >>= aPresPage;
386 bIllegalArgument = false;
387 if( (rPresSettings.maPresPage != aPresPage) || !rPresSettings.mbCustomShow || !rPresSettings.mbAll )
389 bValuesChanged = true;
390 rPresSettings.maPresPage = getUiNameFromPageApiNameImpl(aPresPage);
391 rPresSettings.mbCustomShow = false;
392 rPresSettings.mbAll = false;
394 break;
396 case ATTR_PRESENT_MANUEL:
398 bool bVal = false;
400 if( aValue >>= bVal )
402 bIllegalArgument = false;
404 if( rPresSettings.mbManual != bVal)
406 bValuesChanged = true;
407 rPresSettings.mbManual = bVal;
410 break;
412 case ATTR_PRESENT_MOUSE:
414 bool bVal = false;
416 if( aValue >>= bVal )
418 bIllegalArgument = false;
419 if( rPresSettings.mbMouseVisible != bVal)
421 bValuesChanged = true;
422 rPresSettings.mbMouseVisible = bVal;
425 break;
427 case ATTR_PRESENT_ALWAYS_ON_TOP:
429 bool bVal = false;
431 if( aValue >>= bVal )
433 bIllegalArgument = false;
435 if( rPresSettings.mbAlwaysOnTop != bVal)
437 bValuesChanged = true;
438 rPresSettings.mbAlwaysOnTop = bVal;
441 break;
443 case ATTR_PRESENT_SHOW_NAVIGATION_BUTTONS:
445 bool bVal = false;
447 if (aValue >>= bVal)
449 bIllegalArgument = false;
451 if (rPresSettings.mbUseNavigation != bVal)
453 bValuesChanged = true;
454 rPresSettings.mbUseNavigation = bVal;
457 break;
459 case ATTR_PRESENT_NAVIGATOR:
460 bIllegalArgument = false;
461 //ignored, but exists in some older documents
462 break;
463 case ATTR_PRESENT_PEN:
465 bool bVal = false;
467 if( aValue >>= bVal )
469 bIllegalArgument = false;
471 if(rPresSettings.mbMouseAsPen != bVal)
473 bValuesChanged = true;
474 rPresSettings.mbMouseAsPen = bVal;
477 break;
479 case ATTR_PRESENT_PAUSE_TIMEOUT:
481 sal_Int32 nValue = 0;
482 if( (aValue >>= nValue) && (nValue >= 0) )
484 bIllegalArgument = false;
485 if( rPresSettings.mnPauseTimeout != nValue )
487 bValuesChanged = true;
488 rPresSettings.mnPauseTimeout = nValue;
491 break;
493 case ATTR_PRESENT_SHOW_PAUSELOGO:
495 bool bVal = false;
497 if( aValue >>= bVal )
499 bIllegalArgument = false;
501 if( rPresSettings.mbShowPauseLogo != bVal )
503 bValuesChanged = true;
504 rPresSettings.mbShowPauseLogo = bVal;
507 break;
509 case ATTR_PRESENT_DISPLAY:
511 sal_Int32 nDisplay = 0;
512 if( aValue >>= nDisplay )
514 bIllegalArgument = false;
516 SdOptions* pOptions = SD_MOD()->GetSdOptions(DocumentType::Impress);
517 pOptions->SetDisplay( nDisplay );
519 FullScreenWorkWindow *pWin = dynamic_cast<FullScreenWorkWindow *>(GetWorkWindow());
520 if( !pWin )
521 return;
522 pWin->Restart(true);
524 break;
527 default:
528 throw UnknownPropertyException( OUString::number(pEntry ? pEntry->nWID : -1), static_cast<cppu::OWeakObject*>(this));
531 if( bIllegalArgument )
532 throw IllegalArgumentException();
534 if( bValuesChanged )
535 mpDoc->SetChanged();
538 Any SAL_CALL SlideShow::getPropertyValue( const OUString& PropertyName )
540 SolarMutexGuard aGuard;
541 ThrowIfDisposed();
543 const sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
545 const SfxItemPropertyMapEntry* pEntry = maPropSet.getPropertyMapEntry(PropertyName);
547 switch( pEntry ? pEntry->nWID : -1 )
549 case ATTR_PRESENT_ALL:
550 return Any( !rPresSettings.mbCustomShow && rPresSettings.mbAll );
551 case ATTR_PRESENT_CHANGE_PAGE:
552 return Any( !rPresSettings.mbLockedPages );
553 case ATTR_PRESENT_ANIMATION_ALLOWED:
554 return Any( rPresSettings.mbAnimationAllowed );
555 case ATTR_PRESENT_CUSTOMSHOW:
557 SdCustomShowList* pList = mpDoc->GetCustomShowList();
558 SdCustomShow* pShow = (pList && rPresSettings.mbCustomShow) ? pList->GetCurObject() : nullptr;
559 OUString aShowName;
561 if(pShow)
562 aShowName = pShow->GetName();
564 return Any( aShowName );
566 case ATTR_PRESENT_ENDLESS:
567 return Any( rPresSettings.mbEndless );
568 case ATTR_PRESENT_FULLSCREEN:
569 return Any( rPresSettings.mbFullScreen );
570 case ATTR_PRESENT_DIANAME:
572 OUString aSlideName;
574 if( !rPresSettings.mbCustomShow && !rPresSettings.mbAll )
575 aSlideName = getPageApiNameFromUiName( rPresSettings.maPresPage );
577 return Any( aSlideName );
579 case ATTR_PRESENT_MANUEL:
580 return Any( rPresSettings.mbManual );
581 case ATTR_PRESENT_MOUSE:
582 return Any( rPresSettings.mbMouseVisible );
583 case ATTR_PRESENT_ALWAYS_ON_TOP:
584 return Any( rPresSettings.mbAlwaysOnTop );
585 case ATTR_PRESENT_SHOW_NAVIGATION_BUTTONS:
586 return Any(rPresSettings.mbUseNavigation);
587 case ATTR_PRESENT_NAVIGATOR:
588 return Any( false );
589 case ATTR_PRESENT_PEN:
590 return Any( rPresSettings.mbMouseAsPen );
591 case ATTR_PRESENT_PAUSE_TIMEOUT:
592 return Any( rPresSettings.mnPauseTimeout );
593 case ATTR_PRESENT_SHOW_PAUSELOGO:
594 return Any( rPresSettings.mbShowPauseLogo );
595 case ATTR_PRESENT_DISPLAY:
597 SdOptions* pOptions = SD_MOD()->GetSdOptions(DocumentType::Impress);
598 return Any(pOptions->GetDisplay());
601 default:
602 throw UnknownPropertyException( OUString::number(pEntry ? pEntry->nWID : -1), static_cast<cppu::OWeakObject*>(this));
606 void SAL_CALL SlideShow::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& )
610 void SAL_CALL SlideShow::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& )
614 void SAL_CALL SlideShow::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& )
618 void SAL_CALL SlideShow::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& )
622 // XPresentation
624 void SAL_CALL SlideShow::start()
626 const Sequence< PropertyValue > aArguments;
627 startWithArguments( aArguments );
630 WorkWindow *SlideShow::GetWorkWindow()
632 if( !mpFullScreenViewShellBase )
633 return nullptr;
635 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(mpFullScreenViewShellBase->GetMainViewShell().get());
637 if( !pShell || !pShell->GetViewFrame() )
638 return nullptr;
640 return dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetFrame().GetWindow().GetParent());
643 bool SlideShow::IsExitAfterPresenting() const
645 SolarMutexGuard aGuard;
646 ThrowIfDisposed();
647 return mpDoc->IsExitAfterPresenting();
650 void SlideShow::SetExitAfterPresenting(bool bExit)
652 SolarMutexGuard aGuard;
653 ThrowIfDisposed();
654 mpDoc->SetExitAfterPresenting(bExit);
657 void SAL_CALL SlideShow::end()
659 SolarMutexGuard aGuard;
661 // The mbIsInStartup flag should have been reset during the start of the
662 // slide show. Reset it here just in case that something has horribly
663 // gone wrong.
664 assert(!mbIsInStartup);
666 rtl::Reference< SlideshowImpl > xController( mxController );
667 if( !xController.is() )
668 return;
670 mxController.clear();
672 if( mpFullScreenFrameView )
674 delete mpFullScreenFrameView;
675 mpFullScreenFrameView = nullptr;
678 ViewShellBase* pFullScreenViewShellBase = mpFullScreenViewShellBase;
679 mpFullScreenViewShellBase = nullptr;
681 // dispose before fullscreen window changes screens
682 // (potentially). If this needs to be moved behind
683 // pWorkWindow->StartPresentationMode() again, read issue
684 // pWorkWindow->i94007 & implement the solution outlined
685 // there.
686 xController->dispose();
688 if( pFullScreenViewShellBase )
690 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(pFullScreenViewShellBase->GetMainViewShell().get());
692 if( pShell && pShell->GetViewFrame() )
694 WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetFrame().GetWindow().GetParent());
695 if( pWorkWindow )
697 pWorkWindow->StartPresentationMode( (mxController.is() && mxController->maPresSettings.mbAlwaysOnTop)
698 ? PresentationFlags::HideAllApps : PresentationFlags::NONE );
703 if( pFullScreenViewShellBase )
705 PresentationViewShell* pShell = nullptr;
707 // Get the shell pointer in its own scope to be sure that
708 // the shared_ptr to the shell is released before DoClose()
709 // is called.
710 ::std::shared_ptr<ViewShell> pSharedView (pFullScreenViewShellBase->GetMainViewShell());
711 pShell = dynamic_cast<PresentationViewShell*>(pSharedView.get());
713 if( pShell && pShell->GetViewFrame() )
714 pShell->GetViewFrame()->DoClose();
716 else if( mpCurrentViewShellBase )
718 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
720 if( pViewShell )
722 FrameView* pFrameView = pViewShell->GetFrameView();
724 if( pFrameView && (pFrameView->GetPresentationViewShellId() != SID_VIEWSHELL0) )
726 ViewShell::ShellType ePreviousType (pFrameView->GetPreviousViewShellType());
727 pFrameView->SetPreviousViewShellType(ViewShell::ST_NONE);
729 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL0);
730 pFrameView->SetPreviousViewShellType(pViewShell->GetShellType());
732 framework::FrameworkHelper::Instance(*mpCurrentViewShellBase)->RequestView(
733 framework::FrameworkHelper::GetViewURL(ePreviousType),
734 framework::FrameworkHelper::msCenterPaneURL);
736 pViewShell->GetViewFrame()->GetBindings().InvalidateAll( true );
741 if( mpCurrentViewShellBase )
743 if (ViewShell* const pViewShell = mpCurrentViewShellBase->GetMainViewShell().get())
745 // invalidate the view shell so the presentation slot will be re-enabled
746 // and the rehearsing will be updated
747 pViewShell->Invalidate();
749 if( xController->meAnimationMode ==ANIMATIONMODE_SHOW )
751 // switch to the previously visible Slide
752 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>( pViewShell );
753 if( pDrawViewShell )
754 pDrawViewShell->SwitchPage( static_cast<sal_uInt16>(xController->getRestoreSlide()) );
755 else
757 DrawController& rDrawController =
758 *mpCurrentViewShellBase->GetDrawController();
759 rDrawController.setCurrentPage(
760 Reference<XDrawPage>(
761 mpDoc->GetSdPage(xController->getRestoreSlide(), PageKind::Standard)->getUnoPage(),
762 UNO_QUERY));
766 if( pViewShell->GetDoc()->IsExitAfterPresenting() )
768 pViewShell->GetDoc()->SetExitAfterPresenting( false );
770 Reference<frame::XDispatchProvider> xProvider(pViewShell->GetViewShellBase().GetController()->getFrame(),
771 UNO_QUERY);
772 if( xProvider.is() )
774 util::URL aURL;
775 aURL.Complete = ".uno:CloseFrame";
777 uno::Reference< frame::XDispatch > xDispatch(
778 xProvider->queryDispatch(
779 aURL, OUString(), 0));
780 if( xDispatch.is() )
782 xDispatch->dispatch(aURL,
783 uno::Sequence< beans::PropertyValue >());
788 // In case mbMouseAsPen was set, a new layer DrawnInSlideshow might have been generated
789 // during slideshow, which is not known to FrameView yet.
790 if (any2bool(getPropertyValue("UsePen"))
791 && pViewShell->GetDoc()->GetLayerAdmin().GetLayer("DrawnInSlideshow"))
793 SdrLayerIDSet aDocLayerIDSet;
794 pViewShell->GetDoc()->GetLayerAdmin().getVisibleLayersODF(aDocLayerIDSet);
795 if (pViewShell->GetFrameView()->GetVisibleLayers() != aDocLayerIDSet)
797 pViewShell->GetFrameView()->SetVisibleLayers(aDocLayerIDSet);
799 pViewShell->GetDoc()->GetLayerAdmin().getPrintableLayersODF(aDocLayerIDSet);
800 if (pViewShell->GetFrameView()->GetPrintableLayers() != aDocLayerIDSet)
802 pViewShell->GetFrameView()->SetPrintableLayers(aDocLayerIDSet);
804 pViewShell->GetDoc()->GetLayerAdmin().getLockedLayersODF(aDocLayerIDSet);
805 if (pViewShell->GetFrameView()->GetLockedLayers() != aDocLayerIDSet)
807 pViewShell->GetFrameView()->SetLockedLayers(aDocLayerIDSet);
809 pViewShell->InvalidateWindows();
812 // Fire the acc focus event when focus is switched back. The above method
813 // mpCurrentViewShellBase->GetWindow()->GrabFocus() will set focus to WorkWindow
814 // instead of the sd::window, so here call Shell's method to fire the focus event
815 pViewShell->SwitchActiveViewFireFocus();
818 mpCurrentViewShellBase = nullptr;
821 void SAL_CALL SlideShow::rehearseTimings()
823 Sequence< PropertyValue > aArguments{ comphelper::makePropertyValue("RehearseTimings", true) };
824 startWithArguments( aArguments );
827 // XPresentation2
829 void SAL_CALL SlideShow::startWithArguments(const Sequence< PropertyValue >& rArguments)
831 SolarMutexGuard aGuard;
832 ThrowIfDisposed();
834 // Stop a running show before starting a new one.
835 if( mxController.is() )
837 assert(!mbIsInStartup);
838 end();
840 else if (mbIsInStartup)
842 // We are already somewhere in process of starting a slide show but
843 // have not yet got to the point where mxController is set. There
844 // is not yet a slide show to end so return silently.
845 return;
848 // Prevent multiple instance of the SlideShow class for one document.
849 mbIsInStartup = true;
851 mxCurrentSettings = std::make_shared<PresentationSettingsEx>( mpDoc->getPresentationSettings() );
852 mxCurrentSettings->SetArguments( rArguments );
854 // if there is no view shell base set, use the current one or the first using this document
855 if( mpCurrentViewShellBase == nullptr )
857 // first check current
858 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::Current() );
859 if( pBase && pBase->GetDocument() == mpDoc )
861 mpCurrentViewShellBase = pBase;
863 else
865 // current is not ours, so get first from ours
866 mpCurrentViewShellBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::GetFirst( mpDoc->GetDocSh() ) );
870 // #i118456# make sure TextEdit changes get pushed to model.
871 // mpDrawView is tested against NULL above already.
872 if(mpCurrentViewShellBase)
874 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
876 if(pViewShell && pViewShell->GetView())
878 pViewShell->GetView()->SdrEndTextEdit();
882 // Start either a full-screen or an in-place show.
883 if(mxCurrentSettings->mbFullScreen && !mxCurrentSettings->mbPreview)
884 StartFullscreenPresentation();
885 else
886 StartInPlacePresentation();
890 sal_Bool SAL_CALL SlideShow::isRunning( )
892 SolarMutexGuard aGuard;
893 return mxController.is() && mxController->isRunning();
896 Reference< XSlideShowController > SAL_CALL SlideShow::getController( )
898 ThrowIfDisposed();
900 return mxController;
903 // XComponent
905 void SlideShow::disposing(std::unique_lock<std::mutex>&)
907 SolarMutexGuard aGuard;
909 if( mnInPlaceConfigEvent )
911 Application::RemoveUserEvent( mnInPlaceConfigEvent );
912 mnInPlaceConfigEvent = nullptr;
915 if( mxController.is() )
917 mxController->dispose();
918 mxController.clear();
921 mpCurrentViewShellBase = nullptr;
922 mpFullScreenViewShellBase = nullptr;
923 mpDoc = nullptr;
926 void SlideShow::startPreview( const Reference< XDrawPage >& xDrawPage, const Reference< XAnimationNode >& xAnimationNode )
928 Sequence< PropertyValue > aArguments{
929 comphelper::makePropertyValue("Preview", true),
930 comphelper::makePropertyValue("FirstPage", xDrawPage),
931 comphelper::makePropertyValue("AnimationNode", xAnimationNode),
932 comphelper::makePropertyValue("ParentWindow", Reference< XWindow >()),
935 startWithArguments( aArguments );
938 OutputDevice* SlideShow::getShowWindow()
940 return mxController.is() ? mxController->mpShowWindow->GetOutDev() : nullptr;
943 int SlideShow::getAnimationMode() const
945 return mxController.is() ? mxController->meAnimationMode : ANIMATIONMODE_SHOW;
948 void SlideShow::jumpToPageIndex( sal_Int32 nPageIndex )
950 if( mxController.is() )
951 mxController->displaySlideIndex( nPageIndex );
954 void SlideShow::jumpToPageNumber( sal_Int32 nPageNumber )
956 if( mxController.is() )
957 mxController->displaySlideNumber( nPageNumber );
960 sal_Int32 SlideShow::getCurrentPageNumber() const
962 return mxController.is() ? mxController->getCurrentSlideNumber() : 0;
965 void SlideShow::jumpToBookmark( const OUString& sBookmark )
967 if( mxController.is() )
968 mxController->jumpToBookmark( sBookmark );
971 bool SlideShow::isFullScreen() const
973 return mxController.is() && mxController->maPresSettings.mbFullScreen;
976 void SlideShow::resize( const Size &rSize )
978 if( mxController.is() )
979 mxController->resize( rSize );
982 bool SlideShow::activate( ViewShellBase& rBase )
984 if( (mpFullScreenViewShellBase == &rBase) && !mxController.is() )
986 ::std::shared_ptr<PresentationViewShell> pShell = std::dynamic_pointer_cast<PresentationViewShell>(rBase.GetMainViewShell());
987 if (pShell != nullptr)
989 pShell->FinishInitialization( mpFullScreenFrameView );
990 mpFullScreenFrameView = nullptr;
992 CreateController( pShell.get(), pShell->GetView(), rBase.GetViewWindow() );
994 if (!mxController->startShow(mxCurrentSettings.get()))
995 return false;
997 pShell->Resize();
998 // Defer the sd::ShowWindow's GrabFocus to here. so that the accessible event can be fired correctly.
999 pShell->GetActiveWindow()->GrabFocus();
1003 if( mxController.is() )
1004 mxController->activate();
1006 return true;
1009 void SlideShow::deactivate()
1011 mxController->deactivate();
1014 bool SlideShow::keyInput(const KeyEvent& rKEvt)
1016 return mxController.is() && mxController->keyInput(rKEvt);
1019 void SlideShow::paint()
1021 if( mxController.is() )
1022 mxController->paint();
1025 void SlideShow::pause( bool bPause )
1027 if( mxController.is() )
1029 if( bPause )
1030 mxController->pause();
1031 else
1032 mxController->resume();
1036 bool SlideShow::swipe(const CommandGestureSwipeData& rSwipeData)
1038 return mxController.is() && mxController->swipe(rSwipeData);
1041 bool SlideShow::longpress(const CommandGestureLongPressData& rLongPressData)
1043 return mxController.is() && mxController->longpress(rLongPressData);
1046 void SlideShow::StartInPlacePresentationConfigurationCallback()
1048 if( mnInPlaceConfigEvent != nullptr )
1049 Application::RemoveUserEvent( mnInPlaceConfigEvent );
1051 mnInPlaceConfigEvent = Application::PostUserEvent( LINK( this, SlideShow, StartInPlacePresentationConfigurationHdl ) );
1054 IMPL_LINK_NOARG(SlideShow, StartInPlacePresentationConfigurationHdl, void*, void)
1056 mnInPlaceConfigEvent = nullptr;
1057 StartInPlacePresentation();
1060 void SlideShow::StartInPlacePresentation()
1062 if( mpCurrentViewShellBase )
1064 // Save the current view shell type so that it can be restored after the
1065 // show has ended. If there already is a saved shell type then that is
1066 // not overwritten.
1068 ViewShell::ShellType eShell = ViewShell::ST_NONE;
1070 ::std::shared_ptr<FrameworkHelper> pHelper(FrameworkHelper::Instance(*mpCurrentViewShellBase));
1071 ::std::shared_ptr<ViewShell> pMainViewShell(pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL));
1073 if( pMainViewShell )
1074 eShell = pMainViewShell->GetShellType();
1076 if( eShell != ViewShell::ST_IMPRESS )
1078 // Switch temporary to a DrawViewShell which supports the in-place presentation.
1080 if( pMainViewShell )
1082 FrameView* pFrameView = pMainViewShell->GetFrameView();
1083 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL1);
1084 pFrameView->SetPreviousViewShellType (pMainViewShell->GetShellType());
1085 pFrameView->SetPageKind (PageKind::Standard);
1088 pHelper->RequestView( FrameworkHelper::msImpressViewURL, FrameworkHelper::msCenterPaneURL );
1089 pHelper->RunOnConfigurationEvent(
1090 FrameworkHelper::msConfigurationUpdateEndEvent,
1091 [this] (bool const) { return this->StartInPlacePresentationConfigurationCallback(); } );
1092 return;
1094 else
1096 vcl::Window* pParentWindow = mxCurrentSettings->mpParentWindow;
1097 if( pParentWindow == nullptr )
1098 pParentWindow = mpCurrentViewShellBase->GetViewWindow();
1100 CreateController( pMainViewShell.get(), pMainViewShell->GetView(), pParentWindow );
1103 else if( mxCurrentSettings->mpParentWindow )
1105 // no current view shell, but parent window
1106 CreateController( nullptr, nullptr, mxCurrentSettings->mpParentWindow );
1109 if( !mxController.is() )
1110 return;
1112 bool bSuccess = false;
1113 if( mxCurrentSettings && mxCurrentSettings->mbPreview )
1115 bSuccess = mxController->startPreview(mxCurrentSettings->mxStartPage, mxCurrentSettings->mxAnimationNode, mxCurrentSettings->mpParentWindow );
1117 else
1119 bSuccess = mxController->startShow(mxCurrentSettings.get());
1122 if( !bSuccess )
1123 end();
1124 else
1126 if( mpCurrentViewShellBase && ( !mxCurrentSettings || ( mxCurrentSettings && !mxCurrentSettings->mbPreview ) ) )
1127 mpCurrentViewShellBase->GetWindow()->GrabFocus();
1131 void SlideShow::StartFullscreenPresentation( )
1133 // Create the top level window in which the PresentationViewShell(Base)
1134 // will be created. This is done here explicitly so that we can make it
1135 // fullscreen.
1136 const sal_Int32 nDisplay (GetDisplay());
1137 VclPtr<WorkWindow> pWorkWindow = VclPtr<FullScreenWorkWindow>::Create(this, mpCurrentViewShellBase);
1138 pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
1139 OUString Title(SdResId(STR_FULLSCREEN_SLIDESHOW));
1140 Title = Title.replaceFirst("%s",
1141 mpCurrentViewShellBase->GetDocShell()->GetTitle(SFX_TITLE_DETECT));
1142 pWorkWindow->SetText(Title);
1143 pWorkWindow->StartPresentationMode( true, mpDoc->getPresentationSettings().mbAlwaysOnTop ? PresentationFlags::HideAllApps : PresentationFlags::NONE, nDisplay);
1144 // pWorkWindow->ShowFullScreenMode(sal_False, nDisplay);
1146 if (!pWorkWindow->IsVisible())
1147 return;
1149 // Initialize the new presentation view shell with a copy of the
1150 // frame view of the current view shell. This avoids that
1151 // changes made by the presentation have an effect on the other
1152 // view shells.
1153 FrameView* pOriginalFrameView = nullptr;
1154 ::std::shared_ptr<ViewShell> xShell(mpCurrentViewShellBase->GetMainViewShell());
1155 if (xShell)
1156 pOriginalFrameView = xShell->GetFrameView();
1158 delete mpFullScreenFrameView;
1159 mpFullScreenFrameView = new FrameView(mpDoc, pOriginalFrameView);
1161 // The new frame is created hidden. To make it visible and activate the
1162 // new view shell--a prerequisite to process slot calls and initialize
1163 // its panes--a GrabFocus() has to be called later on.
1164 SfxFrame* pNewFrame = SfxFrame::CreateHidden( *mpDoc->GetDocSh(), *pWorkWindow, PRESENTATION_FACTORY_ID );
1165 pNewFrame->SetPresentationMode(true);
1167 mpFullScreenViewShellBase = static_cast<ViewShellBase*>(pNewFrame->GetCurrentViewFrame()->GetViewShell());
1168 if(mpFullScreenViewShellBase != nullptr)
1170 // The following GrabFocus() is responsible for activating the
1171 // new view shell. Without it the screen remains blank (under
1172 // Windows and some Linux variants.)
1173 mpFullScreenViewShellBase->GetWindow()->GrabFocus();
1177 /// convert configuration setting display concept to real screens
1178 sal_Int32 SlideShow::GetDisplay()
1180 sal_Int32 nDisplay = 0;
1182 SdOptions* pOptions = SD_MOD()->GetSdOptions(DocumentType::Impress);
1183 if( pOptions )
1184 nDisplay = pOptions->GetDisplay();
1186 if( nDisplay < 0 )
1187 nDisplay = -1;
1188 else if( nDisplay == 0)
1189 nDisplay = static_cast<sal_Int32>(Application::GetDisplayExternalScreen());
1190 else
1191 nDisplay--;
1193 SAL_INFO("sd", "Presenting on real screen " << nDisplay);
1195 return nDisplay;
1198 bool SlideShow::dependsOn( ViewShellBase const * pViewShellBase )
1200 return mxController.is() && (pViewShellBase == mpCurrentViewShellBase) && mpFullScreenViewShellBase;
1203 Reference< presentation::XPresentation2 > CreatePresentation( const SdDrawDocument& rDocument )
1205 return Reference< presentation::XPresentation2 >( SlideShow::Create( const_cast< SdDrawDocument* >( &rDocument ) ) );
1208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */