LCOV - code coverage report
Current view: top level - svx/source/sdr/overlay - overlayselection.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 77 0.0 %
Date: 2014-04-14 Functions: 0 8 0.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           0 :         OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
      65             :         {
      66           0 :             if(OVERLAY_INVERT != aOverlayType)
      67             :             {
      68           0 :                 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
      69             : 
      70           0 :                 if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
      71             :                 {
      72             :                     // not possible when switched off by user
      73           0 :                     return OVERLAY_INVERT;
      74             :                 }
      75             :                 else
      76             :                 {
      77           0 :                     const OutputDevice *pOut = Application::GetDefaultDevice();
      78             : 
      79           0 :                     if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
      80             :                     {
      81             :                         // not possible when in high contrast mode
      82           0 :                         return  OVERLAY_INVERT;
      83             :                     }
      84             : 
      85           0 :                     if(!pOut->supportsOperation(OutDevSupport_TransparentRect))
      86             :                     {
      87             :                         // not possible when no fast transparence paint is supported on the system
      88           0 :                         return OVERLAY_INVERT;
      89             :                     }
      90           0 :                 }
      91             :             }
      92             : 
      93           0 :             return aOverlayType;
      94             :         }
      95             : 
      96           0 :         drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::createOverlayObjectPrimitive2DSequence()
      97             :         {
      98           0 :             drawinglayer::primitive2d::Primitive2DSequence aRetval;
      99           0 :             const sal_uInt32 nCount(getRanges().size());
     100             : 
     101           0 :             if(nCount)
     102             :             {
     103             :                 // create range primitives
     104           0 :                 const bool bInvert(OVERLAY_INVERT == maLastOverlayType);
     105           0 :                 basegfx::BColor aRGBColor(getBaseColor().getBColor());
     106           0 :                 aRetval.realloc(nCount);
     107             : 
     108           0 :                 if(bInvert)
     109             :                 {
     110             :                     // force color to white for invert to get a full invert
     111           0 :                     aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
     112             :                 }
     113             : 
     114           0 :                 for(sal_uInt32 a(0);a < nCount; a++)
     115             :                 {
     116           0 :                     const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
     117           0 :                     aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
     118             :                         new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
     119             :                             basegfx::B2DPolyPolygon(aPolygon),
     120           0 :                             aRGBColor));
     121           0 :                 }
     122             : 
     123           0 :                 if(bInvert)
     124             :                 {
     125             :                     // embed all in invert primitive
     126             :                     const drawinglayer::primitive2d::Primitive2DReference aInvert(
     127             :                         new drawinglayer::primitive2d::InvertPrimitive2D(
     128           0 :                             aRetval));
     129           0 :                     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           0 :                 }
     159             :             }
     160             : 
     161           0 :             return aRetval;
     162             :         }
     163             : 
     164           0 :         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           0 :             mbBorder(bBorder)
     175             :         {
     176             :             // no AA for selection overlays
     177           0 :             allowAntiAliase(false);
     178           0 :         }
     179             : 
     180           0 :         OverlaySelection::~OverlaySelection()
     181             :         {
     182           0 :             if(getOverlayManager())
     183             :             {
     184           0 :                 getOverlayManager()->remove(*this);
     185             :             }
     186           0 :         }
     187             : 
     188           0 :         drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::getOverlayObjectPrimitive2DSequence() const
     189             :         {
     190             :             // get current values
     191           0 :                const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
     192           0 :             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     193           0 :             const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
     194             : 
     195           0 :             if(getPrimitive2DSequence().hasElements())
     196             :             {
     197           0 :                 if(aNewOverlayType != maLastOverlayType
     198           0 :                     || 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           0 :             if(!getPrimitive2DSequence().hasElements())
     206             :             {
     207             :                 // remember new values
     208           0 :                 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
     209           0 :                 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
     210             :             }
     211             : 
     212             :             // call base implementation
     213           0 :             return OverlayObject::getOverlayObjectPrimitive2DSequence();
     214             :         }
     215             : 
     216           0 :         void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
     217             :         {
     218           0 :             if(rNew != maRanges)
     219             :             {
     220           0 :                 maRanges = rNew;
     221           0 :                 objectChange();
     222             :             }
     223           0 :         }
     224             :     } // end of namespace overlay
     225             : } // end of namespace sdr
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10