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
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <ooo/vba/msforms/XLineFormat.hpp>
25 #include "vbacolorformat.hxx"
26
27 using namespace ooo::vba;
28 using namespace com::sun::star;
29
30 sal_Int32
getColorIndex(sal_Int32 nIndex)31 MsoColorIndizes::getColorIndex( sal_Int32 nIndex )
32 {
33 const static sal_Int32 COLORINDIZES[56] =
34 { HAPICOLOR_BLACK, HAPICOLOR_WITHE, HAPICOLOR_RED, HAPICOLOR_BRIGHTGREEN, HAPICOLOR_BLUE, HAPICOLOR_YELLOW, HAPICOLOR_PINK,
35 HAPICOLOR_TURQUOISE, HAPICOLOR_DARKRED, HAPICOLOR_GREEN, HAPICOLOR_DARKBLUE, HAPICOLOR_DARKYELLOW, HAPICOLOR_VIOLET,
36 HAPICOLOR_TEAL, HAPICOLOR_GRAY_25_PERCENT, HAPICOLOR_GRAY_50_PERCENT, HAPICOLOR_PERIWINCKLE, HAPICOLOR_PLUM,
37 HAPICOLOR_IVORY, HAPICOLOR_LIGHTTURQUOISE, HAPICOLOR_DARKPRUPLE, HAPICOLOR_CORAL, HAPICOLOR_OCEANBLUE, HAPICOLOR_ICEBLUE,
38 HAPICOLOR_GREEN, HAPICOLOR_PINK, HAPICOLOR_YELLOW, HAPICOLOR_TURQUOISE, HAPICOLOR_VIOLET, HAPICOLOR_DARKRED, HAPICOLOR_TEAL,
39 HAPICOLOR_BLUE, HAPICOLOR_SKYBLUE, HAPICOLOR_LIGHTTURQUOISE, HAPICOLOR_LIGHTGREEN, HAPICOLOR_LIGHTYELLOW, HAPICOLOR_PALEBLUE,
40 HAPICOLOR_ROSE, HAPICOLOR_LAVENDER, HAPICOLOR_TAN, HAPICOLOR_LIGHTBLUE, HAPICOLOR_AQUA, HAPICOLOR_LIME, HAPICOLOR_GOLD,
41 HAPICOLOR_LIGHTORANGE, HAPICOLOR_ORANGE, HAPICOLOR_BLUEGRAY, HAPICOLOR_GRAY_40_PERCENT, HAPICOLOR_DARKTEAL,
42 HAPICOLOR_SEAGREEN, HAPICOLOR_NONAME, HAPICOLOR_OLIVEGREEN, HAPICOLOR_BROWN, HAPICOLOR_PLUM, HAPICOLOR_INDIGO,
43 HAPICOLOR_GRAY_80_PERCENT
44 };
45 return COLORINDIZES[nIndex];
46 }
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)47 ScVbaColorFormat::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_xInternalParent( xInternalParent ), m_xShape( xShape ), m_nColorFormatType( nColorFormatType )
48 {
49 m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
50 m_nFillFormatBackColor = 0;
51 try
52 {
53 uno::Reference< ov::msforms::XFillFormat > xFillFormat( xInternalParent, uno::UNO_QUERY_THROW );
54 m_pFillFormat = ( ScVbaFillFormat* )( xFillFormat.get() );
55 }catch ( uno::RuntimeException e )
56 {
57 m_pFillFormat = NULL;
58 }
59 }
60
61 void
setColorFormat(sal_Int16 _ntype)62 ScVbaColorFormat::setColorFormat( sal_Int16 _ntype )
63 {
64 m_nColorFormatType = _ntype;
65 }
66
67 // Attribute
68 sal_Int32 SAL_CALL
getRGB()69 ScVbaColorFormat::getRGB() throw (uno::RuntimeException)
70 {
71 sal_Int32 nRGB = 0;
72 switch( m_nColorFormatType )
73 {
74 case ColorFormatType::LINEFORMAT_FORECOLOR:
75 m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("LineColor") ) >>= nRGB;
76 break;
77 case ColorFormatType::LINEFORMAT_BACKCOLOR:
78 //TODO BackColor not supported
79 // m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("Color"), uno::makeAny( nRGB ) );
80 break;
81 case ColorFormatType::FILLFORMAT_FORECOLOR:
82 m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("FillColor") ) >>= nRGB;
83 break;
84 case ColorFormatType::FILLFORMAT_BACKCOLOR:
85 nRGB = m_nFillFormatBackColor;
86 break;
87 default:
88 throw uno::RuntimeException( rtl::OUString::createFromAscii("Second parameter of ColorFormat is wrong."), uno::Reference< uno::XInterface >() );
89 }
90 nRGB = OORGBToXLRGB( nRGB );
91 return nRGB;
92 }
93
94 void SAL_CALL
setRGB(sal_Int32 _rgb)95 ScVbaColorFormat::setRGB( sal_Int32 _rgb ) throw (uno::RuntimeException)
96 {
97 sal_Int32 nRGB = XLRGBToOORGB( _rgb );
98 switch( m_nColorFormatType )
99 {
100 case ColorFormatType::LINEFORMAT_FORECOLOR:
101 m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineColor" ), uno::makeAny( nRGB ) );
102 break;
103 case ColorFormatType::LINEFORMAT_BACKCOLOR:
104 // TODO BackColor not supported
105 break;
106 case ColorFormatType::FILLFORMAT_FORECOLOR:
107 m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillColor" ), uno::makeAny( nRGB ) );
108 if( m_pFillFormat )
109 {
110 m_pFillFormat->setForeColorAndInternalStyle(nRGB);
111 }
112 break;
113 case ColorFormatType::FILLFORMAT_BACKCOLOR:
114 m_nFillFormatBackColor = nRGB;
115 if( m_pFillFormat )
116 {
117 m_pFillFormat->setForeColorAndInternalStyle(nRGB);
118 }
119 break;
120 default:
121 throw uno::RuntimeException( rtl::OUString::createFromAscii("Second parameter of ColorFormat is wrong."), uno::Reference< uno::XInterface >() );
122 }
123 }
124
125 sal_Int32 SAL_CALL
getSchemeColor()126 ScVbaColorFormat::getSchemeColor() throw (uno::RuntimeException)
127 {
128 sal_Int32 nColor = getRGB();
129 // #TODO I guess the number of elements is determined by the correct scheme
130 // the implementation here seems to be a rehash of color index ( which seems to be a
131 // different thing ) - I would guess we need to know/import etc. the correct color scheme
132 // or at least find out a little more
133 sal_Int32 i = 0;
134 for( ; i < 56; i++ )
135 {
136 if( nColor == MsoColorIndizes::getColorIndex(i) )
137 break;
138 }
139
140 if( i == 56 ) // this is most likely an error condition
141 --i;
142 return i;
143 // #TODO figure out what craziness is this,
144 // the 56 colors seems incorrect, as in default XL ( 2003 ) there are 80 colors
145 /*
146 if( i == 56 )
147 {
148 i = -2;
149 }
150
151 return ( i + 2 );
152 */
153 }
154
155 void SAL_CALL
setSchemeColor(sal_Int32 _schemecolor)156 ScVbaColorFormat::setSchemeColor( sal_Int32 _schemecolor ) throw (uno::RuntimeException)
157 {
158 // the table is 0 based
159 sal_Int32 nColor = MsoColorIndizes::getColorIndex( _schemecolor );
160 // nColor is already xl RGB
161 setRGB( nColor );
162 }
163
164
165 rtl::OUString&
getServiceImplName()166 ScVbaColorFormat::getServiceImplName()
167 {
168 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaColorFormat") );
169 return sImplName;
170 }
171
172 uno::Sequence< rtl::OUString >
getServiceNames()173 ScVbaColorFormat::getServiceNames()
174 {
175 static uno::Sequence< rtl::OUString > aServiceNames;
176 if ( aServiceNames.getLength() == 0 )
177 {
178 aServiceNames.realloc( 1 );
179 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ColorFormat" ) );
180 }
181 return aServiceNames;
182 }
183
184