LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - ShadowOverlayObject.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 60 74 81.1 %
Date: 2015-06-13 12:38:46 Functions: 17 19 89.5 %
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             : #include <ShadowOverlayObject.hxx>
      21             : 
      22             : #include <view.hxx>
      23             : #include <svx/sdrpaintwindow.hxx>
      24             : #include <svx/svdview.hxx>
      25             : #include <svx/sdr/overlay/overlaymanager.hxx>
      26             : 
      27             : #include <sw_primitivetypes2d.hxx>
      28             : #include <drawinglayer/primitive2d/primitivetools2d.hxx>
      29             : #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
      30             : 
      31             : namespace sw { namespace sidebarwindows {
      32             : 
      33             : // helper SwPostItShadowPrimitive
      34             : 
      35             : // Used to allow view-dependent primitive definition. For that purpose, the
      36             : // initially created primitive (this one) always has to be view-independent,
      37             : // but the decomposition is made view-dependent. Very simple primitive which
      38             : // just remembers the discrete data and applies it at decomposition time.
      39        1008 : class ShadowPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
      40             : {
      41             : private:
      42             :     basegfx::B2DPoint           maBasePosition;
      43             :     basegfx::B2DPoint           maSecondPosition;
      44             :     ShadowState                 maShadowState;
      45             : 
      46             : protected:
      47             :     virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
      48             :         const drawinglayer::geometry::ViewInformation2D& rViewInformation) const SAL_OVERRIDE;
      49             : 
      50             : public:
      51         504 :     ShadowPrimitive(
      52             :         const basegfx::B2DPoint& rBasePosition,
      53             :         const basegfx::B2DPoint& rSecondPosition,
      54             :         ShadowState aShadowState)
      55             :     :   drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
      56             :         maBasePosition(rBasePosition),
      57             :         maSecondPosition(rSecondPosition),
      58         504 :         maShadowState(aShadowState)
      59         504 :     {}
      60             : 
      61             :     // data access
      62         504 :     const basegfx::B2DPoint& getBasePosition() const { return maBasePosition; }
      63        1008 :     const basegfx::B2DPoint& getSecondPosition() const { return maSecondPosition; }
      64           0 :     ShadowState getShadowState() const { return maShadowState; }
      65             : 
      66             :     virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const SAL_OVERRIDE;
      67             : 
      68             :     DeclPrimitive2DIDBlock()
      69             : };
      70             : 
      71         504 : drawinglayer::primitive2d::Primitive2DSequence ShadowPrimitive::create2DDecomposition(
      72             :     const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
      73             : {
      74             :     // get logic sizes in object coordinate system
      75         504 :     drawinglayer::primitive2d::Primitive2DSequence xRetval;
      76         504 :     basegfx::B2DRange aRange(getBasePosition());
      77             : 
      78         504 :     switch(maShadowState)
      79             :     {
      80             :         case SS_NORMAL:
      81             :         {
      82         495 :             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
      83             :             const ::drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
      84             :                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
      85             :                 0.0,
      86             :                 0.5,
      87             :                 0.5,
      88             :                 1800.0 * F_PI1800,
      89             :                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
      90             :                 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
      91         495 :                 2);
      92             : 
      93             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
      94             :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
      95             :                     aRange,
      96         990 :                     aFillGradientAttribute));
      97             : 
      98         495 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
      99         990 :             break;
     100             :         }
     101             :         case SS_VIEW:
     102             :         {
     103           9 :             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
     104             :             const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
     105             :                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
     106             :                 0.0,
     107             :                 0.5,
     108             :                 0.5,
     109             :                 1800.0 * F_PI1800,
     110             :                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
     111             :                 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
     112           9 :                 4);
     113             : 
     114             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     115             :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
     116             :                     aRange,
     117          18 :                     aFillGradientAttribute));
     118             : 
     119           9 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     120          18 :             break;
     121             :         }
     122             :         case SS_EDIT:
     123             :         {
     124           0 :             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
     125             :             const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
     126             :                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
     127             :                 0.0,
     128             :                 0.5,
     129             :                 0.5,
     130             :                 1800.0 * F_PI1800,
     131             :                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
     132             :                 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0),
     133           0 :                 4);
     134             : 
     135             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     136             :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
     137             :                     aRange,
     138           0 :                     aFillGradientAttribute));
     139             : 
     140           0 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     141           0 :             break;
     142             :         }
     143             :         default:
     144             :         {
     145           0 :             break;
     146             :         }
     147             :     }
     148             : 
     149         504 :     return xRetval;
     150             : }
     151             : 
     152           0 : bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
     153             : {
     154           0 :     if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
     155             :     {
     156           0 :         const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
     157             : 
     158           0 :         return (getBasePosition() == rCompare.getBasePosition()
     159           0 :             && getSecondPosition() == rCompare.getSecondPosition()
     160           0 :             && getShadowState() == rCompare.getShadowState());
     161             :     }
     162             : 
     163           0 :     return false;
     164             : }
     165             : 
     166           2 : ImplPrimitive2DIDBlock(ShadowPrimitive, PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE)
     167             : 
     168          84 : /* static */ ShadowOverlayObject* ShadowOverlayObject::CreateShadowOverlayObject( SwView& rDocView )
     169             : {
     170          84 :     ShadowOverlayObject* pShadowOverlayObject( 0 );
     171             : 
     172          84 :     if ( rDocView.GetDrawView() )
     173             :     {
     174          84 :         SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
     175          84 :         if( pPaintWindow )
     176             :         {
     177          84 :             rtl::Reference< sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
     178             : 
     179          84 :             if ( xOverlayManager.is() )
     180             :             {
     181             :                 pShadowOverlayObject = new ShadowOverlayObject( basegfx::B2DPoint(0,0),
     182             :                                                                 basegfx::B2DPoint(0,0),
     183             :                                                                 Color(0,0,0),
     184          84 :                                                                 SS_NORMAL );
     185          84 :                 xOverlayManager->add(*pShadowOverlayObject);
     186          84 :             }
     187             :         }
     188             :     }
     189             : 
     190          84 :     return pShadowOverlayObject;
     191             : }
     192             : 
     193          84 : /* static */ void ShadowOverlayObject::DestroyShadowOverlayObject( ShadowOverlayObject* pShadow )
     194             : {
     195          84 :     if ( pShadow )
     196             :     {
     197          84 :         if ( pShadow->getOverlayManager() )
     198             :         {
     199          84 :             pShadow->getOverlayManager()->remove(*pShadow);
     200             :         }
     201          84 :         delete pShadow;
     202             :     }
     203          84 : }
     204             : 
     205          84 : ShadowOverlayObject::ShadowOverlayObject( const basegfx::B2DPoint& rBasePos,
     206             :                                           const basegfx::B2DPoint& rSecondPosition,
     207             :                                           Color aBaseColor,
     208             :                                           ShadowState aState )
     209             :     : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
     210             :     , maSecondPosition(rSecondPosition)
     211          84 :     , mShadowState(aState)
     212             : {
     213          84 : }
     214             : 
     215         168 : ShadowOverlayObject::~ShadowOverlayObject()
     216             : {
     217         168 : }
     218             : 
     219         504 : drawinglayer::primitive2d::Primitive2DSequence ShadowOverlayObject::createOverlayObjectPrimitive2DSequence()
     220             : {
     221             :     const drawinglayer::primitive2d::Primitive2DReference aReference(
     222         504 :         new ShadowPrimitive( getBasePosition(),
     223             :                              GetSecondPosition(),
     224         504 :                              GetShadowState() ) );
     225         504 :     return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
     226             : }
     227             : 
     228           3 : void ShadowOverlayObject::SetShadowState(ShadowState aState)
     229             : {
     230           3 :     if (mShadowState != aState)
     231             :     {
     232           3 :         mShadowState = aState;
     233             : 
     234           3 :         objectChange();
     235             :     }
     236           3 : }
     237             : 
     238         252 : void ShadowOverlayObject::SetPosition( const basegfx::B2DPoint& rPoint1,
     239             :                                        const basegfx::B2DPoint& rPoint2)
     240             : {
     241         252 :     if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(GetSecondPosition()))
     242             :     {
     243         249 :         maBasePosition = rPoint1;
     244         249 :         maSecondPosition = rPoint2;
     245             : 
     246         249 :         objectChange();
     247             :     }
     248         252 : }
     249             : 
     250         177 : } } // end of namespace sw::sidebarwindows
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11