xref: /aoo41x/main/svx/source/xoutdev/xtabhtch.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 #include <vcl/svapp.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "xmlxtexp.hxx"
37cdf0e10cSrcweir #include "xmlxtimp.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <tools/urlobj.hxx>
42cdf0e10cSrcweir #include <vcl/virdev.hxx>
43cdf0e10cSrcweir #include <svl/itemset.hxx>
44cdf0e10cSrcweir #include <sfx2/docfile.hxx>
45cdf0e10cSrcweir #include <svx/dialogs.hrc>
46cdf0e10cSrcweir #include <svx/dialmgr.hxx>
47cdf0e10cSrcweir #include <svx/xtable.hxx>
48cdf0e10cSrcweir #include <svx/xpool.hxx>
49cdf0e10cSrcweir #include "svx/dlgutil.hxx"
50cdf0e10cSrcweir #include <svx/xflhtit.hxx>
51cdf0e10cSrcweir #include <svx/xflclit.hxx>
52cdf0e10cSrcweir #include <svx/xfillit0.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <svx/svdorect.hxx>
55cdf0e10cSrcweir #include <svx/svdmodel.hxx>
56cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
57cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
58cdf0e10cSrcweir #include <svx/xlnclit.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir using namespace ::com::sun::star;
61cdf0e10cSrcweir using namespace ::rtl;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir sal_Unicode const pszExtHatch[]	 = {'s','o','h'};
64*c7be74b1SArmin Le Grand //char const aChckHatch[]  = { 0x04, 0x00, 'S','O','H','L'};	// < 5.2
65*c7be74b1SArmin Le Grand //char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'};	// = 5.2
66*c7be74b1SArmin Le Grand //char const aChckXML[]    = { '<', '?', 'x', 'm', 'l' };		// = 6.0
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // -----------------
69cdf0e10cSrcweir // class XHatchList
70cdf0e10cSrcweir // -----------------
71cdf0e10cSrcweir 
72*c7be74b1SArmin Le Grand XHatchList::XHatchList(const String& rPath )
73*c7be74b1SArmin Le Grand :   XPropertyList(rPath),
74*c7be74b1SArmin Le Grand     mpBackgroundObject(0),
75*c7be74b1SArmin Le Grand     mpHatchObject(0)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir XHatchList::~XHatchList()
80cdf0e10cSrcweir {
81*c7be74b1SArmin Le Grand     SdrObject::Free(mpBackgroundObject);
82*c7be74b1SArmin Le Grand     SdrObject::Free(mpHatchObject);
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir XHatchEntry* XHatchList::Replace(XHatchEntry* pEntry, long nIndex )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	return (XHatchEntry*) XPropertyList::Replace(pEntry, nIndex);
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir XHatchEntry* XHatchList::Remove(long nIndex)
91cdf0e10cSrcweir {
92*c7be74b1SArmin Le Grand 	return (XHatchEntry*) XPropertyList::Remove(nIndex);
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir XHatchEntry* XHatchList::GetHatch(long nIndex) const
96cdf0e10cSrcweir {
97*c7be74b1SArmin Le Grand 	return (XHatchEntry*) XPropertyList::Get(nIndex);
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir sal_Bool XHatchList::Load()
101cdf0e10cSrcweir {
10297e8a929SArmin Le Grand 	if( mbListDirty )
103cdf0e10cSrcweir 	{
10497e8a929SArmin Le Grand 		mbListDirty = false;
105cdf0e10cSrcweir 
10697e8a929SArmin Le Grand 		INetURLObject aURL( maPath );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
109cdf0e10cSrcweir 		{
11097e8a929SArmin Le Grand 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
111cdf0e10cSrcweir 			return sal_False;
112cdf0e10cSrcweir 		}
113cdf0e10cSrcweir 
11497e8a929SArmin Le Grand 		aURL.Append( maName );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		if( !aURL.getExtension().getLength() )
117cdf0e10cSrcweir 			aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
120cdf0e10cSrcweir 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 	return( sal_False );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir sal_Bool XHatchList::Save()
126cdf0e10cSrcweir {
12797e8a929SArmin Le Grand 	INetURLObject aURL( maPath );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
130cdf0e10cSrcweir 	{
13197e8a929SArmin Le Grand 		DBG_ASSERT( !maPath.Len(), "invalid URL" );
132cdf0e10cSrcweir 		return sal_False;
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 
13597e8a929SArmin Le Grand 	aURL.Append( maName );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if( !aURL.getExtension().getLength() )
138cdf0e10cSrcweir 		aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
141cdf0e10cSrcweir 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir sal_Bool XHatchList::Create()
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	XubString aStr( SVX_RES( RID_SVXSTR_HATCH ) );
147cdf0e10cSrcweir 	xub_StrLen nLen;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	aStr.AppendAscii(" 1");
150cdf0e10cSrcweir 	nLen = aStr.Len() - 1;
151cdf0e10cSrcweir 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100,  0),aStr));
152cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('2'));
153cdf0e10cSrcweir 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED  ),XHATCH_DOUBLE, 80,450),aStr));
154cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('3'));
155cdf0e10cSrcweir 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120,  0),aStr));
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	return( sal_True );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
16097e8a929SArmin Le Grand Bitmap XHatchList::CreateBitmapForUI( long nIndex )
161cdf0e10cSrcweir {
162*c7be74b1SArmin Le Grand     Bitmap aRetval;
163*c7be74b1SArmin Le Grand     OSL_ENSURE(pGlobalsharedModelAndVDev, "OOps, global values missing (!)");
164*c7be74b1SArmin Le Grand     OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)");
165cdf0e10cSrcweir 
166*c7be74b1SArmin Le Grand     if(pGlobalsharedModelAndVDev && nIndex < Count())
167*c7be74b1SArmin Le Grand     {
168*c7be74b1SArmin Le Grand         SdrModel& rModel = pGlobalsharedModelAndVDev->getSharedSdrModel();
169*c7be74b1SArmin Le Grand         VirtualDevice& rVirDev = pGlobalsharedModelAndVDev->getSharedVirtualDevice();
170*c7be74b1SArmin Le Grand         const Point aZero(0, 0);
171*c7be74b1SArmin Le Grand         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
172*c7be74b1SArmin Le Grand         const Size aSize(rVirDev.PixelToLogic(rStyleSettings.GetListBoxPreviewDefaultPixelSize()));
173*c7be74b1SArmin Le Grand 
174*c7be74b1SArmin Le Grand         rVirDev.SetOutputSize(aSize);
175*c7be74b1SArmin Le Grand         rVirDev.SetDrawMode(rStyleSettings.GetHighContrastMode()
176*c7be74b1SArmin Le Grand             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
177*c7be74b1SArmin Le Grand             : DRAWMODE_DEFAULT);
178*c7be74b1SArmin Le Grand         rVirDev.SetBackground(rStyleSettings.GetFieldColor());
179cdf0e10cSrcweir 
180*c7be74b1SArmin Le Grand         const Size aSinglePixel(rVirDev.PixelToLogic(Size(1, 1)));
181*c7be74b1SArmin Le Grand         const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
182cdf0e10cSrcweir 
183*c7be74b1SArmin Le Grand         if(!mpBackgroundObject)
184*c7be74b1SArmin Le Grand         {
185*c7be74b1SArmin Le Grand             mpBackgroundObject = new SdrRectObj(aBackgroundSize);
186*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpBackgroundObject, "XDashList: no BackgroundObject created!" );
187*c7be74b1SArmin Le Grand             mpBackgroundObject->SetModel(&rModel);
188*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
189*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
190*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
191*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
192*c7be74b1SArmin Le Grand         }
193*c7be74b1SArmin Le Grand 
194*c7be74b1SArmin Le Grand         if(!mpHatchObject)
195*c7be74b1SArmin Le Grand         {
196*c7be74b1SArmin Le Grand             mpHatchObject = new SdrRectObj(aBackgroundSize);
197*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpHatchObject, "XDashList: no HatchObject created!" );
198*c7be74b1SArmin Le Grand             mpHatchObject->SetModel(&rModel);
199*c7be74b1SArmin Le Grand             mpHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
200*c7be74b1SArmin Le Grand             mpHatchObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
201*c7be74b1SArmin Le Grand         }
202*c7be74b1SArmin Le Grand 
203*c7be74b1SArmin Le Grand         mpHatchObject->SetMergedItem(XFillStyleItem(XFILL_HATCH));
204*c7be74b1SArmin Le Grand         mpHatchObject->SetMergedItem(XFillHatchItem(String(), GetHatch(nIndex)->GetHatch()));
205*c7be74b1SArmin Le Grand 
206*c7be74b1SArmin Le Grand         sdr::contact::SdrObjectVector aObjectVector;
207*c7be74b1SArmin Le Grand 
208*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpBackgroundObject);
209*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpHatchObject);
210*c7be74b1SArmin Le Grand 
211*c7be74b1SArmin Le Grand         sdr::contact::ObjectContactOfObjListPainter aPainter(rVirDev, aObjectVector, 0);
212*c7be74b1SArmin Le Grand         sdr::contact::DisplayInfo aDisplayInfo;
213*c7be74b1SArmin Le Grand 
214*c7be74b1SArmin Le Grand         rVirDev.Erase();
215*c7be74b1SArmin Le Grand         aPainter.ProcessDisplay(aDisplayInfo);
216*c7be74b1SArmin Le Grand 
217*c7be74b1SArmin Le Grand         aRetval = rVirDev.GetBitmap(aZero, rVirDev.GetOutputSize());
218*c7be74b1SArmin Le Grand     }
219cdf0e10cSrcweir 
220*c7be74b1SArmin Le Grand     return aRetval;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
224cdf0e10cSrcweir // eof
225