Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / table / tablehandles.cxx
blob4322bf2ea6fe8cfa2179023882443208afd969f4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "tablehandles.hxx"
23 #include <vcl/outdev.hxx>
24 #include <vcl/canvastools.hxx>
25 #include <vcl/ptrstyle.hxx>
26 #include <basegfx/polygon/b2dpolygon.hxx>
27 #include <svx/sdr/overlay/overlayobject.hxx>
28 #include <svx/sdr/overlay/overlaymanager.hxx>
29 #include <svx/sdrpagewindow.hxx>
30 #include <svx/sdrpaintwindow.hxx>
31 #include <svx/svdmrkv.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
34 #include <sdr/overlay/overlayrectangle.hxx>
35 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
37 namespace sdr::table {
39 namespace {
41 class OverlayTableEdge : public sdr::overlay::OverlayObject
43 protected:
44 basegfx::B2DPolyPolygon maPolyPolygon;
45 bool mbVisible;
47 // geometry creation for OverlayObject
48 virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override;
50 public:
51 OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible );
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)
65 void TableEdgeHdl::SetEdge( sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState eState )
67 if( (nEdge >= 0) && (nEdge <= sal::static_int_cast<sal_Int32>(maEdges.size())) )
69 maEdges[nEdge].mnStart = nStart;
70 maEdges[nEdge].mnEnd = nEnd;
71 maEdges[nEdge].meState = eState;
73 else
75 OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
79 PointerStyle TableEdgeHdl::GetPointer() const
81 if( mbHorizontal )
82 return PointerStyle::VSplit;
83 else
84 return PointerStyle::HSplit;
87 sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const
89 return std::clamp( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin, mnMax );
92 basegfx::B2DPolyPolygon TableEdgeHdl::getSpecialDragPoly(const SdrDragStat& rDrag) const
94 basegfx::B2DPolyPolygon aVisible;
95 basegfx::B2DPolyPolygon aInvisible;
97 // create and return visible and non-visible parts for drag
98 getPolyPolygon(aVisible, aInvisible, &rDrag);
99 aVisible.append(aInvisible);
101 return aVisible;
104 void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon& rVisible, basegfx::B2DPolyPolygon& rInvisible, const SdrDragStat* pDrag) const
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();
112 if( pDrag )
114 basegfx::Axis2D eDragAxis = mbHorizontal ? basegfx::Axis2D::Y : basegfx::Axis2D::X;
115 aOffset.set(eDragAxis, aOffset.get(eDragAxis) + GetValidDragOffset( *pDrag ));
118 basegfx::B2DPoint aStart(aOffset), aEnd(aOffset);
119 basegfx::Axis2D eAxis = mbHorizontal ? basegfx::Axis2D::X : basegfx::Axis2D::Y;
121 for( const TableEdge& aEdge : maEdges )
123 aStart.set(eAxis, aOffset.get(eAxis) + aEdge.mnStart);
124 aEnd.set(eAxis, aOffset.get(eAxis) + aEdge.mnEnd);
126 basegfx::B2DPolygon aPolygon;
127 aPolygon.append( aStart );
128 aPolygon.append( aEnd );
130 if(aEdge.meState == Visible)
132 rVisible.append(aPolygon);
134 else
136 rInvisible.append(aPolygon);
141 void TableEdgeHdl::CreateB2dIAObject()
143 GetRidOfIAObject();
145 if(!pHdlList || !pHdlList->GetView() || pHdlList->GetView()->areMarkHandlesHidden())
146 return;
148 SdrMarkView* pView = pHdlList->GetView();
149 SdrPageView* pPageView = pView->GetSdrPageView();
151 if(!pPageView)
152 return;
154 basegfx::B2DPolyPolygon aVisible;
155 basegfx::B2DPolyPolygon aInvisible;
157 // get visible and invisible parts
158 getPolyPolygon(aVisible, aInvisible, nullptr);
160 if(!(aVisible.count() || aInvisible.count()))
161 return;
163 for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
165 const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
167 if(rPageWindow.GetPaintWindow().OutputToWindow())
169 const rtl::Reference< sdr::overlay::OverlayManager >& xManager = rPageWindow.GetOverlayManager();
170 if (xManager.is())
172 if(aVisible.count())
174 // create overlay object for visible parts
175 std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aVisible, true));
177 // OVERLAYMANAGER
178 insertNewlyCreatedOverlayObjectForSdrHdl(
179 std::move(pOverlayObject),
180 rPageWindow.GetObjectContact(),
181 *xManager);
184 if(aInvisible.count())
186 // also create overlay object for invisible parts to allow
187 // a standard HitTest using the primitives from that overlay object
188 // (see OverlayTableEdge implementation)
189 std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aInvisible, false));
191 // OVERLAYMANAGER
192 insertNewlyCreatedOverlayObjectForSdrHdl(
193 std::move(pOverlayObject),
194 rPageWindow.GetObjectContact(),
195 *xManager);
203 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon& rPolyPolygon, bool bVisible )
204 : OverlayObject(COL_GRAY)
205 , maPolyPolygon( rPolyPolygon )
206 , mbVisible(bVisible)
210 drawinglayer::primitive2d::Primitive2DContainer OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
212 drawinglayer::primitive2d::Primitive2DContainer aRetval;
214 if(maPolyPolygon.count())
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
218 const drawinglayer::primitive2d::Primitive2DReference aReference(
219 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
220 maPolyPolygon,
221 getBaseColor().getBColor()));
223 if(mbVisible)
225 // visible, just return as sequence
226 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aReference };
228 else
230 // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
231 // overlay object
232 const drawinglayer::primitive2d::Primitive2DContainer aSequence { aReference };
233 const drawinglayer::primitive2d::Primitive2DReference aNewReference(
234 new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(aSequence));
235 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aNewReference };
239 return aRetval;
243 TableBorderHdl::TableBorderHdl(
244 const tools::Rectangle& rRect,
245 bool bAnimate)
246 : SdrHdl(rRect.TopLeft(), SdrHdlKind::Move),
247 maRectangle(rRect),
248 mbAnimate(bAnimate)
252 PointerStyle TableBorderHdl::GetPointer() const
254 return PointerStyle::Move;
257 // create marker for this kind
258 void TableBorderHdl::CreateB2dIAObject()
260 GetRidOfIAObject();
262 if (!pHdlList || !pHdlList->GetView() || pHdlList->GetView()->areMarkHandlesHidden())
263 return;
265 SdrMarkView* pView = pHdlList->GetView();
266 SdrPageView* pPageView = pView->GetSdrPageView();
268 if (!pPageView)
269 return;
271 for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
273 const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
275 if (rPageWindow.GetPaintWindow().OutputToWindow())
277 const rtl::Reference<sdr::overlay::OverlayManager>& xManager = rPageWindow.GetOverlayManager();
279 if (xManager.is())
281 const basegfx::B2DRange aRange = vcl::unotools::b2DRectangleFromRectangle(maRectangle);
282 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
283 const Color aHilightColor(aSvtOptionsDrawinglayer.getHilightColor());
284 const double fTransparence(aSvtOptionsDrawinglayer.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)
290 OutputDevice& rOutDev = rPageWindow.GetPaintWindow().GetOutputDevice();
291 float fScaleFactor = rOutDev.GetDPIScaleFactor();
292 double fWidth = fScaleFactor * 6.0;
294 std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(
295 new sdr::overlay::OverlayRectangle(aRange.getMinimum(), aRange.getMaximum(),
296 aHilightColor, fTransparence,
297 fWidth, 0.0, 0.0, mbAnimate));
299 // OVERLAYMANAGER
300 insertNewlyCreatedOverlayObjectForSdrHdl(
301 std::move(pOverlayObject),
302 rPageWindow.GetObjectContact(),
303 *xManager);
310 } // end of namespace sdr::table
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */