LibreOffice Module sc (master) 1
vbaformat.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
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>
37
38#include <basic/sberrors.hxx>
39#include <rtl/math.hxx>
40
41#include "excelvbahelper.hxx"
42#include "vbaborders.hxx"
43#include "vbapalette.hxx"
44#include "vbafont.hxx"
45#include "vbainterior.hxx"
46
47#include <docsh.hxx>
48#include <unonames.hxx>
49#include <cellsuno.hxx>
50#include <scitems.hxx>
51#include <attrib.hxx>
52#include <utility>
53
54using namespace ::ooo::vba;
55using namespace ::com::sun::star;
56
57constexpr OUStringLiteral FORMATSTRING = u"FormatString";
58constexpr OUStringLiteral LOCALE = u"Locale";
59
60template< typename... Ifc >
61ScVbaFormat< 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( "en", "US", OUString() ),
68 mxPropertySet(std::move( _xPropertySet )),
69 mxModel(std::move( xModel )),
70 mbCheckAmbiguoity( bCheckAmbiguoity ),
71 mbAddIndent( false )
72{
73 try
74 {
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.
79 }
80 catch (const uno::Exception& )
81 {
82 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
83 }
84}
85
86template< typename... Ifc >
87void SAL_CALL
89{
90 try
91 {
92 uno::Any aVal;
93 sal_Int32 nAlignment = 0;
94 if ( !(_oAlignment >>= nAlignment ))
95 throw uno::RuntimeException();
96 switch (nAlignment)
97 {
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;
108
109 case excel::XlVAlign::xlVAlignTop:
110 aVal <<= table::CellVertJustify2::TOP;
111 break;
112 default:
113 aVal <<= table::CellVertJustify2::STANDARD;
114 break;
115 }
116 mxPropertySet->setPropertyValue( SC_UNONAME_CELLVJUS, aVal );
117 }
118 catch (const uno::Exception&)
119 {
120 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
121 }
122}
123
124template< typename... Ifc >
125uno::Any SAL_CALL
127{
128 uno::Any aResult = aNULL();
129 try
130 {
131 if (!isAmbiguous( SC_UNONAME_CELLVJUS ) )
132 {
133 sal_Int32 aAPIAlignment = table::CellVertJustify2::STANDARD;
134 mxPropertySet->getPropertyValue( SC_UNONAME_CELLVJUS ) >>= aAPIAlignment;
135 switch( aAPIAlignment )
136 {
137 case table::CellVertJustify2::BOTTOM:
138 aResult <<= excel::XlVAlign::xlVAlignBottom;
139 break;
140 case table::CellVertJustify2::CENTER:
141 aResult <<= excel::XlVAlign::xlVAlignCenter;
142 break;
143 case table::CellVertJustify2::STANDARD:
144 aResult <<= excel::XlVAlign::xlVAlignBottom;
145 break;
146 case table::CellVertJustify2::TOP:
147 aResult <<= excel::XlVAlign::xlVAlignTop;
148 break;
149 default:
150 break;
151 }
152 }
153 }
154 catch (const uno::Exception& )
155 {
156 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
157 }
158 return aResult;
159}
160
161template< typename... Ifc >
162void SAL_CALL
164{
165 try
166 {
167 uno::Any aVal;
168 sal_Int32 nAlignment = 0;
169 if ( !( HorizontalAlignment >>= nAlignment ) )
170 throw uno::RuntimeException();
171 switch ( nAlignment )
172 {
173 case excel::XlHAlign::xlHAlignJustify:
174 aVal <<= table::CellHoriJustify_BLOCK;
175 break;
176 case excel::XlHAlign::xlHAlignCenter:
177 aVal <<= table::CellHoriJustify_CENTER;
178 break;
179 case excel::XlHAlign::xlHAlignDistributed:
180 aVal <<= table::CellHoriJustify_BLOCK;
181 break;
182 case excel::XlHAlign::xlHAlignLeft:
183 aVal <<= table::CellHoriJustify_LEFT;
184 break;
185 case excel::XlHAlign::xlHAlignRight:
186 aVal <<= table::CellHoriJustify_RIGHT;
187 break;
188 }
189 // #FIXME what about the default case above?
190 // shouldn't need the test below
191 if ( aVal.hasValue() )
192 mxPropertySet->setPropertyValue( SC_UNONAME_CELLHJUS, aVal );
193 }
194 catch (const uno::Exception& )
195 {
196 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
197 }
198
199}
200
201template< typename... Ifc >
202uno::Any SAL_CALL
204{
205 uno::Any NRetAlignment = aNULL();
206 try
207 {
208 OUString sHoriJust( SC_UNONAME_CELLHJUS );
209 if (!isAmbiguous(sHoriJust))
210 {
211 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_BLOCK;
212
213 if ( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment )
214 {
215 switch( aAPIAlignment )
216 {
217 case table::CellHoriJustify_BLOCK:
218 NRetAlignment <<= excel::XlHAlign::xlHAlignJustify;
219 break;
220 case table::CellHoriJustify_CENTER:
221 NRetAlignment <<= excel::XlHAlign::xlHAlignCenter;
222 break;
223 case table::CellHoriJustify_LEFT:
224 NRetAlignment <<= excel::XlHAlign::xlHAlignLeft;
225 break;
226 case table::CellHoriJustify_RIGHT:
227 NRetAlignment <<= excel::XlHAlign::xlHAlignRight;
228 break;
229 default: // handle those other cases with a NULL return
230 break;
231 }
232 }
233 }
234 }
235 catch (const uno::Exception& )
236 {
237 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
238 }
239 return NRetAlignment;
240}
241
242template< typename... Ifc >
243void SAL_CALL
245{
246 try
247 {
248 sal_Int32 nOrientation = 0;
249 if ( !( _aOrientation >>= nOrientation ) )
250 throw uno::RuntimeException();
251 uno::Any aVal;
252 switch( nOrientation )
253 {
254 case excel::XlOrientation::xlDownward:
255 aVal <<= table::CellOrientation_TOPBOTTOM;
256 break;
257 case excel::XlOrientation::xlHorizontal:
258 aVal <<= table::CellOrientation_STANDARD;
259 mxPropertySet->setPropertyValue( SC_UNONAME_ROTANG, uno::Any( sal_Int32(0) ) );
260 break;
261 case excel::XlOrientation::xlUpward:
262 aVal <<= table::CellOrientation_BOTTOMTOP;
263 break;
264 case excel::XlOrientation::xlVertical:
265 aVal <<= table::CellOrientation_STACKED;
266 break;
267 }
268 // #FIXME what about the default case above?
269 // shouldn't need the test below
270 if ( aVal.hasValue() )
271 mxPropertySet->setPropertyValue( SC_UNONAME_CELLORI, aVal );
272
273 }
274 catch (const uno::Exception& )
275 {
276 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
277 }
278}
279template< typename... Ifc >
280uno::Any SAL_CALL
282{
283 uno::Any NRetOrientation = aNULL();
284 try
285 {
286 if (!isAmbiguous(SC_UNONAME_CELLORI))
287 {
288 table::CellOrientation aOrientation = table::CellOrientation_STANDARD;
289 if ( !( mxPropertySet->getPropertyValue( SC_UNONAME_CELLORI ) >>= aOrientation ) )
290 throw uno::RuntimeException();
291
292 switch(aOrientation)
293 {
294 case table::CellOrientation_STANDARD:
295 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
296 break;
297 case table::CellOrientation_BOTTOMTOP:
298 NRetOrientation <<= excel::XlOrientation::xlUpward;
299 break;
300 case table::CellOrientation_TOPBOTTOM:
301 NRetOrientation <<= excel::XlOrientation::xlDownward;
302 break;
303 case table::CellOrientation_STACKED:
304 NRetOrientation <<= excel::XlOrientation::xlVertical;
305 break;
306 default:
307 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
308 }
309 }
310 }
311 catch (const uno::Exception& )
312 {
313 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
314 }
315 return NRetOrientation;
316}
317
318template< typename... Ifc >
319void SAL_CALL
321{
322 try
323 {
324 mxPropertySet->setPropertyValue( SC_UNONAME_WRAP, _aWrapText);
325 }
326 catch (const uno::Exception& )
327 {
328 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
329 }
330}
331
332template< typename... Ifc >
333uno::Any SAL_CALL
335{
336 uno::Any aWrap = aNULL();
337 try
338 {
339 OUString aPropName( SC_UNONAME_WRAP );
340 if (!isAmbiguous( aPropName ))
341 {
342 aWrap = mxPropertySet->getPropertyValue(aPropName);
343 }
344 }
345 catch (const uno::Exception&)
346 {
347 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
348 }
349 return aWrap;
350}
351
352template< typename... Ifc >
353uno::Any SAL_CALL
355{
357 uno::Reference< XCollection > xColl = new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext, uno::Reference< table::XCellRange >( mxPropertySet, uno::UNO_QUERY_THROW ), aPalette );
358
359 if ( Index.hasValue() )
360 {
361 return xColl->Item( Index, uno::Any() );
362 }
363 return uno::Any( xColl );
364}
365
366template< typename... Ifc >
367uno::Reference< excel::XFont > SAL_CALL
369{
371 return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext, aPalette, mxPropertySet );
372}
373
374template< typename... Ifc >
375uno::Reference< excel::XInterior > SAL_CALL
377{
378 return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext, mxPropertySet );
379}
380
381template< typename... Ifc >
382uno::Any SAL_CALL
384{
385 uno::Any aRet{ OUString() };
386 try
387 {
388 OUString sPropName( SC_UNO_DP_NUMBERFO );
389 if (!isAmbiguous( sPropName ))
390 {
391
392 initializeNumberFormats();
393
394 sal_Int32 nFormat = 0;
395 if ( ! (mxPropertySet->getPropertyValue( sPropName ) >>= nFormat ) )
396 throw uno::RuntimeException();
397
398 OUString sFormat;
399 xNumberFormats->getByKey(nFormat)->getPropertyValue( FORMATSTRING ) >>= sFormat;
400 aRet <<= sFormat.toAsciiLowerCase();
401
402 }
403 }
404 catch (const uno::Exception&)
405 {
406 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
407 }
408 return aRet;
409
410}
411
412template< typename... Ifc >
413void SAL_CALL
415{
416 try
417 {
418 OUString sLocalFormatString;
419 sal_Int32 nFormat = -1;
420 OUString sNumFormat( SC_UNO_DP_NUMBERFO );
421 if ( !(_oLocalFormatString >>= sLocalFormatString )
422 || !( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat ) )
423 throw uno::RuntimeException();
424
425 sLocalFormatString = sLocalFormatString.toAsciiUpperCase();
426 initializeNumberFormats();
427 lang::Locale aRangeLocale;
428 xNumberFormats->getByKey(nFormat)->getPropertyValue( LOCALE ) >>= aRangeLocale;
429 sal_Int32 nNewFormat = xNumberFormats->queryKey(sLocalFormatString, aRangeLocale, true);
430
431 if (nNewFormat == -1)
432 nNewFormat = xNumberFormats->addNew(sLocalFormatString, aRangeLocale);
433 mxPropertySet->setPropertyValue(sNumFormat, uno::Any( nNewFormat ));
434 }
435 catch (const uno::Exception& )
436 {
437 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
438 }
439}
440
441template< typename... Ifc >
442void SAL_CALL
444{
445 try
446 {
447 OUString sFormatString;
448 if ( !( _oFormatString >>= sFormatString ) )
449 throw uno::RuntimeException();
450
451 sFormatString = sFormatString.toAsciiUpperCase();
452
453 lang::Locale aDefaultLocale = m_aDefaultLocale;
454 initializeNumberFormats();
455 sal_Int32 nFormat = xNumberFormats->queryKey(sFormatString, aDefaultLocale, true);
456
457 if (nFormat == -1)
458 nFormat = xNumberFormats->addNew(sFormatString, aDefaultLocale);
459
460 lang::Locale aRangeLocale;
461 xNumberFormats->getByKey(nFormat)->getPropertyValue( LOCALE ) >>= aRangeLocale;
462 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, aRangeLocale);
463 mxPropertySet->setPropertyValue( SC_UNO_DP_NUMBERFO, uno::Any( nNewFormat));
464 }
465 catch (const uno::Exception& )
466 {
467 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
468 }
469
470}
471
472template< typename... Ifc >
473void SAL_CALL
475{
476 try
477 {
478 sal_Int32 nLevel = 0;
479 if ( !(_aLevel >>= nLevel ) )
480 throw uno::RuntimeException();
481 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_STANDARD;
482
483 OUString sHoriJust( SC_UNONAME_CELLHJUS );
484 if ( !( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) )
485 throw uno::RuntimeException();
486 if (aAPIAlignment == table::CellHoriJustify_STANDARD)
487 mxPropertySet->setPropertyValue( sHoriJust, uno::Any( table::CellHoriJustify_LEFT) ) ;
488 mxPropertySet->setPropertyValue( SC_UNONAME_PINDENT, uno::Any( sal_Int16(nLevel * 352.8) ) );
489 }
490 catch (const uno::Exception&)
491 {
492 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
493 }
494}
495
496template< typename... Ifc >
497uno::Any SAL_CALL
499{
500 uno::Any NRetIndentLevel = aNULL();
501 try
502 {
503 OUString sParaIndent( SC_UNONAME_PINDENT );
504 if (!isAmbiguous(sParaIndent))
505 {
506 sal_Int16 IndentLevel = 0;
507 if ( mxPropertySet->getPropertyValue(sParaIndent) >>= IndentLevel )
508 NRetIndentLevel <<= sal_Int32( rtl::math::round(static_cast<double>( IndentLevel ) / 352.8));
509 else
510 NRetIndentLevel <<= sal_Int32(0);
511 }
512 }
513 catch (const uno::Exception&)
514 {
515 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
516 }
517 return NRetIndentLevel;
518}
519
520template< typename... Ifc >
521void SAL_CALL
523{
524 try
525 {
526 bool bIsLocked = false;
527 if ( !( _aLocked >>= bIsLocked ) )
528 throw uno::RuntimeException();
529 util::CellProtection aCellProtection;
530 OUString sCellProt( SC_UNONAME_CELLPRO );
531 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
532 aCellProtection.IsLocked = bIsLocked;
533 mxPropertySet->setPropertyValue(sCellProt, uno::Any( aCellProtection ) );
534 }
535 catch (const uno::Exception&)
536 {
537 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
538 }
539}
540
541template< typename... Ifc >
542void SAL_CALL
544{
545 try
546 {
547 bool bIsFormulaHidden = false;
548 FormulaHidden >>= bIsFormulaHidden;
549 util::CellProtection aCellProtection;
550 OUString sCellProt( SC_UNONAME_CELLPRO );
551 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
552 aCellProtection.IsFormulaHidden = bIsFormulaHidden;
553 mxPropertySet->setPropertyValue(sCellProt,uno::Any(aCellProtection));
554 }
555 catch (const uno::Exception&)
556 {
557 DebugHelper::basicexception( ERRCODE_BASIC_METHOD_FAILED, {} );
558 }
559}
560
561template< typename... Ifc >
562uno::Any SAL_CALL
564{
565 uno::Any aCellProtection = aNULL();
566 try
567 {
568 OUString sCellProt( SC_UNONAME_CELLPRO );
569
570 if (!isAmbiguous(sCellProt))
571 {
572 SfxItemSet* pDataSet = getCurrentDataSet();
573 if ( pDataSet )
574 {
575 const ScProtectionAttr& rProtAttr = pDataSet->Get(ATTR_PROTECTION);
576 SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION);
577 if(eState != SfxItemState::DONTCARE)
578 aCellProtection <<= rProtAttr.GetProtection();
579 }
580 else // fallback to propertyset
581 {
582 util::CellProtection cellProtection;
583 mxPropertySet->getPropertyValue(sCellProt) >>= cellProtection;
584 aCellProtection <<= cellProtection.IsLocked;
585 }
586 }
587 }
588 catch (const uno::Exception&)
589 {
590 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
591 }
592 return aCellProtection;
593}
594
595template< typename... Ifc >
596uno::Any SAL_CALL
598{
599 uno::Any aBoolRet = aNULL();
600 try
601 {
602 OUString sCellProt( SC_UNONAME_CELLPRO );
603 if (!isAmbiguous(sCellProt))
604 {
605 SfxItemSet* pDataSet = getCurrentDataSet();
606 if ( pDataSet )
607 {
608 const ScProtectionAttr& rProtAttr = pDataSet->Get(ATTR_PROTECTION);
609 SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION);
610 if(eState != SfxItemState::DONTCARE)
611 aBoolRet <<= rProtAttr.GetHideFormula();
612 }
613 else
614 {
615 util::CellProtection aCellProtection;
616 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
617 aBoolRet <<= aCellProtection.IsFormulaHidden;
618 }
619 }
620 }
621 catch (const uno::Exception&)
622 {
623 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
624 }
625 return aBoolRet;
626}
627
628template< typename... Ifc >
629void SAL_CALL
631{
632 try
633 {
634 mxPropertySet->setPropertyValue( SC_UNONAME_SHRINK_TO_FIT, ShrinkToFit);
635 }
636 catch (const uno::Exception& )
637 {
638 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {} );
639 }
640
641}
642
643template< typename... Ifc >
644uno::Any SAL_CALL
646{
647 uno::Any aRet = aNULL();
648 try
649 {
650 OUString sShrinkToFit( SC_UNONAME_SHRINK_TO_FIT );
651 if (!isAmbiguous(sShrinkToFit))
652 aRet = mxPropertySet->getPropertyValue(sShrinkToFit);
653 }
654 catch (const uno::Exception& )
655 {
656 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
657 }
658 return aRet;
659}
660
661template< typename... Ifc >
662void SAL_CALL
664{
665 try
666 {
667 sal_Int32 nReadingOrder = 0;
668 if ( !(ReadingOrder >>= nReadingOrder ))
669 throw uno::RuntimeException();
670 uno::Any aVal = aNULL();
671 switch(nReadingOrder)
672 {
673 case excel::Constants::xlLTR:
674 aVal <<= sal_Int16(text::WritingMode_LR_TB);
675 break;
676 case excel::Constants::xlRTL:
677 aVal <<= sal_Int16(text::WritingMode_RL_TB);
678 break;
679 case excel::Constants::xlContext:
680 // TODO implement xlContext
681 // Reading order has to depend on the language of the first letter
682 // written.
683 aVal <<= sal_Int16(text::WritingMode_LR_TB);
684 break;
685 default:
686 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
687 }
688 mxPropertySet->setPropertyValue( SC_UNONAME_WRITING, aVal );
689 }
690 catch (const uno::Exception& )
691 {
692 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
693 }
694
695}
696
697template< typename... Ifc >
698uno::Any SAL_CALL
700{
701 uno::Any NRetReadingOrder = aNULL();
702 try
703 {
704 OUString sWritingMode( SC_UNONAME_WRITING );
705 if (!isAmbiguous(sWritingMode))
706 {
707 text::WritingMode aWritingMode = text::WritingMode_LR_TB;
708 if ( ( mxPropertySet->getPropertyValue(sWritingMode) ) >>= aWritingMode )
709 switch (aWritingMode)
710 {
711 case text::WritingMode_LR_TB:
712 NRetReadingOrder <<= excel::Constants::xlLTR;
713 break;
714 case text::WritingMode_RL_TB:
715 NRetReadingOrder <<= excel::Constants::xlRTL;
716 break;
717 default:
718 NRetReadingOrder <<= excel::Constants::xlRTL;
719 }
720 }
721 }
722 catch (const uno::Exception& )
723 {
724 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
725 }
726 return NRetReadingOrder;
727
728}
729
730template< typename... Ifc >
731uno::Any SAL_CALL
733{
734 uno::Any aFormat = aNULL();
735 try
736 {
737 sal_Int32 nFormat = -1;
738 OUString sNumFormat( SC_UNO_DP_NUMBERFO );
739 if (!isAmbiguous(sNumFormat) &&
740 ( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat) )
741 {
742 initializeNumberFormats();
743
744 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, m_aDefaultLocale );
745 OUString sFormat;
746 xNumberFormats->getByKey(nNewFormat)->getPropertyValue( FORMATSTRING ) >>= sFormat;
747 aFormat <<= sFormat;
748 }
749 }
750 catch (const uno::Exception& )
751 {
752 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
753 }
754 return aFormat;
755}
756
757template< typename... Ifc >
758bool
759ScVbaFormat< Ifc... >::isAmbiguous(const OUString& _sPropertyName)
760{
761 bool bResult = false;
762 try
763 {
764 if (mbCheckAmbiguoity)
765 bResult = ( getXPropertyState()->getPropertyState(_sPropertyName) == beans::PropertyState_AMBIGUOUS_VALUE );
766 }
767 catch (const uno::Exception& )
768 {
769 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
770 }
771 return bResult;
772}
773
774template< typename... Ifc >
775void
777{
778 if ( !xNumberFormats.is() )
779 {
780 mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW );
781 xNumberFormats = mxNumberFormatsSupplier->getNumberFormats();
782 xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY ); // _THROW?
783 }
784}
785
786template< typename... Ifc >
787uno::Reference< beans::XPropertyState > const &
789{
790 if ( !xPropertyState.is() )
791 xPropertyState.set( mxPropertySet, uno::UNO_QUERY_THROW );
792 return xPropertyState;
793}
794
795template< typename... Ifc >
798{
799 return comphelper::getFromUnoTunnel<ScCellRangesBase>( mxPropertySet );
800}
801
802template< typename... Ifc >
805{
806 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
807 if ( !pDataSet )
808 throw uno::RuntimeException("Can't access Itemset for XPropertySet" );
809 return pDataSet;
810}
811
812template class ScVbaFormat< excel::XStyle >;
813template class ScVbaFormat< excel::XRange >;
814
815/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
css::uno::Reference< css::frame::XModel2 > mxModel
bool GetHideFormula() const
Definition: attrib.hxx:145
bool GetProtection() const
Definition: attrib.hxx:143
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaformat.hxx:46
virtual void SAL_CALL setIndentLevel(const css::uno::Any &IndentLevel)
Definition: vbaformat.cxx:474
virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font()
Definition: vbaformat.cxx:368
virtual css::uno::Any SAL_CALL getLocked()
Definition: vbaformat.cxx:563
virtual css::uno::Any SAL_CALL getNumberFormatLocal()
Definition: vbaformat.cxx:383
virtual css::uno::Any SAL_CALL getWrapText()
Definition: vbaformat.cxx:334
void initializeNumberFormats()
Definition: vbaformat.cxx:776
virtual void SAL_CALL setNumberFormat(const css::uno::Any &NumberFormat)
Definition: vbaformat.cxx:443
virtual void SAL_CALL setFormulaHidden(const css::uno::Any &FormulaHidden)
Definition: vbaformat.cxx:543
bool isAmbiguous(const OUString &_sPropertyName)
Definition: vbaformat.cxx:759
virtual css::uno::Any SAL_CALL getReadingOrder()
Definition: vbaformat.cxx:699
virtual void SAL_CALL setOrientation(const css::uno::Any &Orientation)
Definition: vbaformat.cxx:244
virtual css::uno::Any SAL_CALL Borders(const css::uno::Any &Index)
Definition: vbaformat.cxx:354
virtual css::uno::Any SAL_CALL getVerticalAlignment()
Definition: vbaformat.cxx:126
virtual css::uno::Any SAL_CALL getIndentLevel()
Definition: vbaformat.cxx:498
virtual css::uno::Any SAL_CALL getFormulaHidden()
Definition: vbaformat.cxx:597
virtual void SAL_CALL setReadingOrder(const css::uno::Any &ReadingOrder)
Definition: vbaformat.cxx:663
virtual void SAL_CALL setHorizontalAlignment(const css::uno::Any &HorizontalAlignment)
Definition: vbaformat.cxx:163
ScVbaFormat(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::beans::XPropertySet > _xPropertySet, css::uno::Reference< css::frame::XModel > xModel, bool bCheckAmbiguoity)
Definition: vbaformat.cxx:61
SfxItemSet * getCurrentDataSet()
Definition: vbaformat.cxx:804
virtual void SAL_CALL setShrinkToFit(const css::uno::Any &ShrinkToFit)
Definition: vbaformat.cxx:630
css::uno::Reference< css::beans::XPropertyState > const & getXPropertyState()
Definition: vbaformat.cxx:788
virtual css::uno::Any SAL_CALL getOrientation()
Definition: vbaformat.cxx:281
virtual void SAL_CALL setVerticalAlignment(const css::uno::Any &VerticalAlignment)
Definition: vbaformat.cxx:88
virtual void SAL_CALL setWrapText(const css::uno::Any &WrapText)
Definition: vbaformat.cxx:320
virtual ScCellRangesBase * getCellRangesBase()
Definition: vbaformat.cxx:797
virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior()
Definition: vbaformat.cxx:376
virtual void SAL_CALL setNumberFormatLocal(const css::uno::Any &NumberFormatLocal)
Definition: vbaformat.cxx:414
virtual void SAL_CALL setLocked(const css::uno::Any &Locked)
Definition: vbaformat.cxx:522
virtual css::uno::Any SAL_CALL getHorizontalAlignment()
Definition: vbaformat.cxx:203
virtual css::uno::Any SAL_CALL getNumberFormat()
Definition: vbaformat.cxx:732
virtual css::uno::Any SAL_CALL getShrinkToFit()
Definition: vbaformat.cxx:645
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
float u
Reference< XPropertySet > _xPropertySet
OUString aPropName
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
const uno::Any & aNULL()
SfxItemState
#define ERRCODE_BASIC_METHOD_FAILED
#define ERRCODE_BASIC_NOT_IMPLEMENTED
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
bool hasValue()
Reference< XModel > xModel
#define SC_UNONAME_ROTANG
Definition: unonames.hxx:118
#define SC_UNONAME_CELLVJUS
Definition: unonames.hxx:103
#define SC_UNONAME_WRITING
Definition: unonames.hxx:121
#define SC_UNONAME_CELLHJUS
Definition: unonames.hxx:102
#define SC_UNONAME_WRAP
Definition: unonames.hxx:112
#define SC_UNONAME_CELLPRO
Definition: unonames.hxx:101
#define SC_UNONAME_PINDENT
Definition: unonames.hxx:113
#define SC_UNONAME_SHRINK_TO_FIT
Definition: unonames.hxx:140
#define SC_UNO_DP_NUMBERFO
Definition: unonames.hxx:614
#define SC_UNONAME_CELLORI
Definition: unonames.hxx:106
constexpr OUStringLiteral FORMATSTRING
Definition: vbaformat.cxx:57
constexpr OUStringLiteral LOCALE
Definition: vbaformat.cxx:58