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: xtabdash.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 <vcl/svapp.hxx>
48 #include <tools/urlobj.hxx>
49 #include <vcl/virdev.hxx>
50 #include <vcl/window.hxx>
51 #include <svtools/itemset.hxx>
52 #include <sfx2/docfile.hxx>
53 #include <svx/dialogs.hrc>
54 #include <svx/dialmgr.hxx>
55 #include <svx/xtable.hxx>
56 #include <svx/xpool.hxx>
57 #include <svx/xlineit0.hxx>
58 #include <svx/xlnclit.hxx>
59 #include <svx/xlnwtit.hxx>
60 #include <svx/xlndsit.hxx>
61 #include <svx/xflclit.hxx>
63 #include <svx/svdorect.hxx>
64 #include <svx/svdopath.hxx>
65 #include <svx/svdmodel.hxx>
66 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
67 #include <svx/sdr/contact/displayinfo.hxx>
68 #include <basegfx/polygon/b2dpolygon.hxx>
70 using namespace com::sun::star
;
73 #define GLOBALOVERFLOW
75 sal_Unicode
const pszExtDash
[] = {'s','o','d'};
76 char const aChckDash
[] = { 0x04, 0x00, 'S','O','D','L'}; // < 5.2
77 char const aChckDash0
[] = { 0x04, 0x00, 'S','O','D','0'}; // = 5.2
78 char const aChckXML
[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
84 /*************************************************************************
86 |* XDashTable::XDashTable()
88 *************************************************************************/
90 XDashTable::XDashTable( const String
& rPath
,
91 XOutdevItemPool
* pInPool
,
92 USHORT nInitSize
, USHORT nReSize
) :
93 XPropertyTable( rPath
, pInPool
, nInitSize
, nReSize
)
95 pBmpTable
= new Table( nInitSize
, nReSize
);
98 /************************************************************************/
100 XDashTable::~XDashTable()
104 /************************************************************************/
106 XDashEntry
* XDashTable::Replace(long nIndex
, XDashEntry
* pEntry
)
108 return (XDashEntry
*) XPropertyTable::Replace(nIndex
, pEntry
);
111 /************************************************************************/
113 XDashEntry
* XDashTable::Remove(long nIndex
)
115 return (XDashEntry
*) XPropertyTable::Remove(nIndex
, 0);
118 /************************************************************************/
120 XDashEntry
* XDashTable::GetDash(long nIndex
) const
122 return (XDashEntry
*) XPropertyTable::Get(nIndex
, 0);
125 /************************************************************************/
127 BOOL
XDashTable::Load()
132 /************************************************************************/
134 BOOL
XDashTable::Save()
139 /************************************************************************/
141 BOOL
XDashTable::Create()
146 /************************************************************************/
148 BOOL
XDashTable::CreateBitmapsForUI()
153 /************************************************************************/
155 Bitmap
* XDashTable::CreateBitmapForUI( long /*nIndex*/, BOOL
/*bDelete*/)
167 VirtualDevice
* mpVirtualDevice
;
168 SdrModel
* mpSdrModel
;
169 SdrObject
* mpBackgroundObject
;
170 SdrObject
* mpLineObject
;
173 impXDashList(VirtualDevice
* pV
, SdrModel
* pM
, SdrObject
* pB
, SdrObject
* pL
)
174 : mpVirtualDevice(pV
),
176 mpBackgroundObject(pB
),
182 delete mpVirtualDevice
;
183 SdrObject::Free(mpBackgroundObject
);
184 SdrObject::Free(mpLineObject
);
188 VirtualDevice
* getVirtualDevice() const { return mpVirtualDevice
; }
189 SdrObject
* getBackgroundObject() const { return mpBackgroundObject
; }
190 SdrObject
* getLineObject() const { return mpLineObject
; }
193 void XDashList::impCreate()
197 const Point
aZero(0, 0);
198 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
200 VirtualDevice
* pVirDev
= new VirtualDevice
;
201 OSL_ENSURE(0 != pVirDev
, "XDashList: no VirtualDevice created!" );
202 pVirDev
->SetMapMode(MAP_100TH_MM
);
203 const Size
aSize(pVirDev
->PixelToLogic(Size(BITMAP_WIDTH
* 2, BITMAP_HEIGHT
)));
204 pVirDev
->SetOutputSize(aSize
);
205 pVirDev
->SetDrawMode(rStyleSettings
.GetHighContrastMode()
206 ? DRAWMODE_SETTINGSLINE
| DRAWMODE_SETTINGSFILL
| DRAWMODE_SETTINGSTEXT
| DRAWMODE_SETTINGSGRADIENT
209 SdrModel
* pSdrModel
= new SdrModel();
210 OSL_ENSURE(0 != pSdrModel
, "XDashList: no SdrModel created!" );
211 pSdrModel
->GetItemPool().FreezeIdRanges();
213 const Rectangle
aBackgroundSize(aZero
, aSize
);
214 SdrObject
* pBackgroundObject
= new SdrRectObj(aBackgroundSize
);
215 OSL_ENSURE(0 != pBackgroundObject
, "XDashList: no BackgroundObject created!" );
216 pBackgroundObject
->SetModel(pSdrModel
);
217 pBackgroundObject
->SetMergedItem(XFillStyleItem(XFILL_SOLID
));
218 pBackgroundObject
->SetMergedItem(XLineStyleItem(XLINE_NONE
));
219 pBackgroundObject
->SetMergedItem(XFillColorItem(String(), rStyleSettings
.GetFieldColor()));
221 const basegfx::B2DPoint
aStart(0, aSize
.Height() / 2);
222 const basegfx::B2DPoint
aEnd(aSize
.Width(), aSize
.Height() / 2);
223 basegfx::B2DPolygon aPolygon
;
224 aPolygon
.append(aStart
);
225 aPolygon
.append(aEnd
);
226 SdrObject
* pLineObject
= new SdrPathObj(OBJ_LINE
, basegfx::B2DPolyPolygon(aPolygon
));
227 OSL_ENSURE(0 != pLineObject
, "XDashList: no LineObject created!" );
228 pLineObject
->SetModel(pSdrModel
);
229 pLineObject
->SetMergedItem(XLineStyleItem(XLINE_DASH
));
230 pLineObject
->SetMergedItem(XLineColorItem(String(), rStyleSettings
.GetFieldTextColor()));
231 pLineObject
->SetMergedItem(XLineWidthItem(30));
233 mpData
= new impXDashList(pVirDev
, pSdrModel
, pBackgroundObject
, pLineObject
);
234 OSL_ENSURE(0 != mpData
, "XDashList: data creation went wrong!" );
238 void XDashList::impDestroy()
247 XDashList::XDashList(const String
& rPath
, XOutdevItemPool
* pInPool
, sal_uInt16 nInitSize
, sal_uInt16 nReSize
)
248 : XPropertyList(rPath
, pInPool
, nInitSize
, nReSize
),
251 pBmpList
= new List(nInitSize
, nReSize
);
254 XDashList::~XDashList()
259 XDashEntry
* XDashList::Replace(XDashEntry
* pEntry
, long nIndex
)
261 return (XDashEntry
*) XPropertyList::Replace(pEntry
, nIndex
);
264 XDashEntry
* XDashList::Remove(long nIndex
)
266 return (XDashEntry
*) XPropertyList::Remove(nIndex
, 0);
269 XDashEntry
* XDashList::GetDash(long nIndex
) const
271 return (XDashEntry
*) XPropertyList::Get(nIndex
, 0);
274 BOOL
XDashList::Load()
280 INetURLObject
aURL( aPath
);
282 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
284 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
288 aURL
.Append( aName
);
290 if( !aURL
.getExtension().getLength() )
291 aURL
.setExtension( rtl::OUString( pszExtDash
, 3 ) );
293 uno::Reference
< container::XNameContainer
> xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY
);
294 return SvxXMLXTableImport::load( aURL
.GetMainURL( INetURLObject::NO_DECODE
), xTable
);
299 BOOL
XDashList::Save()
301 INetURLObject
aURL( aPath
);
303 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
305 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
309 aURL
.Append( aName
);
311 if( !aURL
.getExtension().getLength() )
312 aURL
.setExtension( rtl::OUString( pszExtDash
, 3 ) );
314 uno::Reference
< container::XNameContainer
> xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY
);
315 return SvxXMLXTableExportComponent::save( aURL
.GetMainURL( INetURLObject::NO_DECODE
), xTable
);
318 BOOL
XDashList::Create()
320 XubString
aStr( SVX_RES( RID_SVXSTR_LINESTYLE
) );
323 aStr
.AppendAscii(" 1");
324 nLen
= aStr
.Len() - 1;
325 Insert(new XDashEntry(XDash(XDASH_RECT
,1, 50,1, 50, 50),aStr
));
326 aStr
.SetChar(nLen
, sal_Unicode('2'));
327 Insert(new XDashEntry(XDash(XDASH_RECT
,1,500,1,500,500),aStr
));
328 aStr
.SetChar(nLen
, sal_Unicode('3'));
329 Insert(new XDashEntry(XDash(XDASH_RECT
,2, 50,3,250,120),aStr
));
334 BOOL
XDashList::CreateBitmapsForUI()
338 for( long i
= 0; i
< Count(); i
++)
340 Bitmap
* pBmp
= CreateBitmapForUI( i
, FALSE
);
341 DBG_ASSERT( pBmp
, "XDashList: Bitmap(UI) konnte nicht erzeugt werden!" );
344 pBmpList
->Insert( pBmp
, i
);
352 Bitmap
* XDashList::CreateBitmapForUI( long nIndex
, BOOL bDelete
)
355 VirtualDevice
* pVD
= mpData
->getVirtualDevice();
356 SdrObject
* pLine
= mpData
->getLineObject();
358 pLine
->SetMergedItem(XLineStyleItem(XLINE_DASH
));
359 pLine
->SetMergedItem(XLineDashItem(String(), GetDash(nIndex
)->GetDash()));
361 sdr::contact::SdrObjectVector aObjectVector
;
362 aObjectVector
.push_back(mpData
->getBackgroundObject());
363 aObjectVector
.push_back(pLine
);
364 sdr::contact::ObjectContactOfObjListPainter
aPainter(*pVD
, aObjectVector
, 0);
365 sdr::contact::DisplayInfo aDisplayInfo
;
367 aPainter
.ProcessDisplay(aDisplayInfo
);
369 const Point
aZero(0, 0);
370 Bitmap
* pBitmap
= new Bitmap(pVD
->GetBitmap(aZero
, pVD
->GetOutputSize()));
380 //////////////////////////////////////////////////////////////////////////////