1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svx.hxx" 24 25 // include --------------------------------------------------------------- 26 #include <com/sun/star/container/XNameContainer.hpp> 27 #include "svx/XPropertyTable.hxx" 28 #include <unotools/ucbstreamhelper.hxx> 29 #include "xmlxtexp.hxx" 30 #include "xmlxtimp.hxx" 31 #include <tools/urlobj.hxx> 32 #include <vcl/virdev.hxx> 33 #include <vcl/svapp.hxx> 34 #include <svx/dialogs.hrc> 35 #include <svx/dialmgr.hxx> 36 #include <svx/xtable.hxx> 37 #include <drawinglayer/attribute/linestartendattribute.hxx> 38 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 39 #include <drawinglayer/processor2d/processor2dtools.hxx> 40 #include <basegfx/polygon/b2dpolygontools.hxx> 41 42 #define GLOBALOVERFLOW 43 44 using namespace com::sun::star; 45 using namespace rtl; 46 47 sal_Unicode const pszExtLineEnd[] = {'s','o','e'}; 48 //static char const aChckLEnd[] = { 0x04, 0x00, 'S','O','E','L'}; // < 5.2 49 //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'}; // = 5.2 50 //static char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 51 52 // -------------------- 53 // class XLineEndList 54 // -------------------- 55 56 XLineEndList::XLineEndList(const String& rPath) 57 : XPropertyList(rPath) 58 { 59 } 60 61 XLineEndList::~XLineEndList() 62 { 63 } 64 65 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex ) 66 { 67 return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex); 68 } 69 70 XLineEndEntry* XLineEndList::Remove(long nIndex) 71 { 72 return (XLineEndEntry*) XPropertyList::Remove(nIndex); 73 } 74 75 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const 76 { 77 return (XLineEndEntry*) XPropertyList::Get(nIndex); 78 } 79 80 sal_Bool XLineEndList::Load() 81 { 82 if( mbListDirty ) 83 { 84 mbListDirty = false; 85 86 INetURLObject aURL( maPath ); 87 88 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 89 { 90 OSL_ENSURE( !maPath.Len(), "invalid URL" ); 91 return sal_False; 92 } 93 94 aURL.Append( maName ); 95 96 if( !aURL.getExtension().getLength() ) 97 aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 98 99 uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 100 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 101 } 102 return( sal_False ); 103 } 104 105 sal_Bool XLineEndList::Save() 106 { 107 INetURLObject aURL( maPath ); 108 109 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 110 { 111 OSL_ENSURE( !maPath.Len(), "invalid URL" ); 112 return sal_False; 113 } 114 115 aURL.Append( maName ); 116 117 if( !aURL.getExtension().getLength() ) 118 aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 119 120 uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 121 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 122 } 123 124 sal_Bool XLineEndList::Create() 125 { 126 basegfx::B2DPolygon aTriangle; 127 aTriangle.append(basegfx::B2DPoint(10.0, 0.0)); 128 aTriangle.append(basegfx::B2DPoint(0.0, 30.0)); 129 aTriangle.append(basegfx::B2DPoint(20.0, 30.0)); 130 aTriangle.setClosed(true); 131 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) ); 132 133 basegfx::B2DPolygon aSquare; 134 aSquare.append(basegfx::B2DPoint(0.0, 0.0)); 135 aSquare.append(basegfx::B2DPoint(10.0, 0.0)); 136 aSquare.append(basegfx::B2DPoint(10.0, 10.0)); 137 aSquare.append(basegfx::B2DPoint(0.0, 10.0)); 138 aSquare.setClosed(true); 139 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) ); 140 141 basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0)); 142 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) ); 143 144 return( sal_True ); 145 } 146 147 Bitmap XLineEndList::CreateBitmapForUI( long nIndex ) 148 { 149 Bitmap aRetval; 150 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); 151 152 if(nIndex < Count()) 153 { 154 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 155 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 156 const Size aSize(rSize.Width() * 2, rSize.Height()); 157 158 // prepare line geometry 159 basegfx::B2DPolygon aLine; 160 const double fBorderDistance(aSize.Height() * 0.1); 161 162 aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2)); 163 aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2)); 164 165 // prepare LineAttribute 166 const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor()); 167 const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * 1.1); 168 const drawinglayer::attribute::LineAttribute aLineAttribute( 169 aLineColor, 170 fLineWidth); 171 172 const basegfx::B2DPolyPolygon aLineEnd(GetLineEnd(nIndex)->GetLineEnd()); 173 const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance)); 174 const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute( 175 fArrowHeight, 176 aLineEnd, 177 false); 178 179 // prepare line primitive 180 const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive( 181 new drawinglayer::primitive2d::PolygonStrokeArrowPrimitive2D( 182 aLine, 183 aLineAttribute, 184 aLineStartEndAttribute, 185 aLineStartEndAttribute)); 186 187 // prepare VirtualDevice 188 VirtualDevice aVirtualDevice; 189 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; 190 191 aVirtualDevice.SetOutputSizePixel(aSize); 192 aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() 193 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 194 : DRAWMODE_DEFAULT); 195 196 if(rStyleSettings.GetUIPreviewUsesCheckeredBackground()) 197 { 198 const Point aNull(0, 0); 199 static const sal_uInt32 nLen(8); 200 static const Color aW(COL_WHITE); 201 static const Color aG(0xef, 0xef, 0xef); 202 203 aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG); 204 } 205 else 206 { 207 aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor()); 208 aVirtualDevice.Erase(); 209 } 210 211 // create processor and draw primitives 212 drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( 213 aVirtualDevice, 214 aNewViewInformation2D); 215 216 if(pProcessor2D) 217 { 218 const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLineStartEndPrimitive, 1); 219 220 pProcessor2D->process(aSequence); 221 delete pProcessor2D; 222 } 223 224 // get result bitmap and scale 225 aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); 226 } 227 228 return aRetval; 229 } 230 231 ////////////////////////////////////////////////////////////////////////////// 232 // eof 233