LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - OverlayRanges.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 45 68 66.2 %
Date: 2015-06-13 12:38:46 Functions: 9 11 81.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          95 :         drawinglayer::primitive2d::Primitive2DSequence OverlayRanges::createOverlayObjectPrimitive2DSequence()
      63             :         {
      64          95 :             const sal_uInt32 nCount(getRanges().size());
      65          95 :             drawinglayer::primitive2d::Primitive2DSequence aRetval;
      66          95 :             aRetval.realloc(nCount);
      67         247 :             for ( sal_uInt32 a = 0; a < nCount; ++a )
      68             :             {
      69         152 :                 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
      70         304 :                 const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
      71         304 :                 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
      72             :                     new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
      73             :                     basegfx::B2DPolyPolygon(aPolygon),
      74         456 :                     aRGBColor));
      75         152 :             }
      76             :             // embed all rectangles in transparent paint
      77         190 :             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
      78          95 :             const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() );
      79          95 :             const double fTransparence( nTransparence / 100.0 );
      80             :             const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
      81             :                 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
      82             :                 aRetval,
      83         190 :                 fTransparence));
      84             : 
      85          95 :             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          95 :                 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
     101             :             }
     102             : 
     103         190 :             return aRetval;
     104             :         }
     105             : 
     106          57 :         /*static*/ OverlayRanges* OverlayRanges::CreateOverlayRange(
     107             :             SwView& rDocView,
     108             :             const Color& rColor,
     109             :             const std::vector< basegfx::B2DRange >& rRanges,
     110             :             const bool bShowSolidBorder )
     111             :         {
     112          57 :             OverlayRanges* pOverlayRanges = NULL;
     113             : 
     114          57 :             SdrView* pView = rDocView.GetDrawView();
     115          57 :             if ( pView != NULL )
     116             :             {
     117          57 :                 SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
     118          57 :                 rtl::Reference<sdr::overlay::OverlayManager> xTargetOverlay = pCandidate->GetOverlayManager();
     119             : 
     120          57 :                 if ( xTargetOverlay.is() )
     121             :                 {
     122          57 :                     pOverlayRanges = new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder );
     123          57 :                     xTargetOverlay->add( *pOverlayRanges );
     124          57 :                 }
     125             :             }
     126             : 
     127          57 :             return pOverlayRanges;
     128             :         }
     129             : 
     130          57 :         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          57 :             , mbShowSolidBorder( bShowSolidBorder )
     137             :         {
     138             :             // no AA for highlight overlays
     139          57 :             allowAntiAliase(false);
     140          57 :         }
     141             : 
     142         171 :         OverlayRanges::~OverlayRanges()
     143             :         {
     144          57 :             if( getOverlayManager() )
     145             :             {
     146          57 :                 getOverlayManager()->remove(*this);
     147             :             }
     148         114 :         }
     149             : 
     150         548 :         void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
     151             :         {
     152         548 :             if(rNew != maRanges)
     153             :             {
     154          38 :                 maRanges = rNew;
     155          38 :                 objectChange();
     156             :             }
     157         548 :         }
     158             : 
     159           0 :         void OverlayRanges::ShowSolidBorder()
     160             :         {
     161           0 :             if ( !mbShowSolidBorder )
     162             :             {
     163           0 :                 mbShowSolidBorder = true;
     164           0 :                 objectChange();
     165             :             }
     166           0 :         }
     167             : 
     168         548 :         void OverlayRanges::HideSolidBorder()
     169             :         {
     170         548 :             if ( mbShowSolidBorder )
     171             :             {
     172           0 :                 mbShowSolidBorder = false;
     173           0 :                 objectChange();
     174             :             }
     175         548 :         }
     176             : 
     177             :     } // end of namespace overlay
     178         177 : } // end of namespace sdr
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11