1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablehandles.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "tablehandles.hxx"
36 #include <vcl/svapp.hxx>
37 #include <vcl/outdev.hxx>
38 #include <vcl/salbtype.hxx>
39 #include <vcl/canvastools.hxx>
40 #include <vcl/hatch.hxx>
41 #include <basegfx/polygon/b2dpolygon.hxx>
42 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 #include <basegfx/range/b2drectangle.hxx>
44 #include <basegfx/polygon/b2dpolygontools.hxx>
45 #include <svx/sdr/overlay/overlayobject.hxx>
46 #include <svx/sdr/overlay/overlaymanager.hxx>
47 #include <svx/sdrpagewindow.hxx>
48 #include <sdrpaintwindow.hxx>
49 #include <svx/svdmrkv.hxx>
50 #include <svx/svdpagv.hxx>
51 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
52 #include <svx/sdr/overlay/overlayhatchrect.hxx>
53 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
55 namespace sdr
{ namespace table
{
57 // --------------------------------------------------------------------
59 class OverlayTableEdge
: public sdr::overlay::OverlayObject
62 basegfx::B2DPolyPolygon maPolyPolygon
;
65 // geometry creation for OverlayObject
66 virtual drawinglayer::primitive2d::Primitive2DSequence
createOverlayObjectPrimitive2DSequence();
69 OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
);
70 virtual ~OverlayTableEdge();
73 // --------------------------------------------------------------------
75 TableEdgeHdl::TableEdgeHdl( const Point
& rPnt
, bool bHorizontal
, sal_Int32 nMin
, sal_Int32 nMax
, sal_Int32 nEdges
)
76 : SdrHdl( rPnt
, HDL_USER
)
77 , mbHorizontal( bHorizontal
)
84 void TableEdgeHdl::SetEdge( sal_Int32 nEdge
, sal_Int32 nStart
, sal_Int32 nEnd
, TableEdgeState eState
)
86 if( (nEdge
>= 0) && (nEdge
<= sal::static_int_cast
<sal_Int32
>(maEdges
.size())) )
88 maEdges
[nEdge
].mnStart
= nStart
;
89 maEdges
[nEdge
].mnEnd
= nEnd
;
90 maEdges
[nEdge
].meState
= eState
;
94 OSL_ENSURE( false, "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
98 Pointer
TableEdgeHdl::GetPointer() const
101 return POINTER_VSPLIT
;
103 return POINTER_HSPLIT
;
106 sal_Int32
TableEdgeHdl::GetValidDragOffset( const SdrDragStat
& rDrag
) const
108 return std::min( std::max( static_cast<sal_Int32
>(mbHorizontal
? rDrag
.GetDY() : rDrag
.GetDX()), mnMin
), mnMax
);
111 basegfx::B2DPolyPolygon
TableEdgeHdl::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
113 basegfx::B2DPolyPolygon aVisible
;
114 basegfx::B2DPolyPolygon aInvisible
;
116 // create and return visible and non-visible parts for drag
117 getPolyPolygon(aVisible
, aInvisible
, &rDrag
);
118 aVisible
.append(aInvisible
);
123 void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon
& rVisible
, basegfx::B2DPolyPolygon
& rInvisible
, const SdrDragStat
* pDrag
) const
125 // changed method to create visible and invisible partial polygons in one run in
126 // separate PolyPolygons; both kinds are used
127 basegfx::B2DPoint
aOffset(aPos
.X(), aPos
.Y());
133 int n
= mbHorizontal
? 1 : 0;
134 aOffset
[n
] = aOffset
[n
] + GetValidDragOffset( *pDrag
);
137 basegfx::B2DPoint
aStart(aOffset
), aEnd(aOffset
);
138 int nPos
= mbHorizontal
? 0 : 1;
139 TableEdgeVector::const_iterator
aIter( maEdges
.begin() );
141 while( aIter
!= maEdges
.end() )
143 TableEdge
aEdge(*aIter
++);
145 aStart
[nPos
] = aOffset
[nPos
] + aEdge
.mnStart
;
146 aEnd
[nPos
] = aOffset
[nPos
] + aEdge
.mnEnd
;
148 basegfx::B2DPolygon aPolygon
;
149 aPolygon
.append( aStart
);
150 aPolygon
.append( aEnd
);
152 if(aEdge
.meState
== Visible
)
154 rVisible
.append(aPolygon
);
158 rInvisible
.append(aPolygon
);
163 void TableEdgeHdl::CreateB2dIAObject()
167 if(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
169 SdrMarkView
* pView
= pHdlList
->GetView();
170 SdrPageView
* pPageView
= pView
->GetSdrPageView();
174 basegfx::B2DPolyPolygon aVisible
;
175 basegfx::B2DPolyPolygon aInvisible
;
177 // get visible and invisible parts
178 getPolyPolygon(aVisible
, aInvisible
, 0);
180 if(aVisible
.count() || aInvisible
.count())
182 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
184 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
186 if(rPageWindow
.GetPaintWindow().OutputToWindow())
188 if(rPageWindow
.GetOverlayManager())
192 // create overlay object for visible parts
193 sdr::overlay::OverlayObject
* pOverlayObject
= new OverlayTableEdge(aVisible
, true);
194 rPageWindow
.GetOverlayManager()->add(*pOverlayObject
);
195 maOverlayGroup
.append(*pOverlayObject
);
198 if(aInvisible
.count())
200 // also create overlay object vor invisible parts to allow
201 // a standard HitTest using the primitives from that overlay object
202 // (see OverlayTableEdge implementation)
203 sdr::overlay::OverlayObject
* pOverlayObject
= new OverlayTableEdge(aInvisible
, false);
204 rPageWindow
.GetOverlayManager()->add(*pOverlayObject
);
205 maOverlayGroup
.append(*pOverlayObject
);
215 //////////////////////////////////////////////////////////////////////////////
217 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
)
218 : OverlayObject(Color(COL_GRAY
))
219 , maPolyPolygon( rPolyPolygon
)
220 , mbVisible(bVisible
)
224 OverlayTableEdge::~OverlayTableEdge()
228 drawinglayer::primitive2d::Primitive2DSequence
OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
230 drawinglayer::primitive2d::Primitive2DSequence aRetval
;
232 if(maPolyPolygon
.count())
234 // Discussed with CL. Currently i will leave the transparence out since this
235 // a little bit expensive. We may check the look with drag polygons later
236 const drawinglayer::primitive2d::Primitive2DReference
aReference(
237 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
239 getBaseColor().getBColor()));
243 // visible, just return as sequence
244 aRetval
= drawinglayer::primitive2d::Primitive2DSequence(&aReference
, 1);
248 // embed in HitTest primitive to support HitTest of this overlay object
249 const drawinglayer::primitive2d::Primitive2DSequence
aSequence(&aReference
, 1);
250 const drawinglayer::primitive2d::Primitive2DReference
aNewReference(
251 new drawinglayer::primitive2d::HitTestPrimitive2D(aSequence
));
252 aRetval
= drawinglayer::primitive2d::Primitive2DSequence(&aNewReference
, 1);
259 // ====================================================================
261 TableBorderHdl::TableBorderHdl( const Rectangle
& rRect
)
262 : SdrHdl( rRect
.TopLeft(), HDL_MOVE
)
263 , maRectangle( rRect
)
268 Pointer
TableBorderHdl::GetPointer() const
273 // create marker for this kind
274 void TableBorderHdl::CreateB2dIAObject()
278 if(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
280 SdrMarkView
* pView
= pHdlList
->GetView();
281 SdrPageView
* pPageView
= pView
->GetSdrPageView();
285 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
287 // const SdrPageViewWinRec& rPageViewWinRec = rPageViewWinList[b];
288 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
290 if(rPageWindow
.GetPaintWindow().OutputToWindow())
292 if(rPageWindow
.GetOverlayManager())
294 const basegfx::B2DRange
aRange(vcl::unotools::b2DRectangleFromRectangle(maRectangle
));
295 sdr::overlay::OverlayObject
* pOverlayObject
= new sdr::overlay::OverlayHatchRect(
298 Color(0x80, 0x80, 0x80),
304 rPageWindow
.GetOverlayManager()->add(*pOverlayObject
);
305 maOverlayGroup
.append(*pOverlayObject
);
313 //////////////////////////////////////////////////////////////////////////////
315 } // end of namespace table
316 } // end of namespace sdr