LCOV - code coverage report
Current view: top level - slideshow/source/engine - waitsymbol.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 66 1.5 %
Date: 2014-11-03 Functions: 2 10 20.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10