1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
24
25 #include <cppuhelper/supportsservice.hxx>
26
27 #include <sal/log.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/wrkwin.hxx>
30 #include <svx/svdpool.hxx>
31 #include <svx/svdlayer.hxx>
32 #include <svl/itemprop.hxx>
33
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/sfxsids.hrc>
37
38 #include <framework/FrameworkHelper.hxx>
39 #include <comphelper/extract.hxx>
40
41 #include <FrameView.hxx>
42 #include <createpresentation.hxx>
43 #include <unomodel.hxx>
44 #include <slideshow.hxx>
45 #include "slideshowimpl.hxx"
46 #include <sdattr.hrc>
47 #include <sdmod.hxx>
48 #include <FactoryIds.hxx>
49 #include <DrawDocShell.hxx>
50 #include <ViewShell.hxx>
51 #include <ViewShellBase.hxx>
52 #include "SlideShowRestarter.hxx"
53 #include <DrawController.hxx>
54 #include <PresentationViewShell.hxx>
55 #include <customshowlist.hxx>
56 #include <unopage.hxx>
57 #include <sdpage.hxx>
58 #include <cusshow.hxx>
59 #include <optsitem.hxx>
60 #include <strings.hrc>
61 #include <sdresid.hxx>
62
63 using ::com::sun::star::presentation::XSlideShowController;
64 using ::sd::framework::FrameworkHelper;
65 using ::com::sun::star::awt::XWindow;
66 using namespace ::sd;
67 using namespace ::cppu;
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::drawing;
71 using namespace ::com::sun::star::beans;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::animations;
74 using namespace ::com::sun::star::drawing::framework;
75
76 namespace {
77 /** This local version of the work window overrides DataChanged() so that it
78 can restart the slide show when a display is added or removed.
79 */
80 class FullScreenWorkWindow : public WorkWindow
81 {
82 public:
FullScreenWorkWindow(const::rtl::Reference<SlideShow> & rpSlideShow,ViewShellBase * pViewShellBase)83 FullScreenWorkWindow (
84 const ::rtl::Reference<SlideShow>& rpSlideShow,
85 ViewShellBase* pViewShellBase)
86 : WorkWindow(nullptr, WB_HIDE | WB_CLIPCHILDREN),
87 mpRestarter(std::make_shared<SlideShowRestarter>(rpSlideShow, pViewShellBase))
88 {}
89
Restart(bool bForce)90 void Restart(bool bForce)
91 {
92 mpRestarter->Restart(bForce);
93 }
94
DataChanged(const DataChangedEvent & rEvent)95 virtual void DataChanged (const DataChangedEvent& rEvent) override
96 {
97 if (rEvent.GetType() == DataChangedEventType::DISPLAY)
98 Restart(false);
99 }
100
101 private:
102 ::std::shared_ptr<SlideShowRestarter> mpRestarter;
103 };
104 }
105
ImplGetPresentationPropertyMap()106 static const SfxItemPropertyMapEntry* ImplGetPresentationPropertyMap()
107 {
108 // NOTE: First member must be sorted
109 static const SfxItemPropertyMapEntry aPresentationPropertyMap_Impl[] =
110 {
111 { u"AllowAnimations", ATTR_PRESENT_ANIMATION_ALLOWED, cppu::UnoType<bool>::get(), 0, 0 },
112 { u"CustomShow", ATTR_PRESENT_CUSTOMSHOW, ::cppu::UnoType<OUString>::get(), 0, 0 },
113 { u"Display", ATTR_PRESENT_DISPLAY, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
114 { u"FirstPage", ATTR_PRESENT_DIANAME, ::cppu::UnoType<OUString>::get(), 0, 0 },
115 { u"IsAlwaysOnTop", ATTR_PRESENT_ALWAYS_ON_TOP, cppu::UnoType<bool>::get(), 0, 0 },
116 { u"IsAutomatic", ATTR_PRESENT_MANUEL, cppu::UnoType<bool>::get(), 0, 0 },
117 { u"IsEndless", ATTR_PRESENT_ENDLESS, cppu::UnoType<bool>::get(), 0, 0 },
118 { u"IsFullScreen", ATTR_PRESENT_FULLSCREEN, cppu::UnoType<bool>::get(), 0, 0 },
119 { u"IsShowAll", ATTR_PRESENT_ALL, cppu::UnoType<bool>::get(), 0, 0 },
120 { u"IsMouseVisible", ATTR_PRESENT_MOUSE, cppu::UnoType<bool>::get(), 0, 0 },
121 { u"IsShowLogo", ATTR_PRESENT_SHOW_PAUSELOGO, cppu::UnoType<bool>::get(), 0, 0 },
122 { u"IsTransitionOnClick", ATTR_PRESENT_CHANGE_PAGE, cppu::UnoType<bool>::get(), 0, 0 },
123 { u"Pause", ATTR_PRESENT_PAUSE_TIMEOUT, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
124 { u"StartWithNavigator", ATTR_PRESENT_NAVIGATOR, cppu::UnoType<bool>::get(), 0, 0 },
125 { u"UsePen", ATTR_PRESENT_PEN, cppu::UnoType<bool>::get(), 0, 0 },
126 { u"", 0, css::uno::Type(), 0, 0 }
127 };
128
129 return aPresentationPropertyMap_Impl;
130 }
131
132
SlideShow(SdDrawDocument * pDoc)133 SlideShow::SlideShow( SdDrawDocument* pDoc )
134 : SlideshowBase( m_aMutex )
135 , maPropSet(ImplGetPresentationPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool())
136 , mbIsInStartup(false)
137 , mpDoc( pDoc )
138 , mpCurrentViewShellBase( nullptr )
139 , mpFullScreenViewShellBase( nullptr )
140 , mpFullScreenFrameView( nullptr )
141 , mnInPlaceConfigEvent( nullptr )
142 {
143 }
144
ThrowIfDisposed() const145 void SlideShow::ThrowIfDisposed() const
146 {
147 if( mpDoc == nullptr )
148 throw DisposedException();
149 }
150
151 /// used by the model to create a slideshow for it
Create(SdDrawDocument * pDoc)152 rtl::Reference< SlideShow > SlideShow::Create( SdDrawDocument* pDoc )
153 {
154 return new SlideShow( pDoc );
155 }
156
GetSlideShow(SdDrawDocument const * pDocument)157 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument const * pDocument )
158 {
159 rtl::Reference< SlideShow > xRet;
160
161 if( pDocument )
162 xRet = GetSlideShow( *pDocument );
163
164 return xRet;
165 }
166
GetSlideShow(SdDrawDocument const & rDocument)167 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument const & rDocument )
168 {
169 return rtl::Reference< SlideShow >(
170 dynamic_cast< SlideShow* >( rDocument.getPresentation().get() ) );
171 }
172
GetSlideShow(ViewShellBase const & rBase)173 rtl::Reference< SlideShow > SlideShow::GetSlideShow( ViewShellBase const & rBase )
174 {
175 return GetSlideShow( rBase.GetDocument() );
176 }
177
GetSlideShowController(ViewShellBase const & rBase)178 css::uno::Reference< css::presentation::XSlideShowController > SlideShow::GetSlideShowController(ViewShellBase const & rBase )
179 {
180 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
181
182 Reference< XSlideShowController > xRet;
183 if( xSlideShow.is() )
184 xRet = xSlideShow->getController();
185
186 return xRet;
187 }
188
StartPreview(ViewShellBase const & rBase,const css::uno::Reference<css::drawing::XDrawPage> & xDrawPage,const css::uno::Reference<css::animations::XAnimationNode> & xAnimationNode)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 )
192 {
193 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
194 if( !xSlideShow.is() )
195 return false;
196
197 xSlideShow->startPreview( xDrawPage, xAnimationNode );
198 return true;
199 }
200
Stop(ViewShellBase const & rBase)201 void SlideShow::Stop( ViewShellBase const & rBase )
202 {
203 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
204 if( xSlideShow.is() )
205 xSlideShow->end();
206 }
207
IsRunning(ViewShellBase const & rBase)208 bool SlideShow::IsRunning( ViewShellBase const & rBase )
209 {
210 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
211 return xSlideShow.is() && xSlideShow->isRunning();
212 }
213
IsRunning(ViewShell & rViewShell)214 bool SlideShow::IsRunning( ViewShell& rViewShell )
215 {
216 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rViewShell.GetViewShellBase() ) );
217 return xSlideShow.is() && xSlideShow->isRunning() && (xSlideShow->mxController->getViewShell() == &rViewShell);
218 }
219
CreateController(ViewShell * pViewSh,::sd::View * pView,vcl::Window * pParentWindow)220 void SlideShow::CreateController( ViewShell* pViewSh, ::sd::View* pView, vcl::Window* pParentWindow )
221 {
222 SAL_INFO_IF( !mxController.is(), "sd.slideshow", "sd::SlideShow::CreateController(), clean up old controller first!" );
223
224 Reference< XPresentation2 > xThis( this );
225
226 rtl::Reference<SlideshowImpl> xController (
227 new SlideshowImpl(xThis, pViewSh, pView, mpDoc, pParentWindow));
228
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;
233
234 }
235
236 // XServiceInfo
getImplementationName()237 OUString SAL_CALL SlideShow::getImplementationName( )
238 {
239 return "com.sun.star.comp.sd.SlideShow";
240 }
241
supportsService(const OUString & ServiceName)242 sal_Bool SAL_CALL SlideShow::supportsService( const OUString& ServiceName )
243 {
244 return cppu::supportsService( this, ServiceName );
245 }
246
getSupportedServiceNames()247 Sequence< OUString > SAL_CALL SlideShow::getSupportedServiceNames( )
248 {
249 return { "com.sun.star.presentation.Presentation" };
250 }
251
252 // XPropertySet
getPropertySetInfo()253 Reference< XPropertySetInfo > SAL_CALL SlideShow::getPropertySetInfo()
254 {
255 SolarMutexGuard aGuard;
256 static Reference< XPropertySetInfo > xInfo = maPropSet.getPropertySetInfo();
257 return xInfo;
258 }
259
setPropertyValue(const OUString & aPropertyName,const Any & aValue)260 void SAL_CALL SlideShow::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
261 {
262 SolarMutexGuard aGuard;
263 ThrowIfDisposed();
264
265 sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
266
267 const SfxItemPropertyMapEntry* pEntry = maPropSet.getPropertyMapEntry(aPropertyName);
268
269 if( pEntry && ((pEntry->nFlags & PropertyAttribute::READONLY) != 0) )
270 throw PropertyVetoException();
271
272 bool bValuesChanged = false;
273 bool bIllegalArgument = true;
274
275 switch( pEntry ? pEntry->nWID : -1 )
276 {
277 case ATTR_PRESENT_ALL:
278 {
279 bool bVal = false;
280
281 if( aValue >>= bVal )
282 {
283 bIllegalArgument = false;
284
285 if( rPresSettings.mbAll != bVal )
286 {
287 rPresSettings.mbAll = bVal;
288 bValuesChanged = true;
289 if( bVal )
290 rPresSettings.mbCustomShow = false;
291 }
292 }
293 break;
294 }
295 case ATTR_PRESENT_CHANGE_PAGE:
296 {
297 bool bVal = false;
298
299 if( aValue >>= bVal )
300 {
301 bIllegalArgument = false;
302
303 if( bVal == rPresSettings.mbLockedPages )
304 {
305 bValuesChanged = true;
306 rPresSettings.mbLockedPages = !bVal;
307 }
308 }
309 break;
310 }
311
312 case ATTR_PRESENT_ANIMATION_ALLOWED:
313 {
314 bool bVal = false;
315
316 if( aValue >>= bVal )
317 {
318 bIllegalArgument = false;
319
320 if(rPresSettings.mbAnimationAllowed != bVal)
321 {
322 bValuesChanged = true;
323 rPresSettings.mbAnimationAllowed = bVal;
324 }
325 }
326 break;
327 }
328 case ATTR_PRESENT_CUSTOMSHOW:
329 {
330 OUString aShowName;
331 if( aValue >>= aShowName )
332 {
333 bIllegalArgument = false;
334
335 SdCustomShowList* pCustomShowList = mpDoc->GetCustomShowList();
336 if(pCustomShowList)
337 {
338 SdCustomShow* pCustomShow;
339 for( pCustomShow = pCustomShowList->First(); pCustomShow != nullptr; pCustomShow = pCustomShowList->Next() )
340 {
341 if( pCustomShow->GetName() == aShowName )
342 break;
343 }
344
345 rPresSettings.mbCustomShow = true;
346 bValuesChanged = true;
347 }
348 }
349 break;
350 }
351 case ATTR_PRESENT_ENDLESS:
352 {
353 bool bVal = false;
354
355 if( aValue >>= bVal )
356 {
357 bIllegalArgument = false;
358
359 if( rPresSettings.mbEndless != bVal)
360 {
361 bValuesChanged = true;
362 rPresSettings.mbEndless = bVal;
363 }
364 }
365 break;
366 }
367 case ATTR_PRESENT_FULLSCREEN:
368 {
369 bool bVal = false;
370
371 if( aValue >>= bVal )
372 {
373 bIllegalArgument = false;
374 if( rPresSettings.mbFullScreen != bVal)
375 {
376 bValuesChanged = true;
377 rPresSettings.mbFullScreen = bVal;
378 }
379 }
380 break;
381 }
382 case ATTR_PRESENT_DIANAME:
383 {
384 OUString aPresPage;
385 aValue >>= aPresPage;
386 bIllegalArgument = false;
387 if( (rPresSettings.maPresPage != aPresPage) || !rPresSettings.mbCustomShow || !rPresSettings.mbAll )
388 {
389 bValuesChanged = true;
390 rPresSettings.maPresPage = getUiNameFromPageApiNameImpl(aPresPage);
391 rPresSettings.mbCustomShow = false;
392 rPresSettings.mbAll = false;
393 }
394 break;
395 }
396 case ATTR_PRESENT_MANUEL:
397 {
398 bool bVal = false;
399
400 if( aValue >>= bVal )
401 {
402 bIllegalArgument = false;
403
404 if( rPresSettings.mbManual != bVal)
405 {
406 bValuesChanged = true;
407 rPresSettings.mbManual = bVal;
408 }
409 }
410 break;
411 }
412 case ATTR_PRESENT_MOUSE:
413 {
414 bool bVal = false;
415
416 if( aValue >>= bVal )
417 {
418 bIllegalArgument = false;
419 if( rPresSettings.mbMouseVisible != bVal)
420 {
421 bValuesChanged = true;
422 rPresSettings.mbMouseVisible = bVal;
423 }
424 }
425 break;
426 }
427 case ATTR_PRESENT_ALWAYS_ON_TOP:
428 {
429 bool bVal = false;
430
431 if( aValue >>= bVal )
432 {
433 bIllegalArgument = false;
434
435 if( rPresSettings.mbAlwaysOnTop != bVal)
436 {
437 bValuesChanged = true;
438 rPresSettings.mbAlwaysOnTop = bVal;
439 }
440 }
441 break;
442 }
443 case ATTR_PRESENT_NAVIGATOR:
444 bIllegalArgument = false;
445 //ignored, but exists in some older documents
446 break;
447 case ATTR_PRESENT_PEN:
448 {
449 bool bVal = false;
450
451 if( aValue >>= bVal )
452 {
453 bIllegalArgument = false;
454
455 if(rPresSettings.mbMouseAsPen != bVal)
456 {
457 bValuesChanged = true;
458 rPresSettings.mbMouseAsPen = bVal;
459 }
460 }
461 break;
462 }
463 case ATTR_PRESENT_PAUSE_TIMEOUT:
464 {
465 sal_Int32 nValue = 0;
466 if( (aValue >>= nValue) && (nValue >= 0) )
467 {
468 bIllegalArgument = false;
469 if( rPresSettings.mnPauseTimeout != nValue )
470 {
471 bValuesChanged = true;
472 rPresSettings.mnPauseTimeout = nValue;
473 }
474 }
475 break;
476 }
477 case ATTR_PRESENT_SHOW_PAUSELOGO:
478 {
479 bool bVal = false;
480
481 if( aValue >>= bVal )
482 {
483 bIllegalArgument = false;
484
485 if( rPresSettings.mbShowPauseLogo != bVal )
486 {
487 bValuesChanged = true;
488 rPresSettings.mbShowPauseLogo = bVal;
489 }
490 }
491 break;
492 }
493 case ATTR_PRESENT_DISPLAY:
494 {
495 sal_Int32 nDisplay = 0;
496 if( aValue >>= nDisplay )
497 {
498 bIllegalArgument = false;
499
500 SdOptions* pOptions = SD_MOD()->GetSdOptions(DocumentType::Impress);
501 pOptions->SetDisplay( nDisplay );
502
503 FullScreenWorkWindow *pWin = dynamic_cast<FullScreenWorkWindow *>(GetWorkWindow());
504 if( !pWin )
505 return;
506 pWin->Restart(true);
507 }
508 break;
509 }
510
511 default:
512 throw UnknownPropertyException( OUString::number(pEntry ? pEntry->nWID : -1), static_cast<cppu::OWeakObject*>(this));
513 }
514
515 if( bIllegalArgument )
516 throw IllegalArgumentException();
517
518 if( bValuesChanged )
519 mpDoc->SetChanged();
520 }
521
getPropertyValue(const OUString & PropertyName)522 Any SAL_CALL SlideShow::getPropertyValue( const OUString& PropertyName )
523 {
524 SolarMutexGuard aGuard;
525 ThrowIfDisposed();
526
527 const sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
528
529 const SfxItemPropertyMapEntry* pEntry = maPropSet.getPropertyMapEntry(PropertyName);
530
531 switch( pEntry ? pEntry->nWID : -1 )
532 {
533 case ATTR_PRESENT_ALL:
534 return Any( !rPresSettings.mbCustomShow && rPresSettings.mbAll );
535 case ATTR_PRESENT_CHANGE_PAGE:
536 return Any( !rPresSettings.mbLockedPages );
537 case ATTR_PRESENT_ANIMATION_ALLOWED:
538 return Any( rPresSettings.mbAnimationAllowed );
539 case ATTR_PRESENT_CUSTOMSHOW:
540 {
541 SdCustomShowList* pList = mpDoc->GetCustomShowList();
542 SdCustomShow* pShow = (pList && rPresSettings.mbCustomShow) ? pList->GetCurObject() : nullptr;
543 OUString aShowName;
544
545 if(pShow)
546 aShowName = pShow->GetName();
547
548 return Any( aShowName );
549 }
550 case ATTR_PRESENT_ENDLESS:
551 return Any( rPresSettings.mbEndless );
552 case ATTR_PRESENT_FULLSCREEN:
553 return Any( rPresSettings.mbFullScreen );
554 case ATTR_PRESENT_DIANAME:
555 {
556 OUString aSlideName;
557
558 if( !rPresSettings.mbCustomShow && !rPresSettings.mbAll )
559 aSlideName = getPageApiNameFromUiName( rPresSettings.maPresPage );
560
561 return Any( aSlideName );
562 }
563 case ATTR_PRESENT_MANUEL:
564 return Any( rPresSettings.mbManual );
565 case ATTR_PRESENT_MOUSE:
566 return Any( rPresSettings.mbMouseVisible );
567 case ATTR_PRESENT_ALWAYS_ON_TOP:
568 return Any( rPresSettings.mbAlwaysOnTop );
569 case ATTR_PRESENT_NAVIGATOR:
570 return Any( false );
571 case ATTR_PRESENT_PEN:
572 return Any( rPresSettings.mbMouseAsPen );
573 case ATTR_PRESENT_PAUSE_TIMEOUT:
574 return Any( rPresSettings.mnPauseTimeout );
575 case ATTR_PRESENT_SHOW_PAUSELOGO:
576 return Any( rPresSettings.mbShowPauseLogo );
577 case ATTR_PRESENT_DISPLAY:
578 {
579 SdOptions* pOptions = SD_MOD()->GetSdOptions(DocumentType::Impress);
580 return Any(pOptions->GetDisplay());
581 }
582
583 default:
584 throw UnknownPropertyException( OUString::number(pEntry ? pEntry->nWID : -1), static_cast<cppu::OWeakObject*>(this));
585 }
586 }
587
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)588 void SAL_CALL SlideShow::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& )
589 {
590 }
591
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)592 void SAL_CALL SlideShow::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& )
593 {
594 }
595
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)596 void SAL_CALL SlideShow::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& )
597 {
598 }
599
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)600 void SAL_CALL SlideShow::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& )
601 {
602 }
603
604 // XPresentation
605
start()606 void SAL_CALL SlideShow::start()
607 {
608 const Sequence< PropertyValue > aArguments;
609 startWithArguments( aArguments );
610 }
611
GetWorkWindow()612 WorkWindow *SlideShow::GetWorkWindow()
613 {
614 if( !mpFullScreenViewShellBase )
615 return nullptr;
616
617 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(mpFullScreenViewShellBase->GetMainViewShell().get());
618
619 if( !pShell || !pShell->GetViewFrame() )
620 return nullptr;
621
622 return dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetFrame().GetWindow().GetParent());
623 }
624
IsExitAfterPresenting() const625 bool SlideShow::IsExitAfterPresenting() const
626 {
627 SolarMutexGuard aGuard;
628 ThrowIfDisposed();
629 return mpDoc->IsExitAfterPresenting();
630 }
631
SetExitAfterPresenting(bool bExit)632 void SlideShow::SetExitAfterPresenting(bool bExit)
633 {
634 SolarMutexGuard aGuard;
635 ThrowIfDisposed();
636 mpDoc->SetExitAfterPresenting(bExit);
637 }
638
end()639 void SAL_CALL SlideShow::end()
640 {
641 SolarMutexGuard aGuard;
642
643 // The mbIsInStartup flag should have been reset during the start of the
644 // slide show. Reset it here just in case that something has horribly
645 // gone wrong.
646 assert(!mbIsInStartup);
647
648 rtl::Reference< SlideshowImpl > xController( mxController );
649 if( !xController.is() )
650 return;
651
652 mxController.clear();
653
654 if( mpFullScreenFrameView )
655 {
656 delete mpFullScreenFrameView;
657 mpFullScreenFrameView = nullptr;
658 }
659
660 ViewShellBase* pFullScreenViewShellBase = mpFullScreenViewShellBase;
661 mpFullScreenViewShellBase = nullptr;
662
663 // dispose before fullscreen window changes screens
664 // (potentially). If this needs to be moved behind
665 // pWorkWindow->StartPresentationMode() again, read issue
666 // pWorkWindow->i94007 & implement the solution outlined
667 // there.
668 xController->dispose();
669
670 if( pFullScreenViewShellBase )
671 {
672 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(pFullScreenViewShellBase->GetMainViewShell().get());
673
674 if( pShell && pShell->GetViewFrame() )
675 {
676 WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetFrame().GetWindow().GetParent());
677 if( pWorkWindow )
678 {
679 pWorkWindow->StartPresentationMode( (mxController.is() && mxController->maPresSettings.mbAlwaysOnTop)
680 ? PresentationFlags::HideAllApps : PresentationFlags::NONE );
681 }
682 }
683 }
684
685 if( pFullScreenViewShellBase )
686 {
687 PresentationViewShell* pShell = nullptr;
688 {
689 // Get the shell pointer in its own scope to be sure that
690 // the shared_ptr to the shell is released before DoClose()
691 // is called.
692 ::std::shared_ptr<ViewShell> pSharedView (pFullScreenViewShellBase->GetMainViewShell());
693 pShell = dynamic_cast<PresentationViewShell*>(pSharedView.get());
694 }
695 if( pShell && pShell->GetViewFrame() )
696 pShell->GetViewFrame()->DoClose();
697 }
698 else if( mpCurrentViewShellBase )
699 {
700 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
701
702 if( pViewShell )
703 {
704 FrameView* pFrameView = pViewShell->GetFrameView();
705
706 if( pFrameView && (pFrameView->GetPresentationViewShellId() != SID_VIEWSHELL0) )
707 {
708 ViewShell::ShellType ePreviousType (pFrameView->GetPreviousViewShellType());
709 pFrameView->SetPreviousViewShellType(ViewShell::ST_NONE);
710
711 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL0);
712 pFrameView->SetPreviousViewShellType(pViewShell->GetShellType());
713
714 framework::FrameworkHelper::Instance(*mpCurrentViewShellBase)->RequestView(
715 framework::FrameworkHelper::GetViewURL(ePreviousType),
716 framework::FrameworkHelper::msCenterPaneURL);
717
718 pViewShell->GetViewFrame()->GetBindings().InvalidateAll( true );
719 }
720 }
721 }
722
723 if( mpCurrentViewShellBase )
724 {
725 if (ViewShell* const pViewShell = mpCurrentViewShellBase->GetMainViewShell().get())
726 {
727 // invalidate the view shell so the presentation slot will be re-enabled
728 // and the rehearsing will be updated
729 pViewShell->Invalidate();
730
731 if( xController->meAnimationMode ==ANIMATIONMODE_SHOW )
732 {
733 // switch to the previously visible Slide
734 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>( pViewShell );
735 if( pDrawViewShell )
736 pDrawViewShell->SwitchPage( static_cast<sal_uInt16>(xController->getRestoreSlide()) );
737 else
738 {
739 Reference<XDrawView> xDrawView (
740 Reference<XWeak>(&mpCurrentViewShellBase->GetDrawController()), UNO_QUERY);
741 if (xDrawView.is())
742 xDrawView->setCurrentPage(
743 Reference<XDrawPage>(
744 mpDoc->GetSdPage(xController->getRestoreSlide(), PageKind::Standard)->getUnoPage(),
745 UNO_QUERY));
746 }
747 }
748
749 if( pViewShell->GetDoc()->IsExitAfterPresenting() )
750 {
751 pViewShell->GetDoc()->SetExitAfterPresenting( false );
752
753 Reference<frame::XDispatchProvider> xProvider(pViewShell->GetViewShellBase().GetController()->getFrame(),
754 UNO_QUERY);
755 if( xProvider.is() )
756 {
757 util::URL aURL;
758 aURL.Complete = ".uno:CloseFrame";
759
760 uno::Reference< frame::XDispatch > xDispatch(
761 xProvider->queryDispatch(
762 aURL, OUString(), 0));
763 if( xDispatch.is() )
764 {
765 xDispatch->dispatch(aURL,
766 uno::Sequence< beans::PropertyValue >());
767 }
768 }
769 }
770
771 // In case mbMouseAsPen was set, a new layer DrawnInSlideshow might have been generated
772 // during slideshow, which is not known to FrameView yet.
773 if (any2bool(getPropertyValue("UsePen"))
774 && pViewShell->GetDoc()->GetLayerAdmin().GetLayer("DrawnInSlideshow"))
775 {
776 SdrLayerIDSet aDocLayerIDSet;
777 pViewShell->GetDoc()->GetLayerAdmin().getVisibleLayersODF(aDocLayerIDSet);
778 if (pViewShell->GetFrameView()->GetVisibleLayers() != aDocLayerIDSet)
779 {
780 pViewShell->GetFrameView()->SetVisibleLayers(aDocLayerIDSet);
781 }
782 pViewShell->GetDoc()->GetLayerAdmin().getPrintableLayersODF(aDocLayerIDSet);
783 if (pViewShell->GetFrameView()->GetPrintableLayers() != aDocLayerIDSet)
784 {
785 pViewShell->GetFrameView()->SetPrintableLayers(aDocLayerIDSet);
786 }
787 pViewShell->GetDoc()->GetLayerAdmin().getLockedLayersODF(aDocLayerIDSet);
788 if (pViewShell->GetFrameView()->GetLockedLayers() != aDocLayerIDSet)
789 {
790 pViewShell->GetFrameView()->SetLockedLayers(aDocLayerIDSet);
791 }
792 pViewShell->InvalidateWindows();
793 }
794
795 // Fire the acc focus event when focus is switched back. The above method
796 // mpCurrentViewShellBase->GetWindow()->GrabFocus() will set focus to WorkWindow
797 // instead of the sd::window, so here call Shell's method to fire the focus event
798 pViewShell->SwitchActiveViewFireFocus();
799 }
800 }
801 mpCurrentViewShellBase = nullptr;
802 }
803
rehearseTimings()804 void SAL_CALL SlideShow::rehearseTimings()
805 {
806 Sequence< PropertyValue > aArguments(1);
807 aArguments[0].Name = "RehearseTimings";
808 aArguments[0].Value <<= true;
809 startWithArguments( aArguments );
810 }
811
812 // XPresentation2
813
startWithArguments(const Sequence<PropertyValue> & rArguments)814 void SAL_CALL SlideShow::startWithArguments(const Sequence< PropertyValue >& rArguments)
815 {
816 SolarMutexGuard aGuard;
817 ThrowIfDisposed();
818
819 // Stop a running show before starting a new one.
820 if( mxController.is() )
821 {
822 assert(!mbIsInStartup);
823 end();
824 }
825 else if (mbIsInStartup)
826 {
827 // We are already somewhere in process of starting a slide show but
828 // have not yet got to the point where mxController is set. There
829 // is not yet a slide show to end so return silently.
830 return;
831 }
832
833 // Prevent multiple instance of the SlideShow class for one document.
834 mbIsInStartup = true;
835
836 mxCurrentSettings = std::make_shared<PresentationSettingsEx>( mpDoc->getPresentationSettings() );
837 mxCurrentSettings->SetArguments( rArguments );
838
839 // if there is no view shell base set, use the current one or the first using this document
840 if( mpCurrentViewShellBase == nullptr )
841 {
842 // first check current
843 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::Current() );
844 if( pBase && pBase->GetDocument() == mpDoc )
845 {
846 mpCurrentViewShellBase = pBase;
847 }
848 else
849 {
850 // current is not ours, so get first from ours
851 mpCurrentViewShellBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::GetFirst( mpDoc->GetDocSh() ) );
852 }
853 }
854
855 // #i118456# make sure TextEdit changes get pushed to model.
856 // mpDrawView is tested against NULL above already.
857 if(mpCurrentViewShellBase)
858 {
859 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
860
861 if(pViewShell && pViewShell->GetView())
862 {
863 pViewShell->GetView()->SdrEndTextEdit();
864 }
865 }
866
867 // Start either a full-screen or an in-place show.
868 if(mxCurrentSettings->mbFullScreen && !mxCurrentSettings->mbPreview)
869 StartFullscreenPresentation();
870 else
871 StartInPlacePresentation();
872
873 }
874
isRunning()875 sal_Bool SAL_CALL SlideShow::isRunning( )
876 {
877 SolarMutexGuard aGuard;
878 return mxController.is() && mxController->isRunning();
879 }
880
getController()881 Reference< XSlideShowController > SAL_CALL SlideShow::getController( )
882 {
883 ThrowIfDisposed();
884
885 return mxController;
886 }
887
888 // XComponent
889
disposing()890 void SAL_CALL SlideShow::disposing()
891 {
892 SolarMutexGuard aGuard;
893
894 if( mnInPlaceConfigEvent )
895 {
896 Application::RemoveUserEvent( mnInPlaceConfigEvent );
897 mnInPlaceConfigEvent = nullptr;
898 }
899
900 if( mxController.is() )
901 {
902 mxController->dispose();
903 mxController.clear();
904 }
905
906 mpCurrentViewShellBase = nullptr;
907 mpFullScreenViewShellBase = nullptr;
908 mpDoc = nullptr;
909 }
910
startPreview(const Reference<XDrawPage> & xDrawPage,const Reference<XAnimationNode> & xAnimationNode)911 void SlideShow::startPreview( const Reference< XDrawPage >& xDrawPage, const Reference< XAnimationNode >& xAnimationNode )
912 {
913 Sequence< PropertyValue > aArguments(4);
914
915 aArguments[0].Name = "Preview";
916 aArguments[0].Value <<= true;
917
918 aArguments[1].Name = "FirstPage";
919 aArguments[1].Value <<= xDrawPage;
920
921 aArguments[2].Name = "AnimationNode";
922 aArguments[2].Value <<= xAnimationNode;
923
924 aArguments[3].Name = "ParentWindow";
925 aArguments[3].Value <<= Reference< XWindow >();
926
927 startWithArguments( aArguments );
928 }
929
getShowWindow()930 OutputDevice* SlideShow::getShowWindow()
931 {
932 return mxController.is() ? mxController->mpShowWindow->GetOutDev() : nullptr;
933 }
934
getAnimationMode() const935 int SlideShow::getAnimationMode() const
936 {
937 return mxController.is() ? mxController->meAnimationMode : ANIMATIONMODE_SHOW;
938 }
939
jumpToPageIndex(sal_Int32 nPageIndex)940 void SlideShow::jumpToPageIndex( sal_Int32 nPageIndex )
941 {
942 if( mxController.is() )
943 mxController->displaySlideIndex( nPageIndex );
944 }
945
jumpToPageNumber(sal_Int32 nPageNumber)946 void SlideShow::jumpToPageNumber( sal_Int32 nPageNumber )
947 {
948 if( mxController.is() )
949 mxController->displaySlideNumber( nPageNumber );
950 }
951
getCurrentPageNumber() const952 sal_Int32 SlideShow::getCurrentPageNumber() const
953 {
954 return mxController.is() ? mxController->getCurrentSlideNumber() : 0;
955 }
956
jumpToBookmark(const OUString & sBookmark)957 void SlideShow::jumpToBookmark( const OUString& sBookmark )
958 {
959 if( mxController.is() )
960 mxController->jumpToBookmark( sBookmark );
961 }
962
isFullScreen() const963 bool SlideShow::isFullScreen() const
964 {
965 return mxController.is() && mxController->maPresSettings.mbFullScreen;
966 }
967
resize(const Size & rSize)968 void SlideShow::resize( const Size &rSize )
969 {
970 if( mxController.is() )
971 mxController->resize( rSize );
972 }
973
activate(ViewShellBase & rBase)974 bool SlideShow::activate( ViewShellBase& rBase )
975 {
976 if( (mpFullScreenViewShellBase == &rBase) && !mxController.is() )
977 {
978 ::std::shared_ptr<PresentationViewShell> pShell = std::dynamic_pointer_cast<PresentationViewShell>(rBase.GetMainViewShell());
979 if (pShell != nullptr)
980 {
981 pShell->FinishInitialization( mpFullScreenFrameView );
982 mpFullScreenFrameView = nullptr;
983
984 CreateController( pShell.get(), pShell->GetView(), rBase.GetViewWindow() );
985
986 if (!mxController->startShow(mxCurrentSettings.get()))
987 return false;
988
989 pShell->Resize();
990 // Defer the sd::ShowWindow's GrabFocus to here. so that the accessible event can be fired correctly.
991 pShell->GetActiveWindow()->GrabFocus();
992 }
993 }
994
995 if( mxController.is() )
996 mxController->activate();
997
998 return true;
999 }
1000
deactivate()1001 void SlideShow::deactivate()
1002 {
1003 mxController->deactivate();
1004 }
1005
keyInput(const KeyEvent & rKEvt)1006 bool SlideShow::keyInput(const KeyEvent& rKEvt)
1007 {
1008 return mxController.is() && mxController->keyInput(rKEvt);
1009 }
1010
paint()1011 void SlideShow::paint()
1012 {
1013 if( mxController.is() )
1014 mxController->paint();
1015 }
1016
pause(bool bPause)1017 void SlideShow::pause( bool bPause )
1018 {
1019 if( mxController.is() )
1020 {
1021 if( bPause )
1022 mxController->pause();
1023 else
1024 mxController->resume();
1025 }
1026 }
1027
swipe(const CommandSwipeData & rSwipeData)1028 bool SlideShow::swipe(const CommandSwipeData& rSwipeData)
1029 {
1030 return mxController.is() && mxController->swipe(rSwipeData);
1031 }
1032
longpress(const CommandLongPressData & rLongPressData)1033 bool SlideShow::longpress(const CommandLongPressData& rLongPressData)
1034 {
1035 return mxController.is() && mxController->longpress(rLongPressData);
1036 }
1037
StartInPlacePresentationConfigurationCallback()1038 void SlideShow::StartInPlacePresentationConfigurationCallback()
1039 {
1040 if( mnInPlaceConfigEvent != nullptr )
1041 Application::RemoveUserEvent( mnInPlaceConfigEvent );
1042
1043 mnInPlaceConfigEvent = Application::PostUserEvent( LINK( this, SlideShow, StartInPlacePresentationConfigurationHdl ) );
1044 }
1045
IMPL_LINK_NOARG(SlideShow,StartInPlacePresentationConfigurationHdl,void *,void)1046 IMPL_LINK_NOARG(SlideShow, StartInPlacePresentationConfigurationHdl, void*, void)
1047 {
1048 mnInPlaceConfigEvent = nullptr;
1049 StartInPlacePresentation();
1050 }
1051
StartInPlacePresentation()1052 void SlideShow::StartInPlacePresentation()
1053 {
1054 if( mpCurrentViewShellBase )
1055 {
1056 // Save the current view shell type so that it can be restored after the
1057 // show has ended. If there already is a saved shell type then that is
1058 // not overwritten.
1059
1060 ViewShell::ShellType eShell = ViewShell::ST_NONE;
1061
1062 ::std::shared_ptr<FrameworkHelper> pHelper(FrameworkHelper::Instance(*mpCurrentViewShellBase));
1063 ::std::shared_ptr<ViewShell> pMainViewShell(pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL));
1064
1065 if( pMainViewShell )
1066 eShell = pMainViewShell->GetShellType();
1067
1068 if( eShell != ViewShell::ST_IMPRESS )
1069 {
1070 // Switch temporary to a DrawViewShell which supports the in-place presentation.
1071
1072 if( pMainViewShell )
1073 {
1074 FrameView* pFrameView = pMainViewShell->GetFrameView();
1075 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL1);
1076 pFrameView->SetPreviousViewShellType (pMainViewShell->GetShellType());
1077 pFrameView->SetPageKind (PageKind::Standard);
1078 }
1079
1080 pHelper->RequestView( FrameworkHelper::msImpressViewURL, FrameworkHelper::msCenterPaneURL );
1081 pHelper->RunOnConfigurationEvent(
1082 FrameworkHelper::msConfigurationUpdateEndEvent,
1083 [this] (bool const) { return this->StartInPlacePresentationConfigurationCallback(); } );
1084 return;
1085 }
1086 else
1087 {
1088 vcl::Window* pParentWindow = mxCurrentSettings->mpParentWindow;
1089 if( pParentWindow == nullptr )
1090 pParentWindow = mpCurrentViewShellBase->GetViewWindow();
1091
1092 CreateController( pMainViewShell.get(), pMainViewShell->GetView(), pParentWindow );
1093 }
1094 }
1095 else if( mxCurrentSettings->mpParentWindow )
1096 {
1097 // no current view shell, but parent window
1098 CreateController( nullptr, nullptr, mxCurrentSettings->mpParentWindow );
1099 }
1100
1101 if( !mxController.is() )
1102 return;
1103
1104 bool bSuccess = false;
1105 if( mxCurrentSettings && mxCurrentSettings->mbPreview )
1106 {
1107 bSuccess = mxController->startPreview(mxCurrentSettings->mxStartPage, mxCurrentSettings->mxAnimationNode, mxCurrentSettings->mpParentWindow );
1108 }
1109 else
1110 {
1111 bSuccess = mxController->startShow(mxCurrentSettings.get());
1112 }
1113
1114 if( !bSuccess )
1115 end();
1116 else
1117 {
1118 if( mpCurrentViewShellBase && ( !mxCurrentSettings || ( mxCurrentSettings && !mxCurrentSettings->mbPreview ) ) )
1119 mpCurrentViewShellBase->GetWindow()->GrabFocus();
1120 }
1121 }
1122
StartFullscreenPresentation()1123 void SlideShow::StartFullscreenPresentation( )
1124 {
1125 // Create the top level window in which the PresentationViewShell(Base)
1126 // will be created. This is done here explicitly so that we can make it
1127 // fullscreen.
1128 const sal_Int32 nDisplay (GetDisplay());
1129 VclPtr<WorkWindow> pWorkWindow = VclPtr<FullScreenWorkWindow>::Create(this, mpCurrentViewShellBase);
1130 pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
1131 OUString Title(SdResId(STR_FULLSCREEN_SLIDESHOW));
1132 Title = Title.replaceFirst("%s",
1133 mpCurrentViewShellBase->GetDocShell()->GetTitle(SFX_TITLE_DETECT));
1134 pWorkWindow->SetText(Title);
1135 pWorkWindow->StartPresentationMode( true, mpDoc->getPresentationSettings().mbAlwaysOnTop ? PresentationFlags::HideAllApps : PresentationFlags::NONE, nDisplay);
1136 // pWorkWindow->ShowFullScreenMode(sal_False, nDisplay);
1137
1138 if (!pWorkWindow->IsVisible())
1139 return;
1140
1141 // Initialize the new presentation view shell with a copy of the
1142 // frame view of the current view shell. This avoids that
1143 // changes made by the presentation have an effect on the other
1144 // view shells.
1145 FrameView* pOriginalFrameView = nullptr;
1146 ::std::shared_ptr<ViewShell> xShell(mpCurrentViewShellBase->GetMainViewShell());
1147 if (xShell)
1148 pOriginalFrameView = xShell->GetFrameView();
1149
1150 delete mpFullScreenFrameView;
1151 mpFullScreenFrameView = new FrameView(mpDoc, pOriginalFrameView);
1152
1153 // The new frame is created hidden. To make it visible and activate the
1154 // new view shell--a prerequisite to process slot calls and initialize
1155 // its panes--a GrabFocus() has to be called later on.
1156 SfxFrame* pNewFrame = SfxFrame::CreateHidden( *mpDoc->GetDocSh(), *pWorkWindow, PRESENTATION_FACTORY_ID );
1157 pNewFrame->SetPresentationMode(true);
1158
1159 mpFullScreenViewShellBase = static_cast<ViewShellBase*>(pNewFrame->GetCurrentViewFrame()->GetViewShell());
1160 if(mpFullScreenViewShellBase != nullptr)
1161 {
1162 // The following GrabFocus() is responsible for activating the
1163 // new view shell. Without it the screen remains blank (under
1164 // Windows and some Linux variants.)
1165 mpFullScreenViewShellBase->GetWindow()->GrabFocus();
1166 }
1167 }
1168
1169 /// convert configuration setting display concept to real screens
GetDisplay()1170 sal_Int32 SlideShow::GetDisplay()
1171 {
1172 sal_Int32 nDisplay = 0;
1173
1174 SdOptions* pOptions = SD_MOD()->GetSdOptions(DocumentType::Impress);
1175 if( pOptions )
1176 nDisplay = pOptions->GetDisplay();
1177
1178 if( nDisplay < 0 )
1179 nDisplay = -1;
1180 else if( nDisplay == 0)
1181 nDisplay = static_cast<sal_Int32>(Application::GetDisplayExternalScreen());
1182 else
1183 nDisplay--;
1184
1185 SAL_INFO("sd", "Presenting on real screen " << nDisplay);
1186
1187 return nDisplay;
1188 }
1189
dependsOn(ViewShellBase const * pViewShellBase)1190 bool SlideShow::dependsOn( ViewShellBase const * pViewShellBase )
1191 {
1192 return mxController.is() && (pViewShellBase == mpCurrentViewShellBase) && mpFullScreenViewShellBase;
1193 }
1194
CreatePresentation(const SdDrawDocument & rDocument)1195 Reference< presentation::XPresentation2 > CreatePresentation( const SdDrawDocument& rDocument )
1196 {
1197 return Reference< presentation::XPresentation2 >( SlideShow::Create( const_cast< SdDrawDocument* >( &rDocument ) ) );
1198 }
1199
1200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1201