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