android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbafont.cxx
blob91a31ec66470aa522ee68e94ec2bf9d35797fb4c
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 "vbafont.hxx"
21 #include <com/sun/star/awt/FontUnderline.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XIndexAccess.hpp>
24 #include <ooo/vba/word/WdUnderline.hpp>
25 #include <sal/macros.h>
26 #include <unordered_map>
28 using namespace ::ooo::vba;
29 using namespace ::com::sun::star;
31 const uno::Any aLongAnyTrue( sal_Int16(-1) );
32 const uno::Any aLongAnyFalse( sal_Int16( 0 ) );
34 namespace {
36 struct MapPair
38 sal_Int32 nMSOConst;
39 sal_Int32 nOOOConst;
44 MapPair const UnderLineTable[] = {
45 { word::WdUnderline::wdUnderlineNone, css::awt::FontUnderline::NONE },
46 { word::WdUnderline::wdUnderlineSingle, css::awt::FontUnderline::SINGLE },
47 { word::WdUnderline::wdUnderlineWords, css::awt::FontUnderline::SINGLE },
48 { word::WdUnderline::wdUnderlineDouble, css::awt::FontUnderline::DOUBLE },
49 { word::WdUnderline::wdUnderlineDotted, css::awt::FontUnderline::DOTTED },
50 { word::WdUnderline::wdUnderlineThick, css::awt::FontUnderline::BOLDDASH },
51 { word::WdUnderline::wdUnderlineDash, css::awt::FontUnderline::DASH },
52 { word::WdUnderline::wdUnderlineDotDash, css::awt::FontUnderline::DASHDOT },
53 { word::WdUnderline::wdUnderlineDotDotDash, css::awt::FontUnderline::DASHDOTDOT },
54 { word::WdUnderline::wdUnderlineWavy, css::awt::FontUnderline::WAVE },
55 { word::WdUnderline::wdUnderlineDottedHeavy, css::awt::FontUnderline::BOLDDOTTED },
56 { word::WdUnderline::wdUnderlineDashHeavy, css::awt::FontUnderline::BOLDDASH },
57 { word::WdUnderline::wdUnderlineDotDashHeavy, css::awt::FontUnderline::BOLDDASHDOT },
58 { word::WdUnderline::wdUnderlineDotDotDashHeavy, css::awt::FontUnderline::BOLDDASHDOTDOT },
59 { word::WdUnderline::wdUnderlineWavyHeavy, css::awt::FontUnderline::BOLDWAVE },
60 { word::WdUnderline::wdUnderlineDashLong, css::awt::FontUnderline::LONGDASH },
61 { word::WdUnderline::wdUnderlineWavyDouble, css::awt::FontUnderline::DOUBLEWAVE },
62 { word::WdUnderline::wdUnderlineDashLongHeavy, css::awt::FontUnderline::BOLDLONGDASH },
65 typedef std::unordered_map< sal_Int32, sal_Int32 > ConstToConst;
67 namespace {
69 class UnderLineMapper
71 ConstToConst m_MSO2OOO;
72 ConstToConst m_OOO2MSO;
73 private:
74 UnderLineMapper()
76 for ( auto const & index: UnderLineTable )
78 m_MSO2OOO[ index.nMSOConst ] = index.nOOOConst;
79 m_OOO2MSO[ index.nOOOConst ] = index.nMSOConst;
82 public:
83 static OUString propName()
85 return "CharUnderline";
88 static UnderLineMapper& instance()
90 static UnderLineMapper theMapper;
91 return theMapper;
94 /// @throws lang::IllegalArgumentException
95 sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst )
97 ConstToConst::iterator it = m_MSO2OOO.find( nMSOConst );
98 if ( it == m_MSO2OOO.end() )
99 throw lang::IllegalArgumentException();
100 return it->second;
102 /// @throws lang::IllegalArgumentException
103 sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst )
105 ConstToConst::iterator it = m_OOO2MSO.find( nOOOConst );
106 if ( it == m_OOO2MSO.end() )
107 throw lang::IllegalArgumentException();
108 return it->second;
114 SwVbaFont::SwVbaFont( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPalette, uno::Reference< css::beans::XPropertySet > const & xPropertySet )
115 : SwVbaFont_BASE( xParent, xContext, xPalette, xPropertySet, Component::WORD )
119 uno::Any SAL_CALL
120 SwVbaFont::getUnderline()
122 sal_Int32 nOOVal = 0;
123 mxFont->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal;
124 return uno::Any( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
127 void SAL_CALL
128 SwVbaFont::setUnderline( const uno::Any& _underline )
130 sal_Int32 nMSOVal = 0;
132 if ( _underline >>= nMSOVal )
134 sal_Int32 nOOVal = UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
135 mxFont->setPropertyValue( UnderLineMapper::propName(), uno::Any( nOOVal ) );
139 OUString
140 SwVbaFont::getServiceImplName()
142 return "SwVbaFont";
145 uno::Any SAL_CALL
146 SwVbaFont::getColorIndex()
148 sal_Int32 nColor = 0;
150 getColor() >>= nColor;
151 sal_Int32 nElems = mxPalette->getCount();
152 sal_Int32 nIndex = 0;
153 for ( sal_Int32 count=0; count<nElems; ++count )
155 sal_Int32 nPaletteColor = 0;
156 mxPalette->getByIndex( count ) >>= nPaletteColor;
157 if ( nPaletteColor == nColor )
159 nIndex = count;
160 break;
163 return uno::Any( nIndex );
165 uno::Any SAL_CALL
166 SwVbaFont::getSubscript()
168 bool bRes = false;
169 SwVbaFont_BASE::getSubscript() >>= bRes;
170 if ( bRes )
171 return aLongAnyTrue;
172 return aLongAnyFalse;
175 uno::Any SAL_CALL
176 SwVbaFont::getSuperscript()
178 bool bRes = false;
179 SwVbaFont_BASE::getSuperscript() >>= bRes;
180 if ( bRes )
181 return aLongAnyTrue;
182 return aLongAnyFalse;
185 uno::Any SAL_CALL
186 SwVbaFont::getBold()
188 bool bRes = false;
189 SwVbaFont_BASE::getBold() >>= bRes;
190 if ( bRes )
191 return aLongAnyTrue;
192 return aLongAnyFalse;
195 uno::Any SAL_CALL
196 SwVbaFont::getItalic()
198 bool bRes = false;
199 SwVbaFont_BASE::getItalic() >>= bRes;
200 if ( bRes )
201 return aLongAnyTrue;
202 return aLongAnyFalse;
205 uno::Any SAL_CALL
206 SwVbaFont::getStrikethrough()
208 bool bRes = false;
209 SwVbaFont_BASE::getStrikethrough() >>= bRes;
210 if ( bRes )
211 return aLongAnyTrue;
212 return aLongAnyFalse;
215 uno::Any SAL_CALL
216 SwVbaFont::getShadow()
218 bool bRes = false;
219 SwVbaFont_BASE::getShadow() >>= bRes;
220 if ( bRes )
221 return aLongAnyTrue;
222 return aLongAnyFalse;
225 uno::Sequence< OUString >
226 SwVbaFont::getServiceNames()
228 static uno::Sequence< OUString > const aServiceNames
230 "ooo.vba.word.Font"
232 return aServiceNames;
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */