xref: /aoo42x/main/svx/source/xoutdev/xtabdash.cxx (revision 97e8a929)
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 XDashList
75 // ----------------
76 
77 class impXDashList
78 {
79 private:
80 	VirtualDevice*          mpVirtualDevice;
81 	SdrModel*				mpSdrModel;
82 	SdrObject*			    mpBackgroundObject;
83 	SdrObject*			    mpLineObject;
84 
85 public:
86     impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
87     :   mpVirtualDevice(pV),
88         mpSdrModel(pM),
89         mpBackgroundObject(pB),
90         mpLineObject(pL)
91     {}
92 
93     ~impXDashList()
94     {
95         delete mpVirtualDevice;
96         SdrObject::Free(mpBackgroundObject);
97         SdrObject::Free(mpLineObject);
98         delete mpSdrModel;
99     }
100 
101     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
102     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
103     SdrObject* getLineObject() const { return mpLineObject; }
104 };
105 
106 void XDashList::impCreate()
107 {
108     if(!mpData)
109     {
110     	const Point aZero(0, 0);
111 		const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
112 
113         VirtualDevice* pVirDev = new VirtualDevice;
114 		OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
115 		pVirDev->SetMapMode(MAP_100TH_MM);
116 		const Size aSize(pVirDev->PixelToLogic(Size(getUiBitmapWidth() * 2, getUiBitmapHeight())));
117 		pVirDev->SetOutputSize(aSize);
118         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
119             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
120             : DRAWMODE_DEFAULT);
121         pVirDev->SetBackground(rStyleSettings.GetFieldColor());
122 
123         SdrModel* pSdrModel = new SdrModel();
124 		OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
125 	    pSdrModel->GetItemPool().FreezeIdRanges();
126 
127         const Rectangle aBackgroundSize(aZero, aSize);
128         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
129 		OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
130     	pBackgroundObject->SetModel(pSdrModel);
131         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
132         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
133         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
134 
135         const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
136         const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
137 	    basegfx::B2DPolygon aPolygon;
138 	    aPolygon.append(aStart);
139 	    aPolygon.append(aEnd);
140 	    SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
141 		OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" );
142     	pLineObject->SetModel(pSdrModel);
143         pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
144         pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
145 		const Size aLineWidth(pVirDev->PixelToLogic(Size(getUiBitmapLineWidth(), 0)));
146         pLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth()));
147         mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
148 		OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
149     }
150 }
151 
152 void XDashList::impDestroy()
153 {
154     if(mpData)
155     {
156         delete mpData;
157         mpData = 0;
158     }
159 }
160 
161 XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool )
162 :   XPropertyList(rPath, pInPool ),
163     mpData(0),
164     maBitmapSolidLine(),
165     maStringSolidLine(),
166     maStringNoLine()
167 {
168 }
169 
170 XDashList::~XDashList()
171 {
172     impDestroy();
173 }
174 
175 XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
176 {
177 	return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex);
178 }
179 
180 XDashEntry* XDashList::Remove(long nIndex)
181 {
182 	return (XDashEntry*) XPropertyList::Remove(nIndex, 0);
183 }
184 
185 XDashEntry* XDashList::GetDash(long nIndex) const
186 {
187 	return (XDashEntry*) XPropertyList::Get(nIndex, 0);
188 }
189 
190 sal_Bool XDashList::Load()
191 {
192 	if( mbListDirty )
193 	{
194 		mbListDirty = false;
195 
196 		INetURLObject aURL( maPath );
197 
198 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
199 		{
200 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
201 			return sal_False;
202 		}
203 
204 		aURL.Append( maName );
205 
206 		if( !aURL.getExtension().getLength() )
207 			aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
208 
209 		uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
210 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
211 	}
212 	return( sal_False );
213 }
214 
215 sal_Bool XDashList::Save()
216 {
217 	INetURLObject aURL( maPath );
218 
219 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
220 	{
221 		DBG_ASSERT( !maPath.Len(), "invalid URL" );
222 		return sal_False;
223 	}
224 
225 	aURL.Append( maName );
226 
227 	if( !aURL.getExtension().getLength() )
228 		aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
229 
230 	uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
231 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
232 }
233 
234 sal_Bool XDashList::Create()
235 {
236 	XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) );
237 	xub_StrLen nLen;
238 
239 	aStr.AppendAscii(" 1");
240 	nLen = aStr.Len() - 1;
241 	Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr));
242 	aStr.SetChar(nLen, sal_Unicode('2'));
243 	Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr));
244 	aStr.SetChar(nLen, sal_Unicode('3'));
245 	Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr));
246 
247 	return( sal_True );
248 }
249 
250 Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
251 {
252     impCreate();
253     VirtualDevice* pVD = mpData->getVirtualDevice();
254     SdrObject* pLine = mpData->getLineObject();
255 
256     if(pDash)
257     {
258         pLine->SetMergedItem(XLineStyleItem(XLINE_DASH));
259         pLine->SetMergedItem(XLineDashItem(String(), *pDash));
260     }
261     else
262     {
263         pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID));
264     }
265 
266     sdr::contact::SdrObjectVector aObjectVector;
267 	aObjectVector.push_back(mpData->getBackgroundObject());
268 	aObjectVector.push_back(pLine);
269 	sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
270 	sdr::contact::DisplayInfo aDisplayInfo;
271 
272     pVD->Erase();
273 	aPainter.ProcessDisplay(aDisplayInfo);
274 
275     const Point aZero(0, 0);
276 	return pVD->GetBitmap(aZero, pVD->GetOutputSize());
277 }
278 
279 Bitmap XDashList::CreateBitmapForUI( long nIndex )
280 {
281     const XDash& rDash = GetDash(nIndex)->GetDash();
282 
283     return ImpCreateBitmapForXDash(&rDash);
284 }
285 
286 Bitmap XDashList::GetBitmapForUISolidLine() const
287 {
288     if(maBitmapSolidLine.IsEmpty())
289     {
290         const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0);
291     }
292 
293     return maBitmapSolidLine;
294 }
295 
296 String XDashList::GetStringForUiSolidLine() const
297 {
298     if(!maStringSolidLine.Len())
299     {
300         const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR()));
301     }
302 
303     return maStringSolidLine;
304 }
305 
306 String XDashList::GetStringForUiNoLine() const
307 {
308     if(!maStringNoLine.Len())
309     {
310         // formally was RID_SVXSTR_INVISIBLE, but tomake equal
311         // everywhere, use RID_SVXSTR_NONE
312         const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR()));
313     }
314 
315     return maStringNoLine;
316 }
317 
318 //////////////////////////////////////////////////////////////////////////////
319 // eof
320