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