merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / overlay / overlayselection.cxx
blobb60f1e66ce4000c03a3fb5fc8fbd5d2c37c9e2a2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: overlayline.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/overlay/overlayselection.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
37 #include <svtools/optionsdrawinglayer.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/outdev.hxx>
40 #include <drawinglayer/primitive2d/invertprimitive2d.hxx>
41 #include <drawinglayer/primitive2d/unifiedalphaprimitive2d.hxx>
42 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
43 #include <svx/sdr/overlay/overlaymanager.hxx>
45 //////////////////////////////////////////////////////////////////////////////
47 namespace sdr
49 namespace overlay
51 // combine rages geometrically to a single, ORed polygon
52 basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
54 const sal_uInt32 nCount(rRanges.size());
55 basegfx::B2DPolyPolygon aRetval;
57 for(sal_uInt32 a(0); a < nCount; a++)
59 const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
61 if(0 == a)
63 aRetval.append(aDiscretePolygon);
65 else
67 aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
71 return aRetval;
74 // check if wanted type OVERLAY_TRANSPARENT or OVERLAY_SOLID
75 // is possible. If not, fallback to invert mode (classic mode)
76 OverlayType impCheckPossibleOverlayType(OverlayType aOverlayType)
78 if(OVERLAY_INVERT != aOverlayType)
80 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
82 if(!aSvtOptionsDrawinglayer.IsTransparentSelection())
84 // not possible when switched off by user
85 return OVERLAY_INVERT;
87 else
89 const OutputDevice *pOut = Application::GetDefaultDevice();
91 if(pOut->GetSettings().GetStyleSettings().GetHighContrastMode())
93 // not possible when in high contrast mode
94 return OVERLAY_INVERT;
97 if(!pOut->supportsOperation(OutDevSupport_TransparentRect))
99 // not possible when no fast transparence paint is supported on the system
100 return OVERLAY_INVERT;
105 return aOverlayType;
108 drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::createOverlayObjectPrimitive2DSequence()
110 drawinglayer::primitive2d::Primitive2DSequence aRetval;
111 const sal_uInt32 nCount(getRanges().size());
113 if(nCount)
115 // create range primitives
116 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
117 aRetval.realloc(nCount);
119 for(sal_uInt32 a(0);a < nCount; a++)
121 const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
122 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
123 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
124 basegfx::B2DPolyPolygon(aPolygon),
125 aRGBColor));
128 if(OVERLAY_INVERT == maLastOverlayType)
130 // embed all in invert primitive
131 const drawinglayer::primitive2d::Primitive2DReference aInvert(
132 new drawinglayer::primitive2d::InvertPrimitive2D(
133 aRetval));
134 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aInvert, 1);
136 else if(OVERLAY_TRANSPARENT == maLastOverlayType)
138 // embed all rectangles in transparent paint
139 const double fTransparence(mnLastTransparence / 100.0);
140 const drawinglayer::primitive2d::Primitive2DReference aUnifiedAlpha(
141 new drawinglayer::primitive2d::UnifiedAlphaPrimitive2D(
142 aRetval,
143 fTransparence));
145 if(getBorder())
147 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
148 const drawinglayer::primitive2d::Primitive2DReference aSelectionOutline(
149 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
150 aPolyPolygon,
151 aRGBColor));
153 // add both to result
154 aRetval.realloc(2);
155 aRetval[0] = aUnifiedAlpha;
156 aRetval[1] = aSelectionOutline;
158 else
160 // just add transparent part
161 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedAlpha, 1);
166 return aRetval;
169 OverlaySelection::OverlaySelection(
170 OverlayType eType,
171 const Color& rColor,
172 const std::vector< basegfx::B2DRange >& rRanges,
173 bool bBorder)
174 : OverlayObject(rColor),
175 meOverlayType(eType),
176 maRanges(rRanges),
177 maLastOverlayType(eType),
178 mnLastTransparence(0),
179 mbBorder(bBorder)
181 // no AA for selection overlays
182 allowAntiAliase(false);
185 OverlaySelection::~OverlaySelection()
187 if(getOverlayManager())
189 getOverlayManager()->remove(*this);
193 drawinglayer::primitive2d::Primitive2DSequence OverlaySelection::getOverlayObjectPrimitive2DSequence() const
195 // get current values
196 const OverlayType aNewOverlayType(impCheckPossibleOverlayType(meOverlayType));
197 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
198 const sal_uInt16 nNewTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent());
200 if(getPrimitive2DSequence().hasElements())
202 if(aNewOverlayType != maLastOverlayType
203 || nNewTransparence != mnLastTransparence)
205 // conditions of last local decomposition have changed, delete
206 const_cast< OverlaySelection* >(this)->setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence());
210 if(!getPrimitive2DSequence().hasElements())
212 // remember new values
213 const_cast< OverlaySelection* >(this)->maLastOverlayType = aNewOverlayType;
214 const_cast< OverlaySelection* >(this)->mnLastTransparence = nNewTransparence;
217 // call base implementation
218 return OverlayObject::getOverlayObjectPrimitive2DSequence();
221 void OverlaySelection::setRanges(const std::vector< basegfx::B2DRange >& rNew)
223 if(rNew != maRanges)
225 maRanges = rNew;
226 objectChange();
229 } // end of namespace overlay
230 } // end of namespace sdr
232 //////////////////////////////////////////////////////////////////////////////
233 // eof