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 24cdf0e10cSrcweir #include "vbapalette.hxx" 25cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 26cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 27cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 28cdf0e10cSrcweir #include "excelvbahelper.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir using namespace ::com::sun::star; 31cdf0e10cSrcweir using namespace ::ooo::vba; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** Standard EGA colors, bright. */ 34cdf0e10cSrcweir #define EXC_PALETTE_EGA_COLORS_LIGHT \ 35cdf0e10cSrcweir 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF 36cdf0e10cSrcweir /** Standard EGA colors, dark. */ 37cdf0e10cSrcweir #define EXC_PALETTE_EGA_COLORS_DARK \ 38cdf0e10cSrcweir 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080 39cdf0e10cSrcweir 40cdf0e10cSrcweir static const ColorData spnDefColorTable8[] = 41cdf0e10cSrcweir { 42cdf0e10cSrcweir /* 8 */ EXC_PALETTE_EGA_COLORS_LIGHT, 43cdf0e10cSrcweir /* 16 */ EXC_PALETTE_EGA_COLORS_DARK, 44cdf0e10cSrcweir /* 24 */ 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF, 45cdf0e10cSrcweir /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF, 46cdf0e10cSrcweir /* 40 */ 0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99, 47cdf0e10cSrcweir /* 48 */ 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696, 48cdf0e10cSrcweir /* 56 */ 0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333 49cdf0e10cSrcweir }; 50cdf0e10cSrcweir 51cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE; 52cdf0e10cSrcweir 53cdf0e10cSrcweir class DefaultPalette : public XIndexAccess_BASE 54cdf0e10cSrcweir { 55cdf0e10cSrcweir public: 56cdf0e10cSrcweir DefaultPalette(){} 57cdf0e10cSrcweir 58cdf0e10cSrcweir // Methods XIndexAccess 59cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir return sizeof(spnDefColorTable8) / sizeof(spnDefColorTable8[0]); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir if ( Index < 0 || Index >= getCount() ) 67cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 68cdf0e10cSrcweir return uno::makeAny( sal_Int32( spnDefColorTable8[ Index ] ) ); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir // Methods XElementAcess 72cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir return ::getCppuType( (sal_Int32*)0 ); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir return sal_True; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir }; 82cdf0e10cSrcweir 83cdf0e10cSrcweir ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) : 84cdf0e10cSrcweir m_pShell( excel::getDocShell( rxModel ) ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir uno::Reference< container::XIndexAccess > 89cdf0e10cSrcweir ScVbaPalette::getDefaultPalette() 90cdf0e10cSrcweir { 91cdf0e10cSrcweir return new DefaultPalette(); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir uno::Reference< container::XIndexAccess > 95cdf0e10cSrcweir ScVbaPalette::getPalette() const 96cdf0e10cSrcweir { 97cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xIndex; 98cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps; 99cdf0e10cSrcweir if ( m_pShell ) 100cdf0e10cSrcweir xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW ); 101cdf0e10cSrcweir else 102cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract palette, no doc shell" ) ), uno::Reference< uno::XInterface >() ); 103cdf0e10cSrcweir xIndex.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ColorPalette") ) ), uno::UNO_QUERY ); 104cdf0e10cSrcweir if ( !xIndex.is() ) 105cdf0e10cSrcweir return new DefaultPalette(); 106cdf0e10cSrcweir return xIndex; 107cdf0e10cSrcweir } 108