1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideShowRestarter.cxx,v $
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) )
52 SlideShowRestarter::SlideShowRestarter (
53 const ::rtl::Reference
<SlideShow
>& rpSlideShow
,
54 ViewShellBase
* pViewShellBase
)
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.
80 // Remember the current slide in order to restore it after the slide
81 // show has been restarted.
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
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())
108 Reference
<com::sun::star::container::XIndexAccess
> xIndexAccess (
109 xFactory
->createInstanceWithContext(C2U("com.sun.star.awt.DisplayAccess"),xContext
),
111 if ( ! xIndexAccess
.is())
114 return xIndexAccess
->getCount();
120 IMPL_LINK(SlideShowRestarter
, EndPresentation
, void*, EMPTYARG
)
123 if (mpSlideShow
.is())
125 if (mnDisplayCount
!=GetDisplayCount())
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
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();
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
);
187 } // end of namespace sd