1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <cppuhelper/bootstrap.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 <svl/itemprop.hxx>
33 #include <tools/debug.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/sfxsids.hrc>
39 #include <svx/unoprov.hxx>
41 #include <framework/FrameworkHelper.hxx>
43 #include <FrameView.hxx>
44 #include <createpresentation.hxx>
45 #include <unomodel.hxx>
46 #include <slideshow.hxx>
47 #include "slideshowimpl.hxx"
50 #include <FactoryIds.hxx>
51 #include <DrawDocShell.hxx>
52 #include <ViewShell.hxx>
53 #include <ViewShellBase.hxx>
54 #include "SlideShowRestarter.hxx"
55 #include <DrawController.hxx>
56 #include <PresentationViewShell.hxx>
57 #include <customshowlist.hxx>
58 #include <unopage.hxx>
60 #include <cusshow.hxx>
61 #include <optsitem.hxx>
62 #include <strings.hrc>
63 #include <sdresid.hxx>
65 using ::com::sun::star::presentation::XSlideShowController
;
66 using ::sd::framework::FrameworkHelper
;
67 using ::com::sun::star::awt::XWindow
;
69 using namespace ::cppu
;
70 using namespace ::com::sun::star
;
71 using namespace ::com::sun::star::uno
;
72 using namespace ::com::sun::star::drawing
;
73 using namespace ::com::sun::star::beans
;
74 using namespace ::com::sun::star::lang
;
75 using namespace ::com::sun::star::animations
;
76 using namespace ::com::sun::star::drawing::framework
;
79 /** This local version of the work window overrides DataChanged() so that it
80 can restart the slide show when a display is added or removed.
82 class FullScreenWorkWindow
: public WorkWindow
85 FullScreenWorkWindow (
86 const ::rtl::Reference
<SlideShow
>& rpSlideShow
,
87 ViewShellBase
* pViewShellBase
)
88 : WorkWindow(nullptr, WB_HIDE
| WB_CLIPCHILDREN
),
89 mpRestarter(new SlideShowRestarter(rpSlideShow
, pViewShellBase
))
92 void Restart(bool bForce
)
94 mpRestarter
->Restart(bForce
);
97 virtual void DataChanged (const DataChangedEvent
& rEvent
) override
99 if (rEvent
.GetType() == DataChangedEventType::DISPLAY
)
104 ::std::shared_ptr
<SlideShowRestarter
> mpRestarter
;
108 static const SfxItemPropertyMapEntry
* ImplGetPresentationPropertyMap()
110 // NOTE: First member must be sorted
111 static const SfxItemPropertyMapEntry aPresentationPropertyMap_Impl
[] =
113 { OUString("AllowAnimations"), ATTR_PRESENT_ANIMATION_ALLOWED
, cppu::UnoType
<bool>::get(), 0, 0 },
114 { OUString("CustomShow"), ATTR_PRESENT_CUSTOMSHOW
, ::cppu::UnoType
<OUString
>::get(), 0, 0 },
115 { OUString("Display"), ATTR_PRESENT_DISPLAY
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
116 { OUString("FirstPage"), ATTR_PRESENT_DIANAME
, ::cppu::UnoType
<OUString
>::get(), 0, 0 },
117 { OUString("IsAlwaysOnTop"), ATTR_PRESENT_ALWAYS_ON_TOP
, cppu::UnoType
<bool>::get(), 0, 0 },
118 { OUString("IsAutomatic"), ATTR_PRESENT_MANUEL
, cppu::UnoType
<bool>::get(), 0, 0 },
119 { OUString("IsEndless"), ATTR_PRESENT_ENDLESS
, cppu::UnoType
<bool>::get(), 0, 0 },
120 { OUString("IsFullScreen"), ATTR_PRESENT_FULLSCREEN
, cppu::UnoType
<bool>::get(), 0, 0 },
121 { OUString("IsShowAll"), ATTR_PRESENT_ALL
, cppu::UnoType
<bool>::get(), 0, 0 },
122 { OUString("IsMouseVisible"), ATTR_PRESENT_MOUSE
, cppu::UnoType
<bool>::get(), 0, 0 },
123 { OUString("IsShowLogo"), ATTR_PRESENT_SHOW_PAUSELOGO
, cppu::UnoType
<bool>::get(), 0, 0 },
124 { OUString("IsTransitionOnClick"), ATTR_PRESENT_CHANGE_PAGE
, cppu::UnoType
<bool>::get(), 0, 0 },
125 { OUString("Pause"), ATTR_PRESENT_PAUSE_TIMEOUT
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
126 { OUString("StartWithNavigator"), ATTR_PRESENT_NAVIGATOR
, cppu::UnoType
<bool>::get(), 0, 0 },
127 { OUString("UsePen"), ATTR_PRESENT_PEN
, cppu::UnoType
<bool>::get(), 0, 0 },
128 { OUString(), 0, css::uno::Type(), 0, 0 }
131 return aPresentationPropertyMap_Impl
;
136 SlideShow::SlideShow( SdDrawDocument
* pDoc
)
137 : SlideshowBase( m_aMutex
)
138 , maPropSet(ImplGetPresentationPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool())
139 , mbIsInStartup(false)
141 , mpCurrentViewShellBase( nullptr )
142 , mpFullScreenViewShellBase( nullptr )
143 , mpFullScreenFrameView( nullptr )
144 , mnInPlaceConfigEvent( nullptr )
148 void SlideShow::ThrowIfDisposed() const
150 if( mpDoc
== nullptr )
151 throw DisposedException();
154 /// used by the model to create a slideshow for it
155 rtl::Reference
< SlideShow
> SlideShow::Create( SdDrawDocument
* pDoc
)
157 return new SlideShow( pDoc
);
160 rtl::Reference
< SlideShow
> SlideShow::GetSlideShow( SdDrawDocument
const * pDocument
)
162 rtl::Reference
< SlideShow
> xRet
;
165 xRet
= GetSlideShow( *pDocument
);
170 rtl::Reference
< SlideShow
> SlideShow::GetSlideShow( SdDrawDocument
const & rDocument
)
172 return rtl::Reference
< SlideShow
>(
173 dynamic_cast< SlideShow
* >( rDocument
.getPresentation().get() ) );
176 rtl::Reference
< SlideShow
> SlideShow::GetSlideShow( ViewShellBase
const & rBase
)
178 return GetSlideShow( rBase
.GetDocument() );
181 css::uno::Reference
< css::presentation::XSlideShowController
> SlideShow::GetSlideShowController(ViewShellBase
const & rBase
)
183 rtl::Reference
< SlideShow
> xSlideShow( GetSlideShow( rBase
) );
185 Reference
< XSlideShowController
> xRet
;
186 if( xSlideShow
.is() )
187 xRet
= xSlideShow
->getController();
192 bool SlideShow::StartPreview( ViewShellBase
const & rBase
,
193 const css::uno::Reference
< css::drawing::XDrawPage
>& xDrawPage
,
194 const css::uno::Reference
< css::animations::XAnimationNode
>& xAnimationNode
)
196 rtl::Reference
< SlideShow
> xSlideShow( GetSlideShow( rBase
) );
197 if( !xSlideShow
.is() )
200 xSlideShow
->startPreview( xDrawPage
, xAnimationNode
);
204 void SlideShow::Stop( ViewShellBase
const & rBase
)
206 rtl::Reference
< SlideShow
> xSlideShow( GetSlideShow( rBase
) );
207 if( xSlideShow
.is() )
211 bool SlideShow::IsRunning( ViewShellBase
const & rBase
)
213 rtl::Reference
< SlideShow
> xSlideShow( GetSlideShow( rBase
) );
214 return xSlideShow
.is() && xSlideShow
->isRunning();
217 bool SlideShow::IsRunning( ViewShell
& rViewShell
)
219 rtl::Reference
< SlideShow
> xSlideShow( GetSlideShow( rViewShell
.GetViewShellBase() ) );
220 return xSlideShow
.is() && xSlideShow
->isRunning() && (xSlideShow
->mxController
->getViewShell() == &rViewShell
);
223 void SlideShow::CreateController( ViewShell
* pViewSh
, ::sd::View
* pView
, vcl::Window
* pParentWindow
)
225 SAL_INFO_IF( !mxController
.is(), "sd.slideshow", "sd::SlideShow::CreateController(), clean up old controller first!" );
227 Reference
< XPresentation2
> xThis( this );
229 rtl::Reference
<SlideshowImpl
> xController (
230 new SlideshowImpl(xThis
, pViewSh
, pView
, mpDoc
, pParentWindow
));
232 // Reset mbIsInStartup. From here mxController.is() is used to prevent
233 // multiple slide show instances for one document.
234 mxController
= xController
;
235 mbIsInStartup
= false;
240 OUString SAL_CALL
SlideShow::getImplementationName( )
242 return OUString( "com.sun.star.comp.sd.SlideShow" );
245 sal_Bool SAL_CALL
SlideShow::supportsService( const OUString
& ServiceName
)
247 return cppu::supportsService( this, ServiceName
);
250 Sequence
< OUString
> SAL_CALL
SlideShow::getSupportedServiceNames( )
252 OUString
aService( "com.sun.star.presentation.Presentation" );
253 Sequence
< OUString
> aSeq( &aService
, 1 );
258 Reference
< XPropertySetInfo
> SAL_CALL
SlideShow::getPropertySetInfo()
260 SolarMutexGuard aGuard
;
261 static Reference
< XPropertySetInfo
> xInfo
= maPropSet
.getPropertySetInfo();
265 void SAL_CALL
SlideShow::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
)
267 SolarMutexGuard aGuard
;
270 sd::PresentationSettings
& rPresSettings
= mpDoc
->getPresentationSettings();
272 const SfxItemPropertySimpleEntry
* pEntry
= maPropSet
.getPropertyMapEntry(aPropertyName
);
274 if( pEntry
&& ((pEntry
->nFlags
& PropertyAttribute::READONLY
) != 0) )
275 throw PropertyVetoException();
277 bool bValuesChanged
= false;
278 bool bIllegalArgument
= true;
280 switch( pEntry
? pEntry
->nWID
: -1 )
282 case ATTR_PRESENT_ALL
:
286 if( aValue
>>= bVal
)
288 bIllegalArgument
= false;
290 if( rPresSettings
.mbAll
!= bVal
)
292 rPresSettings
.mbAll
= bVal
;
293 bValuesChanged
= true;
295 rPresSettings
.mbCustomShow
= false;
300 case ATTR_PRESENT_CHANGE_PAGE
:
304 if( aValue
>>= bVal
)
306 bIllegalArgument
= false;
308 if( bVal
== rPresSettings
.mbLockedPages
)
310 bValuesChanged
= true;
311 rPresSettings
.mbLockedPages
= !bVal
;
317 case ATTR_PRESENT_ANIMATION_ALLOWED
:
321 if( aValue
>>= bVal
)
323 bIllegalArgument
= false;
325 if(rPresSettings
.mbAnimationAllowed
!= bVal
)
327 bValuesChanged
= true;
328 rPresSettings
.mbAnimationAllowed
= bVal
;
333 case ATTR_PRESENT_CUSTOMSHOW
:
336 if( aValue
>>= aShowName
)
338 bIllegalArgument
= false;
340 SdCustomShowList
* pCustomShowList
= mpDoc
->GetCustomShowList();
343 SdCustomShow
* pCustomShow
;
344 for( pCustomShow
= pCustomShowList
->First(); pCustomShow
!= nullptr; pCustomShow
= pCustomShowList
->Next() )
346 if( pCustomShow
->GetName() == aShowName
)
350 rPresSettings
.mbCustomShow
= true;
351 bValuesChanged
= true;
356 case ATTR_PRESENT_ENDLESS
:
360 if( aValue
>>= bVal
)
362 bIllegalArgument
= false;
364 if( rPresSettings
.mbEndless
!= bVal
)
366 bValuesChanged
= true;
367 rPresSettings
.mbEndless
= bVal
;
372 case ATTR_PRESENT_FULLSCREEN
:
376 if( aValue
>>= bVal
)
378 bIllegalArgument
= false;
379 if( rPresSettings
.mbFullScreen
!= bVal
)
381 bValuesChanged
= true;
382 rPresSettings
.mbFullScreen
= bVal
;
387 case ATTR_PRESENT_DIANAME
:
390 aValue
>>= aPresPage
;
391 bIllegalArgument
= false;
392 if( (rPresSettings
.maPresPage
!= aPresPage
) || !rPresSettings
.mbCustomShow
|| !rPresSettings
.mbAll
)
394 bValuesChanged
= true;
395 rPresSettings
.maPresPage
= getUiNameFromPageApiNameImpl(aPresPage
);
396 rPresSettings
.mbCustomShow
= false;
397 rPresSettings
.mbAll
= false;
401 case ATTR_PRESENT_MANUEL
:
405 if( aValue
>>= bVal
)
407 bIllegalArgument
= false;
409 if( rPresSettings
.mbManual
!= bVal
)
411 bValuesChanged
= true;
412 rPresSettings
.mbManual
= bVal
;
417 case ATTR_PRESENT_MOUSE
:
421 if( aValue
>>= bVal
)
423 bIllegalArgument
= false;
424 if( rPresSettings
.mbMouseVisible
!= bVal
)
426 bValuesChanged
= true;
427 rPresSettings
.mbMouseVisible
= bVal
;
432 case ATTR_PRESENT_ALWAYS_ON_TOP
:
436 if( aValue
>>= bVal
)
438 bIllegalArgument
= false;
440 if( rPresSettings
.mbAlwaysOnTop
!= bVal
)
442 bValuesChanged
= true;
443 rPresSettings
.mbAlwaysOnTop
= bVal
;
448 case ATTR_PRESENT_NAVIGATOR
:
449 bIllegalArgument
= false;
450 //ignored, but exists in some older documents
452 case ATTR_PRESENT_PEN
:
456 if( aValue
>>= bVal
)
458 bIllegalArgument
= false;
460 if(rPresSettings
.mbMouseAsPen
!= bVal
)
462 bValuesChanged
= true;
463 rPresSettings
.mbMouseAsPen
= bVal
;
468 case ATTR_PRESENT_PAUSE_TIMEOUT
:
470 sal_Int32 nValue
= 0;
471 if( (aValue
>>= nValue
) && (nValue
>= 0) )
473 bIllegalArgument
= false;
474 if( rPresSettings
.mnPauseTimeout
!= nValue
)
476 bValuesChanged
= true;
477 rPresSettings
.mnPauseTimeout
= nValue
;
482 case ATTR_PRESENT_SHOW_PAUSELOGO
:
486 if( aValue
>>= bVal
)
488 bIllegalArgument
= false;
490 if( rPresSettings
.mbShowPauseLogo
!= bVal
)
492 bValuesChanged
= true;
493 rPresSettings
.mbShowPauseLogo
= bVal
;
498 case ATTR_PRESENT_DISPLAY
:
500 sal_Int32 nDisplay
= 0;
501 if( aValue
>>= nDisplay
)
503 bIllegalArgument
= false;
505 SdOptions
* pOptions
= SD_MOD()->GetSdOptions(DocumentType::Impress
);
506 pOptions
->SetDisplay( nDisplay
);
508 FullScreenWorkWindow
*pWin
= dynamic_cast<FullScreenWorkWindow
*>(GetWorkWindow());
517 throw UnknownPropertyException( OUString::number(pEntry
? pEntry
->nWID
: -1), static_cast<cppu::OWeakObject
*>(this));
520 if( bIllegalArgument
)
521 throw IllegalArgumentException();
527 Any SAL_CALL
SlideShow::getPropertyValue( const OUString
& PropertyName
)
529 SolarMutexGuard aGuard
;
532 const sd::PresentationSettings
& rPresSettings
= mpDoc
->getPresentationSettings();
534 const SfxItemPropertySimpleEntry
* pEntry
= maPropSet
.getPropertyMapEntry(PropertyName
);
536 switch( pEntry
? pEntry
->nWID
: -1 )
538 case ATTR_PRESENT_ALL
:
539 return Any( !rPresSettings
.mbCustomShow
&& rPresSettings
.mbAll
);
540 case ATTR_PRESENT_CHANGE_PAGE
:
541 return Any( !rPresSettings
.mbLockedPages
);
542 case ATTR_PRESENT_ANIMATION_ALLOWED
:
543 return Any( rPresSettings
.mbAnimationAllowed
);
544 case ATTR_PRESENT_CUSTOMSHOW
:
546 SdCustomShowList
* pList
= mpDoc
->GetCustomShowList();
547 SdCustomShow
* pShow
= (pList
&& rPresSettings
.mbCustomShow
) ? pList
->GetCurObject() : nullptr;
551 aShowName
= pShow
->GetName();
553 return Any( aShowName
);
555 case ATTR_PRESENT_ENDLESS
:
556 return Any( rPresSettings
.mbEndless
);
557 case ATTR_PRESENT_FULLSCREEN
:
558 return Any( rPresSettings
.mbFullScreen
);
559 case ATTR_PRESENT_DIANAME
:
563 if( !rPresSettings
.mbCustomShow
&& !rPresSettings
.mbAll
)
564 aSlideName
= getPageApiNameFromUiName( rPresSettings
.maPresPage
);
566 return Any( aSlideName
);
568 case ATTR_PRESENT_MANUEL
:
569 return Any( rPresSettings
.mbManual
);
570 case ATTR_PRESENT_MOUSE
:
571 return Any( rPresSettings
.mbMouseVisible
);
572 case ATTR_PRESENT_ALWAYS_ON_TOP
:
573 return Any( rPresSettings
.mbAlwaysOnTop
);
574 case ATTR_PRESENT_NAVIGATOR
:
576 case ATTR_PRESENT_PEN
:
577 return Any( rPresSettings
.mbMouseAsPen
);
578 case ATTR_PRESENT_PAUSE_TIMEOUT
:
579 return Any( rPresSettings
.mnPauseTimeout
);
580 case ATTR_PRESENT_SHOW_PAUSELOGO
:
581 return Any( rPresSettings
.mbShowPauseLogo
);
582 case ATTR_PRESENT_DISPLAY
:
584 SdOptions
* pOptions
= SD_MOD()->GetSdOptions(DocumentType::Impress
);
585 return Any(pOptions
->GetDisplay());
589 throw UnknownPropertyException( OUString::number(pEntry
? pEntry
->nWID
: -1), static_cast<cppu::OWeakObject
*>(this));
593 void SAL_CALL
SlideShow::addPropertyChangeListener( const OUString
& , const Reference
< XPropertyChangeListener
>& )
597 void SAL_CALL
SlideShow::removePropertyChangeListener( const OUString
& , const Reference
< XPropertyChangeListener
>& )
601 void SAL_CALL
SlideShow::addVetoableChangeListener( const OUString
& , const Reference
< XVetoableChangeListener
>& )
605 void SAL_CALL
SlideShow::removeVetoableChangeListener( const OUString
& , const Reference
< XVetoableChangeListener
>& )
611 void SAL_CALL
SlideShow::start()
613 const Sequence
< PropertyValue
> aArguments
;
614 startWithArguments( aArguments
);
617 WorkWindow
*SlideShow::GetWorkWindow()
619 if( !mpFullScreenViewShellBase
)
622 PresentationViewShell
* pShell
= dynamic_cast<PresentationViewShell
*>(mpFullScreenViewShellBase
->GetMainViewShell().get());
624 if( !pShell
|| !pShell
->GetViewFrame() )
627 return dynamic_cast<WorkWindow
*>(pShell
->GetViewFrame()->GetFrame().GetWindow().GetParent());
630 bool SlideShow::IsExitAfterPresenting() const
632 SolarMutexGuard aGuard
;
634 return mpDoc
->IsExitAfterPresenting();
637 void SlideShow::SetExitAfterPresenting(bool bExit
)
639 SolarMutexGuard aGuard
;
641 mpDoc
->SetExitAfterPresenting(bExit
);
644 void SAL_CALL
SlideShow::end()
646 SolarMutexGuard aGuard
;
648 // The mbIsInStartup flag should have been reset during the start of the
649 // slide show. Reset it here just in case that something has horribly
651 assert(!mbIsInStartup
);
653 rtl::Reference
< SlideshowImpl
> xController( mxController
);
654 if( !xController
.is() )
657 mxController
.clear();
659 if( mpFullScreenFrameView
)
661 delete mpFullScreenFrameView
;
662 mpFullScreenFrameView
= nullptr;
665 ViewShellBase
* pFullScreenViewShellBase
= mpFullScreenViewShellBase
;
666 mpFullScreenViewShellBase
= nullptr;
668 // dispose before fullscreen window changes screens
669 // (potentially). If this needs to be moved behind
670 // pWorkWindow->StartPresentationMode() again, read issue
671 // pWorkWindow->i94007 & implement the solution outlined
673 xController
->dispose();
675 if( pFullScreenViewShellBase
)
677 PresentationViewShell
* pShell
= dynamic_cast<PresentationViewShell
*>(pFullScreenViewShellBase
->GetMainViewShell().get());
679 if( pShell
&& pShell
->GetViewFrame() )
681 WorkWindow
* pWorkWindow
= dynamic_cast<WorkWindow
*>(pShell
->GetViewFrame()->GetFrame().GetWindow().GetParent());
684 pWorkWindow
->StartPresentationMode( (mxController
.is() && mxController
->maPresSettings
.mbAlwaysOnTop
)
685 ? PresentationFlags::HideAllApps
: PresentationFlags::NONE
);
690 if( pFullScreenViewShellBase
)
692 PresentationViewShell
* pShell
= nullptr;
694 // Get the shell pointer in its own scope to be sure that
695 // the shared_ptr to the shell is released before DoClose()
697 ::std::shared_ptr
<ViewShell
> pSharedView (pFullScreenViewShellBase
->GetMainViewShell());
698 pShell
= dynamic_cast<PresentationViewShell
*>(pSharedView
.get());
700 if( pShell
&& pShell
->GetViewFrame() )
701 pShell
->GetViewFrame()->DoClose();
703 else if( mpCurrentViewShellBase
)
705 ViewShell
* pViewShell
= mpCurrentViewShellBase
->GetMainViewShell().get();
709 FrameView
* pFrameView
= pViewShell
->GetFrameView();
711 if( pFrameView
&& (pFrameView
->GetPresentationViewShellId() != SID_VIEWSHELL0
) )
713 ViewShell::ShellType
ePreviousType (pFrameView
->GetPreviousViewShellType());
714 pFrameView
->SetPreviousViewShellType(ViewShell::ST_NONE
);
716 pFrameView
->SetPresentationViewShellId(SID_VIEWSHELL0
);
717 pFrameView
->SetPreviousViewShellType(pViewShell
->GetShellType());
719 framework::FrameworkHelper::Instance(*mpCurrentViewShellBase
)->RequestView(
720 framework::FrameworkHelper::GetViewURL(ePreviousType
),
721 framework::FrameworkHelper::msCenterPaneURL
);
723 pViewShell
->GetViewFrame()->GetBindings().InvalidateAll( true );
728 if( mpCurrentViewShellBase
)
730 if (ViewShell
* const pViewShell
= mpCurrentViewShellBase
->GetMainViewShell().get())
732 // invalidate the view shell so the presentation slot will be re-enabled
733 // and the rehearsing will be updated
734 pViewShell
->Invalidate();
736 if( xController
->meAnimationMode
==ANIMATIONMODE_SHOW
)
738 // switch to the previously visible Slide
739 DrawViewShell
* pDrawViewShell
= dynamic_cast<DrawViewShell
*>( pViewShell
);
741 pDrawViewShell
->SwitchPage( static_cast<sal_uInt16
>(xController
->getRestoreSlide()) );
744 Reference
<XDrawView
> xDrawView (
745 Reference
<XWeak
>(&mpCurrentViewShellBase
->GetDrawController()), UNO_QUERY
);
747 xDrawView
->setCurrentPage(
748 Reference
<XDrawPage
>(
749 mpDoc
->GetSdPage(xController
->getRestoreSlide(), PageKind::Standard
)->getUnoPage(),
754 if( pViewShell
->GetDoc()->IsExitAfterPresenting() )
756 pViewShell
->GetDoc()->SetExitAfterPresenting( false );
758 Reference
<frame::XDispatchProvider
> xProvider(pViewShell
->GetViewShellBase().GetController()->getFrame(),
763 aURL
.Complete
= ".uno:CloseFrame";
765 uno::Reference
< frame::XDispatch
> xDispatch(
766 xProvider
->queryDispatch(
767 aURL
, OUString(), 0));
770 xDispatch
->dispatch(aURL
,
771 uno::Sequence
< beans::PropertyValue
>());
776 // Fire the acc focus event when focus is switched back. The above method
777 // mpCurrentViewShellBase->GetWindow()->GrabFocus() will set focus to WorkWindow
778 // instead of the sd::window, so here call Shell's method to fire the focus event
779 pViewShell
->SwitchActiveViewFireFocus();
782 mpCurrentViewShellBase
= nullptr;
785 void SAL_CALL
SlideShow::rehearseTimings()
787 Sequence
< PropertyValue
> aArguments(1);
788 aArguments
[0].Name
= "RehearseTimings";
789 aArguments
[0].Value
<<= true;
790 startWithArguments( aArguments
);
795 void SAL_CALL
SlideShow::startWithArguments(const Sequence
< PropertyValue
>& rArguments
)
797 SolarMutexGuard aGuard
;
800 // Stop a running show before starting a new one.
801 if( mxController
.is() )
803 assert(!mbIsInStartup
);
806 else if (mbIsInStartup
)
808 // We are already somewhere in process of starting a slide show but
809 // have not yet got to the point where mxController is set. There
810 // is not yet a slide show to end so return silently.
814 // Prevent multiple instance of the SlideShow class for one document.
815 mbIsInStartup
= true;
817 mxCurrentSettings
.reset( new PresentationSettingsEx( mpDoc
->getPresentationSettings() ) );
818 mxCurrentSettings
->SetArguments( rArguments
);
820 // if there is no view shell base set, use the current one or the first using this document
821 if( mpCurrentViewShellBase
== nullptr )
823 // first check current
824 ::sd::ViewShellBase
* pBase
= ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::Current() );
825 if( pBase
&& pBase
->GetDocument() == mpDoc
)
827 mpCurrentViewShellBase
= pBase
;
831 // current is not ours, so get first from ours
832 mpCurrentViewShellBase
= ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::GetFirst( mpDoc
->GetDocSh() ) );
836 // #i118456# make sure TextEdit changes get pushed to model.
837 // mpDrawView is tested against NULL above already.
838 if(mpCurrentViewShellBase
)
840 ViewShell
* pViewShell
= mpCurrentViewShellBase
->GetMainViewShell().get();
842 if(pViewShell
&& pViewShell
->GetView())
844 pViewShell
->GetView()->SdrEndTextEdit();
848 // Start either a full-screen or an in-place show.
849 if(mxCurrentSettings
->mbFullScreen
&& !mxCurrentSettings
->mbPreview
)
850 StartFullscreenPresentation();
852 StartInPlacePresentation();
856 sal_Bool SAL_CALL
SlideShow::isRunning( )
858 SolarMutexGuard aGuard
;
859 return mxController
.is() && mxController
->isRunning();
862 Reference
< XSlideShowController
> SAL_CALL
SlideShow::getController( )
866 Reference
< XSlideShowController
> xController( mxController
.get() );
872 void SAL_CALL
SlideShow::disposing()
874 SolarMutexGuard aGuard
;
876 if( mnInPlaceConfigEvent
)
878 Application::RemoveUserEvent( mnInPlaceConfigEvent
);
879 mnInPlaceConfigEvent
= nullptr;
882 if( mxController
.is() )
884 mxController
->dispose();
885 mxController
.clear();
888 mpCurrentViewShellBase
= nullptr;
889 mpFullScreenViewShellBase
= nullptr;
893 void SlideShow::startPreview( const Reference
< XDrawPage
>& xDrawPage
, const Reference
< XAnimationNode
>& xAnimationNode
)
895 Sequence
< PropertyValue
> aArguments(4);
897 aArguments
[0].Name
= "Preview";
898 aArguments
[0].Value
<<= true;
900 aArguments
[1].Name
= "FirstPage";
901 aArguments
[1].Value
<<= xDrawPage
;
903 aArguments
[2].Name
= "AnimationNode";
904 aArguments
[2].Value
<<= xAnimationNode
;
906 aArguments
[3].Name
= "ParentWindow";
907 aArguments
[3].Value
<<= Reference
< XWindow
>();
909 startWithArguments( aArguments
);
912 OutputDevice
* SlideShow::getShowWindow()
914 return mxController
.is() ? mxController
->mpShowWindow
.get() : nullptr;
917 int SlideShow::getAnimationMode()
919 return mxController
.is() ? mxController
->meAnimationMode
: ANIMATIONMODE_SHOW
;
922 void SlideShow::jumpToPageIndex( sal_Int32 nPageIndex
)
924 if( mxController
.is() )
925 mxController
->displaySlideIndex( nPageIndex
);
928 void SlideShow::jumpToPageNumber( sal_Int32 nPageNumber
)
930 if( mxController
.is() )
931 mxController
->displaySlideNumber( nPageNumber
);
934 sal_Int32
SlideShow::getCurrentPageNumber()
936 return mxController
.is() ? mxController
->getCurrentSlideNumber() : 0;
939 void SlideShow::jumpToBookmark( const OUString
& sBookmark
)
941 if( mxController
.is() )
942 mxController
->jumpToBookmark( sBookmark
);
945 bool SlideShow::isFullScreen()
947 return mxController
.is() && mxController
->maPresSettings
.mbFullScreen
;
950 void SlideShow::resize( const Size
&rSize
)
952 if( mxController
.is() )
953 mxController
->resize( rSize
);
956 void SlideShow::activate( ViewShellBase
& rBase
)
958 if( (mpFullScreenViewShellBase
== &rBase
) && !mxController
.is() )
960 ::std::shared_ptr
<PresentationViewShell
> pShell
= std::dynamic_pointer_cast
<PresentationViewShell
>(rBase
.GetMainViewShell());
961 if (pShell
!= nullptr)
963 pShell
->FinishInitialization( mpFullScreenFrameView
);
964 mpFullScreenFrameView
= nullptr;
966 CreateController( pShell
.get(), pShell
->GetView(), rBase
.GetViewWindow() );
968 if( mxController
->startShow(mxCurrentSettings
.get()) )
971 // Defer the sd::ShowWindow's GrabFocus to here. so that the accessible event can be fired correctly.
972 pShell
->GetActiveWindow()->GrabFocus();
982 if( mxController
.is() )
983 mxController
->activate();
987 void SlideShow::deactivate()
989 mxController
->deactivate();
992 bool SlideShow::keyInput(const KeyEvent
& rKEvt
)
994 return mxController
.is() && mxController
->keyInput(rKEvt
);
997 void SlideShow::paint()
999 if( mxController
.is() )
1000 mxController
->paint();
1003 void SlideShow::pause( bool bPause
)
1005 if( mxController
.is() )
1008 mxController
->pause();
1010 mxController
->resume();
1014 bool SlideShow::swipe(const CommandSwipeData
& rSwipeData
)
1016 return mxController
.is() && mxController
->swipe(rSwipeData
);
1019 bool SlideShow::longpress(const CommandLongPressData
& rLongPressData
)
1021 return mxController
.is() && mxController
->longpress(rLongPressData
);
1024 void SlideShow::StartInPlacePresentationConfigurationCallback()
1026 if( mnInPlaceConfigEvent
!= nullptr )
1027 Application::RemoveUserEvent( mnInPlaceConfigEvent
);
1029 mnInPlaceConfigEvent
= Application::PostUserEvent( LINK( this, SlideShow
, StartInPlacePresentationConfigurationHdl
) );
1032 IMPL_LINK_NOARG(SlideShow
, StartInPlacePresentationConfigurationHdl
, void*, void)
1034 mnInPlaceConfigEvent
= nullptr;
1035 StartInPlacePresentation();
1038 void SlideShow::StartInPlacePresentation()
1040 if( mpCurrentViewShellBase
)
1042 // Save the current view shell type so that it can be restored after the
1043 // show has ended. If there already is a saved shell type then that is
1046 ViewShell::ShellType eShell
= ViewShell::ST_NONE
;
1048 ::std::shared_ptr
<FrameworkHelper
> pHelper(FrameworkHelper::Instance(*mpCurrentViewShellBase
));
1049 ::std::shared_ptr
<ViewShell
> pMainViewShell(pHelper
->GetViewShell(FrameworkHelper::msCenterPaneURL
));
1051 if( pMainViewShell
.get() )
1052 eShell
= pMainViewShell
->GetShellType();
1054 if( eShell
!= ViewShell::ST_IMPRESS
)
1056 // Switch temporary to a DrawViewShell which supports the in-place presentation.
1058 if( pMainViewShell
.get() )
1060 FrameView
* pFrameView
= pMainViewShell
->GetFrameView();
1061 pFrameView
->SetPresentationViewShellId(SID_VIEWSHELL1
);
1062 pFrameView
->SetPreviousViewShellType (pMainViewShell
->GetShellType());
1063 pFrameView
->SetPageKind (PageKind::Standard
);
1066 pHelper
->RequestView( FrameworkHelper::msImpressViewURL
, FrameworkHelper::msCenterPaneURL
);
1067 pHelper
->RunOnConfigurationEvent(
1068 FrameworkHelper::msConfigurationUpdateEndEvent
,
1069 [this] (bool const) { return this->StartInPlacePresentationConfigurationCallback(); } );
1074 vcl::Window
* pParentWindow
= mxCurrentSettings
->mpParentWindow
;
1075 if( pParentWindow
== nullptr )
1076 pParentWindow
= mpCurrentViewShellBase
->GetViewWindow();
1078 CreateController( pMainViewShell
.get(), pMainViewShell
->GetView(), pParentWindow
);
1081 else if( mxCurrentSettings
->mpParentWindow
)
1083 // no current view shell, but parent window
1084 CreateController( nullptr, nullptr, mxCurrentSettings
->mpParentWindow
);
1087 if( !mxController
.is() )
1090 bool bSuccess
= false;
1091 if( mxCurrentSettings
.get() && mxCurrentSettings
->mbPreview
)
1093 bSuccess
= mxController
->startPreview(mxCurrentSettings
->mxStartPage
, mxCurrentSettings
->mxAnimationNode
, mxCurrentSettings
->mpParentWindow
);
1097 bSuccess
= mxController
->startShow(mxCurrentSettings
.get());
1104 if( mpCurrentViewShellBase
&& ( !mxCurrentSettings
.get() || ( mxCurrentSettings
.get() && !mxCurrentSettings
->mbPreview
) ) )
1105 mpCurrentViewShellBase
->GetWindow()->GrabFocus();
1109 void SlideShow::StartFullscreenPresentation( )
1111 // Create the top level window in which the PresentationViewShell(Base)
1112 // will be created. This is done here explicitly so that we can make it
1114 const sal_Int32
nDisplay (GetDisplay());
1115 VclPtr
<WorkWindow
> pWorkWindow
= VclPtr
<FullScreenWorkWindow
>::Create(this, mpCurrentViewShellBase
);
1116 pWorkWindow
->SetBackground(Wallpaper(COL_BLACK
));
1117 OUString
Title(SdResId(STR_FULLSCREEN_SLIDESHOW
));
1118 Title
= Title
.replaceFirst("%s",
1119 mpCurrentViewShellBase
->GetDocShell()->GetTitle(SFX_TITLE_DETECT
));
1120 pWorkWindow
->SetText(Title
);
1121 pWorkWindow
->StartPresentationMode( true, mpDoc
->getPresentationSettings().mbAlwaysOnTop
? PresentationFlags::HideAllApps
: PresentationFlags::NONE
, nDisplay
);
1122 // pWorkWindow->ShowFullScreenMode(sal_False, nDisplay);
1124 if (!pWorkWindow
->IsVisible())
1127 // Initialize the new presentation view shell with a copy of the
1128 // frame view of the current view shell. This avoids that
1129 // changes made by the presentation have an effect on the other
1131 FrameView
* pOriginalFrameView
= nullptr;
1132 ::std::shared_ptr
<ViewShell
> xShell(mpCurrentViewShellBase
->GetMainViewShell());
1134 pOriginalFrameView
= xShell
->GetFrameView();
1136 delete mpFullScreenFrameView
;
1137 mpFullScreenFrameView
= new FrameView(mpDoc
, pOriginalFrameView
);
1139 // The new frame is created hidden. To make it visible and activate the
1140 // new view shell--a prerequisite to process slot calls and initialize
1141 // its panes--a GrabFocus() has to be called later on.
1142 SfxFrame
* pNewFrame
= SfxFrame::CreateHidden( *mpDoc
->GetDocSh(), *pWorkWindow
, PRESENTATION_FACTORY_ID
);
1143 pNewFrame
->SetPresentationMode(true);
1145 mpFullScreenViewShellBase
= static_cast<ViewShellBase
*>(pNewFrame
->GetCurrentViewFrame()->GetViewShell());
1146 if(mpFullScreenViewShellBase
!= nullptr)
1148 // The following GrabFocus() is responsible for activating the
1149 // new view shell. Without it the screen remains blank (under
1150 // Windows and some Linux variants.)
1151 mpFullScreenViewShellBase
->GetWindow()->GrabFocus();
1155 /// convert configuration setting display concept to real screens
1156 sal_Int32
SlideShow::GetDisplay()
1158 sal_Int32 nDisplay
= 0;
1160 SdOptions
* pOptions
= SD_MOD()->GetSdOptions(DocumentType::Impress
);
1162 nDisplay
= pOptions
->GetDisplay();
1166 else if( nDisplay
== 0)
1167 nDisplay
= static_cast<sal_Int32
>(Application::GetDisplayExternalScreen());
1171 SAL_INFO("sd", "Presenting on real screen " << nDisplay
);
1176 bool SlideShow::dependsOn( ViewShellBase
const * pViewShellBase
)
1178 return mxController
.is() && (pViewShellBase
== mpCurrentViewShellBase
) && mpFullScreenViewShellBase
;
1181 Reference
< presentation::XPresentation2
> CreatePresentation( const SdDrawDocument
& rDocument
)
1183 return Reference
< presentation::XPresentation2
>( SlideShow::Create( const_cast< SdDrawDocument
* >( &rDocument
) ).get() );
1186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */