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/svapp.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/canvastools.hxx>
26 #include <vcl/hatch.hxx>
27 #include <vcl/ptrstyle.hxx>
28 #include <basegfx/polygon/b2dpolygon.hxx>
29 #include <basegfx/polygon/b2dpolypolygontools.hxx>
30 #include <basegfx/range/b2drectangle.hxx>
31 #include <basegfx/polygon/b2dpolygontools.hxx>
32 #include <svx/sdr/overlay/overlayobject.hxx>
33 #include <svx/sdr/overlay/overlaymanager.hxx>
34 #include <svx/sdrpagewindow.hxx>
35 #include <svx/sdrpaintwindow.hxx>
36 #include <svx/svdmrkv.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
39 #include <sdr/overlay/overlayrectangle.hxx>
40 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
42 namespace sdr
{ namespace table
{
45 class OverlayTableEdge
: public sdr::overlay::OverlayObject
48 basegfx::B2DPolyPolygon
const maPolyPolygon
;
51 // geometry creation for OverlayObject
52 virtual drawinglayer::primitive2d::Primitive2DContainer
createOverlayObjectPrimitive2DSequence() override
;
55 OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, 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::min( std::max( 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(aPos
.X(), aPos
.Y());
117 int n
= mbHorizontal
? 1 : 0;
118 aOffset
[n
] = aOffset
[n
] + GetValidDragOffset( *pDrag
);
121 basegfx::B2DPoint
aStart(aOffset
), aEnd(aOffset
);
122 int nPos
= mbHorizontal
? 0 : 1;
124 for( const TableEdge
& aEdge
: maEdges
)
126 aStart
[nPos
] = aOffset
[nPos
] + aEdge
.mnStart
;
127 aEnd
[nPos
] = aOffset
[nPos
] + 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(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
150 SdrMarkView
* pView
= pHdlList
->GetView();
151 SdrPageView
* pPageView
= pView
->GetSdrPageView();
155 basegfx::B2DPolyPolygon aVisible
;
156 basegfx::B2DPolyPolygon aInvisible
;
158 // get visible and invisible parts
159 getPolyPolygon(aVisible
, aInvisible
, nullptr);
161 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(),
206 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
)
207 : OverlayObject(COL_GRAY
)
208 , maPolyPolygon( rPolyPolygon
)
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 const drawinglayer::primitive2d::Primitive2DContainer aSequence
{ aReference
};
236 const drawinglayer::primitive2d::Primitive2DReference
aNewReference(
237 new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(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 (pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
267 SdrMarkView
* pView
= pHdlList
->GetView();
268 SdrPageView
* pPageView
= pView
->GetSdrPageView();
273 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
275 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
277 if (rPageWindow
.GetPaintWindow().OutputToWindow())
279 const rtl::Reference
<sdr::overlay::OverlayManager
>& xManager
= rPageWindow
.GetOverlayManager();
283 const basegfx::B2DRange aRange
= vcl::unotools::b2DRectangleFromRectangle(maRectangle
);
284 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer
;
285 const Color
aHilightColor(aSvtOptionsDrawinglayer
.getHilightColor());
286 const double fTransparence(aSvtOptionsDrawinglayer
.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)
291 const bool bAnimate
= getAnimate();
293 OutputDevice
& rOutDev
= rPageWindow
.GetPaintWindow().GetOutputDevice();
294 float fScaleFactor
= rOutDev
.GetDPIScaleFactor();
295 double fWidth
= fScaleFactor
* 6.0;
297 std::unique_ptr
<sdr::overlay::OverlayObject
> pOverlayObject(
298 new sdr::overlay::OverlayRectangle(aRange
.getMinimum(), aRange
.getMaximum(),
299 aHilightColor
, fTransparence
,
300 fWidth
, 0.0, 0.0, bAnimate
));
303 insertNewlyCreatedOverlayObjectForSdrHdl(
304 std::move(pOverlayObject
),
305 rPageWindow
.GetObjectContact(),
314 } // end of namespace table
315 } // end of namespace sdr
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */