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/svapp.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/canvastools.hxx>
26 #include <vcl/hatch.hxx>
27 #include <vcl/ptrstyle.hxx>
34 #include <svx/sdrpagewindow.hxx>
35 #include <svx/sdrpaintwindow.hxx>
36 #include <svx/svdmrkv.hxx>
37 #include <svx/svdpagv.hxx>
41 
42 namespace sdr { namespace table {
43 
44 namespace {
45 
46 class OverlayTableEdge : public sdr::overlay::OverlayObject
47 {
48 protected:
50  bool const mbVisible;
51 
52  // geometry creation for OverlayObject
53  virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override;
54 
55 public:
56  OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible );
57 };
58 
59 }
60 
61 TableEdgeHdl::TableEdgeHdl( const Point& rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges )
62 : SdrHdl( rPnt, SdrHdlKind::User )
63 , mbHorizontal( bHorizontal )
64 , mnMin( nMin )
65 , mnMax( nMax )
66 , maEdges(nEdges)
67 {
68 }
69 
70 void TableEdgeHdl::SetEdge( sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState eState )
71 {
72  if( (nEdge >= 0) && (nEdge <= sal::static_int_cast<sal_Int32>(maEdges.size())) )
73  {
74  maEdges[nEdge].mnStart = nStart;
75  maEdges[nEdge].mnEnd = nEnd;
76  maEdges[nEdge].meState = eState;
77  }
78  else
79  {
80  OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
81  }
82 }
83 
85 {
86  if( mbHorizontal )
87  return PointerStyle::VSplit;
88  else
89  return PointerStyle::HSplit;
90 }
91 
92 sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const
93 {
94  return std::min( std::max( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin ), mnMax );
95 }
96 
98 {
99  basegfx::B2DPolyPolygon aVisible;
100  basegfx::B2DPolyPolygon aInvisible;
101 
102  // create and return visible and non-visible parts for drag
103  getPolyPolygon(aVisible, aInvisible, &rDrag);
104  aVisible.append(aInvisible);
105 
106  return aVisible;
107 }
108 
110 {
111  // changed method to create visible and invisible partial polygons in one run in
112  // separate PolyPolygons; both kinds are used
113  basegfx::B2DPoint aOffset(aPos.X(), aPos.Y());
114  rVisible.clear();
115  rInvisible.clear();
116 
117  if( pDrag )
118  {
119  int n = mbHorizontal ? 1 : 0;
120  aOffset[n] = aOffset[n] + GetValidDragOffset( *pDrag );
121  }
122 
123  basegfx::B2DPoint aStart(aOffset), aEnd(aOffset);
124  int nPos = mbHorizontal ? 0 : 1;
125 
126  for( const TableEdge& aEdge : maEdges )
127  {
128  aStart[nPos] = aOffset[nPos] + aEdge.mnStart;
129  aEnd[nPos] = aOffset[nPos] + aEdge.mnEnd;
130 
131  basegfx::B2DPolygon aPolygon;
132  aPolygon.append( aStart );
133  aPolygon.append( aEnd );
134 
135  if(aEdge.meState == Visible)
136  {
137  rVisible.append(aPolygon);
138  }
139  else
140  {
141  rInvisible.append(aPolygon);
142  }
143  }
144 }
145 
147 {
149 
151  {
152  SdrMarkView* pView = pHdlList->GetView();
153  SdrPageView* pPageView = pView->GetSdrPageView();
154 
155  if(pPageView)
156  {
157  basegfx::B2DPolyPolygon aVisible;
158  basegfx::B2DPolyPolygon aInvisible;
159 
160  // get visible and invisible parts
161  getPolyPolygon(aVisible, aInvisible, nullptr);
162 
163  if(aVisible.count() || aInvisible.count())
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 }
206 
207 
208 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible )
209 : OverlayObject(COL_GRAY)
210 , maPolyPolygon( rPolyPolygon )
211 , mbVisible(bVisible)
212 {
213 }
214 
215 drawinglayer::primitive2d::Primitive2DContainer OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
216 {
218 
219  if(maPolyPolygon.count())
220  {
221  // Discussed with CL. Currently i will leave the transparence out since this
222  // a little bit expensive. We may check the look with drag polygons later
226  getBaseColor().getBColor()));
227 
228  if(mbVisible)
229  {
230  // visible, just return as sequence
231  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aReference };
232  }
233  else
234  {
235  // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
236  // overlay object
237  const drawinglayer::primitive2d::Primitive2DContainer aSequence { aReference };
240  aRetval = drawinglayer::primitive2d::Primitive2DContainer { aNewReference };
241  }
242  }
243 
244  return aRetval;
245 }
246 
247 
249  const tools::Rectangle& rRect,
250  bool bAnimate)
251 : SdrHdl(rRect.TopLeft(), SdrHdlKind::Move),
252  maRectangle(rRect),
253  mbAnimate(bAnimate)
254 {
255 }
256 
258 {
259  return PointerStyle::Move;
260 }
261 
262 // create marker for this kind
264 {
266 
268  {
269  SdrMarkView* pView = pHdlList->GetView();
270  SdrPageView* pPageView = pView->GetSdrPageView();
271 
272  if (!pPageView)
273  return;
274 
275  for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
276  {
277  const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
278 
279  if (rPageWindow.GetPaintWindow().OutputToWindow())
280  {
281  const rtl::Reference<sdr::overlay::OverlayManager>& xManager = rPageWindow.GetOverlayManager();
282 
283  if (xManager.is())
284  {
286  const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
287  const Color aHilightColor(aSvtOptionsDrawinglayer.getHilightColor());
288  const double fTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01);
289  // make animation dependent from text edit active, because for tables
290  // this handle is also used when text edit *is* active for it. This
291  // interferes too much concerning repaint stuff (at least as long as
292  // text edit is not yet on the overlay)
293  const bool bAnimate = getAnimate();
294 
295  OutputDevice& rOutDev = rPageWindow.GetPaintWindow().GetOutputDevice();
296  float fScaleFactor = rOutDev.GetDPIScaleFactor();
297  double fWidth = fScaleFactor * 6.0;
298 
299  std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(
301  aHilightColor, fTransparence,
302  fWidth, 0.0, 0.0, bAnimate));
303 
304  // OVERLAYMANAGER
306  std::move(pOverlayObject),
307  rPageWindow.GetObjectContact(),
308  *xManager);
309  }
310  }
311  }
312  }
313 }
314 
315 
316 } // end of namespace table
317 } // end of namespace sdr
318 
319 /* 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:1083
sal_uInt16 GetTransparentSelectionPercent() const
SdrHdlKind
Definition: svdhdl.hxx:52
basegfx::B2DPolyPolygon getSpecialDragPoly(const SdrDragStat &rDrag) const
sal_Int64 n
void SetEdge(sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState nState)
virtual PointerStyle GetPointer() const override
constexpr::Color COL_GRAY(0x80, 0x80, 0x80)
B2DPoint getMaximum() const
basegfx::B2DPolyPolygon const maPolyPolygon
SdrPageWindow * GetPageWindow(sal_uInt32 nIndex) const
Definition: svdpagv.cxx:93
long GetDX() const
Definition: svddrag.hxx:148
bool OutputToWindow() const
Point aPos
Definition: svdhdl.hxx:142
const sdr::contact::ObjectContact & GetObjectContact() const
long X() 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)
void getPolyPolygon(basegfx::B2DPolyPolygon &rVisible, basegfx::B2DPolyPolygon &rInvisible, const SdrDragStat *pDrag) const
sal_uInt32 count() const
sal_Int32 GetValidDragOffset(const SdrDragStat &rDrag) const
SdrPaintWindow & GetPaintWindow() const
void GetRidOfIAObject()
Definition: svdhdl.cxx:400
B2DPoint getMinimum() const
bool const mbVisible
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
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)
tools::Rectangle const maRectangle
OutputDevice & GetOutputDevice() const
long Y() const
sal_uInt16 nPos
Color getHilightColor() const
sal_uInt32 PageWindowCount() const
Definition: svdpagv.hxx:96