Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "vbapalette.hxx"
21 : :
22 : : #include <sal/macros.h>
23 : : #include <cppuhelper/implbase1.hxx>
24 : : #include <com/sun/star/beans/XPropertySet.hpp>
25 : : #include <com/sun/star/container/XIndexAccess.hpp>
26 : : #include "excelvbahelper.hxx"
27 : :
28 : : using namespace ::com::sun::star;
29 : : using namespace ::ooo::vba;
30 : :
31 : : /** Standard EGA colors, bright. */
32 : : #define EXC_PALETTE_EGA_COLORS_LIGHT \
33 : : 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
34 : : /** Standard EGA colors, dark. */
35 : : #define EXC_PALETTE_EGA_COLORS_DARK \
36 : : 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
37 : :
38 : : static const ColorData spnDefColorTable8[] =
39 : : {
40 : : /* 8 */ EXC_PALETTE_EGA_COLORS_LIGHT,
41 : : /* 16 */ EXC_PALETTE_EGA_COLORS_DARK,
42 : : /* 24 */ 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
43 : : /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
44 : : /* 40 */ 0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
45 : : /* 48 */ 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
46 : : /* 56 */ 0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
47 : : };
48 : :
49 : : typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE;
50 : :
51 [ - + ]: 4 : class DefaultPalette : public XIndexAccess_BASE
52 : : {
53 : : public:
54 : 2 : DefaultPalette(){}
55 : :
56 : : // Methods XIndexAccess
57 : 114 : virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException)
58 : : {
59 : 114 : return sizeof(spnDefColorTable8) / sizeof(spnDefColorTable8[0]);
60 : : }
61 : :
62 : 112 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
63 : : {
64 [ + - ][ - + ]: 112 : if ( Index < 0 || Index >= getCount() )
[ - + ]
65 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
66 [ + - ]: 112 : return uno::makeAny( sal_Int32( spnDefColorTable8[ Index ] ) );
67 : : }
68 : :
69 : : // Methods XElementAcess
70 : 0 : virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
71 : : {
72 : 0 : return ::getCppuType( (sal_Int32*)0 );
73 : : }
74 : 0 : virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException)
75 : : {
76 : 0 : return sal_True;
77 : : }
78 : :
79 : : };
80 : :
81 : 0 : ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) :
82 : 0 : m_pShell( excel::getDocShell( rxModel ) )
83 : : {
84 : 0 : }
85 : :
86 : : uno::Reference< container::XIndexAccess >
87 : 2 : ScVbaPalette::getDefaultPalette()
88 : : {
89 [ + - ][ + - ]: 2 : return new DefaultPalette();
90 : : }
91 : :
92 : : uno::Reference< container::XIndexAccess >
93 : 0 : ScVbaPalette::getPalette() const
94 : : {
95 : 0 : uno::Reference< container::XIndexAccess > xIndex;
96 : 0 : uno::Reference< beans::XPropertySet > xProps;
97 [ # # ]: 0 : if ( m_pShell )
98 [ # # ][ # # ]: 0 : xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW );
99 : : else
100 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract palette, no doc shell" ) ), uno::Reference< uno::XInterface >() );
101 [ # # ][ # # ]: 0 : xIndex.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ColorPalette") ) ), uno::UNO_QUERY );
[ # # ][ # # ]
102 [ # # ]: 0 : if ( !xIndex.is() )
103 [ # # ][ # # ]: 0 : return new DefaultPalette();
[ # # ]
104 : 0 : return xIndex;
105 : : }
106 : :
107 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|