merge the formfield patch from ooo-build
[ooovba.git] / svx / source / xoutdev / xtabdash.cxx
blobe2a3ad190216c52575c1f84505be3e5308b915b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xtabdash.cxx,v $
10 * $Revision: 1.21 $
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 ---------------------------------------------------------------
36 #ifndef SVX_LIGHT
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"
45 #endif
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;
71 using namespace rtl;
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
80 // -----------------
81 // class XDashTable
82 // -----------------
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()
129 return( FALSE );
132 /************************************************************************/
134 BOOL XDashTable::Save()
136 return( FALSE );
139 /************************************************************************/
141 BOOL XDashTable::Create()
143 return( FALSE );
146 /************************************************************************/
148 BOOL XDashTable::CreateBitmapsForUI()
150 return( FALSE );
153 /************************************************************************/
155 Bitmap* XDashTable::CreateBitmapForUI( long /*nIndex*/, BOOL /*bDelete*/)
157 return( NULL );
160 // ----------------
161 // class XDashList
162 // ----------------
164 class impXDashList
166 private:
167 VirtualDevice* mpVirtualDevice;
168 SdrModel* mpSdrModel;
169 SdrObject* mpBackgroundObject;
170 SdrObject* mpLineObject;
172 public:
173 impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
174 : mpVirtualDevice(pV),
175 mpSdrModel(pM),
176 mpBackgroundObject(pB),
177 mpLineObject(pL)
180 ~impXDashList()
182 delete mpVirtualDevice;
183 SdrObject::Free(mpBackgroundObject);
184 SdrObject::Free(mpLineObject);
185 delete mpSdrModel;
188 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
189 SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
190 SdrObject* getLineObject() const { return mpLineObject; }
193 void XDashList::impCreate()
195 if(!mpData)
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
207 : DRAWMODE_DEFAULT);
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()
240 if(mpData)
242 delete mpData;
243 mpData = 0;
247 XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
248 : XPropertyList(rPath, pInPool, nInitSize, nReSize),
249 mpData(0)
251 pBmpList = new List(nInitSize, nReSize);
254 XDashList::~XDashList()
256 impDestroy();
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()
276 if( bListDirty )
278 bListDirty = FALSE;
280 INetURLObject aURL( aPath );
282 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
284 DBG_ASSERT( !aPath.Len(), "invalid URL" );
285 return FALSE;
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 );
296 return( FALSE );
299 BOOL XDashList::Save()
301 INetURLObject aURL( aPath );
303 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
305 DBG_ASSERT( !aPath.Len(), "invalid URL" );
306 return FALSE;
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 ) );
321 xub_StrLen nLen;
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));
331 return( TRUE );
334 BOOL XDashList::CreateBitmapsForUI()
336 impCreate();
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!" );
343 if( pBmp )
344 pBmpList->Insert( pBmp, i );
347 impDestroy();
349 return( TRUE );
352 Bitmap* XDashList::CreateBitmapForUI( long nIndex, BOOL bDelete )
354 impCreate();
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()));
372 if(bDelete)
374 impDestroy();
377 return pBitmap;
380 //////////////////////////////////////////////////////////////////////////////
381 // eof