xref: /aoo42x/main/svx/source/xoutdev/xtabgrdt.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 
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 //char const aChckGradient[]  = { 0x04, 0x00, 'S','O','G','L'};	// < 5.2
66 //char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'};	// = 5.2
67 //char const aChckXML[]       = { '<', '?', 'x', 'm', 'l' };		// = 6.0
68 
69 // --------------------
70 // class XGradientList
71 // --------------------
72 
73 XGradientList::XGradientList( const String& rPath )
74 :   XPropertyList(rPath ),
75     mpBackgroundObject(0)
76 {
77 }
78 
79 XGradientList::~XGradientList()
80 {
81     SdrObject::Free(mpBackgroundObject);
82 }
83 
84 XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
85 {
86 	return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) );
87 }
88 
89 XGradientEntry* XGradientList::Remove(long nIndex)
90 {
91 	return( (XGradientEntry*) XPropertyList::Remove( nIndex ) );
92 }
93 
94 XGradientEntry* XGradientList::GetGradient(long nIndex) const
95 {
96 	return( (XGradientEntry*) XPropertyList::Get( nIndex ) );
97 }
98 
99 sal_Bool XGradientList::Load()
100 {
101 	if( mbListDirty )
102 	{
103 		mbListDirty = false;
104 
105 		INetURLObject aURL( maPath );
106 
107 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
108 		{
109 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
110 			return sal_False;
111 		}
112 
113 		aURL.Append( maName );
114 
115 		if( !aURL.getExtension().getLength() )
116 			aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) );
117 
118 		uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
119 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
120 
121 	}
122 	return( sal_False );
123 }
124 
125 sal_Bool XGradientList::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( pszExtGradient, 3 ) );
139 
140 	uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
141 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
142 }
143 
144 sal_Bool XGradientList::Create()
145 {
146 	XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) );
147 	xub_StrLen nLen;
148 
149 	aStr.AppendAscii(" 1");
150 	nLen = aStr.Len() - 1;
151 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK  ),RGB_Color(COL_WHITE	),XGRAD_LINEAR	  ,    0,10,10, 0,100,100),aStr));
152 	aStr.SetChar(nLen, sal_Unicode('2'));
153 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE	 ),RGB_Color(COL_RED	),XGRAD_AXIAL	  ,  300,20,20,10,100,100),aStr));
154 	aStr.SetChar(nLen, sal_Unicode('3'));
155 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED	 ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL	  ,  600,30,30,20,100,100),aStr));
156 	aStr.SetChar(nLen, sal_Unicode('4'));
157 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN	),XGRAD_ELLIPTICAL,  900,40,40,30,100,100),aStr));
158 	aStr.SetChar(nLen, sal_Unicode('5'));
159 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN  ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE	  , 1200,50,50,40,100,100),aStr));
160 	aStr.SetChar(nLen, sal_Unicode('6'));
161 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT	  , 1900,60,60,50,100,100),aStr));
162 
163 	return( sal_True );
164 }
165 
166 Bitmap XGradientList::CreateBitmapForUI( long nIndex )
167 {
168     Bitmap aRetval;
169     OSL_ENSURE(pGlobalsharedModelAndVDev, "OOps, global values missing (!)");
170     OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)");
171 
172     if(pGlobalsharedModelAndVDev && nIndex < Count())
173     {
174         SdrModel& rModel = pGlobalsharedModelAndVDev->getSharedSdrModel();
175         VirtualDevice& rVirDev = pGlobalsharedModelAndVDev->getSharedVirtualDevice();
176         const Point aZero(0, 0);
177         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
178         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
179         const Size aSize(rVirDev.PixelToLogic(rSize));
180 
181         rVirDev.SetOutputSize(aSize);
182         rVirDev.SetDrawMode(rStyleSettings.GetHighContrastMode()
183             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
184             : DRAWMODE_DEFAULT);
185         rVirDev.SetBackground(rStyleSettings.GetFieldColor());
186 
187         if(!mpBackgroundObject)
188         {
189             const Size aSinglePixel(rVirDev.PixelToLogic(Size(1, 1)));
190             const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
191             mpBackgroundObject = new SdrRectObj(aBackgroundSize);
192             OSL_ENSURE(0 != mpBackgroundObject, "XGradientList: no BackgroundObject created!" );
193             mpBackgroundObject->SetModel(&rModel);
194             mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
195             mpBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
196             mpBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
197             mpBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((rSize.Width() + rSize.Height()) / 3)));
198         }
199 
200         const SfxItemSet& rItemSet = mpBackgroundObject->GetMergedItemSet();
201 
202         mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
203         mpBackgroundObject->SetMergedItem(XFillGradientItem(rItemSet.GetPool(), GetGradient(nIndex)->GetGradient()));
204 
205         sdr::contact::SdrObjectVector aObjectVector;
206 
207         aObjectVector.push_back(mpBackgroundObject);
208 
209         sdr::contact::ObjectContactOfObjListPainter aPainter(rVirDev, aObjectVector, 0);
210         sdr::contact::DisplayInfo aDisplayInfo;
211 
212         rVirDev.Erase();
213         aPainter.ProcessDisplay(aDisplayInfo);
214 
215         return rVirDev.GetBitmap(aZero, rVirDev.GetOutputSize());
216 
217     }
218 
219     return aRetval;
220 }
221 
222 //////////////////////////////////////////////////////////////////////////////
223 // eof
224