LCOV - code coverage report
Current view: top level - forms/source/component - EditBase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 136 80.9 %
Date: 2012-08-25 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 73 154 47.4 %

           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 "EditBase.hxx"
      30                 :            : #include "property.hxx"
      31                 :            : #include "property.hrc"
      32                 :            : #include "services.hxx"
      33                 :            : #include <tools/debug.hxx>
      34                 :            : #include <comphelper/basicio.hxx>
      35                 :            : #include <cppuhelper/queryinterface.hxx>
      36                 :            : #include "frm_resource.hxx"
      37                 :            : #include "frm_resource.hrc"
      38                 :            : 
      39                 :            : //.........................................................................
      40                 :            : namespace frm
      41                 :            : {
      42                 :            : using namespace ::com::sun::star::uno;
      43                 :            : using namespace ::com::sun::star::sdb;
      44                 :            : using namespace ::com::sun::star::sdbc;
      45                 :            : using namespace ::com::sun::star::sdbcx;
      46                 :            : using namespace ::com::sun::star::beans;
      47                 :            : using namespace ::com::sun::star::container;
      48                 :            : using namespace ::com::sun::star::form;
      49                 :            : using namespace ::com::sun::star::awt;
      50                 :            : using namespace ::com::sun::star::io;
      51                 :            : using namespace ::com::sun::star::lang;
      52                 :            : using namespace ::com::sun::star::util;
      53                 :            : 
      54                 :            : const sal_uInt16 DEFAULT_LONG    =  0x0001;
      55                 :            : const sal_uInt16 DEFAULT_DOUBLE  =  0x0002;
      56                 :            : const sal_uInt16 FILTERPROPOSAL  =  0x0004;
      57                 :            : 
      58                 :            : DBG_NAME( OEditBaseModel )
      59                 :            : //------------------------------------------------------------------
      60                 :        329 : OEditBaseModel::OEditBaseModel( const Reference< XMultiServiceFactory >& _rxFactory, const ::rtl::OUString& rUnoControlModelName,
      61                 :            :         const ::rtl::OUString& rDefault, const sal_Bool _bSupportExternalBinding, const sal_Bool _bSupportsValidation )
      62                 :            :     :OBoundControlModel( _rxFactory, rUnoControlModelName, rDefault, sal_True, _bSupportExternalBinding, _bSupportsValidation )
      63                 :            :     ,m_nLastReadVersion(0)
      64                 :            :     ,m_bEmptyIsNull(sal_True)
      65                 :        329 :     ,m_bFilterProposal(sal_False)
      66                 :            : {
      67                 :            :     DBG_CTOR( OEditBaseModel, NULL );
      68                 :        329 : }
      69                 :            : 
      70                 :            : //------------------------------------------------------------------
      71                 :         16 : OEditBaseModel::OEditBaseModel( const OEditBaseModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
      72                 :            :      :OBoundControlModel( _pOriginal, _rxFactory )
      73                 :         16 :      ,m_nLastReadVersion(0)
      74                 :            : {
      75                 :            :     DBG_CTOR( OEditBaseModel, NULL );
      76                 :            : 
      77                 :         16 :     m_bFilterProposal = _pOriginal->m_bFilterProposal;
      78                 :         16 :     m_bEmptyIsNull = _pOriginal->m_bEmptyIsNull;
      79                 :         16 :     m_aDefault = _pOriginal->m_aDefault;
      80                 :         16 :     m_aDefaultText = _pOriginal->m_aDefaultText;
      81                 :         16 : }
      82                 :            : 
      83                 :            : //------------------------------------------------------------------
      84                 :        322 : OEditBaseModel::~OEditBaseModel( )
      85                 :            : {
      86                 :            :     DBG_DTOR( OEditBaseModel, NULL );
      87         [ -  + ]:        322 : }
      88                 :            : 
      89                 :            : // XPersist
      90                 :            : //------------------------------------------------------------------------------
      91                 :         16 : void OEditBaseModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
      92                 :            : {
      93                 :         16 :     OBoundControlModel::write(_rxOutStream);
      94                 :            : 
      95                 :            :     // Version
      96                 :         16 :     sal_uInt16 nVersionId = 0x0005;
      97                 :            :     DBG_ASSERT((getPersistenceFlags() & ~PF_SPECIAL_FLAGS) == 0,
      98                 :            :         "OEditBaseModel::write : invalid special version flags !");
      99                 :            :         // please don't use other flags, older versions can't interpret them !
     100                 :            : 
     101                 :         16 :     nVersionId |= getPersistenceFlags();
     102                 :         16 :     _rxOutStream->writeShort(nVersionId);
     103                 :            : 
     104                 :            :     // Name
     105                 :         16 :     _rxOutStream->writeShort(0);    // obsolete
     106                 :         16 :     _rxOutStream << m_aDefaultText;
     107                 :            : 
     108                 :            :     // Masking for any
     109                 :         16 :     sal_uInt16 nAnyMask = 0;
     110         [ -  + ]:         16 :     if (m_aDefault.getValueType().getTypeClass() == TypeClass_LONG)
     111                 :          0 :         nAnyMask |= DEFAULT_LONG;
     112         [ -  + ]:         16 :     else if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
     113                 :          0 :         nAnyMask |= DEFAULT_DOUBLE;
     114                 :            : 
     115         [ -  + ]:         16 :     if (m_bFilterProposal)  // Don't save a value, because it's boolean
     116                 :          0 :         nAnyMask |= FILTERPROPOSAL;
     117                 :            : 
     118                 :         16 :     _rxOutStream->writeBoolean(m_bEmptyIsNull);
     119                 :         16 :     _rxOutStream->writeShort(nAnyMask);
     120                 :            : 
     121         [ -  + ]:         16 :     if ((nAnyMask & DEFAULT_LONG) == DEFAULT_LONG)
     122                 :          0 :         _rxOutStream->writeLong(getINT32(m_aDefault));
     123         [ -  + ]:         16 :     else if ((nAnyMask & DEFAULT_DOUBLE) == DEFAULT_DOUBLE)
     124                 :          0 :         _rxOutStream->writeDouble(getDouble(m_aDefault));
     125                 :            : 
     126                 :            :     // since version 5 we write the help text
     127                 :         16 :     writeHelpTextCompatibly(_rxOutStream);
     128                 :            :     // (that's potentially bad : at the time I added the above line we had two derived classes : OEditModel and
     129                 :            :     // OFormattedModel. The first one does not have an own version handling, so it can't write the help text itself,
     130                 :            :     // the second one does it's own writing (reading) after calling our method, so normally we shouldn't write any
     131                 :            :     // additional members as this is not compatible to older office versions.
     132                 :            :     // We decided to place the writing of the help text here as it seems the less worse alternative. There is no delivered
     133                 :            :     // office version including formatted controls (and thus the OFormattedModel), and the OFormattedModel::read seems
     134                 :            :     // robust against this change (as it will read a wrong and unknown file version and thus set it's members to defaults).
     135                 :            : 
     136         [ +  - ]:         16 :     if ((nVersionId & PF_HANDLE_COMMON_PROPS) != 0)
     137                 :         16 :         writeCommonEditProperties(_rxOutStream);
     138                 :            : 
     139                 :            :     // !!! properties common to all OEditBaseModel derived classes should be written in writeCommonEditProperties !!!
     140                 :         16 : }
     141                 :            : 
     142                 :            : //------------------------------------------------------------------------------
     143                 :         16 : sal_uInt16 OEditBaseModel::getPersistenceFlags() const
     144                 :            : {
     145                 :         16 :     return PF_HANDLE_COMMON_PROPS;
     146                 :            : }
     147                 :            : 
     148                 :            : //------------------------------------------------------------------------------
     149                 :         16 : void OEditBaseModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
     150                 :            : {
     151         [ +  - ]:         16 :     OBoundControlModel::read(_rxInStream);
     152         [ +  - ]:         16 :     ::osl::MutexGuard aGuard(m_aMutex);
     153                 :            : 
     154                 :            :     // Version's own version number
     155 [ +  - ][ +  - ]:         16 :     sal_uInt16 nVersion = _rxInStream->readShort();
     156                 :         16 :     m_nLastReadVersion = nVersion;
     157                 :            : 
     158                 :         16 :     sal_Bool bHandleCommonProps = (nVersion & PF_HANDLE_COMMON_PROPS) != 0;
     159                 :         16 :     nVersion = nVersion & ~PF_SPECIAL_FLAGS;
     160                 :            : 
     161                 :            :     // obsolete
     162 [ +  - ][ +  - ]:         16 :     _rxInStream->readShort();
     163                 :            : 
     164         [ +  - ]:         16 :     _rxInStream >> m_aDefaultText;
     165                 :            : 
     166         [ +  - ]:         16 :     if (nVersion >= 0x0003)
     167                 :            :     {
     168 [ +  - ][ +  - ]:         16 :         m_bEmptyIsNull = _rxInStream->readBoolean();
     169                 :            : 
     170 [ +  - ][ +  - ]:         16 :         sal_uInt16 nAnyMask = _rxInStream->readShort();
     171         [ -  + ]:         16 :         if ((nAnyMask & DEFAULT_LONG) == DEFAULT_LONG)
     172                 :            :         {
     173 [ #  # ][ #  # ]:          0 :             sal_Int32 nValue = _rxInStream->readLong();
     174         [ #  # ]:          0 :             m_aDefault <<= (sal_Int32)nValue;
     175                 :            :         }
     176         [ -  + ]:         16 :         else if ((nAnyMask & DEFAULT_DOUBLE) == DEFAULT_DOUBLE)
     177                 :            :         {
     178 [ #  # ][ #  # ]:          0 :             double fValue = _rxInStream->readDouble();
     179         [ #  # ]:          0 :             m_aDefault <<= (double)fValue;
     180                 :            :         }
     181                 :            : 
     182         [ -  + ]:         16 :         if ((nAnyMask & FILTERPROPOSAL) == FILTERPROPOSAL)
     183                 :          0 :             m_bFilterProposal = sal_True;
     184                 :            :     }
     185                 :            : 
     186         [ +  - ]:         16 :     if (nVersion > 4)
     187         [ +  - ]:         16 :         readHelpTextCompatibly(_rxInStream);
     188                 :            : 
     189         [ +  - ]:         16 :     if (bHandleCommonProps)
     190         [ +  - ]:         16 :         readCommonEditProperties(_rxInStream);
     191                 :            : 
     192                 :            :     // After reading, display default values
     193         [ +  + ]:         16 :     if ( !getControlSource().isEmpty() )
     194                 :            :         // (not if we don't have a control source - the "State" property acts like it is persistent, then)
     195 [ +  - ][ +  - ]:         16 :         resetNoBroadcast();
     196                 :         16 : };
     197                 :            : 
     198                 :            : //------------------------------------------------------------------------------
     199                 :          0 : void OEditBaseModel::defaultCommonEditProperties()
     200                 :            : {
     201                 :          0 :     OBoundControlModel::defaultCommonProperties();
     202                 :            :     // no own common properties at the moment
     203                 :          0 : }
     204                 :            : 
     205                 :            : //------------------------------------------------------------------------------
     206                 :         16 : void OEditBaseModel::readCommonEditProperties(const Reference<XObjectInputStream>& _rxInStream)
     207                 :            : {
     208 [ +  - ][ +  - ]:         16 :     sal_Int32 nLen = _rxInStream->readLong();
     209                 :            : 
     210         [ +  - ]:         16 :     Reference<XMarkableStream>  xMark(_rxInStream, UNO_QUERY);
     211                 :            :     DBG_ASSERT(xMark.is(), "OBoundControlModel::readCommonProperties : can only work with markable streams !");
     212 [ +  - ][ +  - ]:         16 :     sal_Int32 nMark = xMark->createMark();
     213                 :            : 
     214                 :            :     // read properties common to all OBoundControlModels
     215         [ +  - ]:         16 :     OBoundControlModel::readCommonProperties(_rxInStream);
     216                 :            : 
     217                 :            :     // read properties common to all OEditBaseModels
     218                 :            : 
     219                 :            :     // skip the remaining bytes
     220 [ +  - ][ +  - ]:         16 :     xMark->jumpToMark(nMark);
     221 [ +  - ][ +  - ]:         16 :     _rxInStream->skipBytes(nLen);
     222 [ +  - ][ +  - ]:         16 :     xMark->deleteMark(nMark);
     223                 :         16 : }
     224                 :            : 
     225                 :            : //------------------------------------------------------------------------------
     226                 :         16 : void OEditBaseModel::writeCommonEditProperties(const Reference<XObjectOutputStream>& _rxOutStream)
     227                 :            : {
     228         [ +  - ]:         16 :     Reference<XMarkableStream>  xMark(_rxOutStream, UNO_QUERY);
     229                 :            :     DBG_ASSERT(xMark.is(), "OEditBaseModel::writeCommonProperties : can only work with markable streams !");
     230 [ +  - ][ +  - ]:         16 :     sal_Int32 nMark = xMark->createMark();
     231                 :            : 
     232                 :            :     // a placeholder where we will write the overall length (later in this method)
     233                 :         16 :     sal_Int32 nLen = 0;
     234 [ +  - ][ +  - ]:         16 :     _rxOutStream->writeLong(nLen);
     235                 :            : 
     236                 :            :     // write properties common to all OBoundControlModels
     237         [ +  - ]:         16 :     OBoundControlModel::writeCommonProperties(_rxOutStream);
     238                 :            : 
     239                 :            :     // write properties common to all OEditBaseModels
     240                 :            : 
     241                 :            :     // close the block - write the correct length at the beginning
     242 [ +  - ][ +  - ]:         16 :     nLen = xMark->offsetToMark(nMark) - sizeof(nLen);
     243 [ +  - ][ +  - ]:         16 :     xMark->jumpToMark(nMark);
     244 [ +  - ][ +  - ]:         16 :     _rxOutStream->writeLong(nLen);
     245 [ +  - ][ +  - ]:         16 :     xMark->jumpToFurthest();
     246 [ +  - ][ +  - ]:         16 :     xMark->deleteMark(nMark);
     247                 :         16 : }
     248                 :            : 
     249                 :            : //------------------------------------------------------------------------------
     250                 :      65807 : void OEditBaseModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     251                 :            : {
     252   [ +  +  +  +  :      65807 :     switch (nHandle)
                      + ]
     253                 :            :     {
     254                 :            :         case PROPERTY_ID_EMPTY_IS_NULL:
     255         [ +  - ]:        421 :             rValue <<= (sal_Bool)m_bEmptyIsNull;
     256                 :        421 :             break;
     257                 :            :         case PROPERTY_ID_FILTERPROPOSAL:
     258         [ +  - ]:        413 :             rValue <<= (sal_Bool)m_bFilterProposal;
     259                 :        413 :             break;
     260                 :            :         case PROPERTY_ID_DEFAULT_TEXT:
     261                 :        422 :             rValue <<= m_aDefaultText;
     262                 :        422 :             break;
     263                 :            :         case PROPERTY_ID_DEFAULT_VALUE:
     264                 :            :         case PROPERTY_ID_DEFAULT_DATE:
     265                 :            :         case PROPERTY_ID_DEFAULT_TIME:
     266                 :        204 :             rValue = m_aDefault;
     267                 :        204 :             break;
     268                 :            :         default:
     269                 :      64347 :             OBoundControlModel::getFastPropertyValue(rValue, nHandle);
     270                 :            :     }
     271                 :      65807 : }
     272                 :            : 
     273                 :            : //------------------------------------------------------------------------------
     274                 :       4761 : sal_Bool OEditBaseModel::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue,
     275                 :            :                                             sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException )
     276                 :            : {
     277                 :       4761 :     sal_Bool bModified(sal_False);
     278   [ +  +  +  -  :       4761 :     switch (nHandle)
                   -  + ]
     279                 :            :     {
     280                 :            :         case PROPERTY_ID_EMPTY_IS_NULL:
     281                 :        192 :             bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEmptyIsNull);
     282                 :        192 :             break;
     283                 :            :         case PROPERTY_ID_FILTERPROPOSAL:
     284                 :        180 :             bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bFilterProposal);
     285                 :        180 :             break;
     286                 :            :         case PROPERTY_ID_DEFAULT_TEXT:
     287                 :        187 :             bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aDefaultText);
     288                 :        187 :             break;
     289                 :            :         case PROPERTY_ID_DEFAULT_VALUE:
     290                 :          0 :             bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aDefault, ::getCppuType((const double*)0));
     291                 :          0 :             break;
     292                 :            :         case PROPERTY_ID_DEFAULT_DATE:
     293                 :            :         case PROPERTY_ID_DEFAULT_TIME:
     294                 :          0 :             bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aDefault, ::getCppuType((const sal_Int32*)0));
     295                 :          0 :             break;
     296                 :            :         default:
     297                 :            :             bModified = OBoundControlModel::convertFastPropertyValue(
     298                 :            :                                             rConvertedValue,
     299                 :            :                                             rOldValue,
     300                 :            :                                             nHandle,
     301                 :       4202 :                                             rValue);
     302                 :            :     }
     303                 :       4761 :     return bModified;
     304                 :            : }
     305                 :            : 
     306                 :            : //------------------------------------------------------------------------------
     307                 :       1241 : void OEditBaseModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw ( ::com::sun::star::uno::Exception)
     308                 :            : {
     309   [ +  +  +  -  :       1241 :     switch (nHandle)
                      + ]
     310                 :            :     {
     311                 :            :         case PROPERTY_ID_EMPTY_IS_NULL:
     312                 :            :             DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "invalid type" );
     313                 :         36 :             m_bEmptyIsNull = getBOOL(rValue);
     314                 :         36 :             break;
     315                 :            :         case PROPERTY_ID_FILTERPROPOSAL:
     316                 :            :             DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "invalid type" );
     317                 :         32 :             m_bFilterProposal = getBOOL(rValue);
     318                 :         32 :             break;
     319                 :            :         // Changing the default values causes a reset
     320                 :            :         case PROPERTY_ID_DEFAULT_TEXT:
     321                 :            :             DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "invalid type" );
     322                 :         39 :             rValue >>= m_aDefaultText;
     323                 :         39 :             resetNoBroadcast();
     324                 :         39 :             break;
     325                 :            :         case PROPERTY_ID_DEFAULT_VALUE:
     326                 :            :         case PROPERTY_ID_DEFAULT_DATE:
     327                 :            :         case PROPERTY_ID_DEFAULT_TIME:
     328                 :          0 :             m_aDefault = rValue;
     329                 :          0 :             resetNoBroadcast();
     330                 :          0 :             break;
     331                 :            :         default:
     332                 :       1134 :             OBoundControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue );
     333                 :            :     }
     334                 :       1241 : }
     335                 :            : 
     336                 :            : // XPropertyState
     337                 :            : //------------------------------------------------------------------------------
     338                 :          0 : Any OEditBaseModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
     339                 :            : {
     340   [ #  #  #  # ]:          0 :     switch (nHandle)
     341                 :            :     {
     342                 :            :         case PROPERTY_ID_DEFAULT_TEXT:
     343         [ #  # ]:          0 :             return makeAny(::rtl::OUString());
     344                 :            :         case PROPERTY_ID_FILTERPROPOSAL:
     345         [ #  # ]:          0 :             return Any(makeAny((sal_Bool)sal_False));
     346                 :            :         case PROPERTY_ID_DEFAULT_VALUE:
     347                 :            :         case PROPERTY_ID_DEFAULT_DATE:
     348                 :            :         case PROPERTY_ID_DEFAULT_TIME:
     349                 :          0 :             return Any();
     350                 :            :         default:
     351                 :          0 :             return OBoundControlModel::getPropertyDefaultByHandle(nHandle);
     352                 :            :     }
     353                 :            : }
     354                 :            : 
     355                 :            : //.........................................................................
     356                 :            : }
     357                 :            : //.........................................................................
     358                 :            : 
     359                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10