Update ooo320-m1
[ooovba.git] / svx / source / xoutdev / xtabgrdt.cxx
blob4f43f10ce229a5aad6c6e99f6bc3de42b9e431b0
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: xtabgrdt.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
47 #include <tools/urlobj.hxx>
48 #include <vcl/virdev.hxx>
49 #include <svtools/itemset.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <svx/dialogs.hrc>
52 #include <svx/dialmgr.hxx>
53 #include <svx/xtable.hxx>
54 #include <svx/xpool.hxx>
55 #include <svx/xfillit0.hxx>
56 #include <svx/xflgrit.hxx>
58 #include <svx/svdorect.hxx>
59 #include <svx/svdmodel.hxx>
60 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
61 #include <svx/sdr/contact/displayinfo.hxx>
62 #include <vcl/svapp.hxx>
63 #include <svx/xlnclit.hxx>
64 #include <svx/xgrscit.hxx>
66 #define GLOBALOVERFLOW
68 using namespace com::sun::star;
69 using namespace rtl;
71 sal_Unicode const pszExtGradient[] = {'s','o','g'};
73 char const aChckGradient[] = { 0x04, 0x00, 'S','O','G','L'}; // < 5.2
74 char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'}; // = 5.2
75 char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
77 // ---------------------
78 // class XGradientTable
79 // ---------------------
81 /*************************************************************************
83 |* XGradientTable::XGradientTable()
85 *************************************************************************/
87 XGradientTable::XGradientTable( const String& rPath,
88 XOutdevItemPool* pInPool,
89 USHORT nInitSize, USHORT nReSize ) :
90 XPropertyTable( rPath, pInPool, nInitSize, nReSize)
92 pBmpTable = new Table( nInitSize, nReSize );
95 /************************************************************************/
97 XGradientTable::~XGradientTable()
101 /************************************************************************/
103 XGradientEntry* XGradientTable::Replace(long nIndex, XGradientEntry* pEntry )
105 return (XGradientEntry*) XPropertyTable::Replace(nIndex, pEntry);
108 /************************************************************************/
110 XGradientEntry* XGradientTable::Remove(long nIndex)
112 return (XGradientEntry*) XPropertyTable::Remove(nIndex, 0);
115 /************************************************************************/
117 XGradientEntry* XGradientTable::GetGradient(long nIndex) const
119 return (XGradientEntry*) XPropertyTable::Get(nIndex, 0);
122 /************************************************************************/
124 BOOL XGradientTable::Load()
126 return( FALSE );
129 /************************************************************************/
131 BOOL XGradientTable::Save()
133 return( FALSE );
136 /************************************************************************/
138 BOOL XGradientTable::Create()
140 return( FALSE );
143 /************************************************************************/
145 BOOL XGradientTable::CreateBitmapsForUI()
147 return( FALSE );
150 /************************************************************************/
152 Bitmap* XGradientTable::CreateBitmapForUI( long /*nIndex*/, BOOL /*bDelete*/)
154 return( NULL );
157 // --------------------
158 // class XGradientList
159 // --------------------
161 class impXGradientList
163 private:
164 VirtualDevice* mpVirtualDevice;
165 SdrModel* mpSdrModel;
166 SdrObject* mpBackgroundObject;
168 public:
169 impXGradientList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB)
170 : mpVirtualDevice(pV),
171 mpSdrModel(pM),
172 mpBackgroundObject(pB)
175 ~impXGradientList()
177 delete mpVirtualDevice;
178 SdrObject::Free(mpBackgroundObject);
179 delete mpSdrModel;
182 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
183 SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
186 void XGradientList::impCreate()
188 if(!mpData)
190 const Point aZero(0, 0);
191 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
193 VirtualDevice* pVirDev = new VirtualDevice;
194 OSL_ENSURE(0 != pVirDev, "XGradientList: no VirtualDevice created!" );
195 pVirDev->SetMapMode(MAP_100TH_MM);
196 const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH, BITMAP_HEIGHT)));
197 pVirDev->SetOutputSize(aSize);
198 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
199 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
200 : DRAWMODE_DEFAULT);
202 SdrModel* pSdrModel = new SdrModel();
203 OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" );
204 pSdrModel->GetItemPool().FreezeIdRanges();
206 const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1)));
207 const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
208 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
209 OSL_ENSURE(0 != pBackgroundObject, "XGradientList: no BackgroundObject created!" );
210 pBackgroundObject->SetModel(pSdrModel);
211 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
212 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
213 pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
214 pBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((BITMAP_WIDTH + BITMAP_HEIGHT) / 3)));
216 mpData = new impXGradientList(pVirDev, pSdrModel, pBackgroundObject);
217 OSL_ENSURE(0 != mpData, "XGradientList: data creation went wrong!" );
221 void XGradientList::impDestroy()
223 if(mpData)
225 delete mpData;
226 mpData = 0;
230 XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
231 : XPropertyList(rPath, pInPool, nInitSize, nReSize),
232 mpData(0)
234 pBmpList = new List(nInitSize, nReSize);
237 XGradientList::~XGradientList()
239 if(mpData)
241 delete mpData;
242 mpData = 0;
246 XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
248 return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) );
251 XGradientEntry* XGradientList::Remove(long nIndex)
253 return( (XGradientEntry*) XPropertyList::Remove( nIndex, 0 ) );
256 XGradientEntry* XGradientList::GetGradient(long nIndex) const
258 return( (XGradientEntry*) XPropertyList::Get( nIndex, 0 ) );
261 BOOL XGradientList::Load()
263 if( bListDirty )
265 bListDirty = FALSE;
267 INetURLObject aURL( aPath );
269 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
271 DBG_ASSERT( !aPath.Len(), "invalid URL" );
272 return FALSE;
275 aURL.Append( aName );
277 if( !aURL.getExtension().getLength() )
278 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) );
280 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
281 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
284 return( FALSE );
287 BOOL XGradientList::Save()
289 INetURLObject aURL( aPath );
291 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
293 DBG_ASSERT( !aPath.Len(), "invalid URL" );
294 return FALSE;
297 aURL.Append( aName );
299 if( !aURL.getExtension().getLength() )
300 aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) );
302 uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
303 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
306 BOOL XGradientList::Create()
308 XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) );
309 xub_StrLen nLen;
311 aStr.AppendAscii(" 1");
312 nLen = aStr.Len() - 1;
313 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr));
314 aStr.SetChar(nLen, sal_Unicode('2'));
315 Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr));
316 aStr.SetChar(nLen, sal_Unicode('3'));
317 Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr));
318 aStr.SetChar(nLen, sal_Unicode('4'));
319 Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr));
320 aStr.SetChar(nLen, sal_Unicode('5'));
321 Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr));
322 aStr.SetChar(nLen, sal_Unicode('6'));
323 Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr));
325 return( TRUE );
328 BOOL XGradientList::CreateBitmapsForUI()
330 impCreate();
332 for( long i = 0; i < Count(); i++)
334 Bitmap* pBmp = CreateBitmapForUI( i, FALSE );
335 DBG_ASSERT( pBmp, "XGradientList: Bitmap(UI) konnte nicht erzeugt werden!" );
337 if( pBmp )
338 pBmpList->Insert( pBmp, i );
341 impDestroy();
343 return( FALSE );
346 Bitmap* XGradientList::CreateBitmapForUI( long nIndex, BOOL bDelete )
348 impCreate();
349 VirtualDevice* pVD = mpData->getVirtualDevice();
350 SdrObject* pBackgroundObject = mpData->getBackgroundObject();
352 const SfxItemSet& rItemSet = pBackgroundObject->GetMergedItemSet();
353 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
354 pBackgroundObject->SetMergedItem(XFillGradientItem(rItemSet.GetPool(), GetGradient(nIndex)->GetGradient()));
356 sdr::contact::SdrObjectVector aObjectVector;
357 aObjectVector.push_back(pBackgroundObject);
358 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
359 sdr::contact::DisplayInfo aDisplayInfo;
361 aPainter.ProcessDisplay(aDisplayInfo);
363 const Point aZero(0, 0);
364 Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
366 if(bDelete)
368 impDestroy();
371 return pBitmap;
374 //////////////////////////////////////////////////////////////////////////////
375 // eof