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

Generated by: LCOV version 1.10