LCOV - code coverage report
Current view: top level - slideshow/source/engine/shapes - backgroundshape.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 67 0.0 %
Date: 2014-04-14 Functions: 0 19 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             : // must be first
      22             : #include <canvas/debug.hxx>
      23             : 
      24             : #include <com/sun/star/awt/Rectangle.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/awt/FontWeight.hpp>
      27             : 
      28             : #include <vcl/metaact.hxx>
      29             : #include <vcl/gdimtf.hxx>
      30             : 
      31             : #include <basegfx/numeric/ftools.hxx>
      32             : 
      33             : #include <boost/bind.hpp>
      34             : 
      35             : #include <cmath>
      36             : #include <algorithm>
      37             : #include <functional>
      38             : #include <limits>
      39             : 
      40             : #include "backgroundshape.hxx"
      41             : #include "slideshowexceptions.hxx"
      42             : #include "slideshowcontext.hxx"
      43             : #include "gdimtftools.hxx"
      44             : #include "shape.hxx"
      45             : #include "viewbackgroundshape.hxx"
      46             : 
      47             : 
      48             : using namespace ::com::sun::star;
      49             : 
      50             : 
      51             : namespace slideshow
      52             : {
      53             :     namespace internal
      54             :     {
      55             :         /** Representation of a draw document's background shape.
      56             : 
      57             :             This class implements the Shape interface for the
      58             :             background shape. Since the background shape is neither
      59             :             animatable nor attributable, those more specialized
      60             :             derivations of the Shape interface are not implemented
      61             :             here.
      62             : 
      63             :             @attention this class is to be treated 'final', i.e. one
      64             :             should not derive from it.
      65             :          */
      66           0 :         class BackgroundShape : public Shape
      67             :         {
      68             :         public:
      69             :             /** Create the background shape.
      70             : 
      71             :                 This method creates a shape that handles the
      72             :                 peculiarities of the draw API regarding background
      73             :                 content.
      74             :              */
      75             :             BackgroundShape( const ::com::sun::star::uno::Reference<
      76             :                                  ::com::sun::star::drawing::XDrawPage >& xDrawPage,
      77             :                              const ::com::sun::star::uno::Reference<
      78             :                                  ::com::sun::star::drawing::XDrawPage >& xMasterPage,
      79             :                              const SlideShowContext&                    rContext ); // throw ShapeLoadFailedException;
      80             : 
      81             :             virtual ::com::sun::star::uno::Reference<
      82             :                 ::com::sun::star::drawing::XShape > getXShape() const SAL_OVERRIDE;
      83             : 
      84             :             // View layer methods
      85             : 
      86             : 
      87             :             virtual void addViewLayer( const ViewLayerSharedPtr&    rNewLayer,
      88             :                                        bool                         bRedrawLayer ) SAL_OVERRIDE;
      89             :             virtual bool removeViewLayer( const ViewLayerSharedPtr& rNewLayer ) SAL_OVERRIDE;
      90             :             virtual bool clearAllViewLayers() SAL_OVERRIDE;
      91             : 
      92             : 
      93             :             // attribute methods
      94             : 
      95             : 
      96             :             virtual ::basegfx::B2DRectangle getBounds() const SAL_OVERRIDE;
      97             :             virtual ::basegfx::B2DRectangle getDomBounds() const SAL_OVERRIDE;
      98             :             virtual ::basegfx::B2DRectangle getUpdateArea() const SAL_OVERRIDE;
      99             :             virtual bool isVisible() const SAL_OVERRIDE;
     100             :             virtual double getPriority() const SAL_OVERRIDE;
     101             :             virtual bool isBackgroundDetached() const SAL_OVERRIDE;
     102             : 
     103             : 
     104             :             // render methods
     105             : 
     106             : 
     107             :             virtual bool update() const SAL_OVERRIDE;
     108             :             virtual bool render() const SAL_OVERRIDE;
     109             :             virtual bool isContentChanged() const SAL_OVERRIDE;
     110             : 
     111             :         private:
     112             :             /// The metafile actually representing the Shape
     113             :             GDIMetaFileSharedPtr        mpMtf;
     114             : 
     115             :             // The attributes of this Shape
     116             :             ::basegfx::B2DRectangle     maBounds; // always needed for rendering
     117             : 
     118             :             /// the list of active view shapes (one for each registered view layer)
     119             :             typedef ::std::vector< ViewBackgroundShapeSharedPtr > ViewBackgroundShapeVector;
     120             :             ViewBackgroundShapeVector   maViewShapes;
     121             :         };
     122             : 
     123             : 
     124             : 
     125             : 
     126             : 
     127           0 :         BackgroundShape::BackgroundShape( const uno::Reference< drawing::XDrawPage >& xDrawPage,
     128             :                                           const uno::Reference< drawing::XDrawPage >& xMasterPage,
     129             :                                           const SlideShowContext&                     rContext ) :
     130             :             mpMtf(),
     131             :             maBounds(),
     132           0 :             maViewShapes()
     133             :         {
     134             :             uno::Reference< beans::XPropertySet > xPropSet( xDrawPage,
     135           0 :                                                             uno::UNO_QUERY_THROW );
     136           0 :             GDIMetaFileSharedPtr pMtf( new GDIMetaFile() );
     137             : 
     138             :             // first try the page background (overrides
     139             :             // masterpage background), then try masterpage
     140           0 :             if( !getMetaFile( uno::Reference<lang::XComponent>(xDrawPage, uno::UNO_QUERY),
     141           0 :                               xDrawPage, *pMtf, MTF_LOAD_BACKGROUND_ONLY,
     142           0 :                               rContext.mxComponentContext ) &&
     143             :                 !getMetaFile( uno::Reference<lang::XComponent>(xMasterPage, uno::UNO_QUERY),
     144           0 :                               xDrawPage, *pMtf, MTF_LOAD_BACKGROUND_ONLY,
     145           0 :                               rContext.mxComponentContext ))
     146             :             {
     147           0 :                 throw ShapeLoadFailedException();
     148             :             }
     149             : 
     150             :             // there is a special background shape, add it
     151             :             // as the first one
     152             : 
     153             : 
     154           0 :             sal_Int32 nDocWidth=0;
     155           0 :             sal_Int32 nDocHeight=0;
     156           0 :             xPropSet->getPropertyValue("Width") >>= nDocWidth;
     157           0 :             xPropSet->getPropertyValue("Height") >>= nDocHeight;
     158             : 
     159           0 :             mpMtf = pMtf;
     160           0 :             maBounds = ::basegfx::B2DRectangle( 0,0,nDocWidth, nDocHeight );
     161           0 :         }
     162             : 
     163           0 :         uno::Reference< drawing::XShape > BackgroundShape::getXShape() const
     164             :         {
     165             :             // no real XShape representative
     166           0 :             return uno::Reference< drawing::XShape >();
     167             :         }
     168             : 
     169           0 :         void BackgroundShape::addViewLayer( const ViewLayerSharedPtr&   rNewLayer,
     170             :                                             bool                        bRedrawLayer )
     171             :         {
     172           0 :             ViewBackgroundShapeVector::iterator aEnd( maViewShapes.end() );
     173             : 
     174             :             // already added?
     175           0 :             if( ::std::find_if( maViewShapes.begin(),
     176             :                                 aEnd,
     177             :                                 ::boost::bind<bool>(
     178             :                                     ::std::equal_to< ViewLayerSharedPtr >(),
     179             :                                     ::boost::bind( &ViewBackgroundShape::getViewLayer,
     180             :                                                    _1 ),
     181           0 :                                     ::boost::cref( rNewLayer ) ) ) != aEnd )
     182             :             {
     183             :                 // yes, nothing to do
     184           0 :                 return;
     185             :             }
     186             : 
     187             :             maViewShapes.push_back(
     188             :                 ViewBackgroundShapeSharedPtr(
     189             :                     new ViewBackgroundShape( rNewLayer,
     190           0 :                                              maBounds ) ) );
     191             : 
     192             :             // render the Shape on the newly added ViewLayer
     193           0 :             if( bRedrawLayer )
     194           0 :                 maViewShapes.back()->render( mpMtf );
     195             :         }
     196             : 
     197           0 :         bool BackgroundShape::removeViewLayer( const ViewLayerSharedPtr& rLayer )
     198             :         {
     199           0 :             const ViewBackgroundShapeVector::iterator aEnd( maViewShapes.end() );
     200             : 
     201             :             OSL_ENSURE( ::std::count_if(maViewShapes.begin(),
     202             :                                         aEnd,
     203             :                                         ::boost::bind<bool>(
     204             :                                             ::std::equal_to< ViewLayerSharedPtr >(),
     205             :                                             ::boost::bind( &ViewBackgroundShape::getViewLayer,
     206             :                                                            _1 ),
     207             :                                             ::boost::cref( rLayer ) ) ) < 2,
     208             :                         "BackgroundShape::removeViewLayer(): Duplicate ViewLayer entries!" );
     209             : 
     210           0 :             ViewBackgroundShapeVector::iterator aIter;
     211             : 
     212           0 :             if( (aIter=::std::remove_if( maViewShapes.begin(),
     213             :                                          aEnd,
     214             :                                          ::boost::bind<bool>(
     215             :                                              ::std::equal_to< ViewLayerSharedPtr >(),
     216             :                                              ::boost::bind( &ViewBackgroundShape::getViewLayer,
     217             :                                                             _1 ),
     218           0 :                                              ::boost::cref( rLayer ) ) )) == aEnd )
     219             :             {
     220             :                 // view layer seemingly was not added, failed
     221           0 :                 return false;
     222             :             }
     223             : 
     224             :             // actually erase from container
     225           0 :             maViewShapes.erase( aIter, aEnd );
     226             : 
     227           0 :             return true;
     228             :         }
     229             : 
     230           0 :         bool BackgroundShape::clearAllViewLayers()
     231             :         {
     232           0 :             maViewShapes.clear();
     233           0 :             return true;
     234             :         }
     235             : 
     236           0 :         ::basegfx::B2DRectangle BackgroundShape::getBounds() const
     237             :         {
     238           0 :             return maBounds;
     239             :         }
     240             : 
     241           0 :         ::basegfx::B2DRectangle BackgroundShape::getDomBounds() const
     242             :         {
     243           0 :             return maBounds;
     244             :         }
     245             : 
     246           0 :         ::basegfx::B2DRectangle BackgroundShape::getUpdateArea() const
     247             :         {
     248             :             // TODO(F1): Need to expand background, too, when
     249             :             // antialiasing?
     250             : 
     251             :             // no transformation etc. possible for background shape
     252           0 :             return maBounds;
     253             :         }
     254             : 
     255           0 :         bool BackgroundShape::isVisible() const
     256             :         {
     257           0 :             return true;
     258             :         }
     259             : 
     260           0 :         double BackgroundShape::getPriority() const
     261             :         {
     262           0 :             return 0.0; // lowest prio, we're the background
     263             :         }
     264             : 
     265           0 :         bool BackgroundShape::update() const
     266             :         {
     267           0 :             return render();
     268             :         }
     269             : 
     270           0 :         bool BackgroundShape::render() const
     271             :         {
     272             :             SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape::render()" );
     273             :             SAL_INFO( "slideshow", "::presentation::internal::BackgroundShape: 0x" << std::hex << this );
     274             : 
     275             :             // gcc again...
     276           0 :             const ::basegfx::B2DRectangle& rCurrBounds( BackgroundShape::getBounds() );
     277             : 
     278           0 :             if( rCurrBounds.getRange().equalZero() )
     279             :             {
     280             :                 // zero-sized shapes are effectively invisible,
     281             :                 // thus, we save us the rendering...
     282           0 :                 return true;
     283             :             }
     284             : 
     285             :             // redraw all view shapes, by calling their render() method
     286           0 :             if( ::std::count_if( maViewShapes.begin(),
     287             :                                  maViewShapes.end(),
     288             :                                  ::boost::bind( &ViewBackgroundShape::render,
     289             :                                                 _1,
     290           0 :                                                 ::boost::cref( mpMtf ) ) )
     291           0 :                 != static_cast<ViewBackgroundShapeVector::difference_type>(maViewShapes.size()) )
     292             :             {
     293             :                 // at least one of the ViewBackgroundShape::render() calls did return
     294             :                 // false - update failed on at least one ViewLayer
     295           0 :                 return false;
     296             :             }
     297             : 
     298           0 :             return true;
     299             :         }
     300             : 
     301           0 :         bool BackgroundShape::isContentChanged() const
     302             :         {
     303           0 :             return false;
     304             :         }
     305             : 
     306           0 :         bool BackgroundShape::isBackgroundDetached() const
     307             :         {
     308           0 :             return false; // we're not animatable
     309             :         }
     310             : 
     311             : 
     312             : 
     313           0 :         ShapeSharedPtr createBackgroundShape(
     314             :             const uno::Reference< drawing::XDrawPage >& xDrawPage,
     315             :             const uno::Reference< drawing::XDrawPage >& xMasterPage,
     316             :             const SlideShowContext&                     rContext )
     317             :         {
     318             :             return ShapeSharedPtr(
     319             :                 new BackgroundShape(
     320             :                     xDrawPage,
     321             :                     xMasterPage,
     322           0 :                     rContext ));
     323             :         }
     324             :     }
     325           0 : }
     326             : 
     327             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10