xref: /aoo42x/main/svx/source/xoutdev/xtabdash.cxx (revision 81e4f59a)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef SVX_LIGHT
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
32cdf0e10cSrcweir #include "svx/XPropertyTable.hxx"
33cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "xmlxtexp.hxx"
36cdf0e10cSrcweir #include "xmlxtimp.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <vcl/svapp.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <tools/urlobj.hxx>
42cdf0e10cSrcweir #include <vcl/virdev.hxx>
43cdf0e10cSrcweir #include <vcl/window.hxx>
44cdf0e10cSrcweir #include <svl/itemset.hxx>
45cdf0e10cSrcweir #include <sfx2/docfile.hxx>
46cdf0e10cSrcweir #include <svx/dialogs.hrc>
47cdf0e10cSrcweir #include <svx/dialmgr.hxx>
48cdf0e10cSrcweir #include <svx/xtable.hxx>
49cdf0e10cSrcweir #include <svx/xpool.hxx>
50cdf0e10cSrcweir #include <svx/xlineit0.hxx>
51cdf0e10cSrcweir #include <svx/xlnclit.hxx>
52cdf0e10cSrcweir #include <svx/xlnwtit.hxx>
53cdf0e10cSrcweir #include <svx/xlndsit.hxx>
54cdf0e10cSrcweir #include <svx/xflclit.hxx>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include <svx/svdorect.hxx>
57cdf0e10cSrcweir #include <svx/svdopath.hxx>
58cdf0e10cSrcweir #include <svx/svdmodel.hxx>
59cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
60cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
61cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir using namespace com::sun::star;
64cdf0e10cSrcweir using namespace rtl;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #define GLOBALOVERFLOW
67cdf0e10cSrcweir 
68cdf0e10cSrcweir sal_Unicode const pszExtDash[] 	= {'s','o','d'};
69cdf0e10cSrcweir char const aChckDash[]  = { 0x04, 0x00, 'S','O','D','L'};	// < 5.2
70cdf0e10cSrcweir char const aChckDash0[] = { 0x04, 0x00, 'S','O','D','0'};	// = 5.2
71cdf0e10cSrcweir char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };		// = 6.0
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // ----------------
74cdf0e10cSrcweir // class XDashList
75cdf0e10cSrcweir // ----------------
76cdf0e10cSrcweir 
77cdf0e10cSrcweir class impXDashList
78cdf0e10cSrcweir {
79cdf0e10cSrcweir private:
80cdf0e10cSrcweir 	VirtualDevice*          mpVirtualDevice;
81cdf0e10cSrcweir 	SdrModel*				mpSdrModel;
82cdf0e10cSrcweir 	SdrObject*			    mpBackgroundObject;
83cdf0e10cSrcweir 	SdrObject*			    mpLineObject;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir     impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
87cdf0e10cSrcweir     :   mpVirtualDevice(pV),
88cdf0e10cSrcweir         mpSdrModel(pM),
89cdf0e10cSrcweir         mpBackgroundObject(pB),
90cdf0e10cSrcweir         mpLineObject(pL)
91cdf0e10cSrcweir     {}
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     ~impXDashList()
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         delete mpVirtualDevice;
96cdf0e10cSrcweir         SdrObject::Free(mpBackgroundObject);
97cdf0e10cSrcweir         SdrObject::Free(mpLineObject);
98cdf0e10cSrcweir         delete mpSdrModel;
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
102cdf0e10cSrcweir     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
103cdf0e10cSrcweir     SdrObject* getLineObject() const { return mpLineObject; }
104cdf0e10cSrcweir };
105cdf0e10cSrcweir 
106*81e4f59aSArmin Le Grand // to avoid rendering trouble (e.g. vcl renderer) and to get better AAed quality,
107*81e4f59aSArmin Le Grand // use double prerender size
108*81e4f59aSArmin Le Grand static bool bUseDoubleSize = true;
109*81e4f59aSArmin Le Grand 
110cdf0e10cSrcweir void XDashList::impCreate()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     if(!mpData)
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir     	const Point aZero(0, 0);
115cdf0e10cSrcweir 		const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         VirtualDevice* pVirDev = new VirtualDevice;
118cdf0e10cSrcweir 		OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
119cdf0e10cSrcweir 		pVirDev->SetMapMode(MAP_100TH_MM);
120*81e4f59aSArmin Le Grand 		const Size aSize(pVirDev->PixelToLogic(Size(
121*81e4f59aSArmin Le Grand             bUseDoubleSize ? getUiBitmapWidth() * 5 : getUiBitmapWidth() * 5 / 2,
122*81e4f59aSArmin Le Grand             bUseDoubleSize ? getUiBitmapHeight() * 2 : getUiBitmapHeight())));
123cdf0e10cSrcweir 		pVirDev->SetOutputSize(aSize);
124cdf0e10cSrcweir         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
125cdf0e10cSrcweir             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
126cdf0e10cSrcweir             : DRAWMODE_DEFAULT);
12797e8a929SArmin Le Grand         pVirDev->SetBackground(rStyleSettings.GetFieldColor());
12897e8a929SArmin Le Grand 
12997e8a929SArmin Le Grand         SdrModel* pSdrModel = new SdrModel();
130cdf0e10cSrcweir 		OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
131cdf0e10cSrcweir 	    pSdrModel->GetItemPool().FreezeIdRanges();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         const Rectangle aBackgroundSize(aZero, aSize);
134cdf0e10cSrcweir         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
135cdf0e10cSrcweir 		OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
136cdf0e10cSrcweir     	pBackgroundObject->SetModel(pSdrModel);
137cdf0e10cSrcweir         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
138cdf0e10cSrcweir         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
139cdf0e10cSrcweir         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
140cdf0e10cSrcweir 
141*81e4f59aSArmin Le Grand         const sal_uInt32 nHalfHeight(aSize.Height() / 2);
142*81e4f59aSArmin Le Grand         const basegfx::B2DPoint aStart(0, nHalfHeight);
143*81e4f59aSArmin Le Grand         const basegfx::B2DPoint aEnd(aSize.Width(), nHalfHeight);
144cdf0e10cSrcweir 	    basegfx::B2DPolygon aPolygon;
145cdf0e10cSrcweir 	    aPolygon.append(aStart);
146cdf0e10cSrcweir 	    aPolygon.append(aEnd);
147cdf0e10cSrcweir 	    SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
148cdf0e10cSrcweir 		OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" );
149cdf0e10cSrcweir     	pLineObject->SetModel(pSdrModel);
150cdf0e10cSrcweir         pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
151cdf0e10cSrcweir         pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
15297e8a929SArmin Le Grand 		const Size aLineWidth(pVirDev->PixelToLogic(Size(getUiBitmapLineWidth(), 0)));
153*81e4f59aSArmin Le Grand         pLineObject->SetMergedItem(XLineWidthItem(bUseDoubleSize ? aLineWidth.getWidth() * 2 : aLineWidth.getWidth()));
154cdf0e10cSrcweir         mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
155cdf0e10cSrcweir 		OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir void XDashList::impDestroy()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     if(mpData)
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         delete mpData;
164cdf0e10cSrcweir         mpData = 0;
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
16897e8a929SArmin Le Grand XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool )
16997e8a929SArmin Le Grand :   XPropertyList(rPath, pInPool ),
17097e8a929SArmin Le Grand     mpData(0),
17197e8a929SArmin Le Grand     maBitmapSolidLine(),
17297e8a929SArmin Le Grand     maStringSolidLine(),
17397e8a929SArmin Le Grand     maStringNoLine()
174cdf0e10cSrcweir {
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir XDashList::~XDashList()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     impDestroy();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex);
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir XDashEntry* XDashList::Remove(long nIndex)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	return (XDashEntry*) XPropertyList::Remove(nIndex, 0);
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir XDashEntry* XDashList::GetDash(long nIndex) const
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	return (XDashEntry*) XPropertyList::Get(nIndex, 0);
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir sal_Bool XDashList::Load()
198cdf0e10cSrcweir {
19997e8a929SArmin Le Grand 	if( mbListDirty )
200cdf0e10cSrcweir 	{
20197e8a929SArmin Le Grand 		mbListDirty = false;
202cdf0e10cSrcweir 
20397e8a929SArmin Le Grand 		INetURLObject aURL( maPath );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
206cdf0e10cSrcweir 		{
20797e8a929SArmin Le Grand 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
208cdf0e10cSrcweir 			return sal_False;
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
21197e8a929SArmin Le Grand 		aURL.Append( maName );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		if( !aURL.getExtension().getLength() )
214cdf0e10cSrcweir 			aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
217cdf0e10cSrcweir 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
218cdf0e10cSrcweir 	}
219cdf0e10cSrcweir 	return( sal_False );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir sal_Bool XDashList::Save()
223cdf0e10cSrcweir {
22497e8a929SArmin Le Grand 	INetURLObject aURL( maPath );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
227cdf0e10cSrcweir 	{
22897e8a929SArmin Le Grand 		DBG_ASSERT( !maPath.Len(), "invalid URL" );
229cdf0e10cSrcweir 		return sal_False;
230cdf0e10cSrcweir 	}
231cdf0e10cSrcweir 
23297e8a929SArmin Le Grand 	aURL.Append( maName );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	if( !aURL.getExtension().getLength() )
235cdf0e10cSrcweir 		aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
238cdf0e10cSrcweir 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir sal_Bool XDashList::Create()
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) );
244cdf0e10cSrcweir 	xub_StrLen nLen;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	aStr.AppendAscii(" 1");
247cdf0e10cSrcweir 	nLen = aStr.Len() - 1;
248cdf0e10cSrcweir 	Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr));
249cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('2'));
250cdf0e10cSrcweir 	Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr));
251cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('3'));
252cdf0e10cSrcweir 	Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr));
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	return( sal_True );
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
25797e8a929SArmin Le Grand Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     impCreate();
260cdf0e10cSrcweir     VirtualDevice* pVD = mpData->getVirtualDevice();
261cdf0e10cSrcweir     SdrObject* pLine = mpData->getLineObject();
262cdf0e10cSrcweir 
26397e8a929SArmin Le Grand     if(pDash)
26497e8a929SArmin Le Grand     {
26597e8a929SArmin Le Grand         pLine->SetMergedItem(XLineStyleItem(XLINE_DASH));
26697e8a929SArmin Le Grand         pLine->SetMergedItem(XLineDashItem(String(), *pDash));
26797e8a929SArmin Le Grand     }
26897e8a929SArmin Le Grand     else
26997e8a929SArmin Le Grand     {
27097e8a929SArmin Le Grand         pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID));
27197e8a929SArmin Le Grand     }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     sdr::contact::SdrObjectVector aObjectVector;
274cdf0e10cSrcweir 	aObjectVector.push_back(mpData->getBackgroundObject());
275cdf0e10cSrcweir 	aObjectVector.push_back(pLine);
276cdf0e10cSrcweir 	sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
277cdf0e10cSrcweir 	sdr::contact::DisplayInfo aDisplayInfo;
278cdf0e10cSrcweir 
27997e8a929SArmin Le Grand     pVD->Erase();
280cdf0e10cSrcweir 	aPainter.ProcessDisplay(aDisplayInfo);
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     const Point aZero(0, 0);
283*81e4f59aSArmin Le Grand     Bitmap aResult(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
284*81e4f59aSArmin Le Grand 
285*81e4f59aSArmin Le Grand     if(bUseDoubleSize)
286*81e4f59aSArmin Le Grand     {
287*81e4f59aSArmin Le Grand         const Size aCurrentSize(aResult.GetSizePixel());
288*81e4f59aSArmin Le Grand 
289*81e4f59aSArmin Le Grand         aResult.Scale(Size(aCurrentSize.Width() / 2, aCurrentSize.Height() / 2), BMP_SCALE_FASTESTINTERPOLATE);
290*81e4f59aSArmin Le Grand     }
291*81e4f59aSArmin Le Grand 
292*81e4f59aSArmin Le Grand     return aResult;
29397e8a929SArmin Le Grand }
294cdf0e10cSrcweir 
29597e8a929SArmin Le Grand Bitmap XDashList::CreateBitmapForUI( long nIndex )
29697e8a929SArmin Le Grand {
29797e8a929SArmin Le Grand     const XDash& rDash = GetDash(nIndex)->GetDash();
29897e8a929SArmin Le Grand 
29997e8a929SArmin Le Grand     return ImpCreateBitmapForXDash(&rDash);
30097e8a929SArmin Le Grand }
30197e8a929SArmin Le Grand 
30297e8a929SArmin Le Grand Bitmap XDashList::GetBitmapForUISolidLine() const
30397e8a929SArmin Le Grand {
30497e8a929SArmin Le Grand     if(maBitmapSolidLine.IsEmpty())
30597e8a929SArmin Le Grand     {
30697e8a929SArmin Le Grand         const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0);
30797e8a929SArmin Le Grand     }
30897e8a929SArmin Le Grand 
30997e8a929SArmin Le Grand     return maBitmapSolidLine;
31097e8a929SArmin Le Grand }
31197e8a929SArmin Le Grand 
31297e8a929SArmin Le Grand String XDashList::GetStringForUiSolidLine() const
31397e8a929SArmin Le Grand {
31497e8a929SArmin Le Grand     if(!maStringSolidLine.Len())
31597e8a929SArmin Le Grand     {
31697e8a929SArmin Le Grand         const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR()));
31797e8a929SArmin Le Grand     }
31897e8a929SArmin Le Grand 
31997e8a929SArmin Le Grand     return maStringSolidLine;
32097e8a929SArmin Le Grand }
32197e8a929SArmin Le Grand 
32297e8a929SArmin Le Grand String XDashList::GetStringForUiNoLine() const
32397e8a929SArmin Le Grand {
32497e8a929SArmin Le Grand     if(!maStringNoLine.Len())
32597e8a929SArmin Le Grand     {
32697e8a929SArmin Le Grand         // formally was RID_SVXSTR_INVISIBLE, but tomake equal
32797e8a929SArmin Le Grand         // everywhere, use RID_SVXSTR_NONE
32897e8a929SArmin Le Grand         const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR()));
32997e8a929SArmin Le Grand     }
330cdf0e10cSrcweir 
33197e8a929SArmin Le Grand     return maStringNoLine;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
335cdf0e10cSrcweir // eof
336