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"
24 #include <vcl/outdev.hxx>
25 #include <vcl/canvastools.hxx>
26 #include <vcl/ptrstyle.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <svx/sdr/overlay/overlayobject.hxx>
29 #include <svx/sdr/overlay/overlaymanager.hxx>
30 #include <svx/sdrpagewindow.hxx>
31 #include <svx/sdrpaintwindow.hxx>
32 #include <svx/svdmrkv.hxx>
33 #include <svx/svdpagv.hxx>
34 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
35 #include <sdr/overlay/overlayrectangle.hxx>
36 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
37 #include <svtools/optionsdrawinglayer.hxx>
38 #include <osl/diagnose.h>
40 namespace sdr::table
{
44 class OverlayTableEdge
: public sdr::overlay::OverlayObject
47 basegfx::B2DPolyPolygon maPolyPolygon
;
50 // geometry creation for OverlayObject
51 virtual drawinglayer::primitive2d::Primitive2DContainer
createOverlayObjectPrimitive2DSequence() override
;
54 OverlayTableEdge( basegfx::B2DPolyPolygon aPolyPolygon
, bool bVisible
);
59 TableEdgeHdl::TableEdgeHdl( const Point
& rPnt
, bool bHorizontal
, sal_Int32 nMin
, sal_Int32 nMax
, sal_Int32 nEdges
)
60 : SdrHdl( rPnt
, SdrHdlKind::User
)
61 , mbHorizontal( bHorizontal
)
68 void TableEdgeHdl::SetEdge( sal_Int32 nEdge
, sal_Int32 nStart
, sal_Int32 nEnd
, TableEdgeState eState
)
70 if( (nEdge
>= 0) && (nEdge
<= sal::static_int_cast
<sal_Int32
>(maEdges
.size())) )
72 maEdges
[nEdge
].mnStart
= nStart
;
73 maEdges
[nEdge
].mnEnd
= nEnd
;
74 maEdges
[nEdge
].meState
= eState
;
78 OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
82 PointerStyle
TableEdgeHdl::GetPointer() const
85 return PointerStyle::VSplit
;
87 return PointerStyle::HSplit
;
90 sal_Int32
TableEdgeHdl::GetValidDragOffset( const SdrDragStat
& rDrag
) const
92 return std::clamp( static_cast<sal_Int32
>(mbHorizontal
? rDrag
.GetDY() : rDrag
.GetDX()), mnMin
, mnMax
);
95 basegfx::B2DPolyPolygon
TableEdgeHdl::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
97 basegfx::B2DPolyPolygon aVisible
;
98 basegfx::B2DPolyPolygon aInvisible
;
100 // create and return visible and non-visible parts for drag
101 getPolyPolygon(aVisible
, aInvisible
, &rDrag
);
102 aVisible
.append(aInvisible
);
107 void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon
& rVisible
, basegfx::B2DPolyPolygon
& rInvisible
, const SdrDragStat
* pDrag
) const
109 // changed method to create visible and invisible partial polygons in one run in
110 // separate PolyPolygons; both kinds are used
111 basegfx::B2DPoint
aOffset(m_aPos
.X(), m_aPos
.Y());
117 basegfx::Axis2D eDragAxis
= mbHorizontal
? basegfx::Axis2D::Y
: basegfx::Axis2D::X
;
118 aOffset
.set(eDragAxis
, aOffset
.get(eDragAxis
) + GetValidDragOffset( *pDrag
));
121 basegfx::B2DPoint
aStart(aOffset
), aEnd(aOffset
);
122 basegfx::Axis2D eAxis
= mbHorizontal
? basegfx::Axis2D::X
: basegfx::Axis2D::Y
;
124 for( const TableEdge
& aEdge
: maEdges
)
126 aStart
.set(eAxis
, aOffset
.get(eAxis
) + aEdge
.mnStart
);
127 aEnd
.set(eAxis
, aOffset
.get(eAxis
) + aEdge
.mnEnd
);
129 basegfx::B2DPolygon aPolygon
;
130 aPolygon
.append( aStart
);
131 aPolygon
.append( aEnd
);
133 if(aEdge
.meState
== Visible
)
135 rVisible
.append(aPolygon
);
139 rInvisible
.append(aPolygon
);
144 void TableEdgeHdl::CreateB2dIAObject()
148 if(!m_pHdlList
|| !m_pHdlList
->GetView() || m_pHdlList
->GetView()->areMarkHandlesHidden())
151 SdrMarkView
* pView
= m_pHdlList
->GetView();
152 SdrPageView
* pPageView
= pView
->GetSdrPageView();
157 basegfx::B2DPolyPolygon aVisible
;
158 basegfx::B2DPolyPolygon aInvisible
;
160 // get visible and invisible parts
161 getPolyPolygon(aVisible
, aInvisible
, nullptr);
163 if(!(aVisible
.count() || aInvisible
.count()))
166 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
168 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
170 if(rPageWindow
.GetPaintWindow().OutputToWindow())
172 const rtl::Reference
< sdr::overlay::OverlayManager
>& xManager
= rPageWindow
.GetOverlayManager();
177 // create overlay object for visible parts
178 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject(new OverlayTableEdge(aVisible
, true));
181 insertNewlyCreatedOverlayObjectForSdrHdl(
182 std::move(pOverlayObject
),
183 rPageWindow
.GetObjectContact(),
187 if(aInvisible
.count())
189 // also create overlay object for invisible parts to allow
190 // a standard HitTest using the primitives from that overlay object
191 // (see OverlayTableEdge implementation)
192 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject(new OverlayTableEdge(aInvisible
, false));
195 insertNewlyCreatedOverlayObjectForSdrHdl(
196 std::move(pOverlayObject
),
197 rPageWindow
.GetObjectContact(),
206 OverlayTableEdge::OverlayTableEdge( basegfx::B2DPolyPolygon aPolyPolygon
, bool bVisible
)
207 : OverlayObject(COL_GRAY
)
208 , maPolyPolygon(std::move( aPolyPolygon
))
209 , mbVisible(bVisible
)
213 drawinglayer::primitive2d::Primitive2DContainer
OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
215 drawinglayer::primitive2d::Primitive2DContainer aRetval
;
217 if(maPolyPolygon
.count())
219 // Discussed with CL. Currently i will leave the transparence out since this
220 // a little bit expensive. We may check the look with drag polygons later
221 const drawinglayer::primitive2d::Primitive2DReference
aReference(
222 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
224 getBaseColor().getBColor()));
228 // visible, just return as sequence
229 aRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ aReference
};
233 // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
235 drawinglayer::primitive2d::Primitive2DContainer aSequence
{ aReference
};
236 const drawinglayer::primitive2d::Primitive2DReference
aNewReference(
237 new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(std::move(aSequence
)));
238 aRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ aNewReference
};
246 TableBorderHdl::TableBorderHdl(
247 const tools::Rectangle
& rRect
,
249 : SdrHdl(rRect
.TopLeft(), SdrHdlKind::Move
),
255 PointerStyle
TableBorderHdl::GetPointer() const
257 return PointerStyle::Move
;
260 // create marker for this kind
261 void TableBorderHdl::CreateB2dIAObject()
265 if (!m_pHdlList
|| !m_pHdlList
->GetView() || m_pHdlList
->GetView()->areMarkHandlesHidden())
268 SdrMarkView
* pView
= m_pHdlList
->GetView();
269 SdrPageView
* pPageView
= pView
->GetSdrPageView();
274 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
276 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
278 if (rPageWindow
.GetPaintWindow().OutputToWindow())
280 const rtl::Reference
<sdr::overlay::OverlayManager
>& xManager
= rPageWindow
.GetOverlayManager();
284 const basegfx::B2DRange aRange
= vcl::unotools::b2DRectangleFromRectangle(maRectangle
);
285 const Color
aHilightColor(SvtOptionsDrawinglayer::getHilightColor());
286 const double fTransparence(SvtOptionsDrawinglayer::GetTransparentSelectionPercent() * 0.01);
287 // make animation dependent from text edit active, because for tables
288 // this handle is also used when text edit *is* active for it. This
289 // interferes too much concerning repaint stuff (at least as long as
290 // text edit is not yet on the overlay)
292 OutputDevice
& rOutDev
= rPageWindow
.GetPaintWindow().GetOutputDevice();
293 float fScaleFactor
= rOutDev
.GetDPIScaleFactor();
294 double fWidth
= fScaleFactor
* 6.0;
296 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject(
297 new sdr::overlay::OverlayRectangle(aRange
.getMinimum(), aRange
.getMaximum(),
298 aHilightColor
, fTransparence
,
299 fWidth
, 0.0, 0.0, mbAnimate
));
302 insertNewlyCreatedOverlayObjectForSdrHdl(
303 std::move(pOverlayObject
),
304 rPageWindow
.GetObjectContact(),
312 } // end of namespace sdr::table
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */