1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbapalette.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbapalette.hxx"
31 #include <cppuhelper/implbase1.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
35 using namespace ::com::sun::star
;
36 using namespace ::ooo::vba
;
38 /** Standard EGA colors, bright. */
39 #define EXC_PALETTE_EGA_COLORS_LIGHT \
40 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
41 /** Standard EGA colors, dark. */
42 #define EXC_PALETTE_EGA_COLORS_DARK \
43 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
45 static const ColorData spnDefColorTable8
[] =
47 /* 8 */ EXC_PALETTE_EGA_COLORS_LIGHT
,
48 /* 16 */ EXC_PALETTE_EGA_COLORS_DARK
,
49 /* 24 */ 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
50 /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
51 /* 40 */ 0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
52 /* 48 */ 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
53 /* 56 */ 0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
56 typedef ::cppu::WeakImplHelper1
< container::XIndexAccess
> XIndexAccess_BASE
;
58 class DefaultPalette
: public XIndexAccess_BASE
63 // Methods XIndexAccess
64 virtual ::sal_Int32 SAL_CALL
getCount() throw (uno::RuntimeException
)
66 return sizeof(spnDefColorTable8
) / sizeof(spnDefColorTable8
[0]);
69 virtual uno::Any SAL_CALL
getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
71 if ( Index
< 0 || Index
>= getCount() )
72 throw lang::IndexOutOfBoundsException();
73 return uno::makeAny( sal_Int32( spnDefColorTable8
[ Index
] ) );
76 // Methods XElementAcess
77 virtual uno::Type SAL_CALL
getElementType() throw (uno::RuntimeException
)
79 return ::getCppuType( (sal_Int32
*)0 );
81 virtual ::sal_Bool SAL_CALL
hasElements() throw (uno::RuntimeException
)
88 uno::Reference
< container::XIndexAccess
>
89 ScVbaPalette::getDefaultPalette()
91 return new DefaultPalette();
94 uno::Reference
< container::XIndexAccess
>
95 ScVbaPalette::getPalette() const
97 uno::Reference
< container::XIndexAccess
> xIndex
;
98 uno::Reference
< beans::XPropertySet
> xProps
;
100 xProps
.set( m_pShell
->GetModel(), uno::UNO_QUERY_THROW
);
102 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract palette, no doc shell" ) ), uno::Reference
< uno::XInterface
>() );
103 xIndex
.set( xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ColorPalette") ) ), uno::UNO_QUERY
);
105 return new DefaultPalette();