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