LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - ShadowOverlayObject.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 60 74 81.1 %
Date: 2014-11-03 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        1620 : 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         810 :     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         810 :         maShadowState(aShadowState)
      59         810 :     {}
      60             : 
      61             :     // data access
      62         810 :     const basegfx::B2DPoint& getBasePosition() const { return maBasePosition; }
      63        1620 :     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         810 : drawinglayer::primitive2d::Primitive2DSequence ShadowPrimitive::create2DDecomposition(
      72             :     const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
      73             : {
      74             :     // get logic sizes in object coordinate system
      75         810 :     drawinglayer::primitive2d::Primitive2DSequence xRetval;
      76         810 :     basegfx::B2DRange aRange(getBasePosition());
      77             : 
      78         810 :     switch(maShadowState)
      79             :     {
      80             :         case SS_NORMAL:
      81             :         {
      82         792 :             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         792 :                 2);
      92             : 
      93             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
      94             :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
      95             :                     aRange,
      96        1584 :                     aFillGradientAttribute));
      97             : 
      98         792 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
      99        1584 :             break;
     100             :         }
     101             :         case SS_VIEW:
     102             :         {
     103          18 :             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          18 :                 4);
     113             : 
     114             :             const drawinglayer::primitive2d::Primitive2DReference xReference(
     115             :                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
     116             :                     aRange,
     117          36 :                     aFillGradientAttribute));
     118             : 
     119          18 :             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
     120          36 :             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         810 :     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           4 : ImplPrimitive2DIDBlock(ShadowPrimitive, PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE)
     167             : 
     168         130 : /* static */ ShadowOverlayObject* ShadowOverlayObject::CreateShadowOverlayObject( SwView& rDocView )
     169             : {
     170         130 :     ShadowOverlayObject* pShadowOverlayObject( 0 );
     171             : 
     172         130 :     if ( rDocView.GetDrawView() )
     173             :     {
     174         130 :         SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
     175         130 :         if( pPaintWindow )
     176             :         {
     177         130 :             rtl::Reference< ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
     178             : 
     179         130 :             if ( xOverlayManager.is() )
     180             :             {
     181             :                 pShadowOverlayObject = new ShadowOverlayObject( basegfx::B2DPoint(0,0),
     182             :                                                                 basegfx::B2DPoint(0,0),
     183             :                                                                 Color(0,0,0),
     184         130 :                                                                 SS_NORMAL );
     185         130 :                 xOverlayManager->add(*pShadowOverlayObject);
     186         130 :             }
     187             :         }
     188             :     }
     189             : 
     190         130 :     return pShadowOverlayObject;
     191             : }
     192             : 
     193         130 : /* static */ void ShadowOverlayObject::DestroyShadowOverlayObject( ShadowOverlayObject* pShadow )
     194             : {
     195         130 :     if ( pShadow )
     196             :     {
     197         130 :         if ( pShadow->getOverlayManager() )
     198             :         {
     199         130 :             pShadow->getOverlayManager()->remove(*pShadow);
     200             :         }
     201         130 :         delete pShadow;
     202             :     }
     203         130 : }
     204             : 
     205         130 : 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         130 :     , mShadowState(aState)
     212             : {
     213         130 : }
     214             : 
     215         260 : ShadowOverlayObject::~ShadowOverlayObject()
     216             : {
     217         260 : }
     218             : 
     219         810 : drawinglayer::primitive2d::Primitive2DSequence ShadowOverlayObject::createOverlayObjectPrimitive2DSequence()
     220             : {
     221             :     const drawinglayer::primitive2d::Primitive2DReference aReference(
     222         810 :         new ShadowPrimitive( getBasePosition(),
     223             :                              GetSecondPosition(),
     224         810 :                              GetShadowState() ) );
     225         810 :     return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
     226             : }
     227             : 
     228           6 : void ShadowOverlayObject::SetShadowState(ShadowState aState)
     229             : {
     230           6 :     if (mShadowState != aState)
     231             :     {
     232           6 :         mShadowState = aState;
     233             : 
     234           6 :         objectChange();
     235             :     }
     236           6 : }
     237             : 
     238         420 : void ShadowOverlayObject::SetPosition( const basegfx::B2DPoint& rPoint1,
     239             :                                        const basegfx::B2DPoint& rPoint2)
     240             : {
     241         420 :     if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(GetSecondPosition()))
     242             :     {
     243         414 :         maBasePosition = rPoint1;
     244         414 :         maSecondPosition = rPoint2;
     245             : 
     246         414 :         objectChange();
     247             :     }
     248         420 : }
     249             : 
     250         270 : } } // end of namespace sw::sidebarwindows
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10