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 <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/polygon/b2dpolypolygontools.hxx>
29 #include <basegfx/range/b2drectangle.hxx>
30 #include <basegfx/polygon/b2dpolygontools.hxx>
31 #include <svx/sdr/overlay/overlayobject.hxx>
32 #include <svx/sdr/overlay/overlaymanager.hxx>
33 #include <svx/sdrpagewindow.hxx>
34 #include <svx/sdrpaintwindow.hxx>
35 #include <svx/svdmrkv.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
38 #include <sdr/overlay/overlayrectangle.hxx>
39 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
41 namespace sdr
{ namespace table
{
45 class OverlayTableEdge
: public sdr::overlay::OverlayObject
48 basegfx::B2DPolyPolygon maPolyPolygon
;
51 // geometry creation for OverlayObject
52 virtual drawinglayer::primitive2d::Primitive2DSequence
createOverlayObjectPrimitive2DSequence() SAL_OVERRIDE
;
55 OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
);
56 virtual ~OverlayTableEdge();
61 TableEdgeHdl::TableEdgeHdl( const Point
& rPnt
, bool bHorizontal
, sal_Int32 nMin
, sal_Int32 nMax
, sal_Int32 nEdges
)
62 : SdrHdl( rPnt
, HDL_USER
)
63 , mbHorizontal( bHorizontal
)
70 void TableEdgeHdl::SetEdge( sal_Int32 nEdge
, sal_Int32 nStart
, sal_Int32 nEnd
, TableEdgeState eState
)
72 if( (nEdge
>= 0) && (nEdge
<= sal::static_int_cast
<sal_Int32
>(maEdges
.size())) )
74 maEdges
[nEdge
].mnStart
= nStart
;
75 maEdges
[nEdge
].mnEnd
= nEnd
;
76 maEdges
[nEdge
].meState
= eState
;
80 OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
84 Pointer
TableEdgeHdl::GetPointer() const
87 return POINTER_VSPLIT
;
89 return POINTER_HSPLIT
;
92 sal_Int32
TableEdgeHdl::GetValidDragOffset( const SdrDragStat
& rDrag
) const
94 return std::min( std::max( static_cast<sal_Int32
>(mbHorizontal
? rDrag
.GetDY() : rDrag
.GetDX()), mnMin
), mnMax
);
97 basegfx::B2DPolyPolygon
TableEdgeHdl::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
99 basegfx::B2DPolyPolygon aVisible
;
100 basegfx::B2DPolyPolygon aInvisible
;
102 // create and return visible and non-visible parts for drag
103 getPolyPolygon(aVisible
, aInvisible
, &rDrag
);
104 aVisible
.append(aInvisible
);
109 void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon
& rVisible
, basegfx::B2DPolyPolygon
& rInvisible
, const SdrDragStat
* pDrag
) const
111 // changed method to create visible and invisible partial polygons in one run in
112 // separate PolyPolygons; both kinds are used
113 basegfx::B2DPoint
aOffset(aPos
.X(), aPos
.Y());
119 int n
= mbHorizontal
? 1 : 0;
120 aOffset
[n
] = aOffset
[n
] + GetValidDragOffset( *pDrag
);
123 basegfx::B2DPoint
aStart(aOffset
), aEnd(aOffset
);
124 int nPos
= mbHorizontal
? 0 : 1;
125 TableEdgeVector::const_iterator
aIter( maEdges
.begin() );
127 while( aIter
!= maEdges
.end() )
129 TableEdge
aEdge(*aIter
++);
131 aStart
[nPos
] = aOffset
[nPos
] + aEdge
.mnStart
;
132 aEnd
[nPos
] = aOffset
[nPos
] + aEdge
.mnEnd
;
134 basegfx::B2DPolygon aPolygon
;
135 aPolygon
.append( aStart
);
136 aPolygon
.append( aEnd
);
138 if(aEdge
.meState
== Visible
)
140 rVisible
.append(aPolygon
);
144 rInvisible
.append(aPolygon
);
149 void TableEdgeHdl::CreateB2dIAObject()
153 if(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
155 SdrMarkView
* pView
= pHdlList
->GetView();
156 SdrPageView
* pPageView
= pView
->GetSdrPageView();
160 basegfx::B2DPolyPolygon aVisible
;
161 basegfx::B2DPolyPolygon aInvisible
;
163 // get visible and invisible parts
164 getPolyPolygon(aVisible
, aInvisible
, 0);
166 if(aVisible
.count() || aInvisible
.count())
168 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
170 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
172 if(rPageWindow
.GetPaintWindow().OutputToWindow())
174 rtl::Reference
< ::sdr::overlay::OverlayManager
> xManager
= rPageWindow
.GetOverlayManager();
179 // create overlay object for visible parts
180 sdr::overlay::OverlayObject
* pOverlayObject
= new OverlayTableEdge(aVisible
, true);
181 xManager
->add(*pOverlayObject
);
182 maOverlayGroup
.append(*pOverlayObject
);
185 if(aInvisible
.count())
187 // also create overlay object vor invisible parts to allow
188 // a standard HitTest using the primitives from that overlay object
189 // (see OverlayTableEdge implementation)
190 sdr::overlay::OverlayObject
* pOverlayObject
= new OverlayTableEdge(aInvisible
, false);
191 xManager
->add(*pOverlayObject
);
192 maOverlayGroup
.append(*pOverlayObject
);
204 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
)
205 : OverlayObject(Color(COL_GRAY
))
206 , maPolyPolygon( rPolyPolygon
)
207 , mbVisible(bVisible
)
211 OverlayTableEdge::~OverlayTableEdge()
215 drawinglayer::primitive2d::Primitive2DSequence
OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
217 drawinglayer::primitive2d::Primitive2DSequence aRetval
;
219 if(maPolyPolygon
.count())
221 // Discussed with CL. Currently i will leave the transparence out since this
222 // a little bit expensive. We may check the look with drag polygons later
223 const drawinglayer::primitive2d::Primitive2DReference
aReference(
224 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
226 getBaseColor().getBColor()));
230 // visible, just return as sequence
231 aRetval
= drawinglayer::primitive2d::Primitive2DSequence(&aReference
, 1);
235 // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
237 const drawinglayer::primitive2d::Primitive2DSequence
aSequence(&aReference
, 1);
238 const drawinglayer::primitive2d::Primitive2DReference
aNewReference(
239 new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(aSequence
));
240 aRetval
= drawinglayer::primitive2d::Primitive2DSequence(&aNewReference
, 1);
249 TableBorderHdl::TableBorderHdl(
250 const Rectangle
& rRect
,
252 : SdrHdl(rRect
.TopLeft(), HDL_MOVE
),
258 Pointer
TableBorderHdl::GetPointer() const
263 // create marker for this kind
264 void TableBorderHdl::CreateB2dIAObject()
268 if(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
270 SdrMarkView
* pView
= pHdlList
->GetView();
271 SdrPageView
* pPageView
= pView
->GetSdrPageView();
275 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
277 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
279 if(rPageWindow
.GetPaintWindow().OutputToWindow())
281 rtl::Reference
< ::sdr::overlay::OverlayManager
> xManager
= rPageWindow
.GetOverlayManager();
284 const basegfx::B2DRange
aRange(vcl::unotools::b2DRectangleFromRectangle(maRectangle
));
285 const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer
;
286 const Color
aHilightColor(aSvtOptionsDrawinglayer
.getHilightColor());
287 const double fTransparence(aSvtOptionsDrawinglayer
.GetTransparentSelectionPercent() * 0.01);
289 sdr::overlay::OverlayObject
* pOverlayObject
= new sdr::overlay::OverlayRectangle(
298 // make animation dependent from text edit active, because for tables
299 // this handle is also used when text edit *is* active for it. This
300 // interferes too much concerning repaint stuff (at least as long as
301 // text edit is not yet on the overlay)
304 xManager
->add(*pOverlayObject
);
305 maOverlayGroup
.append(*pOverlayObject
);
315 } // end of namespace table
316 } // end of namespace sdr
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */