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>
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
31using namespace ::com::sun::star;
32using 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)
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
52typedef ::cppu::WeakImplHelper< container::XIndexAccess > XIndexAccess_BASE;
53
54namespace {
55
56class DefaultPalette : public XIndexAccess_BASE
57{
58public:
59 DefaultPalette(){}
60
61 // Methods XIndexAccess
62 virtual ::sal_Int32 SAL_CALL getCount() override
63 {
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::Any( 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
88ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) :
89 m_pShell( excel::getDocShell( rxModel ) )
90{
91}
92
93uno::Reference< container::XIndexAccess >
95{
96 return new DefaultPalette();
97}
98
99uno::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: */
struct _ADOIndex Index
css::uno::Reference< css::container::XIndexAccess > getPalette() const
Definition: vbapalette.cxx:100
SfxObjectShell * m_pShell
Definition: vbapalette.hxx:34
ScVbaPalette(SfxObjectShell *pShell)
Definition: vbapalette.hxx:36
static css::uno::Reference< css::container::XIndexAccess > getDefaultPalette()
Definition: vbapalette.cxx:94
css::uno::Reference< css::frame::XModel3 > GetModel() const
Shell * m_pShell
#define SAL_N_ELEMENTS(arr)
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
unsigned char sal_Bool
const Color spnDefColorTable8[]
Definition: vbapalette.cxx:41
#define EXC_PALETTE_EGA_COLORS_LIGHT
Standard EGA colors, bright.
Definition: vbapalette.cxx:35
#define EXC_PALETTE_EGA_COLORS_DARK
Standard EGA colors), dark.
Definition: vbapalette.cxx:38
::cppu::WeakImplHelper< container::XIndexAccess > XIndexAccess_BASE
Definition: vbapalette.cxx:52