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