Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / overlay / overlayselection.cxx
blob14f49046893e8c394a4705180eb58a4640934291
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 namespace sdr
36 namespace overlay
38 // combine rages geometrically to a single, ORed polygon
39 static basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
41 const sal_uInt32 nCount(rRanges.size());
42 basegfx::B2DPolyPolygon aRetval;
44 for(sal_uInt32 a(0); a < nCount; a++)
46 const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
48 if(0 == a)
50 aRetval.append(aDiscretePolygon);
52 else
54 aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
58 return aRetval;
61 // check if wanted type OverlayType::Transparent or OverlayType::Solid
62 // is possible. If not, fallback to invert mode (classic mode)
63 static OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
65 if(OverlayType::Invert != aOverlayType)
67 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
69 if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
71 // not possible when switched off by user
72 return OverlayType::Invert;
74 else if (const OutputDevice* pOut = Application::GetDefaultDevice())
77 if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
79 // not possible when in high contrast mode
80 return OverlayType::Invert;
83 if(!pOut->SupportsOperation(OutDevSupportType::TransparentRect))
85 // not possible when no fast transparence paint is supported on the system
86 return OverlayType::Invert;
91 return aOverlayType;
94 drawinglayer::primitive2d::Primitive2DContainer OverlaySelection::createOverlayObjectPrimitive2DSequence()
96 drawinglayer::primitive2d::Primitive2DContainer aRetval;
97 const sal_uInt32 nCount(getRanges().size());
99 if(nCount)
101 // create range primitives
102 const bool bInvert(OverlayType::Invert == maLastOverlayType);
103 basegfx::BColor aRGBColor(getBaseColor().getBColor());
104 aRetval.resize(nCount);
106 if(bInvert)
108 // force color to white for invert to get a full invert
109 aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
112 for(sal_uInt32 a(0);a < nCount; a++)
114 const basegfx::B2DPolygon aPolygon(basegfx::utils::createPolygonFromRect(maRanges[a]));
115 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
116 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
117 basegfx::B2DPolyPolygon(aPolygon),
118 aRGBColor));
121 if(bInvert)
123 // embed all in invert primitive
124 const drawinglayer::primitive2d::Primitive2DReference aInvert(
125 new drawinglayer::primitive2d::InvertPrimitive2D(
126 aRetval));
127 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aInvert };
129 else if(OverlayType::Transparent == maLastOverlayType)
131 // embed all rectangles in transparent paint
132 const double fTransparence(mnLastTransparence / 100.0);
133 const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
134 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
135 aRetval,
136 fTransparence));
138 if(mbBorder)
140 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
141 const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
142 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
143 aPolyPolygon,
144 aRGBColor));
146 // add both to result
147 aRetval.resize(2);
148 aRetval[0] = aUnifiedTransparence;
149 aRetval[1] = aSelectionOutline;
151 else
153 // just add transparent part
154 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
159 return aRetval;
162 OverlaySelection::OverlaySelection(
163 OverlayType eType,
164 const Color& rColor,
165 const std::vector< basegfx::B2DRange >& rRanges,
166 bool bBorder)
167 : OverlayObject(rColor),
168 meOverlayType(eType),
169 maRanges(rRanges),
170 maLastOverlayType(eType),
171 mnLastTransparence(0),
172 mbBorder(bBorder)
174 // no AA for selection overlays
175 allowAntiAliase(false);
178 OverlaySelection::~OverlaySelection()
180 if(getOverlayManager())
182 getOverlayManager()->remove(*this);
186 drawinglayer::primitive2d::Primitive2DContainer OverlaySelection::getOverlayObjectPrimitive2DSequence() const
188 // get current values
189 const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
190 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
191 const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
193 if(!getPrimitive2DSequence().empty())
195 if(aNewOverlayType != maLastOverlayType
196 || nNewTransparence != mnLastTransparence)
198 // conditions of last local decomposition have changed, delete
199 const_cast< OverlaySelection* >(this)->resetPrimitive2DSequence();
203 if(getPrimitive2DSequence().empty())
205 // remember new values
206 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
207 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
210 // call base implementation
211 return OverlayObject::getOverlayObjectPrimitive2DSequence();
214 void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
216 if(rNew != maRanges)
218 maRanges = rNew;
219 objectChange();
222 } // end of namespace overlay
223 } // end of namespace sdr
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */