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> 37*35726d9dSArmin Le Grand #include <drawinglayer/attribute/fillgradientattribute.hxx> 38*35726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 39*35726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 40*35726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx> 41*35726d9dSArmin 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 57c7be74b1SArmin Le Grand XGradientList::XGradientList( const String& rPath ) 58*35726d9dSArmin Le Grand : XPropertyList(rPath ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir XGradientList::~XGradientList() 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) ); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir XGradientEntry* XGradientList::Remove(long nIndex) 72cdf0e10cSrcweir { 73c7be74b1SArmin Le Grand return( (XGradientEntry*) XPropertyList::Remove( nIndex ) ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir XGradientEntry* XGradientList::GetGradient(long nIndex) const 77cdf0e10cSrcweir { 78c7be74b1SArmin Le Grand return( (XGradientEntry*) XPropertyList::Get( nIndex ) ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir sal_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" ); 92cdf0e10cSrcweir return sal_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 } 104cdf0e10cSrcweir return( sal_False ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir sal_Bool XGradientList::Save() 108cdf0e10cSrcweir { 10997e8a929SArmin Le Grand INetURLObject aURL( maPath ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 112cdf0e10cSrcweir { 11397e8a929SArmin Le Grand DBG_ASSERT( !maPath.Len(), "invalid URL" ); 114cdf0e10cSrcweir return sal_False; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 11797e8a929SArmin Le Grand aURL.Append( maName ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 120cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 123cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir sal_Bool XGradientList::Create() 127cdf0e10cSrcweir { 128cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) ); 129cdf0e10cSrcweir xub_StrLen nLen; 130cdf0e10cSrcweir 131cdf0e10cSrcweir aStr.AppendAscii(" 1"); 132cdf0e10cSrcweir nLen = aStr.Len() - 1; 133cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr)); 134cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2')); 135cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr)); 136cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3')); 137cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr)); 138cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('4')); 139cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr)); 140cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('5')); 141cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr)); 142cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('6')); 143cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr)); 144cdf0e10cSrcweir 145cdf0e10cSrcweir return( sal_True ); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 14897e8a929SArmin Le Grand Bitmap XGradientList::CreateBitmapForUI(long nIndex) 149cdf0e10cSrcweir { 150c7be74b1SArmin Le Grand Bitmap aRetval; 151*35726d9dSArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); 152cdf0e10cSrcweir 153*35726d9dSArmin Le Grand if(nIndex < Count()) 154c7be74b1SArmin Le Grand { 155c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 156c7be74b1SArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 157c7be74b1SArmin Le Grand 158*35726d9dSArmin Le Grand // prepare polygon geometry for rectangle 159*35726d9dSArmin Le Grand const basegfx::B2DPolygon aRectangle( 160*35726d9dSArmin Le Grand basegfx::tools::createPolygonFromRect( 161*35726d9dSArmin Le Grand basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height()))); 162c7be74b1SArmin Le Grand 163*35726d9dSArmin Le Grand const XGradient& rGradient = GetGradient(nIndex)->GetGradient(); 164*35726d9dSArmin Le Grand const sal_uInt16 nStartIntens(rGradient.GetStartIntens()); 165*35726d9dSArmin Le Grand basegfx::BColor aStart(rGradient.GetStartColor().getBColor()); 166*35726d9dSArmin Le Grand 167*35726d9dSArmin Le Grand if(nStartIntens != 100) 168c7be74b1SArmin Le Grand { 169*35726d9dSArmin Le Grand const basegfx::BColor aBlack; 170*35726d9dSArmin Le Grand aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01); 171c7be74b1SArmin Le Grand } 172c7be74b1SArmin Le Grand 173*35726d9dSArmin Le Grand const sal_uInt16 nEndIntens(rGradient.GetEndIntens()); 174*35726d9dSArmin Le Grand basegfx::BColor aEnd(rGradient.GetEndColor().getBColor()); 175c7be74b1SArmin Le Grand 176*35726d9dSArmin Le Grand if(nEndIntens != 100) 177*35726d9dSArmin Le Grand { 178*35726d9dSArmin Le Grand const basegfx::BColor aBlack; 179*35726d9dSArmin Le Grand aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01); 180*35726d9dSArmin Le Grand } 181cdf0e10cSrcweir 182*35726d9dSArmin Le Grand drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT); 183c7be74b1SArmin Le Grand 184*35726d9dSArmin Le Grand switch(rGradient.GetGradientStyle()) 185*35726d9dSArmin Le Grand { 186*35726d9dSArmin Le Grand case XGRAD_LINEAR : 187*35726d9dSArmin Le Grand { 188*35726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR; 189*35726d9dSArmin Le Grand break; 190*35726d9dSArmin Le Grand } 191*35726d9dSArmin Le Grand case XGRAD_AXIAL : 192*35726d9dSArmin Le Grand { 193*35726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL; 194*35726d9dSArmin Le Grand break; 195*35726d9dSArmin Le Grand } 196*35726d9dSArmin Le Grand case XGRAD_RADIAL : 197*35726d9dSArmin Le Grand { 198*35726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL; 199*35726d9dSArmin Le Grand break; 200*35726d9dSArmin Le Grand } 201*35726d9dSArmin Le Grand case XGRAD_ELLIPTICAL : 202*35726d9dSArmin Le Grand { 203*35726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL; 204*35726d9dSArmin Le Grand break; 205*35726d9dSArmin Le Grand } 206*35726d9dSArmin Le Grand case XGRAD_SQUARE : 207*35726d9dSArmin Le Grand { 208*35726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE; 209*35726d9dSArmin Le Grand break; 210*35726d9dSArmin Le Grand } 211*35726d9dSArmin Le Grand default : 212*35726d9dSArmin Le Grand { 213*35726d9dSArmin Le Grand aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT 214*35726d9dSArmin Le Grand break; 215*35726d9dSArmin Le Grand } 216*35726d9dSArmin Le Grand } 217c7be74b1SArmin Le Grand 218*35726d9dSArmin Le Grand const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3); 219*35726d9dSArmin Le Grand const drawinglayer::attribute::FillGradientAttribute aFillGradient( 220*35726d9dSArmin Le Grand aGradientStyle, 221*35726d9dSArmin Le Grand (double)rGradient.GetBorder() * 0.01, 222*35726d9dSArmin Le Grand (double)rGradient.GetXOffset() * 0.01, 223*35726d9dSArmin Le Grand (double)rGradient.GetYOffset() * 0.01, 224*35726d9dSArmin Le Grand (double)rGradient.GetAngle() * F_PI1800, 225*35726d9dSArmin Le Grand aStart, 226*35726d9dSArmin Le Grand aEnd, 227*35726d9dSArmin Le Grand nSteps); 228cdf0e10cSrcweir 229*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive( 230*35726d9dSArmin Le Grand new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D( 231*35726d9dSArmin Le Grand basegfx::B2DPolyPolygon(aRectangle), 232*35726d9dSArmin Le Grand aFillGradient)); 233cdf0e10cSrcweir 234*35726d9dSArmin Le Grand const basegfx::BColor aBlack(0.0, 0.0, 0.0); 235*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive( 236*35726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonHairlinePrimitive2D( 237*35726d9dSArmin Le Grand aRectangle, 238*35726d9dSArmin Le Grand aBlack)); 239c7be74b1SArmin Le Grand 240*35726d9dSArmin Le Grand // prepare VirtualDevice 241*35726d9dSArmin Le Grand VirtualDevice aVirtualDevice; 242*35726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 243*35726d9dSArmin Le Grand 244*35726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(rSize); 245*35726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 246*35726d9dSArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 247*35726d9dSArmin Le Grand : DRAWMODE_DEFAULT); 248*35726d9dSArmin Le Grand 249*35726d9dSArmin Le Grand // create processor and draw primitives 250*35726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 251*35726d9dSArmin Le Grand aVirtualDevice, 252*35726d9dSArmin Le Grand aNewViewInformation2D); 253*35726d9dSArmin Le Grand 254*35726d9dSArmin Le Grand if(pProcessor2D) 255*35726d9dSArmin Le Grand { 256*35726d9dSArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aSequence(2); 257*35726d9dSArmin Le Grand 258*35726d9dSArmin Le Grand aSequence[0] = aGradientPrimitive; 259*35726d9dSArmin Le Grand aSequence[1] = aBlackRectanglePrimitive; 260*35726d9dSArmin Le Grand 261*35726d9dSArmin Le Grand pProcessor2D->process(aSequence); 262*35726d9dSArmin Le Grand delete pProcessor2D; 263*35726d9dSArmin Le Grand } 264*35726d9dSArmin Le Grand 265*35726d9dSArmin Le Grand // get result bitmap and scale 266*35726d9dSArmin Le Grand aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); 267c7be74b1SArmin Le Grand } 268c7be74b1SArmin Le Grand 269c7be74b1SArmin Le Grand return aRetval; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 273cdf0e10cSrcweir // eof 274