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"
11 #include <com/sun/star/presentation/XSlideShowController.hpp>
12 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
13 #include <com/sun/star/presentation/XPresentation2.hpp>
14 #include <com/sun/star/frame/Desktop.hpp>
15 #include <com/sun/star/uno/RuntimeException.hpp>
17 #include <comphelper/processfactory.hxx>
18 #include <comphelper/anytostring.hxx>
19 #include <cppuhelper/exc_hlp.hxx>
20 #include <osl/file.hxx>
21 #include <rtl/ustrbuf.hxx>
22 #include <rtl/strbuf.hxx>
23 #include <sal/log.hxx>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <vcl/svapp.hxx>
26 #include <tools/diagnose_ex.h>
29 using namespace ::osl
;
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::presentation
;
35 using namespace ::com::sun::star::beans
;
37 Receiver::Receiver( Transmitter
*aTransmitter
)
39 pTransmitter
= aTransmitter
;
47 // Bounce the commands to the main thread to avoid threading woes
48 void Receiver::pushCommand( const std::vector
<OString
> &rCommand
)
50 SolarMutexGuard aGuard
;
51 maExecQueue
.push_back( rCommand
);
55 void Receiver::Invoke()
57 if( !maExecQueue
.empty() )
59 std::vector
< OString
> aCommands( maExecQueue
.front() );
60 maExecQueue
.pop_front();
61 if( !aCommands
.empty() )
62 executeCommand( aCommands
);
69 void Receiver::executeCommand( const std::vector
<OString
> &aCommand
)
71 uno::Reference
<presentation::XSlideShowController
> xSlideShowController
;
72 uno::Reference
<presentation::XPresentation2
> xPresentation
;
73 uno::Reference
<presentation::XSlideShow
> xSlideShow
;
75 uno::Reference
< frame::XDesktop2
> xFramesSupplier
= frame::Desktop::create( ::comphelper::getProcessComponentContext() );
76 uno::Reference
< frame::XFrame
> xFrame ( xFramesSupplier
->getActiveFrame(), uno::UNO_SET_THROW
);
77 uno::Reference
<presentation::XPresentationSupplier
> xPS ( xFrame
->getController()->getModel(), uno::UNO_QUERY_THROW
);
78 xPresentation
.set( xPS
->getPresentation(), uno::UNO_QUERY_THROW
);
79 // Throws an exception if now slideshow running
80 xSlideShowController
.set( xPresentation
->getController(), uno::UNO_SET_THROW
);
81 xSlideShow
.set( xSlideShowController
->getSlideShow(), uno::UNO_SET_THROW
);
83 catch (uno::RuntimeException
&)
87 if ( aCommand
[0] == "transition_next" )
89 if ( xSlideShowController
.is() )
90 xSlideShowController
->gotoNextEffect();
92 else if ( aCommand
[0] == "transition_previous" )
94 if ( xSlideShowController
.is() )
95 xSlideShowController
->gotoPreviousEffect();
97 else if ( aCommand
[0] == "goto_slide" )
99 // FIXME: if 0 returned, then not a valid number
100 sal_Int32 aSlide
= aCommand
[1].toInt32();
101 if ( xSlideShowController
.is() &&
102 xSlideShowController
->getCurrentSlideIndex() != aSlide
)
104 xSlideShowController
->gotoSlideIndex( aSlide
);
107 else if ( aCommand
[0] == "presentation_start" )
109 if ( xPresentation
.is() )
110 xPresentation
->start();
112 else if ( aCommand
[0] == "presentation_stop" )
114 if ( xPresentation
.is() )
115 xPresentation
->end();
117 else if ( aCommand
[0] == "presentation_blank_screen" )
119 if ( aCommand
.size() > 1 )
121 // aColour = FIXME: get the colour in some format from this string
122 // Determine the formatting first.
124 if ( xSlideShowController
.is() )
126 xSlideShowController
->blankScreen( 0 ); // Default is black
129 else if (aCommand
[0] == "pointer_started" )
131 // std::cerr << "pointer_started" << std::endl;
132 float x
= aCommand
[1].toFloat();
133 float y
= aCommand
[2].toFloat();
134 SolarMutexGuard aSolarGuard
;
136 const css::geometry::RealPoint2D
pos(x
,y
);
137 // std::cerr << "Pointer at ("<<pos.X<<","<<pos.Y<<")" << std::endl;
143 // std::cerr << "pointer_coordination in the is" << std::endl;
144 xSlideShow
->setProperty(beans::PropertyValue("PointerPosition", -1, makeAny(pos
),
145 beans::PropertyState_DIRECT_VALUE
));
149 SAL_WARN("sdremote", "sd::SlideShowImpl::setPointerPosition(), "
151 << exceptionToString(cppu::getCaughtException()));
156 xSlideShow
->setProperty(beans::PropertyValue("PointerVisible", -1, makeAny(true),
157 beans::PropertyState_DIRECT_VALUE
));
161 SAL_WARN("sdremote", "sd::SlideShowImpl::setPointerMode(), "
163 << exceptionToString(cppu::getCaughtException()));
167 SAL_INFO( "sdremote", "Pointer started, we display the pointer on screen" );
169 else if (aCommand
[0] == "pointer_dismissed" )
171 SolarMutexGuard aSolarGuard
;
172 if (xSlideShow
.is()) try
174 xSlideShow
->setProperty(
175 beans::PropertyValue( "PointerVisible" ,
178 beans::PropertyState_DIRECT_VALUE
) );
182 SAL_WARN( "sdremote", "sd::SlideShowImpl::setPointerMode(), "
183 "exception caught: " << exceptionToString( cppu::getCaughtException() ));
186 SAL_INFO( "sdremote", "Pointer dismissed, we hide the pointer on screen" );
188 else if (aCommand
[0] == "pointer_coordination" )
190 float x
= aCommand
[1].toFloat();
191 float y
= aCommand
[2].toFloat();
193 SAL_INFO( "sdremote", "Pointer at ("<<x
<<","<<y
<<")" );
194 const css::geometry::RealPoint2D
pos(x
,y
);
196 SolarMutexGuard aSolarGuard
;
197 if (xSlideShow
.is()) try
199 xSlideShow
->setProperty(
200 beans::PropertyValue( "PointerPosition" ,
203 beans::PropertyState_DIRECT_VALUE
) );
207 SAL_WARN( "sdremote", "sd::SlideShowImpl::setPointerPosition(), "
208 "exception caught: " << exceptionToString( cppu::getCaughtException() ));
211 else if ( aCommand
[0] == "presentation_resume" )
213 if ( xSlideShowController
.is() )
215 xSlideShowController
->resume();
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */