xref: /aoo41x/main/svx/source/xoutdev/xtabhtch.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 #include <vcl/svapp.hxx>
39 
40 #include "xmlxtexp.hxx"
41 #include "xmlxtimp.hxx"
42 
43 #endif
44 
45 #include <tools/urlobj.hxx>
46 #include <vcl/virdev.hxx>
47 #include <svl/itemset.hxx>
48 #include <sfx2/docfile.hxx>
49 #include <svx/dialogs.hrc>
50 #include <svx/dialmgr.hxx>
51 #include <svx/xtable.hxx>
52 #include <svx/xpool.hxx>
53 #include "svx/dlgutil.hxx"
54 #include <svx/xflhtit.hxx>
55 #include <svx/xflclit.hxx>
56 #include <svx/xfillit0.hxx>
57 
58 #include <svx/svdorect.hxx>
59 #include <svx/svdmodel.hxx>
60 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
61 #include <svx/sdr/contact/displayinfo.hxx>
62 #include <svx/xlnclit.hxx>
63 
64 using namespace ::com::sun::star;
65 using namespace ::rtl;
66 
67 sal_Unicode const pszExtHatch[]	 = {'s','o','h'};
68 
69 char const aChckHatch[]  = { 0x04, 0x00, 'S','O','H','L'};	// < 5.2
70 char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'};	// = 5.2
71 char const aChckXML[]    = { '<', '?', 'x', 'm', 'l' };		// = 6.0
72 
73 // ------------------
74 // class XHatchTable
75 // ------------------
76 
77 /*************************************************************************
78 |*
79 |* XHatchTable::XHatchTable()
80 |*
81 *************************************************************************/
82 
83 XHatchTable::XHatchTable( 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 XHatchTable::~XHatchTable()
94 {
95 }
96 
97 /************************************************************************/
98 
99 XHatchEntry* XHatchTable::Replace(long nIndex, XHatchEntry* pEntry )
100 {
101 	return (XHatchEntry*) XPropertyTable::Replace(nIndex, pEntry);
102 }
103 
104 /************************************************************************/
105 
106 XHatchEntry* XHatchTable::Remove(long nIndex)
107 {
108 	return (XHatchEntry*) XPropertyTable::Remove(nIndex, 0);
109 }
110 
111 /************************************************************************/
112 
113 XHatchEntry* XHatchTable::GetHatch(long nIndex) const
114 {
115 	return (XHatchEntry*) XPropertyTable::Get(nIndex, 0);
116 }
117 
118 /************************************************************************/
119 
120 sal_Bool XHatchTable::Load()
121 {
122 	return( sal_False );
123 }
124 
125 /************************************************************************/
126 
127 sal_Bool XHatchTable::Save()
128 {
129 	return( sal_False );
130 }
131 
132 /************************************************************************/
133 
134 sal_Bool XHatchTable::Create()
135 {
136 	return( sal_False );
137 }
138 
139 /************************************************************************/
140 
141 sal_Bool XHatchTable::CreateBitmapsForUI()
142 {
143 	return( sal_False );
144 }
145 
146 /************************************************************************/
147 
148 Bitmap* XHatchTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/)
149 {
150 	return( NULL );
151 }
152 
153 // -----------------
154 // class XHatchList
155 // -----------------
156 
157 class impXHatchList
158 {
159 private:
160 	VirtualDevice*          mpVirtualDevice;
161 	SdrModel*				mpSdrModel;
162 	SdrObject*			    mpBackgroundObject;
163 	SdrObject*			    mpHatchObject;
164 
165 public:
166     impXHatchList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pH)
167     :   mpVirtualDevice(pV),
168         mpSdrModel(pM),
169         mpBackgroundObject(pB),
170         mpHatchObject(pH)
171     {}
172 
173     ~impXHatchList()
174     {
175         delete mpVirtualDevice;
176         SdrObject::Free(mpBackgroundObject);
177         SdrObject::Free(mpHatchObject);
178         delete mpSdrModel;
179     }
180 
181     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
182     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
183     SdrObject* getHatchObject() const { return mpHatchObject; }
184 };
185 
186 void XHatchList::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, 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 Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1)));
207         const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
208         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
209 		OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
210     	pBackgroundObject->SetModel(pSdrModel);
211         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
212         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
213         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
214         pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
215 
216         SdrObject* pHatchObject = new SdrRectObj(aBackgroundSize);
217 		OSL_ENSURE(0 != pHatchObject, "XDashList: no HatchObject created!" );
218     	pHatchObject->SetModel(pSdrModel);
219         pHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
220         pHatchObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
221 
222         mpData = new impXHatchList(pVirDev, pSdrModel, pBackgroundObject, pHatchObject);
223 		OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
224     }
225 }
226 
227 void XHatchList::impDestroy()
228 {
229     if(mpData)
230     {
231         delete mpData;
232         mpData = 0;
233     }
234 }
235 
236 XHatchList::XHatchList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
237 :   XPropertyList(rPath, pInPool, nInitSize, nReSize),
238     mpData(0)
239 {
240 	pBmpList = new List(nInitSize, nReSize);
241 }
242 
243 XHatchList::~XHatchList()
244 {
245     if(mpData)
246     {
247         delete mpData;
248         mpData = 0;
249     }
250 }
251 
252 XHatchEntry* XHatchList::Replace(XHatchEntry* pEntry, long nIndex )
253 {
254 	return (XHatchEntry*) XPropertyList::Replace(pEntry, nIndex);
255 }
256 
257 XHatchEntry* XHatchList::Remove(long nIndex)
258 {
259 	return (XHatchEntry*) XPropertyList::Remove(nIndex, 0);
260 }
261 
262 XHatchEntry* XHatchList::GetHatch(long nIndex) const
263 {
264 	return (XHatchEntry*) XPropertyList::Get(nIndex, 0);
265 }
266 
267 sal_Bool XHatchList::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( pszExtHatch, 3 ) );
285 
286 		uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_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 XHatchList::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( pszExtHatch, 3 ) );
306 
307 	uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
308 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
309 }
310 
311 sal_Bool XHatchList::Create()
312 {
313 	XubString aStr( SVX_RES( RID_SVXSTR_HATCH ) );
314 	xub_StrLen nLen;
315 
316 	aStr.AppendAscii(" 1");
317 	nLen = aStr.Len() - 1;
318 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100,  0),aStr));
319 	aStr.SetChar(nLen, sal_Unicode('2'));
320 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED  ),XHATCH_DOUBLE, 80,450),aStr));
321 	aStr.SetChar(nLen, sal_Unicode('3'));
322 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120,  0),aStr));
323 
324 	return( sal_True );
325 }
326 
327 sal_Bool XHatchList::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, "XHatchList: 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* XHatchList::CreateBitmapForUI( long nIndex, sal_Bool bDelete )
346 {
347     impCreate();
348     VirtualDevice* pVD = mpData->getVirtualDevice();
349     SdrObject* pHatchObject = mpData->getHatchObject();
350 
351     pHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
352     pHatchObject->SetMergedItem(XFillHatchItem(String(), GetHatch(nIndex)->GetHatch()));
353 
354     sdr::contact::SdrObjectVector aObjectVector;
355 	aObjectVector.push_back(mpData->getBackgroundObject());
356 	aObjectVector.push_back(pHatchObject);
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