1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew 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 XDashList 75cdf0e10cSrcweir // ---------------- 76cdf0e10cSrcweir 77cdf0e10cSrcweir class impXDashList 78cdf0e10cSrcweir { 79cdf0e10cSrcweir private: 80cdf0e10cSrcweir VirtualDevice* mpVirtualDevice; 81cdf0e10cSrcweir SdrModel* mpSdrModel; 82cdf0e10cSrcweir SdrObject* mpBackgroundObject; 83cdf0e10cSrcweir SdrObject* mpLineObject; 84cdf0e10cSrcweir 85cdf0e10cSrcweir public: 86cdf0e10cSrcweir impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL) 87cdf0e10cSrcweir : mpVirtualDevice(pV), 88cdf0e10cSrcweir mpSdrModel(pM), 89cdf0e10cSrcweir mpBackgroundObject(pB), 90cdf0e10cSrcweir mpLineObject(pL) 91cdf0e10cSrcweir {} 92cdf0e10cSrcweir 93cdf0e10cSrcweir ~impXDashList() 94cdf0e10cSrcweir { 95cdf0e10cSrcweir delete mpVirtualDevice; 96cdf0e10cSrcweir SdrObject::Free(mpBackgroundObject); 97cdf0e10cSrcweir SdrObject::Free(mpLineObject); 98cdf0e10cSrcweir delete mpSdrModel; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; } 102cdf0e10cSrcweir SdrObject* getBackgroundObject() const { return mpBackgroundObject; } 103cdf0e10cSrcweir SdrObject* getLineObject() const { return mpLineObject; } 104cdf0e10cSrcweir }; 105cdf0e10cSrcweir 106cdf0e10cSrcweir void XDashList::impCreate() 107cdf0e10cSrcweir { 108cdf0e10cSrcweir if(!mpData) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir const Point aZero(0, 0); 111cdf0e10cSrcweir const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 112cdf0e10cSrcweir 113cdf0e10cSrcweir VirtualDevice* pVirDev = new VirtualDevice; 114cdf0e10cSrcweir OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" ); 115cdf0e10cSrcweir pVirDev->SetMapMode(MAP_100TH_MM); 116*97e8a929SArmin Le Grand const Size aSize(pVirDev->PixelToLogic(Size(getUiBitmapWidth() * 2, getUiBitmapHeight()))); 117cdf0e10cSrcweir pVirDev->SetOutputSize(aSize); 118cdf0e10cSrcweir pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode() 119cdf0e10cSrcweir ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 120cdf0e10cSrcweir : DRAWMODE_DEFAULT); 121*97e8a929SArmin Le Grand pVirDev->SetBackground(rStyleSettings.GetFieldColor()); 122cdf0e10cSrcweir 123cdf0e10cSrcweir SdrModel* pSdrModel = new SdrModel(); 124cdf0e10cSrcweir OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" ); 125cdf0e10cSrcweir pSdrModel->GetItemPool().FreezeIdRanges(); 126cdf0e10cSrcweir 127cdf0e10cSrcweir const Rectangle aBackgroundSize(aZero, aSize); 128cdf0e10cSrcweir SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize); 129cdf0e10cSrcweir OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" ); 130cdf0e10cSrcweir pBackgroundObject->SetModel(pSdrModel); 131cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID)); 132cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE)); 133cdf0e10cSrcweir pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor())); 134cdf0e10cSrcweir 135cdf0e10cSrcweir const basegfx::B2DPoint aStart(0, aSize.Height() / 2); 136cdf0e10cSrcweir const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2); 137cdf0e10cSrcweir basegfx::B2DPolygon aPolygon; 138cdf0e10cSrcweir aPolygon.append(aStart); 139cdf0e10cSrcweir aPolygon.append(aEnd); 140cdf0e10cSrcweir SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon)); 141cdf0e10cSrcweir OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" ); 142cdf0e10cSrcweir pLineObject->SetModel(pSdrModel); 143cdf0e10cSrcweir pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH)); 144cdf0e10cSrcweir pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor())); 145*97e8a929SArmin Le Grand const Size aLineWidth(pVirDev->PixelToLogic(Size(getUiBitmapLineWidth(), 0))); 146*97e8a929SArmin Le Grand pLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth())); 147cdf0e10cSrcweir mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject); 148cdf0e10cSrcweir OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir void XDashList::impDestroy() 153cdf0e10cSrcweir { 154cdf0e10cSrcweir if(mpData) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir delete mpData; 157cdf0e10cSrcweir mpData = 0; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161*97e8a929SArmin Le Grand XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool ) 162*97e8a929SArmin Le Grand : XPropertyList(rPath, pInPool ), 163*97e8a929SArmin Le Grand mpData(0), 164*97e8a929SArmin Le Grand maBitmapSolidLine(), 165*97e8a929SArmin Le Grand maStringSolidLine(), 166*97e8a929SArmin Le Grand maStringNoLine() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir XDashList::~XDashList() 171cdf0e10cSrcweir { 172cdf0e10cSrcweir impDestroy(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir XDashEntry* XDashList::Remove(long nIndex) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir return (XDashEntry*) XPropertyList::Remove(nIndex, 0); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir XDashEntry* XDashList::GetDash(long nIndex) const 186cdf0e10cSrcweir { 187cdf0e10cSrcweir return (XDashEntry*) XPropertyList::Get(nIndex, 0); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir sal_Bool XDashList::Load() 191cdf0e10cSrcweir { 192*97e8a929SArmin Le Grand if( mbListDirty ) 193cdf0e10cSrcweir { 194*97e8a929SArmin Le Grand mbListDirty = false; 195cdf0e10cSrcweir 196*97e8a929SArmin Le Grand INetURLObject aURL( maPath ); 197cdf0e10cSrcweir 198cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 199cdf0e10cSrcweir { 200*97e8a929SArmin Le Grand DBG_ASSERT( !maPath.Len(), "invalid URL" ); 201cdf0e10cSrcweir return sal_False; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204*97e8a929SArmin Le Grand aURL.Append( maName ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 207cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 210cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir return( sal_False ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir sal_Bool XDashList::Save() 216cdf0e10cSrcweir { 217*97e8a929SArmin Le Grand INetURLObject aURL( maPath ); 218cdf0e10cSrcweir 219cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 220cdf0e10cSrcweir { 221*97e8a929SArmin Le Grand DBG_ASSERT( !maPath.Len(), "invalid URL" ); 222cdf0e10cSrcweir return sal_False; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225*97e8a929SArmin Le Grand aURL.Append( maName ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 228cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 231cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir sal_Bool XDashList::Create() 235cdf0e10cSrcweir { 236cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) ); 237cdf0e10cSrcweir xub_StrLen nLen; 238cdf0e10cSrcweir 239cdf0e10cSrcweir aStr.AppendAscii(" 1"); 240cdf0e10cSrcweir nLen = aStr.Len() - 1; 241cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr)); 242cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2')); 243cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr)); 244cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3')); 245cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr)); 246cdf0e10cSrcweir 247cdf0e10cSrcweir return( sal_True ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250*97e8a929SArmin Le Grand Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir impCreate(); 253cdf0e10cSrcweir VirtualDevice* pVD = mpData->getVirtualDevice(); 254cdf0e10cSrcweir SdrObject* pLine = mpData->getLineObject(); 255cdf0e10cSrcweir 256*97e8a929SArmin Le Grand if(pDash) 257*97e8a929SArmin Le Grand { 258cdf0e10cSrcweir pLine->SetMergedItem(XLineStyleItem(XLINE_DASH)); 259*97e8a929SArmin Le Grand pLine->SetMergedItem(XLineDashItem(String(), *pDash)); 260*97e8a929SArmin Le Grand } 261*97e8a929SArmin Le Grand else 262*97e8a929SArmin Le Grand { 263*97e8a929SArmin Le Grand pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID)); 264*97e8a929SArmin Le Grand } 265cdf0e10cSrcweir 266cdf0e10cSrcweir sdr::contact::SdrObjectVector aObjectVector; 267cdf0e10cSrcweir aObjectVector.push_back(mpData->getBackgroundObject()); 268cdf0e10cSrcweir aObjectVector.push_back(pLine); 269cdf0e10cSrcweir sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0); 270cdf0e10cSrcweir sdr::contact::DisplayInfo aDisplayInfo; 271cdf0e10cSrcweir 272*97e8a929SArmin Le Grand pVD->Erase(); 273cdf0e10cSrcweir aPainter.ProcessDisplay(aDisplayInfo); 274cdf0e10cSrcweir 275cdf0e10cSrcweir const Point aZero(0, 0); 276*97e8a929SArmin Le Grand return pVD->GetBitmap(aZero, pVD->GetOutputSize()); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279*97e8a929SArmin Le Grand Bitmap XDashList::CreateBitmapForUI( long nIndex ) 280*97e8a929SArmin Le Grand { 281*97e8a929SArmin Le Grand const XDash& rDash = GetDash(nIndex)->GetDash(); 282*97e8a929SArmin Le Grand 283*97e8a929SArmin Le Grand return ImpCreateBitmapForXDash(&rDash); 284*97e8a929SArmin Le Grand } 285*97e8a929SArmin Le Grand 286*97e8a929SArmin Le Grand Bitmap XDashList::GetBitmapForUISolidLine() const 287*97e8a929SArmin Le Grand { 288*97e8a929SArmin Le Grand if(maBitmapSolidLine.IsEmpty()) 289*97e8a929SArmin Le Grand { 290*97e8a929SArmin Le Grand const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0); 291*97e8a929SArmin Le Grand } 292*97e8a929SArmin Le Grand 293*97e8a929SArmin Le Grand return maBitmapSolidLine; 294*97e8a929SArmin Le Grand } 295*97e8a929SArmin Le Grand 296*97e8a929SArmin Le Grand String XDashList::GetStringForUiSolidLine() const 297*97e8a929SArmin Le Grand { 298*97e8a929SArmin Le Grand if(!maStringSolidLine.Len()) 299*97e8a929SArmin Le Grand { 300*97e8a929SArmin Le Grand const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR())); 301*97e8a929SArmin Le Grand } 302*97e8a929SArmin Le Grand 303*97e8a929SArmin Le Grand return maStringSolidLine; 304*97e8a929SArmin Le Grand } 305*97e8a929SArmin Le Grand 306*97e8a929SArmin Le Grand String XDashList::GetStringForUiNoLine() const 307*97e8a929SArmin Le Grand { 308*97e8a929SArmin Le Grand if(!maStringNoLine.Len()) 309*97e8a929SArmin Le Grand { 310*97e8a929SArmin Le Grand // formally was RID_SVXSTR_INVISIBLE, but tomake equal 311*97e8a929SArmin Le Grand // everywhere, use RID_SVXSTR_NONE 312*97e8a929SArmin Le Grand const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR())); 313*97e8a929SArmin Le Grand } 314*97e8a929SArmin Le Grand 315*97e8a929SArmin Le Grand return maStringNoLine; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 319cdf0e10cSrcweir // eof 320