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