1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*70f497fbSAndrew Rist * distributed with this work for additional information
6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at
10*70f497fbSAndrew Rist *
11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist *
13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the
17*70f497fbSAndrew Rist * specific language governing permissions and limitations
18*70f497fbSAndrew Rist * under the License.
19*70f497fbSAndrew Rist *
20*70f497fbSAndrew Rist *************************************************************/
21*70f497fbSAndrew Rist
22*70f497fbSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <boost/current_function.hpp>
28cdf0e10cSrcweir #include <canvas/canvastools.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
31cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
34cdf0e10cSrcweir #include <basegfx/vector/b2dvector.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "waitsymbol.hxx"
39cdf0e10cSrcweir #include "eventmultiplexer.hxx"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <algorithm>
42cdf0e10cSrcweir
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace com::sun::star;
45cdf0e10cSrcweir
46cdf0e10cSrcweir namespace slideshow {
47cdf0e10cSrcweir namespace internal {
48cdf0e10cSrcweir
49cdf0e10cSrcweir const sal_Int32 LEFT_BORDER_SPACE = 10;
50cdf0e10cSrcweir const sal_Int32 LOWER_BORDER_SPACE = 10;
51cdf0e10cSrcweir
create(const uno::Reference<rendering::XBitmap> & xBitmap,ScreenUpdater & rScreenUpdater,EventMultiplexer & rEventMultiplexer,const UnoViewContainer & rViewContainer)52cdf0e10cSrcweir WaitSymbolSharedPtr WaitSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
53cdf0e10cSrcweir ScreenUpdater& rScreenUpdater,
54cdf0e10cSrcweir EventMultiplexer& rEventMultiplexer,
55cdf0e10cSrcweir const UnoViewContainer& rViewContainer )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir WaitSymbolSharedPtr pRet(
58cdf0e10cSrcweir new WaitSymbol( xBitmap,
59cdf0e10cSrcweir rScreenUpdater,
60cdf0e10cSrcweir rViewContainer ));
61cdf0e10cSrcweir
62cdf0e10cSrcweir rEventMultiplexer.addViewHandler( pRet );
63cdf0e10cSrcweir
64cdf0e10cSrcweir return pRet;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
WaitSymbol(uno::Reference<rendering::XBitmap> const & xBitmap,ScreenUpdater & rScreenUpdater,const UnoViewContainer & rViewContainer)67cdf0e10cSrcweir WaitSymbol::WaitSymbol( uno::Reference<rendering::XBitmap> const & xBitmap,
68cdf0e10cSrcweir ScreenUpdater& rScreenUpdater,
69cdf0e10cSrcweir const UnoViewContainer& rViewContainer ) :
70cdf0e10cSrcweir mxBitmap(xBitmap),
71cdf0e10cSrcweir maViews(),
72cdf0e10cSrcweir mrScreenUpdater( rScreenUpdater ),
73cdf0e10cSrcweir mbVisible(false)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir std::for_each( rViewContainer.begin(),
76cdf0e10cSrcweir rViewContainer.end(),
77cdf0e10cSrcweir boost::bind( &WaitSymbol::viewAdded,
78cdf0e10cSrcweir this,
79cdf0e10cSrcweir _1 ));
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
setVisible(const bool bVisible)82cdf0e10cSrcweir void WaitSymbol::setVisible( const bool bVisible )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir if( mbVisible != bVisible )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir mbVisible = bVisible;
87cdf0e10cSrcweir
88cdf0e10cSrcweir ViewsVecT::const_iterator aIter( maViews.begin() );
89cdf0e10cSrcweir ViewsVecT::const_iterator const aEnd ( maViews.end() );
90cdf0e10cSrcweir while( aIter != aEnd )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir if( aIter->second )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir if( bVisible )
95cdf0e10cSrcweir aIter->second->show();
96cdf0e10cSrcweir else
97cdf0e10cSrcweir aIter->second->hide();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir ++aIter;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir // sprites changed, need a screen update for this frame.
104cdf0e10cSrcweir mrScreenUpdater.requestImmediateUpdate();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
calcSpritePos(UnoViewSharedPtr const & rView) const108cdf0e10cSrcweir basegfx::B2DPoint WaitSymbol::calcSpritePos(
109cdf0e10cSrcweir UnoViewSharedPtr const & rView ) const
110cdf0e10cSrcweir {
111cdf0e10cSrcweir const uno::Reference<rendering::XBitmap> xBitmap( rView->getCanvas()->getUNOCanvas(),
112cdf0e10cSrcweir uno::UNO_QUERY_THROW );
113cdf0e10cSrcweir const geometry::IntegerSize2D realSize( xBitmap->getSize() );
114cdf0e10cSrcweir return basegfx::B2DPoint(
115cdf0e10cSrcweir std::min<sal_Int32>( realSize.Width, LEFT_BORDER_SPACE ),
116cdf0e10cSrcweir std::max<sal_Int32>( 0, realSize.Height - mxBitmap->getSize().Height
117cdf0e10cSrcweir - LOWER_BORDER_SPACE ) );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
viewAdded(const UnoViewSharedPtr & rView)120cdf0e10cSrcweir void WaitSymbol::viewAdded( const UnoViewSharedPtr& rView )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir cppcanvas::CustomSpriteSharedPtr sprite;
123cdf0e10cSrcweir
124cdf0e10cSrcweir try
125cdf0e10cSrcweir {
126cdf0e10cSrcweir const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
127cdf0e10cSrcweir sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width,
128cdf0e10cSrcweir spriteSize.Height ),
129cdf0e10cSrcweir 1000.0 ); // sprite should be in front of all
130cdf0e10cSrcweir // other sprites
131cdf0e10cSrcweir rendering::ViewState viewState;
132cdf0e10cSrcweir canvas::tools::initViewState( viewState );
133cdf0e10cSrcweir rendering::RenderState renderState;
134cdf0e10cSrcweir canvas::tools::initRenderState( renderState );
135cdf0e10cSrcweir sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
136cdf0e10cSrcweir mxBitmap, viewState, renderState );
137cdf0e10cSrcweir
138cdf0e10cSrcweir sprite->setAlpha( 0.9 );
139cdf0e10cSrcweir sprite->movePixel( calcSpritePos( rView ) );
140cdf0e10cSrcweir if( mbVisible )
141cdf0e10cSrcweir sprite->show();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir catch( uno::Exception& )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir OSL_ENSURE( false,
146cdf0e10cSrcweir rtl::OUStringToOString(
147cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ),
148cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir maViews.push_back( ViewsVecT::value_type( rView, sprite ) );
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
viewRemoved(const UnoViewSharedPtr & rView)154cdf0e10cSrcweir void WaitSymbol::viewRemoved( const UnoViewSharedPtr& rView )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir maViews.erase(
157cdf0e10cSrcweir std::remove_if(
158cdf0e10cSrcweir maViews.begin(), maViews.end(),
159cdf0e10cSrcweir boost::bind(
160cdf0e10cSrcweir std::equal_to<UnoViewSharedPtr>(),
161cdf0e10cSrcweir rView,
162cdf0e10cSrcweir // select view:
163cdf0e10cSrcweir boost::bind( std::select1st<ViewsVecT::value_type>(), _1 ) ) ),
164cdf0e10cSrcweir maViews.end() );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
viewChanged(const UnoViewSharedPtr & rView)167cdf0e10cSrcweir void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir // find entry corresponding to modified view
170cdf0e10cSrcweir ViewsVecT::iterator aModifiedEntry(
171cdf0e10cSrcweir std::find_if(
172cdf0e10cSrcweir maViews.begin(),
173cdf0e10cSrcweir maViews.end(),
174cdf0e10cSrcweir boost::bind(
175cdf0e10cSrcweir std::equal_to<UnoViewSharedPtr>(),
176cdf0e10cSrcweir rView,
177cdf0e10cSrcweir // select view:
178cdf0e10cSrcweir boost::bind( std::select1st<ViewsVecT::value_type>(), _1 ))));
179cdf0e10cSrcweir
180cdf0e10cSrcweir OSL_ASSERT( aModifiedEntry != maViews.end() );
181cdf0e10cSrcweir if( aModifiedEntry == maViews.end() )
182cdf0e10cSrcweir return;
183cdf0e10cSrcweir
184cdf0e10cSrcweir if( aModifiedEntry->second )
185cdf0e10cSrcweir aModifiedEntry->second->movePixel(
186cdf0e10cSrcweir calcSpritePos(aModifiedEntry->first) );
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
viewsChanged()189cdf0e10cSrcweir void WaitSymbol::viewsChanged()
190cdf0e10cSrcweir {
191cdf0e10cSrcweir // reposition sprites on all views
192cdf0e10cSrcweir ViewsVecT::const_iterator aIter( maViews.begin() );
193cdf0e10cSrcweir ViewsVecT::const_iterator const aEnd ( maViews.end() );
194cdf0e10cSrcweir while( aIter != aEnd )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir if( aIter->second )
197cdf0e10cSrcweir aIter->second->movePixel(
198cdf0e10cSrcweir calcSpritePos( aIter->first ));
199cdf0e10cSrcweir ++aIter;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir } // namespace internal
204cdf0e10cSrcweir } // namespace presentation
205