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 <tools/urlobj.hxx> 32cdf0e10cSrcweir #include <vcl/virdev.hxx> 33cdf0e10cSrcweir #include <vcl/svapp.hxx> 34cdf0e10cSrcweir #include <svx/dialogs.hrc> 35cdf0e10cSrcweir #include <svx/dialmgr.hxx> 36cdf0e10cSrcweir #include <svx/xtable.hxx> 37*35726d9dSArmin Le Grand #include <drawinglayer/attribute/linestartendattribute.hxx> 38*35726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 39*35726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx> 40cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #define GLOBALOVERFLOW 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace com::sun::star; 45cdf0e10cSrcweir using namespace rtl; 46cdf0e10cSrcweir 47cdf0e10cSrcweir sal_Unicode const pszExtLineEnd[] = {'s','o','e'}; 4897e8a929SArmin Le Grand //static char const aChckLEnd[] = { 0x04, 0x00, 'S','O','E','L'}; // < 5.2 4997e8a929SArmin Le Grand //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'}; // = 5.2 5097e8a929SArmin Le Grand //static char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 51cdf0e10cSrcweir 52cdf0e10cSrcweir // -------------------- 53cdf0e10cSrcweir // class XLineEndList 54cdf0e10cSrcweir // -------------------- 55cdf0e10cSrcweir 56c7be74b1SArmin Le Grand XLineEndList::XLineEndList(const String& rPath) 57*35726d9dSArmin Le Grand : XPropertyList(rPath) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir XLineEndList::~XLineEndList() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir XLineEndEntry* XLineEndList::Remove(long nIndex) 71cdf0e10cSrcweir { 72c7be74b1SArmin Le Grand return (XLineEndEntry*) XPropertyList::Remove(nIndex); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const 76cdf0e10cSrcweir { 77c7be74b1SArmin Le Grand return (XLineEndEntry*) XPropertyList::Get(nIndex); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir sal_Bool XLineEndList::Load() 81cdf0e10cSrcweir { 8297e8a929SArmin Le Grand if( mbListDirty ) 83cdf0e10cSrcweir { 8497e8a929SArmin Le Grand mbListDirty = false; 85cdf0e10cSrcweir 8697e8a929SArmin Le Grand INetURLObject aURL( maPath ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 89cdf0e10cSrcweir { 90*35726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 91cdf0e10cSrcweir return sal_False; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 9497e8a929SArmin Le Grand aURL.Append( maName ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 97cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 100cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir return( sal_False ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir sal_Bool XLineEndList::Save() 106cdf0e10cSrcweir { 10797e8a929SArmin Le Grand INetURLObject aURL( maPath ); 108cdf0e10cSrcweir 109cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 110cdf0e10cSrcweir { 111*35726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" ); 112cdf0e10cSrcweir return sal_False; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 11597e8a929SArmin Le Grand aURL.Append( maName ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 118cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 121cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir sal_Bool XLineEndList::Create() 125cdf0e10cSrcweir { 126cdf0e10cSrcweir basegfx::B2DPolygon aTriangle; 127cdf0e10cSrcweir aTriangle.append(basegfx::B2DPoint(10.0, 0.0)); 128cdf0e10cSrcweir aTriangle.append(basegfx::B2DPoint(0.0, 30.0)); 129cdf0e10cSrcweir aTriangle.append(basegfx::B2DPoint(20.0, 30.0)); 130cdf0e10cSrcweir aTriangle.setClosed(true); 131cdf0e10cSrcweir Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir basegfx::B2DPolygon aSquare; 134cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(0.0, 0.0)); 135cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(10.0, 0.0)); 136cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(10.0, 10.0)); 137cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(0.0, 10.0)); 138cdf0e10cSrcweir aSquare.setClosed(true); 139cdf0e10cSrcweir Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0)); 142cdf0e10cSrcweir Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) ); 143cdf0e10cSrcweir 144cdf0e10cSrcweir return( sal_True ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 14797e8a929SArmin Le Grand Bitmap XLineEndList::CreateBitmapForUI( long nIndex ) 148cdf0e10cSrcweir { 149c7be74b1SArmin Le Grand Bitmap aRetval; 150*35726d9dSArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); 151cdf0e10cSrcweir 152*35726d9dSArmin Le Grand if(nIndex < Count()) 153c7be74b1SArmin Le Grand { 154c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 155c7be74b1SArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 156*35726d9dSArmin Le Grand const Size aSize(rSize.Width() * 2, rSize.Height()); 157c7be74b1SArmin Le Grand 158*35726d9dSArmin Le Grand // prepare line geometry 159*35726d9dSArmin Le Grand basegfx::B2DPolygon aLine; 160*35726d9dSArmin Le Grand const double fBorderDistance(aSize.Height() * 0.1); 161*35726d9dSArmin Le Grand 162*35726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2)); 163*35726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2)); 164*35726d9dSArmin Le Grand 165*35726d9dSArmin Le Grand // prepare LineAttribute 166*35726d9dSArmin Le Grand const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor()); 167*35726d9dSArmin Le Grand const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * 1.1); 168*35726d9dSArmin Le Grand const drawinglayer::attribute::LineAttribute aLineAttribute( 169*35726d9dSArmin Le Grand aLineColor, 170*35726d9dSArmin Le Grand fLineWidth); 171*35726d9dSArmin Le Grand 172*35726d9dSArmin Le Grand const basegfx::B2DPolyPolygon aLineEnd(GetLineEnd(nIndex)->GetLineEnd()); 173*35726d9dSArmin Le Grand const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance)); 174*35726d9dSArmin Le Grand const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute( 175*35726d9dSArmin Le Grand fArrowHeight, 176*35726d9dSArmin Le Grand aLineEnd, 177*35726d9dSArmin Le Grand false); 178*35726d9dSArmin Le Grand 179*35726d9dSArmin Le Grand // prepare line primitive 180*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive( 181*35726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonStrokeArrowPrimitive2D( 182*35726d9dSArmin Le Grand aLine, 183*35726d9dSArmin Le Grand aLineAttribute, 184*35726d9dSArmin Le Grand aLineStartEndAttribute, 185*35726d9dSArmin Le Grand aLineStartEndAttribute)); 186*35726d9dSArmin Le Grand 187*35726d9dSArmin Le Grand // prepare VirtualDevice 188*35726d9dSArmin Le Grand VirtualDevice aVirtualDevice; 189*35726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 190*35726d9dSArmin Le Grand 191*35726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(aSize); 192*35726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 193c7be74b1SArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 194c7be74b1SArmin Le Grand : DRAWMODE_DEFAULT); 195c7be74b1SArmin Le Grand 196*35726d9dSArmin Le Grand if(rStyleSettings.GetUIPreviewUsesCheckeredBackground()) 197c7be74b1SArmin Le Grand { 198*35726d9dSArmin Le Grand const Point aNull(0, 0); 199*35726d9dSArmin Le Grand static const sal_uInt32 nLen(8); 200*35726d9dSArmin Le Grand static const Color aW(COL_WHITE); 201*35726d9dSArmin Le Grand static const Color aG(0xef, 0xef, 0xef); 202*35726d9dSArmin Le Grand 203*35726d9dSArmin Le Grand aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG); 204*35726d9dSArmin Le Grand } 205*35726d9dSArmin Le Grand else 206*35726d9dSArmin Le Grand { 207*35726d9dSArmin Le Grand aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor()); 208*35726d9dSArmin Le Grand aVirtualDevice.Erase(); 209c7be74b1SArmin Le Grand } 210c7be74b1SArmin Le Grand 211*35726d9dSArmin Le Grand // create processor and draw primitives 212*35726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 213*35726d9dSArmin Le Grand aVirtualDevice, 214*35726d9dSArmin Le Grand aNewViewInformation2D); 215*35726d9dSArmin Le Grand 216*35726d9dSArmin Le Grand if(pProcessor2D) 217c7be74b1SArmin Le Grand { 218*35726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLineStartEndPrimitive, 1); 219*35726d9dSArmin Le Grand 220*35726d9dSArmin Le Grand pProcessor2D->process(aSequence); 221*35726d9dSArmin Le Grand delete pProcessor2D; 222c7be74b1SArmin Le Grand } 223c7be74b1SArmin Le Grand 224*35726d9dSArmin Le Grand // get result bitmap and scale 225*35726d9dSArmin Le Grand aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); 226c7be74b1SArmin Le Grand } 227c7be74b1SArmin Le Grand 228c7be74b1SArmin Le Grand return aRetval; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 232cdf0e10cSrcweir // eof 233