Line data Source code
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 :
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>
30 :
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::lang;
33 : using ::rtl::OUString;
34 : using ::sd::framework::FrameworkHelper;
35 :
36 :
37 : namespace sd {
38 :
39 0 : SlideShowRestarter::SlideShowRestarter (
40 : const ::rtl::Reference<SlideShow>& rpSlideShow,
41 : ViewShellBase* pViewShellBase)
42 : : mnEventId(0),
43 : mpSlideShow(rpSlideShow),
44 : mpViewShellBase(pViewShellBase),
45 0 : mnDisplayCount(Application::GetScreenCount()),
46 0 : mpDispatcher(pViewShellBase->GetViewFrame()->GetDispatcher()),
47 0 : mnCurrentSlideNumber(0)
48 : {
49 0 : }
50 :
51 0 : SlideShowRestarter::~SlideShowRestarter (void)
52 : {
53 0 : }
54 :
55 0 : void SlideShowRestarter::Restart (bool bForce)
56 : {
57 : // Prevent multiple and concurrently restarts.
58 0 : if (mnEventId != 0)
59 0 : return;
60 :
61 0 : if (bForce)
62 0 : mnDisplayCount = 0;
63 :
64 : // Remember the current slide in order to restore it after the slide
65 : // show has been restarted.
66 0 : if (mpSlideShow.is())
67 0 : mnCurrentSlideNumber = mpSlideShow->getCurrentPageNumber();
68 :
69 : // Remember a shared pointer to this object to prevent its destruction
70 : // before the whole restarting process has finished.
71 0 : mpSelf = shared_from_this();
72 :
73 : // We do not know in what situation this method was called. So, in
74 : // order to be able to cleanly stop the presentation, we do that
75 : // asynchronously.
76 : mnEventId = Application::PostUserEvent(
77 0 : LINK(this, SlideShowRestarter, EndPresentation));
78 : }
79 :
80 0 : IMPL_LINK_NOARG(SlideShowRestarter, EndPresentation)
81 : {
82 0 : mnEventId = 0;
83 0 : if (mpSlideShow.is())
84 : {
85 0 : if (mnDisplayCount != (sal_Int32)Application::GetScreenCount())
86 : {
87 0 : mpSlideShow->end();
88 :
89 : // The following piece of code should not be here because the
90 : // slide show should be aware of the existence of the presenter
91 : // console (which is displayed in the FullScreenPane). But the
92 : // timing has to be right and I did not find a better place for
93 : // it.
94 :
95 : // Wait for the full screen pane, which displays the presenter
96 : // console, to disappear. Only when it is gone, call
97 : // InitiatePresenterStart(), in order to begin the asynchronous
98 : // restart of the slide show.
99 0 : if (mpViewShellBase != NULL)
100 : {
101 : ::boost::shared_ptr<FrameworkHelper> pHelper(
102 0 : FrameworkHelper::Instance(*mpViewShellBase));
103 0 : if (pHelper->GetConfigurationController()->getResource(
104 0 : pHelper->CreateResourceId(FrameworkHelper::msFullScreenPaneURL)).is())
105 : {
106 : ::sd::framework::ConfigurationController::Lock aLock (
107 0 : pHelper->GetConfigurationController());
108 :
109 : pHelper->RunOnConfigurationEvent(
110 : FrameworkHelper::msConfigurationUpdateEndEvent,
111 0 : ::boost::bind(&SlideShowRestarter::StartPresentation, shared_from_this()));
112 0 : pHelper->UpdateConfiguration();
113 : }
114 : else
115 : {
116 0 : StartPresentation();
117 0 : }
118 : }
119 : }
120 : }
121 0 : return 0;
122 : }
123 :
124 0 : void SlideShowRestarter::StartPresentation (void)
125 : {
126 0 : if (mpDispatcher == NULL && mpViewShellBase!=NULL)
127 0 : mpDispatcher = mpViewShellBase->GetViewFrame()->GetDispatcher();
128 :
129 : // Start the slide show on the saved current slide.
130 0 : if (mpDispatcher != NULL)
131 : {
132 0 : mpDispatcher->Execute(SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON);
133 0 : if (mpSlideShow.is())
134 : {
135 0 : Sequence<css::beans::PropertyValue> aProperties (1);
136 0 : aProperties[0].Name = "FirstPage";
137 0 : aProperties[0].Value <<= "page" + OUString::valueOf(mnCurrentSlideNumber+1);
138 0 : mpSlideShow->startWithArguments(aProperties);
139 : }
140 0 : mpSelf.reset();
141 : }
142 0 : }
143 :
144 9 : } // end of namespace sd
145 :
146 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|