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 <boost/current_function.hpp>
32*cdf0e10cSrcweir #include <canvas/canvastools.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
35*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
38*cdf0e10cSrcweir #include <basegfx/vector/b2dvector.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include "waitsymbol.hxx"
43*cdf0e10cSrcweir #include "eventmultiplexer.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <algorithm>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace com::sun::star;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace slideshow {
51*cdf0e10cSrcweir namespace internal {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir const sal_Int32 LEFT_BORDER_SPACE  = 10;
54*cdf0e10cSrcweir const sal_Int32 LOWER_BORDER_SPACE = 10;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir WaitSymbolSharedPtr WaitSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
57*cdf0e10cSrcweir                                         ScreenUpdater&                            rScreenUpdater,
58*cdf0e10cSrcweir                                         EventMultiplexer&                         rEventMultiplexer,
59*cdf0e10cSrcweir                                         const UnoViewContainer&                   rViewContainer )
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     WaitSymbolSharedPtr pRet(
62*cdf0e10cSrcweir         new WaitSymbol( xBitmap,
63*cdf0e10cSrcweir                         rScreenUpdater,
64*cdf0e10cSrcweir                         rViewContainer ));
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     rEventMultiplexer.addViewHandler( pRet );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     return pRet;
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir WaitSymbol::WaitSymbol( uno::Reference<rendering::XBitmap> const &   xBitmap,
72*cdf0e10cSrcweir                         ScreenUpdater&                               rScreenUpdater,
73*cdf0e10cSrcweir                         const UnoViewContainer&                      rViewContainer ) :
74*cdf0e10cSrcweir     mxBitmap(xBitmap),
75*cdf0e10cSrcweir     maViews(),
76*cdf0e10cSrcweir     mrScreenUpdater( rScreenUpdater ),
77*cdf0e10cSrcweir     mbVisible(false)
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     std::for_each( rViewContainer.begin(),
80*cdf0e10cSrcweir                    rViewContainer.end(),
81*cdf0e10cSrcweir                    boost::bind( &WaitSymbol::viewAdded,
82*cdf0e10cSrcweir                                 this,
83*cdf0e10cSrcweir                                 _1 ));
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir void WaitSymbol::setVisible( const bool bVisible )
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     if( mbVisible != bVisible )
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         mbVisible = bVisible;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         ViewsVecT::const_iterator       aIter( maViews.begin() );
93*cdf0e10cSrcweir         ViewsVecT::const_iterator const aEnd ( maViews.end() );
94*cdf0e10cSrcweir         while( aIter != aEnd )
95*cdf0e10cSrcweir         {
96*cdf0e10cSrcweir             if( aIter->second )
97*cdf0e10cSrcweir             {
98*cdf0e10cSrcweir                 if( bVisible )
99*cdf0e10cSrcweir                     aIter->second->show();
100*cdf0e10cSrcweir                 else
101*cdf0e10cSrcweir                     aIter->second->hide();
102*cdf0e10cSrcweir             }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             ++aIter;
105*cdf0e10cSrcweir         }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         // sprites changed, need a screen update for this frame.
108*cdf0e10cSrcweir         mrScreenUpdater.requestImmediateUpdate();
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir basegfx::B2DPoint WaitSymbol::calcSpritePos(
113*cdf0e10cSrcweir     UnoViewSharedPtr const & rView ) const
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     const uno::Reference<rendering::XBitmap> xBitmap( rView->getCanvas()->getUNOCanvas(),
116*cdf0e10cSrcweir                                                       uno::UNO_QUERY_THROW );
117*cdf0e10cSrcweir     const geometry::IntegerSize2D realSize( xBitmap->getSize() );
118*cdf0e10cSrcweir     return basegfx::B2DPoint(
119*cdf0e10cSrcweir         std::min<sal_Int32>( realSize.Width, LEFT_BORDER_SPACE ),
120*cdf0e10cSrcweir         std::max<sal_Int32>( 0, realSize.Height - mxBitmap->getSize().Height
121*cdf0e10cSrcweir                                                 - LOWER_BORDER_SPACE ) );
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir void WaitSymbol::viewAdded( const UnoViewSharedPtr& rView )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     cppcanvas::CustomSpriteSharedPtr sprite;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     try
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir         const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
131*cdf0e10cSrcweir         sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width,
132*cdf0e10cSrcweir                                                           spriteSize.Height ),
133*cdf0e10cSrcweir                                       1000.0 ); // sprite should be in front of all
134*cdf0e10cSrcweir                                                 // other sprites
135*cdf0e10cSrcweir         rendering::ViewState viewState;
136*cdf0e10cSrcweir         canvas::tools::initViewState( viewState );
137*cdf0e10cSrcweir         rendering::RenderState renderState;
138*cdf0e10cSrcweir         canvas::tools::initRenderState( renderState );
139*cdf0e10cSrcweir         sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
140*cdf0e10cSrcweir             mxBitmap, viewState, renderState );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         sprite->setAlpha( 0.9 );
143*cdf0e10cSrcweir         sprite->movePixel( calcSpritePos( rView ) );
144*cdf0e10cSrcweir         if( mbVisible )
145*cdf0e10cSrcweir             sprite->show();
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir     catch( uno::Exception& )
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir         OSL_ENSURE( false,
150*cdf0e10cSrcweir                     rtl::OUStringToOString(
151*cdf0e10cSrcweir                         comphelper::anyToString( cppu::getCaughtException() ),
152*cdf0e10cSrcweir                         RTL_TEXTENCODING_UTF8 ).getStr() );
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     maViews.push_back( ViewsVecT::value_type( rView, sprite ) );
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir void WaitSymbol::viewRemoved( const UnoViewSharedPtr& rView )
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     maViews.erase(
161*cdf0e10cSrcweir         std::remove_if(
162*cdf0e10cSrcweir             maViews.begin(), maViews.end(),
163*cdf0e10cSrcweir             boost::bind(
164*cdf0e10cSrcweir                 std::equal_to<UnoViewSharedPtr>(),
165*cdf0e10cSrcweir                 rView,
166*cdf0e10cSrcweir                 // select view:
167*cdf0e10cSrcweir                 boost::bind( std::select1st<ViewsVecT::value_type>(), _1 ) ) ),
168*cdf0e10cSrcweir         maViews.end() );
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView )
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     // find entry corresponding to modified view
174*cdf0e10cSrcweir     ViewsVecT::iterator aModifiedEntry(
175*cdf0e10cSrcweir         std::find_if(
176*cdf0e10cSrcweir             maViews.begin(),
177*cdf0e10cSrcweir             maViews.end(),
178*cdf0e10cSrcweir             boost::bind(
179*cdf0e10cSrcweir                 std::equal_to<UnoViewSharedPtr>(),
180*cdf0e10cSrcweir                 rView,
181*cdf0e10cSrcweir                 // select view:
182*cdf0e10cSrcweir                 boost::bind( std::select1st<ViewsVecT::value_type>(), _1 ))));
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     OSL_ASSERT( aModifiedEntry != maViews.end() );
185*cdf0e10cSrcweir     if( aModifiedEntry == maViews.end() )
186*cdf0e10cSrcweir         return;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     if( aModifiedEntry->second )
189*cdf0e10cSrcweir         aModifiedEntry->second->movePixel(
190*cdf0e10cSrcweir             calcSpritePos(aModifiedEntry->first) );
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir void WaitSymbol::viewsChanged()
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     // reposition sprites on all views
196*cdf0e10cSrcweir     ViewsVecT::const_iterator       aIter( maViews.begin() );
197*cdf0e10cSrcweir     ViewsVecT::const_iterator const aEnd ( maViews.end() );
198*cdf0e10cSrcweir     while( aIter != aEnd )
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir         if( aIter->second )
201*cdf0e10cSrcweir             aIter->second->movePixel(
202*cdf0e10cSrcweir                 calcSpritePos( aIter->first ));
203*cdf0e10cSrcweir         ++aIter;
204*cdf0e10cSrcweir     }
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir } // namespace internal
208*cdf0e10cSrcweir } // namespace presentation
209