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 XLineEndList::XLineEndList(const String& rPath) 87 : XPropertyList(rPath), 88 mpBackgroundObject(0), 89 mpLineObject(0) 90 { 91 } 92 93 XLineEndList::~XLineEndList() 94 { 95 SdrObject::Free(mpBackgroundObject); 96 SdrObject::Free(mpLineObject); 97 } 98 99 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex ) 100 { 101 return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex); 102 } 103 104 XLineEndEntry* XLineEndList::Remove(long nIndex) 105 { 106 return (XLineEndEntry*) XPropertyList::Remove(nIndex); 107 } 108 109 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const 110 { 111 return (XLineEndEntry*) XPropertyList::Get(nIndex); 112 } 113 114 sal_Bool XLineEndList::Load() 115 { 116 if( mbListDirty ) 117 { 118 mbListDirty = false; 119 120 INetURLObject aURL( maPath ); 121 122 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 123 { 124 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 125 return sal_False; 126 } 127 128 aURL.Append( maName ); 129 130 if( !aURL.getExtension().getLength() ) 131 aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 132 133 uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 134 return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 135 } 136 return( sal_False ); 137 } 138 139 sal_Bool XLineEndList::Save() 140 { 141 INetURLObject aURL( maPath ); 142 143 if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 144 { 145 DBG_ASSERT( !maPath.Len(), "invalid URL" ); 146 return sal_False; 147 } 148 149 aURL.Append( maName ); 150 151 if( !aURL.getExtension().getLength() ) 152 aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) ); 153 154 uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY ); 155 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable ); 156 } 157 158 sal_Bool XLineEndList::Create() 159 { 160 basegfx::B2DPolygon aTriangle; 161 aTriangle.append(basegfx::B2DPoint(10.0, 0.0)); 162 aTriangle.append(basegfx::B2DPoint(0.0, 30.0)); 163 aTriangle.append(basegfx::B2DPoint(20.0, 30.0)); 164 aTriangle.setClosed(true); 165 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) ); 166 167 basegfx::B2DPolygon aSquare; 168 aSquare.append(basegfx::B2DPoint(0.0, 0.0)); 169 aSquare.append(basegfx::B2DPoint(10.0, 0.0)); 170 aSquare.append(basegfx::B2DPoint(10.0, 10.0)); 171 aSquare.append(basegfx::B2DPoint(0.0, 10.0)); 172 aSquare.setClosed(true); 173 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) ); 174 175 basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0)); 176 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) ); 177 178 return( sal_True ); 179 } 180 181 Bitmap XLineEndList::CreateBitmapForUI( long nIndex ) 182 { 183 Bitmap aRetval; 184 OSL_ENSURE(pGlobalsharedModelAndVDev, "OOps, global values missing (!)"); 185 OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)"); 186 187 if(pGlobalsharedModelAndVDev && nIndex < Count()) 188 { 189 SdrModel& rModel = pGlobalsharedModelAndVDev->getSharedSdrModel(); 190 VirtualDevice& rVirDev = pGlobalsharedModelAndVDev->getSharedVirtualDevice(); 191 const Point aZero(0, 0); 192 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 193 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); 194 const Size aSize(rVirDev.PixelToLogic(Size(rSize.Width() * 2, rSize.Height()))); 195 196 rVirDev.SetOutputSize(aSize); 197 rVirDev.SetDrawMode(rStyleSettings.GetHighContrastMode() 198 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT 199 : DRAWMODE_DEFAULT); 200 rVirDev.SetBackground(rStyleSettings.GetFieldColor()); 201 202 if(!mpBackgroundObject) 203 { 204 const Rectangle aBackgroundSize(aZero, aSize); 205 mpBackgroundObject = new SdrRectObj(aBackgroundSize); 206 OSL_ENSURE(0 != mpBackgroundObject, "XLineEndList: no BackgroundObject created!" ); 207 mpBackgroundObject->SetModel(&rModel); 208 mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID)); 209 mpBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE)); 210 mpBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor())); 211 } 212 213 if(!mpLineObject) 214 { 215 const basegfx::B2DPoint aStart(0, aSize.Height() / 2); 216 const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2); 217 basegfx::B2DPolygon aPolygon; 218 aPolygon.append(aStart); 219 aPolygon.append(aEnd); 220 mpLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon)); 221 OSL_ENSURE(0 != mpLineObject, "XLineEndList: no LineObject created!" ); 222 mpLineObject->SetModel(&rModel); 223 const Size aLineWidth(rVirDev.PixelToLogic(Size(rStyleSettings.GetListBoxPreviewDefaultLineWidth(), 0))); 224 mpLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth())); 225 const sal_uInt32 nArrowHeight((aSize.Height() * 8) / 10); 226 mpLineObject->SetMergedItem(XLineStartWidthItem(nArrowHeight)); 227 mpLineObject->SetMergedItem(XLineEndWidthItem(nArrowHeight)); 228 mpLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor())); 229 } 230 231 mpLineObject->SetMergedItem(XLineStyleItem(XLINE_SOLID)); 232 mpLineObject->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex)->GetLineEnd())); 233 mpLineObject->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex)->GetLineEnd())); 234 235 sdr::contact::SdrObjectVector aObjectVector; 236 237 aObjectVector.push_back(mpBackgroundObject); 238 aObjectVector.push_back(mpLineObject); 239 240 sdr::contact::ObjectContactOfObjListPainter aPainter(rVirDev, aObjectVector, 0); 241 sdr::contact::DisplayInfo aDisplayInfo; 242 243 rVirDev.Erase(); 244 aPainter.ProcessDisplay(aDisplayInfo); 245 246 aRetval = rVirDev.GetBitmap(aZero, rVirDev.GetOutputSize()); 247 } 248 249 return aRetval; 250 } 251 252 ////////////////////////////////////////////////////////////////////////////// 253 // eof 254