xref: /aoo42x/main/svx/source/xoutdev/xtabdash.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 <vcl/svapp.hxx>
40 
41 #include <tools/urlobj.hxx>
42 #include <vcl/virdev.hxx>
43 #include <vcl/window.hxx>
44 #include <svl/itemset.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <svx/dialogs.hrc>
47 #include <svx/dialmgr.hxx>
48 #include <svx/xtable.hxx>
49 #include <svx/xpool.hxx>
50 #include <svx/xlineit0.hxx>
51 #include <svx/xlnclit.hxx>
52 #include <svx/xlnwtit.hxx>
53 #include <svx/xlndsit.hxx>
54 #include <svx/xflclit.hxx>
55 
56 #include <svx/svdorect.hxx>
57 #include <svx/svdopath.hxx>
58 #include <svx/svdmodel.hxx>
59 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
60 #include <svx/sdr/contact/displayinfo.hxx>
61 #include <basegfx/polygon/b2dpolygon.hxx>
62 
63 using namespace com::sun::star;
64 using namespace rtl;
65 
66 #define GLOBALOVERFLOW
67 
68 sal_Unicode const pszExtDash[] 	= {'s','o','d'};
69 char const aChckDash[]  = { 0x04, 0x00, 'S','O','D','L'};	// < 5.2
70 char const aChckDash0[] = { 0x04, 0x00, 'S','O','D','0'};	// = 5.2
71 char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };		// = 6.0
72 
73 // -----------------
74 // class XDashTable
75 // -----------------
76 
77 /*************************************************************************
78 |*
79 |* XDashTable::XDashTable()
80 |*
81 *************************************************************************/
82 
83 XDashTable::XDashTable( const String& rPath,
84 							XOutdevItemPool* pInPool,
85 							sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
86 				XPropertyTable( rPath, pInPool, nInitSize, nReSize)
87 {
88 	pBmpTable = new Table( nInitSize, nReSize );
89 }
90 
91 /************************************************************************/
92 
93 XDashTable::~XDashTable()
94 {
95 }
96 
97 /************************************************************************/
98 
99 XDashEntry* XDashTable::Replace(long nIndex, XDashEntry* pEntry )
100 {
101 	return (XDashEntry*) XPropertyTable::Replace(nIndex, pEntry);
102 }
103 
104 /************************************************************************/
105 
106 XDashEntry* XDashTable::Remove(long nIndex)
107 {
108 	return (XDashEntry*) XPropertyTable::Remove(nIndex, 0);
109 }
110 
111 /************************************************************************/
112 
113 XDashEntry* XDashTable::GetDash(long nIndex) const
114 {
115 	return (XDashEntry*) XPropertyTable::Get(nIndex, 0);
116 }
117 
118 /************************************************************************/
119 
120 sal_Bool XDashTable::Load()
121 {
122 	return( sal_False );
123 }
124 
125 /************************************************************************/
126 
127 sal_Bool XDashTable::Save()
128 {
129 	return( sal_False );
130 }
131 
132 /************************************************************************/
133 
134 sal_Bool XDashTable::Create()
135 {
136 	return( sal_False );
137 }
138 
139 /************************************************************************/
140 
141 sal_Bool XDashTable::CreateBitmapsForUI()
142 {
143 	return( sal_False );
144 }
145 
146 /************************************************************************/
147 
148 Bitmap* XDashTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/)
149 {
150 	return( NULL );
151 }
152 
153 // ----------------
154 // class XDashList
155 // ----------------
156 
157 class impXDashList
158 {
159 private:
160 	VirtualDevice*          mpVirtualDevice;
161 	SdrModel*				mpSdrModel;
162 	SdrObject*			    mpBackgroundObject;
163 	SdrObject*			    mpLineObject;
164 
165 public:
166     impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
167     :   mpVirtualDevice(pV),
168         mpSdrModel(pM),
169         mpBackgroundObject(pB),
170         mpLineObject(pL)
171     {}
172 
173     ~impXDashList()
174     {
175         delete mpVirtualDevice;
176         SdrObject::Free(mpBackgroundObject);
177         SdrObject::Free(mpLineObject);
178         delete mpSdrModel;
179     }
180 
181     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
182     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
183     SdrObject* getLineObject() const { return mpLineObject; }
184 };
185 
186 void XDashList::impCreate()
187 {
188     if(!mpData)
189     {
190     	const Point aZero(0, 0);
191 		const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
192 
193         VirtualDevice* pVirDev = new VirtualDevice;
194 		OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
195 		pVirDev->SetMapMode(MAP_100TH_MM);
196 		const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH * 2, BITMAP_HEIGHT)));
197 		pVirDev->SetOutputSize(aSize);
198         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
199             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
200             : DRAWMODE_DEFAULT);
201 
202 	    SdrModel* pSdrModel = new SdrModel();
203 		OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
204 	    pSdrModel->GetItemPool().FreezeIdRanges();
205 
206         const Rectangle aBackgroundSize(aZero, aSize);
207         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
208 		OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
209     	pBackgroundObject->SetModel(pSdrModel);
210         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
211         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
212         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
213 
214         const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
215         const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
216 	    basegfx::B2DPolygon aPolygon;
217 	    aPolygon.append(aStart);
218 	    aPolygon.append(aEnd);
219 	    SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
220 		OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" );
221     	pLineObject->SetModel(pSdrModel);
222         pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
223         pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
224         pLineObject->SetMergedItem(XLineWidthItem(30));
225 
226         mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
227 		OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
228     }
229 }
230 
231 void XDashList::impDestroy()
232 {
233     if(mpData)
234     {
235         delete mpData;
236         mpData = 0;
237     }
238 }
239 
240 XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
241 :   XPropertyList(rPath, pInPool, nInitSize, nReSize),
242     mpData(0)
243 {
244 	pBmpList = new List(nInitSize, nReSize);
245 }
246 
247 XDashList::~XDashList()
248 {
249     impDestroy();
250 }
251 
252 XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
253 {
254 	return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex);
255 }
256 
257 XDashEntry* XDashList::Remove(long nIndex)
258 {
259 	return (XDashEntry*) XPropertyList::Remove(nIndex, 0);
260 }
261 
262 XDashEntry* XDashList::GetDash(long nIndex) const
263 {
264 	return (XDashEntry*) XPropertyList::Get(nIndex, 0);
265 }
266 
267 sal_Bool XDashList::Load()
268 {
269 	if( bListDirty )
270 	{
271 		bListDirty = sal_False;
272 
273 		INetURLObject aURL( aPath );
274 
275 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
276 		{
277 			DBG_ASSERT( !aPath.Len(), "invalid URL" );
278 			return sal_False;
279 		}
280 
281 		aURL.Append( aName );
282 
283 		if( !aURL.getExtension().getLength() )
284 			aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
285 
286 		uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
287 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
288 	}
289 	return( sal_False );
290 }
291 
292 sal_Bool XDashList::Save()
293 {
294 	INetURLObject aURL( aPath );
295 
296 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
297 	{
298 		DBG_ASSERT( !aPath.Len(), "invalid URL" );
299 		return sal_False;
300 	}
301 
302 	aURL.Append( aName );
303 
304 	if( !aURL.getExtension().getLength() )
305 		aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
306 
307 	uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
308 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
309 }
310 
311 sal_Bool XDashList::Create()
312 {
313 	XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) );
314 	xub_StrLen nLen;
315 
316 	aStr.AppendAscii(" 1");
317 	nLen = aStr.Len() - 1;
318 	Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr));
319 	aStr.SetChar(nLen, sal_Unicode('2'));
320 	Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr));
321 	aStr.SetChar(nLen, sal_Unicode('3'));
322 	Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr));
323 
324 	return( sal_True );
325 }
326 
327 sal_Bool XDashList::CreateBitmapsForUI()
328 {
329     impCreate();
330 
331     for( long i = 0; i < Count(); i++)
332 	{
333 		Bitmap* pBmp = CreateBitmapForUI( i, sal_False );
334 		DBG_ASSERT( pBmp, "XDashList: Bitmap(UI) konnte nicht erzeugt werden!" );
335 
336 		if( pBmp )
337 			pBmpList->Insert( pBmp, i );
338 	}
339 
340     impDestroy();
341 
342 	return( sal_True );
343 }
344 
345 Bitmap* XDashList::CreateBitmapForUI( long nIndex, sal_Bool bDelete )
346 {
347     impCreate();
348     VirtualDevice* pVD = mpData->getVirtualDevice();
349     SdrObject* pLine = mpData->getLineObject();
350 
351     pLine->SetMergedItem(XLineStyleItem(XLINE_DASH));
352     pLine->SetMergedItem(XLineDashItem(String(), GetDash(nIndex)->GetDash()));
353 
354     sdr::contact::SdrObjectVector aObjectVector;
355 	aObjectVector.push_back(mpData->getBackgroundObject());
356 	aObjectVector.push_back(pLine);
357 	sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
358 	sdr::contact::DisplayInfo aDisplayInfo;
359 
360 	aPainter.ProcessDisplay(aDisplayInfo);
361 
362     const Point aZero(0, 0);
363 	Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
364 
365 	if(bDelete)
366 	{
367         impDestroy();
368 	}
369 
370 	return pBitmap;
371 }
372 
373 //////////////////////////////////////////////////////////////////////////////
374 // eof
375