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