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