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