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

Generated by: LCOV version 1.10