1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "vbaformat.hxx"
20 #include <ooo/vba/excel/XStyle.hpp>
21 #include <ooo/vba/excel/XlVAlign.hpp>
22 #include <ooo/vba/excel/XlHAlign.hpp>
23 #include <ooo/vba/excel/XlOrientation.hpp>
24 #include <ooo/vba/excel/Constants.hpp>
25 #include <ooo/vba/excel/XRange.hpp>
26 #include <com/sun/star/table/CellVertJustify2.hpp>
27 #include <com/sun/star/table/CellHoriJustify.hpp>
28 #include <com/sun/star/table/CellOrientation.hpp>
29 #include <com/sun/star/table/XCellRange.hpp>
30 #include <com/sun/star/text/WritingMode.hpp>
31 #include <com/sun/star/util/CellProtection.hpp>
33 #include <rtl/math.hxx>
35 #include "excelvbahelper.hxx"
36 #include "vbaborders.hxx"
37 #include "vbapalette.hxx"
38 #include "vbafont.hxx"
39 #include "vbainterior.hxx"
41 #include <unonames.hxx>
42 #include <cellsuno.hxx>
43 #include <scitems.hxx>
46 using namespace ::ooo::vba
;
47 using namespace ::com::sun::star
;
49 #define FORMATSTRING "FormatString"
50 #define LOCALE "Locale"
52 template< typename Ifc1
>
53 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( OUString("en"), OUString( "US"), OUString() ), mxPropertySet( _xPropertySet
), mxModel( xModel
), mbCheckAmbiguoity( bCheckAmbiguoity
), mbAddIndent( false )
58 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString( "XModel Interface could not be retrieved") );
59 // mxServiceInfo is unused,
60 // mxNumberFormatsSupplier is initialized when needed in initializeNumberFormats.
62 catch (const uno::Exception
& )
64 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
68 template< typename Ifc1
>
70 ScVbaFormat
<Ifc1
>::setVerticalAlignment( const uno::Any
& _oAlignment
) throw (script::BasicErrorException
, uno::RuntimeException
)
75 sal_Int32 nAlignment
= 0;
76 if ( !(_oAlignment
>>= nAlignment
))
77 throw uno::RuntimeException();
80 case excel::XlVAlign::xlVAlignBottom
:
81 aVal
= uno::makeAny( table::CellVertJustify2::BOTTOM
);
83 case excel::XlVAlign::xlVAlignCenter
:
84 aVal
= uno::makeAny( table::CellVertJustify2::CENTER
);
86 case excel::XlVAlign::xlVAlignDistributed
:
87 case excel::XlVAlign::xlVAlignJustify
:
88 aVal
= uno::makeAny( table::CellVertJustify2::STANDARD
);
91 case excel::XlVAlign::xlVAlignTop
:
92 aVal
= uno::makeAny( table::CellVertJustify2::TOP
);
95 aVal
= uno::makeAny( table::CellVertJustify2::STANDARD
);
98 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_CELLVJUS
), aVal
);
100 catch (const uno::Exception
&)
102 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
106 template< typename Ifc1
>
108 ScVbaFormat
<Ifc1
>::getVerticalAlignment( ) throw (script::BasicErrorException
, uno::RuntimeException
)
110 uno::Any aResult
= aNULL();
113 if (!isAmbiguous( OUString( SC_UNONAME_CELLVJUS
) ) )
115 sal_Int32 aAPIAlignment
= table::CellVertJustify2::STANDARD
;
116 mxPropertySet
->getPropertyValue( OUString( SC_UNONAME_CELLVJUS
) ) >>= aAPIAlignment
;
117 switch( aAPIAlignment
)
119 case table::CellVertJustify2::BOTTOM
:
120 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignBottom
);
122 case table::CellVertJustify2::CENTER
:
123 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignCenter
);
125 case table::CellVertJustify2::STANDARD
:
126 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignBottom
);
128 case table::CellVertJustify2::TOP
:
129 aResult
= uno::makeAny( excel::XlVAlign::xlVAlignTop
);
136 catch (const uno::Exception
& )
138 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
143 template< typename Ifc1
>
145 ScVbaFormat
<Ifc1
>::setHorizontalAlignment( const uno::Any
& HorizontalAlignment
) throw (script::BasicErrorException
, uno::RuntimeException
)
150 sal_Int32 nAlignment
= 0;
151 if ( !( HorizontalAlignment
>>= nAlignment
) )
152 throw uno::RuntimeException();
153 switch ( nAlignment
)
155 case excel::XlHAlign::xlHAlignJustify
:
156 aVal
= uno::makeAny( table::CellHoriJustify_BLOCK
);
158 case excel::XlHAlign::xlHAlignCenter
:
159 aVal
= uno::makeAny( table::CellHoriJustify_CENTER
);
161 case excel::XlHAlign::xlHAlignDistributed
:
162 aVal
= uno::makeAny( table::CellHoriJustify_BLOCK
);
164 case excel::XlHAlign::xlHAlignLeft
:
165 aVal
= uno::makeAny( table::CellHoriJustify_LEFT
);
167 case excel::XlHAlign::xlHAlignRight
:
168 aVal
= uno::makeAny( table::CellHoriJustify_RIGHT
);
171 // #FIXME what about the default case above?
172 // shouldn't need the test below
173 if ( aVal
.hasValue() )
174 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_CELLHJUS
), aVal
);
176 catch (const uno::Exception
& )
178 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
183 template< typename Ifc1
>
185 ScVbaFormat
<Ifc1
>::getHorizontalAlignment( ) throw (script::BasicErrorException
, uno::RuntimeException
)
187 uno::Any NRetAlignment
= aNULL();
190 OUString
sHoriJust( SC_UNONAME_CELLHJUS
);
191 if (!isAmbiguous(sHoriJust
))
193 table::CellHoriJustify aAPIAlignment
= table::CellHoriJustify_BLOCK
;
195 if ( mxPropertySet
->getPropertyValue(sHoriJust
) >>= aAPIAlignment
)
197 switch( aAPIAlignment
)
199 case table::CellHoriJustify_BLOCK
:
200 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignJustify
);
202 case table::CellHoriJustify_CENTER
:
203 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignCenter
);
205 case table::CellHoriJustify_LEFT
:
206 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignLeft
);
208 case table::CellHoriJustify_RIGHT
:
209 NRetAlignment
= uno::makeAny( excel::XlHAlign::xlHAlignRight
);
211 default: // handle those other cases with a NULL return
217 catch (const uno::Exception
& )
219 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
221 return NRetAlignment
;
224 template< typename Ifc1
>
226 ScVbaFormat
<Ifc1
>::setOrientation( const uno::Any
& _aOrientation
) throw (script::BasicErrorException
, uno::RuntimeException
)
230 sal_Int32 nOrientation
= 0;
231 if ( !( _aOrientation
>>= nOrientation
) )
232 throw uno::RuntimeException();
234 switch( nOrientation
)
236 case excel::XlOrientation::xlDownward
:
237 aVal
= uno::makeAny( table::CellOrientation_TOPBOTTOM
);
239 case excel::XlOrientation::xlHorizontal
:
240 aVal
= uno::makeAny( table::CellOrientation_STANDARD
);
241 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_ROTANG
), uno::makeAny( sal_Int32(0) ) );
243 case excel::XlOrientation::xlUpward
:
244 aVal
= uno::makeAny( table::CellOrientation_BOTTOMTOP
);
246 case excel::XlOrientation::xlVertical
:
247 aVal
= uno::makeAny( table::CellOrientation_STACKED
);
250 // #FIXME what about the default case above?
251 // shouldn't need the test below
252 if ( aVal
.hasValue() )
253 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_CELLORI
), aVal
);
256 catch (const uno::Exception
& )
258 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
261 template< typename Ifc1
>
263 ScVbaFormat
<Ifc1
>::getOrientation( ) throw (script::BasicErrorException
, uno::RuntimeException
)
265 uno::Any NRetOrientation
= aNULL();
268 if (!isAmbiguous(OUString( SC_UNONAME_CELLORI
)))
270 table::CellOrientation aOrientation
= table::CellOrientation_STANDARD
;
271 if ( !( mxPropertySet
->getPropertyValue( OUString( SC_UNONAME_CELLORI
) ) >>= aOrientation
) )
272 throw uno::RuntimeException();
276 case table::CellOrientation_STANDARD
:
277 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlHorizontal
);
279 case table::CellOrientation_BOTTOMTOP
:
280 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlUpward
);
282 case table::CellOrientation_TOPBOTTOM
:
283 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlDownward
);
285 case table::CellOrientation_STACKED
:
286 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlVertical
);
289 NRetOrientation
= uno::makeAny( excel::XlOrientation::xlHorizontal
);
293 catch (const uno::Exception
& )
295 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
297 return NRetOrientation
;
300 template< typename Ifc1
>
302 ScVbaFormat
<Ifc1
>::setWrapText( const uno::Any
& _aWrapText
) throw (script::BasicErrorException
, uno::RuntimeException
)
306 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_WRAP
), _aWrapText
);
308 catch (const uno::Exception
& )
310 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
314 template< typename Ifc1
>
316 ScVbaFormat
<Ifc1
>::getWrapText( ) throw (script::BasicErrorException
, uno::RuntimeException
)
318 uno::Any aWrap
= aNULL();
321 OUString
aPropName( SC_UNONAME_WRAP
);
322 if (!isAmbiguous( aPropName
))
324 aWrap
= mxPropertySet
->getPropertyValue(aPropName
);
327 catch (const uno::Exception
&)
329 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
334 template< typename Ifc1
>
336 ScVbaFormat
<Ifc1
>::Borders( const uno::Any
& Index
) throw (script::BasicErrorException
, uno::RuntimeException
)
338 ScVbaPalette
aPalette( excel::getDocShell( mxModel
) );
339 uno::Reference
< XCollection
> xColl
= new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext
, uno::Reference
< table::XCellRange
>( mxPropertySet
, uno::UNO_QUERY_THROW
), aPalette
);
341 if ( Index
.hasValue() )
343 return xColl
->Item( Index
, uno::Any() );
345 return uno::makeAny( xColl
);
348 template< typename Ifc1
>
349 uno::Reference
< excel::XFont
> SAL_CALL
350 ScVbaFormat
<Ifc1
>::Font( ) throw (script::BasicErrorException
, uno::RuntimeException
)
352 ScVbaPalette
aPalette( excel::getDocShell( mxModel
) );
353 return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext
, aPalette
, mxPropertySet
);
356 template< typename Ifc1
>
357 uno::Reference
< excel::XInterior
> SAL_CALL
358 ScVbaFormat
<Ifc1
>::Interior( ) throw (script::BasicErrorException
, uno::RuntimeException
)
360 return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext
, mxPropertySet
);
363 template< typename Ifc1
>
365 ScVbaFormat
<Ifc1
>::getNumberFormatLocal( ) throw (script::BasicErrorException
, uno::RuntimeException
)
367 uno::Any aRet
= uno::makeAny( OUString() );
370 OUString
sPropName( SC_UNO_DP_NUMBERFO
);
371 if (!isAmbiguous( sPropName
))
374 initializeNumberFormats();
376 sal_Int32 nFormat
= 0;
377 if ( ! (mxPropertySet
->getPropertyValue( sPropName
) >>= nFormat
) )
378 throw uno::RuntimeException();
381 xNumberFormats
->getByKey(nFormat
)->getPropertyValue( OUString( FORMATSTRING
)) >>= sFormat
;
382 aRet
= uno::makeAny( sFormat
.toAsciiLowerCase() );
386 catch (const uno::Exception
&)
388 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
394 template< typename Ifc1
>
396 ScVbaFormat
<Ifc1
>::setNumberFormatLocal( const uno::Any
& _oLocalFormatString
) throw (script::BasicErrorException
, uno::RuntimeException
)
400 OUString sLocalFormatString
;
401 sal_Int32 nFormat
= -1;
402 OUString
sNumFormat( SC_UNO_DP_NUMBERFO
);
403 if ( !(_oLocalFormatString
>>= sLocalFormatString
)
404 || !( mxPropertySet
->getPropertyValue(sNumFormat
) >>= nFormat
) )
405 throw uno::RuntimeException();
407 sLocalFormatString
= sLocalFormatString
.toAsciiUpperCase();
408 initializeNumberFormats();
409 lang::Locale aRangeLocale
;
410 xNumberFormats
->getByKey(nFormat
)->getPropertyValue( OUString( LOCALE
) ) >>= aRangeLocale
;
411 sal_Int32 nNewFormat
= xNumberFormats
->queryKey(sLocalFormatString
, aRangeLocale
, sal_True
);
413 if (nNewFormat
== -1)
414 nNewFormat
= xNumberFormats
->addNew(sLocalFormatString
, aRangeLocale
);
415 mxPropertySet
->setPropertyValue(sNumFormat
, uno::makeAny( nNewFormat
));
417 catch (const uno::Exception
& )
419 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
423 template< typename Ifc1
>
425 ScVbaFormat
<Ifc1
>::setNumberFormat( const uno::Any
& _oFormatString
) throw (script::BasicErrorException
, uno::RuntimeException
)
429 OUString sFormatString
;
430 if ( !( _oFormatString
>>= sFormatString
) )
431 throw uno::RuntimeException();
433 sFormatString
= sFormatString
.toAsciiUpperCase();
435 lang::Locale aDefaultLocale
= m_aDefaultLocale
;
436 initializeNumberFormats();
437 sal_Int32 nFormat
= xNumberFormats
->queryKey(sFormatString
, aDefaultLocale
, sal_True
);
440 nFormat
= xNumberFormats
->addNew(sFormatString
, aDefaultLocale
);
442 lang::Locale aRangeLocale
;
443 xNumberFormats
->getByKey(nFormat
)->getPropertyValue( OUString( LOCALE
) ) >>= aRangeLocale
;
444 sal_Int32 nNewFormat
= xNumberFormatTypes
->getFormatForLocale(nFormat
, aRangeLocale
);
445 mxPropertySet
->setPropertyValue( OUString( SC_UNO_DP_NUMBERFO
), uno::makeAny( nNewFormat
));
447 catch (const uno::Exception
& )
449 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
454 template< typename Ifc1
>
456 ScVbaFormat
<Ifc1
>::setIndentLevel( const uno::Any
& _aLevel
) throw (script::BasicErrorException
, uno::RuntimeException
)
460 sal_Int32 nLevel
= 0;
461 if ( !(_aLevel
>>= nLevel
) )
462 throw uno::RuntimeException();
463 table::CellHoriJustify aAPIAlignment
= table::CellHoriJustify_STANDARD
;
465 OUString
sHoriJust( SC_UNONAME_CELLHJUS
);
466 if ( !( mxPropertySet
->getPropertyValue(sHoriJust
) >>= aAPIAlignment
) )
467 throw uno::RuntimeException();
468 if (aAPIAlignment
== table::CellHoriJustify_STANDARD
)
469 mxPropertySet
->setPropertyValue( sHoriJust
, uno::makeAny( table::CellHoriJustify_LEFT
) ) ;
470 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_PINDENT
), uno::makeAny( sal_Int16(nLevel
* 352.8) ) );
472 catch (const uno::Exception
&)
474 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
478 template< typename Ifc1
>
480 ScVbaFormat
<Ifc1
>::getIndentLevel( ) throw (script::BasicErrorException
, uno::RuntimeException
)
482 uno::Any NRetIndentLevel
= aNULL();
485 OUString
sParaIndent( SC_UNONAME_PINDENT
);
486 if (!isAmbiguous(sParaIndent
))
488 sal_Int16 IndentLevel
= 0;
489 if ( ( mxPropertySet
->getPropertyValue(sParaIndent
) >>= IndentLevel
) )
490 NRetIndentLevel
= uno::makeAny( sal_Int32( rtl::math::round(static_cast<double>( IndentLevel
) / 352.8)) );
492 NRetIndentLevel
= uno::makeAny( sal_Int32(0) );
495 catch (const uno::Exception
&)
497 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
499 return NRetIndentLevel
;
502 template< typename Ifc1
>
504 ScVbaFormat
<Ifc1
>::setLocked( const uno::Any
& _aLocked
) throw (script::BasicErrorException
, uno::RuntimeException
)
508 bool bIsLocked
= false;
509 if ( !( _aLocked
>>= bIsLocked
) )
510 throw uno::RuntimeException();
511 util::CellProtection aCellProtection
;
512 OUString
sCellProt( SC_UNONAME_CELLPRO
);
513 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
514 aCellProtection
.IsLocked
= bIsLocked
;
515 mxPropertySet
->setPropertyValue(sCellProt
, uno::makeAny( aCellProtection
) );
517 catch (const uno::Exception
&)
519 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
523 template< typename Ifc1
>
525 ScVbaFormat
<Ifc1
>::setFormulaHidden( const uno::Any
& FormulaHidden
) throw (script::BasicErrorException
, uno::RuntimeException
)
529 bool bIsFormulaHidden
= false;
530 FormulaHidden
>>= bIsFormulaHidden
;
531 util::CellProtection aCellProtection
;
532 OUString
sCellProt( SC_UNONAME_CELLPRO
);
533 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
534 aCellProtection
.IsFormulaHidden
= bIsFormulaHidden
;
535 mxPropertySet
->setPropertyValue(sCellProt
,uno::makeAny(aCellProtection
));
537 catch (const uno::Exception
&)
539 DebugHelper::basicexception( SbERR_METHOD_FAILED
, OUString() );
543 template< typename Ifc1
>
545 ScVbaFormat
<Ifc1
>::getLocked( ) throw (script::BasicErrorException
, uno::RuntimeException
)
547 uno::Any aCellProtection
= aNULL();
550 OUString
sCellProt( SC_UNONAME_CELLPRO
);
552 if (!isAmbiguous(sCellProt
))
554 SfxItemSet
* pDataSet
= getCurrentDataSet();
557 const ScProtectionAttr
& rProtAttr
= static_cast<const ScProtectionAttr
&>( pDataSet
->Get(ATTR_PROTECTION
, true) );
558 SfxItemState eState
= pDataSet
->GetItemState(ATTR_PROTECTION
, true, NULL
);
559 if(eState
!= SfxItemState::DONTCARE
)
560 aCellProtection
= uno::makeAny(rProtAttr
.GetProtection());
562 else // fallback to propertyset
564 util::CellProtection cellProtection
;
565 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
566 aCellProtection
= uno::makeAny( cellProtection
.IsLocked
);
570 catch (const uno::Exception
&)
572 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
574 return aCellProtection
;
577 template< typename Ifc1
>
579 ScVbaFormat
<Ifc1
>::getFormulaHidden( ) throw (script::BasicErrorException
, uno::RuntimeException
)
581 uno::Any aBoolRet
= aNULL();
584 OUString
sCellProt( SC_UNONAME_CELLPRO
);
585 if (!isAmbiguous(sCellProt
))
587 SfxItemSet
* pDataSet
= getCurrentDataSet();
590 const ScProtectionAttr
& rProtAttr
= static_cast<const ScProtectionAttr
&>( pDataSet
->Get(ATTR_PROTECTION
, true) );
591 SfxItemState eState
= pDataSet
->GetItemState(ATTR_PROTECTION
, true, NULL
);
592 if(eState
!= SfxItemState::DONTCARE
)
593 aBoolRet
= uno::makeAny(rProtAttr
.GetHideFormula());
597 util::CellProtection aCellProtection
;
598 mxPropertySet
->getPropertyValue(sCellProt
) >>= aCellProtection
;
599 aBoolRet
= uno::makeAny( aCellProtection
.IsFormulaHidden
);
603 catch (const uno::Exception
&)
605 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
610 template< typename Ifc1
>
612 ScVbaFormat
<Ifc1
>::setShrinkToFit( const uno::Any
& ShrinkToFit
) throw (script::BasicErrorException
, uno::RuntimeException
)
616 mxPropertySet
->setPropertyValue(OUString( SC_UNONAME_SHRINK_TO_FIT
), ShrinkToFit
);
618 catch (const uno::Exception
& )
620 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString() );
625 template< typename Ifc1
>
627 ScVbaFormat
<Ifc1
>::getShrinkToFit( ) throw (script::BasicErrorException
, uno::RuntimeException
)
629 uno::Any aRet
= aNULL();
632 OUString
sShrinkToFit( SC_UNONAME_SHRINK_TO_FIT
);
633 if (!isAmbiguous(sShrinkToFit
))
634 aRet
= mxPropertySet
->getPropertyValue(sShrinkToFit
);
636 catch (const uno::Exception
& )
638 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
643 template< typename Ifc1
>
645 ScVbaFormat
<Ifc1
>::setReadingOrder( const uno::Any
& ReadingOrder
) throw (script::BasicErrorException
, uno::RuntimeException
)
649 sal_Int32 nReadingOrder
= 0;
650 if ( !(ReadingOrder
>>= nReadingOrder
))
651 throw uno::RuntimeException();
653 switch(nReadingOrder
)
655 case excel::Constants::xlLTR
:
656 aVal
= uno::makeAny( text::WritingMode_LR_TB
);
658 case excel::Constants::xlRTL
:
659 aVal
= uno::makeAny( text::WritingMode_RL_TB
);
661 case excel::Constants::xlContext
:
662 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
665 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
667 mxPropertySet
->setPropertyValue( OUString( SC_UNONAME_WRITING
), aVal
);
669 catch (const uno::Exception
& )
671 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
676 template< typename Ifc1
>
678 ScVbaFormat
<Ifc1
>::getReadingOrder( ) throw (script::BasicErrorException
, uno::RuntimeException
)
680 uno::Any NRetReadingOrder
= aNULL();
683 OUString
sWritingMode( SC_UNONAME_WRITING
);
684 if (!isAmbiguous(sWritingMode
))
686 text::WritingMode aWritingMode
= text::WritingMode_LR_TB
;
687 if ( ( mxPropertySet
->getPropertyValue(sWritingMode
) ) >>= aWritingMode
)
688 switch (aWritingMode
){
689 case text::WritingMode_LR_TB
:
690 NRetReadingOrder
= uno::makeAny(excel::Constants::xlLTR
);
692 case text::WritingMode_RL_TB
:
693 NRetReadingOrder
= uno::makeAny(excel::Constants::xlRTL
);
696 NRetReadingOrder
= uno::makeAny(excel::Constants::xlRTL
);
700 catch (const uno::Exception
& )
702 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
704 return NRetReadingOrder
;
708 template< typename Ifc1
>
710 ScVbaFormat
< Ifc1
>::getNumberFormat( ) throw (script::BasicErrorException
, uno::RuntimeException
)
712 uno::Any aFormat
= aNULL();
715 sal_Int32 nFormat
= -1;
716 OUString
sNumFormat( SC_UNO_DP_NUMBERFO
);
717 if (!isAmbiguous(sNumFormat
) &&
718 ( mxPropertySet
->getPropertyValue(sNumFormat
) >>= nFormat
) )
720 initializeNumberFormats();
722 sal_Int32 nNewFormat
= xNumberFormatTypes
->getFormatForLocale(nFormat
, getDefaultLocale() );
724 xNumberFormats
->getByKey(nNewFormat
)->getPropertyValue( OUString( FORMATSTRING
)) >>= sFormat
;
725 aFormat
= uno::makeAny( sFormat
);
728 catch (const uno::Exception
& )
730 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
735 template< typename Ifc1
>
737 ScVbaFormat
<Ifc1
>::isAmbiguous(const OUString
& _sPropertyName
) throw ( script::BasicErrorException
)
739 bool bResult
= false;
742 if (mbCheckAmbiguoity
)
743 bResult
= ( getXPropertyState()->getPropertyState(_sPropertyName
) == beans::PropertyState_AMBIGUOUS_VALUE
);
745 catch (const uno::Exception
& )
747 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
752 template< typename Ifc1
>
754 ScVbaFormat
<Ifc1
>::initializeNumberFormats() throw ( script::BasicErrorException
, uno::RuntimeException
)
756 if ( !xNumberFormats
.is() )
758 mxNumberFormatsSupplier
.set( mxModel
, uno::UNO_QUERY_THROW
);
759 xNumberFormats
= mxNumberFormatsSupplier
->getNumberFormats();
760 xNumberFormatTypes
.set( xNumberFormats
, uno::UNO_QUERY
); // _THROW?
764 template< typename Ifc1
>
765 uno::Reference
< beans::XPropertyState
>
766 ScVbaFormat
<Ifc1
>::getXPropertyState() throw ( uno::RuntimeException
)
768 if ( !xPropertyState
.is() )
769 xPropertyState
.set( mxPropertySet
, uno::UNO_QUERY_THROW
);
770 return xPropertyState
;
773 template< typename Ifc1
>
775 ScVbaFormat
<Ifc1
>::getServiceImplName()
777 return OUString("ScVbaFormat");
780 template< typename Ifc1
>
781 uno::Sequence
< OUString
>
782 ScVbaFormat
<Ifc1
>::getServiceNames()
784 static uno::Sequence
< OUString
> aServiceNames
;
785 if ( aServiceNames
.getLength() == 0 )
787 aServiceNames
.realloc( 1 );
788 aServiceNames
[ 0 ] = "ooo.vba.excel.Format";
790 return aServiceNames
;
793 template< typename Ifc1
>
795 ScVbaFormat
<Ifc1
>::getCellRangesBase() throw ( ::uno::RuntimeException
)
797 return ScCellRangesBase::getImplementation( mxPropertySet
);
800 template< typename Ifc1
>
802 ScVbaFormat
<Ifc1
>::getCurrentDataSet( ) throw ( uno::RuntimeException
)
804 SfxItemSet
* pDataSet
= excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
806 throw uno::RuntimeException("Can't access Itemset for XPropertySet" );
810 template class ScVbaFormat
< excel::XStyle
>;
811 template class ScVbaFormat
< excel::XRange
>;
813 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */