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/frame/XFramesSupplier.hpp>
16 #include <com/sun/star/uno/RuntimeException.hpp>
18 #include <comphelper/processfactory.hxx>
19 #include <comphelper/anytostring.hxx>
20 #include "cppuhelper/exc_hlp.hxx"
21 #include <osl/file.hxx>
22 #include <rtl/ustrbuf.hxx>
23 #include <rtl/strbuf.hxx>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/presentation/SlideShow.hpp>
28 using namespace ::com::sun::star
;
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
.size() )
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_QUERY_THROW
);
77 uno::Reference
<presentation::XPresentationSupplier
> xPS ( xFrame
->getController()->getModel(), uno::UNO_QUERY_THROW
);
78 xPresentation
= uno::Reference
<presentation::XPresentation2
>(
79 xPS
->getPresentation(), uno::UNO_QUERY_THROW
);
80 // Throws an exception if now slideshow running
81 xSlideShowController
= uno::Reference
<presentation::XSlideShowController
>(
82 xPresentation
->getController(), uno::UNO_QUERY_THROW
);
83 xSlideShow
= uno::Reference
<presentation::XSlideShow
>(
84 xSlideShowController
->getSlideShow(), uno::UNO_QUERY_THROW
);
86 catch (uno::RuntimeException
&)
90 if ( aCommand
[0].equals( "transition_next" ) )
92 if ( xSlideShowController
.is() )
93 xSlideShowController
->gotoNextEffect();
95 else if ( aCommand
[0].equals( "transition_previous" ) )
97 if ( xSlideShowController
.is() )
98 xSlideShowController
->gotoPreviousEffect();
100 else if ( aCommand
[0].equals( "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].equals( "presentation_start" ) )
112 if ( xPresentation
.is() )
113 xPresentation
->start();
115 else if ( aCommand
[0].equals( "presentation_stop" ) )
117 if ( xPresentation
.is() )
118 xPresentation
->end();
120 else if ( aCommand
[0].equals( "presentation_blank_screen" ) )
122 sal_Int32 aColour
= 0; // Default is black
123 if ( aCommand
.size() > 1 )
125 // aColour = FIXME: get the colour in some format from this string
126 // Determine the formatting first.
128 if ( xSlideShowController
.is() )
130 xSlideShowController
->blankScreen( aColour
);
133 else if (aCommand
[0].equals( "pointer_started" ))
135 // std::cerr << "pointer_started" << std::endl;
136 float x
= aCommand
[1].toFloat();
137 float y
= aCommand
[2].toFloat();
138 SolarMutexGuard aSolarGuard
;
140 const ::com::sun::star::geometry::RealPoint2D
pos(x
,y
);
141 // std::cerr << "Pointer at ("<<pos.X<<","<<pos.Y<<")" << std::endl;
143 if (xSlideShow
.is()) try
145 // std::cerr << "pointer_coordination in the is" << std::endl;
146 xSlideShow
->setProperty(
147 beans::PropertyValue( "PointerPosition" ,
150 beans::PropertyState_DIRECT_VALUE
) );
154 SAL_WARN( "sd.slideshow", "sd::SlideShowImpl::setPointerPosition(), "
155 "exception caught: " << comphelper::anyToString( cppu::getCaughtException() ));
158 if (xSlideShow
.is()) try
160 xSlideShow
->setProperty(
161 beans::PropertyValue( "PointerVisible" ,
164 beans::PropertyState_DIRECT_VALUE
) );
168 SAL_WARN( "sd.slideshow", "sd::SlideShowImpl::setPointerMode(), "
169 "exception caught: " << comphelper::anyToString( cppu::getCaughtException() ));
172 SAL_INFO( "sdremote", "Pointer started, we display the pointer on screen" );
174 else if (aCommand
[0].equals( "pointer_dismissed" ))
176 SolarMutexGuard aSolarGuard
;
177 if (xSlideShow
.is()) try
179 xSlideShow
->setProperty(
180 beans::PropertyValue( "PointerVisible" ,
183 beans::PropertyState_DIRECT_VALUE
) );
187 SAL_WARN( "sd.slideshow", "sd::SlideShowImpl::setPointerMode(), "
188 "exception caught: " << comphelper::anyToString( cppu::getCaughtException() ));
191 SAL_INFO( "sdremote", "Pointer dismissed, we hide the pointer on screen" );
193 else if (aCommand
[0].equals( "pointer_coordination" ))
195 float x
= aCommand
[1].toFloat();
196 float y
= aCommand
[2].toFloat();
198 SAL_INFO( "sdremote", "Pointer at ("<<x
<<","<<y
<<")" );
199 const ::com::sun::star::geometry::RealPoint2D
pos(x
,y
);
201 SolarMutexGuard aSolarGuard
;
202 if (xSlideShow
.is()) try
204 xSlideShow
->setProperty(
205 beans::PropertyValue( "PointerPosition" ,
208 beans::PropertyState_DIRECT_VALUE
) );
212 SAL_WARN( "sd.slideshow", "sd::SlideShowImpl::setPointerPosition(), "
213 "exception caught: " << comphelper::anyToString( cppu::getCaughtException() ));
216 else if ( aCommand
[0].equals( "presentation_resume" ) )
218 if ( xSlideShowController
.is() )
220 xSlideShowController
->resume();
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */