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