/src/libreoffice/sd/source/ui/slideshow/SlideShowRestarter.cxx
Line | Count | Source |
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> |
23 | | #include <ResourceId.hxx> |
24 | | #include "SlideShowRestarter.hxx" |
25 | | |
26 | | #include <comphelper/propertyvalue.hxx> |
27 | | #include <framework/ConfigurationController.hxx> |
28 | | #include <framework/FrameworkHelper.hxx> |
29 | | #include <framework/ConfigurationChangeEvent.hxx> |
30 | | #include <sfx2/dispatch.hxx> |
31 | | #include <sfx2/viewfrm.hxx> |
32 | | #include <svx/svxids.hrc> |
33 | | #include <utility> |
34 | | #include <vcl/svapp.hxx> |
35 | | |
36 | | #include <functional> |
37 | | |
38 | | using namespace ::com::sun::star::uno; |
39 | | using namespace ::com::sun::star::lang; |
40 | | using ::sd::framework::FrameworkHelper; |
41 | | |
42 | | namespace sd { |
43 | | |
44 | | SlideShowRestarter::SlideShowRestarter ( |
45 | | ::rtl::Reference<SlideShow> pSlideShow, |
46 | | ViewShellBase* pViewShellBase) |
47 | 0 | : mnEventId(nullptr), |
48 | 0 | mpSlideShow(std::move(pSlideShow)), |
49 | 0 | mpViewShellBase(pViewShellBase), |
50 | 0 | mnDisplayCount(Application::GetScreenCount()), |
51 | 0 | mpDispatcher(pViewShellBase->GetViewFrame().GetDispatcher()), |
52 | 0 | mnCurrentSlideNumber(0) |
53 | 0 | { |
54 | 0 | } |
55 | | |
56 | | SlideShowRestarter::~SlideShowRestarter() |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | void SlideShowRestarter::Restart (bool bForce) |
61 | 0 | { |
62 | | // Prevent multiple and concurrently restarts. |
63 | 0 | if (mnEventId != nullptr) |
64 | 0 | return; |
65 | | |
66 | 0 | if (bForce) |
67 | 0 | mnDisplayCount = 0; |
68 | | |
69 | | // Remember the current slide in order to restore it after the slide |
70 | | // show has been restarted. |
71 | 0 | if (mpSlideShow.is()) |
72 | 0 | mnCurrentSlideNumber = mpSlideShow->getCurrentPageNumber(); |
73 | | |
74 | | // Remember a shared pointer to this object to prevent its destruction |
75 | | // before the whole restarting process has finished. |
76 | 0 | mpSelf = shared_from_this(); |
77 | | |
78 | | // We do not know in what situation this method was called. So, in |
79 | | // order to be able to cleanly stop the presentation, we do that |
80 | | // asynchronously. |
81 | 0 | mnEventId = Application::PostUserEvent( |
82 | 0 | LINK(this, SlideShowRestarter, EndPresentation)); |
83 | 0 | } |
84 | | |
85 | | IMPL_LINK_NOARG(SlideShowRestarter, EndPresentation, void*, void) |
86 | 0 | { |
87 | 0 | mnEventId = nullptr; |
88 | 0 | if (!mpSlideShow.is()) |
89 | 0 | return; |
90 | | |
91 | 0 | if (mnDisplayCount == static_cast<sal_Int32>(Application::GetScreenCount())) |
92 | 0 | return; |
93 | | |
94 | 0 | bool bIsExitAfterPresenting = mpSlideShow->IsExitAfterPresenting(); |
95 | 0 | mpSlideShow->SetExitAfterPresenting(false); |
96 | 0 | mpSlideShow->end(); |
97 | 0 | mpSlideShow->SetExitAfterPresenting(bIsExitAfterPresenting); |
98 | | |
99 | | // The following piece of code should not be here because the |
100 | | // slide show should be aware of the existence of the presenter |
101 | | // console (which is displayed in the FullScreenPane). But the |
102 | | // timing has to be right and I did not find a better place for |
103 | | // it. |
104 | | |
105 | | // Wait for the full screen pane, which displays the presenter |
106 | | // console, to disappear. Only when it is gone, call |
107 | | // InitiatePresenterStart(), in order to begin the asynchronous |
108 | | // restart of the slide show. |
109 | 0 | if (mpViewShellBase == nullptr) |
110 | 0 | return; |
111 | | |
112 | 0 | ::std::shared_ptr<FrameworkHelper> pHelper( |
113 | 0 | FrameworkHelper::Instance(*mpViewShellBase)); |
114 | 0 | if (pHelper->GetConfigurationController()->getResource( |
115 | 0 | new ::sd::framework::ResourceId(FrameworkHelper::msFullScreenPaneURL)).is()) |
116 | 0 | { |
117 | 0 | ::sd::framework::ConfigurationController::Lock aLock ( |
118 | 0 | pHelper->GetConfigurationController()); |
119 | |
|
120 | 0 | pHelper->RunOnConfigurationEvent( |
121 | 0 | sd::framework::ConfigurationChangeEventType::ConfigurationUpdateEnd, |
122 | 0 | [self = shared_from_this()](bool) { self->StartPresentation(); }); |
123 | 0 | pHelper->UpdateConfiguration(); |
124 | 0 | } |
125 | 0 | else |
126 | 0 | { |
127 | 0 | StartPresentation(); |
128 | 0 | } |
129 | 0 | } |
130 | | |
131 | | void SlideShowRestarter::StartPresentation() |
132 | 0 | { |
133 | | //rhbz#1091117 crash because we're exiting the application, and this is |
134 | | //being called during the configuration update event on exit. At this point |
135 | | //newly created objects won't get disposed called on them, because the |
136 | | //disposer is doing its last execution of that now. |
137 | 0 | if (mpViewShellBase && mpViewShellBase->GetDrawController()->IsDisposing()) |
138 | 0 | return; |
139 | | |
140 | 0 | if (mpDispatcher == nullptr && mpViewShellBase!=nullptr) |
141 | 0 | mpDispatcher = mpViewShellBase->GetViewFrame().GetDispatcher(); |
142 | | |
143 | | // Start the slide show on the saved current slide. |
144 | 0 | if (mpDispatcher != nullptr) |
145 | 0 | { |
146 | 0 | mpDispatcher->Execute(SID_PRESENTATION, SfxCallMode::ASYNCHRON); |
147 | 0 | if (mpSlideShow.is()) |
148 | 0 | { |
149 | 0 | Sequence aProperties{ comphelper::makePropertyValue(u"FirstPage"_ustr, |
150 | 0 | "page" + OUString::number(mnCurrentSlideNumber+1)) }; |
151 | 0 | mpSlideShow->startWithArguments(aProperties); |
152 | 0 | } |
153 | 0 | mpSelf.reset(); |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | | } // end of namespace sd |
158 | | |
159 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |