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

Generated by: LCOV version 1.11