LibreOffice Module vbahelper (master) 1
vbacolorformat.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#include <com/sun/star/beans/XPropertySet.hpp>
20#include "vbacolorformat.hxx"
21
22using namespace ooo::vba;
23using namespace com::sun::star;
24
25sal_Int32
27{
28 const static sal_Int32 COLORINDICES[56] =
39 };
40 return COLORINDICES[nIndex];
41}
42ScVbaColorFormat::ScVbaColorFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XHelperInterface >& xInternalParent, const uno::Reference< drawing::XShape >& xShape, const sal_Int16 nColorFormatType ) : ScVbaColorFormat_BASE( xParent, xContext ), m_nColorFormatType( nColorFormatType )
43{
44 m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
46 try
47 {
48 uno::Reference< ov::msforms::XFillFormat > xFillFormat( xInternalParent, uno::UNO_QUERY_THROW );
49 m_pFillFormat = static_cast<ScVbaFillFormat*>( xFillFormat.get() );
50 }catch ( uno::RuntimeException& )
51 {
52 m_pFillFormat = nullptr;
53 }
54}
55
56// Attribute
57sal_Int32 SAL_CALL
59{
60 sal_Int32 nRGB = 0;
61 switch( m_nColorFormatType )
62 {
64 m_xPropertySet->getPropertyValue( "LineColor" ) >>= nRGB;
65 break;
67 //TODO BackColor not supported
68 // m_xPropertySet->setPropertyValue("Color", uno::makeAny( nRGB ) );
69 break;
71 m_xPropertySet->getPropertyValue( "FillColor" ) >>= nRGB;
72 break;
75 break;
76 default:
77 throw uno::RuntimeException( "Second parameter of ColorFormat is wrong." );
78 }
79 nRGB = OORGBToXLRGB( Color(ColorTransparency, nRGB) );
80 return nRGB;
81}
82
83void SAL_CALL
84ScVbaColorFormat::setRGB( sal_Int32 _rgb )
85{
86 sal_Int32 nRGB = XLRGBToOORGB( _rgb );
87 switch( m_nColorFormatType )
88 {
90 m_xPropertySet->setPropertyValue( "LineColor" , uno::Any( nRGB ) );
91 break;
93 // TODO BackColor not supported
94 break;
96 m_xPropertySet->setPropertyValue( "FillColor" , uno::Any( nRGB ) );
97 if( m_pFillFormat )
98 {
100 }
101 break;
104 if( m_pFillFormat )
105 {
107 }
108 break;
109 default:
110 throw uno::RuntimeException( "Second parameter of ColorFormat is wrong." );
111 }
112}
113
114sal_Int32 SAL_CALL
116{
117 sal_Int32 nColor = getRGB();
118 // #TODO I guess the number of elements is determined by the correct scheme
119 // the implementation here seems to be a rehash of color index ( which seems to be a
120 // different thing ) - I would guess we need to know/import etc. the correct color scheme
121 // or at least find out a little more
122 sal_Int32 i = 0;
123 for( ; i < 56; i++ )
124 {
125 if( nColor == MsoColorIndices::getColorIndex(i) )
126 break;
127 }
128
129 if( i == 56 ) // this is most likely an error condition
130 --i;
131 return i;
132 // #TODO figure out what craziness is this,
133 // the 56 colors seems incorrect, as in default XL ( 2003 ) there are 80 colors
134/*
135 if( i == 56 )
136 {
137 i = -2;
138 }
139
140 return ( i + 2 );
141*/
142}
143
144void SAL_CALL
145ScVbaColorFormat::setSchemeColor( sal_Int32 _schemecolor )
146{
147 // the table is 0 based
148 sal_Int32 nColor = MsoColorIndices::getColorIndex( _schemecolor );
149 // nColor is already xl RGB
150 setRGB( nColor );
151}
152
153OUString
155{
156 return "ScVbaColorFormat";
157}
158
159uno::Sequence< OUString >
161{
162 static uno::Sequence< OUString > const aServiceNames
163 {
164 "ooo.vba.msforms.ColorFormat"
165 };
166 return aServiceNames;
167}
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const sal_Int16 FILLFORMAT_FORECOLOR
static const sal_Int16 LINEFORMAT_FORECOLOR
static const sal_Int16 LINEFORMAT_BACKCOLOR
static const sal_Int16 FILLFORMAT_BACKCOLOR
virtual sal_Int32 SAL_CALL getRGB() override
sal_Int32 m_nFillFormatBackColor
virtual void SAL_CALL setSchemeColor(sal_Int32 _schemecolor) override
ScVbaColorFormat(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< ov::XHelperInterface > &xInternalParent, const css::uno::Reference< css::drawing::XShape > &xShape, const sal_Int16 nColorFormatType)
virtual OUString getServiceImplName() override
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
virtual css::uno::Sequence< OUString > getServiceNames() override
sal_Int16 m_nColorFormatType
virtual void SAL_CALL setRGB(sal_Int32 _rgb) override
virtual sal_Int32 SAL_CALL getSchemeColor() override
ScVbaFillFormat * m_pFillFormat
void setForeColorAndInternalStyle(sal_Int32 nForeColor)
ColorTransparency
Sequence< OUString > aServiceNames
sal_Int32 nIndex
int i
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
Definition: vbahelper.cxx:306
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
Definition: vbahelper.cxx:289
static const sal_Int32 HAPICOLOR_OLIVEGREEN
static const sal_Int32 HAPICOLOR_BROWN
static const sal_Int32 HAPICOLOR_DARKTEAL
static const sal_Int32 HAPICOLOR_GRAY_40_PERCENT
static const sal_Int32 HAPICOLOR_PERIWINCKLE
static const sal_Int32 HAPICOLOR_BLACK
static const sal_Int32 HAPICOLOR_TEAL
static const sal_Int32 HAPICOLOR_TURQUOISE
static const sal_Int32 HAPICOLOR_PLUM
static const sal_Int32 HAPICOLOR_GRAY_50_PERCENT
static const sal_Int32 HAPICOLOR_PINK
static const sal_Int32 HAPICOLOR_YELLOW
static const sal_Int32 HAPICOLOR_NONAME
static const sal_Int32 HAPICOLOR_SKYBLUE
static const sal_Int32 HAPICOLOR_INDIGO
static const sal_Int32 HAPICOLOR_LIGHTTURQUOISE
static const sal_Int32 HAPICOLOR_OCEANBLUE
static const sal_Int32 HAPICOLOR_LIGHTORANGE
static const sal_Int32 HAPICOLOR_IVORY
static const sal_Int32 HAPICOLOR_DARKYELLOW
static const sal_Int32 HAPICOLOR_DARKPRUPLE
static const sal_Int32 HAPICOLOR_RED
static const sal_Int32 HAPICOLOR_ROSE
static const sal_Int32 HAPICOLOR_GRAY_25_PERCENT
static const sal_Int32 HAPICOLOR_BRIGHTGREEN
static const sal_Int32 HAPICOLOR_SEAGREEN
static const sal_Int32 HAPICOLOR_WHITE
static const sal_Int32 HAPICOLOR_GOLD
static const sal_Int32 HAPICOLOR_LIME
static const sal_Int32 HAPICOLOR_GRAY_80_PERCENT
static const sal_Int32 HAPICOLOR_LIGHTGREEN
static const sal_Int32 HAPICOLOR_PALEBLUE
static const sal_Int32 HAPICOLOR_AQUA
static const sal_Int32 HAPICOLOR_VIOLET
static const sal_Int32 HAPICOLOR_TAN
static const sal_Int32 HAPICOLOR_ICEBLUE
static sal_Int32 getColorIndex(sal_Int32 nIndex)
static const sal_Int32 HAPICOLOR_BLUE
static const sal_Int32 HAPICOLOR_DARKBLUE
static const sal_Int32 HAPICOLOR_GREEN
static const sal_Int32 HAPICOLOR_CORAL
static const sal_Int32 HAPICOLOR_LAVENDER
static const sal_Int32 HAPICOLOR_LIGHTBLUE
static const sal_Int32 HAPICOLOR_ORANGE
static const sal_Int32 HAPICOLOR_DARKRED
static const sal_Int32 HAPICOLOR_LIGHTYELLOW
static const sal_Int32 HAPICOLOR_BLUEGRAY