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