LibreOffice Module svx (master)  1
tablehandles.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 
21 #include "tablehandles.hxx"
22 
23 #include <vcl/outdev.hxx>
24 #include <vcl/canvastools.hxx>
25 #include <vcl/ptrstyle.hxx>
29 #include <svx/sdrpagewindow.hxx>
30 #include <svx/sdrpaintwindow.hxx>
31 #include <svx/svdmrkv.hxx>
32 #include <svx/svdpagv.hxx>
37 
38 namespace sdr::table {
39 
40 namespace {
41 
42 class OverlayTableEdge : public sdr::overlay::OverlayObject
43 {
44 protected:
46  bool mbVisible;
47 
48  // geometry creation for OverlayObject
49  virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override;
50 
51 public:
52  OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible );
53 };
54 
55 }
56 
57 TableEdgeHdl::TableEdgeHdl( const Point& rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges )
58 : SdrHdl( rPnt, SdrHdlKind::User )
59 , mbHorizontal( bHorizontal )
60 , mnMin( nMin )
61 , mnMax( nMax )
62 , maEdges(nEdges)
63 {
64 }
65 
66 void TableEdgeHdl::SetEdge( sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState eState )
67 {
68  if( (nEdge >= 0) && (nEdge <= sal::static_int_cast<sal_Int32>(maEdges.size())) )
69  {
70  maEdges[nEdge].mnStart = nStart;
71  maEdges[nEdge].mnEnd = nEnd;
72  maEdges[nEdge].meState = eState;
73  }
74  else
75  {
76  OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
77  }
78 }
79 
81 {
82  if( mbHorizontal )
83  return PointerStyle::VSplit;
84  else
85  return PointerStyle::HSplit;
86 }
87 
88 sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const
89 {
90  return std::clamp( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin, mnMax );
91 }
92 
94 {
95  basegfx::B2DPolyPolygon aVisible;
96  basegfx::B2DPolyPolygon aInvisible;
97 
98  // create and return visible and non-visible parts for drag
99  getPolyPolygon(aVisible, aInvisible, &rDrag);
100  aVisible.append(aInvisible);
101 
102  return aVisible;
103 }
104 
106 {
107  // changed method to create visible and invisible partial polygons in one run in
108  // separate PolyPolygons; both kinds are used
109  basegfx::B2DPoint aOffset(aPos.X(), aPos.Y());
110  rVisible.clear();
111  rInvisible.clear();
112 
113  if( pDrag )
114  {
116  aOffset.set(eDragAxis, aOffset.get(eDragAxis) + GetValidDragOffset( *pDrag ));
117  }
118 
119  basegfx::B2DPoint aStart(aOffset), aEnd(aOffset);
121 
122  for( const TableEdge& aEdge : maEdges )
123  {
124  aStart.set(eAxis, aOffset.get(eAxis) + aEdge.mnStart);
125  aEnd.set(eAxis, aOffset.get(eAxis) + aEdge.mnEnd);
126 
127  basegfx::B2DPolygon aPolygon;
128  aPolygon.append( aStart );
129  aPolygon.append( aEnd );
130 
131  if(aEdge.meState == Visible)
132  {
133  rVisible.append(aPolygon);
134  }
135  else
136  {
137  rInvisible.append(aPolygon);
138  }
139  }
140 }
141 
143 {
145 
147  return;
148 
149  SdrMarkView* pView = pHdlList->GetView();
150  SdrPageView* pPageView = pView->GetSdrPageView();
151 
152  if(!pPageView)
153  return;
154 
155  basegfx::B2DPolyPolygon aVisible;
156  basegfx::B2DPolyPolygon aInvisible;
157 
158  // get visible and invisible parts
159  getPolyPolygon(aVisible, aInvisible, nullptr);
160 
161  if(!(aVisible.count() || aInvisible.count()))
162  return;
163 
164  for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
165  {
166  const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
167 
168  if(rPageWindow.GetPaintWindow().OutputToWindow())
169  {
171  if (xManager.is())
172  {
173  if(aVisible.count())
174  {
175  // create overlay object for visible parts
176  std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aVisible, true));
177 
178  // OVERLAYMANAGER
180  std::move(pOverlayObject),
181  rPageWindow.GetObjectContact(),
182  *xManager);
183  }
184 
185  if(aInvisible.count())
186  {
187  // also create overlay object for invisible parts to allow
188  // a standard HitTest using the primitives from that overlay object
189  // (see OverlayTableEdge implementation)
190  std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aInvisible, false));
191 
192  // OVERLAYMANAGER
194  std::move(pOverlayObject),
195  rPageWindow.GetObjectContact(),
196  *xManager);
197  }
198  }
199  }
200  }
201 }
202 
203 
204 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible )
205 : OverlayObject(COL_GRAY)
206 , maPolyPolygon( rPolyPolygon )
207 , mbVisible(bVisible)
208 {
209 }
210 
211 drawinglayer::primitive2d::Primitive2DContainer OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
212 {
214 
215  if(maPolyPolygon.count())
216  {
217  // Discussed with CL. Currently i will leave the transparence out since this
218  // a little bit expensive. We may check the look with drag polygons later
222  getBaseColor().getBColor()));
223 
224  if(mbVisible)
225  {
226  // visible, just return as sequence
227  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aReference };
228  }
229  else
230  {
231  // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
232  // overlay object
233  drawinglayer::primitive2d::Primitive2DContainer aSequence { aReference };
235  new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(std::move(aSequence)));
236  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aNewReference };
237  }
238  }
239 
240  return aRetval;
241 }
242 
243 
245  const tools::Rectangle& rRect,
246  bool bAnimate)
247 : SdrHdl(rRect.TopLeft(), SdrHdlKind::Move),
248  maRectangle(rRect),
249  mbAnimate(bAnimate)
250 {
251 }
252 
254 {
255  return PointerStyle::Move;
256 }
257 
258 // create marker for this kind
260 {
262 
264  return;
265 
266  SdrMarkView* pView = pHdlList->GetView();
267  SdrPageView* pPageView = pView->GetSdrPageView();
268 
269  if (!pPageView)
270  return;
271 
272  for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
273  {
274  const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
275 
276  if (rPageWindow.GetPaintWindow().OutputToWindow())
277  {
278  const rtl::Reference<sdr::overlay::OverlayManager>& xManager = rPageWindow.GetOverlayManager();
279 
280  if (xManager.is())
281  {
283  const Color aHilightColor(SvtOptionsDrawinglayer::getHilightColor());
284  const double fTransparence(SvtOptionsDrawinglayer::GetTransparentSelectionPercent() * 0.01);
285  // make animation dependent from text edit active, because for tables
286  // this handle is also used when text edit *is* active for it. This
287  // interferes too much concerning repaint stuff (at least as long as
288  // text edit is not yet on the overlay)
289 
290  OutputDevice& rOutDev = rPageWindow.GetPaintWindow().GetOutputDevice();
291  float fScaleFactor = rOutDev.GetDPIScaleFactor();
292  double fWidth = fScaleFactor * 6.0;
293 
294  std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(
296  aHilightColor, fTransparence,
297  fWidth, 0.0, 0.0, mbAnimate));
298 
299  // OVERLAYMANAGER
301  std::move(pOverlayObject),
302  rPageWindow.GetObjectContact(),
303  *xManager);
304  }
305  }
306  }
307 }
308 
309 
310 } // end of namespace sdr::table
311 
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
virtual void CreateB2dIAObject() override
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
SdrHdlList * pHdlList
Definition: svdhdl.hxx:138
virtual PointerStyle GetPointer() const override
tools::Long GetDX() const
Definition: svddrag.hxx:158
virtual void CreateB2dIAObject() override
SdrMarkView * GetView() const
Definition: svdhdl.hxx:453
void insertNewlyCreatedOverlayObjectForSdrHdl(std::unique_ptr< sdr::overlay::OverlayObject > pOverlayObject, const sdr::contact::ObjectContact &rObjectContact, sdr::overlay::OverlayManager &rOverlayManager)
Definition: svdhdl.cxx:1078
tools::Long GetDY() const
Definition: svddrag.hxx:159
SdrHdlKind
Definition: svdhdl.hxx:52
basegfx::B2DPolyPolygon getSpecialDragPoly(const SdrDragStat &rDrag) const
void SetEdge(sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState nState)
virtual PointerStyle GetPointer() const override
tools::Rectangle maRectangle
std::vector< TableEdge > maEdges
B2DPoint getMaximum() const
SdrPageWindow * GetPageWindow(sal_uInt32 nIndex) const
Definition: svdpagv.cxx:83
bool OutputToWindow() const
Point aPos
Definition: svdhdl.hxx:142
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_GRAY
const sdr::contact::ObjectContact & GetObjectContact() const
float GetDPIScaleFactor() const
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
void set(Axis2D eAxis, double fValue)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
void getPolyPolygon(basegfx::B2DPolyPolygon &rVisible, basegfx::B2DPolyPolygon &rInvisible, const SdrDragStat *pDrag) const
sal_uInt32 count() const
bool mbVisible
sal_Int32 GetValidDragOffset(const SdrDragStat &rDrag) const
SdrPaintWindow & GetPaintWindow() const
void GetRidOfIAObject()
Definition: svdhdl.cxx:396
B2DPoint getMinimum() const
basegfx::B2DPolyPolygon maPolyPolygon
bool areMarkHandlesHidden() const
Definition: svdmrkv.hxx:276
TableEdgeHdl(const Point &rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges)
PointerStyle
struct _ADOUser User
SdrPageView * GetSdrPageView() const
Definition: svdpntv.hxx:299
TableBorderHdl(const tools::Rectangle &rRect, bool bAnimate)
sal_uInt16 GetTransparentSelectionPercent()
OutputDevice & GetOutputDevice() const
sal_uInt32 PageWindowCount() const
Definition: svdpagv.hxx:89