1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "tablehandles.hxx"
32 #include <vcl/svapp.hxx>
33 #include <vcl/outdev.hxx>
34 #include <vcl/salbtype.hxx>
35 #include <vcl/canvastools.hxx>
36 #include <vcl/hatch.hxx>
37 #include <basegfx/polygon/b2dpolygon.hxx>
38 #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 #include <basegfx/range/b2drectangle.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <svx/sdr/overlay/overlayobject.hxx>
42 #include <svx/sdr/overlay/overlaymanager.hxx>
43 #include <svx/sdrpagewindow.hxx>
44 #include <svx/sdrpaintwindow.hxx>
45 #include <svx/svdmrkv.hxx>
46 #include <svx/svdpagv.hxx>
47 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
48 #include <svx/sdr/overlay/overlayhatchrect.hxx>
49 #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
51 namespace sdr
{ namespace table
{
53 // --------------------------------------------------------------------
55 class OverlayTableEdge
: public sdr::overlay::OverlayObject
58 basegfx::B2DPolyPolygon maPolyPolygon
;
61 // geometry creation for OverlayObject
62 virtual drawinglayer::primitive2d::Primitive2DSequence
createOverlayObjectPrimitive2DSequence();
65 OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
);
66 virtual ~OverlayTableEdge();
69 // --------------------------------------------------------------------
71 TableEdgeHdl::TableEdgeHdl( const Point
& rPnt
, bool bHorizontal
, sal_Int32 nMin
, sal_Int32 nMax
, sal_Int32 nEdges
)
72 : SdrHdl( rPnt
, HDL_USER
)
73 , mbHorizontal( bHorizontal
)
80 void TableEdgeHdl::SetEdge( sal_Int32 nEdge
, sal_Int32 nStart
, sal_Int32 nEnd
, TableEdgeState eState
)
82 if( (nEdge
>= 0) && (nEdge
<= sal::static_int_cast
<sal_Int32
>(maEdges
.size())) )
84 maEdges
[nEdge
].mnStart
= nStart
;
85 maEdges
[nEdge
].mnEnd
= nEnd
;
86 maEdges
[nEdge
].meState
= eState
;
90 OSL_FAIL( "sdr::table::TableEdgeHdl::SetEdge(), invalid edge!" );
94 Pointer
TableEdgeHdl::GetPointer() const
97 return POINTER_VSPLIT
;
99 return POINTER_HSPLIT
;
102 sal_Int32
TableEdgeHdl::GetValidDragOffset( const SdrDragStat
& rDrag
) const
104 return std::min( std::max( static_cast<sal_Int32
>(mbHorizontal
? rDrag
.GetDY() : rDrag
.GetDX()), mnMin
), mnMax
);
107 basegfx::B2DPolyPolygon
TableEdgeHdl::getSpecialDragPoly(const SdrDragStat
& rDrag
) const
109 basegfx::B2DPolyPolygon aVisible
;
110 basegfx::B2DPolyPolygon aInvisible
;
112 // create and return visible and non-visible parts for drag
113 getPolyPolygon(aVisible
, aInvisible
, &rDrag
);
114 aVisible
.append(aInvisible
);
119 void TableEdgeHdl::getPolyPolygon(basegfx::B2DPolyPolygon
& rVisible
, basegfx::B2DPolyPolygon
& rInvisible
, const SdrDragStat
* pDrag
) const
121 // changed method to create visible and invisible partial polygons in one run in
122 // separate PolyPolygons; both kinds are used
123 basegfx::B2DPoint
aOffset(aPos
.X(), aPos
.Y());
129 int n
= mbHorizontal
? 1 : 0;
130 aOffset
[n
] = aOffset
[n
] + GetValidDragOffset( *pDrag
);
133 basegfx::B2DPoint
aStart(aOffset
), aEnd(aOffset
);
134 int nPos
= mbHorizontal
? 0 : 1;
135 TableEdgeVector::const_iterator
aIter( maEdges
.begin() );
137 while( aIter
!= maEdges
.end() )
139 TableEdge
aEdge(*aIter
++);
141 aStart
[nPos
] = aOffset
[nPos
] + aEdge
.mnStart
;
142 aEnd
[nPos
] = aOffset
[nPos
] + aEdge
.mnEnd
;
144 basegfx::B2DPolygon aPolygon
;
145 aPolygon
.append( aStart
);
146 aPolygon
.append( aEnd
);
148 if(aEdge
.meState
== Visible
)
150 rVisible
.append(aPolygon
);
154 rInvisible
.append(aPolygon
);
159 void TableEdgeHdl::CreateB2dIAObject()
163 if(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
165 SdrMarkView
* pView
= pHdlList
->GetView();
166 SdrPageView
* pPageView
= pView
->GetSdrPageView();
170 basegfx::B2DPolyPolygon aVisible
;
171 basegfx::B2DPolyPolygon aInvisible
;
173 // get visible and invisible parts
174 getPolyPolygon(aVisible
, aInvisible
, 0);
176 if(aVisible
.count() || aInvisible
.count())
178 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
180 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
182 if(rPageWindow
.GetPaintWindow().OutputToWindow())
184 rtl::Reference
< ::sdr::overlay::OverlayManager
> xManager
= rPageWindow
.GetOverlayManager();
189 // create overlay object for visible parts
190 sdr::overlay::OverlayObject
* pOverlayObject
= new OverlayTableEdge(aVisible
, true);
191 xManager
->add(*pOverlayObject
);
192 maOverlayGroup
.append(*pOverlayObject
);
195 if(aInvisible
.count())
197 // also create overlay object vor invisible parts to allow
198 // a standard HitTest using the primitives from that overlay object
199 // (see OverlayTableEdge implementation)
200 sdr::overlay::OverlayObject
* pOverlayObject
= new OverlayTableEdge(aInvisible
, false);
201 xManager
->add(*pOverlayObject
);
202 maOverlayGroup
.append(*pOverlayObject
);
212 //////////////////////////////////////////////////////////////////////////////
214 OverlayTableEdge::OverlayTableEdge( const basegfx::B2DPolyPolygon
& rPolyPolygon
, bool bVisible
)
215 : OverlayObject(Color(COL_GRAY
))
216 , maPolyPolygon( rPolyPolygon
)
217 , mbVisible(bVisible
)
221 OverlayTableEdge::~OverlayTableEdge()
225 drawinglayer::primitive2d::Primitive2DSequence
OverlayTableEdge::createOverlayObjectPrimitive2DSequence()
227 drawinglayer::primitive2d::Primitive2DSequence aRetval
;
229 if(maPolyPolygon
.count())
231 // Discussed with CL. Currently i will leave the transparence out since this
232 // a little bit expensive. We may check the look with drag polygons later
233 const drawinglayer::primitive2d::Primitive2DReference
aReference(
234 new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
236 getBaseColor().getBColor()));
240 // visible, just return as sequence
241 aRetval
= drawinglayer::primitive2d::Primitive2DSequence(&aReference
, 1);
245 // embed in HiddenGeometryPrimitive2D to support HitTest of this invisible
247 const drawinglayer::primitive2d::Primitive2DSequence
aSequence(&aReference
, 1);
248 const drawinglayer::primitive2d::Primitive2DReference
aNewReference(
249 new drawinglayer::primitive2d::HiddenGeometryPrimitive2D(aSequence
));
250 aRetval
= drawinglayer::primitive2d::Primitive2DSequence(&aNewReference
, 1);
257 // ====================================================================
259 TableBorderHdl::TableBorderHdl( const Rectangle
& rRect
)
260 : SdrHdl( rRect
.TopLeft(), HDL_MOVE
)
261 , maRectangle( rRect
)
266 Pointer
TableBorderHdl::GetPointer() const
271 // create marker for this kind
272 void TableBorderHdl::CreateB2dIAObject()
276 if(pHdlList
&& pHdlList
->GetView() && !pHdlList
->GetView()->areMarkHandlesHidden())
278 SdrMarkView
* pView
= pHdlList
->GetView();
279 SdrPageView
* pPageView
= pView
->GetSdrPageView();
283 for(sal_uInt32 nWindow
= 0; nWindow
< pPageView
->PageWindowCount(); nWindow
++)
285 // const SdrPageViewWinRec& rPageViewWinRec = rPageViewWinList[b];
286 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(nWindow
);
288 if(rPageWindow
.GetPaintWindow().OutputToWindow())
290 rtl::Reference
< ::sdr::overlay::OverlayManager
> xManager
= rPageWindow
.GetOverlayManager();
293 const basegfx::B2DRange
aRange(vcl::unotools::b2DRectangleFromRectangle(maRectangle
));
294 sdr::overlay::OverlayObject
* pOverlayObject
= new sdr::overlay::OverlayHatchRect(
297 Color(0x80, 0x80, 0x80),
303 xManager
->add(*pOverlayObject
);
304 maOverlayGroup
.append(*pOverlayObject
);
312 //////////////////////////////////////////////////////////////////////////////
314 } // end of namespace table
315 } // end of namespace sdr
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */