tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / remotecontrol / Receiver.cxx
blob23ac8e9aa4b28e8e3d9293bbaaed57cd1eb60b18
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 #include "Receiver.hxx"
10 #include <com/sun/star/presentation/XSlideShowController.hpp>
11 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
12 #include <com/sun/star/presentation/XPresentation2.hpp>
13 #include <com/sun/star/frame/Desktop.hpp>
14 #include <com/sun/star/uno/RuntimeException.hpp>
16 #include <comphelper/processfactory.hxx>
17 #include <sal/log.hxx>
18 #include <com/sun/star/beans/PropertyValue.hpp>
19 #include <vcl/svapp.hxx>
20 #include <comphelper/diagnose_ex.hxx>
22 using namespace sd;
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::lang;
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star::presentation;
27 using namespace ::com::sun::star::beans;
29 Receiver::Receiver( Transmitter *aTransmitter ) : Timer("sd Receiver")
31 pTransmitter = aTransmitter;
32 SetTimeout( 0 );
35 Receiver::~Receiver()
39 // Bounce the commands to the main thread to avoid threading woes
40 void Receiver::pushCommand( const std::vector<OString> &rCommand )
42 SolarMutexGuard aGuard;
43 maExecQueue.push_back( rCommand );
44 Start();
47 void Receiver::Invoke()
49 if( !maExecQueue.empty() )
51 std::vector< OString > aCommands( maExecQueue.front() );
52 maExecQueue.pop_front();
53 if( !aCommands.empty() )
54 executeCommand( aCommands );
55 Start();
57 else
58 Stop();
61 void Receiver::executeCommand( const std::vector<OString> &aCommand )
63 uno::Reference<presentation::XSlideShowController> xSlideShowController;
64 uno::Reference<presentation::XPresentation2> xPresentation;
65 uno::Reference<presentation::XSlideShow> xSlideShow;
66 try {
67 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
68 uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_SET_THROW );
69 uno::Reference<presentation::XPresentationSupplier> xPS ( xFrame->getController()->getModel(), uno::UNO_QUERY_THROW);
70 xPresentation.set( xPS->getPresentation(), uno::UNO_QUERY_THROW);
71 // Throws an exception if no slideshow running
72 xSlideShowController.set( xPresentation->getController(), uno::UNO_SET_THROW );
73 xSlideShow.set( xSlideShowController->getSlideShow(), uno::UNO_SET_THROW );
75 catch (uno::RuntimeException &)
79 if (aCommand.empty())
81 SAL_WARN("sdremote", "Receiver::executeCommand: no command");
82 return;
85 if ( aCommand[0] == "transition_next" )
87 if ( xSlideShowController.is() )
88 xSlideShowController->gotoNextEffect();
90 else if ( aCommand[0] == "transition_previous" )
92 if ( xSlideShowController.is() )
93 xSlideShowController->gotoPreviousEffect();
95 else if ( aCommand[0] == "goto_slide" )
97 if (aCommand.size() < 2)
99 SAL_WARN("sdremote", "Receiver::executeCommand: invalid goto_slide");
100 return;
102 // FIXME: if 0 returned, then not a valid number
103 sal_Int32 aSlide = aCommand[1].toInt32();
104 if ( xSlideShowController.is() &&
105 xSlideShowController->getCurrentSlideIndex() != aSlide )
107 xSlideShowController->gotoSlideIndex( aSlide );
110 else if ( aCommand[0] == "presentation_start" )
112 if ( xPresentation.is() )
113 xPresentation->start();
115 else if ( aCommand[0] == "presentation_stop" )
117 if ( xPresentation.is() )
118 xPresentation->end();
120 else if ( aCommand[0] == "presentation_blank_screen" )
122 if ( aCommand.size() > 1 )
124 // aColour = FIXME: get the colour in some format from this string
125 // Determine the formatting first.
127 if ( xSlideShowController.is() )
129 xSlideShowController->blankScreen( 0 ); // Default is black
132 else if (aCommand[0] == "pointer_started" )
134 if (aCommand.size() < 3)
136 SAL_WARN("sdremote", "Receiver::executeCommand: invalid pointer_started");
137 return;
139 // std::cerr << "pointer_started" << std::endl;
140 float x = aCommand[1].toFloat();
141 float y = aCommand[2].toFloat();
142 SolarMutexGuard aSolarGuard;
144 const css::geometry::RealPoint2D pos(x,y);
145 // std::cerr << "Pointer at ("<<pos.X<<","<<pos.Y<<")" << std::endl;
147 if (xSlideShow.is())
151 // std::cerr << "pointer_coordination in the is" << std::endl;
152 xSlideShow->setProperty(beans::PropertyValue(u"PointerPosition"_ustr, -1, Any(pos),
153 beans::PropertyState_DIRECT_VALUE));
155 catch (Exception&)
157 TOOLS_WARN_EXCEPTION("sdremote", "sd::SlideShowImpl::setPointerPosition()");
162 xSlideShow->setProperty(beans::PropertyValue(u"PointerVisible"_ustr, -1, Any(true),
163 beans::PropertyState_DIRECT_VALUE));
165 catch (Exception&)
167 TOOLS_WARN_EXCEPTION("sdremote", "sd::SlideShowImpl::setPointerMode()");
171 SAL_INFO( "sdremote", "Pointer started, we display the pointer on screen" );
173 else if (aCommand[0] == "pointer_dismissed" )
175 SolarMutexGuard aSolarGuard;
176 if (xSlideShow.is()) try
178 xSlideShow->setProperty(
179 beans::PropertyValue( u"PointerVisible"_ustr ,
181 Any( false ),
182 beans::PropertyState_DIRECT_VALUE ) );
184 catch ( Exception& )
186 TOOLS_WARN_EXCEPTION( "sdremote", "sd::SlideShowImpl::setPointerMode()" );
189 SAL_INFO( "sdremote", "Pointer dismissed, we hide the pointer on screen" );
191 else if (aCommand[0] == "pointer_coordination" )
193 if (aCommand.size() < 3)
195 SAL_WARN("sdremote", "Receiver::executeCommand: invalid pointer_coordination");
196 return;
198 float x = aCommand[1].toFloat();
199 float y = aCommand[2].toFloat();
201 SAL_INFO( "sdremote", "Pointer at ("<<x<<","<<y<<")" );
202 const css::geometry::RealPoint2D pos(x,y);
204 SolarMutexGuard aSolarGuard;
205 if (xSlideShow.is()) try
207 xSlideShow->setProperty(
208 beans::PropertyValue( u"PointerPosition"_ustr ,
210 Any( pos ),
211 beans::PropertyState_DIRECT_VALUE ) );
213 catch ( Exception& )
215 TOOLS_WARN_EXCEPTION( "sdremote", "sd::SlideShowImpl::setPointerPosition()" );
218 else if ( aCommand[0] == "presentation_resume" )
220 if ( xSlideShowController.is() )
222 xSlideShowController->resume();
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */