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

Generated by: LCOV version 1.10