LCOV - code coverage report
Current view: top level - forms/source/component - File.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 109 17.4 %
Date: 2012-08-25 Functions: 6 22 27.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15 161 9.3 %

           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 "File.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/form/FormComponentType.hpp>
      32                 :            : 
      33                 :            : #include "property.hrc"
      34                 :            : #include "services.hxx"
      35                 :            : #include <tools/debug.hxx>
      36                 :            : #include <comphelper/container.hxx>
      37                 :            : #include <comphelper/basicio.hxx>
      38                 :            : #include <comphelper/guarding.hxx>
      39                 :            : 
      40                 :            : //.........................................................................
      41                 :            : namespace frm
      42                 :            : {
      43                 :            : //.........................................................................
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : using namespace ::com::sun::star::sdb;
      46                 :            : using namespace ::com::sun::star::sdbc;
      47                 :            : using namespace ::com::sun::star::sdbcx;
      48                 :            : using namespace ::com::sun::star::beans;
      49                 :            : using namespace ::com::sun::star::container;
      50                 :            : using namespace ::com::sun::star::form;
      51                 :            : using namespace ::com::sun::star::awt;
      52                 :            : using namespace ::com::sun::star::io;
      53                 :            : using namespace ::com::sun::star::lang;
      54                 :            : using namespace ::com::sun::star::util;
      55                 :            : 
      56                 :            : //------------------------------------------------------------------
      57                 :          3 : InterfaceRef SAL_CALL OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      58                 :            : {
      59         [ +  - ]:          3 :     return *(new OFileControlModel(_rxFactory));
      60                 :            : }
      61                 :            : 
      62                 :            : //------------------------------------------------------------------------------
      63                 :          0 : Sequence<Type> OFileControlModel::_getTypes()
      64                 :            : {
      65 [ #  # ][ #  # ]:          0 :     static Sequence<Type> aTypes;
         [ #  # ][ #  # ]
      66         [ #  # ]:          0 :     if (!aTypes.getLength())
      67                 :            :     {
      68                 :            :         // my base class
      69         [ #  # ]:          0 :         Sequence<Type> aBaseClassTypes = OControlModel::_getTypes();
      70                 :            : 
      71         [ #  # ]:          0 :         Sequence<Type> aOwnTypes(1);
      72         [ #  # ]:          0 :         Type* pOwnTypes = aOwnTypes.getArray();
      73         [ #  # ]:          0 :         pOwnTypes[0] = getCppuType((Reference<XReset>*)NULL);
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 :         aTypes = concatSequences(aBaseClassTypes, aOwnTypes);
         [ #  # ][ #  # ]
                 [ #  # ]
      76                 :            :     }
      77                 :          0 :     return aTypes;
      78                 :            : }
      79                 :            : 
      80                 :            : 
      81                 :            : // XServiceInfo
      82                 :            : //------------------------------------------------------------------------------
      83                 :          0 : StringSequence  OFileControlModel::getSupportedServiceNames() throw(RuntimeException)
      84                 :            : {
      85                 :          0 :     StringSequence aSupported = OControlModel::getSupportedServiceNames();
      86         [ #  # ]:          0 :     aSupported.realloc(aSupported.getLength() + 1);
      87                 :            : 
      88         [ #  # ]:          0 :     ::rtl::OUString*pArray = aSupported.getArray();
      89         [ #  # ]:          0 :     pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_FILECONTROL;
      90                 :          0 :     return aSupported;
      91                 :            : }
      92                 :            : 
      93                 :            : //------------------------------------------------------------------
      94                 :            : DBG_NAME( OFileControlModel )
      95                 :            : //------------------------------------------------------------------
      96                 :          3 : OFileControlModel::OFileControlModel(const Reference<XMultiServiceFactory>& _rxFactory)
      97                 :            :                     :OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
      98 [ +  - ][ +  - ]:          3 :                     ,m_aResetListeners(m_aMutex)
                 [ +  - ]
      99                 :            : {
     100                 :            :     DBG_CTOR( OFileControlModel, NULL );
     101                 :          3 :     m_nClassId = FormComponentType::FILECONTROL;
     102                 :          3 : }
     103                 :            : 
     104                 :            : //------------------------------------------------------------------
     105                 :          0 : OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
     106                 :            :     :OControlModel( _pOriginal, _rxFactory )
     107         [ #  # ]:          0 :     ,m_aResetListeners( m_aMutex )
     108                 :            : {
     109                 :            :     DBG_CTOR( OFileControlModel, NULL );
     110                 :            : 
     111                 :          0 :     m_sDefaultValue = _pOriginal->m_sDefaultValue;
     112                 :          0 : }
     113                 :            : 
     114                 :            : //------------------------------------------------------------------
     115         [ +  - ]:          3 : OFileControlModel::~OFileControlModel()
     116                 :            : {
     117         [ -  + ]:          3 :     if (!OComponentHelper::rBHelper.bDisposed)
     118                 :            :     {
     119                 :          0 :         acquire();
     120         [ #  # ]:          0 :         dispose();
     121                 :            :     }
     122                 :            :     DBG_DTOR( OFileControlModel, NULL );
     123         [ -  + ]:          6 : }
     124                 :            : 
     125                 :            : //------------------------------------------------------------------------------
     126 [ #  # ][ #  # ]:          0 : IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
     127                 :            : 
     128                 :            : //------------------------------------------------------------------------------
     129                 :        112 : Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType) throw (RuntimeException)
     130                 :            : {
     131                 :        112 :     Any aReturn = OControlModel::queryAggregation(_rType);
     132         [ +  + ]:        112 :     if (!aReturn.hasValue())
     133                 :            :         aReturn = ::cppu::queryInterface(_rType
     134                 :            :             ,static_cast<XReset*>(this)
     135         [ +  - ]:          1 :         );
     136                 :            : 
     137                 :        112 :     return aReturn;
     138                 :            : }
     139                 :            : 
     140                 :            : // OComponentHelper
     141                 :            : //-----------------------------------------------------------------------------
     142                 :          3 : void OFileControlModel::disposing()
     143                 :            : {
     144         [ +  - ]:          3 :     OControlModel::disposing();
     145                 :            : 
     146 [ +  - ][ +  - ]:          3 :     EventObject aEvt(static_cast<XWeak*>(this));
     147 [ +  - ][ +  - ]:          3 :     m_aResetListeners.disposeAndClear(aEvt);
     148                 :          3 : }
     149                 :            : 
     150                 :            : //------------------------------------------------------------------------------
     151                 :          0 : Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
     152                 :            : {
     153                 :          0 :     Any aReturn;
     154         [ #  # ]:          0 :     switch ( _nHandle )
     155                 :            :     {
     156                 :            :         case PROPERTY_ID_DEFAULT_TEXT:
     157         [ #  # ]:          0 :             return makeAny( ::rtl::OUString() );
     158                 :            :     }
     159         [ #  # ]:          0 :     return OControlModel::getPropertyDefaultByHandle( _nHandle );
     160                 :            : }
     161                 :            : 
     162                 :            : //------------------------------------------------------------------------------
     163                 :          0 : void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
     164                 :            : {
     165         [ #  # ]:          0 :     switch (nHandle)
     166                 :            :     {
     167                 :          0 :         case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
     168                 :            :         default:
     169                 :          0 :             OControlModel::getFastPropertyValue(rValue, nHandle);
     170                 :            :     }
     171                 :          0 : }
     172                 :            : 
     173                 :            : //------------------------------------------------------------------------------
     174                 :          0 : void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception)
     175                 :            : {
     176         [ #  # ]:          0 :     switch (nHandle)
     177                 :            :     {
     178                 :            :         case PROPERTY_ID_DEFAULT_TEXT :
     179                 :            :             DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
     180                 :          0 :             rValue >>= m_sDefaultValue;
     181                 :          0 :             break;
     182                 :            :         default:
     183                 :          0 :             OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
     184                 :            :     }
     185                 :          0 : }
     186                 :            : 
     187                 :            : //------------------------------------------------------------------------------
     188                 :          0 : sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
     189                 :            :                             throw( IllegalArgumentException )
     190                 :            : {
     191         [ #  # ]:          0 :     switch (nHandle)
     192                 :            :     {
     193                 :            :         case PROPERTY_ID_DEFAULT_TEXT :
     194                 :          0 :             return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
     195                 :            :         default:
     196                 :          0 :             return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
     197                 :            :     }
     198                 :            : }
     199                 :            : 
     200                 :            : //------------------------------------------------------------------------------
     201                 :          0 : void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     202                 :            : {
     203                 :          0 :     BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
     204         [ #  # ]:          0 :         DECL_PROP1(DEFAULT_TEXT,    ::rtl::OUString,    BOUND);
     205         [ #  # ]:          0 :         DECL_PROP1(TABINDEX,        sal_Int16,          BOUND);
     206                 :            :     END_DESCRIBE_PROPERTIES();
     207                 :          0 : }
     208                 :            : 
     209                 :            : //------------------------------------------------------------------------------
     210                 :          0 : ::rtl::OUString SAL_CALL OFileControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
     211                 :            : {
     212                 :          0 :     return FRM_COMPONENT_FILECONTROL;   // old (non-sun) name for compatibility !
     213                 :            : }
     214                 :            : 
     215                 :            : //------------------------------------------------------------------------------
     216                 :          0 : void OFileControlModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
     217                 :            : {
     218         [ #  # ]:          0 :     OControlModel::write(_rxOutStream);
     219                 :            : 
     220         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     221                 :            : 
     222                 :            :     // Version
     223 [ #  # ][ #  # ]:          0 :     _rxOutStream->writeShort(0x0002);
     224                 :            :     // Default-Wert
     225         [ #  # ]:          0 :     _rxOutStream << m_sDefaultValue;
     226 [ #  # ][ #  # ]:          0 :     writeHelpTextCompatibly(_rxOutStream);
     227                 :          0 : }
     228                 :            : 
     229                 :            : //------------------------------------------------------------------------------
     230                 :          0 : void OFileControlModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
     231                 :            : {
     232         [ #  # ]:          0 :     OControlModel::read(_rxInStream);
     233         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     234                 :            : 
     235                 :            :     // Version
     236 [ #  # ][ #  # ]:          0 :     sal_uInt16 nVersion = _rxInStream->readShort();
     237                 :            :     // Default-Wert
     238      [ #  #  # ]:          0 :     switch (nVersion)
     239                 :            :     {
     240                 :            :         case 1:
     241         [ #  # ]:          0 :             _rxInStream >> m_sDefaultValue; break;
     242                 :            :         case 2:
     243         [ #  # ]:          0 :             _rxInStream >> m_sDefaultValue;
     244         [ #  # ]:          0 :             readHelpTextCompatibly(_rxInStream);
     245                 :          0 :             break;
     246                 :            :         default:
     247                 :            :             OSL_FAIL("OFileControlModel::read : unknown version !");
     248                 :          0 :             m_sDefaultValue = ::rtl::OUString();
     249         [ #  # ]:          0 :     }
     250                 :            : 
     251                 :            :     // Display default values after read
     252                 :            : //  _reset();
     253                 :          0 : }
     254                 :            : 
     255                 :            : //-----------------------------------------------------------------------------
     256                 :          0 : void SAL_CALL OFileControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException)
     257                 :            : {
     258         [ #  # ]:          0 :     ::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
     259 [ #  # ][ #  # ]:          0 :     EventObject aEvt(static_cast<XWeak*>(this));
     260                 :          0 :     sal_Bool bContinue = sal_True;
     261 [ #  # ][ #  # ]:          0 :     while (aIter.hasMoreElements() && bContinue)
                 [ #  # ]
     262 [ #  # ][ #  # ]:          0 :         bContinue =((XResetListener*)aIter.next())->approveReset(aEvt);
     263                 :            : 
     264         [ #  # ]:          0 :     if (bContinue)
     265                 :            :     {
     266                 :            :         {
     267                 :            :             // If Models are threadSave
     268         [ #  # ]:          0 :             ::osl::MutexGuard aGuard(m_aMutex);
     269 [ #  # ][ #  # ]:          0 :             _reset();
     270                 :            :         }
     271         [ #  # ]:          0 :         m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
     272 [ #  # ][ #  # ]:          0 :     }
     273                 :          0 : }
     274                 :            : 
     275                 :            : //-----------------------------------------------------------------------------
     276                 :          0 : void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
     277                 :            : {
     278                 :          0 :     m_aResetListeners.addInterface(_rxListener);
     279                 :          0 : }
     280                 :            : 
     281                 :            : //-----------------------------------------------------------------------------
     282                 :          0 : void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException)
     283                 :            : {
     284                 :          0 :     m_aResetListeners.removeInterface(_rxListener);
     285                 :          0 : }
     286                 :            : 
     287                 :            : //------------------------------------------------------------------------------
     288                 :          0 : void OFileControlModel::_reset()
     289                 :            : {
     290                 :            :     {   // release our mutex once (it's acquired in the calling method !), as setting aggregate properties
     291                 :            :         // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
     292                 :            :         // our own mutex locked
     293         [ #  # ]:          0 :         MutexRelease aRelease(m_aMutex);
     294 [ #  # ][ #  # ]:          0 :         m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
         [ #  # ][ #  # ]
                 [ #  # ]
     295                 :            :     }
     296                 :          0 : }
     297                 :            : 
     298                 :            : //.........................................................................
     299                 :            : }   // namespace frm
     300                 :            : //.........................................................................
     301                 :            : 
     302                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10