xref: /aoo42x/main/sw/source/ui/vba/vbapalette.cxx (revision efeef26f)
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 #include "vbapalette.hxx"
23 #include <cppuhelper/implbase1.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <ooo/vba/word/WdColor.hpp>
26 #include <ooo/vba/word/WdColorIndex.hpp>
27 
28 using namespace ::ooo::vba;
29 using namespace ::ooo::vba::word;
30 using namespace ::com::sun::star;
31 
32 static const sal_Int32 ColorTable[] =
33 {
34 WdColor::wdColorAutomatic, // 0
35 WdColor::wdColorBlack,             // 1
36 WdColor::wdColorBlue,               // 2
37 WdColor::wdColorTurquoise,     // 3
38 WdColor::wdColorBrightGreen, // 4
39 WdColor::wdColorPink,               // 5
40 WdColor::wdColorRed,                 // 6
41 WdColor::wdColorYellow,           // 7
42 WdColor::wdColorWhite,             // 8
43 WdColor::wdColorDarkBlue,       // 9
44 WdColor::wdColorTeal,               // 10
45 WdColor::wdColorGreen,             // 11
46 WdColor::wdColorViolet,           // 12
47 WdColor::wdColorDarkRed,         // 13
48 WdColor::wdColorDarkYellow,   // 14
49 WdColor::wdColorGray50,           // 15
50 WdColor::wdColorGray25,           // 16
51 };
52 
53 typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE;
54 
55 class DefaultPalette : public XIndexAccess_BASE
56 {
57 public:
DefaultPalette()58    DefaultPalette(){}
59 
60     // Methods XIndexAccess
getCount()61     virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException)
62     {
63         return sizeof(ColorTable) / sizeof(ColorTable[0]);
64     }
65 
getByIndex(::sal_Int32 Index)66     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
67     {
68 	if ( Index < 0 || Index >= getCount() )
69 		throw lang::IndexOutOfBoundsException();
70         return uno::makeAny( sal_Int32( ColorTable[ Index ] ) );
71     }
72 
73     // Methods XElementAcess
getElementType()74     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
75     {
76         return ::getCppuType( (sal_Int32*)0 );
77     }
hasElements()78     virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException)
79     {
80         return sal_True;
81     }
82 
83 };
84 
VbaPalette()85 VbaPalette::VbaPalette()
86 {
87     mxPalette = new DefaultPalette();
88 }
89 
90 uno::Reference< container::XIndexAccess >
getPalette() const91 VbaPalette::getPalette() const
92 {
93 
94 	return mxPalette;
95 }
96 
97