/src/libreoffice/svx/source/table/tablehandles.cxx
Line | Count | Source |
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> |
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> |
39 | | |
40 | | namespace sdr::table { |
41 | | |
42 | | namespace { |
43 | | |
44 | | class OverlayTableEdge : public sdr::overlay::OverlayObject |
45 | | { |
46 | | protected: |
47 | | basegfx::B2DPolyPolygon maPolyPolygon; |
48 | | bool mbVisible; |
49 | | |
50 | | // geometry creation for OverlayObject |
51 | | virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override; |
52 | | |
53 | | public: |
54 | | OverlayTableEdge( basegfx::B2DPolyPolygon aPolyPolygon, bool bVisible ); |
55 | | }; |
56 | | |
57 | | } |
58 | | |
59 | | TableEdgeHdl::TableEdgeHdl( const Point& rPnt, bool bHorizontal, sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nEdges ) |
60 | 0 | : SdrHdl( rPnt, SdrHdlKind::User ) |
61 | 0 | , mbHorizontal( bHorizontal ) |
62 | 0 | , mnMin( nMin ) |
63 | 0 | , mnMax( nMax ) |
64 | 0 | , maEdges(nEdges) |
65 | 0 | { |
66 | 0 | } |
67 | | |
68 | | void TableEdgeHdl::SetEdge( sal_Int32 nEdge, sal_Int32 nStart, sal_Int32 nEnd, TableEdgeState eState ) |
69 | 0 | { |
70 | 0 | if( (nEdge >= 0) && (nEdge <= sal::static_int_cast<sal_Int32>(maEdges.size())) ) |
71 | 0 | { |
72 | 0 | maEdges[nEdge].mnStart = nStart; |
73 | 0 | maEdges[nEdge].mnEnd = nEnd; |
74 | 0 | maEdges[nEdge].meState = eState; |
75 | 0 | } |
76 | 0 | else |
77 | 0 | { |
78 | 0 | OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" ); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | PointerStyle TableEdgeHdl::GetPointer() const |
83 | 0 | { |
84 | 0 | if( mbHorizontal ) |
85 | 0 | return PointerStyle::VSplit; |
86 | 0 | else |
87 | 0 | return PointerStyle::HSplit; |
88 | 0 | } |
89 | | |
90 | | sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const |
91 | 0 | { |
92 | 0 | return std::clamp( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin, mnMax ); |
93 | 0 | } |
94 | | |
95 | | basegfx::B2DPolyPolygon TableEdgeHdl::getSpecialDragPoly(const SdrDragStat& rDrag) const |
96 | 0 | { |
97 | 0 | basegfx::B2DPolyPolygon aVisible; |
98 | 0 | basegfx::B2DPolyPolygon aInvisible; |
99 | | |
100 | | // create and return visible and non-visible parts for drag |
101 | 0 | getPolyPolygon(aVisible, aInvisible, &rDrag); |
102 | 0 | aVisible.append(aInvisible); |
103 | |
|
104 | 0 | return aVisible; |
105 | 0 | } |
106 | | |
107 | | void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon& rVisible, basegfx::B2DPolyPolygon& rInvisible, const SdrDragStat* pDrag) const |
108 | 0 | { |
109 | | // changed method to create visible and invisible partial polygons in one run in |
110 | | // separate PolyPolygons; both kinds are used |
111 | 0 | basegfx::B2DPoint aOffset(m_aPos.X(), m_aPos.Y()); |
112 | 0 | rVisible.clear(); |
113 | 0 | rInvisible.clear(); |
114 | |
|
115 | 0 | if( pDrag ) |
116 | 0 | { |
117 | 0 | basegfx::Axis2D eDragAxis = mbHorizontal ? basegfx::Axis2D::Y : basegfx::Axis2D::X; |
118 | 0 | aOffset.set(eDragAxis, aOffset.get(eDragAxis) + GetValidDragOffset( *pDrag )); |
119 | 0 | } |
120 | |
|
121 | 0 | basegfx::B2DPoint aStart(aOffset), aEnd(aOffset); |
122 | 0 | basegfx::Axis2D eAxis = mbHorizontal ? basegfx::Axis2D::X : basegfx::Axis2D::Y; |
123 | |
|
124 | 0 | for( const TableEdge& aEdge : maEdges ) |
125 | 0 | { |
126 | 0 | aStart.set(eAxis, aOffset.get(eAxis) + aEdge.mnStart); |
127 | 0 | aEnd.set(eAxis, aOffset.get(eAxis) + aEdge.mnEnd); |
128 | |
|
129 | 0 | basegfx::B2DPolygon aPolygon; |
130 | 0 | aPolygon.append( aStart ); |
131 | 0 | aPolygon.append( aEnd ); |
132 | |
|
133 | 0 | if(aEdge.meState == Visible) |
134 | 0 | { |
135 | 0 | rVisible.append(aPolygon); |
136 | 0 | } |
137 | 0 | else |
138 | 0 | { |
139 | 0 | rInvisible.append(aPolygon); |
140 | 0 | } |
141 | 0 | } |
142 | 0 | } |
143 | | |
144 | | void TableEdgeHdl::CreateB2dIAObject() |
145 | 0 | { |
146 | 0 | GetRidOfIAObject(); |
147 | |
|
148 | 0 | if(!m_pHdlList || !m_pHdlList->GetView() || m_pHdlList->GetView()->areMarkHandlesHidden()) |
149 | 0 | return; |
150 | | |
151 | 0 | SdrMarkView* pView = m_pHdlList->GetView(); |
152 | 0 | SdrPageView* pPageView = pView->GetSdrPageView(); |
153 | |
|
154 | 0 | if(!pPageView) |
155 | 0 | return; |
156 | | |
157 | 0 | basegfx::B2DPolyPolygon aVisible; |
158 | 0 | basegfx::B2DPolyPolygon aInvisible; |
159 | | |
160 | | // get visible and invisible parts |
161 | 0 | getPolyPolygon(aVisible, aInvisible, nullptr); |
162 | |
|
163 | 0 | if(!(aVisible.count() || aInvisible.count())) |
164 | 0 | return; |
165 | | |
166 | 0 | for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++) |
167 | 0 | { |
168 | 0 | const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow); |
169 | |
|
170 | 0 | if(rPageWindow.GetPaintWindow().OutputToWindow()) |
171 | 0 | { |
172 | 0 | const rtl::Reference< sdr::overlay::OverlayManager >& xManager = rPageWindow.GetOverlayManager(); |
173 | 0 | if (xManager.is()) |
174 | 0 | { |
175 | 0 | if(aVisible.count()) |
176 | 0 | { |
177 | | // create overlay object for visible parts |
178 | 0 | std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aVisible, true)); |
179 | | |
180 | | // OVERLAYMANAGER |
181 | 0 | insertNewlyCreatedOverlayObjectForSdrHdl( |
182 | 0 | std::move(pOverlayObject), |
183 | 0 | rPageWindow.GetObjectContact(), |
184 | 0 | *xManager); |
185 | 0 | } |
186 | |
|
187 | 0 | if(aInvisible.count()) |
188 | 0 | { |
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 | 0 | std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject(new OverlayTableEdge(aInvisible, false)); |
193 | | |
194 | | // OVERLAYMANAGER |
195 | 0 | insertNewlyCreatedOverlayObjectForSdrHdl( |
196 | 0 | std::move(pOverlayObject), |
197 | 0 | rPageWindow.GetObjectContact(), |
198 | 0 | *xManager); |
199 | 0 | } |
200 | 0 | } |
201 | 0 | } |
202 | 0 | } |
203 | 0 | } |
204 | | |
205 | | |
206 | | OverlayTableEdge::OverlayTableEdge( basegfx::B2DPolyPolygon aPolyPolygon, bool bVisible ) |
207 | 0 | : OverlayObject(COL_GRAY) |
208 | 0 | , maPolyPolygon(std::move( aPolyPolygon )) |
209 | 0 | , mbVisible(bVisible) |
210 | 0 | { |
211 | 0 | } |
212 | | |
213 | | drawinglayer::primitive2d::Primitive2DContainer OverlayTableEdge::createOverlayObjectPrimitive2DSequence() |
214 | 0 | { |
215 | 0 | drawinglayer::primitive2d::Primitive2DContainer aRetval; |
216 | |
|
217 | 0 | if(maPolyPolygon.count()) |
218 | 0 | { |
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 | 0 | const drawinglayer::primitive2d::Primitive2DReference aReference( |
222 | 0 | new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D( |
223 | 0 | maPolyPolygon, |
224 | 0 | getBaseColor().getBColor())); |
225 | |
|
226 | 0 | if(mbVisible) |
227 | 0 | { |
228 | | // visible, just return as sequence |
229 | 0 | aRetval = drawinglayer::primitive2d::Primitive2DContainer { aReference }; |
230 | 0 | } |
231 | 0 | else |
232 | 0 | { |
233 | | // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible |
234 | | // overlay object |
235 | 0 | drawinglayer::primitive2d::Primitive2DContainer aSequence { aReference }; |
236 | 0 | const drawinglayer::primitive2d::Primitive2DReference aNewReference( |
237 | 0 | new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(std::move(aSequence))); |
238 | 0 | aRetval = drawinglayer::primitive2d::Primitive2DContainer { aNewReference }; |
239 | 0 | } |
240 | 0 | } |
241 | |
|
242 | 0 | return aRetval; |
243 | 0 | } |
244 | | |
245 | | |
246 | | TableBorderHdl::TableBorderHdl( |
247 | | const tools::Rectangle& rRect, |
248 | | bool bAnimate) |
249 | 0 | : SdrHdl(rRect.TopLeft(), SdrHdlKind::Move), |
250 | 0 | maRectangle(rRect), |
251 | 0 | mbAnimate(bAnimate) |
252 | 0 | { |
253 | 0 | } |
254 | | |
255 | | PointerStyle TableBorderHdl::GetPointer() const |
256 | 0 | { |
257 | 0 | return PointerStyle::Move; |
258 | 0 | } |
259 | | |
260 | | // create marker for this kind |
261 | | void TableBorderHdl::CreateB2dIAObject() |
262 | 0 | { |
263 | 0 | GetRidOfIAObject(); |
264 | |
|
265 | 0 | if (!m_pHdlList || !m_pHdlList->GetView() || m_pHdlList->GetView()->areMarkHandlesHidden()) |
266 | 0 | return; |
267 | | |
268 | 0 | SdrMarkView* pView = m_pHdlList->GetView(); |
269 | 0 | SdrPageView* pPageView = pView->GetSdrPageView(); |
270 | |
|
271 | 0 | if (!pPageView) |
272 | 0 | return; |
273 | | |
274 | 0 | for(sal_uInt32 nWindow = 0; nWindow < pPageView->PageWindowCount(); nWindow++) |
275 | 0 | { |
276 | 0 | const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(nWindow); |
277 | |
|
278 | 0 | if (rPageWindow.GetPaintWindow().OutputToWindow()) |
279 | 0 | { |
280 | 0 | const rtl::Reference<sdr::overlay::OverlayManager>& xManager = rPageWindow.GetOverlayManager(); |
281 | |
|
282 | 0 | if (xManager.is()) |
283 | 0 | { |
284 | 0 | const basegfx::B2DRange aRange = vcl::unotools::b2DRectangleFromRectangle(maRectangle); |
285 | 0 | const Color aHilightColor(SvtOptionsDrawinglayer::getHilightColor()); |
286 | 0 | 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 | 0 | OutputDevice& rOutDev = rPageWindow.GetPaintWindow().GetOutputDevice(); |
293 | 0 | float fScaleFactor = rOutDev.GetDPIScaleFactor(); |
294 | 0 | double fWidth = fScaleFactor * 6.0; |
295 | |
|
296 | 0 | std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject( |
297 | 0 | new sdr::overlay::OverlayRectangle(aRange.getMinimum(), aRange.getMaximum(), |
298 | 0 | aHilightColor, fTransparence, |
299 | 0 | fWidth, 0.0, 0.0, mbAnimate)); |
300 | | |
301 | | // OVERLAYMANAGER |
302 | 0 | insertNewlyCreatedOverlayObjectForSdrHdl( |
303 | 0 | std::move(pOverlayObject), |
304 | 0 | rPageWindow.GetObjectContact(), |
305 | 0 | *xManager); |
306 | 0 | } |
307 | 0 | } |
308 | 0 | } |
309 | 0 | } |
310 | | |
311 | | |
312 | | } // end of namespace sdr::table |
313 | | |
314 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |