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