2 #include <com/sun/star/awt/FontUnderline.hpp>
3 #include <ooo/vba/word/WdUnderline.hpp>
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 ) );
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
;
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
;
57 static rtl::OUString
propName()
59 static rtl::OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("CharUnderline") );
63 static UnderLineMapper
& instance()
65 static UnderLineMapper 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();
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();
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
)
90 SwVbaFont::getUnderline() throw (uno::RuntimeException
)
93 mxFont
->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal
;
94 return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal
) );
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
) );
110 SwVbaFont::getServiceImplName()
112 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFont") );
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
)) );
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
)
142 return uno::makeAny( nIndex
);
145 SwVbaFont::getSubscript() throw ( uno::RuntimeException
)
147 sal_Bool bRes
= sal_False
;
148 SwVbaFont_BASE::getSubscript() >>= bRes
;
151 return aLongAnyFalse
;
155 SwVbaFont::getSuperscript() throw ( uno::RuntimeException
)
157 sal_Bool bRes
= sal_False
;
158 SwVbaFont_BASE::getSuperscript() >>= bRes
;
161 return aLongAnyFalse
;
165 SwVbaFont::getBold() throw (uno::RuntimeException
)
167 sal_Bool bRes
= sal_False
;
168 SwVbaFont_BASE::getBold() >>= bRes
;
171 return aLongAnyFalse
;
175 SwVbaFont::getItalic() throw (uno::RuntimeException
)
177 sal_Bool bRes
= sal_False
;
178 SwVbaFont_BASE::getItalic() >>= bRes
;
181 return aLongAnyFalse
;
185 SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException
)
187 sal_Bool bRes
= sal_False
;
188 SwVbaFont_BASE::getStrikethrough() >>= bRes
;
191 return aLongAnyFalse
;
195 SwVbaFont::getShadow() throw (uno::RuntimeException
)
197 sal_Bool bRes
= sal_False
;
198 SwVbaFont_BASE::getShadow() >>= bRes
;
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
;