LibreOffice Module sw (master)  1
OverlayRanges.cxx
Go to the documentation of this file.
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 "OverlayRanges.hxx"
21 #include <view.hxx>
22 #include <svx/sdrpaintwindow.hxx>
23 #include <svx/svdview.hxx>
33 
34 namespace
35 {
36  // combine ranges geometrically to a single, ORed polygon
37  basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
38  {
39  const sal_uInt32 nCount(rRanges.size());
41 
42  for(sal_uInt32 a(0); a < nCount; a++)
43  {
44  const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
45 
46  if(0 == a)
47  {
48  aRetval.append(aDiscretePolygon);
49  }
50  else
51  {
52  aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
53  }
54  }
55 
56  return aRetval;
57  }
58 }
59 
60 namespace sw::overlay
61 {
63  {
64  const sal_uInt32 nCount(getRanges().size());
66  aRetval.resize(nCount);
67  for ( sal_uInt32 a = 0; a < nCount; ++a )
68  {
69  const basegfx::BColor aRGBColor(getBaseColor().getBColor());
73  basegfx::B2DPolyPolygon(aPolygon),
74  aRGBColor));
75  }
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(
81  std::move(aRetval),
82  fTransparence));
83 
84  if ( mbShowSolidBorder )
85  {
86  const basegfx::BColor aRGBColor(getBaseColor().getBColor());
87  const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
90  aPolyPolygon,
91  aRGBColor));
92 
93  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence, aOutline };
94  }
95  else
96  {
97  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
98  }
99 
100  return aRetval;
101  }
102 
103  /*static*/ std::unique_ptr<OverlayRanges> OverlayRanges::CreateOverlayRange(
104  SwView const & rDocView,
105  const Color& rColor,
106  const std::vector< basegfx::B2DRange >& rRanges,
107  const bool bShowSolidBorder )
108  {
109  std::unique_ptr<OverlayRanges> pOverlayRanges;
110 
111  SdrView* pView = rDocView.GetDrawView();
112  if ( pView != nullptr )
113  {
114  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
115  const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
116 
117  if ( xTargetOverlay.is() )
118  {
119  pOverlayRanges.reset(new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder ));
120  xTargetOverlay->add( *pOverlayRanges );
121  }
122  }
123 
124  return pOverlayRanges;
125  }
126 
128  const Color& rColor,
129  const std::vector< basegfx::B2DRange >& rRanges,
130  const bool bShowSolidBorder )
131  : sdr::overlay::OverlayObject( rColor )
132  , maRanges( rRanges )
133  , mbShowSolidBorder( bShowSolidBorder )
134  {
135  // no AA for highlight overlays
136  allowAntiAliase(false);
137  }
138 
140  {
141  if( getOverlayManager() )
142  {
143  getOverlayManager()->remove(*this);
144  }
145  }
146 
147  void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
148  {
149  if(rNew != maRanges)
150  {
151  maRanges = rNew;
152  objectChange();
153  }
154  }
155 
157  {
158  if ( !mbShowSolidBorder )
159  {
160  mbShowSolidBorder = true;
161  objectChange();
162  }
163  }
164 
166  {
167  if ( mbShowSolidBorder )
168  {
169  mbShowSolidBorder = false;
170  objectChange();
171  }
172  }
173 
174 } // end of namespace sw::overlay
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
B2DPolyPolygon solvePolygonOperationOr(const B2DPolyPolygon &rCandidateA, const B2DPolyPolygon &rCandidateB)
virtual ~OverlayRanges() override
OverlayManager * getOverlayManager() const
const std::vector< basegfx::B2DRange > & getRanges() const
void remove(OverlayObject &rOverlayObject)
int nCount
uno_Any a
static std::unique_ptr< OverlayRanges > CreateOverlayRange(SwView const &rDocView, const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, const bool bShowSolidBorder)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
size
void allowAntiAliase(bool bNew)
std::vector< basegfx::B2DRange > maRanges
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
OverlayRanges(const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, const bool bShowSolidBorder)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:621
sal_uInt16 GetTransparentSelectionPercent()
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
void setRanges(const std::vector< basegfx::B2DRange > &rNew)
Definition: view.hxx:144