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 <utility>
24#include <vcl/outdev.hxx>
25#include <vcl/canvastools.hxx>
26#include <vcl/ptrstyle.hxx>
30#include <svx/sdrpagewindow.hxx>
32#include <svx/svdmrkv.hxx>
33#include <svx/svdpagv.hxx>
38#include <osl/diagnose.h>
39
40namespace sdr::table {
41
42namespace {
43
44class OverlayTableEdge : public sdr::overlay::OverlayObject
45{
46protected:
49
50 // geometry creation for OverlayObject
51 virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override;
52
53public:
54 OverlayTableEdge( basegfx::B2DPolyPolygon aPolyPolygon, bool bVisible );
55};
56
57}
58
59TableEdgeHdl::TableEdgeHdl( const Point& rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges )
60: SdrHdl( rPnt, SdrHdlKind::User )
61, mbHorizontal( bHorizontal )
62, mnMin( nMin )
63, mnMax( nMax )
64, maEdges(nEdges)
65{
66}
67
68void TableEdgeHdl::SetEdge( sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState eState )
69{
70 if( (nEdge >= 0) && (nEdge <= sal::static_int_cast<sal_Int32>(maEdges.size())) )
71 {
72 maEdges[nEdge].mnStart = nStart;
73 maEdges[nEdge].mnEnd = nEnd;
74 maEdges[nEdge].meState = eState;
75 }
76 else
77 {
78 OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
79 }
80}
81
83{
84 if( mbHorizontal )
85 return PointerStyle::VSplit;
86 else
87 return PointerStyle::HSplit;
88}
89
90sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const
91{
92 return std::clamp( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin, mnMax );
93}
94
96{
98 basegfx::B2DPolyPolygon aInvisible;
99
100 // create and return visible and non-visible parts for drag
101 getPolyPolygon(aVisible, aInvisible, &rDrag);
102 aVisible.append(aInvisible);
103
104 return aVisible;
105}
106
108{
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());
112 rVisible.clear();
113 rInvisible.clear();
114
115 if( pDrag )
116 {
118 aOffset.set(eDragAxis, aOffset.get(eDragAxis) + GetValidDragOffset( *pDrag ));
119 }
120
121 basegfx::B2DPoint aStart(aOffset), aEnd(aOffset);
123
124 for( const TableEdge& aEdge : maEdges )
125 {
126 aStart.set(eAxis, aOffset.get(eAxis) + aEdge.mnStart);
127 aEnd.set(eAxis, aOffset.get(eAxis) + aEdge.mnEnd);
128
129 basegfx::B2DPolygon aPolygon;
130 aPolygon.append( aStart );
131 aPolygon.append( aEnd );
132
133 if(aEdge.meState == Visible)
134 {
135 rVisible.append(aPolygon);
136 }
137 else
138 {
139 rInvisible.append(aPolygon);
140 }
141 }
142}
143
145{
147
149 return;
150
151 SdrMarkView* pView = pHdlList->GetView();
152 SdrPageView* pPageView = pView->GetSdrPageView();
153
154 if(!pPageView)
155 return;
156
158 basegfx::B2DPolyPolygon aInvisible;
159
160 // get visible and invisible parts
161 getPolyPolygon(aVisible, aInvisible, nullptr);
162
163 if(!(aVisible.count() || aInvisible.count()))
164 return;
165
166 for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
167 {
168 const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
169
170 if(rPageWindow.GetPaintWindow().OutputToWindow())
171 {
173 if (xManager.is())
174 {
175 if(aVisible.count())
176 {
177 // create overlay object for visible parts
178 std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aVisible, true));
179
180 // OVERLAYMANAGER
182 std::move(pOverlayObject),
183 rPageWindow.GetObjectContact(),
184 *xManager);
185 }
186
187 if(aInvisible.count())
188 {
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));
193
194 // OVERLAYMANAGER
196 std::move(pOverlayObject),
197 rPageWindow.GetObjectContact(),
198 *xManager);
199 }
200 }
201 }
202 }
203}
204
205
206OverlayTableEdge::OverlayTableEdge( basegfx::B2DPolyPolygon aPolyPolygon, bool bVisible )
207: OverlayObject(COL_GRAY)
208, maPolyPolygon(std::move( aPolyPolygon ))
210{
211}
212
213drawinglayer::primitive2d::Primitive2DContainer OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
214{
216
217 if(maPolyPolygon.count())
218 {
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
224 getBaseColor().getBColor()));
225
226 if(mbVisible)
227 {
228 // visible, just return as sequence
230 }
231 else
232 {
233 // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
234 // overlay object
238 aRetval = drawinglayer::primitive2d::Primitive2DContainer { aNewReference };
239 }
240 }
241
242 return aRetval;
243}
244
245
247 const tools::Rectangle& rRect,
248 bool bAnimate)
249: SdrHdl(rRect.TopLeft(), SdrHdlKind::Move),
250 maRectangle(rRect),
251 mbAnimate(bAnimate)
252{
253}
254
256{
257 return PointerStyle::Move;
258}
259
260// create marker for this kind
262{
264
266 return;
267
268 SdrMarkView* pView = pHdlList->GetView();
269 SdrPageView* pPageView = pView->GetSdrPageView();
270
271 if (!pPageView)
272 return;
273
274 for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++)
275 {
276 const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow);
277
278 if (rPageWindow.GetPaintWindow().OutputToWindow())
279 {
281
282 if (xManager.is())
283 {
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)
291
292 OutputDevice& rOutDev = rPageWindow.GetPaintWindow().GetOutputDevice();
293 float fScaleFactor = rOutDev.GetDPIScaleFactor();
294 double fWidth = fScaleFactor * 6.0;
295
296 std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(
298 aHilightColor, fTransparence,
299 fWidth, 0.0, 0.0, mbAnimate));
300
301 // OVERLAYMANAGER
303 std::move(pOverlayObject),
304 rPageWindow.GetObjectContact(),
305 *xManager);
306 }
307 }
308 }
309}
310
311
312} // end of namespace sdr::table
313
314/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOUser User
float GetDPIScaleFactor() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
tools::Long GetDY() const
Definition: svddrag.hxx:159
tools::Long GetDX() const
Definition: svddrag.hxx:158
SdrMarkView * GetView() const
Definition: svdhdl.hxx:453
SdrHdlList * pHdlList
Definition: svdhdl.hxx:138
Point aPos
Definition: svdhdl.hxx:142
void insertNewlyCreatedOverlayObjectForSdrHdl(std::unique_ptr< sdr::overlay::OverlayObject > pOverlayObject, const sdr::contact::ObjectContact &rObjectContact, sdr::overlay::OverlayManager &rOverlayManager)
Definition: svdhdl.cxx:1080
void GetRidOfIAObject()
Definition: svdhdl.cxx:398
bool areMarkHandlesHidden() const
Definition: svdmrkv.hxx:283
sal_uInt32 PageWindowCount() const
Definition: svdpagv.hxx:89
SdrPageWindow * GetPageWindow(sal_uInt32 nIndex) const
Definition: svdpagv.cxx:83
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
SdrPaintWindow & GetPaintWindow() const
const sdr::contact::ObjectContact & GetObjectContact() const
SdrPageView * GetSdrPageView() const
Definition: svdpntv.hxx:323
OutputDevice & GetOutputDevice() const
bool OutputToWindow() const
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
sal_uInt32 count() const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
B2DPoint getMaximum() const
B2DPoint getMinimum() const
void set(Axis2D eAxis, TYPE fValue)
double get(Axis2D eAxis)
virtual void CreateB2dIAObject() override
tools::Rectangle maRectangle
TableBorderHdl(const tools::Rectangle &rRect, bool bAnimate)
virtual PointerStyle GetPointer() const override
virtual PointerStyle GetPointer() const override
std::vector< TableEdge > maEdges
sal_Int32 GetValidDragOffset(const SdrDragStat &rDrag) const
virtual void CreateB2dIAObject() override
TableEdgeHdl(const Point &rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges)
basegfx::B2DPolyPolygon getSpecialDragPoly(const SdrDragStat &rDrag) const
void SetEdge(sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState nState)
void getPolyPolygon(basegfx::B2DPolyPolygon &rVisible, basegfx::B2DPolyPolygon &rInvisible, const SdrDragStat *pDrag) const
constexpr ::Color COL_GRAY(0x80, 0x80, 0x80)
sal_uInt16 GetTransparentSelectionPercent()
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
PointerStyle
SdrHdlKind
Definition: svdhdl.hxx:53
basegfx::B2DPolyPolygon maPolyPolygon
bool mbVisible
bool bVisible