1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
{
41 class OverlayTableEdge
: public sdr::overlay::OverlayObject
44 basegfx::B2DPolyPolygon maPolyPolygon
;
47 // geometry creation for OverlayObject
48 virtual drawinglayer::primitive2d::Primitive2DContainer
createOverlayObjectPrimitive2DSequence() override
;
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
)
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
;
75 OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
79 PointerStyle
TableEdgeHdl::GetPointer() const
82 return PointerStyle::VSplit
;
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
);
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());
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
);
136 rInvisible
.append(aPolygon
);
141 void TableEdgeHdl::CreateB2dIAObject()
145 if(!pHdlList
|| !pHdlList
->GetView() || pHdlList
->GetView()->areMarkHandlesHidden())
148 SdrMarkView
* pView
= pHdlList
->GetView();
149 SdrPageView
* pPageView
= pView
->GetSdrPageView();
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()))
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();
174 // create overlay object for visible parts
175 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject(new OverlayTableEdge(aVisible
, true));
178 insertNewlyCreatedOverlayObjectForSdrHdl(
179 std::move(pOverlayObject
),
180 rPageWindow
.GetObjectContact(),
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));
192 insertNewlyCreatedOverlayObjectForSdrHdl(
193 std::move(pOverlayObject
),
194 rPageWindow
.GetObjectContact(),
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(
221 getBaseColor().getBColor()));
225 // visible, just return as sequence
226 aRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ aReference
};
230 // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
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
};
243 TableBorderHdl::TableBorderHdl(
244 const tools::Rectangle
& rRect
,
246 : SdrHdl(rRect
.TopLeft(), SdrHdlKind::Move
),
252 PointerStyle
TableBorderHdl::GetPointer() const
254 return PointerStyle::Move
;
257 // create marker for this kind
258 void TableBorderHdl::CreateB2dIAObject()
262 if (!pHdlList
|| !pHdlList
->GetView() || pHdlList
->GetView()->areMarkHandlesHidden())
265 SdrMarkView
* pView
= pHdlList
->GetView();
266 SdrPageView
* pPageView
= pView
->GetSdrPageView();
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();
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
));
300 insertNewlyCreatedOverlayObjectForSdrHdl(
301 std::move(pOverlayObject
),
302 rPageWindow
.GetObjectContact(),
310 } // end of namespace sdr::table
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */