1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
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
;
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
);
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
);
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
;
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
&)
81 SAL_WARN("sdremote", "Receiver::executeCommand: no command");
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");
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");
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;
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
));
157 TOOLS_WARN_EXCEPTION("sdremote", "sd::SlideShowImpl::setPointerPosition()");
162 xSlideShow
->setProperty(beans::PropertyValue(u
"PointerVisible"_ustr
, -1, Any(true),
163 beans::PropertyState_DIRECT_VALUE
));
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
,
182 beans::PropertyState_DIRECT_VALUE
) );
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");
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
,
211 beans::PropertyState_DIRECT_VALUE
) );
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: */