15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
55b190011SAndrew Rist * distributed with this work for additional information
65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist * "License"); you may not use this file except in compliance
95b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist * software distributed under the License is distributed on an
155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist * KIND, either express or implied. See the License for the
175b190011SAndrew Rist * specific language governing permissions and limitations
185b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
205b190011SAndrew Rist *************************************************************/
215b190011SAndrew Rist
22cdf0e10cSrcweir #include "precompiled_sd.hxx"
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "SlideShowRestarter.hxx"
25cdf0e10cSrcweir #include "framework/ConfigurationController.hxx"
26cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
27cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
28cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
29cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
30cdf0e10cSrcweir #include <svx/svxids.hrc>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include <boost/bind.hpp>
33cdf0e10cSrcweir
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir using ::sd::framework::FrameworkHelper;
38cdf0e10cSrcweir
39cdf0e10cSrcweir #define C2U(x) OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
40cdf0e10cSrcweir
41cdf0e10cSrcweir namespace sd {
42cdf0e10cSrcweir
SlideShowRestarter(const::rtl::Reference<SlideShow> & rpSlideShow,ViewShellBase * pViewShellBase)43cdf0e10cSrcweir SlideShowRestarter::SlideShowRestarter (
44cdf0e10cSrcweir const ::rtl::Reference<SlideShow>& rpSlideShow,
45cdf0e10cSrcweir ViewShellBase* pViewShellBase)
46cdf0e10cSrcweir : mnEventId(0),
47cdf0e10cSrcweir mpSlideShow(rpSlideShow),
48cdf0e10cSrcweir mpViewShellBase(pViewShellBase),
49cdf0e10cSrcweir mnDisplayCount(GetDisplayCount()),
50cdf0e10cSrcweir mpDispatcher(pViewShellBase->GetViewFrame()->GetDispatcher()),
51cdf0e10cSrcweir mnCurrentSlideNumber(0)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir
~SlideShowRestarter(void)55cdf0e10cSrcweir SlideShowRestarter::~SlideShowRestarter (void)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
Restart(void)59cdf0e10cSrcweir void SlideShowRestarter::Restart (void)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir // Prevent multiple and concurrently restarts.
62cdf0e10cSrcweir if (mnEventId != 0)
63cdf0e10cSrcweir return;
64cdf0e10cSrcweir
65cdf0e10cSrcweir // Remember the current slide in order to restore it after the slide
66cdf0e10cSrcweir // show has been restarted.
67cdf0e10cSrcweir if (mpSlideShow.is())
68cdf0e10cSrcweir mnCurrentSlideNumber = mpSlideShow->getCurrentPageNumber();
69cdf0e10cSrcweir
70cdf0e10cSrcweir // Remember a shared pointer to this object to prevent its destruction
71cdf0e10cSrcweir // before the whole restarting process has finished.
72cdf0e10cSrcweir mpSelf = shared_from_this();
73cdf0e10cSrcweir
74cdf0e10cSrcweir // We do not know in what situation this method was called. So, in
75cdf0e10cSrcweir // order to be able to cleanly stop the presentation, we do that
76cdf0e10cSrcweir // asynchronously.
77cdf0e10cSrcweir mnEventId = Application::PostUserEvent(
78cdf0e10cSrcweir LINK(this, SlideShowRestarter, EndPresentation));
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
GetDisplayCount(void)81cdf0e10cSrcweir sal_Int32 SlideShowRestarter::GetDisplayCount (void)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir const Reference<XComponentContext> xContext (
84cdf0e10cSrcweir ::comphelper::getProcessComponentContext() );
85cdf0e10cSrcweir Reference<XMultiComponentFactory> xFactory (
86cdf0e10cSrcweir xContext->getServiceManager(), UNO_QUERY);
87cdf0e10cSrcweir if ( ! xFactory.is())
88cdf0e10cSrcweir return 0;
89cdf0e10cSrcweir
90cdf0e10cSrcweir Reference<com::sun::star::container::XIndexAccess> xIndexAccess (
91cdf0e10cSrcweir xFactory->createInstanceWithContext(C2U("com.sun.star.awt.DisplayAccess"),xContext),
92cdf0e10cSrcweir UNO_QUERY);
93cdf0e10cSrcweir if ( ! xIndexAccess.is())
94cdf0e10cSrcweir return 0;
95cdf0e10cSrcweir
96cdf0e10cSrcweir return xIndexAccess->getCount();
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
IMPL_LINK(SlideShowRestarter,EndPresentation,void *,EMPTYARG)99cdf0e10cSrcweir IMPL_LINK(SlideShowRestarter, EndPresentation, void*, EMPTYARG)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir mnEventId = 0;
102cdf0e10cSrcweir if (mpSlideShow.is())
103cdf0e10cSrcweir {
104cdf0e10cSrcweir if (mnDisplayCount!=GetDisplayCount())
105cdf0e10cSrcweir {
106cdf0e10cSrcweir mpSlideShow->end();
107cdf0e10cSrcweir
108cdf0e10cSrcweir // The following piece of code should not be here because the
109cdf0e10cSrcweir // slide show should be aware of the existence of the presenter
110cdf0e10cSrcweir // console (which is displayed in the FullScreenPane). But the
111cdf0e10cSrcweir // timing has to be right and I did not find a better place for
112cdf0e10cSrcweir // it.
113cdf0e10cSrcweir
114cdf0e10cSrcweir // Wait for the full screen pane, which displays the presenter
115cdf0e10cSrcweir // console, to disappear. Only when it is gone, call
116cdf0e10cSrcweir // InitiatePresenterStart(), in order to begin the asynchronous
117cdf0e10cSrcweir // restart of the slide show.
118cdf0e10cSrcweir if (mpViewShellBase != NULL)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir ::boost::shared_ptr<FrameworkHelper> pHelper(
121cdf0e10cSrcweir FrameworkHelper::Instance(*mpViewShellBase));
122cdf0e10cSrcweir if (pHelper->GetConfigurationController()->getResource(
123cdf0e10cSrcweir pHelper->CreateResourceId(FrameworkHelper::msFullScreenPaneURL)).is())
124cdf0e10cSrcweir {
125cdf0e10cSrcweir ::sd::framework::ConfigurationController::Lock aLock (
126cdf0e10cSrcweir pHelper->GetConfigurationController());
127cdf0e10cSrcweir
128cdf0e10cSrcweir pHelper->RunOnConfigurationEvent(
129cdf0e10cSrcweir FrameworkHelper::msConfigurationUpdateEndEvent,
130cdf0e10cSrcweir ::boost::bind(&SlideShowRestarter::StartPresentation, shared_from_this()));
131cdf0e10cSrcweir pHelper->UpdateConfiguration();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir else
134cdf0e10cSrcweir {
135cdf0e10cSrcweir StartPresentation();
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir return 0;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
StartPresentation(void)143cdf0e10cSrcweir void SlideShowRestarter::StartPresentation (void)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir if (mpDispatcher == NULL && mpViewShellBase!=NULL)
146cdf0e10cSrcweir mpDispatcher = mpViewShellBase->GetViewFrame()->GetDispatcher();
147cdf0e10cSrcweir
148cdf0e10cSrcweir // Start the slide show on the saved current slide.
149cdf0e10cSrcweir if (mpDispatcher != NULL)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir mpDispatcher->Execute(SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON);
152cdf0e10cSrcweir if (mpSlideShow.is())
153cdf0e10cSrcweir {
154cdf0e10cSrcweir Sequence<css::beans::PropertyValue> aProperties (1);
155cdf0e10cSrcweir aProperties[0].Name = C2U("FirstPage");
156cdf0e10cSrcweir aProperties[0].Value <<= C2U("page") + OUString::valueOf(mnCurrentSlideNumber+1);
157cdf0e10cSrcweir mpSlideShow->startWithArguments(aProperties);
158cdf0e10cSrcweir }
159cdf0e10cSrcweir mpSelf.reset();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir } // end of namespace sd
164*9d97e963Smseidel
165*9d97e963Smseidel /* vim: set noet sw=4 ts=4: */
166