merge the formfield patch from ooo-build
[ooovba.git] / svx / source / xoutdev / xtabhtch.cxx
blob90eba033e8ea4a57c27156748d64d239b980c5e4
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: xtabhtch.cxx,v $
10 * $Revision: 1.22 $
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>
41 #include <vcl/svapp.hxx>
43 #include "xmlxtexp.hxx"
44 #include "xmlxtimp.hxx"
46 #endif
48 #include <tools/urlobj.hxx>
49 #include <vcl/virdev.hxx>
50 #include <svtools/itemset.hxx>
51 #include <sfx2/docfile.hxx>
52 #include <svx/dialogs.hrc>
53 #include <svx/dialmgr.hxx>
54 #include <svx/xtable.hxx>
55 #include <svx/xpool.hxx>
56 #include "dlgutil.hxx"
57 #include <svx/xflhtit.hxx>
58 #include <svx/xflclit.hxx>
59 #include <svx/xfillit0.hxx>
61 #include <svx/svdorect.hxx>
62 #include <svx/svdmodel.hxx>
63 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
64 #include <svx/sdr/contact/displayinfo.hxx>
65 #include <svx/xlnclit.hxx>
67 using namespace ::com::sun::star;
68 using namespace ::rtl;
70 sal_Unicode const pszExtHatch[] = {'s','o','h'};
72 char const aChckHatch[] = { 0x04, 0x00, 'S','O','H','L'}; // < 5.2
73 char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'}; // = 5.2
74 char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
76 // ------------------
77 // class XHatchTable
78 // ------------------
80 /*************************************************************************
82 |* XHatchTable::XHatchTable()
84 *************************************************************************/
86 XHatchTable::XHatchTable( const String& rPath,
87 XOutdevItemPool* pInPool,
88 USHORT nInitSize, USHORT nReSize ) :
89 XPropertyTable( rPath, pInPool, nInitSize, nReSize)
91 pBmpTable = new Table( nInitSize, nReSize );
94 /************************************************************************/
96 XHatchTable::~XHatchTable()
100 /************************************************************************/
102 XHatchEntry* XHatchTable::Replace(long nIndex, XHatchEntry* pEntry )
104 return (XHatchEntry*) XPropertyTable::Replace(nIndex, pEntry);
107 /************************************************************************/
109 XHatchEntry* XHatchTable::Remove(long nIndex)
111 return (XHatchEntry*) XPropertyTable::Remove(nIndex, 0);
114 /************************************************************************/
116 XHatchEntry* XHatchTable::GetHatch(long nIndex) const
118 return (XHatchEntry*) XPropertyTable::Get(nIndex, 0);
121 /************************************************************************/
123 BOOL XHatchTable::Load()
125 return( FALSE );
128 /************************************************************************/
130 BOOL XHatchTable::Save()
132 return( FALSE );
135 /************************************************************************/
137 BOOL XHatchTable::Create()
139 return( FALSE );
142 /************************************************************************/
144 BOOL XHatchTable::CreateBitmapsForUI()
146 return( FALSE );
149 /************************************************************************/
151 Bitmap* XHatchTable::CreateBitmapForUI( long /*nIndex*/, BOOL /*bDelete*/)
153 return( NULL );
156 // -----------------
157 // class XHatchList
158 // -----------------
160 class impXHatchList
162 private:
163 VirtualDevice* mpVirtualDevice;
164 SdrModel* mpSdrModel;
165 SdrObject* mpBackgroundObject;
166 SdrObject* mpHatchObject;
168 public:
169 impXHatchList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pH)
170 : mpVirtualDevice(pV),
171 mpSdrModel(pM),
172 mpBackgroundObject(pB),
173 mpHatchObject(pH)
176 ~impXHatchList()
178 delete mpVirtualDevice;
179 SdrObject::Free(mpBackgroundObject);
180 SdrObject::Free(mpHatchObject);
181 delete mpSdrModel;
184 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
185 SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
186 SdrObject* getHatchObject() const { return mpHatchObject; }
189 void XHatchList::impCreate()
191 if(!mpData)
193 const Point aZero(0, 0);
194 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
196 VirtualDevice* pVirDev = new VirtualDevice;
197 OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
198 pVirDev->SetMapMode(MAP_100TH_MM);
199 const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH, BITMAP_HEIGHT)));
200 pVirDev->SetOutputSize(aSize);
201 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
202 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
203 : DRAWMODE_DEFAULT);
205 SdrModel* pSdrModel = new SdrModel();
206 OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
207 pSdrModel->GetItemPool().FreezeIdRanges();
209 const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1)));
210 const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
211 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
212 OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
213 pBackgroundObject->SetModel(pSdrModel);
214 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
215 pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
216 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
217 pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
219 SdrObject* pHatchObject = new SdrRectObj(aBackgroundSize);
220 OSL_ENSURE(0 != pHatchObject, "XDashList: no HatchObject created!" );
221 pHatchObject->SetModel(pSdrModel);
222 pHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
223 pHatchObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
225 mpData = new impXHatchList(pVirDev, pSdrModel, pBackgroundObject, pHatchObject);
226 OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
230 void XHatchList::impDestroy()
232 if(mpData)
234 delete mpData;
235 mpData = 0;
239 XHatchList::XHatchList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
240 : XPropertyList(rPath, pInPool, nInitSize, nReSize),
241 mpData(0)
243 pBmpList = new List(nInitSize, nReSize);
246 XHatchList::~XHatchList()
248 if(mpData)
250 delete mpData;
251 mpData = 0;
255 XHatchEntry* XHatchList::Replace(XHatchEntry* pEntry, long nIndex )
257 return (XHatchEntry*) XPropertyList::Replace(pEntry, nIndex);
260 XHatchEntry* XHatchList::Remove(long nIndex)
262 return (XHatchEntry*) XPropertyList::Remove(nIndex, 0);
265 XHatchEntry* XHatchList::GetHatch(long nIndex) const
267 return (XHatchEntry*) XPropertyList::Get(nIndex, 0);
270 BOOL XHatchList::Load()
272 if( bListDirty )
274 bListDirty = FALSE;
276 INetURLObject aURL( aPath );
278 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
280 DBG_ASSERT( !aPath.Len(), "invalid URL" );
281 return FALSE;
284 aURL.Append( aName );
286 if( !aURL.getExtension().getLength() )
287 aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
289 uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
290 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
292 return( FALSE );
295 BOOL XHatchList::Save()
297 INetURLObject aURL( aPath );
299 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
301 DBG_ASSERT( !aPath.Len(), "invalid URL" );
302 return FALSE;
305 aURL.Append( aName );
307 if( !aURL.getExtension().getLength() )
308 aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
310 uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
311 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
314 BOOL XHatchList::Create()
316 XubString aStr( SVX_RES( RID_SVXSTR_HATCH ) );
317 xub_StrLen nLen;
319 aStr.AppendAscii(" 1");
320 nLen = aStr.Len() - 1;
321 Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100, 0),aStr));
322 aStr.SetChar(nLen, sal_Unicode('2'));
323 Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED ),XHATCH_DOUBLE, 80,450),aStr));
324 aStr.SetChar(nLen, sal_Unicode('3'));
325 Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120, 0),aStr));
327 return( TRUE );
330 BOOL XHatchList::CreateBitmapsForUI()
332 impCreate();
334 for( long i = 0; i < Count(); i++)
336 Bitmap* pBmp = CreateBitmapForUI( i, FALSE );
337 DBG_ASSERT( pBmp, "XHatchList: Bitmap(UI) konnte nicht erzeugt werden!" );
339 if( pBmp )
340 pBmpList->Insert( pBmp, i );
343 impDestroy();
345 return( TRUE );
348 Bitmap* XHatchList::CreateBitmapForUI( long nIndex, BOOL bDelete )
350 impCreate();
351 VirtualDevice* pVD = mpData->getVirtualDevice();
352 SdrObject* pHatchObject = mpData->getHatchObject();
354 pHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
355 pHatchObject->SetMergedItem(XFillHatchItem(String(), GetHatch(nIndex)->GetHatch()));
357 sdr::contact::SdrObjectVector aObjectVector;
358 aObjectVector.push_back(mpData->getBackgroundObject());
359 aObjectVector.push_back(pHatchObject);
360 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
361 sdr::contact::DisplayInfo aDisplayInfo;
363 aPainter.ProcessDisplay(aDisplayInfo);
365 const Point aZero(0, 0);
366 Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
368 if(bDelete)
370 impDestroy();
373 return pBitmap;
376 //////////////////////////////////////////////////////////////////////////////
377 // eof