LCOV - code coverage report
Current view: top level - sw/source/ui/docvw - ShadowOverlayObject.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 73 68.5 %
Date: 2012-08-25 Functions: 14 17 82.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 112 27.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /************************************************************************* *
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2008 by Sun Microsystems, Inc.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <ShadowOverlayObject.hxx>
      30                 :            : 
      31                 :            : #include <view.hxx>
      32                 :            : #include <svx/sdrpaintwindow.hxx>
      33                 :            : #include <svx/svdview.hxx>
      34                 :            : #include <svx/sdr/overlay/overlaymanager.hxx>
      35                 :            : 
      36                 :            : #include <sw_primitivetypes2d.hxx>
      37                 :            : #include <drawinglayer/primitive2d/primitivetools2d.hxx>
      38                 :            : #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
      39                 :            : 
      40                 :            : namespace sw { namespace sidebarwindows {
      41                 :            : 
      42                 :            : //////////////////////////////////////////////////////////////////////////////
      43                 :            : // helper SwPostItShadowPrimitive
      44                 :            : //
      45                 :            : // Used to allow view-dependent primitive definition. For that purpose, the
      46                 :            : // initially created primitive (this one) always has to be view-independent,
      47                 :            : // but the decomposition is made view-dependent. Very simple primitive which
      48                 :            : // just remembers the discrete data and applies it at decomposition time.
      49                 :            : 
      50         [ -  + ]:        174 : class ShadowPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
      51                 :            : {
      52                 :            : private:
      53                 :            :     basegfx::B2DPoint           maBasePosition;
      54                 :            :     basegfx::B2DPoint           maSecondPosition;
      55                 :            :     ShadowState                 maShadowState;
      56                 :            : 
      57                 :            : protected:
      58                 :            :     virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
      59                 :            :         const drawinglayer::geometry::ViewInformation2D& rViewInformation) const;
      60                 :            : 
      61                 :            : public:
      62                 :         90 :     ShadowPrimitive(
      63                 :            :         const basegfx::B2DPoint& rBasePosition,
      64                 :            :         const basegfx::B2DPoint& rSecondPosition,
      65                 :            :         ShadowState aShadowState)
      66                 :            :     :   drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
      67                 :            :         maBasePosition(rBasePosition),
      68                 :            :         maSecondPosition(rSecondPosition),
      69                 :         90 :         maShadowState(aShadowState)
      70                 :         90 :     {}
      71                 :            : 
      72                 :            :     // data access
      73                 :         90 :     const basegfx::B2DPoint& getBasePosition() const { return maBasePosition; }
      74                 :        180 :     const basegfx::B2DPoint& getSecondPosition() const { return maSecondPosition; }
      75                 :          0 :     ShadowState getShadowState() const { return maShadowState; }
      76                 :            : 
      77                 :            :     virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const;
      78                 :            : 
      79                 :            :     DeclPrimitrive2DIDBlock()
      80                 :            : };
      81                 :            : 
      82                 :         90 : drawinglayer::primitive2d::Primitive2DSequence ShadowPrimitive::create2DDecomposition(
      83                 :            :     const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
      84                 :            : {
      85                 :            :     // get logic sizes in object coordinate system
      86         [ +  - ]:         90 :     drawinglayer::primitive2d::Primitive2DSequence xRetval;
      87         [ +  - ]:         90 :     basegfx::B2DRange aRange(getBasePosition());
      88                 :            : 
      89   [ +  -  -  - ]:         90 :     switch(maShadowState)
      90                 :            :     {
      91                 :            :         case SS_NORMAL:
      92                 :            :         {
      93         [ +  - ]:         90 :             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
      94                 :            :             const ::drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
      95                 :            :                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
      96                 :            :                 0.0,
      97                 :            :                 0.5,
      98                 :            :                 0.5,
      99                 :            :                 1800.0 * F_PI1800,
     100                 :            :                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
     101                 :            :                 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
     102         [ +  - ]:         90 :                 2);
     103                 :            : 
     104                 :            :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     105                 :            :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
     106                 :            :                     aRange,
     107 [ +  - ][ +  - ]:         90 :                     aFillGradientAttribute));
                 [ +  - ]
     108                 :            : 
     109 [ +  - ][ +  - ]:         90 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
                 [ +  - ]
     110         [ +  - ]:         90 :             break;
     111                 :            :         }
     112                 :            :         case SS_VIEW:
     113                 :            :         {
     114         [ #  # ]:          0 :             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
     115                 :            :             const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
     116                 :            :                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
     117                 :            :                 0.0,
     118                 :            :                 0.5,
     119                 :            :                 0.5,
     120                 :            :                 1800.0 * F_PI1800,
     121                 :            :                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
     122                 :            :                 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
     123         [ #  # ]:          0 :                 4);
     124                 :            : 
     125                 :            :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     126                 :            :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
     127                 :            :                     aRange,
     128 [ #  # ][ #  # ]:          0 :                     aFillGradientAttribute));
                 [ #  # ]
     129                 :            : 
     130 [ #  # ][ #  # ]:          0 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
                 [ #  # ]
     131         [ #  # ]:          0 :             break;
     132                 :            :         }
     133                 :            :         case SS_EDIT:
     134                 :            :         {
     135         [ #  # ]:          0 :             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
     136                 :            :             const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
     137                 :            :                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
     138                 :            :                 0.0,
     139                 :            :                 0.5,
     140                 :            :                 0.5,
     141                 :            :                 1800.0 * F_PI1800,
     142                 :            :                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
     143                 :            :                 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0),
     144         [ #  # ]:          0 :                 4);
     145                 :            : 
     146                 :            :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     147                 :            :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
     148                 :            :                     aRange,
     149 [ #  # ][ #  # ]:          0 :                     aFillGradientAttribute));
                 [ #  # ]
     150                 :            : 
     151 [ #  # ][ #  # ]:          0 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
                 [ #  # ]
     152         [ #  # ]:          0 :             break;
     153                 :            :         }
     154                 :            :         default:
     155                 :            :         {
     156                 :         90 :             break;
     157                 :            :         }
     158                 :            :     }
     159                 :            : 
     160                 :         90 :     return xRetval;
     161                 :            : }
     162                 :            : 
     163                 :          0 : bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
     164                 :            : {
     165         [ #  # ]:          0 :     if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
     166                 :            :     {
     167                 :          0 :         const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
     168                 :            : 
     169                 :          0 :         return (getBasePosition() == rCompare.getBasePosition()
     170                 :          0 :             && getSecondPosition() == rCompare.getSecondPosition()
     171         [ #  # ]:          0 :             && getShadowState() == rCompare.getShadowState());
           [ #  #  #  # ]
     172                 :            :     }
     173                 :            : 
     174                 :          0 :     return false;
     175                 :            : }
     176                 :            : 
     177                 :          3 : ImplPrimitrive2DIDBlock(ShadowPrimitive, PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE)
     178                 :            : 
     179                 :            : /****** ShadowOverlayObject  **************************************************/
     180                 :         18 : /* static */ ShadowOverlayObject* ShadowOverlayObject::CreateShadowOverlayObject( SwView& rDocView )
     181                 :            : {
     182                 :         18 :     ShadowOverlayObject* pShadowOverlayObject( 0 );
     183                 :            : 
     184         [ +  - ]:         18 :     if ( rDocView.GetDrawView() )
     185                 :            :     {
     186                 :         18 :         SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
     187         [ +  - ]:         18 :         if( pPaintWindow )
     188                 :            :         {
     189         [ +  - ]:         18 :             rtl::Reference< ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
     190                 :            : 
     191         [ +  - ]:         18 :             if ( xOverlayManager.is() )
     192                 :            :             {
     193                 :            :                 pShadowOverlayObject = new ShadowOverlayObject( basegfx::B2DPoint(0,0),
     194                 :            :                                                                 basegfx::B2DPoint(0,0),
     195                 :            :                                                                 Color(0,0,0),
     196 [ +  - ][ +  - ]:         18 :                                                                 SS_NORMAL );
     197         [ +  - ]:         18 :                 xOverlayManager->add(*pShadowOverlayObject);
     198         [ +  - ]:         18 :             }
     199                 :            :         }
     200                 :            :     }
     201                 :            : 
     202                 :         18 :     return pShadowOverlayObject;
     203                 :            : }
     204                 :            : 
     205                 :         15 : /* static */ void ShadowOverlayObject::DestroyShadowOverlayObject( ShadowOverlayObject* pShadow )
     206                 :            : {
     207         [ +  - ]:         15 :     if ( pShadow )
     208                 :            :     {
     209         [ +  - ]:         15 :         if ( pShadow->getOverlayManager() )
     210                 :            :         {
     211                 :         15 :             pShadow->getOverlayManager()->remove(*pShadow);
     212                 :            :         }
     213         [ +  - ]:         15 :         delete pShadow;
     214                 :            :     }
     215                 :         15 : }
     216                 :            : 
     217                 :         18 : ShadowOverlayObject::ShadowOverlayObject( const basegfx::B2DPoint& rBasePos,
     218                 :            :                                           const basegfx::B2DPoint& rSecondPosition,
     219                 :            :                                           Color aBaseColor,
     220                 :            :                                           ShadowState aState )
     221                 :            :     : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
     222                 :            :     , maSecondPosition(rSecondPosition)
     223                 :         18 :     , mShadowState(aState)
     224                 :            : {
     225                 :         18 : }
     226                 :            : 
     227                 :         15 : ShadowOverlayObject::~ShadowOverlayObject()
     228                 :            : {
     229         [ -  + ]:         30 : }
     230                 :            : 
     231                 :         90 : drawinglayer::primitive2d::Primitive2DSequence ShadowOverlayObject::createOverlayObjectPrimitive2DSequence()
     232                 :            : {
     233                 :            :     const drawinglayer::primitive2d::Primitive2DReference aReference(
     234                 :         90 :         new ShadowPrimitive( getBasePosition(),
     235                 :            :                              GetSecondPosition(),
     236 [ +  - ][ +  - ]:         90 :                              GetShadowState() ) );
                 [ +  - ]
     237         [ +  - ]:         90 :     return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
     238                 :            : }
     239                 :            : 
     240                 :          0 : void ShadowOverlayObject::SetShadowState(ShadowState aState)
     241                 :            : {
     242         [ #  # ]:          0 :     if (mShadowState != aState)
     243                 :            :     {
     244                 :          0 :         mShadowState = aState;
     245                 :            : 
     246                 :          0 :         objectChange();
     247                 :            :     }
     248                 :          0 : }
     249                 :            : 
     250                 :         36 : void ShadowOverlayObject::SetPosition( const basegfx::B2DPoint& rPoint1,
     251                 :            :                                        const basegfx::B2DPoint& rPoint2)
     252                 :            : {
     253 [ -  + ][ #  # ]:         36 :     if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(GetSecondPosition()))
                 [ +  - ]
     254                 :            :     {
     255                 :         36 :         maBasePosition = rPoint1;
     256                 :         36 :         maSecondPosition = rPoint2;
     257                 :            : 
     258                 :         36 :         objectChange();
     259                 :            :     }
     260                 :         36 : }
     261                 :            : 
     262                 :            : } } // end of namespace sw::sidebarwindows
     263                 :            : 
     264                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10