LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - OverlayRanges.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 44 67 65.7 %
Date: 2014-04-11 Functions: 7 9 77.8 %
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 <OverlayRanges.hxx>
      21             : #include <view.hxx>
      22             : #include <svx/sdrpaintwindow.hxx>
      23             : #include <svx/svdview.hxx>
      24             : #include <svx/sdr/overlay/overlaymanager.hxx>
      25             : #include <basegfx/polygon/b2dpolygon.hxx>
      26             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      27             : #include <basegfx/polygon/b2dpolygontools.hxx>
      28             : #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
      29             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      30             : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
      31             : 
      32             : namespace
      33             : {
      34             :     // combine ranges geometrically to a single, ORed polygon
      35           0 :     basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
      36             :     {
      37           0 :         const sal_uInt32 nCount(rRanges.size());
      38           0 :         basegfx::B2DPolyPolygon aRetval;
      39             : 
      40           0 :         for(sal_uInt32 a(0); a < nCount; a++)
      41             :         {
      42           0 :             const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
      43             : 
      44           0 :             if(0 == a)
      45             :             {
      46           0 :                 aRetval.append(aDiscretePolygon);
      47             :             }
      48             :             else
      49             :             {
      50           0 :                 aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
      51             :             }
      52           0 :         }
      53             : 
      54           0 :         return aRetval;
      55             :     }
      56             : }
      57             : 
      58             : namespace sw
      59             : {
      60             :     namespace overlay
      61             :     {
      62          55 :         drawinglayer::primitive2d::Primitive2DSequence OverlayRanges::createOverlayObjectPrimitive2DSequence()
      63             :         {
      64          55 :             const sal_uInt32 nCount(getRanges().size());
      65          55 :             drawinglayer::primitive2d::Primitive2DSequence aRetval;
      66          55 :             aRetval.realloc(nCount);
      67         131 :             for ( sal_uInt32 a = 0; a < nCount; ++a )
      68             :             {
      69          76 :                 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
      70         152 :                 const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
      71         152 :                 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
      72             :                     new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
      73             :                     basegfx::B2DPolyPolygon(aPolygon),
      74         228 :                     aRGBColor));
      75          76 :             }
      76             :             // embed all rectangles in transparent paint
      77         110 :             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
      78          55 :             const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() );
      79          55 :             const double fTransparence( nTransparence / 100.0 );
      80             :             const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
      81             :                 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
      82             :                 aRetval,
      83         110 :                 fTransparence));
      84             : 
      85          55 :             if ( mbShowSolidBorder )
      86             :             {
      87           0 :                 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
      88           0 :                 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
      89             :                 const drawinglayer::primitive2d::Primitive2DReference aOutline(
      90             :                     new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
      91             :                     aPolyPolygon,
      92           0 :                     aRGBColor));
      93             : 
      94           0 :                 aRetval.realloc(2);
      95           0 :                 aRetval[0] = aUnifiedTransparence;
      96           0 :                 aRetval[1] = aOutline;
      97             :             }
      98             :             else
      99             :             {
     100          55 :                 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
     101             :             }
     102             : 
     103         110 :             return aRetval;
     104             :         }
     105             : 
     106          38 :         /*static*/ OverlayRanges* OverlayRanges::CreateOverlayRange(
     107             :             SwView& rDocView,
     108             :             const Color& rColor,
     109             :             const std::vector< basegfx::B2DRange >& rRanges,
     110             :             const bool bShowSolidBorder )
     111             :         {
     112          38 :             OverlayRanges* pOverlayRanges = NULL;
     113             : 
     114          38 :             SdrView* pView = rDocView.GetDrawView();
     115          38 :             if ( pView != NULL )
     116             :             {
     117          38 :                 SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
     118          38 :                 rtl::Reference<sdr::overlay::OverlayManager> xTargetOverlay = pCandidate->GetOverlayManager();
     119             : 
     120          38 :                 if ( xTargetOverlay.is() )
     121             :                 {
     122          38 :                     pOverlayRanges = new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder );
     123          38 :                     xTargetOverlay->add( *pOverlayRanges );
     124          38 :                 }
     125             :             }
     126             : 
     127          38 :             return pOverlayRanges;
     128             :         }
     129             : 
     130          38 :         OverlayRanges::OverlayRanges(
     131             :             const Color& rColor,
     132             :             const std::vector< basegfx::B2DRange >& rRanges,
     133             :             const bool bShowSolidBorder )
     134             :             : sdr::overlay::OverlayObject( rColor )
     135             :             , maRanges( rRanges )
     136          38 :             , mbShowSolidBorder( bShowSolidBorder )
     137             :         {
     138             :             // no AA for highlight overlays
     139          38 :             allowAntiAliase(false);
     140          38 :         }
     141             : 
     142         114 :         OverlayRanges::~OverlayRanges()
     143             :         {
     144          38 :             if( getOverlayManager() )
     145             :             {
     146          38 :                 getOverlayManager()->remove(*this);
     147             :             }
     148          76 :         }
     149             : 
     150         223 :         void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
     151             :         {
     152         223 :             if(rNew != maRanges)
     153             :             {
     154          17 :                 maRanges = rNew;
     155          17 :                 objectChange();
     156             :             }
     157         223 :         }
     158             : 
     159           0 :         void OverlayRanges::ShowSolidBorder()
     160             :         {
     161           0 :             if ( !mbShowSolidBorder )
     162             :             {
     163           0 :                 mbShowSolidBorder = true;
     164           0 :                 objectChange();
     165             :             }
     166           0 :         }
     167             : 
     168         223 :         void OverlayRanges::HideSolidBorder()
     169             :         {
     170         223 :             if ( mbShowSolidBorder )
     171             :             {
     172           0 :                 mbShowSolidBorder = false;
     173           0 :                 objectChange();
     174             :             }
     175         223 :         }
     176             : 
     177             :     } // end of namespace overlay
     178             : } // end of namespace sdr
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10