xref: /trunk/main/svx/source/xoutdev/xtabhtch.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 #include <vcl/svapp.hxx>
35 
36 #include "xmlxtexp.hxx"
37 #include "xmlxtimp.hxx"
38 
39 #endif
40 
41 #include <tools/urlobj.hxx>
42 #include <vcl/virdev.hxx>
43 #include <svl/itemset.hxx>
44 #include <sfx2/docfile.hxx>
45 #include <svx/dialogs.hrc>
46 #include <svx/dialmgr.hxx>
47 #include <svx/xtable.hxx>
48 #include <svx/xpool.hxx>
49 #include "svx/dlgutil.hxx"
50 #include <svx/xflhtit.hxx>
51 #include <svx/xflclit.hxx>
52 #include <svx/xfillit0.hxx>
53 
54 #include <svx/svdorect.hxx>
55 #include <svx/svdmodel.hxx>
56 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
57 #include <svx/sdr/contact/displayinfo.hxx>
58 #include <svx/xlnclit.hxx>
59 
60 using namespace ::com::sun::star;
61 using namespace ::rtl;
62 
63 sal_Unicode const pszExtHatch[]	 = {'s','o','h'};
64 
65 char const aChckHatch[]  = { 0x04, 0x00, 'S','O','H','L'};	// < 5.2
66 char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'};	// = 5.2
67 char const aChckXML[]    = { '<', '?', 'x', 'm', 'l' };		// = 6.0
68 
69 // -----------------
70 // class XHatchList
71 // -----------------
72 
73 class impXHatchList
74 {
75 private:
76 	VirtualDevice*          mpVirtualDevice;
77 	SdrModel*				mpSdrModel;
78 	SdrObject*			    mpBackgroundObject;
79 	SdrObject*			    mpHatchObject;
80 
81 public:
82     impXHatchList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pH)
83     :   mpVirtualDevice(pV),
84         mpSdrModel(pM),
85         mpBackgroundObject(pB),
86         mpHatchObject(pH)
87     {}
88 
89     ~impXHatchList()
90     {
91         delete mpVirtualDevice;
92         SdrObject::Free(mpBackgroundObject);
93         SdrObject::Free(mpHatchObject);
94         delete mpSdrModel;
95     }
96 
97     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
98     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
99     SdrObject* getHatchObject() const { return mpHatchObject; }
100 };
101 
102 void XHatchList::impCreate()
103 {
104     if(!mpData)
105     {
106     	const Point aZero(0, 0);
107 		const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
108 
109         VirtualDevice* pVirDev = new VirtualDevice;
110 		OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
111 		pVirDev->SetMapMode(MAP_100TH_MM);
112 		const Size aSize(pVirDev->PixelToLogic(Size(getUiBitmapWidth(), getUiBitmapHeight())));
113 		pVirDev->SetOutputSize(aSize);
114         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
115             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
116             : DRAWMODE_DEFAULT);
117         pVirDev->SetBackground(rStyleSettings.GetFieldColor());
118 
119         SdrModel* pSdrModel = new SdrModel();
120 		OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
121 	    pSdrModel->GetItemPool().FreezeIdRanges();
122 
123         const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1)));
124         const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
125         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
126 		OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
127     	pBackgroundObject->SetModel(pSdrModel);
128         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
129         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
130         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
131         pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
132 
133         SdrObject* pHatchObject = new SdrRectObj(aBackgroundSize);
134 		OSL_ENSURE(0 != pHatchObject, "XDashList: no HatchObject created!" );
135     	pHatchObject->SetModel(pSdrModel);
136         pHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
137         pHatchObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
138 
139         mpData = new impXHatchList(pVirDev, pSdrModel, pBackgroundObject, pHatchObject);
140 		OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
141     }
142 }
143 
144 void XHatchList::impDestroy()
145 {
146     if(mpData)
147     {
148         delete mpData;
149         mpData = 0;
150     }
151 }
152 
153 XHatchList::XHatchList(const String& rPath, XOutdevItemPool* pInPool)
154 :   XPropertyList(rPath, pInPool),
155     mpData(0)
156 {
157 }
158 
159 XHatchList::~XHatchList()
160 {
161     if(mpData)
162     {
163         delete mpData;
164         mpData = 0;
165     }
166 }
167 
168 XHatchEntry* XHatchList::Replace(XHatchEntry* pEntry, long nIndex )
169 {
170 	return (XHatchEntry*) XPropertyList::Replace(pEntry, nIndex);
171 }
172 
173 XHatchEntry* XHatchList::Remove(long nIndex)
174 {
175 	return (XHatchEntry*) XPropertyList::Remove(nIndex, 0);
176 }
177 
178 XHatchEntry* XHatchList::GetHatch(long nIndex) const
179 {
180 	return (XHatchEntry*) XPropertyList::Get(nIndex, 0);
181 }
182 
183 sal_Bool XHatchList::Load()
184 {
185 	if( mbListDirty )
186 	{
187 		mbListDirty = false;
188 
189 		INetURLObject aURL( maPath );
190 
191 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
192 		{
193 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
194 			return sal_False;
195 		}
196 
197 		aURL.Append( maName );
198 
199 		if( !aURL.getExtension().getLength() )
200 			aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
201 
202 		uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
203 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
204 	}
205 	return( sal_False );
206 }
207 
208 sal_Bool XHatchList::Save()
209 {
210 	INetURLObject aURL( maPath );
211 
212 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
213 	{
214 		DBG_ASSERT( !maPath.Len(), "invalid URL" );
215 		return sal_False;
216 	}
217 
218 	aURL.Append( maName );
219 
220 	if( !aURL.getExtension().getLength() )
221 		aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
222 
223 	uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
224 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
225 }
226 
227 sal_Bool XHatchList::Create()
228 {
229 	XubString aStr( SVX_RES( RID_SVXSTR_HATCH ) );
230 	xub_StrLen nLen;
231 
232 	aStr.AppendAscii(" 1");
233 	nLen = aStr.Len() - 1;
234 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100,  0),aStr));
235 	aStr.SetChar(nLen, sal_Unicode('2'));
236 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED  ),XHATCH_DOUBLE, 80,450),aStr));
237 	aStr.SetChar(nLen, sal_Unicode('3'));
238 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120,  0),aStr));
239 
240 	return( sal_True );
241 }
242 
243 Bitmap XHatchList::CreateBitmapForUI( long nIndex )
244 {
245     impCreate();
246     VirtualDevice* pVD = mpData->getVirtualDevice();
247     SdrObject* pHatchObject = mpData->getHatchObject();
248 
249     pHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
250     pHatchObject->SetMergedItem(XFillHatchItem(String(), GetHatch(nIndex)->GetHatch()));
251 
252     sdr::contact::SdrObjectVector aObjectVector;
253 	aObjectVector.push_back(mpData->getBackgroundObject());
254 	aObjectVector.push_back(pHatchObject);
255 	sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
256 	sdr::contact::DisplayInfo aDisplayInfo;
257 
258     pVD->Erase();
259 	aPainter.ProcessDisplay(aDisplayInfo);
260 
261     const Point aZero(0, 0);
262 	return pVD->GetBitmap(aZero, pVD->GetOutputSize());
263 }
264 
265 //////////////////////////////////////////////////////////////////////////////
266 // eof
267