fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbaformat.cxx
blobe2cff4b168efa96f4e875f83d98d1f5afd022a0b
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/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>
44 #include <attrib.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 )
55 try
57 if ( !mxModel.is() )
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 >
69 void SAL_CALL
70 ScVbaFormat<Ifc1>::setVerticalAlignment( const uno::Any& _oAlignment) throw (script::BasicErrorException, uno::RuntimeException)
72 try
74 uno::Any aVal;
75 sal_Int32 nAlignment = 0;
76 if ( !(_oAlignment >>= nAlignment ))
77 throw uno::RuntimeException();
78 switch (nAlignment)
80 case excel::XlVAlign::xlVAlignBottom :
81 aVal = uno::makeAny( table::CellVertJustify2::BOTTOM );
82 break;
83 case excel::XlVAlign::xlVAlignCenter :
84 aVal = uno::makeAny( table::CellVertJustify2::CENTER );
85 break;
86 case excel::XlVAlign::xlVAlignDistributed:
87 case excel::XlVAlign::xlVAlignJustify:
88 aVal = uno::makeAny( table::CellVertJustify2::STANDARD );
89 break;
91 case excel::XlVAlign::xlVAlignTop:
92 aVal = uno::makeAny( table::CellVertJustify2::TOP);
93 break;
94 default:
95 aVal = uno::makeAny( table::CellVertJustify2::STANDARD );
96 break;
98 mxPropertySet->setPropertyValue( OUString( SC_UNONAME_CELLVJUS ), aVal );
100 catch (const uno::Exception&)
102 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
106 template< typename Ifc1 >
107 uno::Any SAL_CALL
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 );
121 break;
122 case table::CellVertJustify2::CENTER:
123 aResult = uno::makeAny( excel::XlVAlign::xlVAlignCenter );
124 break;
125 case table::CellVertJustify2::STANDARD:
126 aResult = uno::makeAny( excel::XlVAlign::xlVAlignBottom );
127 break;
128 case table::CellVertJustify2::TOP:
129 aResult = uno::makeAny( excel::XlVAlign::xlVAlignTop );
130 break;
131 default:
132 break;
136 catch (const uno::Exception& )
138 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
140 return aResult;
143 template< typename Ifc1 >
144 void SAL_CALL
145 ScVbaFormat<Ifc1>::setHorizontalAlignment( const uno::Any& HorizontalAlignment ) throw (script::BasicErrorException, uno::RuntimeException)
149 uno::Any aVal;
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);
157 break;
158 case excel::XlHAlign::xlHAlignCenter:
159 aVal = uno::makeAny( table::CellHoriJustify_CENTER );
160 break;
161 case excel::XlHAlign::xlHAlignDistributed:
162 aVal = uno::makeAny( table::CellHoriJustify_BLOCK);
163 break;
164 case excel::XlHAlign::xlHAlignLeft:
165 aVal = uno::makeAny( table::CellHoriJustify_LEFT);
166 break;
167 case excel::XlHAlign::xlHAlignRight:
168 aVal = uno::makeAny( table::CellHoriJustify_RIGHT);
169 break;
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 >
184 uno::Any SAL_CALL
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 );
201 break;
202 case table::CellHoriJustify_CENTER:
203 NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignCenter );
204 break;
205 case table::CellHoriJustify_LEFT:
206 NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignLeft );
207 break;
208 case table::CellHoriJustify_RIGHT:
209 NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignRight );
210 break;
211 default: // handle those other cases with a NULL return
212 break;
217 catch (const uno::Exception& )
219 DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
221 return NRetAlignment;
224 template< typename Ifc1 >
225 void SAL_CALL
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();
233 uno::Any aVal;
234 switch( nOrientation )
236 case excel::XlOrientation::xlDownward:
237 aVal = uno::makeAny( table::CellOrientation_TOPBOTTOM);
238 break;
239 case excel::XlOrientation::xlHorizontal:
240 aVal = uno::makeAny( table::CellOrientation_STANDARD );
241 mxPropertySet->setPropertyValue( OUString( SC_UNONAME_ROTANG ), uno::makeAny( sal_Int32(0) ) );
242 break;
243 case excel::XlOrientation::xlUpward:
244 aVal = uno::makeAny( table::CellOrientation_BOTTOMTOP);
245 break;
246 case excel::XlOrientation::xlVertical:
247 aVal = uno::makeAny( table::CellOrientation_STACKED);
248 break;
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 >
262 uno::Any SAL_CALL
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();
274 switch(aOrientation)
276 case table::CellOrientation_STANDARD:
277 NRetOrientation = uno::makeAny( excel::XlOrientation::xlHorizontal );
278 break;
279 case table::CellOrientation_BOTTOMTOP:
280 NRetOrientation = uno::makeAny( excel::XlOrientation::xlUpward );
281 break;
282 case table::CellOrientation_TOPBOTTOM:
283 NRetOrientation = uno::makeAny( excel::XlOrientation::xlDownward );
284 break;
285 case table::CellOrientation_STACKED:
286 NRetOrientation = uno::makeAny( excel::XlOrientation::xlVertical );
287 break;
288 default:
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 >
301 void SAL_CALL
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 >
315 uno::Any SAL_CALL
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() );
331 return aWrap;
334 template< typename Ifc1 >
335 uno::Any SAL_CALL
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 >
364 uno::Any SAL_CALL
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();
380 OUString sFormat;
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());
390 return aRet;
394 template< typename Ifc1 >
395 void SAL_CALL
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 >
424 void SAL_CALL
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);
439 if (nFormat == -1)
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 >
455 void SAL_CALL
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 >
479 uno::Any SAL_CALL
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)) );
491 else
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 >
503 void SAL_CALL
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 >
524 void SAL_CALL
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 >
544 uno::Any SAL_CALL
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();
555 if ( pDataSet )
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 >
578 uno::Any SAL_CALL
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();
588 if ( pDataSet )
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());
595 else
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());
607 return aBoolRet;
610 template< typename Ifc1 >
611 void SAL_CALL
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 >
626 uno::Any SAL_CALL
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());
640 return aRet;
643 template< typename Ifc1 >
644 void SAL_CALL
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();
652 uno::Any aVal;
653 switch(nReadingOrder)
655 case excel::Constants::xlLTR:
656 aVal = uno::makeAny( text::WritingMode_LR_TB );
657 break;
658 case excel::Constants::xlRTL:
659 aVal = uno::makeAny( text::WritingMode_RL_TB );
660 break;
661 case excel::Constants::xlContext:
662 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED, OUString());
663 break;
664 default:
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 >
677 uno::Any SAL_CALL
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);
691 break;
692 case text::WritingMode_RL_TB:
693 NRetReadingOrder = uno::makeAny(excel::Constants::xlRTL);
694 break;
695 default:
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 >
709 uno::Any SAL_CALL
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() );
723 OUString sFormat;
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());
732 return aFormat;
735 template< typename Ifc1 >
736 bool
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());
749 return bResult;
752 template< typename Ifc1 >
753 void
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 >
774 OUString
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 >
794 ScCellRangesBase*
795 ScVbaFormat<Ifc1>::getCellRangesBase() throw ( ::uno::RuntimeException )
797 return ScCellRangesBase::getImplementation( mxPropertySet );
800 template< typename Ifc1 >
801 SfxItemSet*
802 ScVbaFormat<Ifc1>::getCurrentDataSet( ) throw ( uno::RuntimeException )
804 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
805 if ( !pDataSet )
806 throw uno::RuntimeException("Can't access Itemset for XPropertySet" );
807 return pDataSet;
810 template class ScVbaFormat< excel::XStyle >;
811 template class ScVbaFormat< excel::XRange >;
813 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */