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: xtablend.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 ---------------------------------------------------------------
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include "XPropertyTable.hxx"
40 #include <unotools/ucbstreamhelper.hxx>
42 #include "xmlxtexp.hxx"
43 #include "xmlxtimp.hxx"
46 #include <tools/urlobj.hxx>
47 #include <vcl/virdev.hxx>
50 #include <vcl/svapp.hxx>
52 #include <svtools/itemset.hxx>
53 #include <sfx2/docfile.hxx>
55 #include <svx/dialogs.hrc>
56 #include <svx/dialmgr.hxx>
58 #include <svx/xtable.hxx>
59 #include <svx/xpool.hxx>
60 #include <svx/xfillit0.hxx>
61 #include <svx/xflclit.hxx>
62 #include <svx/xlnstwit.hxx>
63 #include <svx/xlnedwit.hxx>
64 #include <svx/xlnclit.hxx>
65 #include <svx/xlineit0.hxx>
66 #include <svx/xlnstit.hxx>
67 #include <svx/xlnedit.hxx>
68 #include <basegfx/point/b2dpoint.hxx>
69 #include <basegfx/polygon/b2dpolygon.hxx>
70 #include <basegfx/polygon/b2dpolygontools.hxx>
72 #include <svx/svdorect.hxx>
73 #include <svx/svdopath.hxx>
74 #include <svx/svdmodel.hxx>
75 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
76 #include <svx/sdr/contact/displayinfo.hxx>
78 #define GLOBALOVERFLOW
80 using namespace com::sun::star
;
83 sal_Unicode
const pszExtLineEnd
[] = {'s','o','e'};
85 static char const aChckLEnd
[] = { 0x04, 0x00, 'S','O','E','L'}; // < 5.2
86 static char const aChckLEnd0
[] = { 0x04, 0x00, 'S','O','E','0'}; // = 5.2
87 static char const aChckXML
[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
89 // --------------------
90 // class XLineEndTable
91 // --------------------
93 /*************************************************************************
95 |* XLineEndTable::XLineEndTable()
97 *************************************************************************/
99 XLineEndTable::XLineEndTable( const String
& rPath
,
100 XOutdevItemPool
* pInPool
,
101 USHORT nInitSize
, USHORT nReSize
) :
102 XPropertyTable( rPath
, pInPool
, nInitSize
, nReSize
)
104 pBmpTable
= new Table( nInitSize
, nReSize
);
107 /************************************************************************/
109 XLineEndTable::~XLineEndTable()
113 /************************************************************************/
115 XLineEndEntry
* XLineEndTable::Replace(long nIndex
, XLineEndEntry
* pEntry
)
117 return (XLineEndEntry
*) XPropertyTable::Replace(nIndex
, pEntry
);
120 /************************************************************************/
122 XLineEndEntry
* XLineEndTable::Remove(long nIndex
)
124 return (XLineEndEntry
*) XPropertyTable::Remove(nIndex
, 0);
127 /************************************************************************/
129 XLineEndEntry
* XLineEndTable::GetLineEnd(long nIndex
) const
131 return (XLineEndEntry
*) XPropertyTable::Get(nIndex
, 0);
134 /************************************************************************/
136 BOOL
XLineEndTable::Load()
141 /************************************************************************/
143 BOOL
XLineEndTable::Save()
148 /************************************************************************/
150 BOOL
XLineEndTable::Create()
155 /************************************************************************/
157 Bitmap
* XLineEndTable::CreateBitmapForUI( long /*nIndex*/, BOOL
/*bDelete*/)
162 /************************************************************************/
164 BOOL
XLineEndTable::CreateBitmapsForUI()
169 // --------------------
170 // class XLineEndList
171 // --------------------
173 class impXLineEndList
176 VirtualDevice
* mpVirtualDevice
;
177 SdrModel
* mpSdrModel
;
178 SdrObject
* mpBackgroundObject
;
179 SdrObject
* mpLineObject
;
182 impXLineEndList(VirtualDevice
* pV
, SdrModel
* pM
, SdrObject
* pB
, SdrObject
* pL
)
183 : mpVirtualDevice(pV
),
185 mpBackgroundObject(pB
),
191 delete mpVirtualDevice
;
192 SdrObject::Free(mpBackgroundObject
);
193 SdrObject::Free(mpLineObject
);
197 VirtualDevice
* getVirtualDevice() const { return mpVirtualDevice
; }
198 SdrObject
* getBackgroundObject() const { return mpBackgroundObject
; }
199 SdrObject
* getLineObject() const { return mpLineObject
; }
202 void XLineEndList::impCreate()
206 const Point
aZero(0, 0);
207 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
209 VirtualDevice
* pVirDev
= new VirtualDevice
;
210 OSL_ENSURE(0 != pVirDev
, "XLineEndList: no VirtualDevice created!" );
211 pVirDev
->SetMapMode(MAP_100TH_MM
);
212 const Size
aSize(pVirDev
->PixelToLogic(Size(BITMAP_WIDTH
* 2, BITMAP_HEIGHT
)));
213 pVirDev
->SetOutputSize(aSize
);
214 pVirDev
->SetDrawMode(rStyleSettings
.GetHighContrastMode()
215 ? DRAWMODE_SETTINGSLINE
| DRAWMODE_SETTINGSFILL
| DRAWMODE_SETTINGSTEXT
| DRAWMODE_SETTINGSGRADIENT
218 SdrModel
* pSdrModel
= new SdrModel();
219 OSL_ENSURE(0 != pSdrModel
, "XLineEndList: no SdrModel created!" );
220 pSdrModel
->GetItemPool().FreezeIdRanges();
222 const Rectangle
aBackgroundSize(aZero
, aSize
);
223 SdrObject
* pBackgroundObject
= new SdrRectObj(aBackgroundSize
);
224 OSL_ENSURE(0 != pBackgroundObject
, "XLineEndList: no BackgroundObject created!" );
225 pBackgroundObject
->SetModel(pSdrModel
);
226 pBackgroundObject
->SetMergedItem(XFillStyleItem(XFILL_SOLID
));
227 pBackgroundObject
->SetMergedItem(XLineStyleItem(XLINE_NONE
));
228 pBackgroundObject
->SetMergedItem(XFillColorItem(String(), rStyleSettings
.GetFieldColor()));
230 const basegfx::B2DPoint
aStart(0, aSize
.Height() / 2);
231 const basegfx::B2DPoint
aEnd(aSize
.Width(), aSize
.Height() / 2);
232 basegfx::B2DPolygon aPolygon
;
233 aPolygon
.append(aStart
);
234 aPolygon
.append(aEnd
);
235 SdrObject
* pLineObject
= new SdrPathObj(OBJ_LINE
, basegfx::B2DPolyPolygon(aPolygon
));
236 OSL_ENSURE(0 != pLineObject
, "XLineEndList: no LineObject created!" );
237 pLineObject
->SetModel(pSdrModel
);
238 pLineObject
->SetMergedItem(XLineStartWidthItem(aSize
.Height()));
239 pLineObject
->SetMergedItem(XLineEndWidthItem(aSize
.Height()));
240 pLineObject
->SetMergedItem(XLineColorItem(String(), rStyleSettings
.GetFieldTextColor()));
242 mpData
= new impXLineEndList(pVirDev
, pSdrModel
, pBackgroundObject
, pLineObject
);
243 OSL_ENSURE(0 != mpData
, "XLineEndList: data creation went wrong!" );
247 void XLineEndList::impDestroy()
256 XLineEndList::XLineEndList(const String
& rPath
, XOutdevItemPool
* _pXPool
, sal_uInt16 nInitSize
, sal_uInt16 nReSize
)
257 : XPropertyList(rPath
, _pXPool
, nInitSize
, nReSize
),
260 pBmpList
= new List(nInitSize
, nReSize
);
263 XLineEndList::~XLineEndList()
268 XLineEndEntry
* XLineEndList::Replace(XLineEndEntry
* pEntry
, long nIndex
)
270 return (XLineEndEntry
*) XPropertyList::Replace(pEntry
, nIndex
);
273 XLineEndEntry
* XLineEndList::Remove(long nIndex
)
275 return (XLineEndEntry
*) XPropertyList::Remove(nIndex
, 0);
278 XLineEndEntry
* XLineEndList::GetLineEnd(long nIndex
) const
280 return (XLineEndEntry
*) XPropertyList::Get(nIndex
, 0);
283 BOOL
XLineEndList::Load()
289 INetURLObject
aURL( aPath
);
291 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
293 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
297 aURL
.Append( aName
);
299 if( !aURL
.getExtension().getLength() )
300 aURL
.setExtension( rtl::OUString( pszExtLineEnd
, 3 ) );
302 uno::Reference
< container::XNameContainer
> xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY
);
303 return SvxXMLXTableImport::load( aURL
.GetMainURL( INetURLObject::NO_DECODE
), xTable
);
308 BOOL
XLineEndList::Save()
310 INetURLObject
aURL( aPath
);
312 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
314 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
318 aURL
.Append( aName
);
320 if( !aURL
.getExtension().getLength() )
321 aURL
.setExtension( rtl::OUString( pszExtLineEnd
, 3 ) );
323 uno::Reference
< container::XNameContainer
> xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY
);
324 return SvxXMLXTableExportComponent::save( aURL
.GetMainURL( INetURLObject::NO_DECODE
), xTable
);
327 BOOL
XLineEndList::Create()
329 basegfx::B2DPolygon aTriangle
;
330 aTriangle
.append(basegfx::B2DPoint(10.0, 0.0));
331 aTriangle
.append(basegfx::B2DPoint(0.0, 30.0));
332 aTriangle
.append(basegfx::B2DPoint(20.0, 30.0));
333 aTriangle
.setClosed(true);
334 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle
), SVX_RESSTR( RID_SVXSTR_ARROW
) ) );
336 basegfx::B2DPolygon aSquare
;
337 aSquare
.append(basegfx::B2DPoint(0.0, 0.0));
338 aSquare
.append(basegfx::B2DPoint(10.0, 0.0));
339 aSquare
.append(basegfx::B2DPoint(10.0, 10.0));
340 aSquare
.append(basegfx::B2DPoint(0.0, 10.0));
341 aSquare
.setClosed(true);
342 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare
), SVX_RESSTR( RID_SVXSTR_SQUARE
) ) );
344 basegfx::B2DPolygon
aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
345 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle
), SVX_RESSTR( RID_SVXSTR_CIRCLE
) ) );
350 BOOL
XLineEndList::CreateBitmapsForUI()
354 for( long i
= 0; i
< Count(); i
++)
356 Bitmap
* pBmp
= CreateBitmapForUI( i
, FALSE
);
357 OSL_ENSURE(0 != pBmp
, "XLineEndList: Bitmap(UI) could not be created!" );
360 pBmpList
->Insert( pBmp
, i
);
368 Bitmap
* XLineEndList::CreateBitmapForUI( long nIndex
, BOOL bDelete
)
371 VirtualDevice
* pVD
= mpData
->getVirtualDevice();
372 SdrObject
* pLine
= mpData
->getLineObject();
374 pLine
->SetMergedItem(XLineStyleItem(XLINE_SOLID
));
375 pLine
->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex
)->GetLineEnd()));
376 pLine
->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex
)->GetLineEnd()));
378 sdr::contact::SdrObjectVector aObjectVector
;
379 aObjectVector
.push_back(mpData
->getBackgroundObject());
380 aObjectVector
.push_back(pLine
);
381 sdr::contact::ObjectContactOfObjListPainter
aPainter(*pVD
, aObjectVector
, 0);
382 sdr::contact::DisplayInfo aDisplayInfo
;
384 aPainter
.ProcessDisplay(aDisplayInfo
);
386 const Point
aZero(0, 0);
387 Bitmap
* pBitmap
= new Bitmap(pVD
->GetBitmap(aZero
, pVD
->GetOutputSize()));
397 //////////////////////////////////////////////////////////////////////////////