xref: /AOO41X/main/sc/source/ui/vba/vbainterior.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
28*cdf0e10cSrcweir #include <com/sun/star/table/XCell.hpp>
29*cdf0e10cSrcweir #include <com/sun/star/table/XColumnRowRange.hpp>
30*cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospectionAccess.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlMethod.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/beans/MethodConcept.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/xml/AttributeData.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <ooo/vba/excel/XlColorIndex.hpp>
38*cdf0e10cSrcweir #include <ooo/vba/excel/XlPattern.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <map>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <svx/xtable.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include "vbainterior.hxx"
48*cdf0e10cSrcweir #include "vbapalette.hxx"
49*cdf0e10cSrcweir #include "document.hxx"
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #define STATIC_TABLE_SIZE( array )  (sizeof(array)/sizeof(*(array)))
52*cdf0e10cSrcweir #define COLORMAST 0xFFFFFF
53*cdf0e10cSrcweir const sal_uInt16 EXC_COLOR_WINDOWBACK = 65;
54*cdf0e10cSrcweir typedef std::map< sal_Int32, sal_Int32 >  PatternMap;
55*cdf0e10cSrcweir typedef std::pair< sal_Int32, sal_Int32 > PatternPair;
56*cdf0e10cSrcweir using namespace ::com::sun::star;
57*cdf0e10cSrcweir using namespace ::ooo::vba;
58*cdf0e10cSrcweir using namespace ::ooo::vba::excel::XlPattern;
59*cdf0e10cSrcweir static const rtl::OUString BACKCOLOR( RTL_CONSTASCII_USTRINGPARAM( "CellBackColor" ) );
60*cdf0e10cSrcweir static const rtl::OUString PATTERN( RTL_CONSTASCII_USTRINGPARAM( "Pattern" ) );
61*cdf0e10cSrcweir static const rtl::OUString PATTERNCOLOR( RTL_CONSTASCII_USTRINGPARAM( "PatternColor" ) );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir PatternMap lcl_getPatternMap()
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     PatternMap aPatternMap;
66*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternAutomatic, 0 ) );
67*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternChecker, 9 ) );
68*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternCrissCross, 16 ) );
69*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternDown, 7 ) );
70*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternGray16, 17 ) );
71*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternGray25, 4 ) );
72*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternGray50, 2 ) );
73*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternGray75, 3 ) );
74*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternGray8, 18 ) );
75*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternGrid, 15 ) );
76*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternHorizontal, 5 ) );
77*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternLightDown, 13 ) );
78*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternLightHorizontal, 11 ) );
79*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternLightUp, 14 ) );
80*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternLightVertical, 12 ) );
81*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternNone, 0 ) );
82*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternSemiGray75, 10 ) );
83*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternSolid, 0 ) );
84*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternUp, 8 ) );
85*cdf0e10cSrcweir     aPatternMap.insert( PatternPair( xlPatternVertical, 6 ) );
86*cdf0e10cSrcweir     return aPatternMap;
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir static PatternMap aPatternMap( lcl_getPatternMap() );
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir ScVbaInterior::ScVbaInterior( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< beans::XPropertySet >&  xProps, ScDocument* pScDoc ) throw ( lang::IllegalArgumentException) : ScVbaInterior_BASE( xParent, xContext ), m_xProps(xProps), m_pScDoc( pScDoc )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     // auto color
94*cdf0e10cSrcweir     //m_aPattColor.SetColor( (sal_uInt32)0xFFFFFFFF );
95*cdf0e10cSrcweir     m_aPattColor.SetColor( (sal_uInt32)0x0 );
96*cdf0e10cSrcweir     m_nPattern = 0L;
97*cdf0e10cSrcweir 	if ( !m_xProps.is() )
98*cdf0e10cSrcweir 		throw lang::IllegalArgumentException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "properties") ), uno::Reference< uno::XInterface >(), 2 );
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir uno::Any
102*cdf0e10cSrcweir ScVbaInterior::getColor() throw (uno::RuntimeException)
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     Color aBackColor( GetBackColor() );
105*cdf0e10cSrcweir 	return uno::makeAny( OORGBToXLRGB( aBackColor.GetColor() ) );
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void
109*cdf0e10cSrcweir ScVbaInterior::setColor( const uno::Any& _color  ) throw (uno::RuntimeException)
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     sal_Int32 nColor = 0;
112*cdf0e10cSrcweir     if( _color >>= nColor )
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir         SetUserDefinedAttributes( BACKCOLOR, SetAttributeData( XLRGBToOORGB( nColor ) ) );
115*cdf0e10cSrcweir 	    //m_xProps->setPropertyValue( BACKCOLOR , XLRGBToOORGB(_color));
116*cdf0e10cSrcweir         SetMixedColor();
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir void
121*cdf0e10cSrcweir ScVbaInterior::SetMixedColor()
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     // pattern
124*cdf0e10cSrcweir     uno::Any aPattern = GetUserDefinedAttributes( PATTERN );
125*cdf0e10cSrcweir     if( aPattern.hasValue() )
126*cdf0e10cSrcweir     {
127*cdf0e10cSrcweir         m_nPattern = GetAttributeData( aPattern );
128*cdf0e10cSrcweir     }
129*cdf0e10cSrcweir     sal_Int32 nPattern = aPatternMap[ m_nPattern ];
130*cdf0e10cSrcweir     // pattern color
131*cdf0e10cSrcweir     uno::Any aPatternColor = GetUserDefinedAttributes( PATTERNCOLOR );
132*cdf0e10cSrcweir     if( aPatternColor.hasValue() )
133*cdf0e10cSrcweir     {
134*cdf0e10cSrcweir         sal_uInt32 nPatternColor = GetAttributeData( aPatternColor );
135*cdf0e10cSrcweir         m_aPattColor.SetColor( nPatternColor );
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir     sal_Int32 nPatternColor = m_aPattColor.GetColor();
138*cdf0e10cSrcweir     // back color
139*cdf0e10cSrcweir     Color aBackColor( GetBackColor() );
140*cdf0e10cSrcweir     // set mixed color
141*cdf0e10cSrcweir     Color aMixedColor;
142*cdf0e10cSrcweir     if( nPattern > 0 )
143*cdf0e10cSrcweir         aMixedColor = GetPatternColor( Color(nPatternColor), aBackColor, (sal_uInt32)nPattern );
144*cdf0e10cSrcweir     else
145*cdf0e10cSrcweir         aMixedColor = GetPatternColor( aBackColor, aBackColor, (sal_uInt32)nPattern );
146*cdf0e10cSrcweir     sal_Int32 nMixedColor = aMixedColor.GetColor() & COLORMAST;
147*cdf0e10cSrcweir 	m_xProps->setPropertyValue( BACKCOLOR , uno::makeAny( nMixedColor ) );
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir uno::Reference< container::XIndexAccess >
151*cdf0e10cSrcweir ScVbaInterior::getPalette()
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir 	if ( !m_pScDoc )
154*cdf0e10cSrcweir 		throw uno::RuntimeException();
155*cdf0e10cSrcweir 	SfxObjectShell* pShell = m_pScDoc->GetDocumentShell();
156*cdf0e10cSrcweir 	ScVbaPalette aPalette( pShell );
157*cdf0e10cSrcweir 	return aPalette.getPalette();
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir void SAL_CALL
161*cdf0e10cSrcweir ScVbaInterior::setColorIndex( const css::uno::Any& _colorindex ) throw (css::uno::RuntimeException)
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
164*cdf0e10cSrcweir 	_colorindex >>= nIndex;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     // hackly for excel::XlColorIndex::xlColorIndexNone
167*cdf0e10cSrcweir     if( nIndex == excel::XlColorIndex::xlColorIndexNone )
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         m_xProps->setPropertyValue( BACKCOLOR, uno::makeAny( sal_Int32( -1 ) ) );
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir     else
172*cdf0e10cSrcweir     {
173*cdf0e10cSrcweir 	    // setColor expects colors in XL RGB values
174*cdf0e10cSrcweir     	// #FIXME this is daft we convert OO RGB val to XL RGB val and
175*cdf0e10cSrcweir 	    // then back again to OO RGB value
176*cdf0e10cSrcweir     	setColor( OORGBToXLRGB( GetIndexColor( nIndex ) ) );
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir uno::Any
180*cdf0e10cSrcweir ScVbaInterior::GetIndexColor( const sal_Int32& nColorIndex )
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 	sal_Int32 nIndex = nColorIndex;
183*cdf0e10cSrcweir 	// #FIXME  xlColorIndexAutomatic & xlColorIndexNone are not really
184*cdf0e10cSrcweir 	// handled properly here
185*cdf0e10cSrcweir 	if ( !nIndex || ( nIndex == excel::XlColorIndex::xlColorIndexAutomatic ) || ( nIndex == excel::XlColorIndex::xlColorIndexNone )  )
186*cdf0e10cSrcweir 		nIndex = 2; // default is white ( this maybe will probably break, e.g. we may at some stage need to know what this interior is,  a cell or something else and then pick a default colour based on that )
187*cdf0e10cSrcweir 	--nIndex; // OOo indices are zero bases
188*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess > xIndex = getPalette();
189*cdf0e10cSrcweir     return xIndex->getByIndex( nIndex );
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir sal_Int32
193*cdf0e10cSrcweir ScVbaInterior::GetColorIndex( const sal_Int32 nColor )
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	uno::Reference< container::XIndexAccess > xIndex = getPalette();
196*cdf0e10cSrcweir 	sal_Int32 nElems = xIndex->getCount();
197*cdf0e10cSrcweir 	sal_Int32 nIndex = -1;
198*cdf0e10cSrcweir 	for ( sal_Int32 count=0; count<nElems; ++count )
199*cdf0e10cSrcweir        	{
200*cdf0e10cSrcweir 		sal_Int32 nPaletteColor = 0;
201*cdf0e10cSrcweir 		xIndex->getByIndex( count ) >>= nPaletteColor;
202*cdf0e10cSrcweir 		if ( nPaletteColor == nColor )
203*cdf0e10cSrcweir 		{
204*cdf0e10cSrcweir 			nIndex = count + 1; // 1 based
205*cdf0e10cSrcweir 			break;
206*cdf0e10cSrcweir 		}
207*cdf0e10cSrcweir 	}
208*cdf0e10cSrcweir     return nIndex;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir uno::Any SAL_CALL
212*cdf0e10cSrcweir ScVbaInterior::getColorIndex() throw ( css::uno::RuntimeException )
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	sal_Int32 nColor = 0;
215*cdf0e10cSrcweir     // hackly for excel::XlColorIndex::xlColorIndexNone
216*cdf0e10cSrcweir     uno::Any aColor = m_xProps->getPropertyValue( BACKCOLOR );
217*cdf0e10cSrcweir     if( ( aColor >>= nColor ) && ( nColor == -1 ) )
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         nColor = excel::XlColorIndex::xlColorIndexNone;
220*cdf0e10cSrcweir         return uno::makeAny( nColor );
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	// getColor returns Xl ColorValue, need to convert it to OO val
224*cdf0e10cSrcweir 	// as the palette deals with OO RGB values
225*cdf0e10cSrcweir 	// #FIXME this is daft in getColor we convert OO RGB val to XL RGB val
226*cdf0e10cSrcweir 	// and then back again to OO RGB value
227*cdf0e10cSrcweir 	XLRGBToOORGB( getColor() ) >>= nColor;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	return uno::makeAny( GetColorIndex( nColor ) );
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir Color
232*cdf0e10cSrcweir ScVbaInterior::GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt32 nXclPattern )
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     // 0x00 == 0% transparence (full rPattColor)
235*cdf0e10cSrcweir     // 0x80 == 100% transparence (full rBackColor)
236*cdf0e10cSrcweir     static const sal_uInt8 pnRatioTable[] =
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir         0x80, 0x00, 0x40, 0x20, 0x60, 0x40, 0x40, 0x40,     // 00 - 07
239*cdf0e10cSrcweir         0x40, 0x40, 0x20, 0x60, 0x60, 0x60, 0x60, 0x48,     // 08 - 15
240*cdf0e10cSrcweir         0x50, 0x70, 0x78                                    // 16 - 18
241*cdf0e10cSrcweir     };
242*cdf0e10cSrcweir     return ( nXclPattern < STATIC_TABLE_SIZE( pnRatioTable ) ) ?
243*cdf0e10cSrcweir         GetMixedColor( rPattColor, rBackColor, pnRatioTable[ nXclPattern ] ) : rPattColor;
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir Color
246*cdf0e10cSrcweir ScVbaInterior::GetMixedColor( const Color& rFore, const Color& rBack, sal_uInt8 nTrans )
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     return Color(
249*cdf0e10cSrcweir         nTrans,
250*cdf0e10cSrcweir         GetMixedColorComp( rFore.GetRed(), rBack.GetRed(), nTrans ),
251*cdf0e10cSrcweir         GetMixedColorComp( rFore.GetGreen(), rBack.GetGreen(), nTrans ),
252*cdf0e10cSrcweir         GetMixedColorComp( rFore.GetBlue(), rBack.GetBlue(), nTrans ));
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir sal_uInt8
255*cdf0e10cSrcweir ScVbaInterior::GetMixedColorComp(  sal_uInt8 nFore, sal_uInt8 nBack, sal_uInt8 nTrans )
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     sal_uInt32 nTemp = ((static_cast< sal_Int32 >( nBack ) - nFore) * nTrans) / 0x80 + nFore;
258*cdf0e10cSrcweir     return static_cast< sal_uInt8 >( nTemp );
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir uno::Reference< container::XNameContainer >
261*cdf0e10cSrcweir ScVbaInterior::GetAttributeContainer()
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir     return uno::Reference < container::XNameContainer > ( m_xProps->getPropertyValue( rtl::OUString::createFromAscii( "UserDefinedAttributes" ) ), uno::UNO_QUERY_THROW );
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir sal_Int32
266*cdf0e10cSrcweir ScVbaInterior::GetAttributeData( uno::Any aValue )
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir     xml::AttributeData aDataValue;
269*cdf0e10cSrcweir     if( aValue >>= aDataValue )
270*cdf0e10cSrcweir     {
271*cdf0e10cSrcweir         return aDataValue.Value.toInt32();
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir     return sal_Int32( 0 );
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir uno::Any
276*cdf0e10cSrcweir ScVbaInterior::SetAttributeData( sal_Int32 nValue )
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     xml::AttributeData aAttributeData;
279*cdf0e10cSrcweir     //aAttributeData.Namespace = rtl::OUString::createFromAscii( "ooo.vba.excel.CellPatten");
280*cdf0e10cSrcweir     aAttributeData.Type = rtl::OUString::createFromAscii( "sal_Int32" );
281*cdf0e10cSrcweir     aAttributeData.Value = rtl::OUString::valueOf( nValue );
282*cdf0e10cSrcweir     return uno::makeAny( aAttributeData );
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir uno::Any
285*cdf0e10cSrcweir ScVbaInterior::GetUserDefinedAttributes( const rtl::OUString& sName )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xNameContainer( GetAttributeContainer(), uno::UNO_QUERY_THROW );
288*cdf0e10cSrcweir     if( xNameContainer->hasByName( sName ) )
289*cdf0e10cSrcweir     {
290*cdf0e10cSrcweir         return xNameContainer->getByName( sName );
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir     return uno::Any();
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir void
295*cdf0e10cSrcweir ScVbaInterior::SetUserDefinedAttributes( const rtl::OUString& sName, const uno::Any& aValue )
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     if( aValue.hasValue() )
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xNameContainer( GetAttributeContainer(), uno::UNO_QUERY_THROW );
300*cdf0e10cSrcweir         if( xNameContainer->hasByName( sName ) )
301*cdf0e10cSrcweir             xNameContainer->removeByName( sName );
302*cdf0e10cSrcweir         xNameContainer->insertByName( sName, aValue );
303*cdf0e10cSrcweir         m_xProps->setPropertyValue( rtl::OUString::createFromAscii( "UserDefinedAttributes" ), uno::makeAny( xNameContainer ) );
304*cdf0e10cSrcweir     }
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir // OOo do not support below API
307*cdf0e10cSrcweir uno::Any SAL_CALL
308*cdf0e10cSrcweir ScVbaInterior::getPattern() throw (uno::RuntimeException)
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     // XlPattern
311*cdf0e10cSrcweir     uno::Any aPattern = GetUserDefinedAttributes( PATTERN );
312*cdf0e10cSrcweir     if( aPattern.hasValue() )
313*cdf0e10cSrcweir         return uno::makeAny( GetAttributeData( aPattern ) );
314*cdf0e10cSrcweir     return uno::makeAny( excel::XlPattern::xlPatternNone );
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir void SAL_CALL
317*cdf0e10cSrcweir ScVbaInterior::setPattern( const uno::Any& _pattern ) throw (uno::RuntimeException)
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir     if( _pattern >>= m_nPattern )
320*cdf0e10cSrcweir     {
321*cdf0e10cSrcweir         SetUserDefinedAttributes( PATTERN, SetAttributeData( m_nPattern ) );
322*cdf0e10cSrcweir         SetMixedColor();
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir     else
325*cdf0e10cSrcweir         throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Pattern index" ), uno::Reference< uno::XInterface >() );
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir Color
328*cdf0e10cSrcweir ScVbaInterior::GetBackColor()
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir     sal_Int32 nColor = 0;
331*cdf0e10cSrcweir     Color aBackColor;
332*cdf0e10cSrcweir     uno::Any aColor = GetUserDefinedAttributes( BACKCOLOR );
333*cdf0e10cSrcweir     if( aColor.hasValue() )
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         nColor = GetAttributeData( aColor );
336*cdf0e10cSrcweir         aBackColor.SetColor( nColor );
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir     else
339*cdf0e10cSrcweir     {
340*cdf0e10cSrcweir 	    uno::Any aAny;
341*cdf0e10cSrcweir 	    aAny = OORGBToXLRGB( m_xProps->getPropertyValue( BACKCOLOR ) );
342*cdf0e10cSrcweir         if( aAny >>= nColor )
343*cdf0e10cSrcweir         {
344*cdf0e10cSrcweir             nColor = XLRGBToOORGB( nColor );
345*cdf0e10cSrcweir             aBackColor.SetColor( nColor );
346*cdf0e10cSrcweir             SetUserDefinedAttributes( BACKCOLOR, SetAttributeData( nColor ) );
347*cdf0e10cSrcweir         }
348*cdf0e10cSrcweir     }
349*cdf0e10cSrcweir     return aBackColor;
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir uno::Any SAL_CALL
352*cdf0e10cSrcweir ScVbaInterior::getPatternColor() throw (uno::RuntimeException)
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir     // 0 is the default color. no filled.
355*cdf0e10cSrcweir     uno::Any aPatternColor = GetUserDefinedAttributes( PATTERNCOLOR );
356*cdf0e10cSrcweir     if( aPatternColor.hasValue() )
357*cdf0e10cSrcweir     {
358*cdf0e10cSrcweir         sal_uInt32 nPatternColor = GetAttributeData( aPatternColor );
359*cdf0e10cSrcweir         return uno::makeAny( OORGBToXLRGB( nPatternColor ) );
360*cdf0e10cSrcweir     }
361*cdf0e10cSrcweir     return uno::makeAny( sal_Int32( 0 ) );
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir void SAL_CALL
364*cdf0e10cSrcweir ScVbaInterior::setPatternColor( const uno::Any& _patterncolor ) throw (uno::RuntimeException)
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     sal_Int32 nPattColor = 0;
367*cdf0e10cSrcweir     if( _patterncolor >>= nPattColor )
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         SetUserDefinedAttributes( PATTERNCOLOR, SetAttributeData( XLRGBToOORGB( nPattColor ) ) );
370*cdf0e10cSrcweir         SetMixedColor();
371*cdf0e10cSrcweir     }
372*cdf0e10cSrcweir     else
373*cdf0e10cSrcweir         throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Pattern Color" ), uno::Reference< uno::XInterface >() );
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir uno::Any SAL_CALL
376*cdf0e10cSrcweir ScVbaInterior::getPatternColorIndex() throw (uno::RuntimeException)
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir 	sal_Int32 nColor = 0;
379*cdf0e10cSrcweir 	XLRGBToOORGB( getPatternColor() ) >>= nColor;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 	return uno::makeAny( GetIndexColor( nColor ) );
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir void SAL_CALL
384*cdf0e10cSrcweir ScVbaInterior::setPatternColorIndex( const uno::Any& _patterncolorindex ) throw (uno::RuntimeException)
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     sal_Int32 nColorIndex = 0;
387*cdf0e10cSrcweir     if( _patterncolorindex >>= nColorIndex )
388*cdf0e10cSrcweir     {
389*cdf0e10cSrcweir         if( nColorIndex == 0 )
390*cdf0e10cSrcweir             return;
391*cdf0e10cSrcweir         sal_Int32 nPattColor = 0;
392*cdf0e10cSrcweir         GetIndexColor( nColorIndex ) >>= nPattColor;
393*cdf0e10cSrcweir         setPatternColor( uno::makeAny( OORGBToXLRGB( nPattColor ) ) );
394*cdf0e10cSrcweir     }
395*cdf0e10cSrcweir     else
396*cdf0e10cSrcweir         throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Pattern Color" ), uno::Reference< uno::XInterface >() );
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir rtl::OUString&
400*cdf0e10cSrcweir ScVbaInterior::getServiceImplName()
401*cdf0e10cSrcweir {
402*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaInterior") );
403*cdf0e10cSrcweir 	return sImplName;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
407*cdf0e10cSrcweir ScVbaInterior::getServiceNames()
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
410*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
411*cdf0e10cSrcweir 	{
412*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
413*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Interior" ) );
414*cdf0e10cSrcweir 	}
415*cdf0e10cSrcweir 	return aServiceNames;
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418