LibreOffice Module vbahelper (master) 1
vbafontbase.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/beans/XPropertySet.hpp>
21#include <com/sun/star/container/XIndexAccess.hpp>
22#include <com/sun/star/awt/FontWeight.hpp>
23#include <com/sun/star/awt/FontStrikeout.hpp>
24#include <com/sun/star/awt/FontSlant.hpp>
26
27using namespace ::ooo::vba;
28using namespace ::com::sun::star;
29
30
31// form controls use other property name as the remaining OOo API
32#define VBAFONTBASE_PROPNAME( ascii_normal, ascii_control ) \
33 mbFormControl ? OUString( ascii_control ) : OUString( ascii_normal )
34
36 const uno::Reference< XHelperInterface >& xParent,
37 const uno::Reference< uno::XComponentContext >& xContext,
38 const uno::Reference< css::container::XIndexAccess >& xPalette,
39 const uno::Reference< beans::XPropertySet >& xPropertySet,
40 Component eWhich,
41 bool bFormControl ) :
42 VbaFontBase_BASE( xParent, xContext ),
43 mxFont( xPropertySet, uno::UNO_SET_THROW ),
44 mxPalette( xPalette, uno::UNO_SET_THROW ),
45 meWhich( eWhich ),
46 mbFormControl( bFormControl )
47{
48}
49
51{
52}
53
54void SAL_CALL
56{
57 // not supported in form controls
58 if( mbFormControl )
59 return;
60
61 bool bValue = false;
62 aValue >>= bValue;
63 sal_Int16 nValue = NORMAL;
64 sal_Int8 nValue2 = NORMALHEIGHT;
65
66 if( bValue )
67 {
69 nValue2 = SUPERSCRIPTHEIGHT;
70 }
71 mxFont->setPropertyValue( "CharEscapement" , uno::Any(nValue) );
72 mxFont->setPropertyValue( "CharEscapementHeight" , uno::Any(nValue2) );
73}
74
75uno::Any SAL_CALL
77{
78 short nValue = NORMAL;
79 // not supported in form controls
80 if( !mbFormControl )
81 mxFont->getPropertyValue( "CharEscapement" ) >>= nValue;
82 return uno::Any( nValue == SUPERSCRIPT );
83}
84
85void SAL_CALL
87{
88 // not supported in form controls
89 if( mbFormControl )
90 return;
91
92 bool bValue = false;
93 aValue >>= bValue;
94 sal_Int16 nValue = NORMAL;
95 sal_Int8 nValue2 = NORMALHEIGHT;
96
97 if( bValue )
98 {
100 nValue2 = SUBSCRIPTHEIGHT;
101 }
102
103 mxFont->setPropertyValue( "CharEscapementHeight" , uno::Any(nValue2) );
104 mxFont->setPropertyValue( "CharEscapement" , uno::Any(nValue) );
105
106}
107
108uno::Any SAL_CALL
110{
111 short nValue = NORMAL;
112 // not supported in form controls
113 if( !mbFormControl )
114 mxFont->getPropertyValue( "CharEscapement" ) >>= nValue;
115 return uno::Any( nValue == SUBSCRIPT );
116}
117
118void SAL_CALL
120{
121 // form controls need a sal_Int16 containing points, other APIs need a float
122 uno::Any aVal( aValue );
123 if( mbFormControl )
124 {
125 float fVal = 0.0;
126 aVal >>= fVal;
127 aVal <<= static_cast< sal_Int16 >( fVal );
128 }
129 mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharHeight", "FontHeight" ), aVal );
130}
131
132uno::Any SAL_CALL
134{
135 return mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharHeight", "FontHeight" ) );
136}
137
138void SAL_CALL
140{
141 sal_Int32 nIndex = 0;
142 _colorindex >>= nIndex;
143
144 --nIndex; // OOo indices are zero bases
145
146 if (meWhich == EXCEL){
147 setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
148 }
149 else{
150 setColor( mxPalette->getByIndex( nIndex ));
151 }
152}
153
154
155uno::Any SAL_CALL
157{
158 sal_Int32 nColor = 0;
159
160 if (meWhich == EXCEL){
161 XLRGBToOORGB( getColor() ) >>= nColor;
162 }
163 else{
164 getColor() >>= nColor;
165 }
166
167 sal_Int32 nElems = mxPalette->getCount();
168 sal_Int32 nIndex = -1;
169 for ( sal_Int32 count=0; count<nElems; ++count )
170 {
171 sal_Int32 nPaletteColor = 0;
172 mxPalette->getByIndex( count ) >>= nPaletteColor;
173 if ( nPaletteColor == nColor )
174 {
175 nIndex = count + 1; // 1 based
176 break;
177 }
178 }
179 return uno::Any( nIndex );
180}
181
182void SAL_CALL
184{
185 bool bValue = false;
186 aValue >>= bValue;
187 double fBoldValue = awt::FontWeight::NORMAL;
188 if( bValue )
189 fBoldValue = awt::FontWeight::BOLD;
190 mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharWeight", "FontWeight" ), uno::Any( fBoldValue ) );
191
192}
193
194uno::Any SAL_CALL
196{
197 double fValue = 0.0;
198 mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharWeight", "FontWeight" ) ) >>= fValue;
199 return uno::Any( fValue == awt::FontWeight::BOLD );
200}
201
202void SAL_CALL
204{
205 bool bValue = false;
206 aValue >>= bValue;
207 short nValue = awt::FontStrikeout::NONE;
208 if( bValue )
209 nValue = awt::FontStrikeout::SINGLE;
210 mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharStrikeout", "FontStrikeout" ), uno::Any( nValue ) );
211}
212
213uno::Any SAL_CALL
215{
216 short nValue = 0;
217 mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharStrikeout", "FontStrikeout" ) ) >>= nValue;
218 return uno::Any( nValue == awt::FontStrikeout::SINGLE );
219}
220
221void SAL_CALL
223{
224 if( !mbFormControl )
225 mxFont->setPropertyValue( "CharShadowed" , aValue );
226}
227
228uno::Any SAL_CALL
230{
231 return mbFormControl ? uno::Any( false ) : mxFont->getPropertyValue( "CharShadowed" );
232}
233
234void SAL_CALL
236{
237 bool bValue = false;
238 aValue >>= bValue;
239 awt::FontSlant nValue = awt::FontSlant_NONE;
240 if( bValue )
241 nValue = awt::FontSlant_ITALIC;
242 mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharPosture", "FontSlant" ), uno::Any( static_cast<short>(nValue) ) );
243}
244
245uno::Any SAL_CALL
247{
248 awt::FontSlant aFS;
249 mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharPosture", "FontSlant" ) ) >>= aFS;
250 return uno::Any( aFS == awt::FontSlant_ITALIC );
251}
252
253void SAL_CALL
255{
256 OUString sString;
257 aValue >>= sString;
258 mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharFontName", "FontName" ), aValue );
259}
260
261uno::Any SAL_CALL
263{
264 return mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharFontName", "FontName" ) );
265}
266
269{
270 if (meWhich == EXCEL){
271 uno::Any aAny = OORGBToXLRGB( mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ) ) );
272 return aAny;
273 }
274 else{
275 uno::Any aAny = mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ) );
276 return aAny;
277 }
278}
279
280void
282{
283 mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ), XLRGBToOORGB(_color) );
284}
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setSize(const css::uno::Any &_size) override
static const short SUPERSCRIPT
Definition: vbafontbase.hxx:66
static const short NORMAL
Definition: vbafontbase.hxx:63
virtual css::uno::Any SAL_CALL getSubscript() override
static const sal_Int8 SUPERSCRIPTHEIGHT
Definition: vbafontbase.hxx:72
static const short SUBSCRIPT
Definition: vbafontbase.hxx:69
virtual css::uno::Any SAL_CALL getName() override
Component meWhich
Definition: vbafontbase.hxx:53
virtual css::uno::Any SAL_CALL getItalic() override
virtual css::uno::Any SAL_CALL getColor() override
virtual void SAL_CALL setColor(const css::uno::Any &_color) override
virtual ~VbaFontBase() override
Definition: vbafontbase.cxx:50
virtual void SAL_CALL setSubscript(const css::uno::Any &_subscript) override
Definition: vbafontbase.cxx:86
virtual void SAL_CALL setName(const css::uno::Any &_name) override
virtual void SAL_CALL setColorIndex(const css::uno::Any &_colorindex) override
virtual css::uno::Any SAL_CALL getSuperscript() override
Definition: vbafontbase.cxx:76
virtual css::uno::Any SAL_CALL getColorIndex() override
VbaFontBase(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xPalette, const css::uno::Reference< css::beans::XPropertySet > &xPropertySet, Component eWhich, bool bFormControl=false)
Definition: vbafontbase.cxx:35
virtual css::uno::Any SAL_CALL getSize() override
virtual void SAL_CALL setSuperscript(const css::uno::Any &_superscript) override
Definition: vbafontbase.cxx:55
virtual css::uno::Any SAL_CALL getShadow() override
virtual void SAL_CALL setBold(const css::uno::Any &_bold) override
virtual css::uno::Any SAL_CALL getStrikethrough() override
virtual void SAL_CALL setStrikethrough(const css::uno::Any &_strikethrough) override
css::uno::Reference< css::beans::XPropertySet > mxFont
Definition: vbafontbase.hxx:51
virtual void SAL_CALL setShadow(const css::uno::Any &_shadow) override
virtual void SAL_CALL setItalic(const css::uno::Any &_italic) override
virtual css::uno::Any SAL_CALL getBold() override
css::uno::Reference< css::container::XIndexAccess > mxPalette
Definition: vbafontbase.hxx:52
static const short NORMALHEIGHT
Definition: vbafontbase.hxx:78
bool mbFormControl
Definition: vbafontbase.hxx:54
static const sal_Int8 SUBSCRIPTHEIGHT
Definition: vbafontbase.hxx:75
sal_Int16 nValue
sal_Int32 nIndex
sal_Int32 XLRGBToOORGB(sal_Int32 nCol)
Definition: vbahelper.cxx:306
sal_Int32 OORGBToXLRGB(sal_Int32 nCol)
Definition: vbahelper.cxx:289
uno::Reference< rendering::XCanvasFont > mxFont
signed char sal_Int8
#define VBAFONTBASE_PROPNAME(ascii_normal, ascii_control)
Definition: vbafontbase.cxx:32