fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / overlay / overlayselection.cxx
blob7706bba9c4e2b7628f6cbbf9649e99ae7135380e
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 <drawinglayer/primitive2d/invertprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
29 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
30 #include <svx/sdr/overlay/overlaymanager.hxx>
32 //////////////////////////////////////////////////////////////////////////////
34 namespace sdr
36 namespace overlay
38 // combine rages geometrically to a single, ORed polygon
39 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::tools::createPolygonFromRect(rRanges[a]));
48 if(0 == a)
50 aRetval.append(aDiscretePolygon);
52 else
54 aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
58 return aRetval;
61 // check if wanted type OVERLAY_TRANSPARENT or OVERLAY_SOLID
62 // is possible. If not, fallback to invert mode (classic mode)
63 OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
65 if(OVERLAY_INVERT != aOverlayType)
67 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
69 if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
71 // not possible when switched off by user
72 return OVERLAY_INVERT;
74 else
76 const OutputDevice *pOut = Application::GetDefaultDevice();
78 if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
80 // not possible when in high contrast mode
81 return OVERLAY_INVERT;
84 if(!pOut->supportsOperation(OutDevSupport_TransparentRect))
86 // not possible when no fast transparence paint is supported on the system
87 return OVERLAY_INVERT;
92 return aOverlayType;
95 drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::createOverlayObjectPrimitive2DSequence()
97 drawinglayer::primitive2d::Primitive2DSequence aRetval;
98 const sal_uInt32 nCount(getRanges().size());
100 if(nCount)
102 // create range primitives
103 const bool bInvert(OVERLAY_INVERT == maLastOverlayType);
104 basegfx::BColor aRGBColor(getBaseColor().getBColor());
105 aRetval.realloc(nCount);
107 if(bInvert)
109 // force color to white for invert to get a full invert
110 aRGBColor = basegfx::BColor(1.0, 1.0, 1.0);
113 for(sal_uInt32 a(0);a < nCount; a++)
115 const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
116 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
117 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
118 basegfx::B2DPolyPolygon(aPolygon),
119 aRGBColor));
122 if(bInvert)
124 // embed all in invert primitive
125 const drawinglayer::primitive2d::Primitive2DReference aInvert(
126 new drawinglayer::primitive2d::InvertPrimitive2D(
127 aRetval));
128 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aInvert, 1);
130 else if(OVERLAY_TRANSPARENT == maLastOverlayType)
132 // embed all rectangles in transparent paint
133 const double fTransparence(mnLastTransparence / 100.0);
134 const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
135 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
136 aRetval,
137 fTransparence));
139 if(getBorder())
141 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
142 const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
143 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
144 aPolyPolygon,
145 aRGBColor));
147 // add both to result
148 aRetval.realloc(2);
149 aRetval[0] = aUnifiedTransparence;
150 aRetval[1] = aSelectionOutline;
152 else
154 // just add transparent part
155 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
160 return aRetval;
163 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 mbBorder(bBorder)
175 // no AA for selection overlays
176 allowAntiAliase(false);
179 OverlaySelection::~OverlaySelection()
181 if(getOverlayManager())
183 getOverlayManager()->remove(*this);
187 drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::getOverlayObjectPrimitive2DSequence() const
189 // get current values
190 const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
191 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
192 const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
194 if(getPrimitive2DSequence().hasElements())
196 if(aNewOverlayType != maLastOverlayType
197 || nNewTransparence != mnLastTransparence)
199 // conditions of last local decomposition have changed, delete
200 const_cast< OverlaySelection* >(this)->setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence());
204 if(!getPrimitive2DSequence().hasElements())
206 // remember new values
207 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
208 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
211 // call base implementation
212 return OverlayObject::getOverlayObjectPrimitive2DSequence();
215 void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
217 if(rNew != maRanges)
219 maRanges = rNew;
220 objectChange();
223 } // end of namespace overlay
224 } // end of namespace sdr
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */