LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - AnchorOverlayObject.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 114 181 63.0 %
Date: 2014-04-11 Functions: 22 28 78.6 %
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 <AnchorOverlayObject.hxx>
      21             : #include <SidebarWindowsConsts.hxx>
      22             : 
      23             : #include <swrect.hxx>
      24             : #include <view.hxx>
      25             : #include <svx/sdrpaintwindow.hxx>
      26             : #include <svx/svdview.hxx>
      27             : #include <svx/sdr/overlay/overlaymanager.hxx>
      28             : 
      29             : #include <sw_primitivetypes2d.hxx>
      30             : #include <drawinglayer/primitive2d/primitivetools2d.hxx>
      31             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      32             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      33             : #include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
      34             : 
      35             : namespace sw { namespace sidebarwindows {
      36             : 
      37             : // helper class: Primitive for discrete visualisation
      38         346 : class AnchorPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
      39             : {
      40             : private:
      41             :     basegfx::B2DPolygon             maTriangle;
      42             :     basegfx::B2DPolygon             maLine;
      43             :     basegfx::B2DPolygon             maLineTop;
      44             :     const AnchorState               maAnchorState;
      45             :     basegfx::BColor                 maColor;
      46             : 
      47             :     // discrete line width
      48             :     double                          mfDiscreteLineWidth;
      49             : 
      50             :     // bitfield
      51             :     bool                            mbShadow : 1;
      52             :     bool                            mbLineSolid : 1;
      53             : 
      54             : protected:
      55             :     virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
      56             :         const drawinglayer::geometry::ViewInformation2D& rViewInformation) const SAL_OVERRIDE;
      57             : 
      58             : public:
      59         173 :     AnchorPrimitive( const basegfx::B2DPolygon& rTriangle,
      60             :                      const basegfx::B2DPolygon& rLine,
      61             :                      const basegfx::B2DPolygon& rLineTop,
      62             :                      AnchorState aAnchorState,
      63             :                      const basegfx::BColor& rColor,
      64             :                      double fDiscreteLineWidth,
      65             :                      bool bShadow,
      66             :                      bool bLineSolid )
      67             :     :   drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
      68             :         maTriangle(rTriangle),
      69             :         maLine(rLine),
      70             :         maLineTop(rLineTop),
      71             :         maAnchorState(aAnchorState),
      72             :         maColor(rColor),
      73             :         mfDiscreteLineWidth(fDiscreteLineWidth),
      74             :         mbShadow(bShadow),
      75         173 :         mbLineSolid(bLineSolid)
      76         173 :     {}
      77             : 
      78             :     // data access
      79         173 :     const basegfx::B2DPolygon& getTriangle() const { return maTriangle; }
      80         125 :     const basegfx::B2DPolygon& getLine() const { return maLine; }
      81         125 :     const basegfx::B2DPolygon& getLineTop() const { return maLineTop; }
      82           0 :     AnchorState getAnchorState() const { return maAnchorState; }
      83         346 :     const basegfx::BColor& getColor() const { return maColor; }
      84         173 :     double getDiscreteLineWidth() const { return mfDiscreteLineWidth; }
      85         173 :     bool getShadow() const { return mbShadow; }
      86         125 :     bool getLineSolid() const { return mbLineSolid; }
      87             : 
      88             :     virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const SAL_OVERRIDE;
      89             : 
      90             :     DeclPrimitive2DIDBlock()
      91             : };
      92             : 
      93         173 : drawinglayer::primitive2d::Primitive2DSequence AnchorPrimitive::create2DDecomposition(
      94             :     const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
      95             : {
      96         173 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
      97             : 
      98         298 :     if ( AS_TRI == maAnchorState ||
      99         125 :          AS_ALL == maAnchorState ||
     100           0 :          AS_START == maAnchorState )
     101             :     {
     102             :         // create triangle
     103             :         const drawinglayer::primitive2d::Primitive2DReference aTriangle(
     104             :             new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
     105         173 :                 basegfx::B2DPolyPolygon(getTriangle()),
     106         173 :                 getColor()));
     107             : 
     108         173 :         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aTriangle);
     109             :     }
     110             : 
     111             :     // prepare view-independent LineWidth and color
     112             :     const drawinglayer::attribute::LineAttribute aLineAttribute(
     113         173 :         getColor(),
     114         519 :         getDiscreteLineWidth() * getDiscreteUnit());
     115             : 
     116         221 :     if ( AS_ALL == maAnchorState ||
     117          48 :          AS_START == maAnchorState )
     118             :     {
     119             :         // create line start
     120         125 :         if(getLineSolid())
     121             :         {
     122             :             const drawinglayer::primitive2d::Primitive2DReference aSolidLine(
     123             :                 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
     124             :                     getLine(),
     125           0 :                     aLineAttribute));
     126             : 
     127           0 :             drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aSolidLine);
     128             :         }
     129             :         else
     130             :         {
     131         125 :             ::std::vector< double > aDotDashArray;
     132         125 :             const double fDistance(3.0 * 15.0);
     133         125 :             const double fDashLen(5.0 * 15.0);
     134             : 
     135         125 :             aDotDashArray.push_back(fDashLen);
     136         125 :             aDotDashArray.push_back(fDistance);
     137             : 
     138             :             const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
     139             :                 aDotDashArray,
     140         250 :                 fDistance + fDashLen);
     141             : 
     142             :             const drawinglayer::primitive2d::Primitive2DReference aStrokedLine(
     143             :                 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
     144             :                     getLine(),
     145             :                     aLineAttribute,
     146         250 :                     aStrokeAttribute));
     147             : 
     148         250 :             drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aStrokedLine);
     149             :         }
     150             :     }
     151             : 
     152         173 :     if(aRetval.hasElements() && getShadow())
     153             :     {
     154             :         // shadow is only for triangle and line start, and in upper left
     155             :         // and lower right direction, in different colors
     156           0 :         const double fColorChange(20.0 / 255.0);
     157           0 :         const basegfx::B3DTuple aColorChange(fColorChange, fColorChange, fColorChange);
     158           0 :         basegfx::BColor aLighterColor(getColor() + aColorChange);
     159           0 :         basegfx::BColor aDarkerColor(getColor() - aColorChange);
     160             : 
     161           0 :         aLighterColor.clamp();
     162           0 :         aDarkerColor.clamp();
     163             : 
     164             :         // create shadow sequence
     165           0 :         drawinglayer::primitive2d::Primitive2DSequence aShadows(2);
     166           0 :         basegfx::B2DHomMatrix aTransform;
     167             : 
     168           0 :         aTransform.set(0, 2, -getDiscreteUnit());
     169           0 :         aTransform.set(1, 2, -getDiscreteUnit());
     170             : 
     171           0 :         aShadows[0] = drawinglayer::primitive2d::Primitive2DReference(
     172             :             new drawinglayer::primitive2d::ShadowPrimitive2D(
     173             :                 aTransform,
     174             :                 aLighterColor,
     175           0 :                 aRetval));
     176             : 
     177           0 :         aTransform.set(0, 2, getDiscreteUnit());
     178           0 :         aTransform.set(1, 2, getDiscreteUnit());
     179             : 
     180           0 :         aShadows[1] = drawinglayer::primitive2d::Primitive2DReference(
     181             :             new drawinglayer::primitive2d::ShadowPrimitive2D(
     182             :                 aTransform,
     183             :                 aDarkerColor,
     184           0 :                 aRetval));
     185             : 
     186             :         // add shadow before geometry to make it be proccessed first
     187           0 :         const drawinglayer::primitive2d::Primitive2DSequence aTemporary(aRetval);
     188             : 
     189           0 :         aRetval = aShadows;
     190           0 :         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, aTemporary);
     191             :     }
     192             : 
     193         221 :     if ( AS_ALL == maAnchorState ||
     194          48 :          AS_END == maAnchorState )
     195             :     {
     196             :         // LineTop has to be created, too, but uses no shadow, so add after
     197             :         // the other parts are created
     198             :         const drawinglayer::primitive2d::Primitive2DReference aLineTop(
     199             :             new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
     200             :                 getLineTop(),
     201         125 :                 aLineAttribute));
     202             : 
     203         125 :         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aLineTop);
     204             :     }
     205             : 
     206         346 :     return aRetval;
     207             : }
     208             : 
     209           0 : bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
     210             : {
     211           0 :     if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
     212             :     {
     213           0 :         const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
     214             : 
     215           0 :         return (getTriangle() == rCompare.getTriangle()
     216           0 :             && getLine() == rCompare.getLine()
     217           0 :             && getLineTop() == rCompare.getLineTop()
     218           0 :             && getAnchorState() == rCompare.getAnchorState()
     219           0 :             && getColor() == rCompare.getColor()
     220           0 :             && getDiscreteLineWidth() == rCompare.getDiscreteLineWidth()
     221           0 :             && getShadow() == rCompare.getShadow()
     222           0 :             && getLineSolid() == rCompare.getLineSolid());
     223             :     }
     224             : 
     225           0 :     return false;
     226             : }
     227             : 
     228           1 : ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE)
     229             : 
     230          48 : /*static*/ AnchorOverlayObject* AnchorOverlayObject::CreateAnchorOverlayObject(
     231             :                                                        SwView& rDocView,
     232             :                                                        const SwRect& aAnchorRect,
     233             :                                                        const long& aPageBorder,
     234             :                                                        const Point& aLineStart,
     235             :                                                        const Point& aLineEnd,
     236             :                                                        const Color& aColorAnchor )
     237             : {
     238          48 :     AnchorOverlayObject* pAnchorOverlayObject( 0 );
     239          48 :     if ( rDocView.GetDrawView() )
     240             :     {
     241          48 :         SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
     242          48 :         if( pPaintWindow )
     243             :         {
     244          48 :             rtl::Reference< ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
     245             : 
     246          48 :             if ( xOverlayManager.is() )
     247             :             {
     248             :                 pAnchorOverlayObject = new AnchorOverlayObject(
     249          96 :                     basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
     250          96 :                     basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
     251          96 :                     basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
     252          96 :                     basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
     253          48 :                     basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
     254          96 :                     basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
     255          96 :                     basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
     256             :                     aColorAnchor,
     257             :                     false,
     258         624 :                     false);
     259          48 :                 xOverlayManager->add(*pAnchorOverlayObject);
     260          48 :             }
     261             :         }
     262             :     }
     263             : 
     264          48 :     return pAnchorOverlayObject;
     265             : }
     266             : 
     267          48 : /*static*/ void AnchorOverlayObject::DestroyAnchorOverlayObject( AnchorOverlayObject* pAnchor )
     268             : {
     269          48 :     if ( pAnchor )
     270             :     {
     271          48 :         if ( pAnchor->getOverlayManager() )
     272             :         {
     273             :             // remove this object from the chain
     274          48 :             pAnchor->getOverlayManager()->remove(*pAnchor);
     275             :         }
     276          48 :         delete pAnchor;
     277             :     }
     278          48 : }
     279             : 
     280          48 : AnchorOverlayObject::AnchorOverlayObject( const basegfx::B2DPoint& rBasePos,
     281             :                                           const basegfx::B2DPoint& rSecondPos,
     282             :                                           const basegfx::B2DPoint& rThirdPos,
     283             :                                           const basegfx::B2DPoint& rFourthPos,
     284             :                                           const basegfx::B2DPoint& rFifthPos,
     285             :                                           const basegfx::B2DPoint& rSixthPos,
     286             :                                           const basegfx::B2DPoint& rSeventhPos,
     287             :                                           const Color aBaseColor,
     288             :                                           const bool bShadowedEffect,
     289             :                                           const bool bLineSolid)
     290             :     : OverlayObjectWithBasePosition( rBasePos, aBaseColor )
     291             :     , maSecondPosition(rSecondPos)
     292             :     , maThirdPosition(rThirdPos)
     293             :     , maFourthPosition(rFourthPos)
     294             :     , maFifthPosition(rFifthPos)
     295             :     , maSixthPosition(rSixthPos)
     296             :     , maSeventhPosition(rSeventhPos)
     297             :     , maTriangle()
     298             :     , maLine()
     299             :     , maLineTop()
     300             :     , mHeight(0)
     301             :     , mAnchorState(AS_ALL)
     302             :     , mbShadowedEffect(bShadowedEffect)
     303          48 :     , mbLineSolid(bLineSolid)
     304             : {
     305          48 : }
     306             : 
     307          96 : AnchorOverlayObject::~AnchorOverlayObject()
     308             : {
     309          96 : }
     310             : 
     311         173 : void AnchorOverlayObject::implEnsureGeometry()
     312             : {
     313         173 :     if(!maTriangle.count())
     314             :     {
     315          77 :         maTriangle.append(getBasePosition());
     316          77 :         maTriangle.append(GetSecondPosition());
     317          77 :         maTriangle.append(GetThirdPosition());
     318          77 :         maTriangle.setClosed(true);
     319             :     }
     320             : 
     321         173 :     if(!maLine.count())
     322             :     {
     323          77 :         maLine.append(GetFourthPosition());
     324          77 :         maLine.append(GetFifthPosition());
     325          77 :         maLine.append(GetSixthPosition());
     326             :     }
     327             : 
     328         173 :   if(!maLineTop.count())
     329             :     {
     330          77 :         maLineTop.append(GetSixthPosition());
     331          77 :         maLineTop.append(GetSeventhPosition());
     332             :     }
     333         173 : }
     334             : 
     335          29 : void AnchorOverlayObject::implResetGeometry()
     336             : {
     337          29 :     maTriangle.clear();
     338          29 :     maLine.clear();
     339          29 :     maLineTop.clear();
     340          29 : }
     341             : 
     342         173 : drawinglayer::primitive2d::Primitive2DSequence AnchorOverlayObject::createOverlayObjectPrimitive2DSequence()
     343             : {
     344         173 :     implEnsureGeometry();
     345             : 
     346             :     static double aDiscreteLineWidth(1.6);
     347             :     const drawinglayer::primitive2d::Primitive2DReference aReference(
     348             :         new AnchorPrimitive( maTriangle,
     349             :                              maLine,
     350             :                              maLineTop,
     351             :                              GetAnchorState(),
     352         173 :                              getBaseColor().getBColor(),
     353             :                              ANCHORLINE_WIDTH * aDiscreteLineWidth,
     354         173 :                              getShadowedEffect(),
     355         519 :                              getLineSolid()) );
     356             : 
     357         173 :     return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
     358             : }
     359             : 
     360          29 : void AnchorOverlayObject::SetAllPosition( const basegfx::B2DPoint& rPoint1,
     361             :                                           const basegfx::B2DPoint& rPoint2,
     362             :                                           const basegfx::B2DPoint& rPoint3,
     363             :                                           const basegfx::B2DPoint& rPoint4,
     364             :                                           const basegfx::B2DPoint& rPoint5,
     365             :                                           const basegfx::B2DPoint& rPoint6,
     366             :                                           const basegfx::B2DPoint& rPoint7)
     367             : {
     368          87 :     if ( rPoint1 != getBasePosition() ||
     369          58 :          rPoint2 != GetSecondPosition() ||
     370          58 :          rPoint3 != GetThirdPosition() ||
     371          58 :          rPoint4 != GetFourthPosition() ||
     372          58 :          rPoint5 != GetFifthPosition() ||
     373          58 :          rPoint6 != GetSixthPosition() ||
     374           0 :          rPoint7 != GetSeventhPosition() )
     375             :     {
     376          29 :         maBasePosition = rPoint1;
     377          29 :         maSecondPosition = rPoint2;
     378          29 :         maThirdPosition = rPoint3;
     379          29 :         maFourthPosition = rPoint4;
     380          29 :         maFifthPosition = rPoint5;
     381          29 :         maSixthPosition = rPoint6;
     382          29 :         maSeventhPosition = rPoint7;
     383             : 
     384          29 :         implResetGeometry();
     385          29 :         objectChange();
     386             :     }
     387          29 : }
     388             : 
     389           0 : void AnchorOverlayObject::SetSixthPosition(const basegfx::B2DPoint& rNew)
     390             : {
     391           0 :   if(rNew != maSixthPosition)
     392             :   {
     393           0 :       maSixthPosition = rNew;
     394           0 :         implResetGeometry();
     395           0 :       objectChange();
     396             :   }
     397           0 : }
     398             : 
     399           0 : void AnchorOverlayObject::SetSeventhPosition(const basegfx::B2DPoint& rNew)
     400             : {
     401           0 :   if(rNew != maSeventhPosition)
     402             :   {
     403           0 :       maSeventhPosition = rNew;
     404           0 :         implResetGeometry();
     405           0 :       objectChange();
     406             :   }
     407           0 : }
     408             : 
     409           0 : void AnchorOverlayObject::SetTriPosition(const basegfx::B2DPoint& rPoint1,const basegfx::B2DPoint& rPoint2,const basegfx::B2DPoint& rPoint3,
     410             :                                   const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
     411             : {
     412           0 :     if(rPoint1 != getBasePosition()
     413           0 :         || rPoint2 != GetSecondPosition()
     414           0 :         || rPoint3 != GetThirdPosition()
     415           0 :         || rPoint4 != GetFourthPosition()
     416           0 :         || rPoint5 != GetFifthPosition())
     417             :     {
     418           0 :       maBasePosition = rPoint1;
     419           0 :       maSecondPosition = rPoint2;
     420           0 :       maThirdPosition = rPoint3;
     421           0 :       maFourthPosition = rPoint4;
     422           0 :       maFifthPosition = rPoint5;
     423             : 
     424           0 :       implResetGeometry();
     425           0 :       objectChange();
     426             :     }
     427           0 : }
     428             : 
     429           0 : void AnchorOverlayObject::setLineSolid( const bool bNew )
     430             : {
     431           0 :   if ( bNew != getLineSolid() )
     432             :   {
     433           0 :       mbLineSolid = bNew;
     434           0 :       objectChange();
     435             :   }
     436           0 : }
     437             : 
     438         370 : void AnchorOverlayObject::SetAnchorState( const AnchorState aState)
     439             : {
     440         370 :   if ( mAnchorState != aState)
     441             :   {
     442          96 :       mAnchorState = aState;
     443          96 :       objectChange();
     444             :   }
     445         370 : }
     446             : 
     447             : } } // end of namespace sw::annotation
     448             : 
     449             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10