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