xref: /aoo42x/main/svx/source/xoutdev/xtablend.cxx (revision f6e50924)
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 
71 #define GLOBALOVERFLOW
72 
73 using namespace com::sun::star;
74 using namespace rtl;
75 
76 sal_Unicode const pszExtLineEnd[]	= {'s','o','e'};
77 
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 XLineEndTable
84 // --------------------
85 
86 /*************************************************************************
87 |*
88 |* XLineEndTable::XLineEndTable()
89 |*
90 *************************************************************************/
91 
92 XLineEndTable::XLineEndTable( const String& rPath,
93 							XOutdevItemPool* pInPool,
94 							sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
95 				XPropertyTable( rPath, pInPool, nInitSize, nReSize)
96 {
97 	pBmpTable = new Table( nInitSize, nReSize );
98 }
99 
100 /************************************************************************/
101 
102 XLineEndTable::~XLineEndTable()
103 {
104 }
105 
106 /************************************************************************/
107 
108 XLineEndEntry* XLineEndTable::Replace(long nIndex, XLineEndEntry* pEntry )
109 {
110 	return (XLineEndEntry*) XPropertyTable::Replace(nIndex, pEntry);
111 }
112 
113 /************************************************************************/
114 
115 XLineEndEntry* XLineEndTable::Remove(long nIndex)
116 {
117 	return (XLineEndEntry*) XPropertyTable::Remove(nIndex, 0);
118 }
119 
120 /************************************************************************/
121 
122 XLineEndEntry* XLineEndTable::GetLineEnd(long nIndex) const
123 {
124 	return (XLineEndEntry*) XPropertyTable::Get(nIndex, 0);
125 }
126 
127 /************************************************************************/
128 
129 sal_Bool XLineEndTable::Load()
130 {
131 	return( sal_False );
132 }
133 
134 /************************************************************************/
135 
136 sal_Bool XLineEndTable::Save()
137 {
138 	return( sal_False );
139 }
140 
141 /************************************************************************/
142 
143 sal_Bool XLineEndTable::Create()
144 {
145 	return( sal_False );
146 }
147 
148 /************************************************************************/
149 
150 Bitmap* XLineEndTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/)
151 {
152 	return( NULL );
153 }
154 
155 /************************************************************************/
156 
157 sal_Bool XLineEndTable::CreateBitmapsForUI()
158 {
159 	return( sal_False );
160 }
161 
162 // --------------------
163 // class XLineEndList
164 // --------------------
165 
166 class impXLineEndList
167 {
168 private:
169 	VirtualDevice*          mpVirtualDevice;
170 	SdrModel*				mpSdrModel;
171 	SdrObject*			    mpBackgroundObject;
172 	SdrObject*			    mpLineObject;
173 
174 public:
175     impXLineEndList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
176     :   mpVirtualDevice(pV),
177         mpSdrModel(pM),
178         mpBackgroundObject(pB),
179         mpLineObject(pL)
180     {}
181 
182     ~impXLineEndList()
183     {
184         delete mpVirtualDevice;
185         SdrObject::Free(mpBackgroundObject);
186         SdrObject::Free(mpLineObject);
187         delete mpSdrModel;
188     }
189 
190     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
191     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
192     SdrObject* getLineObject() const { return mpLineObject; }
193 };
194 
195 void XLineEndList::impCreate()
196 {
197     if(!mpData)
198     {
199     	const Point aZero(0, 0);
200 		const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
201 
202         VirtualDevice* pVirDev = new VirtualDevice;
203 		OSL_ENSURE(0 != pVirDev, "XLineEndList: no VirtualDevice created!" );
204 		pVirDev->SetMapMode(MAP_100TH_MM);
205 		const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH * 2, BITMAP_HEIGHT)));
206 		pVirDev->SetOutputSize(aSize);
207         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
208             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
209             : DRAWMODE_DEFAULT);
210 
211 	    SdrModel* pSdrModel = new SdrModel();
212 		OSL_ENSURE(0 != pSdrModel, "XLineEndList: no SdrModel created!" );
213 	    pSdrModel->GetItemPool().FreezeIdRanges();
214 
215         const Rectangle aBackgroundSize(aZero, aSize);
216         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
217 		OSL_ENSURE(0 != pBackgroundObject, "XLineEndList: no BackgroundObject created!" );
218     	pBackgroundObject->SetModel(pSdrModel);
219         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
220         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
221         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
222 
223         const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
224         const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
225 	    basegfx::B2DPolygon aPolygon;
226 	    aPolygon.append(aStart);
227 	    aPolygon.append(aEnd);
228 	    SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
229 		OSL_ENSURE(0 != pLineObject, "XLineEndList: no LineObject created!" );
230     	pLineObject->SetModel(pSdrModel);
231         pLineObject->SetMergedItem(XLineStartWidthItem(aSize.Height()));
232         pLineObject->SetMergedItem(XLineEndWidthItem(aSize.Height()));
233         pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
234 
235         mpData = new impXLineEndList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
236 		OSL_ENSURE(0 != mpData, "XLineEndList: data creation went wrong!" );
237     }
238 }
239 
240 void XLineEndList::impDestroy()
241 {
242     if(mpData)
243     {
244         delete mpData;
245         mpData = 0;
246     }
247 }
248 
249 XLineEndList::XLineEndList(const String& rPath, XOutdevItemPool* _pXPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
250 :	XPropertyList(rPath, _pXPool, nInitSize, nReSize),
251 	mpData(0)
252 {
253 	pBmpList = new List(nInitSize, nReSize);
254 }
255 
256 XLineEndList::~XLineEndList()
257 {
258     impDestroy();
259 }
260 
261 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex )
262 {
263 	return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex);
264 }
265 
266 XLineEndEntry* XLineEndList::Remove(long nIndex)
267 {
268 	return (XLineEndEntry*) XPropertyList::Remove(nIndex, 0);
269 }
270 
271 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const
272 {
273 	return (XLineEndEntry*) XPropertyList::Get(nIndex, 0);
274 }
275 
276 sal_Bool XLineEndList::Load()
277 {
278 	if( bListDirty )
279 	{
280 		bListDirty = sal_False;
281 
282 		INetURLObject aURL( aPath );
283 
284 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
285 		{
286 			DBG_ASSERT( !aPath.Len(), "invalid URL" );
287 			return sal_False;
288 		}
289 
290 		aURL.Append( aName );
291 
292 		if( !aURL.getExtension().getLength() )
293 			aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
294 
295 		uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
296 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
297 	}
298 	return( sal_False );
299 }
300 
301 sal_Bool XLineEndList::Save()
302 {
303 	INetURLObject aURL( aPath );
304 
305 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
306 	{
307 		DBG_ASSERT( !aPath.Len(), "invalid URL" );
308 		return sal_False;
309 	}
310 
311 	aURL.Append( aName );
312 
313 	if( !aURL.getExtension().getLength() )
314 		aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
315 
316 	uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
317 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
318 }
319 
320 sal_Bool XLineEndList::Create()
321 {
322 	basegfx::B2DPolygon aTriangle;
323 	aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
324 	aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
325 	aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
326 	aTriangle.setClosed(true);
327 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) );
328 
329 	basegfx::B2DPolygon aSquare;
330 	aSquare.append(basegfx::B2DPoint(0.0, 0.0));
331 	aSquare.append(basegfx::B2DPoint(10.0, 0.0));
332 	aSquare.append(basegfx::B2DPoint(10.0, 10.0));
333 	aSquare.append(basegfx::B2DPoint(0.0, 10.0));
334 	aSquare.setClosed(true);
335 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) );
336 
337 	basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
338 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) );
339 
340 	return( sal_True );
341 }
342 
343 sal_Bool XLineEndList::CreateBitmapsForUI()
344 {
345     impCreate();
346 
347     for( long i = 0; i < Count(); i++)
348 	{
349 		Bitmap* pBmp = CreateBitmapForUI( i, sal_False );
350 		OSL_ENSURE(0 != pBmp, "XLineEndList: Bitmap(UI) could not be created!" );
351 
352 		if( pBmp )
353 			pBmpList->Insert( pBmp, i );
354 	}
355 
356     impDestroy();
357 
358 	return( sal_True );
359 }
360 
361 Bitmap* XLineEndList::CreateBitmapForUI( long nIndex, sal_Bool bDelete )
362 {
363     impCreate();
364     VirtualDevice* pVD = mpData->getVirtualDevice();
365     SdrObject* pLine = mpData->getLineObject();
366 
367     pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID));
368     pLine->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
369     pLine->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
370 
371     sdr::contact::SdrObjectVector aObjectVector;
372 	aObjectVector.push_back(mpData->getBackgroundObject());
373 	aObjectVector.push_back(pLine);
374 	sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
375 	sdr::contact::DisplayInfo aDisplayInfo;
376 
377 	aPainter.ProcessDisplay(aDisplayInfo);
378 
379     const Point aZero(0, 0);
380 	Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
381 
382 	if(bDelete)
383 	{
384         impDestroy();
385 	}
386 
387 	return pBitmap;
388 }
389 
390 //////////////////////////////////////////////////////////////////////////////
391 // eof
392