bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / slideshow / SlideShowRestarter.cxx
blobb4fb2b0d218c76266fc8f15a5112a9d69a211540
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 .
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 <svx/svxids.hrc>
28 #include <vcl/svapp.hxx>
29 #include <boost/bind.hpp>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 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 (void)
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 mpSlideShow->end();
88 // The following piece of code should not be here because the
89 // slide show should be aware of the existence of the presenter
90 // console (which is displayed in the FullScreenPane). But the
91 // timing has to be right and I did not find a better place for
92 // it.
94 // Wait for the full screen pane, which displays the presenter
95 // console, to disappear. Only when it is gone, call
96 // InitiatePresenterStart(), in order to begin the asynchronous
97 // restart of the slide show.
98 if (mpViewShellBase != NULL)
100 ::boost::shared_ptr<FrameworkHelper> pHelper(
101 FrameworkHelper::Instance(*mpViewShellBase));
102 if (pHelper->GetConfigurationController()->getResource(
103 pHelper->CreateResourceId(FrameworkHelper::msFullScreenPaneURL)).is())
105 ::sd::framework::ConfigurationController::Lock aLock (
106 pHelper->GetConfigurationController());
108 pHelper->RunOnConfigurationEvent(
109 FrameworkHelper::msConfigurationUpdateEndEvent,
110 ::boost::bind(&SlideShowRestarter::StartPresentation, shared_from_this()));
111 pHelper->UpdateConfiguration();
113 else
115 StartPresentation();
120 return 0;
123 void SlideShowRestarter::StartPresentation (void)
125 if (mpDispatcher == NULL && mpViewShellBase!=NULL)
126 mpDispatcher = mpViewShellBase->GetViewFrame()->GetDispatcher();
128 // Start the slide show on the saved current slide.
129 if (mpDispatcher != NULL)
131 mpDispatcher->Execute(SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON);
132 if (mpSlideShow.is())
134 Sequence<css::beans::PropertyValue> aProperties (1);
135 aProperties[0].Name = "FirstPage";
136 aProperties[0].Value <<= "page" + OUString::valueOf(mnCurrentSlideNumber+1);
137 mpSlideShow->startWithArguments(aProperties);
139 mpSelf.reset();
143 } // end of namespace sd
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */