LibreOffice Module sc (master) 1
vbafont.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
20#include <com/sun/star/awt/FontUnderline.hpp>
21#include <ooo/vba/excel/XlColorIndex.hpp>
22#include <ooo/vba/excel/XlUnderlineStyle.hpp>
23#include <svl/itemset.hxx>
24#include <o3tl/string_view.hxx>
25#include "excelvbahelper.hxx"
26#include "vbafont.hxx"
27#include "vbapalette.hxx"
28#include <scitems.hxx>
29#include <cellsuno.hxx>
30
31using namespace ::ooo::vba;
32using namespace ::com::sun::star;
33
35 const uno::Reference< XHelperInterface >& xParent,
36 const uno::Reference< uno::XComponentContext >& xContext,
37 const ScVbaPalette& dPalette,
38 const uno::Reference< beans::XPropertySet >& xPropertySet,
39 ScCellRangeObj* pRangeObj, bool bFormControl ) :
40 ScVbaFont_BASE( xParent, xContext, dPalette.getPalette(), xPropertySet, Component::EXCEL, bFormControl ),
41 mpRangeObj( pRangeObj )
42{
43}
44
47{
48 return mpRangeObj ? excel::ScVbaCellRangeAccess::GetDataSet( mpRangeObj ) : nullptr;
49}
50
52{
53}
54
55uno::Any SAL_CALL
57{
58 if ( GetDataSet() )
59 if ( GetDataSet()->GetItemState( ATTR_FONT_HEIGHT) == SfxItemState::DONTCARE )
60 return aNULL();
61 return ScVbaFont_BASE::getSize();
62}
63
64void SAL_CALL
66{
67 if(mbFormControl)
68 return;
69
70 sal_Int32 nIndex = 0;
71 _colorindex >>= nIndex;
72 // #FIXME xlColorIndexAutomatic & xlColorIndexNone are not really
73 // handled properly here
74
75 if ( !nIndex || ( nIndex == excel::XlColorIndex::xlColorIndexAutomatic ) )
76 {
77 nIndex = 1; // check default ( assume black )
78 ScVbaFont_BASE::setColorIndex( uno::Any( nIndex ) );
79 }
80 else
81 ScVbaFont_BASE::setColorIndex( _colorindex );
82}
83
84uno::Any SAL_CALL
86{
87 if(mbFormControl)
88 return uno::Any( sal_Int32(0) );
89 if ( GetDataSet() )
90 if ( GetDataSet()->GetItemState( ATTR_FONT_COLOR) == SfxItemState::DONTCARE )
91 return aNULL();
92 return ScVbaFont_BASE::getColorIndex();
93}
94
95void SAL_CALL
97{
98//XXX #TODO# #FIXME#
99 //mxFont->setPropertyValue("CharSize", ( uno::Any )fValue );
100 throw uno::RuntimeException(
101 "setStandardFontSize not supported" );
102}
103
104uno::Any SAL_CALL
106{
107//XXX #TODO# #FIXME#
108 throw uno::RuntimeException( "getStandardFontSize not supported" );
109 // return uno::Any();
110}
111
112void SAL_CALL
114{
115//XXX #TODO# #FIXME#
116 throw uno::RuntimeException("setStandardFont not supported" );
117}
118
119uno::Any SAL_CALL
121{
122//XXX #TODO# #FIXME#
123 throw uno::RuntimeException("getStandardFont not supported");
124 // return uno::Any();
125}
126
127void SAL_CALL
129{
130 bool bBold = false;
131 bool bItalic = false;
132
133 OUString aStyles;
134 aValue >>= aStyles;
135
136 for (sal_Int32 nIdx{ 0 }; nIdx>=0; )
137 {
138 const std::u16string_view aToken{ o3tl::getToken(aStyles, 0, ' ', nIdx ) };
139 if (o3tl::equalsIgnoreAsciiCase(aToken, u"Bold"))
140 {
141 bBold = true;
142 if (bItalic)
143 break;
144 }
145 else if (o3tl::equalsIgnoreAsciiCase(aToken, u"Italic"))
146 {
147 bItalic = true;
148 if (bBold)
149 break;
150 }
151 }
152
153 setBold( uno::Any( bBold ) );
154 setItalic( uno::Any( bItalic ) );
155}
156
157uno::Any SAL_CALL
159{
160 OUStringBuffer aStyles;
161 bool bValue = false;
162 getBold() >>= bValue;
163 if( bValue )
164 aStyles.append("Bold");
165
166 getItalic() >>= bValue;
167 if( bValue )
168 {
169 if( !aStyles.isEmpty() )
170 aStyles.append(" ");
171 aStyles.append("Italic");
172 }
173 return uno::Any( aStyles.makeStringAndClear() );
174}
175
176uno::Any SAL_CALL
178{
179 if ( GetDataSet() )
180 if ( GetDataSet()->GetItemState( ATTR_FONT_WEIGHT) == SfxItemState::DONTCARE )
181 return aNULL();
182 return ScVbaFont_BASE::getBold();
183}
184
185void SAL_CALL
187{
188 if(mbFormControl)
189 return;
190
191 // default
192 sal_Int32 nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone;
193 aValue >>= nValue;
194 switch ( nValue )
195 {
196// NOTE:: #TODO #FIMXE
197// xlUnderlineStyleDoubleAccounting & xlUnderlineStyleSingleAccounting
198// don't seem to be supported in Openoffice.
199// The import filter converts them to single or double underlines as appropriate
200// So, here at the moment we are similarly silently converting
201// xlUnderlineStyleSingleAccounting to xlUnderlineStyleSingle.
202
203 case excel::XlUnderlineStyle::xlUnderlineStyleNone:
205 break;
206 case excel::XlUnderlineStyle::xlUnderlineStyleSingle:
207 case excel::XlUnderlineStyle::xlUnderlineStyleSingleAccounting:
208 nValue = awt::FontUnderline::SINGLE;
209 break;
210 case excel::XlUnderlineStyle::xlUnderlineStyleDouble:
211 case excel::XlUnderlineStyle::xlUnderlineStyleDoubleAccounting:
212 nValue = awt::FontUnderline::DOUBLE;
213 break;
214 default:
215 throw uno::RuntimeException("Unknown value for Underline" );
216 }
217
218 mxFont->setPropertyValue("CharUnderline", uno::Any(nValue) );
219
220}
221
222uno::Any SAL_CALL
224{
225 if ( GetDataSet() )
226 if ( GetDataSet()->GetItemState( ATTR_FONT_UNDERLINE) == SfxItemState::DONTCARE )
227 return aNULL();
228
230
231 if(mbFormControl)
232 return uno::Any( nValue );
233
234 mxFont->getPropertyValue("CharUnderline") >>= nValue;
235 switch ( nValue )
236 {
237 case awt::FontUnderline::DOUBLE:
238 nValue = excel::XlUnderlineStyle::xlUnderlineStyleDouble;
239 break;
240 case awt::FontUnderline::SINGLE:
241 nValue = excel::XlUnderlineStyle::xlUnderlineStyleSingle;
242 break;
244 nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone;
245 break;
246 default:
247 throw uno::RuntimeException("Unknown value retrieved for Underline" );
248
249 }
250 return uno::Any( nValue );
251}
252
253uno::Any SAL_CALL
255{
256 if ( GetDataSet() )
257 if ( GetDataSet()->GetItemState( ATTR_FONT_CROSSEDOUT) == SfxItemState::DONTCARE )
258 return aNULL();
259 return ScVbaFont_BASE::getStrikethrough();
260}
261
262uno::Any SAL_CALL
264{
265 if ( GetDataSet() )
266 if ( GetDataSet()->GetItemState( ATTR_FONT_SHADOWED) == SfxItemState::DONTCARE )
267 return aNULL();
268 return ScVbaFont_BASE::getShadow();
269}
270
271uno::Any SAL_CALL
273{
274 if ( GetDataSet() )
275 if ( GetDataSet()->GetItemState( ATTR_FONT_POSTURE) == SfxItemState::DONTCARE )
276 return aNULL();
277
278 return ScVbaFont_BASE::getItalic();
279}
280
281uno::Any SAL_CALL
283{
284 if ( GetDataSet() )
285 if ( GetDataSet()->GetItemState( ATTR_FONT) == SfxItemState::DONTCARE )
286 return aNULL();
287 return ScVbaFont_BASE::getName();
288}
291{
292 // #TODO #FIXME - behave like getXXX above ( wrt. GetDataSet )
293 uno::Any aAny = OORGBToXLRGB( mxFont->getPropertyValue("CharColor") );
294 return aAny;
295}
296
297void SAL_CALL
299{
300 if(!mbFormControl)
301 mxFont->setPropertyValue("CharContoured", aValue );
302}
303
304uno::Any SAL_CALL
306{
307 if ( GetDataSet() )
308 if ( GetDataSet()->GetItemState( ATTR_FONT_CONTOUR) == SfxItemState::DONTCARE )
309 return aNULL();
310 return mbFormControl ? uno::Any( false ) : mxFont->getPropertyValue("CharContoured");
311}
312
313OUString
315{
316 return "ScVbaFont";
317}
318
319uno::Sequence< OUString >
321{
322 static uno::Sequence< OUString > const aServiceNames
323 {
324 "ooo.vba.excel.Font"
325 };
326 return aServiceNames;
327}
328
329/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Any SAL_CALL getColorIndex() override
Definition: vbafont.cxx:85
virtual void SAL_CALL setUnderline(const css::uno::Any &_underline) override
Definition: vbafont.cxx:186
virtual css::uno::Any SAL_CALL getStrikethrough() override
Definition: vbafont.cxx:254
virtual css::uno::Any SAL_CALL getFontStyle() override
Definition: vbafont.cxx:158
virtual css::uno::Any SAL_CALL getShadow() override
Definition: vbafont.cxx:263
virtual OUString getServiceImplName() override
Definition: vbafont.cxx:314
SfxItemSet * GetDataSet()
Definition: vbafont.cxx:46
virtual css::uno::Any SAL_CALL getStandardFont() override
Definition: vbafont.cxx:120
virtual css::uno::Any SAL_CALL getUnderline() override
Definition: vbafont.cxx:223
virtual css::uno::Any SAL_CALL getOutlineFont() override
Definition: vbafont.cxx:305
virtual css::uno::Any SAL_CALL getColor() override
Definition: vbafont.cxx:290
virtual css::uno::Any SAL_CALL getStandardFontSize() override
Definition: vbafont.cxx:105
virtual void SAL_CALL setStandardFontSize(const css::uno::Any &_standardfontsize) override
Definition: vbafont.cxx:96
virtual void SAL_CALL setFontStyle(const css::uno::Any &_fontstyle) override
Definition: vbafont.cxx:128
virtual ~ScVbaFont() override
Definition: vbafont.cxx:51
virtual void SAL_CALL setColorIndex(const css::uno::Any &_colorindex) override
Definition: vbafont.cxx:65
ScCellRangeObj * mpRangeObj
Definition: vbafont.hxx:39
virtual css::uno::Any SAL_CALL getBold() override
Definition: vbafont.cxx:177
virtual css::uno::Any SAL_CALL getItalic() override
Definition: vbafont.cxx:272
virtual css::uno::Any SAL_CALL getSize() override
Definition: vbafont.cxx:56
virtual void SAL_CALL setOutlineFont(const css::uno::Any &_outlinefont) override
Definition: vbafont.cxx:298
virtual css::uno::Any SAL_CALL getName() override
Definition: vbafont.cxx:282
ScVbaFont(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const ScVbaPalette &dPalette, const css::uno::Reference< css::beans::XPropertySet > &xPropertySet, ScCellRangeObj *pRangeObj=nullptr, bool bFormControl=false)
Definition: vbafont.cxx:34
virtual void SAL_CALL setStandardFont(const css::uno::Any &_standardfont) override
Definition: vbafont.cxx:113
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbafont.cxx:320
float u
Sequence< OUString > aServiceNames
sal_Int16 nValue
sal_Int32 nIndex
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
const uno::Any & aNULL()
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
constexpr TypedWhichId< SvxShadowedItem > ATTR_FONT_SHADOWED(108)
constexpr TypedWhichId< SvxContourItem > ATTR_FONT_CONTOUR(107)
constexpr TypedWhichId< SvxCrossedOutItem > ATTR_FONT_CROSSEDOUT(106)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
uno::Reference< rendering::XCanvasFont > mxFont
::std::pair< MetaAction *, int > Component
cppu::ImplInheritanceHelper< VbaFontBase, ov::excel::XFont > ScVbaFont_BASE
Definition: vbafont.hxx:33