LCOV - code coverage report
Current view: top level - xmloff/source/forms - gridcolumnproptranslator.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 113 0.0 %
Date: 2014-04-14 Functions: 0 26 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             : 
      20             : #include "gridcolumnproptranslator.hxx"
      21             : 
      22             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      23             : #include <com/sun/star/awt/TextAlign.hpp>
      24             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      25             : #include <osl/diagnose.h>
      26             : #include <cppuhelper/implbase1.hxx>
      27             : 
      28             : #include <algorithm>
      29             : 
      30             : namespace xmloff
      31             : {
      32             : 
      33             :     using namespace ::com::sun::star::uno;
      34             :     using namespace ::com::sun::star::awt;
      35             :     using namespace ::com::sun::star;
      36             :     using namespace ::com::sun::star::lang;
      37             :     using namespace ::com::sun::star::beans;
      38             :     using namespace ::com::sun::star::style;
      39             : 
      40             :     namespace
      41             :     {
      42           0 :         OUString getParaAlignProperty()
      43             :         {
      44           0 :             return OUString( "ParaAdjust" );
      45             :         }
      46             : 
      47           0 :         OUString getAlignProperty()
      48             :         {
      49           0 :             return OUString( "Align" );
      50             :         }
      51             : 
      52           0 :         sal_Int32 findStringElement( const Sequence< OUString >& _rNames, const OUString& _rName )
      53             :         {
      54           0 :             const OUString* pStart = _rNames.getConstArray();
      55           0 :             const OUString* pEnd = _rNames.getConstArray() + _rNames.getLength();
      56           0 :             const OUString* pPos = ::std::find( pStart, pEnd, _rName );
      57           0 :             if ( pPos != pEnd )
      58           0 :                 return pPos - pStart;
      59           0 :             return -1;
      60             :         }
      61             : 
      62             :         struct AlignmentTranslationEntry
      63             :         {
      64             :             ParagraphAdjust nParagraphValue;
      65             :             sal_Int16       nControlValue;
      66             :         }
      67             :         AlignmentTranslations[] =
      68             :         {
      69             :             // note that order matters:
      70             :             // valueAlignToParaAdjust and valueParaAdjustToAlign search this map from the _beginning_
      71             :             // and use the first matching entry
      72             :             { ParagraphAdjust_LEFT,             awt::TextAlign::LEFT     },
      73             :             { ParagraphAdjust_CENTER,           awt::TextAlign::CENTER   },
      74             :             { ParagraphAdjust_RIGHT,            awt::TextAlign::RIGHT    },
      75             :             { ParagraphAdjust_BLOCK,            awt::TextAlign::RIGHT    },
      76             :             { ParagraphAdjust_STRETCH,          awt::TextAlign::LEFT     },
      77             :             { ParagraphAdjust_MAKE_FIXED_SIZE,  awt::TextAlign::LEFT     },
      78             :             { ParagraphAdjust_MAKE_FIXED_SIZE,  -1 }
      79             :         };
      80             : 
      81           0 :         void valueAlignToParaAdjust(Any& rValue)
      82             :         {
      83           0 :             sal_Int16 nValue = 0;
      84           0 :             rValue >>= nValue;
      85           0 :             const AlignmentTranslationEntry* pTranslation = AlignmentTranslations;
      86           0 :             while (-1 != pTranslation->nControlValue)
      87             :             {
      88           0 :                 if ( nValue == pTranslation->nControlValue )
      89             :                 {
      90           0 :                     rValue <<= pTranslation->nParagraphValue;
      91           0 :                     return;
      92             :                 }
      93           0 :                 ++pTranslation;
      94             :             }
      95             :             OSL_FAIL( "valueAlignToParaAdjust: unreachable!" );
      96             :         }
      97             : 
      98           0 :         void valueParaAdjustToAlign(Any& rValue)
      99             :         {
     100           0 :             sal_Int32 nValue = 0;
     101           0 :             rValue >>= nValue;
     102           0 :             const AlignmentTranslationEntry* pTranslation = AlignmentTranslations;
     103           0 :             while ( ParagraphAdjust_MAKE_FIXED_SIZE != pTranslation->nParagraphValue)
     104             :             {
     105           0 :                 if ( nValue == pTranslation->nParagraphValue)
     106             :                 {
     107           0 :                     rValue <<= pTranslation->nControlValue;
     108           0 :                     return;
     109             :                 }
     110           0 :                 ++pTranslation;
     111             :             }
     112             :             OSL_FAIL( "valueParaAdjustToAlign: unreachable!" );
     113             :         }
     114             : 
     115             :         //= OMergedPropertySetInfo
     116             :         typedef ::cppu::WeakAggImplHelper1  <   XPropertySetInfo
     117             :                                             >   OMergedPropertySetInfo_Base;
     118             :         class OMergedPropertySetInfo : public OMergedPropertySetInfo_Base
     119             :         {
     120             :         private:
     121             :             Reference< XPropertySetInfo >   m_xMasterInfo;
     122             : 
     123             :         public:
     124             :             OMergedPropertySetInfo( const Reference< XPropertySetInfo >& _rxMasterInfo );
     125             : 
     126             :         protected:
     127             :             virtual ~OMergedPropertySetInfo();
     128             : 
     129             :             // XPropertySetInfo
     130             :             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL getProperties(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     131             :             virtual ::com::sun::star::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     132             :             virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     133             :         };
     134             : 
     135           0 :         OMergedPropertySetInfo::OMergedPropertySetInfo( const Reference< XPropertySetInfo >& _rxMasterInfo )
     136           0 :             :m_xMasterInfo( _rxMasterInfo )
     137             :         {
     138             :             OSL_ENSURE( m_xMasterInfo.is(), "OMergedPropertySetInfo::OMergedPropertySetInfo: hmm?" );
     139           0 :         }
     140             : 
     141           0 :         OMergedPropertySetInfo::~OMergedPropertySetInfo()
     142             :         {
     143           0 :         }
     144             : 
     145           0 :         Sequence< Property > SAL_CALL OMergedPropertySetInfo::getProperties(  ) throw (RuntimeException, std::exception)
     146             :         {
     147             :             // add a "ParaAdjust" property to the master properties
     148           0 :             Sequence< Property > aProperties;
     149           0 :             if ( m_xMasterInfo.is() )
     150           0 :                 aProperties = m_xMasterInfo->getProperties();
     151             : 
     152           0 :             sal_Int32 nOldLength = aProperties.getLength();
     153           0 :             aProperties.realloc( nOldLength + 1 );
     154           0 :             aProperties[ nOldLength ] = getPropertyByName( getParaAlignProperty() );
     155             : 
     156           0 :             return aProperties;
     157             :         }
     158             : 
     159           0 :         Property SAL_CALL OMergedPropertySetInfo::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException, std::exception)
     160             :         {
     161           0 :             if ( aName == getParaAlignProperty() )
     162             :                 return Property( getParaAlignProperty(), -1,
     163           0 :                     ::getCppuType( static_cast< const ParagraphAdjust* >( NULL ) ), 0 );
     164             : 
     165           0 :             if ( !m_xMasterInfo.is() )
     166           0 :                 return Property();
     167             : 
     168           0 :             return m_xMasterInfo->getPropertyByName( aName );
     169             :         }
     170             : 
     171           0 :         sal_Bool SAL_CALL OMergedPropertySetInfo::hasPropertyByName( const OUString& Name ) throw (RuntimeException, std::exception)
     172             :         {
     173           0 :             if ( Name == getParaAlignProperty() )
     174           0 :                 return sal_True;
     175             : 
     176           0 :             if ( !m_xMasterInfo.is() )
     177           0 :                 return sal_False;
     178             : 
     179           0 :             return m_xMasterInfo->hasPropertyByName( Name );
     180             :         }
     181             :     }
     182             : 
     183             :     //= OGridColumnPropertyTranslator
     184           0 :     OGridColumnPropertyTranslator::OGridColumnPropertyTranslator( const Reference< XMultiPropertySet >& _rxGridColumn )
     185           0 :         :m_xGridColumn( _rxGridColumn )
     186             :     {
     187             :         OSL_ENSURE( m_xGridColumn.is(), "OGridColumnPropertyTranslator: invalid grid column!" );
     188           0 :     }
     189             : 
     190           0 :     OGridColumnPropertyTranslator::~OGridColumnPropertyTranslator()
     191             :     {
     192           0 :     }
     193             : 
     194           0 :     Reference< XPropertySetInfo > SAL_CALL OGridColumnPropertyTranslator::getPropertySetInfo(  ) throw (RuntimeException, std::exception)
     195             :     {
     196           0 :         Reference< XPropertySetInfo > xColumnPropInfo;
     197           0 :         if ( m_xGridColumn.is() )
     198           0 :             xColumnPropInfo = m_xGridColumn->getPropertySetInfo();
     199           0 :         return new OMergedPropertySetInfo( xColumnPropInfo );
     200             :     }
     201             : 
     202           0 :     void SAL_CALL OGridColumnPropertyTranslator::setPropertyValue( const OUString& _rPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
     203             :     {
     204             :         // we implement this by delegating it to setPropertyValues, which is to ignore unknown properties. On the other hand, our
     205             :         // contract requires us to throw a UnknownPropertyException for unknown properties, so check this first.
     206             : 
     207           0 :         if ( !getPropertySetInfo()->hasPropertyByName( _rPropertyName ) )
     208           0 :             throw UnknownPropertyException( _rPropertyName, *this );
     209             : 
     210           0 :         Sequence< OUString > aNames( &_rPropertyName, 1 );
     211           0 :         Sequence< Any >             aValues( &aValue, 1 );
     212           0 :         setPropertyValues( aNames, aValues );
     213           0 :     }
     214             : 
     215           0 :     Any SAL_CALL OGridColumnPropertyTranslator::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     216             :     {
     217           0 :         Sequence< OUString > aNames( &PropertyName, 1 );
     218           0 :         Sequence< Any > aValues = getPropertyValues( aNames );
     219             :         OSL_ENSURE( aValues.getLength() == 1, "OGridColumnPropertyTranslator::getPropertyValue: nonsense!" );
     220           0 :         if ( aValues.getLength() == 1 )
     221           0 :             return aValues[0];
     222           0 :         return Any();
     223             :     }
     224             : 
     225           0 :     void SAL_CALL OGridColumnPropertyTranslator::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     226             :     {
     227             :         OSL_FAIL( "OGridColumnPropertyTranslator::addPropertyChangeListener: not implemented - this should not be needed!" );
     228           0 :     }
     229             : 
     230           0 :     void SAL_CALL OGridColumnPropertyTranslator::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     231             :     {
     232             :         OSL_FAIL( "OGridColumnPropertyTranslator::removePropertyChangeListener: not implemented - this should not be needed!" );
     233           0 :     }
     234             : 
     235           0 :     void SAL_CALL OGridColumnPropertyTranslator::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     236             :     {
     237             :         OSL_FAIL( "OGridColumnPropertyTranslator::addVetoableChangeListener: not implemented - this should not be needed!" );
     238           0 :     }
     239             : 
     240           0 :     void SAL_CALL OGridColumnPropertyTranslator::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     241             :     {
     242             :         OSL_FAIL( "OGridColumnPropertyTranslator::removeVetoableChangeListener: not implemented - this should not be needed!" );
     243           0 :     }
     244             : 
     245           0 :     void SAL_CALL OGridColumnPropertyTranslator::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
     246             :     {
     247           0 :         if ( !m_xGridColumn.is() )
     248           0 :             return;
     249             : 
     250             :         // if there's ever the need for more than one property being translated, then we should
     251             :         // certainly have a more clever implementation than this ...
     252             : 
     253           0 :         Sequence< OUString > aTranslatedNames( aPropertyNames );
     254           0 :         Sequence< Any >             aTranslatedValues( aValues );
     255             : 
     256           0 :         sal_Int32 nParaAlignPos = findStringElement( aTranslatedNames, getParaAlignProperty() );
     257           0 :         if ( nParaAlignPos != -1 )
     258             :         {
     259           0 :             aTranslatedNames[ nParaAlignPos ] = getAlignProperty();
     260           0 :             valueParaAdjustToAlign( aTranslatedValues[ nParaAlignPos ] );
     261             :         }
     262             : 
     263           0 :         m_xGridColumn->setPropertyValues( aTranslatedNames, aTranslatedValues );
     264             :     }
     265             : 
     266           0 :     Sequence< Any > SAL_CALL OGridColumnPropertyTranslator::getPropertyValues( const Sequence< OUString >& aPropertyNames ) throw (RuntimeException, std::exception)
     267             :     {
     268           0 :         Sequence< Any > aValues( aPropertyNames.getLength() );
     269           0 :         if ( !m_xGridColumn.is() )
     270           0 :             return aValues;
     271             : 
     272           0 :         Sequence< OUString > aTranslatedNames( aPropertyNames );
     273           0 :         sal_Int32 nAlignPos = findStringElement( aTranslatedNames, getParaAlignProperty() );
     274           0 :         if ( nAlignPos != -1 )
     275           0 :             aTranslatedNames[ nAlignPos ] = getAlignProperty();
     276             : 
     277           0 :         aValues = m_xGridColumn->getPropertyValues( aPropertyNames );
     278           0 :         if ( nAlignPos != -1 )
     279           0 :             valueAlignToParaAdjust( aValues[ nAlignPos ] );
     280             : 
     281           0 :         return aValues;
     282             :     }
     283             : 
     284           0 :     void SAL_CALL OGridColumnPropertyTranslator::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException, std::exception)
     285             :     {
     286             :         OSL_FAIL( "OGridColumnPropertyTranslator::addPropertiesChangeListener: not implemented - this should not be needed!" );
     287           0 :     }
     288             : 
     289           0 :     void SAL_CALL OGridColumnPropertyTranslator::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw (RuntimeException, std::exception)
     290             :     {
     291             :         OSL_FAIL( "OGridColumnPropertyTranslator::removePropertiesChangeListener: not implemented - this should not be needed!" );
     292           0 :     }
     293             : 
     294           0 :     void SAL_CALL OGridColumnPropertyTranslator::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw (RuntimeException, std::exception)
     295             :     {
     296             :         OSL_FAIL( "OGridColumnPropertyTranslator::firePropertiesChangeEvent: not implemented - this should not be needed!" );
     297           0 :     }
     298             : 
     299             : } // namespace xmloff
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10