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