xref: /AOO41X/main/svx/source/xoutdev/xtabgrdt.cxx (revision c7be74b172cff98608900673693e02cf2b814c3c)
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
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
35cdf0e10cSrcweir #include "xmlxtexp.hxx"
36cdf0e10cSrcweir #include "xmlxtimp.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <tools/urlobj.hxx>
41cdf0e10cSrcweir #include <vcl/virdev.hxx>
42cdf0e10cSrcweir #include <svl/itemset.hxx>
43cdf0e10cSrcweir #include <sfx2/docfile.hxx>
44cdf0e10cSrcweir #include <svx/dialogs.hrc>
45cdf0e10cSrcweir #include <svx/dialmgr.hxx>
46cdf0e10cSrcweir #include <svx/xtable.hxx>
47cdf0e10cSrcweir #include <svx/xpool.hxx>
48cdf0e10cSrcweir #include <svx/xfillit0.hxx>
49cdf0e10cSrcweir #include <svx/xflgrit.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <svx/svdorect.hxx>
52cdf0e10cSrcweir #include <svx/svdmodel.hxx>
53cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
54cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
55cdf0e10cSrcweir #include <vcl/svapp.hxx>
56cdf0e10cSrcweir #include <svx/xlnclit.hxx>
57cdf0e10cSrcweir #include <svx/xgrscit.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define GLOBALOVERFLOW
60cdf0e10cSrcweir 
61cdf0e10cSrcweir using namespace com::sun::star;
62cdf0e10cSrcweir using namespace rtl;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir sal_Unicode const pszExtGradient[]	= {'s','o','g'};
65*c7be74b1SArmin Le Grand //char const aChckGradient[]  = { 0x04, 0x00, 'S','O','G','L'};	// < 5.2
66*c7be74b1SArmin Le Grand //char const aChckGradient0[] = { 0x04, 0x00, 'S','O','G','0'};	// = 5.2
67*c7be74b1SArmin Le Grand //char const aChckXML[]       = { '<', '?', 'x', 'm', 'l' };		// = 6.0
68cdf0e10cSrcweir 
69cdf0e10cSrcweir // --------------------
70cdf0e10cSrcweir // class XGradientList
71cdf0e10cSrcweir // --------------------
72cdf0e10cSrcweir 
73*c7be74b1SArmin Le Grand XGradientList::XGradientList( const String& rPath )
74*c7be74b1SArmin Le Grand :   XPropertyList(rPath ),
75*c7be74b1SArmin Le Grand     mpBackgroundObject(0)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir XGradientList::~XGradientList()
80cdf0e10cSrcweir {
81*c7be74b1SArmin Le Grand     SdrObject::Free(mpBackgroundObject);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	return( (XGradientEntry*) XPropertyList::Replace( pEntry, nIndex ) );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir XGradientEntry* XGradientList::Remove(long nIndex)
90cdf0e10cSrcweir {
91*c7be74b1SArmin Le Grand 	return( (XGradientEntry*) XPropertyList::Remove( nIndex ) );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir XGradientEntry* XGradientList::GetGradient(long nIndex) const
95cdf0e10cSrcweir {
96*c7be74b1SArmin Le Grand 	return( (XGradientEntry*) XPropertyList::Get( nIndex ) );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir sal_Bool XGradientList::Load()
100cdf0e10cSrcweir {
10197e8a929SArmin Le Grand 	if( mbListDirty )
102cdf0e10cSrcweir 	{
10397e8a929SArmin Le Grand 		mbListDirty = false;
104cdf0e10cSrcweir 
10597e8a929SArmin Le Grand 		INetURLObject aURL( maPath );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
108cdf0e10cSrcweir 		{
10997e8a929SArmin Le Grand 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
110cdf0e10cSrcweir 			return sal_False;
111cdf0e10cSrcweir 		}
112cdf0e10cSrcweir 
11397e8a929SArmin Le Grand 		aURL.Append( maName );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		if( !aURL.getExtension().getLength() )
116cdf0e10cSrcweir 			aURL.setExtension( rtl::OUString( pszExtGradient, 3 ) );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
119cdf0e10cSrcweir 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 	return( sal_False );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir sal_Bool XGradientList::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( pszExtGradient, 3 ) );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xTable( SvxUnoXGradientTable_createInstance( this ), uno::UNO_QUERY );
141cdf0e10cSrcweir 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir sal_Bool XGradientList::Create()
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	XubString aStr( SVX_RES( RID_SVXSTR_GRADIENT ) );
147cdf0e10cSrcweir 	xub_StrLen nLen;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	aStr.AppendAscii(" 1");
150cdf0e10cSrcweir 	nLen = aStr.Len() - 1;
151cdf0e10cSrcweir 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLACK  ),RGB_Color(COL_WHITE	),XGRAD_LINEAR	  ,    0,10,10, 0,100,100),aStr));
152cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('2'));
153cdf0e10cSrcweir 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_BLUE	 ),RGB_Color(COL_RED	),XGRAD_AXIAL	  ,  300,20,20,10,100,100),aStr));
154cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('3'));
155cdf0e10cSrcweir 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_RED	 ),RGB_Color(COL_YELLOW ),XGRAD_RADIAL	  ,  600,30,30,20,100,100),aStr));
156cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('4'));
157cdf0e10cSrcweir 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_YELLOW ),RGB_Color(COL_GREEN	),XGRAD_ELLIPTICAL,  900,40,40,30,100,100),aStr));
158cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('5'));
159cdf0e10cSrcweir 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_GREEN  ),RGB_Color(COL_MAGENTA),XGRAD_SQUARE	  , 1200,50,50,40,100,100),aStr));
160cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('6'));
161cdf0e10cSrcweir 	Insert(new XGradientEntry(XGradient(RGB_Color(COL_MAGENTA),RGB_Color(COL_YELLOW ),XGRAD_RECT	  , 1900,60,60,50,100,100),aStr));
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	return( sal_True );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
16697e8a929SArmin Le Grand Bitmap XGradientList::CreateBitmapForUI( long nIndex )
167cdf0e10cSrcweir {
168*c7be74b1SArmin Le Grand     Bitmap aRetval;
169*c7be74b1SArmin Le Grand     OSL_ENSURE(pGlobalsharedModelAndVDev, "OOps, global values missing (!)");
170*c7be74b1SArmin Le Grand     OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)");
171cdf0e10cSrcweir 
172*c7be74b1SArmin Le Grand     if(pGlobalsharedModelAndVDev && nIndex < Count())
173*c7be74b1SArmin Le Grand     {
174*c7be74b1SArmin Le Grand         SdrModel& rModel = pGlobalsharedModelAndVDev->getSharedSdrModel();
175*c7be74b1SArmin Le Grand         VirtualDevice& rVirDev = pGlobalsharedModelAndVDev->getSharedVirtualDevice();
176*c7be74b1SArmin Le Grand         const Point aZero(0, 0);
177*c7be74b1SArmin Le Grand         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
178*c7be74b1SArmin Le Grand         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
179*c7be74b1SArmin Le Grand         const Size aSize(rVirDev.PixelToLogic(rSize));
180*c7be74b1SArmin Le Grand 
181*c7be74b1SArmin Le Grand         rVirDev.SetOutputSize(aSize);
182*c7be74b1SArmin Le Grand         rVirDev.SetDrawMode(rStyleSettings.GetHighContrastMode()
183*c7be74b1SArmin Le Grand             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
184*c7be74b1SArmin Le Grand             : DRAWMODE_DEFAULT);
185*c7be74b1SArmin Le Grand         rVirDev.SetBackground(rStyleSettings.GetFieldColor());
186*c7be74b1SArmin Le Grand 
187*c7be74b1SArmin Le Grand         if(!mpBackgroundObject)
188*c7be74b1SArmin Le Grand         {
189*c7be74b1SArmin Le Grand             const Size aSinglePixel(rVirDev.PixelToLogic(Size(1, 1)));
190*c7be74b1SArmin Le Grand             const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight()));
191*c7be74b1SArmin Le Grand             mpBackgroundObject = new SdrRectObj(aBackgroundSize);
192*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpBackgroundObject, "XGradientList: no BackgroundObject created!" );
193*c7be74b1SArmin Le Grand             mpBackgroundObject->SetModel(&rModel);
194*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
195*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
196*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK)));
197*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((rSize.Width() + rSize.Height()) / 3)));
198*c7be74b1SArmin Le Grand         }
199*c7be74b1SArmin Le Grand 
200*c7be74b1SArmin Le Grand         const SfxItemSet& rItemSet = mpBackgroundObject->GetMergedItemSet();
201*c7be74b1SArmin Le Grand 
202*c7be74b1SArmin Le Grand         mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT));
203*c7be74b1SArmin Le Grand         mpBackgroundObject->SetMergedItem(XFillGradientItem(rItemSet.GetPool(), GetGradient(nIndex)->GetGradient()));
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         sdr::contact::SdrObjectVector aObjectVector;
206*c7be74b1SArmin Le Grand 
207*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpBackgroundObject);
208*c7be74b1SArmin Le Grand 
209*c7be74b1SArmin Le Grand         sdr::contact::ObjectContactOfObjListPainter aPainter(rVirDev, aObjectVector, 0);
210cdf0e10cSrcweir         sdr::contact::DisplayInfo aDisplayInfo;
211cdf0e10cSrcweir 
212*c7be74b1SArmin Le Grand         rVirDev.Erase();
213cdf0e10cSrcweir         aPainter.ProcessDisplay(aDisplayInfo);
214cdf0e10cSrcweir 
215*c7be74b1SArmin Le Grand         return rVirDev.GetBitmap(aZero, rVirDev.GetOutputSize());
216*c7be74b1SArmin Le Grand 
217*c7be74b1SArmin Le Grand     }
218*c7be74b1SArmin Le Grand 
219*c7be74b1SArmin Le Grand     return aRetval;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
223cdf0e10cSrcweir // eof
224