LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - AnchorOverlayObject.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 123 182 67.6 %
Date: 2014-11-03 Functions: 25 30 83.3 %
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         944 : 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         472 :     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         472 :         mbLineSolid(bLineSolid)
      76         472 :     {}
      77             : 
      78             :     // data access
      79         458 :     const basegfx::B2DPolygon& getTriangle() const { return maTriangle; }
      80         328 :     const basegfx::B2DPolygon& getLine() const { return maLine; }
      81         342 :     const basegfx::B2DPolygon& getLineTop() const { return maLineTop; }
      82           0 :     AnchorState getAnchorState() const { return maAnchorState; }
      83         930 :     const basegfx::BColor& getColor() const { return maColor; }
      84         472 :     double getDiscreteLineWidth() const { return mfDiscreteLineWidth; }
      85         458 :     bool getShadow() const { return mbShadow; }
      86         328 :     bool getLineSolid() const { return mbLineSolid; }
      87             : 
      88             :     virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const SAL_OVERRIDE;
      89             : 
      90             :     DeclPrimitive2DIDBlock()
      91             : };
      92             : 
      93         472 : drawinglayer::primitive2d::Primitive2DSequence AnchorPrimitive::create2DDecomposition(
      94             :     const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
      95             : {
      96         472 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
      97             : 
      98         814 :     if ( AS_TRI == maAnchorState ||
      99         356 :          AS_ALL == maAnchorState ||
     100          14 :          AS_START == maAnchorState )
     101             :     {
     102             :         // create triangle
     103             :         const drawinglayer::primitive2d::Primitive2DReference aTriangle(
     104             :             new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
     105         458 :                 basegfx::B2DPolyPolygon(getTriangle()),
     106         458 :                 getColor()));
     107             : 
     108         458 :         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aTriangle);
     109             :     }
     110             : 
     111             :     // prepare view-independent LineWidth and color
     112             :     const drawinglayer::attribute::LineAttribute aLineAttribute(
     113         472 :         getColor(),
     114        1416 :         getDiscreteLineWidth() * getDiscreteUnit());
     115             : 
     116         616 :     if ( AS_ALL == maAnchorState ||
     117         144 :          AS_START == maAnchorState )
     118             :     {
     119             :         // create line start
     120         328 :         if(getLineSolid())
     121             :         {
     122             :             const drawinglayer::primitive2d::Primitive2DReference aSolidLine(
     123             :                 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
     124             :                     getLine(),
     125          12 :                     aLineAttribute));
     126             : 
     127          12 :             drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aSolidLine);
     128             :         }
     129             :         else
     130             :         {
     131         316 :             ::std::vector< double > aDotDashArray;
     132         316 :             const double fDistance(3.0 * 15.0);
     133         316 :             const double fDashLen(5.0 * 15.0);
     134             : 
     135         316 :             aDotDashArray.push_back(fDashLen);
     136         316 :             aDotDashArray.push_back(fDistance);
     137             : 
     138             :             const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
     139             :                 aDotDashArray,
     140         632 :                 fDistance + fDashLen);
     141             : 
     142             :             const drawinglayer::primitive2d::Primitive2DReference aStrokedLine(
     143             :                 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
     144             :                     getLine(),
     145             :                     aLineAttribute,
     146         632 :                     aStrokeAttribute));
     147             : 
     148         632 :             drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aStrokedLine);
     149             :         }
     150             :     }
     151             : 
     152         472 :     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         616 :     if ( AS_ALL == maAnchorState ||
     194         144 :          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         342 :                 aLineAttribute));
     202             : 
     203         342 :         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aLineTop);
     204             :     }
     205             : 
     206         944 :     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           8 : ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE)
     229             : 
     230         130 : /*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         130 :     AnchorOverlayObject* pAnchorOverlayObject( 0 );
     239         130 :     if ( rDocView.GetDrawView() )
     240             :     {
     241         130 :         SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
     242         130 :         if( pPaintWindow )
     243             :         {
     244         130 :             rtl::Reference< ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
     245             : 
     246         130 :             if ( xOverlayManager.is() )
     247             :             {
     248             :                 pAnchorOverlayObject = new AnchorOverlayObject(
     249         260 :                     basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
     250         260 :                     basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
     251         260 :                     basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
     252         260 :                     basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
     253         130 :                     basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
     254         260 :                     basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
     255         260 :                     basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
     256             :                     aColorAnchor,
     257             :                     false,
     258        1690 :                     false);
     259         130 :                 xOverlayManager->add(*pAnchorOverlayObject);
     260         130 :             }
     261             :         }
     262             :     }
     263             : 
     264         130 :     return pAnchorOverlayObject;
     265             : }
     266             : 
     267         130 : /*static*/ void AnchorOverlayObject::DestroyAnchorOverlayObject( AnchorOverlayObject* pAnchor )
     268             : {
     269         130 :     if ( pAnchor )
     270             :     {
     271         130 :         if ( pAnchor->getOverlayManager() )
     272             :         {
     273             :             // remove this object from the chain
     274         130 :             pAnchor->getOverlayManager()->remove(*pAnchor);
     275             :         }
     276         130 :         delete pAnchor;
     277             :     }
     278         130 : }
     279             : 
     280         130 : 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         130 :     , mbLineSolid(bLineSolid)
     304             : {
     305         130 : }
     306             : 
     307         260 : AnchorOverlayObject::~AnchorOverlayObject()
     308             : {
     309         260 : }
     310             : 
     311         472 : void AnchorOverlayObject::implEnsureGeometry()
     312             : {
     313         472 :     if(!maTriangle.count())
     314             :     {
     315         206 :         maTriangle.append(getBasePosition());
     316         206 :         maTriangle.append(GetSecondPosition());
     317         206 :         maTriangle.append(GetThirdPosition());
     318         206 :         maTriangle.setClosed(true);
     319             :     }
     320             : 
     321         472 :     if(!maLine.count())
     322             :     {
     323         206 :         maLine.append(GetFourthPosition());
     324         206 :         maLine.append(GetFifthPosition());
     325         206 :         maLine.append(GetSixthPosition());
     326             :     }
     327             : 
     328         472 :   if(!maLineTop.count())
     329             :     {
     330         206 :         maLineTop.append(GetSixthPosition());
     331         206 :         maLineTop.append(GetSeventhPosition());
     332             :     }
     333         472 : }
     334             : 
     335          76 : void AnchorOverlayObject::implResetGeometry()
     336             : {
     337          76 :     maTriangle.clear();
     338          76 :     maLine.clear();
     339          76 :     maLineTop.clear();
     340          76 : }
     341             : 
     342         472 : drawinglayer::primitive2d::Primitive2DSequence AnchorOverlayObject::createOverlayObjectPrimitive2DSequence()
     343             : {
     344         472 :     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         472 :                              getBaseColor().getBColor(),
     353             :                              ANCHORLINE_WIDTH * aDiscreteLineWidth,
     354         472 :                              getShadowedEffect(),
     355        1416 :                              getLineSolid()) );
     356             : 
     357         472 :     return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
     358             : }
     359             : 
     360          76 : 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         228 :     if ( rPoint1 != getBasePosition() ||
     369         152 :          rPoint2 != GetSecondPosition() ||
     370         152 :          rPoint3 != GetThirdPosition() ||
     371         152 :          rPoint4 != GetFourthPosition() ||
     372         148 :          rPoint5 != GetFifthPosition() ||
     373         148 :          rPoint6 != GetSixthPosition() ||
     374           0 :          rPoint7 != GetSeventhPosition() )
     375             :     {
     376          76 :         maBasePosition = rPoint1;
     377          76 :         maSecondPosition = rPoint2;
     378          76 :         maThirdPosition = rPoint3;
     379          76 :         maFourthPosition = rPoint4;
     380          76 :         maFifthPosition = rPoint5;
     381          76 :         maSixthPosition = rPoint6;
     382          76 :         maSeventhPosition = rPoint7;
     383             : 
     384          76 :         implResetGeometry();
     385          76 :         objectChange();
     386             :     }
     387          76 : }
     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           6 : void AnchorOverlayObject::setLineSolid( const bool bNew )
     430             : {
     431           6 :   if ( bNew != getLineSolid() )
     432             :   {
     433           6 :       mbLineSolid = bNew;
     434           6 :       objectChange();
     435             :   }
     436           6 : }
     437             : 
     438        1290 : void AnchorOverlayObject::SetAnchorState( const AnchorState aState)
     439             : {
     440        1290 :   if ( mAnchorState != aState)
     441             :   {
     442         260 :       mAnchorState = aState;
     443         260 :       objectChange();
     444             :   }
     445        1290 : }
     446             : 
     447         270 : } } // end of namespace sw::annotation
     448             : 
     449             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10