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