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