tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbaformat.cxx
bloba866b7c6105e2501f65edcc46922503216c85830
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/XFont.hpp>
21 #include <ooo/vba/excel/XStyle.hpp>
22 #include <ooo/vba/excel/XlVAlign.hpp>
23 #include <ooo/vba/excel/XlHAlign.hpp>
24 #include <ooo/vba/excel/XlOrientation.hpp>
25 #include <ooo/vba/excel/Constants.hpp>
26 #include <ooo/vba/excel/XRange.hpp>
27 #include <com/sun/star/table/CellVertJustify2.hpp>
28 #include <com/sun/star/table/CellHoriJustify.hpp>
29 #include <com/sun/star/table/CellOrientation.hpp>
30 #include <com/sun/star/table/XCellRange.hpp>
31 #include <com/sun/star/text/WritingMode.hpp>
32 #include <com/sun/star/util/CellProtection.hpp>
33 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
34 #include <com/sun/star/util/XNumberFormats.hpp>
35 #include <com/sun/star/util/XNumberFormatTypes.hpp>
36 #include <com/sun/star/frame/XModel.hpp>
38 #include <basic/sberrors.hxx>
39 #include <rtl/math.hxx>
41 #include "excelvbahelper.hxx"
42 #include "vbaborders.hxx"
43 #include "vbapalette.hxx"
44 #include "vbafont.hxx"
45 #include "vbainterior.hxx"
47 #include <docsh.hxx>
48 #include <unonames.hxx>
49 #include <cellsuno.hxx>
50 #include <scitems.hxx>
51 #include <attrib.hxx>
52 #include <utility>
54 using namespace ::ooo::vba;
55 using namespace ::com::sun::star;
57 constexpr OUString FORMATSTRING = u"FormatString"_ustr;
58 constexpr OUString LOCALE = u"Locale"_ustr;
60 template< typename... Ifc >
61 ScVbaFormat< Ifc... >::ScVbaFormat( const uno::Reference< XHelperInterface >& xParent,
62 const uno::Reference< uno::XComponentContext > & xContext,
63 uno::Reference< beans::XPropertySet > _xPropertySet,
64 uno::Reference< frame::XModel > xModel,
65 bool bCheckAmbiguoity )
66 : ScVbaFormat_BASE( xParent, xContext ),
67 m_aDefaultLocale( u"en"_ustr, u"US"_ustr, OUString() ),
68 mxPropertySet(std::move( _xPropertySet )),
69 mxModel(std::move( xModel )),
70 mbCheckAmbiguoity( bCheckAmbiguoity ),
71 mbAddIndent( false )
73 try
75 if ( !mxModel.is() )
76 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, u"XModel Interface could not be retrieved" );
77 // mxServiceInfo is unused,
78 // mxNumberFormatsSupplier is initialized when needed in initializeNumberFormats.
80 catch (const uno::Exception& )
82 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
86 template< typename... Ifc >
87 void SAL_CALL
88 ScVbaFormat< Ifc... >::setVerticalAlignment( const uno::Any& _oAlignment)
90 try
92 uno::Any aVal;
93 sal_Int32 nAlignment = 0;
94 if ( !(_oAlignment >>= nAlignment ))
95 throw uno::RuntimeException();
96 switch (nAlignment)
98 case excel::XlVAlign::xlVAlignBottom :
99 aVal <<= table::CellVertJustify2::BOTTOM;
100 break;
101 case excel::XlVAlign::xlVAlignCenter :
102 aVal <<= table::CellVertJustify2::CENTER;
103 break;
104 case excel::XlVAlign::xlVAlignDistributed:
105 case excel::XlVAlign::xlVAlignJustify:
106 aVal <<= table::CellVertJustify2::STANDARD;
107 break;
109 case excel::XlVAlign::xlVAlignTop:
110 aVal <<= table::CellVertJustify2::TOP;
111 break;
112 default:
113 aVal <<= table::CellVertJustify2::STANDARD;
114 break;
116 mxPropertySet->setPropertyValue( SC_UNONAME_CELLVJUS, aVal );
118 catch (const uno::Exception&)
120 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
124 template< typename... Ifc >
125 uno::Any SAL_CALL
126 ScVbaFormat< Ifc... >::getVerticalAlignment( )
128 uno::Any aResult = aNULL();
131 if (!isAmbiguous( SC_UNONAME_CELLVJUS ) )
133 sal_Int32 aAPIAlignment = table::CellVertJustify2::STANDARD;
134 mxPropertySet->getPropertyValue( SC_UNONAME_CELLVJUS ) >>= aAPIAlignment;
135 switch( aAPIAlignment )
137 case table::CellVertJustify2::BOTTOM:
138 case table::CellVertJustify2::STANDARD:
139 aResult <<= excel::XlVAlign::xlVAlignBottom;
140 break;
141 case table::CellVertJustify2::CENTER:
142 aResult <<= excel::XlVAlign::xlVAlignCenter;
143 break;
144 case table::CellVertJustify2::TOP:
145 aResult <<= excel::XlVAlign::xlVAlignTop;
146 break;
147 default:
148 break;
152 catch (const uno::Exception& )
154 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
156 return aResult;
159 template< typename... Ifc >
160 void SAL_CALL
161 ScVbaFormat< Ifc... >::setHorizontalAlignment( const uno::Any& HorizontalAlignment )
165 uno::Any aVal;
166 sal_Int32 nAlignment = 0;
167 if ( !( HorizontalAlignment >>= nAlignment ) )
168 throw uno::RuntimeException();
169 switch ( nAlignment )
171 case excel::XlHAlign::xlHAlignJustify:
172 case excel::XlHAlign::xlHAlignDistributed:
173 aVal <<= table::CellHoriJustify_BLOCK;
174 break;
175 case excel::XlHAlign::xlHAlignCenter:
176 aVal <<= table::CellHoriJustify_CENTER;
177 break;
178 case excel::XlHAlign::xlHAlignLeft:
179 aVal <<= table::CellHoriJustify_LEFT;
180 break;
181 case excel::XlHAlign::xlHAlignRight:
182 aVal <<= table::CellHoriJustify_RIGHT;
183 break;
185 // #FIXME what about the default case above?
186 // shouldn't need the test below
187 if ( aVal.hasValue() )
188 mxPropertySet->setPropertyValue( SC_UNONAME_CELLHJUS, aVal );
190 catch (const uno::Exception& )
192 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
197 template< typename... Ifc >
198 uno::Any SAL_CALL
199 ScVbaFormat< Ifc... >::getHorizontalAlignment( )
201 uno::Any NRetAlignment = aNULL();
204 OUString sHoriJust( SC_UNONAME_CELLHJUS );
205 if (!isAmbiguous(sHoriJust))
207 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_BLOCK;
209 if ( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment )
211 switch( aAPIAlignment )
213 case table::CellHoriJustify_BLOCK:
214 NRetAlignment <<= excel::XlHAlign::xlHAlignJustify;
215 break;
216 case table::CellHoriJustify_CENTER:
217 NRetAlignment <<= excel::XlHAlign::xlHAlignCenter;
218 break;
219 case table::CellHoriJustify_LEFT:
220 NRetAlignment <<= excel::XlHAlign::xlHAlignLeft;
221 break;
222 case table::CellHoriJustify_RIGHT:
223 NRetAlignment <<= excel::XlHAlign::xlHAlignRight;
224 break;
225 default: // handle those other cases with a NULL return
226 break;
231 catch (const uno::Exception& )
233 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
235 return NRetAlignment;
238 template< typename... Ifc >
239 void SAL_CALL
240 ScVbaFormat< Ifc... >::setOrientation( const uno::Any& _aOrientation )
244 sal_Int32 nOrientation = 0;
245 if ( !( _aOrientation >>= nOrientation ) )
246 throw uno::RuntimeException();
247 uno::Any aVal;
248 switch( nOrientation )
250 case excel::XlOrientation::xlDownward:
251 aVal <<= table::CellOrientation_TOPBOTTOM;
252 break;
253 case excel::XlOrientation::xlHorizontal:
254 aVal <<= table::CellOrientation_STANDARD;
255 mxPropertySet->setPropertyValue( SC_UNONAME_ROTANG, uno::Any( sal_Int32(0) ) );
256 break;
257 case excel::XlOrientation::xlUpward:
258 aVal <<= table::CellOrientation_BOTTOMTOP;
259 break;
260 case excel::XlOrientation::xlVertical:
261 aVal <<= table::CellOrientation_STACKED;
262 break;
264 // #FIXME what about the default case above?
265 // shouldn't need the test below
266 if ( aVal.hasValue() )
267 mxPropertySet->setPropertyValue( SC_UNONAME_CELLORI, aVal );
270 catch (const uno::Exception& )
272 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
275 template< typename... Ifc >
276 uno::Any SAL_CALL
277 ScVbaFormat< Ifc... >::getOrientation( )
279 uno::Any NRetOrientation = aNULL();
282 if (!isAmbiguous(SC_UNONAME_CELLORI))
284 table::CellOrientation aOrientation = table::CellOrientation_STANDARD;
285 if ( !( mxPropertySet->getPropertyValue( SC_UNONAME_CELLORI ) >>= aOrientation ) )
286 throw uno::RuntimeException();
288 switch(aOrientation)
290 case table::CellOrientation_STANDARD:
291 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
292 break;
293 case table::CellOrientation_BOTTOMTOP:
294 NRetOrientation <<= excel::XlOrientation::xlUpward;
295 break;
296 case table::CellOrientation_TOPBOTTOM:
297 NRetOrientation <<= excel::XlOrientation::xlDownward;
298 break;
299 case table::CellOrientation_STACKED:
300 NRetOrientation <<= excel::XlOrientation::xlVertical;
301 break;
302 default:
303 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
307 catch (const uno::Exception& )
309 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
311 return NRetOrientation;
314 template< typename... Ifc >
315 void SAL_CALL
316 ScVbaFormat< Ifc... >::setWrapText( const uno::Any& _aWrapText )
320 mxPropertySet->setPropertyValue( SC_UNONAME_WRAP, _aWrapText);
322 catch (const uno::Exception& )
324 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
328 template< typename... Ifc >
329 uno::Any SAL_CALL
330 ScVbaFormat< Ifc... >::getWrapText( )
332 uno::Any aWrap = aNULL();
335 OUString aPropName( SC_UNONAME_WRAP );
336 if (!isAmbiguous( aPropName ))
338 aWrap = mxPropertySet->getPropertyValue(aPropName);
341 catch (const uno::Exception&)
343 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
345 return aWrap;
348 template< typename... Ifc >
349 uno::Any SAL_CALL
350 ScVbaFormat< Ifc... >::Borders( const uno::Any& Index )
352 ScVbaPalette aPalette( excel::getDocShell( mxModel ) );
353 uno::Reference< XCollection > xColl = new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext, uno::Reference< table::XCellRange >( mxPropertySet, uno::UNO_QUERY_THROW ), aPalette );
355 if ( Index.hasValue() )
357 return xColl->Item( Index, uno::Any() );
359 return uno::Any( xColl );
362 template< typename... Ifc >
363 uno::Reference< excel::XFont > SAL_CALL
364 ScVbaFormat< Ifc... >::Font( )
366 ScVbaPalette aPalette( excel::getDocShell( mxModel ) );
367 return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext, aPalette, mxPropertySet );
370 template< typename... Ifc >
371 uno::Reference< excel::XInterior > SAL_CALL
372 ScVbaFormat< Ifc... >::Interior( )
374 return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext, mxPropertySet );
377 template< typename... Ifc >
378 uno::Any SAL_CALL
379 ScVbaFormat< Ifc... >::getNumberFormatLocal( )
381 uno::Any aRet{ OUString() };
384 OUString sPropName( SC_UNO_DP_NUMBERFO );
385 if (!isAmbiguous( sPropName ))
388 initializeNumberFormats();
390 sal_Int32 nFormat = 0;
391 if ( ! (mxPropertySet->getPropertyValue( sPropName ) >>= nFormat ) )
392 throw uno::RuntimeException();
394 OUString sFormat;
395 xNumberFormats->getByKey(nFormat)->getPropertyValue( FORMATSTRING ) >>= sFormat;
396 aRet <<= sFormat.toAsciiLowerCase();
400 catch (const uno::Exception&)
402 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
404 return aRet;
408 template< typename... Ifc >
409 void SAL_CALL
410 ScVbaFormat< Ifc... >::setNumberFormatLocal( const uno::Any& _oLocalFormatString )
414 OUString sLocalFormatString;
415 sal_Int32 nFormat = -1;
416 OUString sNumFormat( SC_UNO_DP_NUMBERFO );
417 if ( !(_oLocalFormatString >>= sLocalFormatString )
418 || !( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat ) )
419 throw uno::RuntimeException();
421 sLocalFormatString = sLocalFormatString.toAsciiUpperCase();
422 initializeNumberFormats();
423 lang::Locale aRangeLocale;
424 xNumberFormats->getByKey(nFormat)->getPropertyValue( LOCALE ) >>= aRangeLocale;
425 sal_Int32 nNewFormat = xNumberFormats->queryKey(sLocalFormatString, aRangeLocale, true);
427 if (nNewFormat == -1)
428 nNewFormat = xNumberFormats->addNew(sLocalFormatString, aRangeLocale);
429 mxPropertySet->setPropertyValue(sNumFormat, uno::Any( nNewFormat ));
431 catch (const uno::Exception& )
433 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
437 template< typename... Ifc >
438 void SAL_CALL
439 ScVbaFormat< Ifc... >::setNumberFormat( const uno::Any& _oFormatString )
443 OUString sFormatString;
444 if ( !( _oFormatString >>= sFormatString ) )
445 throw uno::RuntimeException();
447 sFormatString = sFormatString.toAsciiUpperCase();
449 lang::Locale aDefaultLocale = m_aDefaultLocale;
450 initializeNumberFormats();
451 sal_Int32 nFormat = xNumberFormats->queryKey(sFormatString, aDefaultLocale, true);
453 if (nFormat == -1)
454 nFormat = xNumberFormats->addNew(sFormatString, aDefaultLocale);
456 lang::Locale aRangeLocale;
457 xNumberFormats->getByKey(nFormat)->getPropertyValue( LOCALE ) >>= aRangeLocale;
458 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, aRangeLocale);
459 mxPropertySet->setPropertyValue( SC_UNO_DP_NUMBERFO, uno::Any( nNewFormat));
461 catch (const uno::Exception& )
463 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
468 template< typename... Ifc >
469 void SAL_CALL
470 ScVbaFormat< Ifc... >::setIndentLevel( const uno::Any& _aLevel )
474 sal_Int32 nLevel = 0;
475 if ( !(_aLevel >>= nLevel ) )
476 throw uno::RuntimeException();
477 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_STANDARD;
479 OUString sHoriJust( SC_UNONAME_CELLHJUS );
480 if ( !( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) )
481 throw uno::RuntimeException();
482 if (aAPIAlignment == table::CellHoriJustify_STANDARD)
483 mxPropertySet->setPropertyValue( sHoriJust, uno::Any( table::CellHoriJustify_LEFT) ) ;
484 mxPropertySet->setPropertyValue( SC_UNONAME_PINDENT, uno::Any( sal_Int16(nLevel * 352.8) ) );
486 catch (const uno::Exception&)
488 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
492 template< typename... Ifc >
493 uno::Any SAL_CALL
494 ScVbaFormat< Ifc... >::getIndentLevel( )
496 uno::Any NRetIndentLevel = aNULL();
499 OUString sParaIndent( SC_UNONAME_PINDENT );
500 if (!isAmbiguous(sParaIndent))
502 sal_Int16 IndentLevel = 0;
503 if ( mxPropertySet->getPropertyValue(sParaIndent) >>= IndentLevel )
504 NRetIndentLevel <<= sal_Int32( rtl::math::round(static_cast<double>( IndentLevel ) / 352.8));
505 else
506 NRetIndentLevel <<= sal_Int32(0);
509 catch (const uno::Exception&)
511 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
513 return NRetIndentLevel;
516 template< typename... Ifc >
517 void SAL_CALL
518 ScVbaFormat< Ifc... >::setLocked( const uno::Any& _aLocked )
522 bool bIsLocked = false;
523 if ( !( _aLocked >>= bIsLocked ) )
524 throw uno::RuntimeException();
525 util::CellProtection aCellProtection;
526 OUString sCellProt( SC_UNONAME_CELLPRO );
527 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
528 aCellProtection.IsLocked = bIsLocked;
529 mxPropertySet->setPropertyValue(sCellProt, uno::Any( aCellProtection ) );
531 catch (const uno::Exception&)
533 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
537 template< typename... Ifc >
538 void SAL_CALL
539 ScVbaFormat< Ifc... >::setFormulaHidden( const uno::Any& FormulaHidden )
543 bool bIsFormulaHidden = false;
544 FormulaHidden >>= bIsFormulaHidden;
545 util::CellProtection aCellProtection;
546 OUString sCellProt( SC_UNONAME_CELLPRO );
547 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
548 aCellProtection.IsFormulaHidden = bIsFormulaHidden;
549 mxPropertySet->setPropertyValue(sCellProt,uno::Any(aCellProtection));
551 catch (const uno::Exception&)
553 DebugHelper::basicexception( ERRCODE_BASIC_METHOD_FAILED, {} );
557 template< typename... Ifc >
558 uno::Any SAL_CALL
559 ScVbaFormat< Ifc... >::getLocked( )
561 uno::Any aCellProtection = aNULL();
564 OUString sCellProt( SC_UNONAME_CELLPRO );
566 if (!isAmbiguous(sCellProt))
568 SfxItemSet* pDataSet = getCurrentDataSet();
569 if ( pDataSet )
571 const ScProtectionAttr& rProtAttr = pDataSet->Get(ATTR_PROTECTION);
572 SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION);
573 if(eState != SfxItemState::INVALID)
574 aCellProtection <<= rProtAttr.GetProtection();
576 else // fallback to propertyset
578 util::CellProtection cellProtection;
579 mxPropertySet->getPropertyValue(sCellProt) >>= cellProtection;
580 aCellProtection <<= cellProtection.IsLocked;
584 catch (const uno::Exception&)
586 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
588 return aCellProtection;
591 template< typename... Ifc >
592 uno::Any SAL_CALL
593 ScVbaFormat< Ifc... >::getFormulaHidden( )
595 uno::Any aBoolRet = aNULL();
598 OUString sCellProt( SC_UNONAME_CELLPRO );
599 if (!isAmbiguous(sCellProt))
601 SfxItemSet* pDataSet = getCurrentDataSet();
602 if ( pDataSet )
604 const ScProtectionAttr& rProtAttr = pDataSet->Get(ATTR_PROTECTION);
605 SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION);
606 if(eState != SfxItemState::INVALID)
607 aBoolRet <<= rProtAttr.GetHideFormula();
609 else
611 util::CellProtection aCellProtection;
612 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
613 aBoolRet <<= aCellProtection.IsFormulaHidden;
617 catch (const uno::Exception&)
619 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
621 return aBoolRet;
624 template< typename... Ifc >
625 void SAL_CALL
626 ScVbaFormat< Ifc... >::setShrinkToFit( const uno::Any& ShrinkToFit )
630 mxPropertySet->setPropertyValue( SC_UNONAME_SHRINK_TO_FIT, ShrinkToFit);
632 catch (const uno::Exception& )
634 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {} );
639 template< typename... Ifc >
640 uno::Any SAL_CALL
641 ScVbaFormat< Ifc... >::getShrinkToFit( )
643 uno::Any aRet = aNULL();
646 OUString sShrinkToFit( SC_UNONAME_SHRINK_TO_FIT );
647 if (!isAmbiguous(sShrinkToFit))
648 aRet = mxPropertySet->getPropertyValue(sShrinkToFit);
650 catch (const uno::Exception& )
652 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
654 return aRet;
657 template< typename... Ifc >
658 void SAL_CALL
659 ScVbaFormat< Ifc... >::setReadingOrder( const uno::Any& ReadingOrder )
663 sal_Int32 nReadingOrder = 0;
664 if ( !(ReadingOrder >>= nReadingOrder ))
665 throw uno::RuntimeException();
666 uno::Any aVal = aNULL();
667 switch(nReadingOrder)
669 case excel::Constants::xlLTR:
670 aVal <<= sal_Int16(text::WritingMode_LR_TB);
671 break;
672 case excel::Constants::xlRTL:
673 aVal <<= sal_Int16(text::WritingMode_RL_TB);
674 break;
675 case excel::Constants::xlContext:
676 // TODO implement xlContext
677 // Reading order has to depend on the language of the first letter
678 // written.
679 aVal <<= sal_Int16(text::WritingMode_LR_TB);
680 break;
681 default:
682 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
684 mxPropertySet->setPropertyValue( SC_UNONAME_WRITING, aVal );
686 catch (const uno::Exception& )
688 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
693 template< typename... Ifc >
694 uno::Any SAL_CALL
695 ScVbaFormat< Ifc... >::getReadingOrder( )
697 uno::Any NRetReadingOrder = aNULL();
700 OUString sWritingMode( SC_UNONAME_WRITING );
701 if (!isAmbiguous(sWritingMode))
703 text::WritingMode aWritingMode = text::WritingMode_LR_TB;
704 if ( ( mxPropertySet->getPropertyValue(sWritingMode) ) >>= aWritingMode )
705 switch (aWritingMode)
707 case text::WritingMode_LR_TB:
708 NRetReadingOrder <<= excel::Constants::xlLTR;
709 break;
710 case text::WritingMode_RL_TB:
711 NRetReadingOrder <<= excel::Constants::xlRTL;
712 break;
713 default:
714 NRetReadingOrder <<= excel::Constants::xlRTL;
718 catch (const uno::Exception& )
720 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
722 return NRetReadingOrder;
726 template< typename... Ifc >
727 uno::Any SAL_CALL
728 ScVbaFormat< Ifc... >::getNumberFormat( )
730 uno::Any aFormat = aNULL();
733 sal_Int32 nFormat = -1;
734 OUString sNumFormat( SC_UNO_DP_NUMBERFO );
735 if (!isAmbiguous(sNumFormat) &&
736 ( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat) )
738 initializeNumberFormats();
740 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, m_aDefaultLocale );
741 OUString sFormat;
742 xNumberFormats->getByKey(nNewFormat)->getPropertyValue( FORMATSTRING ) >>= sFormat;
743 aFormat <<= sFormat;
746 catch (const uno::Exception& )
748 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
750 return aFormat;
753 template< typename... Ifc >
754 bool
755 ScVbaFormat< Ifc... >::isAmbiguous(const OUString& _sPropertyName)
757 bool bResult = false;
760 if (mbCheckAmbiguoity)
761 bResult = ( getXPropertyState()->getPropertyState(_sPropertyName) == beans::PropertyState_AMBIGUOUS_VALUE );
763 catch (const uno::Exception& )
765 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
767 return bResult;
770 template< typename... Ifc >
771 void
772 ScVbaFormat< Ifc... >::initializeNumberFormats()
774 if ( !xNumberFormats.is() )
776 mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW );
777 xNumberFormats = mxNumberFormatsSupplier->getNumberFormats();
778 xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY ); // _THROW?
782 template< typename... Ifc >
783 uno::Reference< beans::XPropertyState > const &
784 ScVbaFormat< Ifc... >::getXPropertyState()
786 if ( !xPropertyState.is() )
787 xPropertyState.set( mxPropertySet, uno::UNO_QUERY_THROW );
788 return xPropertyState;
791 template< typename... Ifc >
792 ScCellRangesBase*
793 ScVbaFormat< Ifc... >::getCellRangesBase()
795 return dynamic_cast<ScCellRangesBase*>( mxPropertySet.get() );
798 template< typename... Ifc >
799 SfxItemSet*
800 ScVbaFormat< Ifc... >::getCurrentDataSet()
802 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
803 if ( !pDataSet )
804 throw uno::RuntimeException(u"Can't access Itemset for XPropertySet"_ustr );
805 return pDataSet;
808 template class ScVbaFormat< excel::XStyle >;
809 template class ScVbaFormat< excel::XRange >;
811 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */