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> 37*35726d9dSArmin Le Grand #include <drawinglayer/attribute/lineattribute.hxx> 38*35726d9dSArmin Le Grand #include <drawinglayer/attribute/strokeattribute.hxx> 39*35726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 40*35726d9dSArmin 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 83cdf0e10cSrcweir sal_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 { 93*35726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 94cdf0e10cSrcweir return sal_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 } 105cdf0e10cSrcweir return( sal_False ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir sal_Bool XDashList::Save() 109cdf0e10cSrcweir { 11097e8a929SArmin Le Grand INetURLObject aURL( maPath ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 113cdf0e10cSrcweir { 114*35726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 115cdf0e10cSrcweir return sal_False; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 11897e8a929SArmin Le Grand aURL.Append( maName ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 121cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtDash, 3 ) ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY ); 124cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir sal_Bool XDashList::Create() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) ); 130cdf0e10cSrcweir xub_StrLen nLen; 131cdf0e10cSrcweir 132cdf0e10cSrcweir aStr.AppendAscii(" 1"); 133cdf0e10cSrcweir nLen = aStr.Len() - 1; 134cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr)); 135cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2')); 136cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr)); 137cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3')); 138cdf0e10cSrcweir Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr)); 139cdf0e10cSrcweir 140cdf0e10cSrcweir return( sal_True ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 14397e8a929SArmin Le Grand Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash) 144cdf0e10cSrcweir { 145c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 146c7be74b1SArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 147*35726d9dSArmin Le Grand const sal_uInt32 nFactor(2); 148*35726d9dSArmin Le Grand const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor); 149c7be74b1SArmin Le Grand 150*35726d9dSArmin Le Grand // prepare polygon geometry for line 151*35726d9dSArmin Le Grand basegfx::B2DPolygon aLine; 152*35726d9dSArmin Le Grand 153*35726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0)); 154*35726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0)); 155*35726d9dSArmin Le Grand 156*35726d9dSArmin Le Grand // prepare LineAttribute 157*35726d9dSArmin Le Grand const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor()); 158*35726d9dSArmin Le Grand const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1)); 159*35726d9dSArmin Le Grand const drawinglayer::attribute::LineAttribute aLineAttribute( 160*35726d9dSArmin Le Grand aLineColor, 161*35726d9dSArmin Le Grand fLineWidth); 162*35726d9dSArmin Le Grand 163*35726d9dSArmin Le Grand // prepare StrokeAttribute 164*35726d9dSArmin Le Grand ::std::vector< double > aDotDashArray; 165*35726d9dSArmin Le Grand double fFullDotDashLen(0.0); 166*35726d9dSArmin Le Grand 167*35726d9dSArmin Le Grand if(pDash && (pDash->GetDots() || pDash->GetDashes())) 168*35726d9dSArmin Le Grand { 169*35726d9dSArmin Le Grand const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL)); 170*35726d9dSArmin Le Grand const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0)); 171*35726d9dSArmin Le Grand const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0))); 172*35726d9dSArmin Le Grand const double fLineWidthInUnits(fLineWidth / fScaleValue); 173*35726d9dSArmin Le Grand 174*35726d9dSArmin Le Grand fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits); 175*35726d9dSArmin Le Grand 176*35726d9dSArmin Le Grand if(!aDotDashArray.empty()) 177*35726d9dSArmin Le Grand { 178*35726d9dSArmin Le Grand for(sal_uInt32 a(0); a < aDotDashArray.size(); a++) 179*35726d9dSArmin Le Grand { 180*35726d9dSArmin Le Grand aDotDashArray[a] *= fScaleValue; 181*35726d9dSArmin Le Grand } 182*35726d9dSArmin Le Grand 183*35726d9dSArmin Le Grand fFullDotDashLen *= fScaleValue; 184*35726d9dSArmin Le Grand } 185*35726d9dSArmin Le Grand } 186*35726d9dSArmin Le Grand 187*35726d9dSArmin Le Grand const drawinglayer::attribute::StrokeAttribute aStrokeAttribute( 188*35726d9dSArmin Le Grand aDotDashArray, 189*35726d9dSArmin Le Grand fFullDotDashLen); 190*35726d9dSArmin Le Grand 191*35726d9dSArmin Le Grand // cerate LinePrimitive 192*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aLinePrimitive( 193*35726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonStrokePrimitive2D( 194*35726d9dSArmin Le Grand aLine, 195*35726d9dSArmin Le Grand aLineAttribute, 196*35726d9dSArmin Le Grand aStrokeAttribute)); 197*35726d9dSArmin Le Grand 198*35726d9dSArmin Le Grand // prepare VirtualDevice 199*35726d9dSArmin Le Grand VirtualDevice aVirtualDevice; 200*35726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 201*35726d9dSArmin Le Grand 202*35726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(aSize); 203*35726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 204c7be74b1SArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 205c7be74b1SArmin Le Grand : DRAWMODE_DEFAULT); 206c7be74b1SArmin Le Grand 207*35726d9dSArmin Le Grand if(rStyleSettings.GetUIPreviewUsesCheckeredBackground()) 208c7be74b1SArmin Le Grand { 209*35726d9dSArmin Le Grand const Point aNull(0, 0); 210*35726d9dSArmin Le Grand static const sal_uInt32 nLen(8 * nFactor); 211*35726d9dSArmin Le Grand static const Color aW(COL_WHITE); 212*35726d9dSArmin Le Grand static const Color aG(0xef, 0xef, 0xef); 213c7be74b1SArmin Le Grand 214*35726d9dSArmin Le Grand aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG); 21597e8a929SArmin Le Grand } 21697e8a929SArmin Le Grand else 21797e8a929SArmin Le Grand { 218*35726d9dSArmin Le Grand aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor()); 219*35726d9dSArmin Le Grand aVirtualDevice.Erase(); 22097e8a929SArmin Le Grand } 221cdf0e10cSrcweir 222*35726d9dSArmin Le Grand // create processor and draw primitives 223*35726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 224*35726d9dSArmin Le Grand aVirtualDevice, 225*35726d9dSArmin Le Grand aNewViewInformation2D); 226c7be74b1SArmin Le Grand 227*35726d9dSArmin Le Grand if(pProcessor2D) 22881e4f59aSArmin Le Grand { 229*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLinePrimitive, 1); 23081e4f59aSArmin Le Grand 231*35726d9dSArmin Le Grand pProcessor2D->process(aSequence); 232*35726d9dSArmin Le Grand delete pProcessor2D; 233c7be74b1SArmin Le Grand } 234*35726d9dSArmin Le Grand 235*35726d9dSArmin Le Grand // get result bitmap and scale 236*35726d9dSArmin Le Grand Bitmap aRetval(aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel())); 237*35726d9dSArmin Le Grand 238*35726d9dSArmin Le Grand if(1 != nFactor) 239*35726d9dSArmin Le Grand { 240*35726d9dSArmin Le Grand aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()), BMP_SCALE_FASTESTINTERPOLATE); 24181e4f59aSArmin Le Grand } 24281e4f59aSArmin Le Grand 243c7be74b1SArmin Le Grand return aRetval; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 24697e8a929SArmin Le Grand Bitmap XDashList::CreateBitmapForUI( long nIndex ) 24797e8a929SArmin Le Grand { 248c7be74b1SArmin Le Grand Bitmap aRetval; 249c7be74b1SArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)"); 250c7be74b1SArmin Le Grand 251c7be74b1SArmin Le Grand if(nIndex < Count()) 252c7be74b1SArmin Le Grand { 25397e8a929SArmin Le Grand const XDash& rDash = GetDash(nIndex)->GetDash(); 25497e8a929SArmin Le Grand 255c7be74b1SArmin Le Grand aRetval = ImpCreateBitmapForXDash(&rDash); 256c7be74b1SArmin Le Grand } 257c7be74b1SArmin Le Grand 258c7be74b1SArmin Le Grand return aRetval; 25997e8a929SArmin Le Grand } 26097e8a929SArmin Le Grand 26197e8a929SArmin Le Grand Bitmap XDashList::GetBitmapForUISolidLine() const 26297e8a929SArmin Le Grand { 26397e8a929SArmin Le Grand if(maBitmapSolidLine.IsEmpty()) 26497e8a929SArmin Le Grand { 26597e8a929SArmin Le Grand const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0); 26697e8a929SArmin Le Grand } 26797e8a929SArmin Le Grand 26897e8a929SArmin Le Grand return maBitmapSolidLine; 26997e8a929SArmin Le Grand } 27097e8a929SArmin Le Grand 27197e8a929SArmin Le Grand String XDashList::GetStringForUiSolidLine() const 27297e8a929SArmin Le Grand { 27397e8a929SArmin Le Grand if(!maStringSolidLine.Len()) 27497e8a929SArmin Le Grand { 27597e8a929SArmin Le Grand const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR())); 27697e8a929SArmin Le Grand } 27797e8a929SArmin Le Grand 27897e8a929SArmin Le Grand return maStringSolidLine; 27997e8a929SArmin Le Grand } 28097e8a929SArmin Le Grand 28197e8a929SArmin Le Grand String XDashList::GetStringForUiNoLine() const 28297e8a929SArmin Le Grand { 28397e8a929SArmin Le Grand if(!maStringNoLine.Len()) 28497e8a929SArmin Le Grand { 28597e8a929SArmin Le Grand // formally was RID_SVXSTR_INVISIBLE, but tomake equal 28697e8a929SArmin Le Grand // everywhere, use RID_SVXSTR_NONE 28797e8a929SArmin Le Grand const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR())); 28897e8a929SArmin Le Grand } 28997e8a929SArmin Le Grand 29097e8a929SArmin Le Grand return maStringNoLine; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 294cdf0e10cSrcweir // eof 295