LCOV - code coverage report
Current view: top level - slideshow/source/engine/shapes - backgroundshape.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 67 0.0 %
Date: 2012-08-25 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10