xref: /trunk/main/sc/source/ui/vba/vbapalette.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "vbapalette.hxx"
25 #include <cppuhelper/implbase1.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XIndexAccess.hpp>
28 #include "excelvbahelper.hxx"
29 
30 using namespace ::com::sun::star;
31 using namespace ::ooo::vba;
32 
33 /** Standard EGA colors, bright. */
34 #define EXC_PALETTE_EGA_COLORS_LIGHT \
35             0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
36 /** Standard EGA colors, dark. */
37 #define EXC_PALETTE_EGA_COLORS_DARK \
38             0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
39 
40 static const ColorData spnDefColorTable8[] =
41 {
42 /*  8 */    EXC_PALETTE_EGA_COLORS_LIGHT,
43 /* 16 */    EXC_PALETTE_EGA_COLORS_DARK,
44 /* 24 */    0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
45 /* 32 */    0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
46 /* 40 */    0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
47 /* 48 */    0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
48 /* 56 */    0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
49 };
50 
51 typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE;
52 
53 class DefaultPalette : public XIndexAccess_BASE
54 {
55 public:
DefaultPalette()56    DefaultPalette(){}
57 
58     // Methods XIndexAccess
getCount()59     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException)
60     {
61         return sizeof(spnDefColorTable8) / sizeof(spnDefColorTable8[0]);
62     }
63 
getByIndex(::sal_Int32 Index)64     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
65     {
66 	if ( Index < 0 || Index >= getCount() )
67 		throw lang::IndexOutOfBoundsException();
68         return uno::makeAny( sal_Int32( spnDefColorTable8[ Index ] ) );
69     }
70 
71     // Methods XElementAcess
getElementType()72     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
73     {
74         return ::getCppuType( (sal_Int32*)0 );
75     }
hasElements()76     virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException)
77     {
78         return sal_True;
79     }
80 
81 };
82 
ScVbaPalette(const uno::Reference<frame::XModel> & rxModel)83 ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) :
84     m_pShell( excel::getDocShell( rxModel ) )
85 {
86 }
87 
88 uno::Reference< container::XIndexAccess >
getDefaultPalette()89 ScVbaPalette::getDefaultPalette()
90 {
91 	return new DefaultPalette();
92 }
93 
94 uno::Reference< container::XIndexAccess >
getPalette() const95 ScVbaPalette::getPalette() const
96 {
97 	uno::Reference< container::XIndexAccess > xIndex;
98 	uno::Reference< beans::XPropertySet > xProps;
99 	if ( m_pShell )
100 		xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW );
101 	else
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 );
104 	if ( !xIndex.is() )
105 		return new DefaultPalette();
106 	return xIndex;
107 }
108