tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbapalette.cxx
blob67a444cba0ec3edaed3b4ee205a4cb03dc21fc1a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "vbapalette.hxx"
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"
31 using namespace ::com::sun::star;
32 using namespace ::ooo::vba;
34 /** Standard EGA colors, bright. */
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 /** Standard EGA colors), dark. */
38 #define EXC_PALETTE_EGA_COLORS_DARK \
39 Color(0x800000), Color(0x008000), Color(0x000080), Color(0x808000), Color(0x800080), Color(0x008080), Color(0xC0C0C0), Color(0x808080)
41 const Color spnDefColorTable8[] =
43 /* 8 */ EXC_PALETTE_EGA_COLORS_LIGHT,
44 /* 16 */ EXC_PALETTE_EGA_COLORS_DARK,
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)
52 typedef ::cppu::WeakImplHelper< container::XIndexAccess > XIndexAccess_BASE;
54 namespace {
56 class DefaultPalette : public XIndexAccess_BASE
58 public:
59 DefaultPalette(){}
61 // Methods XIndexAccess
62 virtual ::sal_Int32 SAL_CALL getCount() override
64 return SAL_N_ELEMENTS(spnDefColorTable8);
67 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
69 if ( Index < 0 || Index >= getCount() )
70 throw lang::IndexOutOfBoundsException();
71 return uno::Any( sal_Int32( spnDefColorTable8[ Index ] ) );
74 // Methods XElementAccess
75 virtual uno::Type SAL_CALL getElementType() override
77 return ::cppu::UnoType<sal_Int32>::get();
79 virtual sal_Bool SAL_CALL hasElements() override
81 return true;
88 ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) :
89 m_pShell( excel::getDocShell( rxModel ) )
93 uno::Reference< container::XIndexAccess >
94 ScVbaPalette::getDefaultPalette()
96 return new DefaultPalette();
99 uno::Reference< container::XIndexAccess >
100 ScVbaPalette::getPalette() const
102 uno::Reference< container::XIndexAccess > xIndex;
103 uno::Reference< beans::XPropertySet > xProps;
104 if ( !m_pShell )
105 throw uno::RuntimeException(u"Can't extract palette, no doc shell"_ustr );
107 xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW );
109 xIndex.set( xProps->getPropertyValue(u"ColorPalette"_ustr), uno::UNO_QUERY );
110 if ( !xIndex.is() )
111 return new DefaultPalette();
112 return xIndex;
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */