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

Generated by: LCOV version 1.10