LCOV - code coverage report
Current view: top level - xmloff/source/forms - gridcolumnproptranslator.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 112 0.0 %
Date: 2012-08-25 Functions: 0 26 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 156 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "gridcolumnproptranslator.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      32                 :            : #include <com/sun/star/awt/TextAlign.hpp>
      33                 :            : #include <com/sun/star/style/ParagraphAdjust.hpp>
      34                 :            : #include <osl/diagnose.h>
      35                 :            : #include <cppuhelper/implbase1.hxx>
      36                 :            : 
      37                 :            : #include <algorithm>
      38                 :            : 
      39                 :            : //........................................................................
      40                 :            : namespace xmloff
      41                 :            : {
      42                 :            : //........................................................................
      43                 :            : 
      44                 :            :     using namespace ::com::sun::star::uno;
      45                 :            :     using namespace ::com::sun::star::awt;
      46                 :            :     using namespace ::com::sun::star::lang;
      47                 :            :     using namespace ::com::sun::star::beans;
      48                 :            :     using namespace ::com::sun::star::style;
      49                 :            : 
      50                 :            :     namespace
      51                 :            :     {
      52                 :            :         //----------------------------------------------------------------
      53                 :          0 :         ::rtl::OUString getParaAlignProperty()
      54                 :            :         {
      55                 :          0 :             return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParaAdjust" ) );
      56                 :            :         }
      57                 :            : 
      58                 :            :         //----------------------------------------------------------------
      59                 :          0 :         ::rtl::OUString getAlignProperty()
      60                 :            :         {
      61                 :          0 :             return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Align" ) );
      62                 :            :         }
      63                 :            : 
      64                 :            :         //----------------------------------------------------------------
      65                 :          0 :         sal_Int32 findStringElement( const Sequence< ::rtl::OUString >& _rNames, const ::rtl::OUString& _rName )
      66                 :            :         {
      67                 :          0 :             const ::rtl::OUString* pStart = _rNames.getConstArray();
      68                 :          0 :             const ::rtl::OUString* pEnd = _rNames.getConstArray() + _rNames.getLength();
      69                 :          0 :             const ::rtl::OUString* pPos = ::std::find( pStart, pEnd, _rName );
      70         [ #  # ]:          0 :             if ( pPos != pEnd )
      71                 :          0 :                 return pPos - pStart;
      72                 :          0 :             return -1;
      73                 :            :         }
      74                 :            : 
      75                 :            :         //----------------------------------------------------------------
      76                 :            :         struct AlignmentTranslationEntry
      77                 :            :         {
      78                 :            :             ParagraphAdjust nParagraphValue;
      79                 :            :             sal_Int16       nControlValue;
      80                 :            :         }
      81                 :            :         AlignmentTranslations[] =
      82                 :            :         {
      83                 :            :             // note that order matters:
      84                 :            :             // valueAlignToParaAdjust and valueParaAdjustToAlign search this map from the _beginning_
      85                 :            :             // and use the first matching entry
      86                 :            :             { ParagraphAdjust_LEFT,             TextAlign::LEFT     },
      87                 :            :             { ParagraphAdjust_CENTER,           TextAlign::CENTER   },
      88                 :            :             { ParagraphAdjust_RIGHT,            TextAlign::RIGHT    },
      89                 :            :             { ParagraphAdjust_BLOCK,            TextAlign::RIGHT    },
      90                 :            :             { ParagraphAdjust_STRETCH,          TextAlign::LEFT     },
      91                 :            :             { ParagraphAdjust_MAKE_FIXED_SIZE,  TextAlign::LEFT     },
      92                 :            :             { ParagraphAdjust_MAKE_FIXED_SIZE,  -1 }
      93                 :            :         };
      94                 :            : 
      95                 :            :         //----------------------------------------------------------------
      96                 :          0 :         void valueAlignToParaAdjust(Any& rValue)
      97                 :            :         {
      98                 :          0 :             sal_Int16 nValue = 0;
      99                 :          0 :             rValue >>= nValue;
     100                 :          0 :             const AlignmentTranslationEntry* pTranslation = AlignmentTranslations;
     101         [ #  # ]:          0 :             while (-1 != pTranslation->nControlValue)
     102                 :            :             {
     103         [ #  # ]:          0 :                 if ( nValue == pTranslation->nControlValue )
     104                 :            :                 {
     105         [ #  # ]:          0 :                     rValue <<= pTranslation->nParagraphValue;
     106                 :          0 :                     return;
     107                 :            :                 }
     108                 :          0 :                 ++pTranslation;
     109                 :            :             }
     110                 :            :             OSL_FAIL( "valueAlignToParaAdjust: unreachable!" );
     111                 :            :         }
     112                 :            : 
     113                 :            :         //----------------------------------------------------------------
     114                 :          0 :         void valueParaAdjustToAlign(Any& rValue)
     115                 :            :         {
     116                 :          0 :             sal_Int32 nValue = 0;
     117                 :          0 :             rValue >>= nValue;
     118                 :          0 :             const AlignmentTranslationEntry* pTranslation = AlignmentTranslations;
     119         [ #  # ]:          0 :             while ( ParagraphAdjust_MAKE_FIXED_SIZE != pTranslation->nParagraphValue)
     120                 :            :             {
     121         [ #  # ]:          0 :                 if ( nValue == pTranslation->nParagraphValue)
     122                 :            :                 {
     123         [ #  # ]:          0 :                     rValue <<= pTranslation->nControlValue;
     124                 :          0 :                     return;
     125                 :            :                 }
     126                 :          0 :                 ++pTranslation;
     127                 :            :             }
     128                 :            :             OSL_FAIL( "valueParaAdjustToAlign: unreachable!" );
     129                 :            :         }
     130                 :            : 
     131                 :            :         //====================================================================
     132                 :            :         //= OMergedPropertySetInfo
     133                 :            :         //====================================================================
     134                 :            :         typedef ::cppu::WeakAggImplHelper1  <   XPropertySetInfo
     135                 :            :                                             >   OMergedPropertySetInfo_Base;
     136                 :            :         class OMergedPropertySetInfo : public OMergedPropertySetInfo_Base
     137                 :            :         {
     138                 :            :         private:
     139                 :            :             Reference< XPropertySetInfo >   m_xMasterInfo;
     140                 :            : 
     141                 :            :         public:
     142                 :            :             OMergedPropertySetInfo( const Reference< XPropertySetInfo >& _rxMasterInfo );
     143                 :            : 
     144                 :            :         protected:
     145                 :            :             virtual ~OMergedPropertySetInfo();
     146                 :            : 
     147                 :            :             // XPropertySetInfo
     148                 :            :             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties(  ) throw (::com::sun::star::uno::RuntimeException);
     149                 :            :             virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const ::rtl::OUString& aName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
     150                 :            :             virtual ::sal_Bool SAL_CALL hasPropertyByName( const ::rtl::OUString& Name ) throw (::com::sun::star::uno::RuntimeException);
     151                 :            :         };
     152                 :            : 
     153                 :            :         //----------------------------------------------------------------
     154                 :          0 :         OMergedPropertySetInfo::OMergedPropertySetInfo( const Reference< XPropertySetInfo >& _rxMasterInfo )
     155                 :          0 :             :m_xMasterInfo( _rxMasterInfo )
     156                 :            :         {
     157                 :            :             OSL_ENSURE( m_xMasterInfo.is(), "OMergedPropertySetInfo::OMergedPropertySetInfo: hmm?" );
     158                 :          0 :         }
     159                 :            : 
     160                 :            :         //----------------------------------------------------------------
     161                 :          0 :         OMergedPropertySetInfo::~OMergedPropertySetInfo()
     162                 :            :         {
     163         [ #  # ]:          0 :         }
     164                 :            : 
     165                 :            :         //----------------------------------------------------------------
     166                 :          0 :         Sequence< Property > SAL_CALL OMergedPropertySetInfo::getProperties(  ) throw (RuntimeException)
     167                 :            :         {
     168                 :            :             // add a "ParaAdjust" property to the master properties
     169                 :          0 :             Sequence< Property > aProperties;
     170         [ #  # ]:          0 :             if ( m_xMasterInfo.is() )
     171 [ #  # ][ #  # ]:          0 :                 aProperties = m_xMasterInfo->getProperties();
         [ #  # ][ #  # ]
     172                 :            : 
     173                 :          0 :             sal_Int32 nOldLength = aProperties.getLength();
     174         [ #  # ]:          0 :             aProperties.realloc( nOldLength + 1 );
     175 [ #  # ][ #  # ]:          0 :             aProperties[ nOldLength ] = getPropertyByName( getParaAlignProperty() );
                 [ #  # ]
     176                 :            : 
     177                 :          0 :             return aProperties;
     178                 :            :         }
     179                 :            : 
     180                 :            :         //----------------------------------------------------------------
     181                 :          0 :         Property SAL_CALL OMergedPropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw (UnknownPropertyException, RuntimeException)
     182                 :            :         {
     183         [ #  # ]:          0 :             if ( aName == getParaAlignProperty() )
     184                 :            :                 return Property( getParaAlignProperty(), -1,
     185 [ #  # ][ #  # ]:          0 :                     ::getCppuType( static_cast< const ParagraphAdjust* >( NULL ) ), 0 );
     186                 :            : 
     187         [ #  # ]:          0 :             if ( !m_xMasterInfo.is() )
     188                 :          0 :                 return Property();
     189                 :            : 
     190                 :          0 :             return m_xMasterInfo->getPropertyByName( aName );
     191                 :            :         }
     192                 :            : 
     193                 :            :         //----------------------------------------------------------------
     194                 :          0 :         ::sal_Bool SAL_CALL OMergedPropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw (RuntimeException)
     195                 :            :         {
     196         [ #  # ]:          0 :             if ( Name == getParaAlignProperty() )
     197                 :          0 :                 return sal_True;
     198                 :            : 
     199         [ #  # ]:          0 :             if ( !m_xMasterInfo.is() )
     200                 :          0 :                 return sal_False;
     201                 :            : 
     202                 :          0 :             return m_xMasterInfo->hasPropertyByName( Name );
     203                 :            :         }
     204                 :            :     }
     205                 :            : 
     206                 :            : 
     207                 :            :     //====================================================================
     208                 :            :     //= OGridColumnPropertyTranslator
     209                 :            :     //====================================================================
     210                 :            :     //--------------------------------------------------------------------
     211                 :          0 :     OGridColumnPropertyTranslator::OGridColumnPropertyTranslator( const Reference< XMultiPropertySet >& _rxGridColumn )
     212                 :          0 :         :m_xGridColumn( _rxGridColumn )
     213                 :            :     {
     214                 :            :         OSL_ENSURE( m_xGridColumn.is(), "OGridColumnPropertyTranslator: invalid grid column!" );
     215                 :          0 :     }
     216                 :            : 
     217                 :            :     //--------------------------------------------------------------------
     218                 :          0 :     OGridColumnPropertyTranslator::~OGridColumnPropertyTranslator()
     219                 :            :     {
     220         [ #  # ]:          0 :     }
     221                 :            : 
     222                 :            :     //--------------------------------------------------------------------
     223                 :          0 :     Reference< XPropertySetInfo > SAL_CALL OGridColumnPropertyTranslator::getPropertySetInfo(  ) throw (RuntimeException)
     224                 :            :     {
     225                 :          0 :         Reference< XPropertySetInfo > xColumnPropInfo;
     226         [ #  # ]:          0 :         if ( m_xGridColumn.is() )
     227 [ #  # ][ #  # ]:          0 :             xColumnPropInfo = m_xGridColumn->getPropertySetInfo();
                 [ #  # ]
     228 [ #  # ][ #  # ]:          0 :         return new OMergedPropertySetInfo( xColumnPropInfo );
                 [ #  # ]
     229                 :            :     }
     230                 :            : 
     231                 :            :     //--------------------------------------------------------------------
     232                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
     233                 :            :     {
     234                 :            :         // we implement this by delegating it to setPropertyValues, which is to ignore unknown properties. On the other hand, our
     235                 :            :         // contract requires us to throw a UnknownPropertyException for unknown properties, so check this first.
     236                 :            : 
     237 [ #  # ][ #  # ]:          0 :         if ( !getPropertySetInfo()->hasPropertyByName( _rPropertyName ) )
         [ #  # ][ #  # ]
     238 [ #  # ][ #  # ]:          0 :             throw UnknownPropertyException( _rPropertyName, *this );
     239                 :            : 
     240         [ #  # ]:          0 :         Sequence< ::rtl::OUString > aNames( &_rPropertyName, 1 );
     241         [ #  # ]:          0 :         Sequence< Any >             aValues( &aValue, 1 );
     242 [ #  # ][ #  # ]:          0 :         setPropertyValues( aNames, aValues );
                 [ #  # ]
     243                 :          0 :     }
     244                 :            : 
     245                 :            :     //--------------------------------------------------------------------
     246                 :          0 :     Any SAL_CALL OGridColumnPropertyTranslator::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     247                 :            :     {
     248         [ #  # ]:          0 :         Sequence< ::rtl::OUString > aNames( &PropertyName, 1 );
     249         [ #  # ]:          0 :         Sequence< Any > aValues = getPropertyValues( aNames );
     250                 :            :         OSL_ENSURE( aValues.getLength() == 1, "OGridColumnPropertyTranslator::getPropertyValue: nonsense!" );
     251         [ #  # ]:          0 :         if ( aValues.getLength() == 1 )
     252         [ #  # ]:          0 :             return aValues[0];
     253 [ #  # ][ #  # ]:          0 :         return Any();
     254                 :            :     }
     255                 :            : 
     256                 :            :     //--------------------------------------------------------------------
     257                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     258                 :            :     {
     259                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::addPropertyChangeListener: not implemented - this should not be needed!" );
     260                 :          0 :     }
     261                 :            : 
     262                 :            :     //--------------------------------------------------------------------
     263                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     264                 :            :     {
     265                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::removePropertyChangeListener: not implemented - this should not be needed!" );
     266                 :          0 :     }
     267                 :            : 
     268                 :            :     //--------------------------------------------------------------------
     269                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     270                 :            :     {
     271                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::addVetoableChangeListener: not implemented - this should not be needed!" );
     272                 :          0 :     }
     273                 :            : 
     274                 :            :     //--------------------------------------------------------------------
     275                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
     276                 :            :     {
     277                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::removeVetoableChangeListener: not implemented - this should not be needed!" );
     278                 :          0 :     }
     279                 :            : 
     280                 :            :     //--------------------------------------------------------------------
     281                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
     282                 :            :     {
     283         [ #  # ]:          0 :         if ( !m_xGridColumn.is() )
     284                 :          0 :             return;
     285                 :            : 
     286                 :            :         // if there's ever the need for more than one property being translated, then we should
     287                 :            :         // certainly have a more clever implementation than this ...
     288                 :            : 
     289         [ #  # ]:          0 :         Sequence< ::rtl::OUString > aTranslatedNames( aPropertyNames );
     290         [ #  # ]:          0 :         Sequence< Any >             aTranslatedValues( aValues );
     291                 :            : 
     292 [ #  # ][ #  # ]:          0 :         sal_Int32 nParaAlignPos = findStringElement( aTranslatedNames, getParaAlignProperty() );
     293         [ #  # ]:          0 :         if ( nParaAlignPos != -1 )
     294                 :            :         {
     295 [ #  # ][ #  # ]:          0 :             aTranslatedNames[ nParaAlignPos ] = getAlignProperty();
     296 [ #  # ][ #  # ]:          0 :             valueParaAdjustToAlign( aTranslatedValues[ nParaAlignPos ] );
     297                 :            :         }
     298                 :            : 
     299 [ #  # ][ #  # ]:          0 :         m_xGridColumn->setPropertyValues( aTranslatedNames, aTranslatedValues );
         [ #  # ][ #  # ]
     300                 :            :     }
     301                 :            : 
     302                 :            :     //--------------------------------------------------------------------
     303                 :          0 :     Sequence< Any > SAL_CALL OGridColumnPropertyTranslator::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw (RuntimeException)
     304                 :            :     {
     305         [ #  # ]:          0 :         Sequence< Any > aValues( aPropertyNames.getLength() );
     306         [ #  # ]:          0 :         if ( !m_xGridColumn.is() )
     307                 :            :             return aValues;
     308                 :            : 
     309         [ #  # ]:          0 :         Sequence< ::rtl::OUString > aTranslatedNames( aPropertyNames );
     310 [ #  # ][ #  # ]:          0 :         sal_Int32 nAlignPos = findStringElement( aTranslatedNames, getParaAlignProperty() );
     311         [ #  # ]:          0 :         if ( nAlignPos != -1 )
     312 [ #  # ][ #  # ]:          0 :             aTranslatedNames[ nAlignPos ] = getAlignProperty();
     313                 :            : 
     314 [ #  # ][ #  # ]:          0 :         aValues = m_xGridColumn->getPropertyValues( aPropertyNames );
         [ #  # ][ #  # ]
     315         [ #  # ]:          0 :         if ( nAlignPos != -1 )
     316 [ #  # ][ #  # ]:          0 :             valueAlignToParaAdjust( aValues[ nAlignPos ] );
     317                 :            : 
     318         [ #  # ]:          0 :         return aValues;
     319                 :            :     }
     320                 :            : 
     321                 :            :     //--------------------------------------------------------------------
     322                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
     323                 :            :     {
     324                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::addPropertiesChangeListener: not implemented - this should not be needed!" );
     325                 :          0 :     }
     326                 :            : 
     327                 :            :     //--------------------------------------------------------------------
     328                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
     329                 :            :     {
     330                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::removePropertiesChangeListener: not implemented - this should not be needed!" );
     331                 :          0 :     }
     332                 :            : 
     333                 :            :     //--------------------------------------------------------------------
     334                 :          0 :     void SAL_CALL OGridColumnPropertyTranslator::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException)
     335                 :            :     {
     336                 :            :         OSL_FAIL( "OGridColumnPropertyTranslator::firePropertiesChangeEvent: not implemented - this should not be needed!" );
     337                 :          0 :     }
     338                 :            : 
     339                 :            : //........................................................................
     340                 :            : } // namespace xmloff
     341                 :            : //........................................................................
     342                 :            : 
     343                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10