bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slideshow / SlideShowRestarter.cxx
blobcdf9b8401f9d96745b74c433b1f9b9eabbf41f82
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "SlideShowRestarter.hxx"
22 #include "framework/ConfigurationController.hxx"
23 #include "framework/FrameworkHelper.hxx"
24 #include <comphelper/processfactory.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <sfx2/app.hxx>
28 #include <svx/svxids.hrc>
29 #include <vcl/svapp.hxx>
30 #include <boost/bind.hpp>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using ::sd::framework::FrameworkHelper;
36 namespace sd {
38 SlideShowRestarter::SlideShowRestarter (
39 const ::rtl::Reference<SlideShow>& rpSlideShow,
40 ViewShellBase* pViewShellBase)
41 : mnEventId(0),
42 mpSlideShow(rpSlideShow),
43 mpViewShellBase(pViewShellBase),
44 mnDisplayCount(Application::GetScreenCount()),
45 mpDispatcher(pViewShellBase->GetViewFrame()->GetDispatcher()),
46 mnCurrentSlideNumber(0)
50 SlideShowRestarter::~SlideShowRestarter()
54 void SlideShowRestarter::Restart (bool bForce)
56 // Prevent multiple and concurrently restarts.
57 if (mnEventId != 0)
58 return;
60 if (bForce)
61 mnDisplayCount = 0;
63 // Remember the current slide in order to restore it after the slide
64 // show has been restarted.
65 if (mpSlideShow.is())
66 mnCurrentSlideNumber = mpSlideShow->getCurrentPageNumber();
68 // Remember a shared pointer to this object to prevent its destruction
69 // before the whole restarting process has finished.
70 mpSelf = shared_from_this();
72 // We do not know in what situation this method was called. So, in
73 // order to be able to cleanly stop the presentation, we do that
74 // asynchronously.
75 mnEventId = Application::PostUserEvent(
76 LINK(this, SlideShowRestarter, EndPresentation));
79 IMPL_LINK_NOARG(SlideShowRestarter, EndPresentation)
81 mnEventId = 0;
82 if (mpSlideShow.is())
84 if (mnDisplayCount != (sal_Int32)Application::GetScreenCount())
86 bool bIsExitAfterPresenting = mpSlideShow->IsExitAfterPresenting();
87 mpSlideShow->SetExitAfterPresenting(false);
88 mpSlideShow->end();
89 mpSlideShow->SetExitAfterPresenting(bIsExitAfterPresenting);
91 // The following piece of code should not be here because the
92 // slide show should be aware of the existence of the presenter
93 // console (which is displayed in the FullScreenPane). But the
94 // timing has to be right and I did not find a better place for
95 // it.
97 // Wait for the full screen pane, which displays the presenter
98 // console, to disappear. Only when it is gone, call
99 // InitiatePresenterStart(), in order to begin the asynchronous
100 // restart of the slide show.
101 if (mpViewShellBase != NULL)
103 ::boost::shared_ptr<FrameworkHelper> pHelper(
104 FrameworkHelper::Instance(*mpViewShellBase));
105 if (pHelper->GetConfigurationController()->getResource(
106 FrameworkHelper::CreateResourceId(FrameworkHelper::msFullScreenPaneURL)).is())
108 ::sd::framework::ConfigurationController::Lock aLock (
109 pHelper->GetConfigurationController());
111 pHelper->RunOnConfigurationEvent(
112 FrameworkHelper::msConfigurationUpdateEndEvent,
113 ::boost::bind(&SlideShowRestarter::StartPresentation, shared_from_this()));
114 pHelper->UpdateConfiguration();
116 else
118 StartPresentation();
123 return 0;
126 void SlideShowRestarter::StartPresentation()
128 //rhbz#1091117 crash because we're exiting the application, and this is
129 //being called during the configuration update event on exit. At this point
130 //newly created objects won't get disposed called on them, because the
131 //disposer is doing its last execution of that now.
132 if (mpViewShellBase && mpViewShellBase->GetDrawController().IsDisposing())
133 return;
135 if (mpDispatcher == NULL && mpViewShellBase!=NULL)
136 mpDispatcher = mpViewShellBase->GetViewFrame()->GetDispatcher();
138 // Start the slide show on the saved current slide.
139 if (mpDispatcher != NULL)
141 mpDispatcher->Execute(SID_PRESENTATION, SfxCallMode::ASYNCHRON);
142 if (mpSlideShow.is())
144 Sequence<css::beans::PropertyValue> aProperties (1);
145 aProperties[0].Name = "FirstPage";
146 aProperties[0].Value <<= "page" + OUString::number(mnCurrentSlideNumber+1);
147 mpSlideShow->startWithArguments(aProperties);
149 mpSelf.reset();
153 } // end of namespace sd
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */