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>
31 
32 namespace
33 {
34  // combine ranges geometrically to a single, ORed polygon
35  basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
36  {
37  const sal_uInt32 nCount(rRanges.size());
39 
40  for(sal_uInt32 a(0); a < nCount; a++)
41  {
42  const basegfx::B2DPolygon aDiscretePolygon(basegfx::utils::createPolygonFromRect(rRanges[a]));
43 
44  if(0 == a)
45  {
46  aRetval.append(aDiscretePolygon);
47  }
48  else
49  {
50  aRetval = basegfx::utils::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
51  }
52  }
53 
54  return aRetval;
55  }
56 }
57 
58 namespace sw
59 {
60  namespace 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 SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
78  const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() );
79  const double fTransparence( nTransparence / 100.0 );
80  const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
82  aRetval,
83  fTransparence));
84 
85  if ( mbShowSolidBorder )
86  {
87  const basegfx::BColor aRGBColor(getBaseColor().getBColor());
88  const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
91  aPolyPolygon,
92  aRGBColor));
93 
94  aRetval.resize(2);
95  aRetval[0] = aUnifiedTransparence;
96  aRetval[1] = aOutline;
97  }
98  else
99  {
100  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence };
101  }
102 
103  return aRetval;
104  }
105 
106  /*static*/ std::unique_ptr<OverlayRanges> OverlayRanges::CreateOverlayRange(
107  SwView const & rDocView,
108  const Color& rColor,
109  const std::vector< basegfx::B2DRange >& rRanges,
110  const bool bShowSolidBorder )
111  {
112  std::unique_ptr<OverlayRanges> pOverlayRanges;
113 
114  SdrView* pView = rDocView.GetDrawView();
115  if ( pView != nullptr )
116  {
117  SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
118  const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager();
119 
120  if ( xTargetOverlay.is() )
121  {
122  pOverlayRanges.reset(new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder ));
123  xTargetOverlay->add( *pOverlayRanges );
124  }
125  }
126 
127  return pOverlayRanges;
128  }
129 
131  const Color& rColor,
132  const std::vector< basegfx::B2DRange >& rRanges,
133  const bool bShowSolidBorder )
134  : sdr::overlay::OverlayObject( rColor )
135  , maRanges( rRanges )
136  , mbShowSolidBorder( bShowSolidBorder )
137  {
138  // no AA for highlight overlays
139  allowAntiAliase(false);
140  }
141 
143  {
144  if( getOverlayManager() )
145  {
146  getOverlayManager()->remove(*this);
147  }
148  }
149 
150  void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
151  {
152  if(rNew != maRanges)
153  {
154  maRanges = rNew;
155  objectChange();
156  }
157  }
158 
160  {
161  if ( !mbShowSolidBorder )
162  {
163  mbShowSolidBorder = true;
164  objectChange();
165  }
166  }
167 
169  {
170  if ( mbShowSolidBorder )
171  {
172  mbShowSolidBorder = false;
173  objectChange();
174  }
175  }
176 
177  } // end of namespace overlay
178 } // end of namespace sdr
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetTransparentSelectionPercent() const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
B2DPolyPolygon solvePolygonOperationOr(const B2DPolyPolygon &rCandidateA, const B2DPolyPolygon &rCandidateB)
virtual ~OverlayRanges() override
Dialog to specify the properties of date form field.
OverlayManager * getOverlayManager() const
const std::vector< basegfx::B2DRange > & getRanges() const
void remove(OverlayObject &rOverlayObject)
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
OverlayRanges(const Color &rColor, const std::vector< basegfx::B2DRange > &rRanges, const bool bShowSolidBorder)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:622
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
void setRanges(const std::vector< basegfx::B2DRange > &rNew)
Definition: view.hxx:146