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 <DrawController.hxx>
21 #include <ViewShellBase.hxx>
22 #include <slideshow.hxx>
23 #include "SlideShowRestarter.hxx"
25 #include <comphelper/propertyvalue.hxx>
26 #include <framework/ConfigurationController.hxx>
27 #include <framework/FrameworkHelper.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svx/svxids.hrc>
32 #include <vcl/svapp.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
38 using ::sd::framework::FrameworkHelper
;
42 SlideShowRestarter::SlideShowRestarter (
43 ::rtl::Reference
<SlideShow
> pSlideShow
,
44 ViewShellBase
* pViewShellBase
)
46 mpSlideShow(std::move(pSlideShow
)),
47 mpViewShellBase(pViewShellBase
),
48 mnDisplayCount(Application::GetScreenCount()),
49 mpDispatcher(pViewShellBase
->GetViewFrame().GetDispatcher()),
50 mnCurrentSlideNumber(0)
54 SlideShowRestarter::~SlideShowRestarter()
58 void SlideShowRestarter::Restart (bool bForce
)
60 // Prevent multiple and concurrently restarts.
61 if (mnEventId
!= nullptr)
67 // Remember the current slide in order to restore it after the slide
68 // show has been restarted.
70 mnCurrentSlideNumber
= mpSlideShow
->getCurrentPageNumber();
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();
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
79 mnEventId
= Application::PostUserEvent(
80 LINK(this, SlideShowRestarter
, EndPresentation
));
83 IMPL_LINK_NOARG(SlideShowRestarter
, EndPresentation
, void*, void)
86 if (!mpSlideShow
.is())
89 if (mnDisplayCount
== static_cast<sal_Int32
>(Application::GetScreenCount()))
92 bool bIsExitAfterPresenting
= mpSlideShow
->IsExitAfterPresenting();
93 mpSlideShow
->SetExitAfterPresenting(false);
95 mpSlideShow
->SetExitAfterPresenting(bIsExitAfterPresenting
);
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
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)
110 ::std::shared_ptr
<FrameworkHelper
> pHelper(
111 FrameworkHelper::Instance(*mpViewShellBase
));
112 if (pHelper
->GetConfigurationController()->getResource(
113 FrameworkHelper::CreateResourceId(FrameworkHelper::msFullScreenPaneURL
)).is())
115 ::sd::framework::ConfigurationController::Lock
aLock (
116 pHelper
->GetConfigurationController());
118 pHelper
->RunOnConfigurationEvent(
119 FrameworkHelper::msConfigurationUpdateEndEvent
,
120 ::std::bind(&SlideShowRestarter::StartPresentation
, shared_from_this()));
121 pHelper
->UpdateConfiguration();
129 void SlideShowRestarter::StartPresentation()
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.
135 if (mpViewShellBase
&& mpViewShellBase
->GetDrawController()->IsDisposing())
138 if (mpDispatcher
== nullptr && mpViewShellBase
!=nullptr)
139 mpDispatcher
= mpViewShellBase
->GetViewFrame().GetDispatcher();
141 // Start the slide show on the saved current slide.
142 if (mpDispatcher
!= nullptr)
144 mpDispatcher
->Execute(SID_PRESENTATION
, SfxCallMode::ASYNCHRON
);
145 if (mpSlideShow
.is())
147 Sequence aProperties
{ comphelper::makePropertyValue(u
"FirstPage"_ustr
,
148 "page" + OUString::number(mnCurrentSlideNumber
+1)) };
149 mpSlideShow
->startWithArguments(aProperties
);
155 } // end of namespace sd
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */