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 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_svx.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir // include --------------------------------------------------------------- 26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 27cdf0e10cSrcweir #include "svx/XPropertyTable.hxx" 28cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 29cdf0e10cSrcweir #include "xmlxtexp.hxx" 30cdf0e10cSrcweir #include "xmlxtimp.hxx" 31cdf0e10cSrcweir #include <vcl/svapp.hxx> 32cdf0e10cSrcweir #include <tools/urlobj.hxx> 33cdf0e10cSrcweir #include <vcl/virdev.hxx> 34cdf0e10cSrcweir #include <svx/dialogs.hrc> 35cdf0e10cSrcweir #include <svx/dialmgr.hxx> 36cdf0e10cSrcweir #include <svx/xtable.hxx> 3735726d9dSArmin Le Grand #include <drawinglayer/attribute/lineattribute.hxx> 3835726d9dSArmin Le Grand #include <drawinglayer/attribute/strokeattribute.hxx> 3935726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 4035726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace com::sun::star; 43cdf0e10cSrcweir using namespace rtl; 44cdf0e10cSrcweir 45cdf0e10cSrcweir #define GLOBALOVERFLOW 46cdf0e10cSrcweir 47cdf0e10cSrcweir sal_Unicode const pszExtDash[] = {'s','o','d'}; 48c7be74b1SArmin Le Grand //char const aChckDash[] = { 0x04, 0x00, 'S','O','D','L'}; // < 5.2 49c7be74b1SArmin Le Grand //char const aChckDash0[] = { 0x04, 0x00, 'S','O','D','0'}; // = 5.2 50c7be74b1SArmin Le Grand //char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 51cdf0e10cSrcweir 52cdf0e10cSrcweir // ---------------- 53cdf0e10cSrcweir // class XDashList 54cdf0e10cSrcweir // ---------------- 55cdf0e10cSrcweir 56c7be74b1SArmin Le Grand XDashList::XDashList(const String& rPath ) 57c7be74b1SArmin Le Grand : XPropertyList(rPath), 5897e8a929SArmin Le Grand maBitmapSolidLine(), 5997e8a929SArmin Le Grand maStringSolidLine(), 6097e8a929SArmin Le Grand maStringNoLine() 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir XDashList::~XDashList() 65cdf0e10cSrcweir { 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir XDashEntry* XDashList::Remove(long nIndex) 74cdf0e10cSrcweir { 75c7be74b1SArmin Le Grand return (XDashEntry*) XPropertyList::Remove(nIndex); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir XDashEntry* XDashList::GetDash(long nIndex) const 79cdf0e10cSrcweir { 80c7be74b1SArmin Le Grand return (XDashEntry*) XPropertyList::Get(nIndex); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83*3e407bd8SArmin Le Grand bool XDashList::Load() 84cdf0e10cSrcweir { 8597e8a929SArmin Le Grand if( mbListDirty ) 86cdf0e10cSrcweir { 8797e8a929SArmin Le Grand mbListDirty = false; 88cdf0e10cSrcweir 8997e8a929SArmin Le Grand INetURLObject aURL( maPath ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 92cdf0e10cSrcweir { 9335726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 94*3e407bd8SArmin Le Grand return false; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 9797e8a929SArmin Le Grand aURL.Append( maName ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 100cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 103cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 104cdf0e10cSrcweir } 105*3e407bd8SArmin Le Grand 106*3e407bd8SArmin Le Grand return false; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109*3e407bd8SArmin Le Grand bool XDashList::Save() 110cdf0e10cSrcweir { 11197e8a929SArmin Le Grand INetURLObject aURL( maPath ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 114cdf0e10cSrcweir { 11535726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 116*3e407bd8SArmin Le Grand return false; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 11997e8a929SArmin Le Grand aURL.Append( maName ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 122cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 123cdf0e10cSrcweir 124cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 125cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128*3e407bd8SArmin Le Grand bool XDashList::Create() 129cdf0e10cSrcweir { 130cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) ); 131cdf0e10cSrcweir xub_StrLen nLen; 132cdf0e10cSrcweir 133cdf0e10cSrcweir aStr.AppendAscii(" 1"); 134cdf0e10cSrcweir nLen = aStr.Len() - 1; 135cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr)); 136cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2')); 137cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr)); 138cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3')); 139cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr)); 140cdf0e10cSrcweir 141*3e407bd8SArmin Le Grand return true; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 14497e8a929SArmin Le Grand Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash) 145cdf0e10cSrcweir { 146c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 147c7be74b1SArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 14835726d9dSArmin Le Grand const sal_uInt32 nFactor(2); 14935726d9dSArmin Le Grand const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor); 150c7be74b1SArmin Le Grand 15135726d9dSArmin Le Grand // prepare polygon geometry for line 15235726d9dSArmin Le Grand basegfx::B2DPolygon aLine; 15335726d9dSArmin Le Grand 15435726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0)); 15535726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0)); 15635726d9dSArmin Le Grand 15735726d9dSArmin Le Grand // prepare LineAttribute 15835726d9dSArmin Le Grand const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor()); 15935726d9dSArmin Le Grand const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1)); 16035726d9dSArmin Le Grand const drawinglayer::attribute::LineAttribute aLineAttribute( 16135726d9dSArmin Le Grand aLineColor, 16235726d9dSArmin Le Grand fLineWidth); 16335726d9dSArmin Le Grand 16435726d9dSArmin Le Grand // prepare StrokeAttribute 16535726d9dSArmin Le Grand ::std::vector< double > aDotDashArray; 16635726d9dSArmin Le Grand double fFullDotDashLen(0.0); 16735726d9dSArmin Le Grand 16835726d9dSArmin Le Grand if(pDash && (pDash->GetDots() || pDash->GetDashes())) 16935726d9dSArmin Le Grand { 17035726d9dSArmin Le Grand const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL)); 17135726d9dSArmin Le Grand const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0)); 17235726d9dSArmin Le Grand const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0))); 17335726d9dSArmin Le Grand const double fLineWidthInUnits(fLineWidth / fScaleValue); 17435726d9dSArmin Le Grand 17535726d9dSArmin Le Grand fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits); 17635726d9dSArmin Le Grand 17735726d9dSArmin Le Grand if(!aDotDashArray.empty()) 17835726d9dSArmin Le Grand { 17935726d9dSArmin Le Grand for(sal_uInt32 a(0); a < aDotDashArray.size(); a++) 18035726d9dSArmin Le Grand { 18135726d9dSArmin Le Grand aDotDashArray[a] *= fScaleValue; 18235726d9dSArmin Le Grand } 18335726d9dSArmin Le Grand 18435726d9dSArmin Le Grand fFullDotDashLen *= fScaleValue; 18535726d9dSArmin Le Grand } 18635726d9dSArmin Le Grand } 18735726d9dSArmin Le Grand 18835726d9dSArmin Le Grand const drawinglayer::attribute::StrokeAttribute aStrokeAttribute( 18935726d9dSArmin Le Grand aDotDashArray, 19035726d9dSArmin Le Grand fFullDotDashLen); 19135726d9dSArmin Le Grand 19235726d9dSArmin Le Grand // cerate LinePrimitive 19335726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aLinePrimitive( 19435726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonStrokePrimitive2D( 19535726d9dSArmin Le Grand aLine, 19635726d9dSArmin Le Grand aLineAttribute, 19735726d9dSArmin Le Grand aStrokeAttribute)); 19835726d9dSArmin Le Grand 19935726d9dSArmin Le Grand // prepare VirtualDevice 20035726d9dSArmin Le Grand VirtualDevice aVirtualDevice; 20135726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 20235726d9dSArmin Le Grand 20335726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(aSize); 20435726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 205c7be74b1SArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 206c7be74b1SArmin Le Grand : DRAWMODE_DEFAULT); 207c7be74b1SArmin Le Grand 20835726d9dSArmin Le Grand if(rStyleSettings.GetUIPreviewUsesCheckeredBackground()) 209c7be74b1SArmin Le Grand { 21035726d9dSArmin Le Grand const Point aNull(0, 0); 21135726d9dSArmin Le Grand static const sal_uInt32 nLen(8 * nFactor); 21235726d9dSArmin Le Grand static const Color aW(COL_WHITE); 21335726d9dSArmin Le Grand static const Color aG(0xef, 0xef, 0xef); 214c7be74b1SArmin Le Grand 21535726d9dSArmin Le Grand aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG); 21697e8a929SArmin Le Grand } 21797e8a929SArmin Le Grand else 21897e8a929SArmin Le Grand { 21935726d9dSArmin Le Grand aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor()); 22035726d9dSArmin Le Grand aVirtualDevice.Erase(); 22197e8a929SArmin Le Grand } 222cdf0e10cSrcweir 22335726d9dSArmin Le Grand // create processor and draw primitives 22435726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 22535726d9dSArmin Le Grand aVirtualDevice, 22635726d9dSArmin Le Grand aNewViewInformation2D); 227c7be74b1SArmin Le Grand 22835726d9dSArmin Le Grand if(pProcessor2D) 22981e4f59aSArmin Le Grand { 23035726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLinePrimitive, 1); 23181e4f59aSArmin Le Grand 23235726d9dSArmin Le Grand pProcessor2D->process(aSequence); 23335726d9dSArmin Le Grand delete pProcessor2D; 234c7be74b1SArmin Le Grand } 23535726d9dSArmin Le Grand 23635726d9dSArmin Le Grand // get result bitmap and scale 23735726d9dSArmin Le Grand Bitmap aRetval(aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel())); 23835726d9dSArmin Le Grand 23935726d9dSArmin Le Grand if(1 != nFactor) 24035726d9dSArmin Le Grand { 24135726d9dSArmin Le Grand aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()), BMP_SCALE_FASTESTINTERPOLATE); 24281e4f59aSArmin Le Grand } 24381e4f59aSArmin Le Grand 244c7be74b1SArmin Le Grand return aRetval; 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 24797e8a929SArmin Le Grand Bitmap XDashList::CreateBitmapForUI( long nIndex ) 24897e8a929SArmin Le Grand { 249c7be74b1SArmin Le Grand Bitmap aRetval; 250c7be74b1SArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)"); 251c7be74b1SArmin Le Grand 252c7be74b1SArmin Le Grand if(nIndex < Count()) 253c7be74b1SArmin Le Grand { 25497e8a929SArmin Le Grand const XDash& rDash = GetDash(nIndex)->GetDash(); 25597e8a929SArmin Le Grand 256c7be74b1SArmin Le Grand aRetval = ImpCreateBitmapForXDash(&rDash); 257c7be74b1SArmin Le Grand } 258c7be74b1SArmin Le Grand 259c7be74b1SArmin Le Grand return aRetval; 26097e8a929SArmin Le Grand } 26197e8a929SArmin Le Grand 26297e8a929SArmin Le Grand Bitmap XDashList::GetBitmapForUISolidLine() const 26397e8a929SArmin Le Grand { 26497e8a929SArmin Le Grand if(maBitmapSolidLine.IsEmpty()) 26597e8a929SArmin Le Grand { 26697e8a929SArmin Le Grand const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0); 26797e8a929SArmin Le Grand } 26897e8a929SArmin Le Grand 26997e8a929SArmin Le Grand return maBitmapSolidLine; 27097e8a929SArmin Le Grand } 27197e8a929SArmin Le Grand 27297e8a929SArmin Le Grand String XDashList::GetStringForUiSolidLine() const 27397e8a929SArmin Le Grand { 27497e8a929SArmin Le Grand if(!maStringSolidLine.Len()) 27597e8a929SArmin Le Grand { 27697e8a929SArmin Le Grand const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR())); 27797e8a929SArmin Le Grand } 27897e8a929SArmin Le Grand 27997e8a929SArmin Le Grand return maStringSolidLine; 28097e8a929SArmin Le Grand } 28197e8a929SArmin Le Grand 28297e8a929SArmin Le Grand String XDashList::GetStringForUiNoLine() const 28397e8a929SArmin Le Grand { 28497e8a929SArmin Le Grand if(!maStringNoLine.Len()) 28597e8a929SArmin Le Grand { 28697e8a929SArmin Le Grand // formally was RID_SVXSTR_INVISIBLE, but tomake equal 28797e8a929SArmin Le Grand // everywhere, use RID_SVXSTR_NONE 28897e8a929SArmin Le Grand const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR())); 28997e8a929SArmin Le Grand } 29097e8a929SArmin Le Grand 29197e8a929SArmin Le Grand return maStringNoLine; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 295cdf0e10cSrcweir // eof 296