LibreOffice Module sd (master) 1
SlideShowRestarter.cxx
Go to the documentation of this file.
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 <DrawController.hxx>
21#include <ViewShellBase.hxx>
22#include <slideshow.hxx>
24
28#include <sfx2/dispatch.hxx>
29#include <sfx2/viewfrm.hxx>
30#include <svx/svxids.hrc>
31#include <utility>
32#include <vcl/svapp.hxx>
33
34#include <functional>
35
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::lang;
38using ::sd::framework::FrameworkHelper;
39
40namespace sd {
41
44 ViewShellBase* pViewShellBase)
45 : mnEventId(nullptr),
46 mpSlideShow(std::move(pSlideShow)),
47 mpViewShellBase(pViewShellBase),
48 mnDisplayCount(Application::GetScreenCount()),
49 mpDispatcher(pViewShellBase->GetViewFrame().GetDispatcher()),
50 mnCurrentSlideNumber(0)
51{
52}
53
55{
56}
57
59{
60 // Prevent multiple and concurrently restarts.
61 if (mnEventId != nullptr)
62 return;
63
64 if (bForce)
66
67 // Remember the current slide in order to restore it after the slide
68 // show has been restarted.
69 if (mpSlideShow.is())
70 mnCurrentSlideNumber = mpSlideShow->getCurrentPageNumber();
71
72 // Remember a shared pointer to this object to prevent its destruction
73 // before the whole restarting process has finished.
74 mpSelf = shared_from_this();
75
76 // We do not know in what situation this method was called. So, in
77 // order to be able to cleanly stop the presentation, we do that
78 // asynchronously.
80 LINK(this, SlideShowRestarter, EndPresentation));
81}
82
83IMPL_LINK_NOARG(SlideShowRestarter, EndPresentation, void*, void)
84{
85 mnEventId = nullptr;
86 if (!mpSlideShow.is())
87 return;
88
89 if (mnDisplayCount == static_cast<sal_Int32>(Application::GetScreenCount()))
90 return;
91
92 bool bIsExitAfterPresenting = mpSlideShow->IsExitAfterPresenting();
93 mpSlideShow->SetExitAfterPresenting(false);
94 mpSlideShow->end();
95 mpSlideShow->SetExitAfterPresenting(bIsExitAfterPresenting);
96
97 // The following piece of code should not be here because the
98 // slide show should be aware of the existence of the presenter
99 // console (which is displayed in the FullScreenPane). But the
100 // timing has to be right and I did not find a better place for
101 // it.
102
103 // Wait for the full screen pane, which displays the presenter
104 // console, to disappear. Only when it is gone, call
105 // InitiatePresenterStart(), in order to begin the asynchronous
106 // restart of the slide show.
107 if (mpViewShellBase == nullptr)
108 return;
109
110 ::std::shared_ptr<FrameworkHelper> pHelper(
111 FrameworkHelper::Instance(*mpViewShellBase));
112 if (pHelper->GetConfigurationController()->getResource(
113 FrameworkHelper::CreateResourceId(FrameworkHelper::msFullScreenPaneURL)).is())
114 {
116 pHelper->GetConfigurationController());
117
118 pHelper->RunOnConfigurationEvent(
119 FrameworkHelper::msConfigurationUpdateEndEvent,
120 ::std::bind(&SlideShowRestarter::StartPresentation, shared_from_this()));
121 pHelper->UpdateConfiguration();
122 }
123 else
124 {
125 StartPresentation();
126 }
127}
128
130{
131 //rhbz#1091117 crash because we're exiting the application, and this is
132 //being called during the configuration update event on exit. At this point
133 //newly created objects won't get disposed called on them, because the
134 //disposer is doing its last execution of that now.
136 return;
137
138 if (mpDispatcher == nullptr && mpViewShellBase!=nullptr)
140
141 // Start the slide show on the saved current slide.
142 if (mpDispatcher != nullptr)
143 {
144 mpDispatcher->Execute(SID_PRESENTATION, SfxCallMode::ASYNCHRON);
145 if (mpSlideShow.is())
146 {
148 "page" + OUString::number(mnCurrentSlideNumber+1)) };
149 mpSlideShow->startWithArguments(aProperties);
150 }
151 mpSelf.reset();
152 }
153}
154
155} // end of namespace sd
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int16 mnEventId
PropertiesInfo aProperties
static unsigned int GetScreenCount()
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
SfxDispatcher * GetDispatcher()
SfxViewFrame & GetViewFrame() const
bool IsDisposing() const
This class is used when a display is removed or added to restart the slide show.
::rtl::Reference< SlideShow > mpSlideShow
SlideShowRestarter(::rtl::Reference< SlideShow > pSlideShow, ViewShellBase *pViewShellBase)
Create a new SlideShowRestarter object.
void StartPresentation()
Restart the presentation on the slide last shown before the restart was initiated.
::std::shared_ptr< SlideShowRestarter > mpSelf
void Restart(bool bForce)
Restarting the slide show is an asynchronous multi step process which is started by calling this meth...
ViewShellBase * mpViewShellBase
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
DrawController * GetDrawController() const
Use this class instead of calling lock() and unlock() directly in order to be exception safe.
SfxDispatcher * GetDispatcher()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)