1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // include --------------------------------------------------------------- 28cdf0e10cSrcweir 29cdf0e10cSrcweir #ifndef SVX_LIGHT 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 32cdf0e10cSrcweir #include "svx/XPropertyTable.hxx" 33cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include "xmlxtexp.hxx" 36cdf0e10cSrcweir #include "xmlxtimp.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <tools/urlobj.hxx> 41cdf0e10cSrcweir #include <vcl/virdev.hxx> 42cdf0e10cSrcweir #include <svl/itemset.hxx> 43cdf0e10cSrcweir #include <sfx2/docfile.hxx> 44cdf0e10cSrcweir #include <svx/dialogs.hrc> 45cdf0e10cSrcweir #include <svx/dialmgr.hxx> 46cdf0e10cSrcweir #include <svx/xtable.hxx> 47cdf0e10cSrcweir #include <svx/xpool.hxx> 48cdf0e10cSrcweir #include <svx/xfillit0.hxx> 49cdf0e10cSrcweir #include <svx/xflgrit.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include <svx/svdorect.hxx> 52cdf0e10cSrcweir #include <svx/svdmodel.hxx> 53cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx> 54cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx> 55cdf0e10cSrcweir #include <vcl/svapp.hxx> 56cdf0e10cSrcweir #include <svx/xlnclit.hxx> 57cdf0e10cSrcweir #include <svx/xgrscit.hxx> 58cdf0e10cSrcweir 59cdf0e10cSrcweir #define GLOBALOVERFLOW 60cdf0e10cSrcweir 61cdf0e10cSrcweir using namespace com::sun::star; 62cdf0e10cSrcweir using namespace rtl; 63cdf0e10cSrcweir 64cdf0e10cSrcweir sal_Unicode const pszExtGradient[] = {'s','o','g'}; 65cdf0e10cSrcweir 66cdf0e10cSrcweir char const aChckGradient[] = { 0x04, 0x00, 'S','O','G','L'}; // < 5.2 67cdf0e10cSrcweir char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'}; // = 5.2 68cdf0e10cSrcweir char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 69cdf0e10cSrcweir 70cdf0e10cSrcweir // --------------------- 71cdf0e10cSrcweir // class XGradientTable 72cdf0e10cSrcweir // --------------------- 73cdf0e10cSrcweir 74cdf0e10cSrcweir /************************************************************************* 75cdf0e10cSrcweir |* 76cdf0e10cSrcweir |* XGradientTable::XGradientTable() 77cdf0e10cSrcweir |* 78cdf0e10cSrcweir *************************************************************************/ 79cdf0e10cSrcweir 80cdf0e10cSrcweir XGradientTable::XGradientTable( const String& rPath, 81cdf0e10cSrcweir XOutdevItemPool* pInPool, 82cdf0e10cSrcweir sal_uInt16 nInitSize, sal_uInt16 nReSize ) : 83cdf0e10cSrcweir XPropertyTable( rPath, pInPool, nInitSize, nReSize) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir pBmpTable = new Table( nInitSize, nReSize ); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir /************************************************************************/ 89cdf0e10cSrcweir 90cdf0e10cSrcweir XGradientTable::~XGradientTable() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir /************************************************************************/ 95cdf0e10cSrcweir 96cdf0e10cSrcweir XGradientEntry* XGradientTable::Replace(long nIndex, XGradientEntry* pEntry ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir return (XGradientEntry*) XPropertyTable::Replace(nIndex, pEntry); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir /************************************************************************/ 102cdf0e10cSrcweir 103cdf0e10cSrcweir XGradientEntry* XGradientTable::Remove(long nIndex) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir return (XGradientEntry*) XPropertyTable::Remove(nIndex, 0); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir /************************************************************************/ 109cdf0e10cSrcweir 110cdf0e10cSrcweir XGradientEntry* XGradientTable::GetGradient(long nIndex) const 111cdf0e10cSrcweir { 112cdf0e10cSrcweir return (XGradientEntry*) XPropertyTable::Get(nIndex, 0); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir /************************************************************************/ 116cdf0e10cSrcweir 117cdf0e10cSrcweir sal_Bool XGradientTable::Load() 118cdf0e10cSrcweir { 119cdf0e10cSrcweir return( sal_False ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir /************************************************************************/ 123cdf0e10cSrcweir 124cdf0e10cSrcweir sal_Bool XGradientTable::Save() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir return( sal_False ); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir /************************************************************************/ 130cdf0e10cSrcweir 131cdf0e10cSrcweir sal_Bool XGradientTable::Create() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir return( sal_False ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir /************************************************************************/ 137cdf0e10cSrcweir 138cdf0e10cSrcweir sal_Bool XGradientTable::CreateBitmapsForUI() 139cdf0e10cSrcweir { 140cdf0e10cSrcweir return( sal_False ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir /************************************************************************/ 144cdf0e10cSrcweir 145cdf0e10cSrcweir Bitmap* XGradientTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir return( NULL ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir // -------------------- 151cdf0e10cSrcweir // class XGradientList 152cdf0e10cSrcweir // -------------------- 153cdf0e10cSrcweir 154cdf0e10cSrcweir class impXGradientList 155cdf0e10cSrcweir { 156cdf0e10cSrcweir private: 157cdf0e10cSrcweir VirtualDevice* mpVirtualDevice; 158cdf0e10cSrcweir SdrModel* mpSdrModel; 159cdf0e10cSrcweir SdrObject* mpBackgroundObject; 160cdf0e10cSrcweir 161cdf0e10cSrcweir public: 162cdf0e10cSrcweir impXGradientList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB) 163cdf0e10cSrcweir : mpVirtualDevice(pV), 164cdf0e10cSrcweir mpSdrModel(pM), 165cdf0e10cSrcweir mpBackgroundObject(pB) 166cdf0e10cSrcweir {} 167cdf0e10cSrcweir 168cdf0e10cSrcweir ~impXGradientList() 169cdf0e10cSrcweir { 170cdf0e10cSrcweir delete mpVirtualDevice; 171cdf0e10cSrcweir SdrObject::Free(mpBackgroundObject); 172cdf0e10cSrcweir delete mpSdrModel; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; } 176cdf0e10cSrcweir SdrObject* getBackgroundObject() const { return mpBackgroundObject; } 177cdf0e10cSrcweir }; 178cdf0e10cSrcweir 179cdf0e10cSrcweir void XGradientList::impCreate() 180cdf0e10cSrcweir { 181cdf0e10cSrcweir if(!mpData) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir const Point aZero(0, 0); 184cdf0e10cSrcweir const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 185cdf0e10cSrcweir 186cdf0e10cSrcweir VirtualDevice* pVirDev = new VirtualDevice; 187cdf0e10cSrcweir OSL_ENSURE(0 != pVirDev, "XGradientList: no VirtualDevice created!" ); 188cdf0e10cSrcweir pVirDev->SetMapMode(MAP_100TH_MM); 189cdf0e10cSrcweir const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH, BITMAP_HEIGHT))); 190cdf0e10cSrcweir pVirDev->SetOutputSize(aSize); 191cdf0e10cSrcweir pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode() 192cdf0e10cSrcweir ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 193cdf0e10cSrcweir : DRAWMODE_DEFAULT); 194cdf0e10cSrcweir 195cdf0e10cSrcweir SdrModel* pSdrModel = new SdrModel(); 196cdf0e10cSrcweir OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" ); 197cdf0e10cSrcweir pSdrModel->GetItemPool().FreezeIdRanges(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1))); 200cdf0e10cSrcweir const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight())); 201cdf0e10cSrcweir SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize); 202cdf0e10cSrcweir OSL_ENSURE(0 != pBackgroundObject, "XGradientList: no BackgroundObject created!" ); 203cdf0e10cSrcweir pBackgroundObject->SetModel(pSdrModel); 204cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT)); 205cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID)); 206cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK))); 207cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((BITMAP_WIDTH + BITMAP_HEIGHT) / 3))); 208cdf0e10cSrcweir 209cdf0e10cSrcweir mpData = new impXGradientList(pVirDev, pSdrModel, pBackgroundObject); 210cdf0e10cSrcweir OSL_ENSURE(0 != mpData, "XGradientList: data creation went wrong!" ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir void XGradientList::impDestroy() 215cdf0e10cSrcweir { 216cdf0e10cSrcweir if(mpData) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir delete mpData; 219cdf0e10cSrcweir mpData = 0; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize) 224cdf0e10cSrcweir : XPropertyList(rPath, pInPool, nInitSize, nReSize), 225cdf0e10cSrcweir mpData(0) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir pBmpList = new List(nInitSize, nReSize); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir XGradientList::~XGradientList() 231cdf0e10cSrcweir { 232cdf0e10cSrcweir if(mpData) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir delete mpData; 235cdf0e10cSrcweir mpData = 0; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex ) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir XGradientEntry* XGradientList::Remove(long nIndex) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir return( (XGradientEntry*) XPropertyList::Remove( nIndex, 0 ) ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir XGradientEntry* XGradientList::GetGradient(long nIndex) const 250cdf0e10cSrcweir { 251cdf0e10cSrcweir return( (XGradientEntry*) XPropertyList::Get( nIndex, 0 ) ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir sal_Bool XGradientList::Load() 255cdf0e10cSrcweir { 256cdf0e10cSrcweir if( bListDirty ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir bListDirty = sal_False; 259cdf0e10cSrcweir 260cdf0e10cSrcweir INetURLObject aURL( aPath ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir DBG_ASSERT( !aPath.Len(), "invalid URL" ); 265cdf0e10cSrcweir return sal_False; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir aURL.Append( aName ); 269cdf0e10cSrcweir 270cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 271cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 274cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 275cdf0e10cSrcweir 276cdf0e10cSrcweir } 277cdf0e10cSrcweir return( sal_False ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir sal_Bool XGradientList::Save() 281cdf0e10cSrcweir { 282cdf0e10cSrcweir INetURLObject aURL( aPath ); 283cdf0e10cSrcweir 284cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir DBG_ASSERT( !aPath.Len(), "invalid URL" ); 287cdf0e10cSrcweir return sal_False; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir aURL.Append( aName ); 291cdf0e10cSrcweir 292cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 293cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) ); 294cdf0e10cSrcweir 295cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY ); 296cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir sal_Bool XGradientList::Create() 300cdf0e10cSrcweir { 301cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) ); 302cdf0e10cSrcweir xub_StrLen nLen; 303cdf0e10cSrcweir 304cdf0e10cSrcweir aStr.AppendAscii(" 1"); 305cdf0e10cSrcweir nLen = aStr.Len() - 1; 306cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK ),RGB_Color(COL_WHITE ),XGRAD_LINEAR , 0,10,10, 0,100,100),aStr)); 307cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2')); 308cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE ),RGB_Color(COL_RED ),XGRAD_AXIAL , 300,20,20,10,100,100),aStr)); 309cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3')); 310cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL , 600,30,30,20,100,100),aStr)); 311cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('4')); 312cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN ),XGRAD_ELLIPTICAL, 900,40,40,30,100,100),aStr)); 313cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('5')); 314cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE , 1200,50,50,40,100,100),aStr)); 315cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('6')); 316cdf0e10cSrcweir Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT , 1900,60,60,50,100,100),aStr)); 317cdf0e10cSrcweir 318cdf0e10cSrcweir return( sal_True ); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir sal_Bool XGradientList::CreateBitmapsForUI() 322cdf0e10cSrcweir { 323cdf0e10cSrcweir impCreate(); 324cdf0e10cSrcweir 325cdf0e10cSrcweir for( long i = 0; i < Count(); i++) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir Bitmap* pBmp = CreateBitmapForUI( i, sal_False ); 328cdf0e10cSrcweir DBG_ASSERT( pBmp, "XGradientList: Bitmap(UI) konnte nicht erzeugt werden!" ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir if( pBmp ) 331cdf0e10cSrcweir pBmpList->Insert( pBmp, i ); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir impDestroy(); 335cdf0e10cSrcweir 336cdf0e10cSrcweir return( sal_False ); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir Bitmap* XGradientList::CreateBitmapForUI( long nIndex, sal_Bool bDelete ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir impCreate(); 342cdf0e10cSrcweir VirtualDevice* pVD = mpData->getVirtualDevice(); 343cdf0e10cSrcweir SdrObject* pBackgroundObject = mpData->getBackgroundObject(); 344cdf0e10cSrcweir 345cdf0e10cSrcweir const SfxItemSet& rItemSet = pBackgroundObject->GetMergedItemSet(); 346cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT)); 347cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XFillGradientItem(rItemSet.GetPool(), GetGradient(nIndex)->GetGradient())); 348cdf0e10cSrcweir 349cdf0e10cSrcweir sdr::contact::SdrObjectVector aObjectVector; 350cdf0e10cSrcweir aObjectVector.push_back(pBackgroundObject); 351cdf0e10cSrcweir sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0); 352cdf0e10cSrcweir sdr::contact::DisplayInfo aDisplayInfo; 353cdf0e10cSrcweir 354cdf0e10cSrcweir aPainter.ProcessDisplay(aDisplayInfo); 355cdf0e10cSrcweir 356cdf0e10cSrcweir const Point aZero(0, 0); 357cdf0e10cSrcweir Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize())); 358cdf0e10cSrcweir 359cdf0e10cSrcweir if(bDelete) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir impDestroy(); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir return pBitmap; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 368cdf0e10cSrcweir // eof 369