1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbaformat.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbaformat.hxx"
31 #include <ooo/vba/excel/XStyle.hpp>
32 #include <ooo/vba/excel/XlVAlign.hpp>
33 #include <ooo/vba/excel/XlHAlign.hpp>
34 #include <ooo/vba/excel/XlOrientation.hpp>
35 #include <ooo/vba/excel/Constants.hpp>
36 #include <ooo/vba/excel/XRange.hpp>
37 #include <com/sun/star/table/CellVertJustify.hpp>
38 #include <com/sun/star/table/CellHoriJustify.hpp>
39 #include <com/sun/star/table/CellOrientation.hpp>
40 #include <com/sun/star/table/XCellRange.hpp>
41 #include <com/sun/star/text/WritingMode.hpp>
42 #include <com/sun/star/util/CellProtection.hpp>
44 #include <rtl/math.hxx>
46 #include "vbaborders.hxx"
47 #include "vbapalette.hxx"
48 #include "vbafont.hxx"
49 #include "vbainterior.hxx"
51 #include "unonames.hxx"
53 using namespace ::ooo::vba
;
54 using namespace ::com::sun::star
;
56 #define FORMATSTRING "FormatString"
57 #define LOCALE "Locale"
59 template< typename Ifc1
>
60 ScVbaFormat
< Ifc1
>::ScVbaFormat( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
> & xContext
, const uno::Reference
< beans::XPropertySet
>& _xPropertySet
, const uno::Reference
< frame::XModel
>& xModel
, bool bCheckAmbiguoity
) throw ( script::BasicErrorException
) : ScVbaFormat_BASE( xParent
, xContext
), m_aDefaultLocale( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("en") ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "US") ), rtl::OUString() ), mxPropertySet( _xPropertySet
), mxModel( xModel
), mbCheckAmbiguoity( bCheckAmbiguoity
), mbAddIndent( sal_False
)
64 mxServiceInfo
.set( mxPropertySet
, uno::UNO_QUERY_THROW
);
66 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved") ) );
67 mxNumberFormatsSupplier
.set( mxModel
, uno::UNO_QUERY_THROW
);
69 catch (uno::Exception
& )
71 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
75 template< typename Ifc1
>
77 ScVbaFormat
<Ifc1
>::setVerticalAlignment( const uno::Any
& _oAlignment
) throw (script::BasicErrorException
, uno::RuntimeException
)
82 sal_Int32 nAlignment
= 0;
83 if ( !(_oAlignment
>>= nAlignment
))
84 throw uno::RuntimeException();
87 case excel::XlVAlign::xlVAlignBottom
:
88 aVal
= uno::makeAny( table::CellVertJustify_BOTTOM
);
90 case excel::XlVAlign::xlVAlignCenter
:
91 aVal
= uno::makeAny( table::CellVertJustify_CENTER
);
93 case excel::XlVAlign::xlVAlignDistributed
:
94 case excel::XlVAlign::xlVAlignJustify
:
95 aVal
= uno::makeAny( table::CellVertJustify_STANDARD
);
98 case excel::XlVAlign::xlVAlignTop
:
99 aVal
= uno::makeAny( table::CellVertJustify_TOP
);
102 aVal
= uno::makeAny( table::CellVertJustify_STANDARD
);
105 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS
) ), aVal
);
107 catch (uno::Exception
& )
109 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
113 template< typename Ifc1
>
115 ScVbaFormat
<Ifc1
>::getVerticalAlignment( ) throw (script::BasicErrorException
, uno::RuntimeException
)
117 uno::Any aResult
= aNULL();
120 if (!isAmbiguous( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS
) ) ) )
122 table::CellVertJustify aAPIAlignment
;
123 mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS
) ) ) >>= aAPIAlignment
;
124 switch( aAPIAlignment
)
126 case table::CellVertJustify_BOTTOM
:
127 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignBottom
);
129 case table::CellVertJustify_CENTER
:
130 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignCenter
);
132 case table::CellVertJustify_STANDARD
:
133 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignBottom
);
135 case table::CellVertJustify_TOP
:
136 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignTop
);
143 catch (uno::Exception
& )
145 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
150 template< typename Ifc1
>
152 ScVbaFormat
<Ifc1
>::setHorizontalAlignment( const uno::Any
& HorizontalAlignment
) throw (script::BasicErrorException
, uno::RuntimeException
)
157 sal_Int32 nAlignment
= 0;
158 if ( !( HorizontalAlignment
>>= nAlignment
) )
159 throw uno::RuntimeException();
160 switch ( nAlignment
)
162 case excel::XlHAlign::xlHAlignJustify
:
163 aVal
= uno::makeAny( table::CellHoriJustify_BLOCK
);
165 case excel::XlHAlign::xlHAlignCenter
:
166 aVal
= uno::makeAny( table::CellHoriJustify_CENTER
);
168 case excel::XlHAlign::xlHAlignDistributed
:
169 aVal
= uno::makeAny( table::CellHoriJustify_BLOCK
);
171 case excel::XlHAlign::xlHAlignLeft
:
172 aVal
= uno::makeAny( table::CellHoriJustify_LEFT
);
174 case excel::XlHAlign::xlHAlignRight
:
175 aVal
= uno::makeAny( table::CellHoriJustify_RIGHT
);
178 // #FIXME what about the default case above?
179 // shouldn't need the test below
180 if ( aVal
.hasValue() )
181 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS
) ), aVal
);
183 catch (uno::Exception
& )
185 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
190 template< typename Ifc1
>
192 ScVbaFormat
<Ifc1
>::getHorizontalAlignment( ) throw (script::BasicErrorException
, uno::RuntimeException
)
194 uno::Any NRetAlignment
= aNULL();
197 rtl::OUString
sHoriJust( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS
) );
198 if (!isAmbiguous(sHoriJust
))
200 table::CellHoriJustify aAPIAlignment
= table::CellHoriJustify_BLOCK
;
202 if ( mxPropertySet
->getPropertyValue(sHoriJust
) >>= aAPIAlignment
)
204 switch( aAPIAlignment
)
206 case table::CellHoriJustify_BLOCK
:
207 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignJustify
);
209 case table::CellHoriJustify_CENTER
:
210 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignCenter
);
212 case table::CellHoriJustify_LEFT
:
213 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignLeft
);
215 case table::CellHoriJustify_RIGHT
:
216 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignRight
);
218 default: // handle those other cases with a NULL return
224 catch (uno::Exception
& )
226 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
228 return NRetAlignment
;
231 template< typename Ifc1
>
233 ScVbaFormat
<Ifc1
>::setOrientation( const uno::Any
& _aOrientation
) throw (script::BasicErrorException
, uno::RuntimeException
)
237 sal_Int32 nOrientation
= 0;
238 if ( !( _aOrientation
>>= nOrientation
) )
239 throw uno::RuntimeException();
241 switch( nOrientation
)
243 case excel::XlOrientation::xlDownward
:
244 aVal
= uno::makeAny( table::CellOrientation_TOPBOTTOM
);
246 case excel::XlOrientation::xlHorizontal
:
247 aVal
= uno::makeAny( table::CellOrientation_STANDARD
);
248 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ROTANG
) ), uno::makeAny( sal_Int32(0) ) );
250 case excel::XlOrientation::xlUpward
:
251 aVal
= uno::makeAny( table::CellOrientation_BOTTOMTOP
);
253 case excel::XlOrientation::xlVertical
:
254 aVal
= uno::makeAny( table::CellOrientation_STACKED
);
257 // #FIXME what about the default case above?
258 // shouldn't need the test below
259 if ( aVal
.hasValue() )
260 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI
) ), aVal
);
263 catch (uno::Exception
& )
265 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
268 template< typename Ifc1
>
270 ScVbaFormat
<Ifc1
>::getOrientation( ) throw (script::BasicErrorException
, uno::RuntimeException
)
272 uno::Any NRetOrientation
= aNULL();
275 if (!isAmbiguous(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI
) )))
277 table::CellOrientation aOrientation
= table::CellOrientation_STANDARD
;
278 if ( !( mxPropertySet
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI
) ) ) >>= aOrientation
) )
279 throw uno::RuntimeException();
283 case table::CellOrientation_STANDARD
:
284 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlHorizontal
);
286 case table::CellOrientation_BOTTOMTOP
:
287 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlUpward
);
289 case table::CellOrientation_TOPBOTTOM
:
290 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlDownward
);
292 case table::CellOrientation_STACKED
:
293 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlVertical
);
296 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlHorizontal
);
300 catch (uno::Exception
& )
302 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
304 return NRetOrientation
;
307 template< typename Ifc1
>
309 ScVbaFormat
<Ifc1
>::setWrapText( const uno::Any
& _aWrapText
) throw (script::BasicErrorException
, uno::RuntimeException
)
313 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRAP
) ), _aWrapText
);
315 catch (uno::Exception
& )
317 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
321 template< typename Ifc1
>
323 ScVbaFormat
<Ifc1
>::getWrapText( ) throw (script::BasicErrorException
, uno::RuntimeException
)
325 uno::Any aWrap
= aNULL();
328 rtl::OUString
aPropName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRAP
) ) );
329 if (!isAmbiguous( aPropName
))
331 aWrap
= mxPropertySet
->getPropertyValue(aPropName
);
334 catch (uno::Exception
& )
336 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
341 template< typename Ifc1
>
343 ScVbaFormat
<Ifc1
>::Borders( const uno::Any
& Index
) throw (script::BasicErrorException
, uno::RuntimeException
)
345 ScVbaPalette
aPalette( excel::getDocShell( mxModel
) );
346 uno::Reference
< XCollection
> xColl
= new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext
, uno::Reference
< table::XCellRange
>( mxPropertySet
, uno::UNO_QUERY_THROW
), aPalette
);
348 if ( Index
.hasValue() )
350 return xColl
->Item( Index
, uno::Any() );
352 return uno::makeAny( xColl
);
355 template< typename Ifc1
>
356 uno::Reference
< excel::XFont
> SAL_CALL
357 ScVbaFormat
<Ifc1
>::Font( ) throw (script::BasicErrorException
, uno::RuntimeException
)
359 ScVbaPalette
aPalette( excel::getDocShell( mxModel
) );
360 return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext
, aPalette
, mxPropertySet
);
363 template< typename Ifc1
>
364 uno::Reference
< excel::XInterior
> SAL_CALL
365 ScVbaFormat
<Ifc1
>::Interior( ) throw (script::BasicErrorException
, uno::RuntimeException
)
367 return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext
, mxPropertySet
);
370 template< typename Ifc1
>
372 ScVbaFormat
<Ifc1
>::getNumberFormatLocal( ) throw (script::BasicErrorException
, uno::RuntimeException
)
374 uno::Any aRet
= uno::makeAny( rtl::OUString() );
377 rtl::OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO
) );
378 if (!isAmbiguous( sPropName
))
381 initializeNumberFormats();
383 sal_Int32 nFormat
= 0;
384 if ( ! (mxPropertySet
->getPropertyValue( sPropName
) >>= nFormat
) )
385 throw uno::RuntimeException();
387 rtl::OUString sFormat
;
388 xNumberFormats
->getByKey(nFormat
)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( FORMATSTRING
))) >>= sFormat
;
389 aRet
= uno::makeAny( sFormat
.toAsciiLowerCase() );
393 catch (uno::Exception
& )
395 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
401 template< typename Ifc1
>
403 ScVbaFormat
<Ifc1
>::setNumberFormat( lang::Locale _aLocale
, const rtl::OUString
& _sFormatString
) throw( script::BasicErrorException
)
407 initializeNumberFormats();
408 sal_Int32 nFormat
= xNumberFormats
->queryKey(_sFormatString
, _aLocale
, sal_True
);
411 xNumberFormats
->addNew(_sFormatString
, _aLocale
);
413 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO
) ), uno::makeAny( nFormat
) );
415 catch (uno::Exception
& )
417 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
421 template< typename Ifc1
>
423 ScVbaFormat
<Ifc1
>::setNumberFormatLocal( const uno::Any
& _oLocalFormatString
) throw (script::BasicErrorException
, uno::RuntimeException
)
427 rtl::OUString sLocalFormatString
;
428 sal_Int32 nFormat
= -1;
429 rtl::OUString
sNumFormat( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO
) );
430 if ( !(_oLocalFormatString
>>= sLocalFormatString
)
431 || !( mxPropertySet
->getPropertyValue(sNumFormat
) >>= nFormat
) )
432 throw uno::RuntimeException();
434 sLocalFormatString
= sLocalFormatString
.toAsciiUpperCase();
435 initializeNumberFormats();
436 lang::Locale aRangeLocale
;
437 xNumberFormats
->getByKey(nFormat
)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALE
) ) ) >>= aRangeLocale
;
438 sal_Int32 nNewFormat
= xNumberFormats
->queryKey(sLocalFormatString
, aRangeLocale
, sal_True
);
440 if (nNewFormat
== -1)
441 nNewFormat
= xNumberFormats
->addNew(sLocalFormatString
, aRangeLocale
);
442 mxPropertySet
->setPropertyValue(sNumFormat
, uno::makeAny( nNewFormat
));
444 catch (uno::Exception
& )
446 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
450 template< typename Ifc1
>
452 ScVbaFormat
<Ifc1
>::setNumberFormat( const uno::Any
& _oFormatString
) throw (script::BasicErrorException
, uno::RuntimeException
)
456 rtl::OUString sFormatString
;
457 if ( !( _oFormatString
>>= sFormatString
) )
458 throw uno::RuntimeException();
460 sFormatString
= sFormatString
.toAsciiUpperCase();
462 lang::Locale aDefaultLocale
= m_aDefaultLocale
;
463 initializeNumberFormats();
464 sal_Int32 nFormat
= xNumberFormats
->queryKey(sFormatString
, aDefaultLocale
, sal_True
);
467 nFormat
= xNumberFormats
->addNew(sFormatString
, aDefaultLocale
);
469 lang::Locale aRangeLocale
;
470 xNumberFormats
->getByKey(nFormat
)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALE
) ) ) >>= aRangeLocale
;
471 sal_Int32 nNewFormat
= xNumberFormatTypes
->getFormatForLocale(nFormat
, aRangeLocale
);
472 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO
) ), uno::makeAny( nNewFormat
));
474 catch (uno::Exception
& )
476 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
481 template< typename Ifc1
>
483 ScVbaFormat
<Ifc1
>::setIndentLevel( const uno::Any
& _aLevel
) throw (script::BasicErrorException
, uno::RuntimeException
)
487 sal_Int32 nLevel
= 0;
488 if ( !(_aLevel
>>= nLevel
) )
489 throw uno::RuntimeException();
490 table::CellHoriJustify aAPIAlignment
= table::CellHoriJustify_STANDARD
;
492 rtl::OUString
sHoriJust( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS
) );
493 if ( !( mxPropertySet
->getPropertyValue(sHoriJust
) >>= aAPIAlignment
) )
494 throw uno::RuntimeException();
495 if (aAPIAlignment
== table::CellHoriJustify_STANDARD
)
496 mxPropertySet
->setPropertyValue( sHoriJust
, uno::makeAny( table::CellHoriJustify_LEFT
) ) ;
497 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_PINDENT
) ), uno::makeAny( sal_Int16(nLevel
* 352.8) ) );
499 catch (uno::Exception
& )
501 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
505 template< typename Ifc1
>
507 ScVbaFormat
<Ifc1
>::getIndentLevel( ) throw (script::BasicErrorException
, uno::RuntimeException
)
509 uno::Any NRetIndentLevel
= aNULL();
512 rtl::OUString
sParaIndent( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_PINDENT
) );
513 if (!isAmbiguous(sParaIndent
))
515 sal_Int16 IndentLevel
= 0;
516 if ( ( mxPropertySet
->getPropertyValue(sParaIndent
) >>= IndentLevel
) )
517 NRetIndentLevel
= uno::makeAny( sal_Int32( rtl::math::round(static_cast<double>( IndentLevel
) / 352.8)) );
519 NRetIndentLevel
= uno::makeAny( sal_Int32(0) );
522 catch (uno::Exception
& )
524 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
526 return NRetIndentLevel
;
529 template< typename Ifc1
>
531 ScVbaFormat
<Ifc1
>::setLocked( const uno::Any
& _aLocked
) throw (script::BasicErrorException
, uno::RuntimeException
)
535 sal_Bool bIsLocked
= sal_False
;
536 if ( !( _aLocked
>>= bIsLocked
) )
537 throw uno::RuntimeException();
538 util::CellProtection aCellProtection
;
539 rtl::OUString
sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO
) );
540 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
541 aCellProtection
.IsLocked
= bIsLocked
;
542 mxPropertySet
->setPropertyValue(sCellProt
, uno::makeAny( aCellProtection
) );
544 catch (uno::Exception
& )
546 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString() );
550 template< typename Ifc1
>
552 ScVbaFormat
<Ifc1
>::setFormulaHidden( const uno::Any
& FormulaHidden
) throw (script::BasicErrorException
, uno::RuntimeException
)
556 sal_Bool bIsFormulaHidden
= sal_False
;
557 FormulaHidden
>>= bIsFormulaHidden
;
558 util::CellProtection aCellProtection
;
559 rtl::OUString
sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO
) );
560 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
561 aCellProtection
.IsFormulaHidden
= bIsFormulaHidden
;
562 mxPropertySet
->setPropertyValue(sCellProt
,uno::makeAny(aCellProtection
));
564 catch (uno::Exception
& )
566 DebugHelper::exception( SbERR_METHOD_FAILED
, rtl::OUString() );
570 template< typename Ifc1
>
572 ScVbaFormat
<Ifc1
>::getLocked( ) throw (script::BasicErrorException
, uno::RuntimeException
)
574 uno::Any aCellProtection
= aNULL();
578 rtl::OUString
sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO
) );
579 if (!isAmbiguous(sCellProt
))
581 util::CellProtection cellProtection
;
582 mxPropertySet
->getPropertyValue(sCellProt
) >>= cellProtection
;
584 aCellProtection
= uno::makeAny( cellProtection
.IsLocked
);
587 catch (uno::Exception
& )
589 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
591 return aCellProtection
;
594 template< typename Ifc1
>
596 ScVbaFormat
<Ifc1
>::getFormulaHidden( ) throw (script::BasicErrorException
, uno::RuntimeException
)
598 uno::Any aBoolRet
= aNULL();
601 rtl::OUString
sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO
) );
602 if (!isAmbiguous(sCellProt
))
604 util::CellProtection aCellProtection
;
605 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
606 aBoolRet
= uno::makeAny( aCellProtection
.IsFormulaHidden
);
609 catch (uno::Exception e
)
611 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
616 template< typename Ifc1
>
618 ScVbaFormat
<Ifc1
>::setShrinkToFit( const uno::Any
& ShrinkToFit
) throw (script::BasicErrorException
, uno::RuntimeException
)
622 mxPropertySet
->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHRINK_TO_FIT
) ), ShrinkToFit
);
624 catch (uno::Exception
& )
626 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString() );
631 template< typename Ifc1
>
633 ScVbaFormat
<Ifc1
>::getShrinkToFit( ) throw (script::BasicErrorException
, uno::RuntimeException
)
635 uno::Any aRet
= aNULL();
638 rtl::OUString
sShrinkToFit( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHRINK_TO_FIT
) );
639 if (!isAmbiguous(sShrinkToFit
))
640 aRet
= mxPropertySet
->getPropertyValue(sShrinkToFit
);
642 catch (uno::Exception
& )
644 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
649 template< typename Ifc1
>
651 ScVbaFormat
<Ifc1
>::setReadingOrder( const uno::Any
& ReadingOrder
) throw (script::BasicErrorException
, uno::RuntimeException
)
655 sal_Int32 nReadingOrder
= 0;
656 if ( !(ReadingOrder
>>= nReadingOrder
))
657 throw uno::RuntimeException();
659 switch(nReadingOrder
)
661 case excel::Constants::xlLTR
:
662 aVal
= uno::makeAny( text::WritingMode_LR_TB
);
664 case excel::Constants::xlRTL
:
665 aVal
= uno::makeAny( text::WritingMode_RL_TB
);
667 case excel::Constants::xlContext
:
668 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
671 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
673 mxPropertySet
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRITING
) ), aVal
);
675 catch (uno::Exception
& )
677 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
682 template< typename Ifc1
>
684 ScVbaFormat
<Ifc1
>::getReadingOrder( ) throw (script::BasicErrorException
, uno::RuntimeException
)
686 uno::Any NRetReadingOrder
= aNULL();
689 rtl::OUString
sWritingMode( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRITING
) );
690 if (!isAmbiguous(sWritingMode
))
692 text::WritingMode aWritingMode
= text::WritingMode_LR_TB
;
693 if ( ( mxPropertySet
->getPropertyValue(sWritingMode
) ) >>= aWritingMode
)
694 switch (aWritingMode
){
695 case text::WritingMode_LR_TB
:
696 NRetReadingOrder
= uno::makeAny(excel::Constants::xlLTR
);
698 case text::WritingMode_RL_TB
:
699 NRetReadingOrder
= uno::makeAny(excel::Constants::xlRTL
);
702 NRetReadingOrder
= uno::makeAny(excel::Constants::xlRTL
);
706 catch (uno::Exception
& )
708 DebugHelper::exception(SbERR_NOT_IMPLEMENTED
, rtl::OUString());
710 return NRetReadingOrder
;
714 template< typename Ifc1
>
716 ScVbaFormat
< Ifc1
>::getNumberFormat( ) throw (script::BasicErrorException
, uno::RuntimeException
)
718 uno::Any aFormat
= aNULL();
721 sal_Int32 nFormat
= -1;
722 rtl::OUString
sNumFormat( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO
) );
723 if (!isAmbiguous(sNumFormat
) &&
724 ( mxPropertySet
->getPropertyValue(sNumFormat
) >>= nFormat
) )
726 initializeNumberFormats();
728 sal_Int32 nNewFormat
= xNumberFormatTypes
->getFormatForLocale(nFormat
, getDefaultLocale() );
729 rtl::OUString sFormat
;
730 xNumberFormats
->getByKey(nNewFormat
)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( FORMATSTRING
))) >>= sFormat
;
731 aFormat
= uno::makeAny( sFormat
);
734 catch (uno::Exception
& )
736 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
741 template< typename Ifc1
>
743 ScVbaFormat
<Ifc1
>::isAmbiguous(const rtl::OUString
& _sPropertyName
) throw ( script::BasicErrorException
)
745 bool bResult
= false;
748 if (mbCheckAmbiguoity
)
749 bResult
= ( getXPropertyState()->getPropertyState(_sPropertyName
) == beans::PropertyState_AMBIGUOUS_VALUE
);
751 catch (uno::Exception
& )
753 DebugHelper::exception(SbERR_METHOD_FAILED
, rtl::OUString());
758 template< typename Ifc1
>
760 ScVbaFormat
<Ifc1
>::initializeNumberFormats() throw ( script::BasicErrorException
)
762 if ( !xNumberFormats
.is() )
764 mxNumberFormatsSupplier
.set( mxModel
, uno::UNO_QUERY_THROW
);
765 xNumberFormats
= mxNumberFormatsSupplier
->getNumberFormats();
766 xNumberFormatTypes
.set( xNumberFormats
, uno::UNO_QUERY
); // _THROW?
770 template< typename Ifc1
>
771 uno::Reference
< beans::XPropertyState
>
772 ScVbaFormat
<Ifc1
>::getXPropertyState() throw ( uno::RuntimeException
)
774 if ( !xPropertyState
.is() )
775 xPropertyState
.set( mxPropertySet
, uno::UNO_QUERY_THROW
);
776 return xPropertyState
;
779 template< typename Ifc1
>
781 ScVbaFormat
<Ifc1
>::getServiceImplName()
783 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormat") );
787 template< typename Ifc1
>
788 uno::Sequence
< rtl::OUString
>
789 ScVbaFormat
<Ifc1
>::getServiceNames()
791 static uno::Sequence
< rtl::OUString
> aServiceNames
;
792 if ( aServiceNames
.getLength() == 0 )
794 aServiceNames
.realloc( 1 );
795 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Format" ) );
797 return aServiceNames
;
800 template class ScVbaFormat
< excel::XStyle
>;
801 template class ScVbaFormat
< excel::XRange
>;