xref: /aoo41x/main/svx/source/xoutdev/xtablend.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 // include ---------------------------------------------------------------
32 
33 #ifndef SVX_LIGHT
34 
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include "svx/XPropertyTable.hxx"
37 #include <unotools/ucbstreamhelper.hxx>
38 
39 #include "xmlxtexp.hxx"
40 #include "xmlxtimp.hxx"
41 
42 #endif
43 #include <tools/urlobj.hxx>
44 #include <vcl/virdev.hxx>
45 
46 #ifndef _SV_APP_HXX
47 #include <vcl/svapp.hxx>
48 #endif
49 #include <svl/itemset.hxx>
50 #include <sfx2/docfile.hxx>
51 
52 #include <svx/dialogs.hrc>
53 #include <svx/dialmgr.hxx>
54 
55 #include <svx/xtable.hxx>
56 #include <svx/xpool.hxx>
57 #include <svx/xfillit0.hxx>
58 #include <svx/xflclit.hxx>
59 #include <svx/xlnstwit.hxx>
60 #include <svx/xlnedwit.hxx>
61 #include <svx/xlnclit.hxx>
62 #include <svx/xlineit0.hxx>
63 #include <svx/xlnstit.hxx>
64 #include <svx/xlnedit.hxx>
65 #include <basegfx/point/b2dpoint.hxx>
66 #include <basegfx/polygon/b2dpolygon.hxx>
67 #include <basegfx/polygon/b2dpolygontools.hxx>
68 
69 #include <svx/svdorect.hxx>
70 #include <svx/svdopath.hxx>
71 #include <svx/svdmodel.hxx>
72 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
73 #include <svx/sdr/contact/displayinfo.hxx>
74 
75 #define GLOBALOVERFLOW
76 
77 using namespace com::sun::star;
78 using namespace rtl;
79 
80 sal_Unicode const pszExtLineEnd[]	= {'s','o','e'};
81 
82 static char const aChckLEnd[]  = { 0x04, 0x00, 'S','O','E','L'};	// < 5.2
83 static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'};	// = 5.2
84 static char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };		// = 6.0
85 
86 // --------------------
87 // class XLineEndTable
88 // --------------------
89 
90 /*************************************************************************
91 |*
92 |* XLineEndTable::XLineEndTable()
93 |*
94 *************************************************************************/
95 
96 XLineEndTable::XLineEndTable( const String& rPath,
97 							XOutdevItemPool* pInPool,
98 							sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
99 				XPropertyTable( rPath, pInPool, nInitSize, nReSize)
100 {
101 	pBmpTable = new Table( nInitSize, nReSize );
102 }
103 
104 /************************************************************************/
105 
106 XLineEndTable::~XLineEndTable()
107 {
108 }
109 
110 /************************************************************************/
111 
112 XLineEndEntry* XLineEndTable::Replace(long nIndex, XLineEndEntry* pEntry )
113 {
114 	return (XLineEndEntry*) XPropertyTable::Replace(nIndex, pEntry);
115 }
116 
117 /************************************************************************/
118 
119 XLineEndEntry* XLineEndTable::Remove(long nIndex)
120 {
121 	return (XLineEndEntry*) XPropertyTable::Remove(nIndex, 0);
122 }
123 
124 /************************************************************************/
125 
126 XLineEndEntry* XLineEndTable::GetLineEnd(long nIndex) const
127 {
128 	return (XLineEndEntry*) XPropertyTable::Get(nIndex, 0);
129 }
130 
131 /************************************************************************/
132 
133 sal_Bool XLineEndTable::Load()
134 {
135 	return( sal_False );
136 }
137 
138 /************************************************************************/
139 
140 sal_Bool XLineEndTable::Save()
141 {
142 	return( sal_False );
143 }
144 
145 /************************************************************************/
146 
147 sal_Bool XLineEndTable::Create()
148 {
149 	return( sal_False );
150 }
151 
152 /************************************************************************/
153 
154 Bitmap* XLineEndTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/)
155 {
156 	return( NULL );
157 }
158 
159 /************************************************************************/
160 
161 sal_Bool XLineEndTable::CreateBitmapsForUI()
162 {
163 	return( sal_False );
164 }
165 
166 // --------------------
167 // class XLineEndList
168 // --------------------
169 
170 class impXLineEndList
171 {
172 private:
173 	VirtualDevice*          mpVirtualDevice;
174 	SdrModel*				mpSdrModel;
175 	SdrObject*			    mpBackgroundObject;
176 	SdrObject*			    mpLineObject;
177 
178 public:
179     impXLineEndList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
180     :   mpVirtualDevice(pV),
181         mpSdrModel(pM),
182         mpBackgroundObject(pB),
183         mpLineObject(pL)
184     {}
185 
186     ~impXLineEndList()
187     {
188         delete mpVirtualDevice;
189         SdrObject::Free(mpBackgroundObject);
190         SdrObject::Free(mpLineObject);
191         delete mpSdrModel;
192     }
193 
194     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
195     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
196     SdrObject* getLineObject() const { return mpLineObject; }
197 };
198 
199 void XLineEndList::impCreate()
200 {
201     if(!mpData)
202     {
203     	const Point aZero(0, 0);
204 		const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
205 
206         VirtualDevice* pVirDev = new VirtualDevice;
207 		OSL_ENSURE(0 != pVirDev, "XLineEndList: no VirtualDevice created!" );
208 		pVirDev->SetMapMode(MAP_100TH_MM);
209 		const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH * 2, BITMAP_HEIGHT)));
210 		pVirDev->SetOutputSize(aSize);
211         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
212             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
213             : DRAWMODE_DEFAULT);
214 
215 	    SdrModel* pSdrModel = new SdrModel();
216 		OSL_ENSURE(0 != pSdrModel, "XLineEndList: no SdrModel created!" );
217 	    pSdrModel->GetItemPool().FreezeIdRanges();
218 
219         const Rectangle aBackgroundSize(aZero, aSize);
220         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
221 		OSL_ENSURE(0 != pBackgroundObject, "XLineEndList: no BackgroundObject created!" );
222     	pBackgroundObject->SetModel(pSdrModel);
223         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
224         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
225         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
226 
227         const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
228         const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
229 	    basegfx::B2DPolygon aPolygon;
230 	    aPolygon.append(aStart);
231 	    aPolygon.append(aEnd);
232 	    SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
233 		OSL_ENSURE(0 != pLineObject, "XLineEndList: no LineObject created!" );
234     	pLineObject->SetModel(pSdrModel);
235         pLineObject->SetMergedItem(XLineStartWidthItem(aSize.Height()));
236         pLineObject->SetMergedItem(XLineEndWidthItem(aSize.Height()));
237         pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
238 
239         mpData = new impXLineEndList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
240 		OSL_ENSURE(0 != mpData, "XLineEndList: data creation went wrong!" );
241     }
242 }
243 
244 void XLineEndList::impDestroy()
245 {
246     if(mpData)
247     {
248         delete mpData;
249         mpData = 0;
250     }
251 }
252 
253 XLineEndList::XLineEndList(const String& rPath, XOutdevItemPool* _pXPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
254 :	XPropertyList(rPath, _pXPool, nInitSize, nReSize),
255 	mpData(0)
256 {
257 	pBmpList = new List(nInitSize, nReSize);
258 }
259 
260 XLineEndList::~XLineEndList()
261 {
262     impDestroy();
263 }
264 
265 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex )
266 {
267 	return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex);
268 }
269 
270 XLineEndEntry* XLineEndList::Remove(long nIndex)
271 {
272 	return (XLineEndEntry*) XPropertyList::Remove(nIndex, 0);
273 }
274 
275 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const
276 {
277 	return (XLineEndEntry*) XPropertyList::Get(nIndex, 0);
278 }
279 
280 sal_Bool XLineEndList::Load()
281 {
282 	if( bListDirty )
283 	{
284 		bListDirty = sal_False;
285 
286 		INetURLObject aURL( aPath );
287 
288 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
289 		{
290 			DBG_ASSERT( !aPath.Len(), "invalid URL" );
291 			return sal_False;
292 		}
293 
294 		aURL.Append( aName );
295 
296 		if( !aURL.getExtension().getLength() )
297 			aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
298 
299 		uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
300 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
301 	}
302 	return( sal_False );
303 }
304 
305 sal_Bool XLineEndList::Save()
306 {
307 	INetURLObject aURL( aPath );
308 
309 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
310 	{
311 		DBG_ASSERT( !aPath.Len(), "invalid URL" );
312 		return sal_False;
313 	}
314 
315 	aURL.Append( aName );
316 
317 	if( !aURL.getExtension().getLength() )
318 		aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
319 
320 	uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
321 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
322 }
323 
324 sal_Bool XLineEndList::Create()
325 {
326 	basegfx::B2DPolygon aTriangle;
327 	aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
328 	aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
329 	aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
330 	aTriangle.setClosed(true);
331 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) );
332 
333 	basegfx::B2DPolygon aSquare;
334 	aSquare.append(basegfx::B2DPoint(0.0, 0.0));
335 	aSquare.append(basegfx::B2DPoint(10.0, 0.0));
336 	aSquare.append(basegfx::B2DPoint(10.0, 10.0));
337 	aSquare.append(basegfx::B2DPoint(0.0, 10.0));
338 	aSquare.setClosed(true);
339 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) );
340 
341 	basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
342 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) );
343 
344 	return( sal_True );
345 }
346 
347 sal_Bool XLineEndList::CreateBitmapsForUI()
348 {
349     impCreate();
350 
351     for( long i = 0; i < Count(); i++)
352 	{
353 		Bitmap* pBmp = CreateBitmapForUI( i, sal_False );
354 		OSL_ENSURE(0 != pBmp, "XLineEndList: Bitmap(UI) could not be created!" );
355 
356 		if( pBmp )
357 			pBmpList->Insert( pBmp, i );
358 	}
359 
360     impDestroy();
361 
362 	return( sal_True );
363 }
364 
365 Bitmap* XLineEndList::CreateBitmapForUI( long nIndex, sal_Bool bDelete )
366 {
367     impCreate();
368     VirtualDevice* pVD = mpData->getVirtualDevice();
369     SdrObject* pLine = mpData->getLineObject();
370 
371     pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID));
372     pLine->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
373     pLine->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
374 
375     sdr::contact::SdrObjectVector aObjectVector;
376 	aObjectVector.push_back(mpData->getBackgroundObject());
377 	aObjectVector.push_back(pLine);
378 	sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
379 	sdr::contact::DisplayInfo aDisplayInfo;
380 
381 	aPainter.ProcessDisplay(aDisplayInfo);
382 
383     const Point aZero(0, 0);
384 	Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
385 
386 	if(bDelete)
387 	{
388         impDestroy();
389 	}
390 
391 	return pBitmap;
392 }
393 
394 //////////////////////////////////////////////////////////////////////////////
395 // eof
396