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 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 // include --------------------------------------------------------------- 28 29 #ifndef SVX_LIGHT 30 31 #include <com/sun/star/container/XNameContainer.hpp> 32 #include "svx/XPropertyTable.hxx" 33 #include <unotools/ucbstreamhelper.hxx> 34 35 #include "xmlxtexp.hxx" 36 #include "xmlxtimp.hxx" 37 38 #endif 39 #include <tools/urlobj.hxx> 40 #include <vcl/virdev.hxx> 41 42 #ifndef _SV_APP_HXX 43 #include <vcl/svapp.hxx> 44 #endif 45 #include <svl/itemset.hxx> 46 #include <sfx2/docfile.hxx> 47 48 #include <svx/dialogs.hrc> 49 #include <svx/dialmgr.hxx> 50 51 #include <svx/xtable.hxx> 52 #include <svx/xpool.hxx> 53 #include <svx/xfillit0.hxx> 54 #include <svx/xflclit.hxx> 55 #include <svx/xlnstwit.hxx> 56 #include <svx/xlnedwit.hxx> 57 #include <svx/xlnclit.hxx> 58 #include <svx/xlineit0.hxx> 59 #include <svx/xlnstit.hxx> 60 #include <svx/xlnedit.hxx> 61 #include <basegfx/point/b2dpoint.hxx> 62 #include <basegfx/polygon/b2dpolygon.hxx> 63 #include <basegfx/polygon/b2dpolygontools.hxx> 64 65 #include <svx/svdorect.hxx> 66 #include <svx/svdopath.hxx> 67 #include <svx/svdmodel.hxx> 68 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx> 69 #include <svx/sdr/contact/displayinfo.hxx> 70 #include <svx/xlnwtit.hxx> 71 72 #define GLOBALOVERFLOW 73 74 using namespace com::sun::star; 75 using namespace rtl; 76 77 sal_Unicode const pszExtLineEnd[] = {'s','o','e'}; 78 //static char const aChckLEnd[] = { 0x04, 0x00, 'S','O','E','L'}; // < 5.2 79 //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'}; // = 5.2 80 //static char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0 81 82 // -------------------- 83 // class XLineEndList 84 // -------------------- 85 86 class impXLineEndList 87 { 88 private: 89 VirtualDevice* mpVirtualDevice; 90 SdrModel* mpSdrModel; 91 SdrObject* mpBackgroundObject; 92 SdrObject* mpLineObject; 93 94 public: 95 impXLineEndList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL) 96 : mpVirtualDevice(pV), 97 mpSdrModel(pM), 98 mpBackgroundObject(pB), 99 mpLineObject(pL) 100 {} 101 102 ~impXLineEndList() 103 { 104 delete mpVirtualDevice; 105 SdrObject::Free(mpBackgroundObject); 106 SdrObject::Free(mpLineObject); 107 delete mpSdrModel; 108 } 109 110 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; } 111 SdrObject* getBackgroundObject() const { return mpBackgroundObject; } 112 SdrObject* getLineObject() const { return mpLineObject; } 113 }; 114 115 void XLineEndList::impCreate() 116 { 117 if(!mpData) 118 { 119 const Point aZero(0, 0); 120 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 121 122 VirtualDevice* pVirDev = new VirtualDevice; 123 OSL_ENSURE(0 != pVirDev, "XLineEndList: no VirtualDevice created!" ); 124 pVirDev->SetMapMode(MAP_100TH_MM); 125 const Size aSize(pVirDev->PixelToLogic(Size(getUiBitmapWidth() * 2, getUiBitmapHeight()))); 126 pVirDev->SetOutputSize(aSize); 127 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode() 128 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 129 : DRAWMODE_DEFAULT); 130 pVirDev->SetBackground(rStyleSettings.GetFieldColor()); 131 132 SdrModel* pSdrModel = new SdrModel(); 133 OSL_ENSURE(0 != pSdrModel, "XLineEndList: no SdrModel created!" ); 134 pSdrModel->GetItemPool().FreezeIdRanges(); 135 136 const Rectangle aBackgroundSize(aZero, aSize); 137 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize); 138 OSL_ENSURE(0 != pBackgroundObject, "XLineEndList: no BackgroundObject created!" ); 139 pBackgroundObject->SetModel(pSdrModel); 140 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID)); 141 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE)); 142 pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor())); 143 144 const basegfx::B2DPoint aStart(0, aSize.Height() / 2); 145 const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2); 146 basegfx::B2DPolygon aPolygon; 147 aPolygon.append(aStart); 148 aPolygon.append(aEnd); 149 SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon)); 150 OSL_ENSURE(0 != pLineObject, "XLineEndList: no LineObject created!" ); 151 pLineObject->SetModel(pSdrModel); 152 const Size aLineWidth(pVirDev->PixelToLogic(Size(getUiBitmapLineWidth(), 0))); 153 pLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth())); 154 const sal_uInt32 nArrowHeight((aSize.Height() * 8) / 10); 155 pLineObject->SetMergedItem(XLineStartWidthItem(nArrowHeight)); 156 pLineObject->SetMergedItem(XLineEndWidthItem(nArrowHeight)); 157 pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor())); 158 159 mpData = new impXLineEndList(pVirDev, pSdrModel, pBackgroundObject, pLineObject); 160 OSL_ENSURE(0 != mpData, "XLineEndList: data creation went wrong!" ); 161 } 162 } 163 164 void XLineEndList::impDestroy() 165 { 166 if(mpData) 167 { 168 delete mpData; 169 mpData = 0; 170 } 171 } 172 173 XLineEndList::XLineEndList(const String& rPath, XOutdevItemPool* _pXPool) 174 : XPropertyList(rPath, _pXPool), 175 mpData(0) 176 { 177 } 178 179 XLineEndList::~XLineEndList() 180 { 181 impDestroy(); 182 } 183 184 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex ) 185 { 186 return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex); 187 } 188 189 XLineEndEntry* XLineEndList::Remove(long nIndex) 190 { 191 return (XLineEndEntry*) XPropertyList::Remove(nIndex, 0); 192 } 193 194 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const 195 { 196 return (XLineEndEntry*) XPropertyList::Get(nIndex, 0); 197 } 198 199 sal_Bool XLineEndList::Load() 200 { 201 if( mbListDirty ) 202 { 203 mbListDirty = false; 204 205 INetURLObject aURL( maPath ); 206 207 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 208 { 209 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 210 return sal_False; 211 } 212 213 aURL.Append( maName ); 214 215 if( !aURL.getExtension().getLength() ) 216 aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 217 218 uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 219 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 220 } 221 return( sal_False ); 222 } 223 224 sal_Bool XLineEndList::Save() 225 { 226 INetURLObject aURL( maPath ); 227 228 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 229 { 230 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 231 return sal_False; 232 } 233 234 aURL.Append( maName ); 235 236 if( !aURL.getExtension().getLength() ) 237 aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 238 239 uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 240 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 241 } 242 243 sal_Bool XLineEndList::Create() 244 { 245 basegfx::B2DPolygon aTriangle; 246 aTriangle.append(basegfx::B2DPoint(10.0, 0.0)); 247 aTriangle.append(basegfx::B2DPoint(0.0, 30.0)); 248 aTriangle.append(basegfx::B2DPoint(20.0, 30.0)); 249 aTriangle.setClosed(true); 250 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) ); 251 252 basegfx::B2DPolygon aSquare; 253 aSquare.append(basegfx::B2DPoint(0.0, 0.0)); 254 aSquare.append(basegfx::B2DPoint(10.0, 0.0)); 255 aSquare.append(basegfx::B2DPoint(10.0, 10.0)); 256 aSquare.append(basegfx::B2DPoint(0.0, 10.0)); 257 aSquare.setClosed(true); 258 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) ); 259 260 basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0)); 261 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) ); 262 263 return( sal_True ); 264 } 265 266 Bitmap XLineEndList::CreateBitmapForUI( long nIndex ) 267 { 268 impCreate(); 269 VirtualDevice* pVD = mpData->getVirtualDevice(); 270 SdrObject* pLine = mpData->getLineObject(); 271 272 pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID)); 273 pLine->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex)->GetLineEnd())); 274 pLine->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex)->GetLineEnd())); 275 276 sdr::contact::SdrObjectVector aObjectVector; 277 aObjectVector.push_back(mpData->getBackgroundObject()); 278 aObjectVector.push_back(pLine); 279 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0); 280 sdr::contact::DisplayInfo aDisplayInfo; 281 282 pVD->Erase(); 283 aPainter.ProcessDisplay(aDisplayInfo); 284 285 const Point aZero(0, 0); 286 return pVD->GetBitmap(aZero, pVD->GetOutputSize()); 287 } 288 289 ////////////////////////////////////////////////////////////////////////////// 290 // eof 291