LCOV - code coverage report
Current view: top level - svx/source/sdr/overlay - overlayselection.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 52 78 66.7 %
Date: 2014-11-03 Functions: 9 10 90.0 %
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 <svx/sdr/overlay/overlayselection.hxx>
      21             : #include <basegfx/polygon/b2dpolygontools.hxx>
      22             : #include <basegfx/polygon/b2dpolygon.hxx>
      23             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      24             : #include <svtools/optionsdrawinglayer.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include <vcl/outdev.hxx>
      27             : #include <vcl/settings.hxx>
      28             : #include <drawinglayer/primitive2d/invertprimitive2d.hxx>
      29             : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
      30             : #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
      31             : #include <svx/sdr/overlay/overlaymanager.hxx>
      32             : 
      33             : 
      34             : 
      35             : namespace sdr
      36             : {
      37             :     namespace overlay
      38             :     {
      39             :         // combine rages geometrically to a single, ORed polygon
      40           0 :         basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
      41             :         {
      42           0 :             const sal_uInt32 nCount(rRanges.size());
      43           0 :             basegfx::B2DPolyPolygon aRetval;
      44             : 
      45           0 :             for(sal_uInt32 a(0); a < nCount; a++)
      46             :             {
      47           0 :                 const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
      48             : 
      49           0 :                 if(0 == a)
      50             :                 {
      51           0 :                     aRetval.append(aDiscretePolygon);
      52             :                 }
      53             :                 else
      54             :                 {
      55           0 :                     aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
      56             :                 }
      57           0 :             }
      58             : 
      59           0 :             return aRetval;
      60             :         }
      61             : 
      62             :         // check if wanted type OVERLAY_TRANSPARENT or OVERLAY_SOLID
      63             :         // is possible. If not, fallback to invert mode (classic mode)
      64       12902 :         OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
      65             :         {
      66       12902 :             if(OVERLAY_INVERT != aOverlayType)
      67             :             {
      68       12902 :                 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
      69             : 
      70       12902 :                 if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
      71             :                 {
      72             :                     // not possible when switched off by user
      73           0 :                     return OVERLAY_INVERT;
      74             :                 }
      75             :                 else
      76             :                 {
      77       12902 :                     const OutputDevice *pOut = Application::GetDefaultDevice();
      78             : 
      79       12902 :                     if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
      80             :                     {
      81             :                         // not possible when in high contrast mode
      82           0 :                         return  OVERLAY_INVERT;
      83             :                     }
      84             : 
      85       12902 :                     if(!pOut->SupportsOperation(OutDevSupport_TransparentRect))
      86             :                     {
      87             :                         // not possible when no fast transparence paint is supported on the system
      88       12902 :                         return OVERLAY_INVERT;
      89             :                     }
      90           0 :                 }
      91             :             }
      92             : 
      93           0 :             return aOverlayType;
      94             :         }
      95             : 
      96        7904 :         drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::createOverlayObjectPrimitive2DSequence()
      97             :         {
      98        7904 :             drawinglayer::primitive2d::Primitive2DSequence aRetval;
      99        7904 :             const sal_uInt32 nCount(getRanges().size());
     100             : 
     101        7904 :             if(nCount)
     102             :             {
     103             :                 // create range primitives
     104        7904 :                 const bool bInvert(OVERLAY_INVERT == maLastOverlayType);
     105        7904 :                 basegfx::BColor aRGBColor(getBaseColor().getBColor());
     106        7904 :                 aRetval.realloc(nCount);
     107             : 
     108        7904 :                 if(bInvert)
     109             :                 {
     110             :                     // force color to white for invert to get a full invert
     111        7904 :                     aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
     112             :                 }
     113             : 
     114       27934 :                 for(sal_uInt32 a(0);a < nCount; a++)
     115             :                 {
     116       20030 :                     const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
     117       40060 :                     aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
     118             :                         new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
     119             :                             basegfx::B2DPolyPolygon(aPolygon),
     120       60090 :                             aRGBColor));
     121       20030 :                 }
     122             : 
     123        7904 :                 if(bInvert)
     124             :                 {
     125             :                     // embed all in invert primitive
     126             :                     const drawinglayer::primitive2d::Primitive2DReference aInvert(
     127             :                         new drawinglayer::primitive2d::InvertPrimitive2D(
     128        7904 :                             aRetval));
     129        7904 :                     aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aInvert, 1);
     130             :                 }
     131           0 :                 else if(OVERLAY_TRANSPARENT == maLastOverlayType)
     132             :                 {
     133             :                     // embed all rectangles in transparent paint
     134           0 :                     const double fTransparence(mnLastTransparence / 100.0);
     135             :                     const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
     136             :                         new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
     137             :                             aRetval,
     138           0 :                             fTransparence));
     139             : 
     140           0 :                     if(getBorder())
     141             :                     {
     142           0 :                         const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
     143             :                         const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
     144             :                             new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
     145             :                                 aPolyPolygon,
     146           0 :                                 aRGBColor));
     147             : 
     148             :                         // add both to result
     149           0 :                         aRetval.realloc(2);
     150           0 :                         aRetval[0] = aUnifiedTransparence;
     151           0 :                         aRetval[1] = aSelectionOutline;
     152             :                     }
     153             :                     else
     154             :                     {
     155             :                         // just add transparent part
     156           0 :                         aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
     157           0 :                     }
     158        7904 :                 }
     159             :             }
     160             : 
     161        7904 :             return aRetval;
     162             :         }
     163             : 
     164        7880 :         OverlaySelection::OverlaySelection(
     165             :             OverlayType eType,
     166             :             const Color& rColor,
     167             :             const std::vector< basegfx::B2DRange >& rRanges,
     168             :             bool bBorder)
     169             :         :   OverlayObject(rColor),
     170             :             meOverlayType(eType),
     171             :             maRanges(rRanges),
     172             :             maLastOverlayType(eType),
     173             :             mnLastTransparence(0),
     174        7880 :             mbBorder(bBorder)
     175             :         {
     176             :             // no AA for selection overlays
     177        7880 :             allowAntiAliase(false);
     178        7880 :         }
     179             : 
     180       23640 :         OverlaySelection::~OverlaySelection()
     181             :         {
     182        7880 :             if(getOverlayManager())
     183             :             {
     184         186 :                 getOverlayManager()->remove(*this);
     185             :             }
     186       15760 :         }
     187             : 
     188       12902 :         drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::getOverlayObjectPrimitive2DSequence() const
     189             :         {
     190             :             // get current values
     191       12902 :                const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
     192       12902 :             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     193       12902 :             const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
     194             : 
     195       12902 :             if(getPrimitive2DSequence().hasElements())
     196             :             {
     197        4998 :                 if(aNewOverlayType != maLastOverlayType
     198        4998 :                     || nNewTransparence != mnLastTransparence)
     199             :                 {
     200             :                     // conditions of last local decomposition have changed, delete
     201           0 :                     const_cast< OverlaySelection* >(this)->setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence());
     202             :                 }
     203             :             }
     204             : 
     205       12902 :             if(!getPrimitive2DSequence().hasElements())
     206             :             {
     207             :                 // remember new values
     208        7904 :                 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
     209        7904 :                 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
     210             :             }
     211             : 
     212             :             // call base implementation
     213       12902 :             return OverlayObject::getOverlayObjectPrimitive2DSequence();
     214             :         }
     215             : 
     216         434 :         void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
     217             :         {
     218         434 :             if(rNew != maRanges)
     219             :             {
     220          24 :                 maRanges = rNew;
     221          24 :                 objectChange();
     222             :             }
     223         434 :         }
     224             :     } // end of namespace overlay
     225         651 : } // end of namespace sdr
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10