merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / vba / vbafont.cxx
blob58fe73ef6c83dc2f4a157d502acf1b39d72109f6
1 #include "vbafont.hxx"
2 #include <com/sun/star/awt/FontUnderline.hpp>
3 #include <ooo/vba/word/WdUnderline.hpp>
4 #include <hash_map>
5 #include <ooo/vba/word/WdColorIndex.hpp>
7 using namespace ::ooo::vba;
8 using namespace ::com::sun::star;
10 const uno::Any aLongAnyTrue( sal_Int16(-1) );
11 const uno::Any aLongAnyFalse( sal_Int16( 0 ) );
13 struct MapPair
15 sal_Int32 nMSOConst;
16 sal_Int32 nOOOConst;
19 static MapPair UnderLineTable[] = {
20 { word::WdUnderline::wdUnderlineNone, com::sun::star::awt::FontUnderline::NONE },
21 { word::WdUnderline::wdUnderlineSingle, com::sun::star::awt::FontUnderline::SINGLE },
22 { word::WdUnderline::wdUnderlineWords, com::sun::star::awt::FontUnderline::SINGLE },
23 { word::WdUnderline::wdUnderlineDouble, com::sun::star::awt::FontUnderline::DOUBLE },
24 { word::WdUnderline::wdUnderlineDotted, com::sun::star::awt::FontUnderline::DOTTED },
25 { word::WdUnderline::wdUnderlineThick, com::sun::star::awt::FontUnderline::BOLDDASH },
26 { word::WdUnderline::wdUnderlineDash, com::sun::star::awt::FontUnderline::DASH },
27 { word::WdUnderline::wdUnderlineDotDash, com::sun::star::awt::FontUnderline::DASHDOT },
28 { word::WdUnderline::wdUnderlineDotDotDash, com::sun::star::awt::FontUnderline::DASHDOTDOT },
29 { word::WdUnderline::wdUnderlineWavy, com::sun::star::awt::FontUnderline::WAVE },
30 { word::WdUnderline::wdUnderlineDottedHeavy, com::sun::star::awt::FontUnderline::BOLDDOTTED },
31 { word::WdUnderline::wdUnderlineDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASH },
32 { word::WdUnderline::wdUnderlineDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOT },
33 { word::WdUnderline::wdUnderlineDotDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOTDOT },
34 { word::WdUnderline::wdUnderlineWavyHeavy, com::sun::star::awt::FontUnderline::BOLDWAVE },
35 { word::WdUnderline::wdUnderlineDashLong, com::sun::star::awt::FontUnderline::LONGDASH },
36 { word::WdUnderline::wdUnderlineWavyDouble, com::sun::star::awt::FontUnderline::DOUBLEWAVE },
37 { word::WdUnderline::wdUnderlineDashLongHeavy, com::sun::star::awt::FontUnderline::BOLDLONGDASH },
40 typedef std::hash_map< sal_Int32, sal_Int32 > ConstToConst;
41 class UnderLineMapper
43 ConstToConst MSO2OOO;
44 ConstToConst OOO2MSO;
45 private:
46 UnderLineMapper()
48 sal_Int32 nLen = sizeof( UnderLineTable )/ sizeof( UnderLineTable[0] );
50 for ( sal_Int32 index=0; index<nLen; ++index )
52 MSO2OOO[ UnderLineTable[ index ].nMSOConst ] = UnderLineTable[ index ].nOOOConst;
53 OOO2MSO[ UnderLineTable[ index ].nOOOConst ] = UnderLineTable[ index ].nMSOConst;
56 public:
57 static rtl::OUString propName()
59 static rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("CharUnderline") );
60 return sPropName;
63 static UnderLineMapper& instance()
65 static UnderLineMapper theMapper;
66 return theMapper;
69 sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst ) throw( lang::IllegalArgumentException )
71 ConstToConst::iterator it = MSO2OOO.find( nMSOConst );
72 if ( it == MSO2OOO.end() )
73 throw lang::IllegalArgumentException();
74 return it->second;
76 sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst ) throw( lang::IllegalArgumentException )
78 ConstToConst::iterator it = OOO2MSO.find( nOOOConst );
79 if ( it == OOO2MSO.end() )
80 throw lang::IllegalArgumentException();
81 return it->second;
85 SwVbaFont::SwVbaFont( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPalette, uno::Reference< css::beans::XPropertySet > xPropertySet ) throw ( css::uno::RuntimeException ) : SwVbaFont_BASE( xParent, xContext, xPalette, xPropertySet )
89 uno::Any SAL_CALL
90 SwVbaFont::getUnderline() throw (uno::RuntimeException)
92 sal_Int32 nOOVal = 0;
93 mxFont->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal;
94 return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
97 void SAL_CALL
98 SwVbaFont::setUnderline( const uno::Any& _underline ) throw (uno::RuntimeException)
100 sal_Int32 nMSOVal = 0;
102 if ( _underline >>= nMSOVal )
104 sal_Int32 nOOVal = UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
105 mxFont->setPropertyValue( UnderLineMapper::propName(), uno::makeAny( nOOVal ) );
109 rtl::OUString&
110 SwVbaFont::getServiceImplName()
112 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFont") );
113 return sImplName;
116 void SAL_CALL
117 SwVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException )
119 sal_Int32 nIndex = 0;
120 _colorindex >>= nIndex;
121 return setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
124 uno::Any SAL_CALL
125 SwVbaFont::getColorIndex() throw ( uno::RuntimeException )
127 sal_Int32 nColor = 0;
129 XLRGBToOORGB( getColor() ) >>= nColor;
130 sal_Int32 nElems = mxPalette->getCount();
131 sal_Int32 nIndex = 0;
132 for ( sal_Int32 count=0; count<nElems; ++count )
134 sal_Int32 nPaletteColor = 0;
135 mxPalette->getByIndex( count ) >>= nPaletteColor;
136 if ( nPaletteColor == nColor )
138 nIndex = count;
139 break;
142 return uno::makeAny( nIndex );
144 uno::Any SAL_CALL
145 SwVbaFont::getSubscript() throw ( uno::RuntimeException )
147 sal_Bool bRes = sal_False;
148 SwVbaFont_BASE::getSubscript() >>= bRes;
149 if ( bRes )
150 return aLongAnyTrue;
151 return aLongAnyFalse;
154 uno::Any SAL_CALL
155 SwVbaFont::getSuperscript() throw ( uno::RuntimeException )
157 sal_Bool bRes = sal_False;
158 SwVbaFont_BASE::getSuperscript() >>= bRes;
159 if ( bRes )
160 return aLongAnyTrue;
161 return aLongAnyFalse;
164 uno::Any SAL_CALL
165 SwVbaFont::getBold() throw (uno::RuntimeException)
167 sal_Bool bRes = sal_False;
168 SwVbaFont_BASE::getBold() >>= bRes;
169 if ( bRes )
170 return aLongAnyTrue;
171 return aLongAnyFalse;
174 uno::Any SAL_CALL
175 SwVbaFont::getItalic() throw (uno::RuntimeException)
177 sal_Bool bRes = sal_False;
178 SwVbaFont_BASE::getItalic() >>= bRes;
179 if ( bRes )
180 return aLongAnyTrue;
181 return aLongAnyFalse;
184 uno::Any SAL_CALL
185 SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException)
187 sal_Bool bRes = sal_False;
188 SwVbaFont_BASE::getStrikethrough() >>= bRes;
189 if ( bRes )
190 return aLongAnyTrue;
191 return aLongAnyFalse;
194 uno::Any SAL_CALL
195 SwVbaFont::getShadow() throw (uno::RuntimeException)
197 sal_Bool bRes = sal_False;
198 SwVbaFont_BASE::getShadow() >>= bRes;
199 if ( bRes )
200 return aLongAnyTrue;
201 return aLongAnyFalse;
204 uno::Sequence< rtl::OUString >
205 SwVbaFont::getServiceNames()
207 static uno::Sequence< rtl::OUString > aServiceNames;
208 if ( aServiceNames.getLength() == 0 )
210 aServiceNames.realloc( 1 );
211 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Font" ) );
213 return aServiceNames;