LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbaformat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 365 0.0 %
Date: 2012-12-27 Functions: 0 66 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10