Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / docvw / OverlayRanges.cxx
blob2b30f9543ebe9b3822a8360c3de2121e5aa1cb70
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 "OverlayRanges.hxx"
21 #include <view.hxx>
22 #include <svx/sdrpaintwindow.hxx>
23 #include <svx/svdview.hxx>
24 #include <svx/sdr/overlay/overlaymanager.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <basegfx/polygon/b2dpolygontools.hxx>
28 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
29 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
30 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
31 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
32 #include <svtools/optionsdrawinglayer.hxx>
34 namespace
36 // combine ranges geometrically to a single, ORed polygon
37 basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
39 const sal_uInt32 nCount(rRanges.size());
40 basegfx::B2DPolyPolygon aRetval;
42 for(sal_uInt32 a(0); a < nCount; a++)
44 const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
46 if(0 == a)
48 aRetval.append(aDiscretePolygon);
50 else
52 aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
56 return aRetval;
60 namespace sw::overlay
62 drawinglayer::primitive2d::Primitive2DContainer OverlayRanges::createOverlayObjectPrimitive2DSequence()
64 const sal_uInt32 nCount(getRanges().size());
65 drawinglayer::primitive2d::Primitive2DContainer aRetval;
66 aRetval.resize(nCount);
67 for ( sal_uInt32 a = 0; a < nCount; ++a )
69 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
70 const basegfx::B2DPolygon aPolygon(basegfx::utils::createPolygonFromRect(maRanges[a]));
71 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
72 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
73 basegfx::B2DPolyPolygon(aPolygon),
74 aRGBColor));
76 // embed all rectangles in transparent paint
77 const sal_uInt16 nTransparence( SvtOptionsDrawinglayer::GetTransparentSelectionPercent() );
78 const double fTransparence( nTransparence / 100.0 );
79 const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
80 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
81 std::move(aRetval),
82 fTransparence));
84 if ( mbShowSolidBorder )
86 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
87 basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
88 const drawinglayer::primitive2d::Primitive2DReference aOutline(
89 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
90 std::move(aPolyPolygon),
91 aRGBColor));
93 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence, aOutline };
95 else
97 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
100 return aRetval;
103 /*static*/ std::unique_ptr<OverlayRanges> OverlayRanges::CreateOverlayRange(
104 SwView const & rDocView,
105 const Color& rColor,
106 std::vector< basegfx::B2DRange >&& rRanges,
107 const bool bShowSolidBorder )
109 std::unique_ptr<OverlayRanges> pOverlayRanges;
111 SdrView* pView = rDocView.GetDrawView();
112 if ( pView != nullptr )
114 SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
115 const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
117 if ( xTargetOverlay.is() )
119 pOverlayRanges.reset(new sw::overlay::OverlayRanges( rColor, std::move(rRanges), bShowSolidBorder ));
120 xTargetOverlay->add( *pOverlayRanges );
124 return pOverlayRanges;
127 OverlayRanges::OverlayRanges(
128 const Color& rColor,
129 std::vector< basegfx::B2DRange >&& rRanges,
130 const bool bShowSolidBorder )
131 : sdr::overlay::OverlayObject( rColor )
132 , maRanges( std::move(rRanges) )
133 , mbShowSolidBorder( bShowSolidBorder )
135 // no AA for highlight overlays
136 allowAntiAliase(false);
139 OverlayRanges::~OverlayRanges()
141 if( getOverlayManager() )
143 getOverlayManager()->remove(*this);
147 void OverlayRanges::setRanges(std::vector< basegfx::B2DRange >&& rNew)
149 if(rNew != maRanges)
151 maRanges = std::move(rNew);
152 objectChange();
156 void OverlayRanges::ShowSolidBorder()
158 if ( !mbShowSolidBorder )
160 mbShowSolidBorder = true;
161 objectChange();
165 void OverlayRanges::HideSolidBorder()
167 if ( mbShowSolidBorder )
169 mbShowSolidBorder = false;
170 objectChange();
174 } // end of namespace sw::overlay
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */