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