xref: /aoo41x/main/svx/source/xoutdev/xtabdash.cxx (revision c7be74b1)
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'};
69*c7be74b1SArmin Le Grand //char const aChckDash[]  = { 0x04, 0x00, 'S','O','D','L'};	// < 5.2
70*c7be74b1SArmin Le Grand //char const aChckDash0[] = { 0x04, 0x00, 'S','O','D','0'};	// = 5.2
71*c7be74b1SArmin Le Grand //char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };		// = 6.0
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // ----------------
74cdf0e10cSrcweir // class XDashList
75cdf0e10cSrcweir // ----------------
76cdf0e10cSrcweir 
77*c7be74b1SArmin Le Grand XDashList::XDashList(const String& rPath )
78*c7be74b1SArmin Le Grand :   XPropertyList(rPath ),
79*c7be74b1SArmin Le Grand     mpBackgroundObject(0),
80*c7be74b1SArmin Le Grand     mpLineObject(0),
8197e8a929SArmin Le Grand     maBitmapSolidLine(),
8297e8a929SArmin Le Grand     maStringSolidLine(),
8397e8a929SArmin Le Grand     maStringNoLine()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir XDashList::~XDashList()
88cdf0e10cSrcweir {
89*c7be74b1SArmin Le Grand     SdrObject::Free(mpBackgroundObject);
90*c7be74b1SArmin Le Grand     SdrObject::Free(mpLineObject);
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex);
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir XDashEntry* XDashList::Remove(long nIndex)
99cdf0e10cSrcweir {
100*c7be74b1SArmin Le Grand 	return (XDashEntry*) XPropertyList::Remove(nIndex);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir XDashEntry* XDashList::GetDash(long nIndex) const
104cdf0e10cSrcweir {
105*c7be74b1SArmin Le Grand 	return (XDashEntry*) XPropertyList::Get(nIndex);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir sal_Bool XDashList::Load()
109cdf0e10cSrcweir {
11097e8a929SArmin Le Grand 	if( mbListDirty )
111cdf0e10cSrcweir 	{
11297e8a929SArmin Le Grand 		mbListDirty = false;
113cdf0e10cSrcweir 
11497e8a929SArmin Le Grand 		INetURLObject aURL( maPath );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
117cdf0e10cSrcweir 		{
11897e8a929SArmin Le Grand 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
119cdf0e10cSrcweir 			return sal_False;
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 
12297e8a929SArmin Le Grand 		aURL.Append( maName );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 		if( !aURL.getExtension().getLength() )
125cdf0e10cSrcweir 			aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
128cdf0e10cSrcweir 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
129cdf0e10cSrcweir 	}
130cdf0e10cSrcweir 	return( sal_False );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir sal_Bool XDashList::Save()
134cdf0e10cSrcweir {
13597e8a929SArmin Le Grand 	INetURLObject aURL( maPath );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
138cdf0e10cSrcweir 	{
13997e8a929SArmin Le Grand 		DBG_ASSERT( !maPath.Len(), "invalid URL" );
140cdf0e10cSrcweir 		return sal_False;
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 
14397e8a929SArmin Le Grand 	aURL.Append( maName );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	if( !aURL.getExtension().getLength() )
146cdf0e10cSrcweir 		aURL.setExtension( rtl::OUString( pszExtDash, 3 ) );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xTable( SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
149cdf0e10cSrcweir 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir sal_Bool XDashList::Create()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) );
155cdf0e10cSrcweir 	xub_StrLen nLen;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	aStr.AppendAscii(" 1");
158cdf0e10cSrcweir 	nLen = aStr.Len() - 1;
159cdf0e10cSrcweir 	Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr));
160cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('2'));
161cdf0e10cSrcweir 	Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr));
162cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('3'));
163cdf0e10cSrcweir 	Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr));
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	return( sal_True );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
16897e8a929SArmin Le Grand Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
169cdf0e10cSrcweir {
170*c7be74b1SArmin Le Grand     // to avoid rendering trouble (e.g. vcl renderer) and to get better AAed quality,
171*c7be74b1SArmin Le Grand     // use double prerender size
172*c7be74b1SArmin Le Grand     static bool bUseDoubleSize = true;
173cdf0e10cSrcweir 
174*c7be74b1SArmin Le Grand     Bitmap aRetval;
175*c7be74b1SArmin Le Grand     OSL_ENSURE(pGlobalsharedModelAndVDev, "OOps, global values missing (!)");
176cdf0e10cSrcweir 
177*c7be74b1SArmin Le Grand     if(pGlobalsharedModelAndVDev)
178*c7be74b1SArmin Le Grand     {
179*c7be74b1SArmin Le Grand         SdrModel& rModel = pGlobalsharedModelAndVDev->getSharedSdrModel();
180*c7be74b1SArmin Le Grand         VirtualDevice& rVirDev = pGlobalsharedModelAndVDev->getSharedVirtualDevice();
181*c7be74b1SArmin Le Grand         const Point aZero(0, 0);
182*c7be74b1SArmin Le Grand         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
183*c7be74b1SArmin Le Grand         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
184*c7be74b1SArmin Le Grand         const Size aSize(rVirDev.PixelToLogic(Size(
185*c7be74b1SArmin Le Grand             bUseDoubleSize ? rSize.Width() * 5 : rSize.Width() * 5 / 2,
186*c7be74b1SArmin Le Grand             bUseDoubleSize ? rSize.Height() * 2 : rSize.Height())));
187cdf0e10cSrcweir 
188*c7be74b1SArmin Le Grand         rVirDev.SetOutputSize(aSize);
189*c7be74b1SArmin Le Grand         rVirDev.SetDrawMode(rStyleSettings.GetHighContrastMode()
190*c7be74b1SArmin Le Grand             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
191*c7be74b1SArmin Le Grand             : DRAWMODE_DEFAULT);
192*c7be74b1SArmin Le Grand         rVirDev.SetBackground(rStyleSettings.GetFieldColor());
193*c7be74b1SArmin Le Grand 
194*c7be74b1SArmin Le Grand         if(!mpBackgroundObject)
195*c7be74b1SArmin Le Grand         {
196*c7be74b1SArmin Le Grand             const Rectangle aBackgroundSize(aZero, aSize);
197*c7be74b1SArmin Le Grand             mpBackgroundObject = new SdrRectObj(aBackgroundSize);
198*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpBackgroundObject, "XDashList: no BackgroundObject created!" );
199*c7be74b1SArmin Le Grand             mpBackgroundObject->SetModel(&rModel);
200*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
201*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
202*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
203*c7be74b1SArmin Le Grand         }
204*c7be74b1SArmin Le Grand 
205*c7be74b1SArmin Le Grand         if(!mpLineObject)
206*c7be74b1SArmin Le Grand         {
207*c7be74b1SArmin Le Grand             const sal_uInt32 nHalfHeight(aSize.Height() / 2);
208*c7be74b1SArmin Le Grand             const basegfx::B2DPoint aStart(0, nHalfHeight);
209*c7be74b1SArmin Le Grand             const basegfx::B2DPoint aEnd(aSize.Width(), nHalfHeight);
210*c7be74b1SArmin Le Grand             basegfx::B2DPolygon aPolygon;
211*c7be74b1SArmin Le Grand             aPolygon.append(aStart);
212*c7be74b1SArmin Le Grand             aPolygon.append(aEnd);
213*c7be74b1SArmin Le Grand             mpLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
214*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpLineObject, "XDashList: no LineObject created!" );
215*c7be74b1SArmin Le Grand             mpLineObject->SetModel(&rModel);
216*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
217*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
218*c7be74b1SArmin Le Grand             const Size aLineWidth(rVirDev.PixelToLogic(Size(rStyleSettings.GetListBoxPreviewDefaultLineWidth(), 0)));
219*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineWidthItem(bUseDoubleSize ? aLineWidth.getWidth() * 2 : aLineWidth.getWidth()));
220*c7be74b1SArmin Le Grand         }
221*c7be74b1SArmin Le Grand 
222*c7be74b1SArmin Le Grand         if(pDash)
223*c7be74b1SArmin Le Grand         {
224*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
225*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineDashItem(String(), *pDash));
226*c7be74b1SArmin Le Grand         }
227*c7be74b1SArmin Le Grand         else
228*c7be74b1SArmin Le Grand         {
229*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
230*c7be74b1SArmin Le Grand         }
231*c7be74b1SArmin Le Grand 
232*c7be74b1SArmin Le Grand         sdr::contact::SdrObjectVector aObjectVector;
233*c7be74b1SArmin Le Grand 
234*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpBackgroundObject);
235*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpLineObject);
236*c7be74b1SArmin Le Grand 
237*c7be74b1SArmin Le Grand         sdr::contact::ObjectContactOfObjListPainter aPainter(rVirDev, aObjectVector, 0);
238*c7be74b1SArmin Le Grand         sdr::contact::DisplayInfo aDisplayInfo;
239*c7be74b1SArmin Le Grand 
240*c7be74b1SArmin Le Grand         rVirDev.Erase();
241*c7be74b1SArmin Le Grand         aPainter.ProcessDisplay(aDisplayInfo);
242*c7be74b1SArmin Le Grand 
243*c7be74b1SArmin Le Grand         aRetval = rVirDev.GetBitmap(aZero, rVirDev.GetOutputSize());
24481e4f59aSArmin Le Grand 
245*c7be74b1SArmin Le Grand         if(bUseDoubleSize)
246*c7be74b1SArmin Le Grand         {
247*c7be74b1SArmin Le Grand             const Size aCurrentSize(aRetval.GetSizePixel());
24881e4f59aSArmin Le Grand 
249*c7be74b1SArmin Le Grand             aRetval.Scale(Size(aCurrentSize.Width() / 2, aCurrentSize.Height() / 2), BMP_SCALE_FASTESTINTERPOLATE);
250*c7be74b1SArmin Le Grand         }
25181e4f59aSArmin Le Grand     }
25281e4f59aSArmin Le Grand 
253*c7be74b1SArmin Le Grand     return aRetval;
25497e8a929SArmin Le Grand }
255cdf0e10cSrcweir 
25697e8a929SArmin Le Grand Bitmap XDashList::CreateBitmapForUI( long nIndex )
25797e8a929SArmin Le Grand {
258*c7be74b1SArmin Le Grand     Bitmap aRetval;
259*c7be74b1SArmin Le Grand     OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)");
260*c7be74b1SArmin Le Grand 
261*c7be74b1SArmin Le Grand     if(nIndex < Count())
262*c7be74b1SArmin Le Grand     {
263*c7be74b1SArmin Le Grand         const XDash& rDash = GetDash(nIndex)->GetDash();
264*c7be74b1SArmin Le Grand 
265*c7be74b1SArmin Le Grand         aRetval = ImpCreateBitmapForXDash(&rDash);
266*c7be74b1SArmin Le Grand     }
26797e8a929SArmin Le Grand 
268*c7be74b1SArmin Le Grand     return aRetval;
26997e8a929SArmin Le Grand }
27097e8a929SArmin Le Grand 
27197e8a929SArmin Le Grand Bitmap XDashList::GetBitmapForUISolidLine() const
27297e8a929SArmin Le Grand {
27397e8a929SArmin Le Grand     if(maBitmapSolidLine.IsEmpty())
27497e8a929SArmin Le Grand     {
27597e8a929SArmin Le Grand         const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0);
27697e8a929SArmin Le Grand     }
27797e8a929SArmin Le Grand 
27897e8a929SArmin Le Grand     return maBitmapSolidLine;
27997e8a929SArmin Le Grand }
28097e8a929SArmin Le Grand 
28197e8a929SArmin Le Grand String XDashList::GetStringForUiSolidLine() const
28297e8a929SArmin Le Grand {
28397e8a929SArmin Le Grand     if(!maStringSolidLine.Len())
28497e8a929SArmin Le Grand     {
28597e8a929SArmin Le Grand         const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR()));
28697e8a929SArmin Le Grand     }
28797e8a929SArmin Le Grand 
28897e8a929SArmin Le Grand     return maStringSolidLine;
28997e8a929SArmin Le Grand }
29097e8a929SArmin Le Grand 
29197e8a929SArmin Le Grand String XDashList::GetStringForUiNoLine() const
29297e8a929SArmin Le Grand {
29397e8a929SArmin Le Grand     if(!maStringNoLine.Len())
29497e8a929SArmin Le Grand     {
29597e8a929SArmin Le Grand         // formally was RID_SVXSTR_INVISIBLE, but tomake equal
29697e8a929SArmin Le Grand         // everywhere, use RID_SVXSTR_NONE
29797e8a929SArmin Le Grand         const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR()));
29897e8a929SArmin Le Grand     }
299cdf0e10cSrcweir 
30097e8a929SArmin Le Grand     return maStringNoLine;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
304cdf0e10cSrcweir // eof
305