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 #include <vcl/svapp.hxx> 44 45 #include <tools/urlobj.hxx> 46 #include <vcl/virdev.hxx> 47 #include <vcl/window.hxx> 48 #include <svl/itemset.hxx> 49 #include <sfx2/docfile.hxx> 50 #include <svx/dialogs.hrc> 51 #include <svx/dialmgr.hxx> 52 #include <svx/xtable.hxx> 53 #include <svx/xpool.hxx> 54 #include <svx/xlineit0.hxx> 55 #include <svx/xlnclit.hxx> 56 #include <svx/xlnwtit.hxx> 57 #include <svx/xlndsit.hxx> 58 #include <svx/xflclit.hxx> 59 60 #include <svx/svdorect.hxx> 61 #include <svx/svdopath.hxx> 62 #include <svx/svdmodel.hxx> 63 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx> 64 #include <svx/sdr/contact/displayinfo.hxx> 65 #include <basegfx/polygon/b2dpolygon.hxx> 66 67 using namespace com::sun::star; 68 using namespace rtl; 69 70 #define GLOBALOVERFLOW 71 72 sal_Unicode const pszExtDash[] = {'s','o','d'}; 73 char const aChckDash[] = { 0x04, 0x00, 'S','O','D','L'}; // < 5.2 74 char const aChckDash0[] = { 0x04, 0x00, 'S','O','D','0'}; // = 5.2 75 char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 76 77 // ----------------- 78 // class XDashTable 79 // ----------------- 80 81 /************************************************************************* 82 |* 83 |* XDashTable::XDashTable() 84 |* 85 *************************************************************************/ 86 87 XDashTable::XDashTable( const String& rPath, 88 XOutdevItemPool* pInPool, 89 sal_uInt16 nInitSize, sal_uInt16 nReSize ) : 90 XPropertyTable( rPath, pInPool, nInitSize, nReSize) 91 { 92 pBmpTable = new Table( nInitSize, nReSize ); 93 } 94 95 /************************************************************************/ 96 97 XDashTable::~XDashTable() 98 { 99 } 100 101 /************************************************************************/ 102 103 XDashEntry* XDashTable::Replace(long nIndex, XDashEntry* pEntry ) 104 { 105 return (XDashEntry*) XPropertyTable::Replace(nIndex, pEntry); 106 } 107 108 /************************************************************************/ 109 110 XDashEntry* XDashTable::Remove(long nIndex) 111 { 112 return (XDashEntry*) XPropertyTable::Remove(nIndex, 0); 113 } 114 115 /************************************************************************/ 116 117 XDashEntry* XDashTable::GetDash(long nIndex) const 118 { 119 return (XDashEntry*) XPropertyTable::Get(nIndex, 0); 120 } 121 122 /************************************************************************/ 123 124 sal_Bool XDashTable::Load() 125 { 126 return( sal_False ); 127 } 128 129 /************************************************************************/ 130 131 sal_Bool XDashTable::Save() 132 { 133 return( sal_False ); 134 } 135 136 /************************************************************************/ 137 138 sal_Bool XDashTable::Create() 139 { 140 return( sal_False ); 141 } 142 143 /************************************************************************/ 144 145 sal_Bool XDashTable::CreateBitmapsForUI() 146 { 147 return( sal_False ); 148 } 149 150 /************************************************************************/ 151 152 Bitmap* XDashTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/) 153 { 154 return( NULL ); 155 } 156 157 // ---------------- 158 // class XDashList 159 // ---------------- 160 161 class impXDashList 162 { 163 private: 164 VirtualDevice* mpVirtualDevice; 165 SdrModel* mpSdrModel; 166 SdrObject* mpBackgroundObject; 167 SdrObject* mpLineObject; 168 169 public: 170 impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL) 171 : mpVirtualDevice(pV), 172 mpSdrModel(pM), 173 mpBackgroundObject(pB), 174 mpLineObject(pL) 175 {} 176 177 ~impXDashList() 178 { 179 delete mpVirtualDevice; 180 SdrObject::Free(mpBackgroundObject); 181 SdrObject::Free(mpLineObject); 182 delete mpSdrModel; 183 } 184 185 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; } 186 SdrObject* getBackgroundObject() const { return mpBackgroundObject; } 187 SdrObject* getLineObject() const { return mpLineObject; } 188 }; 189 190 void XDashList::impCreate() 191 { 192 if(!mpData) 193 { 194 const Point aZero(0, 0); 195 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 196 197 VirtualDevice* pVirDev = new VirtualDevice; 198 OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" ); 199 pVirDev->SetMapMode(MAP_100TH_MM); 200 const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH * 2, BITMAP_HEIGHT))); 201 pVirDev->SetOutputSize(aSize); 202 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode() 203 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 204 : DRAWMODE_DEFAULT); 205 206 SdrModel* pSdrModel = new SdrModel(); 207 OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" ); 208 pSdrModel->GetItemPool().FreezeIdRanges(); 209 210 const Rectangle aBackgroundSize(aZero, aSize); 211 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize); 212 OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" ); 213 pBackgroundObject->SetModel(pSdrModel); 214 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID)); 215 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE)); 216 pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor())); 217 218 const basegfx::B2DPoint aStart(0, aSize.Height() / 2); 219 const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2); 220 basegfx::B2DPolygon aPolygon; 221 aPolygon.append(aStart); 222 aPolygon.append(aEnd); 223 SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon)); 224 OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" ); 225 pLineObject->SetModel(pSdrModel); 226 pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH)); 227 pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor())); 228 pLineObject->SetMergedItem(XLineWidthItem(30)); 229 230 mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject); 231 OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" ); 232 } 233 } 234 235 void XDashList::impDestroy() 236 { 237 if(mpData) 238 { 239 delete mpData; 240 mpData = 0; 241 } 242 } 243 244 XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize) 245 : XPropertyList(rPath, pInPool, nInitSize, nReSize), 246 mpData(0) 247 { 248 pBmpList = new List(nInitSize, nReSize); 249 } 250 251 XDashList::~XDashList() 252 { 253 impDestroy(); 254 } 255 256 XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex ) 257 { 258 return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex); 259 } 260 261 XDashEntry* XDashList::Remove(long nIndex) 262 { 263 return (XDashEntry*) XPropertyList::Remove(nIndex, 0); 264 } 265 266 XDashEntry* XDashList::GetDash(long nIndex) const 267 { 268 return (XDashEntry*) XPropertyList::Get(nIndex, 0); 269 } 270 271 sal_Bool XDashList::Load() 272 { 273 if( bListDirty ) 274 { 275 bListDirty = sal_False; 276 277 INetURLObject aURL( aPath ); 278 279 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 280 { 281 DBG_ASSERT( !aPath.Len(), "invalid URL" ); 282 return sal_False; 283 } 284 285 aURL.Append( aName ); 286 287 if( !aURL.getExtension().getLength() ) 288 aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 289 290 uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 291 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 292 } 293 return( sal_False ); 294 } 295 296 sal_Bool XDashList::Save() 297 { 298 INetURLObject aURL( aPath ); 299 300 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 301 { 302 DBG_ASSERT( !aPath.Len(), "invalid URL" ); 303 return sal_False; 304 } 305 306 aURL.Append( aName ); 307 308 if( !aURL.getExtension().getLength() ) 309 aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 310 311 uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 312 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 313 } 314 315 sal_Bool XDashList::Create() 316 { 317 XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) ); 318 xub_StrLen nLen; 319 320 aStr.AppendAscii(" 1"); 321 nLen = aStr.Len() - 1; 322 Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr)); 323 aStr.SetChar(nLen, sal_Unicode('2')); 324 Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr)); 325 aStr.SetChar(nLen, sal_Unicode('3')); 326 Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr)); 327 328 return( sal_True ); 329 } 330 331 sal_Bool XDashList::CreateBitmapsForUI() 332 { 333 impCreate(); 334 335 for( long i = 0; i < Count(); i++) 336 { 337 Bitmap* pBmp = CreateBitmapForUI( i, sal_False ); 338 DBG_ASSERT( pBmp, "XDashList: Bitmap(UI) konnte nicht erzeugt werden!" ); 339 340 if( pBmp ) 341 pBmpList->Insert( pBmp, i ); 342 } 343 344 impDestroy(); 345 346 return( sal_True ); 347 } 348 349 Bitmap* XDashList::CreateBitmapForUI( long nIndex, sal_Bool bDelete ) 350 { 351 impCreate(); 352 VirtualDevice* pVD = mpData->getVirtualDevice(); 353 SdrObject* pLine = mpData->getLineObject(); 354 355 pLine->SetMergedItem(XLineStyleItem(XLINE_DASH)); 356 pLine->SetMergedItem(XLineDashItem(String(), GetDash(nIndex)->GetDash())); 357 358 sdr::contact::SdrObjectVector aObjectVector; 359 aObjectVector.push_back(mpData->getBackgroundObject()); 360 aObjectVector.push_back(pLine); 361 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0); 362 sdr::contact::DisplayInfo aDisplayInfo; 363 364 aPainter.ProcessDisplay(aDisplayInfo); 365 366 const Point aZero(0, 0); 367 Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize())); 368 369 if(bDelete) 370 { 371 impDestroy(); 372 } 373 374 return pBitmap; 375 } 376 377 ////////////////////////////////////////////////////////////////////////////// 378 // eof 379