1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <canvas/debug.hxx>
32*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
33*cdf0e10cSrcweir #include <canvas/canvastools.hxx>
34*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx>
35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
36*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
37*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
38*cdf0e10cSrcweir #include <cppcanvas/basegfxfactory.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "slidechangebase.hxx"
41*cdf0e10cSrcweir #include "tools.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <boost/bind.hpp>
44*cdf0e10cSrcweir #include <algorithm>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace com::sun::star;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir namespace slideshow {
49*cdf0e10cSrcweir namespace internal {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir SlideChangeBase::SlideChangeBase( boost::optional<SlideSharedPtr> const & leavingSlide,
52*cdf0e10cSrcweir                                   const SlideSharedPtr&                   pEnteringSlide,
53*cdf0e10cSrcweir                                   const SoundPlayerSharedPtr&             pSoundPlayer,
54*cdf0e10cSrcweir                                   const UnoViewContainer&                 rViewContainer,
55*cdf0e10cSrcweir                                   ScreenUpdater&                          rScreenUpdater,
56*cdf0e10cSrcweir                                   EventMultiplexer&                       rEventMultiplexer,
57*cdf0e10cSrcweir                                   bool                                    bCreateLeavingSprites,
58*cdf0e10cSrcweir                                   bool                                    bCreateEnteringSprites ) :
59*cdf0e10cSrcweir       mpSoundPlayer( pSoundPlayer ),
60*cdf0e10cSrcweir       mrEventMultiplexer(rEventMultiplexer),
61*cdf0e10cSrcweir       mrScreenUpdater(rScreenUpdater),
62*cdf0e10cSrcweir       maLeavingSlide( leavingSlide ),
63*cdf0e10cSrcweir       mpEnteringSlide( pEnteringSlide ),
64*cdf0e10cSrcweir       maViewData(),
65*cdf0e10cSrcweir       mrViewContainer(rViewContainer),
66*cdf0e10cSrcweir       mbCreateLeavingSprites(bCreateLeavingSprites),
67*cdf0e10cSrcweir       mbCreateEnteringSprites(bCreateEnteringSprites),
68*cdf0e10cSrcweir       mbSpritesVisible(false),
69*cdf0e10cSrcweir       mbFinished(false),
70*cdf0e10cSrcweir       mbPrefetched(false)
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     ENSURE_OR_THROW(
73*cdf0e10cSrcweir         pEnteringSlide,
74*cdf0e10cSrcweir         "SlideChangeBase::SlideChangeBase(): Invalid entering slide!" );
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir SlideBitmapSharedPtr SlideChangeBase::getLeavingBitmap( const ViewEntry& rViewEntry ) const
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     if( !rViewEntry.mpLeavingBitmap )
80*cdf0e10cSrcweir         rViewEntry.mpLeavingBitmap = createBitmap(rViewEntry.mpView,
81*cdf0e10cSrcweir                                                   maLeavingSlide);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     return rViewEntry.mpLeavingBitmap;
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir SlideBitmapSharedPtr SlideChangeBase::getEnteringBitmap( const ViewEntry& rViewEntry ) const
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     if( !rViewEntry.mpEnteringBitmap )
89*cdf0e10cSrcweir         rViewEntry.mpEnteringBitmap = createBitmap( rViewEntry.mpView,
90*cdf0e10cSrcweir                                                     boost::optional<SlideSharedPtr>(mpEnteringSlide) );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     return rViewEntry.mpEnteringBitmap;
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir SlideBitmapSharedPtr SlideChangeBase::createBitmap( const UnoViewSharedPtr&                rView,
96*cdf0e10cSrcweir                                                     const boost::optional<SlideSharedPtr>& rSlide ) const
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     SlideBitmapSharedPtr pRet;
99*cdf0e10cSrcweir     if( !rSlide )
100*cdf0e10cSrcweir         return pRet;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     SlideSharedPtr const & pSlide = *rSlide;
103*cdf0e10cSrcweir     if( !pSlide )
104*cdf0e10cSrcweir     {
105*cdf0e10cSrcweir         // TODO(P3): No need to generate a bitmap here. This only made
106*cdf0e10cSrcweir         // the code more uniform. Faster would be to simply clear the
107*cdf0e10cSrcweir         // sprite to black.
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         // create empty, black-filled bitmap
110*cdf0e10cSrcweir         const basegfx::B2ISize slideSizePixel(
111*cdf0e10cSrcweir             getSlideSizePixel( mpEnteringSlide->getSlideSize(),
112*cdf0e10cSrcweir                                rView ));
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         cppcanvas::CanvasSharedPtr pCanvas( rView->getCanvas() );
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir         // create a bitmap of appropriate size
117*cdf0e10cSrcweir         cppcanvas::BitmapSharedPtr pBitmap(
118*cdf0e10cSrcweir             cppcanvas::BaseGfxFactory::getInstance().createBitmap(
119*cdf0e10cSrcweir                 pCanvas,
120*cdf0e10cSrcweir                 slideSizePixel ) );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir         ENSURE_OR_THROW(
123*cdf0e10cSrcweir             pBitmap,
124*cdf0e10cSrcweir             "SlideChangeBase::createBitmap(): Cannot create page bitmap" );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir         cppcanvas::BitmapCanvasSharedPtr pBitmapCanvas(
127*cdf0e10cSrcweir             pBitmap->getBitmapCanvas() );
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         ENSURE_OR_THROW( pBitmapCanvas,
130*cdf0e10cSrcweir                           "SlideChangeBase::createBitmap(): "
131*cdf0e10cSrcweir                           "Cannot create page bitmap canvas" );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         // set transformation to identitiy (->device pixel)
134*cdf0e10cSrcweir         pBitmapCanvas->setTransformation( ::basegfx::B2DHomMatrix() );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         // clear bitmap to black
137*cdf0e10cSrcweir         fillRect( pBitmapCanvas,
138*cdf0e10cSrcweir                   ::basegfx::B2DRectangle( 0.0, 0.0,
139*cdf0e10cSrcweir                                            slideSizePixel.getX(),
140*cdf0e10cSrcweir                                            slideSizePixel.getY() ),
141*cdf0e10cSrcweir                   0x000000FFU );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir         pRet.reset( new SlideBitmap( pBitmap ));
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir     else
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir         pRet = pSlide->getCurrentSlideBitmap( rView );
148*cdf0e10cSrcweir     }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     return pRet;
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir ::basegfx::B2ISize SlideChangeBase::getEnteringSlideSizePixel( const UnoViewSharedPtr& pView ) const
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     return getSlideSizePixel( mpEnteringSlide->getSlideSize(),
156*cdf0e10cSrcweir                               pView );
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir ::basegfx::B2ISize SlideChangeBase::getLeavingSlideSizePixel( const UnoViewSharedPtr& pView ) const
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     return getSlideSizePixel( (*maLeavingSlide)->getSlideSize(),
162*cdf0e10cSrcweir                               pView );
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir void SlideChangeBase::renderBitmap(
167*cdf0e10cSrcweir     SlideBitmapSharedPtr const & pSlideBitmap,
168*cdf0e10cSrcweir     cppcanvas::CanvasSharedPtr const & pCanvas )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     if( pSlideBitmap && pCanvas )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         // need to render without any transformation (we
173*cdf0e10cSrcweir         // assume device units):
174*cdf0e10cSrcweir         const basegfx::B2DHomMatrix viewTransform(
175*cdf0e10cSrcweir             pCanvas->getTransformation() );
176*cdf0e10cSrcweir         const basegfx::B2DPoint pageOrigin(
177*cdf0e10cSrcweir             viewTransform * basegfx::B2DPoint() );
178*cdf0e10cSrcweir         const cppcanvas::CanvasSharedPtr pDevicePixelCanvas(
179*cdf0e10cSrcweir             pCanvas->clone() );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         // render at output position, don't modify bitmap object (no move!):
182*cdf0e10cSrcweir         const basegfx::B2DHomMatrix transform(basegfx::tools::createTranslateB2DHomMatrix(
183*cdf0e10cSrcweir             pageOrigin.getX(), pageOrigin.getY()));
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         pDevicePixelCanvas->setTransformation( transform );
186*cdf0e10cSrcweir         pSlideBitmap->draw( pDevicePixelCanvas );
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir void SlideChangeBase::prefetch( const AnimatableShapeSharedPtr&,
191*cdf0e10cSrcweir                                 const ShapeAttributeLayerSharedPtr& )
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
194*cdf0e10cSrcweir     if( mbFinished || mbPrefetched )
195*cdf0e10cSrcweir         return;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     // register ourselves for view change events
198*cdf0e10cSrcweir     mrEventMultiplexer.addViewHandler( shared_from_this() );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     // init views and create slide bitmaps
201*cdf0e10cSrcweir     std::for_each( mrViewContainer.begin(),
202*cdf0e10cSrcweir                    mrViewContainer.end(),
203*cdf0e10cSrcweir                    boost::bind( &SlideChangeBase::viewAdded,
204*cdf0e10cSrcweir                                 this,
205*cdf0e10cSrcweir                                 _1 ));
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     mbPrefetched = true;
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir void SlideChangeBase::start( const AnimatableShapeSharedPtr&     rShape,
211*cdf0e10cSrcweir                              const ShapeAttributeLayerSharedPtr& rLayer )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
214*cdf0e10cSrcweir     if( mbFinished )
215*cdf0e10cSrcweir         return;
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir     prefetch(rShape,rLayer); // no-op, if already done
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     // start accompanying sound effect, if any
220*cdf0e10cSrcweir     if( mpSoundPlayer )
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         mpSoundPlayer->startPlayback();
223*cdf0e10cSrcweir         // xxx todo: for now, presentation.cxx takes care about the slide
224*cdf0e10cSrcweir         // #i50492#  transition sound object, so just release it here
225*cdf0e10cSrcweir         mpSoundPlayer.reset();
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir void SlideChangeBase::end()
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
232*cdf0e10cSrcweir     if( mbFinished )
233*cdf0e10cSrcweir         return;
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     try
236*cdf0e10cSrcweir     {
237*cdf0e10cSrcweir         // draw fully entered bitmap:
238*cdf0e10cSrcweir         ViewsVecT::const_iterator aCurr( beginViews() );
239*cdf0e10cSrcweir         const ViewsVecT::const_iterator aEnd( endViews() );
240*cdf0e10cSrcweir         while( aCurr != aEnd )
241*cdf0e10cSrcweir         {
242*cdf0e10cSrcweir             // fully clear view content to background color
243*cdf0e10cSrcweir             aCurr->mpView->clearAll();
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir             const SlideBitmapSharedPtr pSlideBitmap( getEnteringBitmap( *aCurr ));
246*cdf0e10cSrcweir             pSlideBitmap->clip( basegfx::B2DPolyPolygon() /* no clipping */ );
247*cdf0e10cSrcweir             renderBitmap( pSlideBitmap,
248*cdf0e10cSrcweir                           aCurr->mpView->getCanvas() );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir             ++aCurr;
251*cdf0e10cSrcweir         }
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir     catch( uno::Exception& )
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         // make sure releasing below happens
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     // swap changes to screen
259*cdf0e10cSrcweir     mrScreenUpdater.notifyUpdate();
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir     // make object dysfunctional
262*cdf0e10cSrcweir     mbFinished = true;
263*cdf0e10cSrcweir     ViewsVecT().swap(maViewData);
264*cdf0e10cSrcweir     maLeavingSlide.reset();
265*cdf0e10cSrcweir     mpEnteringSlide.reset();
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     // sprites have been binned above
268*cdf0e10cSrcweir     mbSpritesVisible = false;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     // remove also from event multiplexer, we're dead anyway
271*cdf0e10cSrcweir     mrEventMultiplexer.removeViewHandler( shared_from_this() );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir bool SlideChangeBase::operator()( double nValue )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     if( mbFinished )
277*cdf0e10cSrcweir         return false;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     const std::size_t nEntries( maViewData.size() );
280*cdf0e10cSrcweir     bool bSpritesVisible( mbSpritesVisible );
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     for( ::std::size_t i=0; i<nEntries; ++i )
283*cdf0e10cSrcweir     {
284*cdf0e10cSrcweir         // calc sprite offsets. The enter/leaving bitmaps are only
285*cdf0e10cSrcweir         // as large as the actual slides. For scaled-down
286*cdf0e10cSrcweir         // presentations, we have to move the left, top edge of
287*cdf0e10cSrcweir         // those bitmaps to the actual position, governed by the
288*cdf0e10cSrcweir         // given view transform. The aSpritePosPixel local
289*cdf0e10cSrcweir         // variable is already in device coordinate space
290*cdf0e10cSrcweir         // (i.e. pixel).
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir         ViewEntry& rViewEntry( maViewData[i] );
293*cdf0e10cSrcweir         const ::cppcanvas::CanvasSharedPtr& rCanvas( rViewEntry.mpView->getCanvas() );
294*cdf0e10cSrcweir         ::cppcanvas::CustomSpriteSharedPtr& rInSprite( rViewEntry.mpInSprite );
295*cdf0e10cSrcweir         ::cppcanvas::CustomSpriteSharedPtr& rOutSprite( rViewEntry.mpOutSprite );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         // TODO(F2): Properly respect clip here.
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir         // Might have to be transformed, too.
300*cdf0e10cSrcweir         const ::basegfx::B2DHomMatrix aViewTransform(
301*cdf0e10cSrcweir             rViewEntry.mpView->getTransformation() );
302*cdf0e10cSrcweir         const ::basegfx::B2DPoint aSpritePosPixel(
303*cdf0e10cSrcweir             aViewTransform * ::basegfx::B2DPoint() );
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir         // move sprite to final output position, in
306*cdf0e10cSrcweir         // device coordinates
307*cdf0e10cSrcweir         if( rOutSprite )
308*cdf0e10cSrcweir             rOutSprite->movePixel( aSpritePosPixel );
309*cdf0e10cSrcweir         if( rInSprite )
310*cdf0e10cSrcweir             rInSprite->movePixel( aSpritePosPixel );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir         if( !mbSpritesVisible )
313*cdf0e10cSrcweir         {
314*cdf0e10cSrcweir             if( rOutSprite )
315*cdf0e10cSrcweir             {
316*cdf0e10cSrcweir                 // only render once: clipping is done
317*cdf0e10cSrcweir                 // exclusively with the sprite
318*cdf0e10cSrcweir                 const ::cppcanvas::CanvasSharedPtr pOutContentCanvas(
319*cdf0e10cSrcweir                     rOutSprite->getContentCanvas() );
320*cdf0e10cSrcweir                 if( pOutContentCanvas)
321*cdf0e10cSrcweir                 {
322*cdf0e10cSrcweir                     // TODO(Q2): Use basegfx bitmaps here
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir                     // TODO(F1): SlideBitmap is not fully portable
325*cdf0e10cSrcweir                     // between different canvases!
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir                     // render the content
328*cdf0e10cSrcweir                     OSL_ASSERT( getLeavingBitmap( rViewEntry ) );
329*cdf0e10cSrcweir                     if( getLeavingBitmap( rViewEntry ) )
330*cdf0e10cSrcweir                         getLeavingBitmap( rViewEntry )->draw( pOutContentCanvas );
331*cdf0e10cSrcweir                 }
332*cdf0e10cSrcweir             }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir             if( rInSprite )
335*cdf0e10cSrcweir             {
336*cdf0e10cSrcweir                 // only render once: clipping is done
337*cdf0e10cSrcweir                 // exclusively with the sprite
338*cdf0e10cSrcweir                 const ::cppcanvas::CanvasSharedPtr pInContentCanvas(
339*cdf0e10cSrcweir                     rInSprite->getContentCanvas() );
340*cdf0e10cSrcweir                 if( pInContentCanvas )
341*cdf0e10cSrcweir                 {
342*cdf0e10cSrcweir                     // TODO(Q2): Use basegfx bitmaps here
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir                     // TODO(F1): SlideBitmap is not fully portable
345*cdf0e10cSrcweir                     // between different canvases!
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir                     // render the content
348*cdf0e10cSrcweir                     getEnteringBitmap( rViewEntry )->draw( pInContentCanvas );
349*cdf0e10cSrcweir                 }
350*cdf0e10cSrcweir             }
351*cdf0e10cSrcweir         }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir         if( rOutSprite )
354*cdf0e10cSrcweir             performOut( rOutSprite, rViewEntry, rCanvas, nValue );
355*cdf0e10cSrcweir         if( rInSprite )
356*cdf0e10cSrcweir             performIn( rInSprite, rViewEntry, rCanvas, nValue );
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir         // finishing deeds for first run.
359*cdf0e10cSrcweir         if( !mbSpritesVisible)
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir             // enable sprites:
362*cdf0e10cSrcweir             if( rOutSprite )
363*cdf0e10cSrcweir                 rOutSprite->show();
364*cdf0e10cSrcweir             if( rInSprite )
365*cdf0e10cSrcweir                 rInSprite->show();
366*cdf0e10cSrcweir             bSpritesVisible = true;
367*cdf0e10cSrcweir         }
368*cdf0e10cSrcweir     } // for_each( sprite )
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     mbSpritesVisible = bSpritesVisible;
371*cdf0e10cSrcweir     mrScreenUpdater.notifyUpdate();
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     return true;
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir void SlideChangeBase::performIn(
377*cdf0e10cSrcweir     const cppcanvas::CustomSpriteSharedPtr&   /*rSprite*/,
378*cdf0e10cSrcweir     const ViewEntry&                          /*rViewEntry*/,
379*cdf0e10cSrcweir     const cppcanvas::CanvasSharedPtr&         /*rDestinationCanvas*/,
380*cdf0e10cSrcweir     double                                    /*t*/ )
381*cdf0e10cSrcweir {
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir void SlideChangeBase::performOut(
385*cdf0e10cSrcweir     const cppcanvas::CustomSpriteSharedPtr&  /*rSprite*/,
386*cdf0e10cSrcweir     const ViewEntry&                         /*rViewEntry*/,
387*cdf0e10cSrcweir     const cppcanvas::CanvasSharedPtr&        /*rDestinationCanvas*/,
388*cdf0e10cSrcweir     double                                   /*t*/ )
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir double SlideChangeBase::getUnderlyingValue() const
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir     return 0.0;     // though this should be used in concert with
395*cdf0e10cSrcweir 				    // ActivitiesFactory::createSimpleActivity, better
396*cdf0e10cSrcweir 			    	// explicitely name our start value.
397*cdf0e10cSrcweir 				    // Permissible range for operator() above is [0,1]
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir void SlideChangeBase::viewAdded( const UnoViewSharedPtr& rView )
401*cdf0e10cSrcweir {
402*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
403*cdf0e10cSrcweir     if( mbFinished )
404*cdf0e10cSrcweir         return;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     maViewData.push_back( ViewEntry(rView) );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     ViewEntry& rEntry( maViewData.back() );
409*cdf0e10cSrcweir     getEnteringBitmap( rEntry );
410*cdf0e10cSrcweir     getLeavingBitmap( rEntry );
411*cdf0e10cSrcweir     addSprites( rEntry );
412*cdf0e10cSrcweir }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir void SlideChangeBase::viewRemoved( const UnoViewSharedPtr& rView )
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
417*cdf0e10cSrcweir     if( mbFinished )
418*cdf0e10cSrcweir         return;
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     // erase corresponding entry from maViewData
421*cdf0e10cSrcweir     maViewData.erase(
422*cdf0e10cSrcweir         std::remove_if(
423*cdf0e10cSrcweir             maViewData.begin(),
424*cdf0e10cSrcweir             maViewData.end(),
425*cdf0e10cSrcweir             boost::bind(
426*cdf0e10cSrcweir                 std::equal_to<UnoViewSharedPtr>(),
427*cdf0e10cSrcweir                 rView,
428*cdf0e10cSrcweir                 // select view:
429*cdf0e10cSrcweir                 boost::bind( &ViewEntry::getView, _1 ))),
430*cdf0e10cSrcweir         maViewData.end() );
431*cdf0e10cSrcweir }
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir void SlideChangeBase::viewChanged( const UnoViewSharedPtr& rView )
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
436*cdf0e10cSrcweir     if( mbFinished )
437*cdf0e10cSrcweir         return;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     // find entry corresponding to modified view
440*cdf0e10cSrcweir     ViewsVecT::iterator aModifiedEntry(
441*cdf0e10cSrcweir         std::find_if(
442*cdf0e10cSrcweir             maViewData.begin(),
443*cdf0e10cSrcweir             maViewData.end(),
444*cdf0e10cSrcweir             boost::bind(
445*cdf0e10cSrcweir                 std::equal_to<UnoViewSharedPtr>(),
446*cdf0e10cSrcweir                 rView,
447*cdf0e10cSrcweir                 // select view:
448*cdf0e10cSrcweir                 boost::bind( &ViewEntry::getView, _1 ) )));
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir     OSL_ASSERT( aModifiedEntry != maViewData.end() );
451*cdf0e10cSrcweir     if( aModifiedEntry == maViewData.end() )
452*cdf0e10cSrcweir         return;
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir     // clear stale info (both bitmaps and sprites prolly need a
455*cdf0e10cSrcweir     // resize)
456*cdf0e10cSrcweir     clearViewEntry( *aModifiedEntry );
457*cdf0e10cSrcweir     addSprites( *aModifiedEntry );
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir void SlideChangeBase::viewsChanged()
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     // we're a one-shot activity, and already finished
463*cdf0e10cSrcweir     if( mbFinished )
464*cdf0e10cSrcweir         return;
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir     ViewsVecT::iterator       aIter( maViewData.begin() );
467*cdf0e10cSrcweir     ViewsVecT::iterator const aEnd ( maViewData.end() );
468*cdf0e10cSrcweir     while( aIter != aEnd )
469*cdf0e10cSrcweir     {
470*cdf0e10cSrcweir         // clear stale info (both bitmaps and sprites prolly need a
471*cdf0e10cSrcweir         // resize)
472*cdf0e10cSrcweir         clearViewEntry( *aIter );
473*cdf0e10cSrcweir         addSprites( *aIter );
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir         ++aIter;
476*cdf0e10cSrcweir     }
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir cppcanvas::CustomSpriteSharedPtr SlideChangeBase::createSprite(
480*cdf0e10cSrcweir     UnoViewSharedPtr const & pView,
481*cdf0e10cSrcweir     basegfx::B2DSize const & rSpriteSize,
482*cdf0e10cSrcweir     double                   nPrio ) const
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir     // TODO(P2): change to bitmapsprite once that's working
485*cdf0e10cSrcweir     const cppcanvas::CustomSpriteSharedPtr pSprite(
486*cdf0e10cSrcweir         pView->createSprite( rSpriteSize,
487*cdf0e10cSrcweir                              nPrio ));
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     // alpha default is 0.0, which seems to be
490*cdf0e10cSrcweir     // a bad idea when viewing content...
491*cdf0e10cSrcweir     pSprite->setAlpha( 1.0 );
492*cdf0e10cSrcweir     if (mbSpritesVisible)
493*cdf0e10cSrcweir         pSprite->show();
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir     return pSprite;
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir void SlideChangeBase::addSprites( ViewEntry& rEntry )
499*cdf0e10cSrcweir {
500*cdf0e10cSrcweir     if( mbCreateLeavingSprites && maLeavingSlide )
501*cdf0e10cSrcweir     {
502*cdf0e10cSrcweir         // create leaving sprite:
503*cdf0e10cSrcweir         const basegfx::B2ISize leavingSlideSizePixel(
504*cdf0e10cSrcweir             getLeavingBitmap( rEntry )->getSize() );
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir         rEntry.mpOutSprite = createSprite( rEntry.mpView,
507*cdf0e10cSrcweir                                            leavingSlideSizePixel,
508*cdf0e10cSrcweir                                            100 );
509*cdf0e10cSrcweir     }
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir     if( mbCreateEnteringSprites )
512*cdf0e10cSrcweir     {
513*cdf0e10cSrcweir         // create entering sprite:
514*cdf0e10cSrcweir         const basegfx::B2ISize enteringSlideSizePixel(
515*cdf0e10cSrcweir             getSlideSizePixel( mpEnteringSlide->getSlideSize(),
516*cdf0e10cSrcweir                                rEntry.mpView ));
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir         rEntry.mpInSprite = createSprite( rEntry.mpView,
519*cdf0e10cSrcweir                                           enteringSlideSizePixel,
520*cdf0e10cSrcweir                                           101 );
521*cdf0e10cSrcweir     }
522*cdf0e10cSrcweir }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir void SlideChangeBase::clearViewEntry( ViewEntry& rEntry )
525*cdf0e10cSrcweir {
526*cdf0e10cSrcweir     // clear stale info (both bitmaps and sprites prolly need a
527*cdf0e10cSrcweir     // resize)
528*cdf0e10cSrcweir     rEntry.mpEnteringBitmap.reset();
529*cdf0e10cSrcweir     rEntry.mpLeavingBitmap.reset();
530*cdf0e10cSrcweir     rEntry.mpInSprite.reset();
531*cdf0e10cSrcweir     rEntry.mpOutSprite.reset();
532*cdf0e10cSrcweir }
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir } // namespace internal
535*cdf0e10cSrcweir } // namespace presentation
536