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

Generated by: LCOV version 1.10