1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5f6e50924SAndrew Rist * distributed with this work for additional information
6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist * software distributed under the License is distributed on an
15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17f6e50924SAndrew Rist * specific language governing permissions and limitations
18f6e50924SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20f6e50924SAndrew Rist *************************************************************/
21f6e50924SAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir // include ---------------------------------------------------------------
26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
27cdf0e10cSrcweir #include "svx/XPropertyTable.hxx"
28cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
29cdf0e10cSrcweir #include "xmlxtexp.hxx"
30cdf0e10cSrcweir #include "xmlxtimp.hxx"
31cdf0e10cSrcweir #include <tools/urlobj.hxx>
32cdf0e10cSrcweir #include <vcl/virdev.hxx>
33cdf0e10cSrcweir #include <svx/dialogs.hrc>
34cdf0e10cSrcweir #include <svx/dialmgr.hxx>
35cdf0e10cSrcweir #include <svx/xtable.hxx>
36cdf0e10cSrcweir #include <vcl/svapp.hxx>
3735726d9dSArmin Le Grand #include <drawinglayer/attribute/fillgradientattribute.hxx>
3835726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
3935726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
4035726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx>
4135726d9dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #define GLOBALOVERFLOW
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace com::sun::star;
46cdf0e10cSrcweir using namespace rtl;
47cdf0e10cSrcweir
48cdf0e10cSrcweir sal_Unicode const pszExtGradient[] = {'s','o','g'};
49c7be74b1SArmin Le Grand //char const aChckGradient[] = { 0x04, 0x00, 'S','O','G','L'}; // < 5.2
50c7be74b1SArmin Le Grand //char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'}; // = 5.2
51c7be74b1SArmin Le Grand //char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
52cdf0e10cSrcweir
53cdf0e10cSrcweir // --------------------
54cdf0e10cSrcweir // class XGradientList
55cdf0e10cSrcweir // --------------------
56cdf0e10cSrcweir
XGradientList(const String & rPath)57c7be74b1SArmin Le Grand XGradientList::XGradientList( const String& rPath )
5835726d9dSArmin Le Grand : XPropertyList(rPath )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
~XGradientList()62cdf0e10cSrcweir XGradientList::~XGradientList()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
Replace(XGradientEntry * pEntry,long nIndex)66cdf0e10cSrcweir XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
Remove(long nIndex)71cdf0e10cSrcweir XGradientEntry* XGradientList::Remove(long nIndex)
72cdf0e10cSrcweir {
73c7be74b1SArmin Le Grand return( (XGradientEntry*) XPropertyList::Remove( nIndex ) );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
GetGradient(long nIndex) const76cdf0e10cSrcweir XGradientEntry* XGradientList::GetGradient(long nIndex) const
77cdf0e10cSrcweir {
78c7be74b1SArmin Le Grand return( (XGradientEntry*) XPropertyList::Get( nIndex ) );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
Load()81*3e407bd8SArmin Le Grand bool XGradientList::Load()
82cdf0e10cSrcweir {
8397e8a929SArmin Le Grand if( mbListDirty )
84cdf0e10cSrcweir {
8597e8a929SArmin Le Grand mbListDirty = false;
86cdf0e10cSrcweir
8797e8a929SArmin Le Grand INetURLObject aURL( maPath );
88cdf0e10cSrcweir
89cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
90cdf0e10cSrcweir {
9197e8a929SArmin Le Grand DBG_ASSERT( !maPath.Len(), "invalid URL" );
92*3e407bd8SArmin Le Grand return false;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
9597e8a929SArmin Le Grand aURL.Append( maName );
96cdf0e10cSrcweir
97cdf0e10cSrcweir if( !aURL.getExtension().getLength() )
98cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) );
99cdf0e10cSrcweir
100cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
101cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
102cdf0e10cSrcweir
103cdf0e10cSrcweir }
104*3e407bd8SArmin Le Grand
105*3e407bd8SArmin Le Grand return false;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
Save()108*3e407bd8SArmin Le Grand bool XGradientList::Save()
109cdf0e10cSrcweir {
11097e8a929SArmin Le Grand INetURLObject aURL( maPath );
111cdf0e10cSrcweir
112cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
113cdf0e10cSrcweir {
11497e8a929SArmin Le Grand DBG_ASSERT( !maPath.Len(), "invalid URL" );
115*3e407bd8SArmin Le Grand return false;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
11897e8a929SArmin Le Grand aURL.Append( maName );
119cdf0e10cSrcweir
120cdf0e10cSrcweir if( !aURL.getExtension().getLength() )
121cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) );
122cdf0e10cSrcweir
123cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
124cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
Create()127*3e407bd8SArmin Le Grand bool XGradientList::Create()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) );
130cdf0e10cSrcweir xub_StrLen nLen;
131cdf0e10cSrcweir
132cdf0e10cSrcweir aStr.AppendAscii(" 1");
133cdf0e10cSrcweir nLen = aStr.Len() - 1;
134cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr));
135cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2'));
136cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr));
137cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3'));
138cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr));
139cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('4'));
140cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr));
141cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('5'));
142cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr));
143cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('6'));
144cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr));
145cdf0e10cSrcweir
146*3e407bd8SArmin Le Grand return true;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
CreateBitmapForUI(long nIndex)14997e8a929SArmin Le Grand Bitmap XGradientList::CreateBitmapForUI(long nIndex)
150cdf0e10cSrcweir {
151c7be74b1SArmin Le Grand Bitmap aRetval;
15235726d9dSArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
153cdf0e10cSrcweir
15435726d9dSArmin Le Grand if(nIndex < Count())
155c7be74b1SArmin Le Grand {
156c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
157c7be74b1SArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
158c7be74b1SArmin Le Grand
15935726d9dSArmin Le Grand // prepare polygon geometry for rectangle
16035726d9dSArmin Le Grand const basegfx::B2DPolygon aRectangle(
16135726d9dSArmin Le Grand basegfx::tools::createPolygonFromRect(
16235726d9dSArmin Le Grand basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
163c7be74b1SArmin Le Grand
16435726d9dSArmin Le Grand const XGradient& rGradient = GetGradient(nIndex)->GetGradient();
16535726d9dSArmin Le Grand const sal_uInt16 nStartIntens(rGradient.GetStartIntens());
16635726d9dSArmin Le Grand basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
16735726d9dSArmin Le Grand
16835726d9dSArmin Le Grand if(nStartIntens != 100)
169c7be74b1SArmin Le Grand {
17035726d9dSArmin Le Grand const basegfx::BColor aBlack;
17135726d9dSArmin Le Grand aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01);
172c7be74b1SArmin Le Grand }
173c7be74b1SArmin Le Grand
17435726d9dSArmin Le Grand const sal_uInt16 nEndIntens(rGradient.GetEndIntens());
17535726d9dSArmin Le Grand basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
176c7be74b1SArmin Le Grand
17735726d9dSArmin Le Grand if(nEndIntens != 100)
17835726d9dSArmin Le Grand {
17935726d9dSArmin Le Grand const basegfx::BColor aBlack;
18035726d9dSArmin Le Grand aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01);
18135726d9dSArmin Le Grand }
182cdf0e10cSrcweir
18335726d9dSArmin Le Grand drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT);
184c7be74b1SArmin Le Grand
18535726d9dSArmin Le Grand switch(rGradient.GetGradientStyle())
18635726d9dSArmin Le Grand {
18735726d9dSArmin Le Grand case XGRAD_LINEAR :
18835726d9dSArmin Le Grand {
18935726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR;
19035726d9dSArmin Le Grand break;
19135726d9dSArmin Le Grand }
19235726d9dSArmin Le Grand case XGRAD_AXIAL :
19335726d9dSArmin Le Grand {
19435726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL;
19535726d9dSArmin Le Grand break;
19635726d9dSArmin Le Grand }
19735726d9dSArmin Le Grand case XGRAD_RADIAL :
19835726d9dSArmin Le Grand {
19935726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL;
20035726d9dSArmin Le Grand break;
20135726d9dSArmin Le Grand }
20235726d9dSArmin Le Grand case XGRAD_ELLIPTICAL :
20335726d9dSArmin Le Grand {
20435726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL;
20535726d9dSArmin Le Grand break;
20635726d9dSArmin Le Grand }
20735726d9dSArmin Le Grand case XGRAD_SQUARE :
20835726d9dSArmin Le Grand {
20935726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE;
21035726d9dSArmin Le Grand break;
21135726d9dSArmin Le Grand }
21235726d9dSArmin Le Grand default :
21335726d9dSArmin Le Grand {
21435726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT
21535726d9dSArmin Le Grand break;
21635726d9dSArmin Le Grand }
21735726d9dSArmin Le Grand }
218c7be74b1SArmin Le Grand
21935726d9dSArmin Le Grand const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3);
22035726d9dSArmin Le Grand const drawinglayer::attribute::FillGradientAttribute aFillGradient(
22135726d9dSArmin Le Grand aGradientStyle,
22235726d9dSArmin Le Grand (double)rGradient.GetBorder() * 0.01,
22335726d9dSArmin Le Grand (double)rGradient.GetXOffset() * 0.01,
22435726d9dSArmin Le Grand (double)rGradient.GetYOffset() * 0.01,
22535726d9dSArmin Le Grand (double)rGradient.GetAngle() * F_PI1800,
22635726d9dSArmin Le Grand aStart,
22735726d9dSArmin Le Grand aEnd,
22835726d9dSArmin Le Grand nSteps);
229cdf0e10cSrcweir
23035726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
23135726d9dSArmin Le Grand new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(
23235726d9dSArmin Le Grand basegfx::B2DPolyPolygon(aRectangle),
23335726d9dSArmin Le Grand aFillGradient));
234cdf0e10cSrcweir
23535726d9dSArmin Le Grand const basegfx::BColor aBlack(0.0, 0.0, 0.0);
23635726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
23735726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
23835726d9dSArmin Le Grand aRectangle,
23935726d9dSArmin Le Grand aBlack));
240c7be74b1SArmin Le Grand
24135726d9dSArmin Le Grand // prepare VirtualDevice
24235726d9dSArmin Le Grand VirtualDevice aVirtualDevice;
24335726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
24435726d9dSArmin Le Grand
24535726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(rSize);
24635726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode()
24735726d9dSArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
24835726d9dSArmin Le Grand : DRAWMODE_DEFAULT);
24935726d9dSArmin Le Grand
25035726d9dSArmin Le Grand // create processor and draw primitives
25135726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
25235726d9dSArmin Le Grand aVirtualDevice,
25335726d9dSArmin Le Grand aNewViewInformation2D);
25435726d9dSArmin Le Grand
25535726d9dSArmin Le Grand if(pProcessor2D)
25635726d9dSArmin Le Grand {
25735726d9dSArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aSequence(2);
25835726d9dSArmin Le Grand
25935726d9dSArmin Le Grand aSequence[0] = aGradientPrimitive;
26035726d9dSArmin Le Grand aSequence[1] = aBlackRectanglePrimitive;
26135726d9dSArmin Le Grand
26235726d9dSArmin Le Grand pProcessor2D->process(aSequence);
26335726d9dSArmin Le Grand delete pProcessor2D;
26435726d9dSArmin Le Grand }
26535726d9dSArmin Le Grand
26635726d9dSArmin Le Grand // get result bitmap and scale
26735726d9dSArmin Le Grand aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel());
268c7be74b1SArmin Le Grand }
269c7be74b1SArmin Le Grand
270c7be74b1SArmin Le Grand return aRetval;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
274cdf0e10cSrcweir // eof
275