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"
24 #include <framework/ConfigurationController.hxx>
25 #include <framework/FrameworkHelper.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/app.hxx>
29 #include <svx/svxids.hrc>
30 #include <vcl/svapp.hxx>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::lang
;
36 using ::sd::framework::FrameworkHelper
;
40 SlideShowRestarter::SlideShowRestarter (
41 const ::rtl::Reference
<SlideShow
>& rpSlideShow
,
42 ViewShellBase
* pViewShellBase
)
44 mpSlideShow(rpSlideShow
),
45 mpViewShellBase(pViewShellBase
),
46 mnDisplayCount(Application::GetScreenCount()),
47 mpDispatcher(pViewShellBase
->GetViewFrame()->GetDispatcher()),
48 mnCurrentSlideNumber(0)
52 SlideShowRestarter::~SlideShowRestarter()
56 void SlideShowRestarter::Restart (bool bForce
)
58 // Prevent multiple and concurrently restarts.
59 if (mnEventId
!= nullptr)
65 // Remember the current slide in order to restore it after the slide
66 // show has been restarted.
68 mnCurrentSlideNumber
= mpSlideShow
->getCurrentPageNumber();
70 // Remember a shared pointer to this object to prevent its destruction
71 // before the whole restarting process has finished.
72 mpSelf
= shared_from_this();
74 // We do not know in what situation this method was called. So, in
75 // order to be able to cleanly stop the presentation, we do that
77 mnEventId
= Application::PostUserEvent(
78 LINK(this, SlideShowRestarter
, EndPresentation
));
81 IMPL_LINK_NOARG(SlideShowRestarter
, EndPresentation
, void*, void)
84 if (!mpSlideShow
.is())
87 if (mnDisplayCount
== static_cast<sal_Int32
>(Application::GetScreenCount()))
90 bool bIsExitAfterPresenting
= mpSlideShow
->IsExitAfterPresenting();
91 mpSlideShow
->SetExitAfterPresenting(false);
93 mpSlideShow
->SetExitAfterPresenting(bIsExitAfterPresenting
);
95 // The following piece of code should not be here because the
96 // slide show should be aware of the existence of the presenter
97 // console (which is displayed in the FullScreenPane). But the
98 // timing has to be right and I did not find a better place for
101 // Wait for the full screen pane, which displays the presenter
102 // console, to disappear. Only when it is gone, call
103 // InitiatePresenterStart(), in order to begin the asynchronous
104 // restart of the slide show.
105 if (mpViewShellBase
== nullptr)
108 ::std::shared_ptr
<FrameworkHelper
> pHelper(
109 FrameworkHelper::Instance(*mpViewShellBase
));
110 if (pHelper
->GetConfigurationController()->getResource(
111 FrameworkHelper::CreateResourceId(FrameworkHelper::msFullScreenPaneURL
)).is())
113 ::sd::framework::ConfigurationController::Lock
aLock (
114 pHelper
->GetConfigurationController());
116 pHelper
->RunOnConfigurationEvent(
117 FrameworkHelper::msConfigurationUpdateEndEvent
,
118 ::std::bind(&SlideShowRestarter::StartPresentation
, shared_from_this()));
119 pHelper
->UpdateConfiguration();
127 void SlideShowRestarter::StartPresentation()
129 //rhbz#1091117 crash because we're exiting the application, and this is
130 //being called during the configuration update event on exit. At this point
131 //newly created objects won't get disposed called on them, because the
132 //disposer is doing its last execution of that now.
133 if (mpViewShellBase
&& mpViewShellBase
->GetDrawController().IsDisposing())
136 if (mpDispatcher
== nullptr && mpViewShellBase
!=nullptr)
137 mpDispatcher
= mpViewShellBase
->GetViewFrame()->GetDispatcher();
139 // Start the slide show on the saved current slide.
140 if (mpDispatcher
!= nullptr)
142 mpDispatcher
->Execute(SID_PRESENTATION
, SfxCallMode::ASYNCHRON
);
143 if (mpSlideShow
.is())
145 Sequence
<css::beans::PropertyValue
> aProperties (1);
146 aProperties
[0].Name
= "FirstPage";
147 aProperties
[0].Value
<<= "page" + OUString::number(mnCurrentSlideNumber
+1);
148 mpSlideShow
->startWithArguments(aProperties
);
154 } // end of namespace sd
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */