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: xtabgrdt.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"
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
;
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()
129 /************************************************************************/
131 BOOL
XGradientTable::Save()
136 /************************************************************************/
138 BOOL
XGradientTable::Create()
143 /************************************************************************/
145 BOOL
XGradientTable::CreateBitmapsForUI()
150 /************************************************************************/
152 Bitmap
* XGradientTable::CreateBitmapForUI( long /*nIndex*/, BOOL
/*bDelete*/)
157 // --------------------
158 // class XGradientList
159 // --------------------
161 class impXGradientList
164 VirtualDevice
* mpVirtualDevice
;
165 SdrModel
* mpSdrModel
;
166 SdrObject
* mpBackgroundObject
;
169 impXGradientList(VirtualDevice
* pV
, SdrModel
* pM
, SdrObject
* pB
)
170 : mpVirtualDevice(pV
),
172 mpBackgroundObject(pB
)
177 delete mpVirtualDevice
;
178 SdrObject::Free(mpBackgroundObject
);
182 VirtualDevice
* getVirtualDevice() const { return mpVirtualDevice
; }
183 SdrObject
* getBackgroundObject() const { return mpBackgroundObject
; }
186 void XGradientList::impCreate()
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
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()
230 XGradientList::XGradientList( const String
& rPath
, XOutdevItemPool
* pInPool
, sal_uInt16 nInitSize
, sal_uInt16 nReSize
)
231 : XPropertyList(rPath
, pInPool
, nInitSize
, nReSize
),
234 pBmpList
= new List(nInitSize
, nReSize
);
237 XGradientList::~XGradientList()
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()
267 INetURLObject
aURL( aPath
);
269 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
271 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
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
);
287 BOOL
XGradientList::Save()
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( 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
) );
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
));
328 BOOL
XGradientList::CreateBitmapsForUI()
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!" );
338 pBmpList
->Insert( pBmp
, i
);
346 Bitmap
* XGradientList::CreateBitmapForUI( long nIndex
, BOOL bDelete
)
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()));
374 //////////////////////////////////////////////////////////////////////////////