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

Generated by: LCOV version 1.10