merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slideshow / SlideShowRestarter.cxx
blob1a9c226677f6f784db32095dafda0fc157a10dc0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideShowRestarter.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "SlideShowRestarter.hxx"
34 #include "framework/ConfigurationController.hxx"
35 #include "framework/FrameworkHelper.hxx"
36 #include <comphelper/processfactory.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <svx/svxids.hrc>
40 #include <vcl/svapp.hxx>
41 #include <boost/bind.hpp>
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using ::rtl::OUString;
46 using ::sd::framework::FrameworkHelper;
48 #define C2U(x) OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
50 namespace sd {
52 SlideShowRestarter::SlideShowRestarter (
53 const ::rtl::Reference<SlideShow>& rpSlideShow,
54 ViewShellBase* pViewShellBase)
55 : mnEventId(0),
56 mpSlideShow(rpSlideShow),
57 mpViewShellBase(pViewShellBase),
58 mnDisplayCount(GetDisplayCount()),
59 mpDispatcher(pViewShellBase->GetViewFrame()->GetDispatcher()),
60 mnCurrentSlideNumber(0)
67 SlideShowRestarter::~SlideShowRestarter (void)
74 void SlideShowRestarter::Restart (void)
76 // Prevent multiple and concurrently restarts.
77 if (mnEventId != 0)
78 return;
80 // Remember the current slide in order to restore it after the slide
81 // show has been restarted.
82 if (mpSlideShow.is())
83 mnCurrentSlideNumber = mpSlideShow->getCurrentPageNumber();
85 // Remember a shared pointer to this object to prevent its destruction
86 // before the whole restarting process has finished.
87 mpSelf = shared_from_this();
89 // We do not know in what situation this method was called. So, in
90 // order to be able to cleanly stop the presentation, we do that
91 // asynchronously.
92 mnEventId = Application::PostUserEvent(
93 LINK(this, SlideShowRestarter, EndPresentation));
99 sal_Int32 SlideShowRestarter::GetDisplayCount (void)
101 const Reference<XComponentContext> xContext (
102 ::comphelper::getProcessComponentContext() );
103 Reference<XMultiComponentFactory> xFactory (
104 xContext->getServiceManager(), UNO_QUERY);
105 if ( ! xFactory.is())
106 return 0;
108 Reference<com::sun::star::container::XIndexAccess> xIndexAccess (
109 xFactory->createInstanceWithContext(C2U("com.sun.star.awt.DisplayAccess"),xContext),
110 UNO_QUERY);
111 if ( ! xIndexAccess.is())
112 return 0;
114 return xIndexAccess->getCount();
120 IMPL_LINK(SlideShowRestarter, EndPresentation, void*, EMPTYARG)
122 mnEventId = 0;
123 if (mpSlideShow.is())
125 if (mnDisplayCount!=GetDisplayCount())
127 mpSlideShow->end();
129 // The following piece of code should not be here because the
130 // slide show should be aware of the existence of the presenter
131 // console (which is displayed in the FullScreenPane). But the
132 // timing has to be right and I did not find a better place for
133 // it.
135 // Wait for the full screen pane, which displays the presenter
136 // console, to disappear. Only when it is gone, call
137 // InitiatePresenterStart(), in order to begin the asynchronous
138 // restart of the slide show.
139 if (mpViewShellBase != NULL)
141 ::boost::shared_ptr<FrameworkHelper> pHelper(
142 FrameworkHelper::Instance(*mpViewShellBase));
143 if (pHelper->GetConfigurationController()->getResource(
144 pHelper->CreateResourceId(FrameworkHelper::msFullScreenPaneURL)).is())
146 ::sd::framework::ConfigurationController::Lock aLock (
147 pHelper->GetConfigurationController());
149 pHelper->RunOnConfigurationEvent(
150 FrameworkHelper::msConfigurationUpdateEndEvent,
151 ::boost::bind(&SlideShowRestarter::StartPresentation, shared_from_this()));
152 pHelper->UpdateConfiguration();
154 else
156 StartPresentation();
161 return 0;
167 void SlideShowRestarter::StartPresentation (void)
169 if (mpDispatcher == NULL && mpViewShellBase!=NULL)
170 mpDispatcher = mpViewShellBase->GetViewFrame()->GetDispatcher();
172 // Start the slide show on the saved current slide.
173 if (mpDispatcher != NULL)
175 mpDispatcher->Execute(SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON);
176 if (mpSlideShow.is())
178 Sequence<css::beans::PropertyValue> aProperties (1);
179 aProperties[0].Name = C2U("FirstPage");
180 aProperties[0].Value <<= C2U("page") + OUString::valueOf(mnCurrentSlideNumber+1);
181 mpSlideShow->startWithArguments(aProperties);
183 mpSelf.reset();
187 } // end of namespace sd