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 // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir #include <slideshowviewimpl.hxx>
27cdf0e10cSrcweir #include <slideshowimpl.hxx>
28cdf0e10cSrcweir #include <vos/mutex.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
33cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
34cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx>
37cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir
40cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
41cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
42cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
43cdf0e10cSrcweir using ::com::sun::star::uno::WeakReference;
44cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
45cdf0e10cSrcweir using ::com::sun::star::lang::XComponent;
46cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
47cdf0e10cSrcweir using ::com::sun::star::presentation::XSlideShow;
48cdf0e10cSrcweir using ::com::sun::star::presentation::XSlideShowView;
49cdf0e10cSrcweir using ::com::sun::star::presentation::XShapeEventListener;
50cdf0e10cSrcweir using ::com::sun::star::presentation::XSlideShowListener;
51cdf0e10cSrcweir using ::comphelper::ImplementationReference;
52cdf0e10cSrcweir
53cdf0e10cSrcweir using ::rtl::OUString;
54cdf0e10cSrcweir using namespace ::com::sun::star;
55cdf0e10cSrcweir using namespace ::com::sun::star;
56cdf0e10cSrcweir
57cdf0e10cSrcweir namespace sd
58cdf0e10cSrcweir {
59cdf0e10cSrcweir
60cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
61cdf0e10cSrcweir // SlideShowViewListeners
62cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
63cdf0e10cSrcweir
SlideShowViewListeners(::osl::Mutex & rMutex)64cdf0e10cSrcweir SlideShowViewListeners::SlideShowViewListeners( ::osl::Mutex& rMutex )
65cdf0e10cSrcweir : mrMutex( rMutex )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
addListener(const Reference<util::XModifyListener> & _rxListener)69cdf0e10cSrcweir void SlideShowViewListeners::addListener( const Reference< util::XModifyListener >& _rxListener )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir ::osl::MutexGuard aGuard( mrMutex );
72cdf0e10cSrcweir
73cdf0e10cSrcweir WeakReference< util::XModifyListener > xWeak( _rxListener );
74cdf0e10cSrcweir if( std::find( maListeners.begin(), maListeners.end(), xWeak ) == maListeners.end() )
75cdf0e10cSrcweir maListeners.push_back( xWeak );
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
removeListener(const Reference<util::XModifyListener> & _rxListener)78cdf0e10cSrcweir void SlideShowViewListeners::removeListener( const Reference< util::XModifyListener >& _rxListener )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir ::osl::MutexGuard aGuard( mrMutex );
81cdf0e10cSrcweir
82cdf0e10cSrcweir WeakReference< util::XModifyListener > xWeak( _rxListener );
83cdf0e10cSrcweir ViewListenerVector::iterator aIter( std::find( maListeners.begin(), maListeners.end(), xWeak ) );
84cdf0e10cSrcweir if( aIter != maListeners.end() )
85cdf0e10cSrcweir maListeners.erase( aIter );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
notify(const lang::EventObject & _rEvent)88cdf0e10cSrcweir bool SlideShowViewListeners::notify( const lang::EventObject& _rEvent ) throw( com::sun::star::uno::Exception )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir ::osl::MutexGuard aGuard( mrMutex );
91cdf0e10cSrcweir
92cdf0e10cSrcweir ViewListenerVector::iterator aIter( maListeners.begin() );
93cdf0e10cSrcweir while( aIter != maListeners.end() )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir Reference< util::XModifyListener > xListener( (*aIter) );
96cdf0e10cSrcweir if( xListener.is() )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir xListener->modified( _rEvent );
99cdf0e10cSrcweir aIter++;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir else
102cdf0e10cSrcweir {
103cdf0e10cSrcweir aIter = maListeners.erase( aIter );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir }
106cdf0e10cSrcweir return true;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
disposing(const lang::EventObject & _rEventSource)109cdf0e10cSrcweir void SlideShowViewListeners::disposing( const lang::EventObject& _rEventSource )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ::osl::MutexGuard aGuard( mrMutex );
112cdf0e10cSrcweir
113cdf0e10cSrcweir ViewListenerVector::iterator aIter( maListeners.begin() );
114cdf0e10cSrcweir while( aIter != maListeners.end() )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir Reference< util::XModifyListener > xListener( (*aIter++) );
117cdf0e10cSrcweir if( xListener.is() )
118cdf0e10cSrcweir xListener->disposing( _rEventSource );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir maListeners.clear();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
125cdf0e10cSrcweir // SlideShowViewPaintListeners
126cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
127cdf0e10cSrcweir
SlideShowViewPaintListeners(::osl::Mutex & rMutex)128cdf0e10cSrcweir SlideShowViewPaintListeners::SlideShowViewPaintListeners( ::osl::Mutex& rMutex )
129cdf0e10cSrcweir : SlideShowViewPaintListeners_Base( rMutex )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
implTypedNotify(const Reference<awt::XPaintListener> & rListener,const awt::PaintEvent & rEvent)133cdf0e10cSrcweir bool SlideShowViewPaintListeners::implTypedNotify( const Reference< awt::XPaintListener >& rListener,
134cdf0e10cSrcweir const awt::PaintEvent& rEvent ) throw( uno::Exception )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir rListener->windowPaint( rEvent );
137cdf0e10cSrcweir return true; // continue calling listeners
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
141cdf0e10cSrcweir // SlideShowViewMouseListeners
142cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
143cdf0e10cSrcweir
SlideShowViewMouseListeners(::osl::Mutex & rMutex)144cdf0e10cSrcweir SlideShowViewMouseListeners::SlideShowViewMouseListeners( ::osl::Mutex& rMutex ) :
145cdf0e10cSrcweir SlideShowViewMouseListeners_Base( rMutex )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
implTypedNotify(const Reference<awt::XMouseListener> & rListener,const WrappedMouseEvent & rEvent)149cdf0e10cSrcweir bool SlideShowViewMouseListeners::implTypedNotify( const Reference< awt::XMouseListener >& rListener,
150cdf0e10cSrcweir const WrappedMouseEvent& rEvent ) throw( uno::Exception )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir switch( rEvent.meType )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir case WrappedMouseEvent::PRESSED:
155cdf0e10cSrcweir rListener->mousePressed( rEvent.maEvent );
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir
158cdf0e10cSrcweir case WrappedMouseEvent::RELEASED:
159cdf0e10cSrcweir rListener->mouseReleased( rEvent.maEvent );
160cdf0e10cSrcweir break;
161cdf0e10cSrcweir
162cdf0e10cSrcweir case WrappedMouseEvent::ENTERED:
163cdf0e10cSrcweir rListener->mouseEntered( rEvent.maEvent );
164cdf0e10cSrcweir break;
165cdf0e10cSrcweir
166cdf0e10cSrcweir case WrappedMouseEvent::EXITED:
167cdf0e10cSrcweir rListener->mouseExited( rEvent.maEvent );
168cdf0e10cSrcweir break;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
171cdf0e10cSrcweir return true; // continue calling listeners
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
175cdf0e10cSrcweir // SlideShowViewMouseMotionListeners
176cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
177cdf0e10cSrcweir
SlideShowViewMouseMotionListeners(::osl::Mutex & rMutex)178cdf0e10cSrcweir SlideShowViewMouseMotionListeners::SlideShowViewMouseMotionListeners( ::osl::Mutex& rMutex ) :
179cdf0e10cSrcweir SlideShowViewMouseMotionListeners_Base( rMutex )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
implTypedNotify(const Reference<awt::XMouseMotionListener> & rListener,const WrappedMouseMotionEvent & rEvent)183cdf0e10cSrcweir bool SlideShowViewMouseMotionListeners::implTypedNotify( const Reference< awt::XMouseMotionListener >& rListener,
184cdf0e10cSrcweir const WrappedMouseMotionEvent& rEvent ) throw( uno::Exception )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir switch( rEvent.meType )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir case WrappedMouseMotionEvent::DRAGGED:
189cdf0e10cSrcweir rListener->mouseDragged( rEvent.maEvent );
190cdf0e10cSrcweir break;
191cdf0e10cSrcweir
192cdf0e10cSrcweir case WrappedMouseMotionEvent::MOVED:
193cdf0e10cSrcweir rListener->mouseMoved( rEvent.maEvent );
194cdf0e10cSrcweir break;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir return true; // continue calling listeners
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
201cdf0e10cSrcweir // SlideShowView
202cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
203cdf0e10cSrcweir
SlideShowView(ShowWindow & rOutputWindow,SdDrawDocument * pDoc,AnimationMode eAnimationMode,SlideshowImpl * pSlideShow,bool bFullScreen)204cdf0e10cSrcweir SlideShowView::SlideShowView( ShowWindow& rOutputWindow,
205cdf0e10cSrcweir SdDrawDocument* pDoc,
206cdf0e10cSrcweir AnimationMode eAnimationMode,
207cdf0e10cSrcweir SlideshowImpl* pSlideShow,
208cdf0e10cSrcweir bool bFullScreen )
209cdf0e10cSrcweir : SlideShowView_Base( m_aMutex ),
210cdf0e10cSrcweir mpCanvas( ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( rOutputWindow ) ),
211cdf0e10cSrcweir mxWindow( VCLUnoHelper::GetInterface( &rOutputWindow ), uno::UNO_QUERY_THROW ),
212cdf0e10cSrcweir mxWindowPeer( mxWindow, uno::UNO_QUERY_THROW ),
213cdf0e10cSrcweir mxPointer(),
214cdf0e10cSrcweir mpSlideShow( pSlideShow ),
215cdf0e10cSrcweir mrOutputWindow( rOutputWindow ),
216cdf0e10cSrcweir mpViewListeners( new SlideShowViewListeners( m_aMutex ) ),
217cdf0e10cSrcweir mpPaintListeners( new SlideShowViewPaintListeners( m_aMutex ) ),
218cdf0e10cSrcweir mpMouseListeners( new SlideShowViewMouseListeners( m_aMutex ) ),
219cdf0e10cSrcweir mpMouseMotionListeners( new SlideShowViewMouseMotionListeners( m_aMutex ) ),
220cdf0e10cSrcweir mpDoc( pDoc ),
221cdf0e10cSrcweir mbIsMouseMotionListener( false ),
222cdf0e10cSrcweir meAnimationMode( eAnimationMode ),
223cdf0e10cSrcweir mbFirstPaint( true ),
224cdf0e10cSrcweir mbFullScreen( bFullScreen ),
225cdf0e10cSrcweir mbMousePressedEaten( false )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir init();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir /// Dispose all internal references
dispose()231cdf0e10cSrcweir void SAL_CALL SlideShowView::dispose() throw (RuntimeException)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
234cdf0e10cSrcweir
235cdf0e10cSrcweir mpSlideShow = 0;
236cdf0e10cSrcweir
237cdf0e10cSrcweir // deregister listeners
238cdf0e10cSrcweir if( mxWindow.is() )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir mxWindow->removeWindowListener( this );
241cdf0e10cSrcweir mxWindow->removeMouseListener( this );
242cdf0e10cSrcweir
243cdf0e10cSrcweir if( mbIsMouseMotionListener )
244cdf0e10cSrcweir mxWindow->removeMouseMotionListener( this );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir mpCanvas.reset();
248cdf0e10cSrcweir mxWindow.clear();
249cdf0e10cSrcweir
250cdf0e10cSrcweir // clear all listener containers
251cdf0e10cSrcweir disposing( lang::EventObject() );
252cdf0e10cSrcweir
253cdf0e10cSrcweir // call base
254cdf0e10cSrcweir WeakComponentImplHelperBase::dispose();
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir /// Disposing our broadcaster
disposing(const lang::EventObject &)258cdf0e10cSrcweir void SAL_CALL SlideShowView::disposing( const lang::EventObject& ) throw(RuntimeException)
259cdf0e10cSrcweir {
260cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
261cdf0e10cSrcweir
262cdf0e10cSrcweir // notify all listeners that _we_ are going down (send a disposing()),
263cdf0e10cSrcweir // then delete listener containers:
264cdf0e10cSrcweir lang::EventObject const evt( static_cast<OWeakObject *>(this) );
265cdf0e10cSrcweir if (mpViewListeners.get() != 0) {
266cdf0e10cSrcweir mpViewListeners->disposing( evt );
267cdf0e10cSrcweir mpViewListeners.reset();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir if (mpPaintListeners.get() != 0) {
270cdf0e10cSrcweir mpPaintListeners->disposing( evt );
271cdf0e10cSrcweir mpPaintListeners.reset();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir if (mpMouseListeners.get() != 0) {
274cdf0e10cSrcweir mpMouseListeners->disposing( evt );
275cdf0e10cSrcweir mpMouseListeners.reset();
276cdf0e10cSrcweir }
277cdf0e10cSrcweir if (mpMouseMotionListeners.get() != 0) {
278cdf0e10cSrcweir mpMouseMotionListeners->disposing( evt );
279cdf0e10cSrcweir mpMouseMotionListeners.reset();
280cdf0e10cSrcweir }
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
paint(const awt::PaintEvent & e)283cdf0e10cSrcweir void SAL_CALL SlideShowView::paint( const awt::PaintEvent& e ) throw (RuntimeException)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
286cdf0e10cSrcweir
287cdf0e10cSrcweir if( mbFirstPaint )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir mbFirstPaint = false;
290cdf0e10cSrcweir SlideshowImpl* pSlideShow = mpSlideShow;
291cdf0e10cSrcweir aGuard.clear();
292cdf0e10cSrcweir if( pSlideShow )
293cdf0e10cSrcweir pSlideShow->onFirstPaint();
294cdf0e10cSrcweir }
295cdf0e10cSrcweir else
296cdf0e10cSrcweir {
297cdf0e10cSrcweir // Change event source, to enable listeners to match event
298cdf0e10cSrcweir // with view
299cdf0e10cSrcweir awt::PaintEvent aEvent( e );
300cdf0e10cSrcweir aEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
301cdf0e10cSrcweir mpPaintListeners->notify( aEvent );
302cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
303cdf0e10cSrcweir }
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306cdf0e10cSrcweir // XSlideShowView methods
getCanvas()307cdf0e10cSrcweir Reference< rendering::XSpriteCanvas > SAL_CALL SlideShowView::getCanvas( ) throw (RuntimeException)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
310cdf0e10cSrcweir
311cdf0e10cSrcweir return mpCanvas.get() ? mpCanvas->getUNOSpriteCanvas() : Reference< rendering::XSpriteCanvas >();
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
clear()314cdf0e10cSrcweir void SAL_CALL SlideShowView::clear() throw (::com::sun::star::uno::RuntimeException)
315cdf0e10cSrcweir {
316cdf0e10cSrcweir // paint background in black
317cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
318cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
319cdf0e10cSrcweir
320cdf0e10cSrcweir // fill the bounds rectangle in black
321cdf0e10cSrcweir // ----------------------------------
322cdf0e10cSrcweir
323cdf0e10cSrcweir const Size aWindowSize( mrOutputWindow.GetSizePixel() );
324cdf0e10cSrcweir
325cdf0e10cSrcweir ::basegfx::B2DPolygon aPoly( ::basegfx::tools::createPolygonFromRect(
326cdf0e10cSrcweir ::basegfx::B2DRectangle(0.0,0.0,
327cdf0e10cSrcweir aWindowSize.Width(),
328cdf0e10cSrcweir aWindowSize.Height() ) ) );
329cdf0e10cSrcweir ::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
330cdf0e10cSrcweir ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( mpCanvas, aPoly ) );
331cdf0e10cSrcweir
332cdf0e10cSrcweir if( pPolyPoly.get() )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir pPolyPoly->setRGBAFillColor( 0x000000FFU );
335cdf0e10cSrcweir pPolyPoly->draw();
336cdf0e10cSrcweir }
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
getTransformation()339cdf0e10cSrcweir geometry::AffineMatrix2D SAL_CALL SlideShowView::getTransformation( ) throw (RuntimeException)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
342cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
343cdf0e10cSrcweir
344cdf0e10cSrcweir const Size& rTmpSize( mrOutputWindow.GetSizePixel() );
345cdf0e10cSrcweir
346cdf0e10cSrcweir if (rTmpSize.Width()<=0 || rTmpSize.Height()<=0)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir return geometry::AffineMatrix2D (1,0,0,0,1,0);
349cdf0e10cSrcweir }
350cdf0e10cSrcweir
351cdf0e10cSrcweir // Reduce available width by one, as the slides might actually
352cdf0e10cSrcweir // render one pixel wider and higher as aPageSize below specifies
353cdf0e10cSrcweir // (when shapes of page size have visible border lines)
354cdf0e10cSrcweir const Size aWindowSize( rTmpSize.Width()-1,
355cdf0e10cSrcweir rTmpSize.Height()-1 );
356cdf0e10cSrcweir Size aOutputSize( aWindowSize );
357cdf0e10cSrcweir
358cdf0e10cSrcweir if( meAnimationMode != ANIMATIONMODE_SHOW )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir aOutputSize.Width() = (long)( aOutputSize.Width() / 1.03 );
361cdf0e10cSrcweir aOutputSize.Height() = (long)( aOutputSize.Height() / 1.03 );
362cdf0e10cSrcweir }
363cdf0e10cSrcweir
364cdf0e10cSrcweir SdPage* pP = mpDoc->GetSdPage( 0, PK_STANDARD );
365cdf0e10cSrcweir Size aPageSize( pP->GetSize() );
366cdf0e10cSrcweir
367cdf0e10cSrcweir const double page_ratio = (double)aPageSize.Width() / (double)aPageSize.Height();
368cdf0e10cSrcweir const double output_ratio = (double)aOutputSize.Width() / (double)aOutputSize.Height();
369cdf0e10cSrcweir
370cdf0e10cSrcweir if( page_ratio > output_ratio )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir aOutputSize.Height() = ( aOutputSize.Width() * aPageSize.Height() ) / aPageSize.Width();
373cdf0e10cSrcweir }
374cdf0e10cSrcweir else if( page_ratio < output_ratio )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir aOutputSize.Width() = ( aOutputSize.Height() * aPageSize.Width() ) / aPageSize.Height();
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
379cdf0e10cSrcweir Point aOutputOffset( ( aWindowSize.Width() - aOutputSize.Width() ) >> 1,
380cdf0e10cSrcweir ( aWindowSize.Height() - aOutputSize.Height() ) >> 1 );
381cdf0e10cSrcweir
382cdf0e10cSrcweir maPresentationArea = Rectangle( aOutputOffset, aOutputSize );
383cdf0e10cSrcweir mrOutputWindow.SetPresentationArea( maPresentationArea );
384cdf0e10cSrcweir
385cdf0e10cSrcweir // scale presentation into available window rect (minus 10%); center in the window
386cdf0e10cSrcweir const basegfx::B2DHomMatrix aMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix(
387cdf0e10cSrcweir aOutputSize.Width(), aOutputSize.Height(), aOutputOffset.X(), aOutputOffset.Y()));
388cdf0e10cSrcweir
389cdf0e10cSrcweir geometry::AffineMatrix2D aRes;
390cdf0e10cSrcweir
391cdf0e10cSrcweir return ::basegfx::unotools::affineMatrixFromHomMatrix( aRes, aMatrix );
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
addTransformationChangedListener(const Reference<util::XModifyListener> & xListener)394cdf0e10cSrcweir void SAL_CALL SlideShowView::addTransformationChangedListener( const Reference< util::XModifyListener >& xListener ) throw (RuntimeException)
395cdf0e10cSrcweir {
396cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
397cdf0e10cSrcweir
398cdf0e10cSrcweir if( mpViewListeners.get() )
399cdf0e10cSrcweir mpViewListeners->addListener( xListener );
400cdf0e10cSrcweir }
401cdf0e10cSrcweir
removeTransformationChangedListener(const Reference<util::XModifyListener> & xListener)402cdf0e10cSrcweir void SAL_CALL SlideShowView::removeTransformationChangedListener( const Reference< util::XModifyListener >& xListener ) throw (RuntimeException)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
405cdf0e10cSrcweir
406cdf0e10cSrcweir if( mpViewListeners.get() )
407cdf0e10cSrcweir mpViewListeners->removeListener( xListener );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
addPaintListener(const Reference<awt::XPaintListener> & xListener)410cdf0e10cSrcweir void SAL_CALL SlideShowView::addPaintListener( const Reference< awt::XPaintListener >& xListener ) throw (RuntimeException)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
413cdf0e10cSrcweir
414cdf0e10cSrcweir if( mpPaintListeners.get() )
415cdf0e10cSrcweir mpPaintListeners->addTypedListener( xListener );
416cdf0e10cSrcweir }
417cdf0e10cSrcweir
removePaintListener(const Reference<awt::XPaintListener> & xListener)418cdf0e10cSrcweir void SAL_CALL SlideShowView::removePaintListener( const Reference< awt::XPaintListener >& xListener ) throw (RuntimeException)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
421cdf0e10cSrcweir
422cdf0e10cSrcweir if( mpPaintListeners.get() )
423cdf0e10cSrcweir mpPaintListeners->removeTypedListener( xListener );
424cdf0e10cSrcweir }
425cdf0e10cSrcweir
addMouseListener(const Reference<awt::XMouseListener> & xListener)426cdf0e10cSrcweir void SAL_CALL SlideShowView::addMouseListener( const Reference< awt::XMouseListener >& xListener ) throw (RuntimeException)
427cdf0e10cSrcweir {
428cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
429cdf0e10cSrcweir
430cdf0e10cSrcweir if( mpMouseListeners.get() )
431cdf0e10cSrcweir mpMouseListeners->addTypedListener( xListener );
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
removeMouseListener(const Reference<awt::XMouseListener> & xListener)434cdf0e10cSrcweir void SAL_CALL SlideShowView::removeMouseListener( const Reference< awt::XMouseListener >& xListener ) throw (RuntimeException)
435cdf0e10cSrcweir {
436cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
437cdf0e10cSrcweir
438cdf0e10cSrcweir if( mpMouseListeners.get() )
439cdf0e10cSrcweir mpMouseListeners->removeTypedListener( xListener );
440cdf0e10cSrcweir }
441cdf0e10cSrcweir
addMouseMotionListener(const Reference<awt::XMouseMotionListener> & xListener)442cdf0e10cSrcweir void SAL_CALL SlideShowView::addMouseMotionListener( const Reference< awt::XMouseMotionListener >& xListener ) throw (RuntimeException)
443cdf0e10cSrcweir {
444cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
445cdf0e10cSrcweir
446cdf0e10cSrcweir if( !mbIsMouseMotionListener && mxWindow.is() )
447cdf0e10cSrcweir {
448cdf0e10cSrcweir // delay motion event registration, until we really
449cdf0e10cSrcweir // need it
450cdf0e10cSrcweir mbIsMouseMotionListener = true;
451cdf0e10cSrcweir mxWindow->addMouseMotionListener( this );
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir if( mpMouseMotionListeners.get() )
455cdf0e10cSrcweir mpMouseMotionListeners->addTypedListener( xListener );
456cdf0e10cSrcweir }
457cdf0e10cSrcweir
removeMouseMotionListener(const Reference<awt::XMouseMotionListener> & xListener)458cdf0e10cSrcweir void SAL_CALL SlideShowView::removeMouseMotionListener( const Reference< awt::XMouseMotionListener >& xListener ) throw (RuntimeException)
459cdf0e10cSrcweir {
460cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
461cdf0e10cSrcweir
462cdf0e10cSrcweir if( mpMouseMotionListeners.get() )
463cdf0e10cSrcweir mpMouseMotionListeners->removeTypedListener( xListener );
464cdf0e10cSrcweir
465cdf0e10cSrcweir // TODO(P1): Might be nice to deregister for mouse motion
466cdf0e10cSrcweir // events, when the last listener is gone.
467cdf0e10cSrcweir }
468cdf0e10cSrcweir
setMouseCursor(sal_Int16 nPointerShape)469cdf0e10cSrcweir void SAL_CALL SlideShowView::setMouseCursor( sal_Int16 nPointerShape ) throw (RuntimeException)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
472cdf0e10cSrcweir
473cdf0e10cSrcweir // forward to window
474cdf0e10cSrcweir if( mxPointer.is() )
475cdf0e10cSrcweir mxPointer->setType( nPointerShape );
476cdf0e10cSrcweir
477cdf0e10cSrcweir if( mxWindowPeer.is() )
478cdf0e10cSrcweir mxWindowPeer->setPointer( mxPointer );
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
getCanvasArea()481cdf0e10cSrcweir awt::Rectangle SAL_CALL SlideShowView::getCanvasArea( ) throw (RuntimeException)
482cdf0e10cSrcweir {
483cdf0e10cSrcweir awt::Rectangle aRectangle;
484cdf0e10cSrcweir
485cdf0e10cSrcweir if( mxWindow.is() )
486cdf0e10cSrcweir return mxWindow->getPosSize();
487cdf0e10cSrcweir
488cdf0e10cSrcweir aRectangle.X = aRectangle.Y = aRectangle.Width = aRectangle.Height = 0;
489cdf0e10cSrcweir
490cdf0e10cSrcweir return aRectangle;
491cdf0e10cSrcweir }
492cdf0e10cSrcweir
updateimpl(::osl::ClearableMutexGuard & rGuard,SlideshowImpl * pSlideShow)493cdf0e10cSrcweir void SlideShowView::updateimpl( ::osl::ClearableMutexGuard& rGuard, SlideshowImpl* pSlideShow )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir if( pSlideShow )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir ::rtl::Reference< SlideshowImpl > aSLGuard( pSlideShow );
498cdf0e10cSrcweir rGuard.clear();
499cdf0e10cSrcweir pSlideShow->startUpdateTimer();
500cdf0e10cSrcweir }
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir // XWindowListener methods
windowResized(const awt::WindowEvent & e)504cdf0e10cSrcweir void SAL_CALL SlideShowView::windowResized( const awt::WindowEvent& e ) throw (RuntimeException)
505cdf0e10cSrcweir {
506cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
507cdf0e10cSrcweir
508cdf0e10cSrcweir if( mpViewListeners.get() )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir // Change event source, to enable listeners to match event
511cdf0e10cSrcweir // with view
512cdf0e10cSrcweir awt::WindowEvent aEvent( e );
513cdf0e10cSrcweir aEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
514cdf0e10cSrcweir
515cdf0e10cSrcweir mpViewListeners->notify( aEvent );
516cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
517cdf0e10cSrcweir }
518cdf0e10cSrcweir }
519cdf0e10cSrcweir
windowMoved(const awt::WindowEvent &)520cdf0e10cSrcweir void SAL_CALL SlideShowView::windowMoved( const awt::WindowEvent& ) throw (RuntimeException)
521cdf0e10cSrcweir {
522cdf0e10cSrcweir // ignored
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
windowShown(const lang::EventObject &)525cdf0e10cSrcweir void SAL_CALL SlideShowView::windowShown( const lang::EventObject& ) throw (RuntimeException)
526cdf0e10cSrcweir {
527cdf0e10cSrcweir // ignored
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
windowHidden(const lang::EventObject &)530cdf0e10cSrcweir void SAL_CALL SlideShowView::windowHidden( const lang::EventObject& ) throw (RuntimeException)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir // ignored
533cdf0e10cSrcweir }
534cdf0e10cSrcweir
535cdf0e10cSrcweir // XMouseListener implementation
mousePressed(const awt::MouseEvent & e)536cdf0e10cSrcweir void SAL_CALL SlideShowView::mousePressed( const awt::MouseEvent& e ) throw (uno::RuntimeException)
537cdf0e10cSrcweir {
538cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
539cdf0e10cSrcweir if( mpSlideShow && mpSlideShow->isInputFreezed() )
540cdf0e10cSrcweir {
541cdf0e10cSrcweir mbMousePressedEaten = true;
542cdf0e10cSrcweir }
543cdf0e10cSrcweir else
544cdf0e10cSrcweir {
545cdf0e10cSrcweir mbMousePressedEaten = false;
546cdf0e10cSrcweir
547cdf0e10cSrcweir // Change event source, to enable listeners to match event
548cdf0e10cSrcweir // with view
549cdf0e10cSrcweir WrappedMouseEvent aEvent;
550cdf0e10cSrcweir aEvent.meType = WrappedMouseEvent::PRESSED;
551cdf0e10cSrcweir aEvent.maEvent = e;
552cdf0e10cSrcweir aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
553cdf0e10cSrcweir
554cdf0e10cSrcweir if( mpMouseListeners.get() )
555cdf0e10cSrcweir mpMouseListeners->notify( aEvent );
556cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
557cdf0e10cSrcweir }
558cdf0e10cSrcweir }
559cdf0e10cSrcweir
mouseReleased(const awt::MouseEvent & e)560cdf0e10cSrcweir void SAL_CALL SlideShowView::mouseReleased( const awt::MouseEvent& e ) throw (uno::RuntimeException)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
563cdf0e10cSrcweir if( mbMousePressedEaten )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir // if mouse button down was ignored, also ignore mouse button up
566cdf0e10cSrcweir mbMousePressedEaten = false;
567cdf0e10cSrcweir }
568cdf0e10cSrcweir else if( mpSlideShow && !mpSlideShow->isInputFreezed() )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir // Change event source, to enable listeners to match event
571cdf0e10cSrcweir // with view
572cdf0e10cSrcweir WrappedMouseEvent aEvent;
573cdf0e10cSrcweir aEvent.meType = WrappedMouseEvent::RELEASED;
574cdf0e10cSrcweir aEvent.maEvent = e;
575cdf0e10cSrcweir aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
576cdf0e10cSrcweir
577cdf0e10cSrcweir if( mpMouseListeners.get() )
578cdf0e10cSrcweir mpMouseListeners->notify( aEvent );
579cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
580cdf0e10cSrcweir }
581cdf0e10cSrcweir }
582cdf0e10cSrcweir
mouseEntered(const awt::MouseEvent & e)583cdf0e10cSrcweir void SAL_CALL SlideShowView::mouseEntered( const awt::MouseEvent& e ) throw (uno::RuntimeException)
584cdf0e10cSrcweir {
585cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
586cdf0e10cSrcweir
587cdf0e10cSrcweir // Change event source, to enable listeners to match event
588cdf0e10cSrcweir // with view
589cdf0e10cSrcweir WrappedMouseEvent aEvent;
590cdf0e10cSrcweir aEvent.meType = WrappedMouseEvent::ENTERED;
591cdf0e10cSrcweir aEvent.maEvent = e;
592cdf0e10cSrcweir aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
593cdf0e10cSrcweir
594cdf0e10cSrcweir if( mpMouseListeners.get() )
595cdf0e10cSrcweir mpMouseListeners->notify( aEvent );
596cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
597cdf0e10cSrcweir }
598cdf0e10cSrcweir
mouseExited(const awt::MouseEvent & e)599cdf0e10cSrcweir void SAL_CALL SlideShowView::mouseExited( const awt::MouseEvent& e ) throw (uno::RuntimeException)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
602cdf0e10cSrcweir
603cdf0e10cSrcweir // Change event source, to enable listeners to match event
604cdf0e10cSrcweir // with view
605cdf0e10cSrcweir WrappedMouseEvent aEvent;
606cdf0e10cSrcweir aEvent.meType = WrappedMouseEvent::EXITED;
607cdf0e10cSrcweir aEvent.maEvent = e;
608cdf0e10cSrcweir aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
609cdf0e10cSrcweir
610cdf0e10cSrcweir if( mpMouseListeners.get() )
611cdf0e10cSrcweir mpMouseListeners->notify( aEvent );
612cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
613cdf0e10cSrcweir }
614cdf0e10cSrcweir
615cdf0e10cSrcweir // XMouseMotionListener implementation
mouseDragged(const awt::MouseEvent & e)616cdf0e10cSrcweir void SAL_CALL SlideShowView::mouseDragged( const awt::MouseEvent& e ) throw (uno::RuntimeException)
617cdf0e10cSrcweir {
618cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
619cdf0e10cSrcweir
620cdf0e10cSrcweir // Change event source, to enable listeners to match event
621cdf0e10cSrcweir // with view
622cdf0e10cSrcweir WrappedMouseMotionEvent aEvent;
623cdf0e10cSrcweir aEvent.meType = WrappedMouseMotionEvent::DRAGGED;
624cdf0e10cSrcweir aEvent.maEvent = e;
625cdf0e10cSrcweir aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
626cdf0e10cSrcweir
627cdf0e10cSrcweir if( mpMouseMotionListeners.get() )
628cdf0e10cSrcweir mpMouseMotionListeners->notify( aEvent );
629cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
630cdf0e10cSrcweir }
631cdf0e10cSrcweir
mouseMoved(const awt::MouseEvent & e)632cdf0e10cSrcweir void SAL_CALL SlideShowView::mouseMoved( const awt::MouseEvent& e ) throw (uno::RuntimeException)
633cdf0e10cSrcweir {
634cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex );
635cdf0e10cSrcweir
636cdf0e10cSrcweir // Change event source, to enable listeners to match event
637cdf0e10cSrcweir // with view
638cdf0e10cSrcweir WrappedMouseMotionEvent aEvent;
639cdf0e10cSrcweir aEvent.meType = WrappedMouseMotionEvent::MOVED;
640cdf0e10cSrcweir aEvent.maEvent = e;
641cdf0e10cSrcweir aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
642cdf0e10cSrcweir
643cdf0e10cSrcweir if( mpMouseMotionListeners.get() )
644cdf0e10cSrcweir mpMouseMotionListeners->notify( aEvent );
645cdf0e10cSrcweir updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
646cdf0e10cSrcweir }
647cdf0e10cSrcweir
init()648cdf0e10cSrcweir void SlideShowView::init()
649cdf0e10cSrcweir {
650cdf0e10cSrcweir mxWindow->addWindowListener( this );
651cdf0e10cSrcweir mxWindow->addMouseListener( this );
652cdf0e10cSrcweir
653cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(),
654cdf0e10cSrcweir uno::UNO_QUERY_THROW );
655cdf0e10cSrcweir
656cdf0e10cSrcweir if( xFactory.is() )
657cdf0e10cSrcweir mxPointer.set( xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Pointer")) ),
658cdf0e10cSrcweir uno::UNO_QUERY );
659cdf0e10cSrcweir
660cdf0e10cSrcweir getTransformation();
661cdf0e10cSrcweir
662cdf0e10cSrcweir // #i48939# only switch on kind of hacky scroll optimisation, when
663cdf0e10cSrcweir // running fullscreen. this minimizes the probability that other
664cdf0e10cSrcweir // windows partially cover the show.
665cdf0e10cSrcweir if( mbFullScreen )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir try
668cdf0e10cSrcweir {
669cdf0e10cSrcweir Reference< beans::XPropertySet > xCanvasProps( getCanvas(),
670cdf0e10cSrcweir uno::UNO_QUERY_THROW );
671cdf0e10cSrcweir xCanvasProps->setPropertyValue(
672cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UnsafeScrolling")),
673cdf0e10cSrcweir uno::makeAny( true ) );
674cdf0e10cSrcweir }
675cdf0e10cSrcweir catch( uno::Exception& )
676cdf0e10cSrcweir {
677cdf0e10cSrcweir }
678cdf0e10cSrcweir }
679cdf0e10cSrcweir }
680cdf0e10cSrcweir
681cdf0e10cSrcweir } // namespace ::sd
682