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 <vcl/svapp.hxx> 30cdf0e10cSrcweir #include "xmlxtexp.hxx" 31cdf0e10cSrcweir #include "xmlxtimp.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/fillhatchattribute.hxx> 38*35726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 39*35726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 40*35726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx> 41*35726d9dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::com::sun::star; 44cdf0e10cSrcweir using namespace ::rtl; 45cdf0e10cSrcweir 46cdf0e10cSrcweir sal_Unicode const pszExtHatch[] = {'s','o','h'}; 47c7be74b1SArmin Le Grand //char const aChckHatch[] = { 0x04, 0x00, 'S','O','H','L'}; // < 5.2 48c7be74b1SArmin Le Grand //char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'}; // = 5.2 49c7be74b1SArmin Le Grand //char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 50cdf0e10cSrcweir 51cdf0e10cSrcweir // ----------------- 52cdf0e10cSrcweir // class XHatchList 53cdf0e10cSrcweir // ----------------- 54cdf0e10cSrcweir 55c7be74b1SArmin Le Grand XHatchList::XHatchList(const String& rPath ) 56*35726d9dSArmin Le Grand : XPropertyList(rPath) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir XHatchList::~XHatchList() 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir XHatchEntry* XHatchList::Replace(XHatchEntry* pEntry, long nIndex ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir return (XHatchEntry*) XPropertyList::Replace(pEntry, nIndex); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir XHatchEntry* XHatchList::Remove(long nIndex) 70cdf0e10cSrcweir { 71c7be74b1SArmin Le Grand return (XHatchEntry*) XPropertyList::Remove(nIndex); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir XHatchEntry* XHatchList::GetHatch(long nIndex) const 75cdf0e10cSrcweir { 76c7be74b1SArmin Le Grand return (XHatchEntry*) XPropertyList::Get(nIndex); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir sal_Bool XHatchList::Load() 80cdf0e10cSrcweir { 8197e8a929SArmin Le Grand if( mbListDirty ) 82cdf0e10cSrcweir { 8397e8a929SArmin Le Grand mbListDirty = false; 84cdf0e10cSrcweir 8597e8a929SArmin Le Grand INetURLObject aURL( maPath ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 88cdf0e10cSrcweir { 89*35726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 90cdf0e10cSrcweir return sal_False; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 9397e8a929SArmin Le Grand aURL.Append( maName ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 96cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY ); 99cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir return( sal_False ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir sal_Bool XHatchList::Save() 105cdf0e10cSrcweir { 10697e8a929SArmin Le Grand INetURLObject aURL( maPath ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 109cdf0e10cSrcweir { 110*35726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 111cdf0e10cSrcweir return sal_False; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 11497e8a929SArmin Le Grand aURL.Append( maName ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 117cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY ); 120cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir sal_Bool XHatchList::Create() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir XubString aStr( SVX_RES( RID_SVXSTR_HATCH ) ); 126cdf0e10cSrcweir xub_StrLen nLen; 127cdf0e10cSrcweir 128cdf0e10cSrcweir aStr.AppendAscii(" 1"); 129cdf0e10cSrcweir nLen = aStr.Len() - 1; 130cdf0e10cSrcweir Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100, 0),aStr)); 131cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('2')); 132cdf0e10cSrcweir Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED ),XHATCH_DOUBLE, 80,450),aStr)); 133cdf0e10cSrcweir aStr.SetChar(nLen, sal_Unicode('3')); 134cdf0e10cSrcweir Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120, 0),aStr)); 135cdf0e10cSrcweir 136cdf0e10cSrcweir return( sal_True ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 13997e8a929SArmin Le Grand Bitmap XHatchList::CreateBitmapForUI( long nIndex ) 140cdf0e10cSrcweir { 141c7be74b1SArmin Le Grand Bitmap aRetval; 142*35726d9dSArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); 143cdf0e10cSrcweir 144*35726d9dSArmin Le Grand if(nIndex < Count()) 145c7be74b1SArmin Le Grand { 146c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 147*35726d9dSArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 148c7be74b1SArmin Le Grand 149*35726d9dSArmin Le Grand // prepare polygon geometry for rectangle 150*35726d9dSArmin Le Grand const basegfx::B2DPolygon aRectangle( 151*35726d9dSArmin Le Grand basegfx::tools::createPolygonFromRect( 152*35726d9dSArmin Le Grand basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height()))); 153*35726d9dSArmin Le Grand 154*35726d9dSArmin Le Grand const XHatch& rHatch = GetHatch(nIndex)->GetHatch(); 155*35726d9dSArmin Le Grand drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HATCHSTYLE_TRIPLE); 156*35726d9dSArmin Le Grand 157*35726d9dSArmin Le Grand switch(rHatch.GetHatchStyle()) 158*35726d9dSArmin Le Grand { 159*35726d9dSArmin Le Grand case XHATCH_SINGLE : 160*35726d9dSArmin Le Grand { 161*35726d9dSArmin Le Grand aHatchStyle = drawinglayer::attribute::HATCHSTYLE_SINGLE; 162*35726d9dSArmin Le Grand break; 163*35726d9dSArmin Le Grand } 164*35726d9dSArmin Le Grand case XHATCH_DOUBLE : 165*35726d9dSArmin Le Grand { 166*35726d9dSArmin Le Grand aHatchStyle = drawinglayer::attribute::HATCHSTYLE_DOUBLE; 167*35726d9dSArmin Le Grand break; 168*35726d9dSArmin Le Grand } 169*35726d9dSArmin Le Grand default : 170*35726d9dSArmin Le Grand { 171*35726d9dSArmin Le Grand aHatchStyle = drawinglayer::attribute::HATCHSTYLE_TRIPLE; // XHATCH_TRIPLE 172*35726d9dSArmin Le Grand break; 173*35726d9dSArmin Le Grand } 174*35726d9dSArmin Le Grand } 175*35726d9dSArmin Le Grand 176*35726d9dSArmin Le Grand const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL)); 177*35726d9dSArmin Le Grand const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0)); 178*35726d9dSArmin Le Grand const double fScaleValue(aScaleVector.getLength()); 179*35726d9dSArmin Le Grand 180*35726d9dSArmin Le Grand const drawinglayer::attribute::FillHatchAttribute aFillHatch( 181*35726d9dSArmin Le Grand aHatchStyle, 182*35726d9dSArmin Le Grand (double)rHatch.GetDistance() * fScaleValue, 183*35726d9dSArmin Le Grand (double)rHatch.GetAngle() * F_PI1800, 184*35726d9dSArmin Le Grand rHatch.GetColor().getBColor(), 185*35726d9dSArmin Le Grand 3, // same default as VCL, a minimum of three discrete units (pixels) offset 186*35726d9dSArmin Le Grand false); 187*35726d9dSArmin Le Grand 188*35726d9dSArmin Le Grand const basegfx::BColor aBlack(0.0, 0.0, 0.0); 189*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive( 190*35726d9dSArmin Le Grand new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D( 191*35726d9dSArmin Le Grand basegfx::B2DPolyPolygon(aRectangle), 192*35726d9dSArmin Le Grand aBlack, 193*35726d9dSArmin Le Grand aFillHatch)); 194*35726d9dSArmin Le Grand 195*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive( 196*35726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonHairlinePrimitive2D( 197*35726d9dSArmin Le Grand aRectangle, 198*35726d9dSArmin Le Grand aBlack)); 199*35726d9dSArmin Le Grand 200*35726d9dSArmin Le Grand // prepare VirtualDevice 201*35726d9dSArmin Le Grand VirtualDevice aVirtualDevice; 202*35726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 203*35726d9dSArmin Le Grand 204*35726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(rSize); 205*35726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 206c7be74b1SArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 207c7be74b1SArmin Le Grand : DRAWMODE_DEFAULT); 208c7be74b1SArmin Le Grand 209*35726d9dSArmin Le Grand if(rStyleSettings.GetUIPreviewUsesCheckeredBackground()) 210c7be74b1SArmin Le Grand { 211*35726d9dSArmin Le Grand const Point aNull(0, 0); 212*35726d9dSArmin Le Grand static const sal_uInt32 nLen(8); 213*35726d9dSArmin Le Grand static const Color aW(COL_WHITE); 214*35726d9dSArmin Le Grand static const Color aG(0xef, 0xef, 0xef); 215*35726d9dSArmin Le Grand 216*35726d9dSArmin Le Grand aVirtualDevice.DrawCheckered(aNull, rSize, nLen, aW, aG); 217*35726d9dSArmin Le Grand } 218*35726d9dSArmin Le Grand else 219*35726d9dSArmin Le Grand { 220*35726d9dSArmin Le Grand aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor()); 221*35726d9dSArmin Le Grand aVirtualDevice.Erase(); 222c7be74b1SArmin Le Grand } 223c7be74b1SArmin Le Grand 224*35726d9dSArmin Le Grand // create processor and draw primitives 225*35726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 226*35726d9dSArmin Le Grand aVirtualDevice, 227*35726d9dSArmin Le Grand aNewViewInformation2D); 228*35726d9dSArmin Le Grand 229*35726d9dSArmin Le Grand if(pProcessor2D) 230c7be74b1SArmin Le Grand { 231*35726d9dSArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aSequence(2); 232*35726d9dSArmin Le Grand 233*35726d9dSArmin Le Grand aSequence[0] = aHatchPrimitive; 234*35726d9dSArmin Le Grand aSequence[1] = aBlackRectanglePrimitive; 235*35726d9dSArmin Le Grand 236*35726d9dSArmin Le Grand pProcessor2D->process(aSequence); 237*35726d9dSArmin Le Grand delete pProcessor2D; 238c7be74b1SArmin Le Grand } 239c7be74b1SArmin Le Grand 240*35726d9dSArmin Le Grand // get result bitmap and scale 241*35726d9dSArmin Le Grand aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); 242c7be74b1SArmin Le Grand } 243c7be74b1SArmin Le Grand 244c7be74b1SArmin Le Grand return aRetval; 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 247cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 248cdf0e10cSrcweir // eof 249