xref: /AOO41X/main/sc/source/ui/vba/vbafont.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include <com/sun/star/beans/XProperty.hpp>
28*cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp>
29*cdf0e10cSrcweir #include <com/sun/star/awt/FontUnderline.hpp>
30*cdf0e10cSrcweir #include <com/sun/star/awt/FontStrikeout.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/text/XSimpleText.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/table/XCell.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/table/XColumnRowRange.hpp>
36*cdf0e10cSrcweir #include <ooo/vba/excel/XlColorIndex.hpp>
37*cdf0e10cSrcweir #include <ooo/vba/excel/XlUnderlineStyle.hpp>
38*cdf0e10cSrcweir #include <svl/itemset.hxx>
39*cdf0e10cSrcweir #include "excelvbahelper.hxx"
40*cdf0e10cSrcweir #include "vbafont.hxx"
41*cdf0e10cSrcweir #include "scitems.hxx"
42*cdf0e10cSrcweir #include "cellsuno.hxx"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::ooo::vba;
45*cdf0e10cSrcweir using namespace ::com::sun::star;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir ScVbaFont::ScVbaFont(
48*cdf0e10cSrcweir         const uno::Reference< XHelperInterface >& xParent,
49*cdf0e10cSrcweir         const uno::Reference< uno::XComponentContext >& xContext,
50*cdf0e10cSrcweir         const ScVbaPalette& dPalette,
51*cdf0e10cSrcweir         const uno::Reference< beans::XPropertySet >& xPropertySet,
52*cdf0e10cSrcweir         ScCellRangeObj* pRangeObj, bool bFormControl ) throw ( uno::RuntimeException ) :
53*cdf0e10cSrcweir     ScVbaFont_BASE( xParent, xContext, dPalette.getPalette(), xPropertySet, bFormControl ),
54*cdf0e10cSrcweir     mPalette( dPalette ),
55*cdf0e10cSrcweir     mpRangeObj( pRangeObj )
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir SfxItemSet*
60*cdf0e10cSrcweir ScVbaFont::GetDataSet()
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     return mpRangeObj ? excel::ScVbaCellRangeAccess::GetDataSet( mpRangeObj ) : 0;
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir ScVbaFont::~ScVbaFont()
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > lcl_TextProperties( uno::Reference< table::XCell >& xIf ) throw ( uno::RuntimeException )
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir 	uno::Reference< text::XTextRange > xTxtRange( xIf, uno::UNO_QUERY_THROW );
73*cdf0e10cSrcweir 	uno::Reference< text::XSimpleText > xTxt( xTxtRange->getText(), uno::UNO_QUERY_THROW ) ;
74*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps( xTxt->createTextCursor(), uno::UNO_QUERY_THROW );
75*cdf0e10cSrcweir 	return xProps;
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir void SAL_CALL
78*cdf0e10cSrcweir ScVbaFont::setSuperscript( const uno::Any& aValue ) throw ( uno::RuntimeException )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	// #FIXEME create some sort of generic get/set code where
81*cdf0e10cSrcweir 	// you can pass a functor
82*cdf0e10cSrcweir 	// get/set - Super/sub script code is exactly the same
83*cdf0e10cSrcweir 	// except for the call applied at each cell position
84*cdf0e10cSrcweir         uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY );
85*cdf0e10cSrcweir         uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY );
86*cdf0e10cSrcweir 	if ( !xCell.is() )
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW );
89*cdf0e10cSrcweir 		sal_Int32 nCols = xColumnRowRange->getColumns()->getCount();
90*cdf0e10cSrcweir 		sal_Int32 nRows = xColumnRowRange->getRows()->getCount();
91*cdf0e10cSrcweir 		for ( sal_Int32 col = 0; col < nCols; ++col )
92*cdf0e10cSrcweir 		{
93*cdf0e10cSrcweir 			for ( sal_Int32 row = 0; row < nRows; ++row )
94*cdf0e10cSrcweir 			{
95*cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ) , uno::UNO_QUERY_THROW );
96*cdf0e10cSrcweir 				ScVbaFont aFont( getParent(), mxContext, mPalette, xProps );
97*cdf0e10cSrcweir 				aFont.setSuperscript( aValue );
98*cdf0e10cSrcweir 			}
99*cdf0e10cSrcweir 		}
100*cdf0e10cSrcweir 		return;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir         xCell.set( xCellRange->getCellByPosition( 0,0 ) );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell );
106*cdf0e10cSrcweir 	sal_Bool bValue = sal_False;
107*cdf0e10cSrcweir 	aValue >>= bValue;
108*cdf0e10cSrcweir 	sal_Int16 nValue = NORMAL;
109*cdf0e10cSrcweir 	sal_Int8 nValue2 = NORMALHEIGHT;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         if( bValue )
112*cdf0e10cSrcweir 	{
113*cdf0e10cSrcweir 		nValue = SUPERSCRIPT;
114*cdf0e10cSrcweir 	        nValue2 = SUPERSCRIPTHEIGHT;
115*cdf0e10cSrcweir 	}
116*cdf0e10cSrcweir 	xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ), ( uno::Any )nValue );
117*cdf0e10cSrcweir  	xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapementHeight" ) ), ( uno::Any )nValue2 );
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir uno::Any SAL_CALL
121*cdf0e10cSrcweir ScVbaFont::getSuperscript() throw ( uno::RuntimeException )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir         uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY );
124*cdf0e10cSrcweir         uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY );
125*cdf0e10cSrcweir 	if ( !xCell.is() )
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 		uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW );
128*cdf0e10cSrcweir 		sal_Int32 nCols = xColumnRowRange->getColumns()->getCount();
129*cdf0e10cSrcweir 		sal_Int32 nRows = xColumnRowRange->getRows()->getCount();
130*cdf0e10cSrcweir 		uno::Any aRes;
131*cdf0e10cSrcweir 		for ( sal_Int32 col = 0; col < nCols; ++col )
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			for ( sal_Int32 row = 0; row < nRows; ++row )
134*cdf0e10cSrcweir 			{
135*cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ), uno::UNO_QUERY_THROW );
136*cdf0e10cSrcweir 				ScVbaFont aFont( getParent(), mxContext, mPalette, xProps );
137*cdf0e10cSrcweir 				if ( !col && !row )
138*cdf0e10cSrcweir 					aRes = aFont.getSuperscript();
139*cdf0e10cSrcweir 				else if ( aRes != aFont.getSuperscript() )
140*cdf0e10cSrcweir 					return aNULL();
141*cdf0e10cSrcweir 			}
142*cdf0e10cSrcweir 		}
143*cdf0e10cSrcweir 		return aRes;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	}
146*cdf0e10cSrcweir         xCell.set( xCellRange->getCellByPosition( 0,0 ) );
147*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell );
148*cdf0e10cSrcweir 	short nValue = 0;
149*cdf0e10cSrcweir 	xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ) ) >>= nValue;
150*cdf0e10cSrcweir 	return uno::makeAny( ( nValue == SUPERSCRIPT ) );
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir void SAL_CALL
154*cdf0e10cSrcweir ScVbaFont::setSubscript( const uno::Any& aValue ) throw ( uno::RuntimeException )
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir         uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY );
157*cdf0e10cSrcweir         uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY );
158*cdf0e10cSrcweir 	if ( !xCell.is() )
159*cdf0e10cSrcweir 	{
160*cdf0e10cSrcweir 		uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW );
161*cdf0e10cSrcweir 		sal_Int32 nCols = xColumnRowRange->getColumns()->getCount();
162*cdf0e10cSrcweir 		sal_Int32 nRows = xColumnRowRange->getRows()->getCount();
163*cdf0e10cSrcweir 		for ( sal_Int32 col = 0; col < nCols; ++col )
164*cdf0e10cSrcweir 		{
165*cdf0e10cSrcweir 			for ( sal_Int32 row = 0; row < nRows; ++row )
166*cdf0e10cSrcweir 			{
167*cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ) , uno::UNO_QUERY_THROW );
168*cdf0e10cSrcweir 				ScVbaFont aFont( getParent(), mxContext, mPalette, xProps );
169*cdf0e10cSrcweir 				aFont.setSubscript( aValue );
170*cdf0e10cSrcweir 			}
171*cdf0e10cSrcweir 		}
172*cdf0e10cSrcweir 		return;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	}
175*cdf0e10cSrcweir         xCell.set( xCellRange->getCellByPosition( 0,0 ) );
176*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	sal_Bool bValue = sal_False;
179*cdf0e10cSrcweir 	aValue >>= bValue;
180*cdf0e10cSrcweir 	sal_Int16 nValue = NORMAL;
181*cdf0e10cSrcweir 	sal_Int8 nValue2 = NORMALHEIGHT;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         if( bValue )
184*cdf0e10cSrcweir 	{
185*cdf0e10cSrcweir 		nValue= SUBSCRIPT;
186*cdf0e10cSrcweir 	        nValue2 = SUBSCRIPTHEIGHT;
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir  	xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapementHeight" ) ), ( uno::Any )nValue2 );
190*cdf0e10cSrcweir 	xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ), ( uno::Any )nValue );
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir uno::Any SAL_CALL
195*cdf0e10cSrcweir ScVbaFont::getSubscript() throw ( uno::RuntimeException )
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir         uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY );
198*cdf0e10cSrcweir         uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY );
199*cdf0e10cSrcweir 	if ( !xCell.is() )
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW );
202*cdf0e10cSrcweir 		sal_Int32 nCols = xColumnRowRange->getColumns()->getCount();
203*cdf0e10cSrcweir 		sal_Int32 nRows = xColumnRowRange->getRows()->getCount();
204*cdf0e10cSrcweir 		uno::Any aRes;
205*cdf0e10cSrcweir 		for ( sal_Int32 col = 0; col < nCols; ++col )
206*cdf0e10cSrcweir 		{
207*cdf0e10cSrcweir 			for ( sal_Int32 row = 0; row < nRows; ++row )
208*cdf0e10cSrcweir 			{
209*cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ), uno::UNO_QUERY_THROW );
210*cdf0e10cSrcweir 				ScVbaFont aFont( getParent(), mxContext, mPalette, xProps );
211*cdf0e10cSrcweir 				if ( !col && !row )
212*cdf0e10cSrcweir 					aRes = aFont.getSubscript();
213*cdf0e10cSrcweir 				else if ( aRes != aFont.getSubscript() )
214*cdf0e10cSrcweir 					return aNULL();
215*cdf0e10cSrcweir 			}
216*cdf0e10cSrcweir 		}
217*cdf0e10cSrcweir 		return aRes;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	}
220*cdf0e10cSrcweir         xCell.set( xCellRange->getCellByPosition( 0,0 ) );
221*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	short nValue = NORMAL;
224*cdf0e10cSrcweir 	xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ) ) >>= nValue;
225*cdf0e10cSrcweir 	return uno::makeAny( ( nValue == SUBSCRIPT ) );
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir uno::Any SAL_CALL
229*cdf0e10cSrcweir ScVbaFont::getSize() throw ( uno::RuntimeException )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir 	if ( GetDataSet() )
232*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_HEIGHT, sal_True, NULL) == SFX_ITEM_DONTCARE )
233*cdf0e10cSrcweir 			return aNULL();
234*cdf0e10cSrcweir         return ScVbaFont_BASE::getSize();
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir void SAL_CALL
238*cdf0e10cSrcweir ScVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
241*cdf0e10cSrcweir 	_colorindex >>= nIndex;
242*cdf0e10cSrcweir 	// #FIXME  xlColorIndexAutomatic & xlColorIndexNone are not really
243*cdf0e10cSrcweir 	// handled properly here
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	if ( !nIndex || ( nIndex == excel::XlColorIndex::xlColorIndexAutomatic ) )
246*cdf0e10cSrcweir         {
247*cdf0e10cSrcweir 		nIndex = 1;  // check defualt ( assume black )
248*cdf0e10cSrcweir                 ScVbaFont_BASE::setColorIndex( uno::makeAny( nIndex ) );
249*cdf0e10cSrcweir         }
250*cdf0e10cSrcweir         else
251*cdf0e10cSrcweir             ScVbaFont_BASE::setColorIndex( _colorindex );
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir uno::Any SAL_CALL
256*cdf0e10cSrcweir ScVbaFont::getColorIndex() throw ( uno::RuntimeException )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir 	if ( GetDataSet() )
259*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_COLOR, sal_True, NULL) == SFX_ITEM_DONTCARE )
260*cdf0e10cSrcweir 			return aNULL();
261*cdf0e10cSrcweir 	return ScVbaFont_BASE::getColorIndex();
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
265*cdf0e10cSrcweir void  SAL_CALL
266*cdf0e10cSrcweir ScVbaFont::setStandardFontSize( const uno::Any& /*aValue*/ ) throw( uno::RuntimeException )
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir //XXX #TODO# #FIXME#
269*cdf0e10cSrcweir 	//mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharSize" ) ), ( uno::Any )fValue );
270*cdf0e10cSrcweir 	throw uno::RuntimeException(
271*cdf0e10cSrcweir 		rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setStandardFontSize not supported") ), uno::Reference< uno::XInterface >() );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir uno::Any SAL_CALL
276*cdf0e10cSrcweir ScVbaFont::getStandardFontSize() throw ( uno::RuntimeException )
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir //XXX #TODO# #FIXME#
279*cdf0e10cSrcweir 	throw uno::RuntimeException(
280*cdf0e10cSrcweir 		rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getStandardFontSize not supported") ), uno::Reference< uno::XInterface >() );
281*cdf0e10cSrcweir 	// return uno::Any();
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void  SAL_CALL
286*cdf0e10cSrcweir ScVbaFont::setStandardFont( const uno::Any& /*aValue*/ ) throw( uno::RuntimeException )
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir //XXX #TODO# #FIXME#
289*cdf0e10cSrcweir 	throw uno::RuntimeException(
290*cdf0e10cSrcweir 		rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setStandardFont not supported") ), uno::Reference< uno::XInterface >() );
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir uno::Any SAL_CALL
295*cdf0e10cSrcweir ScVbaFont::getStandardFont() throw ( uno::RuntimeException )
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir //XXX #TODO# #FIXME#
298*cdf0e10cSrcweir 	throw uno::RuntimeException(
299*cdf0e10cSrcweir 		rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getStandardFont not supported") ), uno::Reference< uno::XInterface >() );
300*cdf0e10cSrcweir 	// return uno::Any();
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir void SAL_CALL
304*cdf0e10cSrcweir ScVbaFont::setFontStyle( const uno::Any& aValue ) throw( uno::RuntimeException )
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir     sal_Bool bBold = sal_False;
307*cdf0e10cSrcweir     sal_Bool bItalic = sal_False;
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     rtl::OUString aStyles;
310*cdf0e10cSrcweir     aValue >>= aStyles;
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     std::vector< rtl::OUString > aTokens;
313*cdf0e10cSrcweir     sal_Int32 nIndex = 0;
314*cdf0e10cSrcweir     do
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         rtl::OUString aToken = aStyles.getToken( 0, ' ', nIndex );
317*cdf0e10cSrcweir         aTokens.push_back( aToken );
318*cdf0e10cSrcweir     }while( nIndex >= 0 );
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     std::vector< rtl::OUString >::iterator it;
321*cdf0e10cSrcweir     for( it = aTokens.begin(); it != aTokens.end(); ++it )
322*cdf0e10cSrcweir     {
323*cdf0e10cSrcweir         if( (*it).equalsIgnoreAsciiCaseAscii( "Bold" ) )
324*cdf0e10cSrcweir             bBold = sal_True;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir         if( (*it).equalsIgnoreAsciiCaseAscii( "Italic" ) )
327*cdf0e10cSrcweir             bItalic = sal_True;
328*cdf0e10cSrcweir     }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     setBold( uno::makeAny( bBold ) );
331*cdf0e10cSrcweir     setItalic( uno::makeAny( bItalic ) );
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir uno::Any SAL_CALL
336*cdf0e10cSrcweir ScVbaFont::getFontStyle() throw ( uno::RuntimeException )
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir     rtl::OUStringBuffer aStyles;
339*cdf0e10cSrcweir     sal_Bool bValue = sal_False;
340*cdf0e10cSrcweir     getBold() >>= bValue;
341*cdf0e10cSrcweir     if( bValue )
342*cdf0e10cSrcweir         aStyles.appendAscii("Bold");
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     getItalic() >>= bValue;
345*cdf0e10cSrcweir     if( bValue )
346*cdf0e10cSrcweir     {
347*cdf0e10cSrcweir         if( aStyles.getLength() )
348*cdf0e10cSrcweir             aStyles.appendAscii(" ");
349*cdf0e10cSrcweir         aStyles.appendAscii("Italic");
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir     return uno::makeAny( aStyles.makeStringAndClear() );
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir uno::Any SAL_CALL
355*cdf0e10cSrcweir ScVbaFont::getBold() throw ( uno::RuntimeException )
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir 	if ( GetDataSet() )
358*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_WEIGHT, sal_True, NULL) == SFX_ITEM_DONTCARE )
359*cdf0e10cSrcweir 			return aNULL();
360*cdf0e10cSrcweir 	return ScVbaFont_BASE::getBold();
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir void SAL_CALL
364*cdf0e10cSrcweir ScVbaFont::setUnderline( const uno::Any& aValue ) throw ( uno::RuntimeException )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir 	// default
367*cdf0e10cSrcweir 	sal_Int32 nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone;
368*cdf0e10cSrcweir 	aValue >>= nValue;
369*cdf0e10cSrcweir 	switch ( nValue )
370*cdf0e10cSrcweir 	{
371*cdf0e10cSrcweir // NOTE:: #TODO #FIMXE
372*cdf0e10cSrcweir // xlUnderlineStyleDoubleAccounting & xlUnderlineStyleSingleAccounting
373*cdf0e10cSrcweir // don't seem to be supported in Openoffice.
374*cdf0e10cSrcweir // The import filter converts them to single or double underlines as appropriate
375*cdf0e10cSrcweir // So, here at the moment we are similarly silently converting
376*cdf0e10cSrcweir // xlUnderlineStyleSingleAccounting to xlUnderlineStyleSingle.
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 		case excel::XlUnderlineStyle::xlUnderlineStyleNone:
379*cdf0e10cSrcweir 			nValue = awt::FontUnderline::NONE;
380*cdf0e10cSrcweir 			break;
381*cdf0e10cSrcweir 		case excel::XlUnderlineStyle::xlUnderlineStyleSingle:
382*cdf0e10cSrcweir 		case excel::XlUnderlineStyle::xlUnderlineStyleSingleAccounting:
383*cdf0e10cSrcweir 			nValue = awt::FontUnderline::SINGLE;
384*cdf0e10cSrcweir 			break;
385*cdf0e10cSrcweir 		case excel::XlUnderlineStyle::xlUnderlineStyleDouble:
386*cdf0e10cSrcweir 		case excel::XlUnderlineStyle::xlUnderlineStyleDoubleAccounting:
387*cdf0e10cSrcweir 			nValue = awt::FontUnderline::DOUBLE;
388*cdf0e10cSrcweir 			break;
389*cdf0e10cSrcweir 		default:
390*cdf0e10cSrcweir 			throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value for Underline")), uno::Reference< uno::XInterface >() );
391*cdf0e10cSrcweir 	}
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 	mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharUnderline" ) ), ( uno::Any )nValue );
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir uno::Any SAL_CALL
398*cdf0e10cSrcweir ScVbaFont::getUnderline() throw ( uno::RuntimeException )
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	if ( GetDataSet() )
401*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_UNDERLINE, sal_True, NULL) == SFX_ITEM_DONTCARE )
402*cdf0e10cSrcweir 			return aNULL();
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	sal_Int32 nValue = awt::FontUnderline::NONE;
405*cdf0e10cSrcweir 	mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharUnderline" ) ) ) >>= nValue;
406*cdf0e10cSrcweir 	switch ( nValue )
407*cdf0e10cSrcweir 	{
408*cdf0e10cSrcweir 		case  awt::FontUnderline::DOUBLE:
409*cdf0e10cSrcweir 			nValue = excel::XlUnderlineStyle::xlUnderlineStyleDouble;
410*cdf0e10cSrcweir 			break;
411*cdf0e10cSrcweir 		case  awt::FontUnderline::SINGLE:
412*cdf0e10cSrcweir 			nValue = excel::XlUnderlineStyle::xlUnderlineStyleSingle;
413*cdf0e10cSrcweir 			break;
414*cdf0e10cSrcweir 		case  awt::FontUnderline::NONE:
415*cdf0e10cSrcweir 			nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone;
416*cdf0e10cSrcweir 			break;
417*cdf0e10cSrcweir 		default:
418*cdf0e10cSrcweir 			throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value retrieved for Underline") ), uno::Reference< uno::XInterface >() );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	}
421*cdf0e10cSrcweir 	return uno::makeAny( nValue );
422*cdf0e10cSrcweir }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir uno::Any SAL_CALL
425*cdf0e10cSrcweir ScVbaFont::getStrikethrough() throw ( uno::RuntimeException )
426*cdf0e10cSrcweir {
427*cdf0e10cSrcweir 	if ( GetDataSet() )
428*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_CROSSEDOUT, sal_True, NULL) == SFX_ITEM_DONTCARE )
429*cdf0e10cSrcweir 			return aNULL();
430*cdf0e10cSrcweir 	return ScVbaFont_BASE::getStrikethrough();
431*cdf0e10cSrcweir }
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir uno::Any SAL_CALL
434*cdf0e10cSrcweir ScVbaFont::getShadow() throw (uno::RuntimeException)
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir 	if ( GetDataSet() )
437*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_SHADOWED, sal_True, NULL) == SFX_ITEM_DONTCARE )
438*cdf0e10cSrcweir 			return aNULL();
439*cdf0e10cSrcweir 	return ScVbaFont_BASE::getShadow();
440*cdf0e10cSrcweir }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir uno::Any SAL_CALL
443*cdf0e10cSrcweir ScVbaFont::getItalic() throw ( uno::RuntimeException )
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir 	if ( GetDataSet() )
446*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_POSTURE, sal_True, NULL) == SFX_ITEM_DONTCARE )
447*cdf0e10cSrcweir 			return aNULL();
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 	return ScVbaFont_BASE::getItalic();
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir uno::Any SAL_CALL
453*cdf0e10cSrcweir ScVbaFont::getName() throw ( uno::RuntimeException )
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir 	if ( GetDataSet() )
456*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT, sal_True, NULL) == SFX_ITEM_DONTCARE )
457*cdf0e10cSrcweir 			return aNULL();
458*cdf0e10cSrcweir 	return ScVbaFont_BASE::getName();
459*cdf0e10cSrcweir }
460*cdf0e10cSrcweir uno::Any
461*cdf0e10cSrcweir ScVbaFont::getColor() throw (uno::RuntimeException)
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir 	// #TODO #FIXME - behave like getXXX above ( wrt. GetDataSet )
464*cdf0e10cSrcweir 	uno::Any aAny;
465*cdf0e10cSrcweir 	aAny = OORGBToXLRGB( mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharColor" ) ) ) );
466*cdf0e10cSrcweir 	return aAny;
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir void  SAL_CALL
470*cdf0e10cSrcweir ScVbaFont::setOutlineFont( const uno::Any& aValue ) throw ( uno::RuntimeException )
471*cdf0e10cSrcweir {
472*cdf0e10cSrcweir 	mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharContoured" ) ), aValue );
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir uno::Any SAL_CALL
476*cdf0e10cSrcweir ScVbaFont::getOutlineFont() throw (uno::RuntimeException)
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	if ( GetDataSet() )
479*cdf0e10cSrcweir 		if (  GetDataSet()->GetItemState( ATTR_FONT_CONTOUR, sal_True, NULL) == SFX_ITEM_DONTCARE )
480*cdf0e10cSrcweir 			return aNULL();
481*cdf0e10cSrcweir 	return mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharContoured" ) ) );
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir rtl::OUString&
485*cdf0e10cSrcweir ScVbaFont::getServiceImplName()
486*cdf0e10cSrcweir {
487*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFont") );
488*cdf0e10cSrcweir 	return sImplName;
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
492*cdf0e10cSrcweir ScVbaFont::getServiceNames()
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
495*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
496*cdf0e10cSrcweir 	{
497*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
498*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Font" ) );
499*cdf0e10cSrcweir 	}
500*cdf0e10cSrcweir 	return aServiceNames;
501*cdf0e10cSrcweir }
502