LibreOffice Module sc (master)  1
vbapalette.cxx
Go to the documentation of this file.
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/implbase.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <docsh.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XIndexAccess.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include "excelvbahelper.hxx"
30 
31 using namespace ::com::sun::star;
32 using namespace ::ooo::vba;
33 
35 #define EXC_PALETTE_EGA_COLORS_LIGHT \
36  Color(0x000000), Color(0xFFFFFF), Color(0xFF0000), Color(0x00FF00), Color(0x0000FF), Color(0xFFFF00), Color(0xFF00FF), Color(0x00FFFF)
37 
38 #define EXC_PALETTE_EGA_COLORS_DARK \
39  Color(0x800000), Color(0x008000), Color(0x000080), Color(0x808000), Color(0x800080), Color(0x008080), Color(0xC0C0C0), Color(0x808080)
40 
42 {
45 /* 24 */ Color(0x9999FF), Color(0x993366), Color(0xFFFFCC), Color(0xCCFFFF), Color(0x660066), Color(0xFF8080), Color(0x0066CC), Color(0xCCCCFF),
46 /* 32 */ Color(0x000080), Color(0xFF00FF), Color(0xFFFF00), Color(0x00FFFF), Color(0x800080), Color(0x800000), Color(0x008080), Color(0x0000FF),
47 /* 40 */ Color(0x00CCFF), Color(0xCCFFFF), Color(0xCCFFCC), Color(0xFFFF99), Color(0x99CCFF), Color(0xFF99CC), Color(0xCC99FF), Color(0xFFCC99),
48 /* 48 */ Color(0x3366FF), Color(0x33CCCC), Color(0x99CC00), Color(0xFFCC00), Color(0xFF9900), Color(0xFF6600), Color(0x666699), Color(0x969696),
49 /* 56 */ Color(0x003366), Color(0x339966), Color(0x003300), Color(0x333300), Color(0x993300), Color(0x993366), Color(0x333399), Color(0x333333)
50 };
51 
52 typedef ::cppu::WeakImplHelper< container::XIndexAccess > XIndexAccess_BASE;
53 
54 namespace {
55 
56 class DefaultPalette : public XIndexAccess_BASE
57 {
58 public:
59  DefaultPalette(){}
60 
61  // Methods XIndexAccess
62  virtual ::sal_Int32 SAL_CALL getCount() override
63  {
64  return SAL_N_ELEMENTS(spnDefColorTable8);
65  }
66 
67  virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
68  {
69  if ( Index < 0 || Index >= getCount() )
70  throw lang::IndexOutOfBoundsException();
71  return uno::makeAny( sal_Int32( spnDefColorTable8[ Index ] ) );
72  }
73 
74  // Methods XElementAccess
75  virtual uno::Type SAL_CALL getElementType() override
76  {
77  return ::cppu::UnoType<sal_Int32>::get();
78  }
79  virtual sal_Bool SAL_CALL hasElements() override
80  {
81  return true;
82  }
83 
84 };
85 
86 }
87 
88 ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) :
89  m_pShell( excel::getDocShell( rxModel ) )
90 {
91 }
92 
93 uno::Reference< container::XIndexAccess >
95 {
96  return new DefaultPalette();
97 }
98 
99 uno::Reference< container::XIndexAccess >
101 {
102  uno::Reference< container::XIndexAccess > xIndex;
103  uno::Reference< beans::XPropertySet > xProps;
104  if ( !m_pShell )
105  throw uno::RuntimeException("Can't extract palette, no doc shell" );
106 
107  xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW );
108 
109  xIndex.set( xProps->getPropertyValue("ColorPalette"), uno::UNO_QUERY );
110  if ( !xIndex.is() )
111  return new DefaultPalette();
112  return xIndex;
113 }
114 
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel > GetModel() const
#define EXC_PALETTE_EGA_COLORS_LIGHT
Standard EGA colors, bright.
Definition: vbapalette.cxx:35
#define SAL_N_ELEMENTS(arr)
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
ScVbaPalette(SfxObjectShell *pShell)
Definition: vbapalette.hxx:37
#define EXC_PALETTE_EGA_COLORS_DARK
Standard EGA colors), dark.
Definition: vbapalette.cxx:38
unsigned char sal_Bool
SfxObjectShell * m_pShell
Definition: vbapalette.hxx:35
Shell * m_pShell
const Color spnDefColorTable8[]
Definition: vbapalette.cxx:41
::cppu::WeakImplHelper< container::XIndexAccess > XIndexAccess_BASE
Definition: vbapalette.cxx:52
struct _ADOIndex Index
static css::uno::Reference< css::container::XIndexAccess > getDefaultPalette()
Definition: vbapalette.cxx:94
css::uno::Reference< css::container::XIndexAccess > getPalette() const
Definition: vbapalette.cxx:100