LCOV - code coverage report
Current view: top level - forms/source/component - File.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 109 0.0 %
Date: 2014-04-14 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "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           0 : InterfaceRef SAL_CALL OFileControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      50             : {
      51           0 :     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, std::exception)
      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             : 
      87           0 : OFileControlModel::OFileControlModel(const Reference<XComponentContext>& _rxFactory)
      88             :                     :OControlModel(_rxFactory, VCL_CONTROLMODEL_FILECONTROL)
      89           0 :                     ,m_aResetListeners(m_aMutex)
      90             : {
      91           0 :     m_nClassId = FormComponentType::FILECONTROL;
      92           0 : }
      93             : 
      94             : 
      95           0 : OFileControlModel::OFileControlModel( const OFileControlModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
      96             :     :OControlModel( _pOriginal, _rxFactory )
      97           0 :     ,m_aResetListeners( m_aMutex )
      98             : {
      99             : 
     100           0 :     m_sDefaultValue = _pOriginal->m_sDefaultValue;
     101           0 : }
     102             : 
     103             : 
     104           0 : OFileControlModel::~OFileControlModel()
     105             : {
     106           0 :     if (!OComponentHelper::rBHelper.bDisposed)
     107             :     {
     108           0 :         acquire();
     109           0 :         dispose();
     110             :     }
     111           0 : }
     112             : 
     113             : 
     114           0 : IMPLEMENT_DEFAULT_CLONING( OFileControlModel )
     115             : 
     116             : 
     117           0 : Any SAL_CALL OFileControlModel::queryAggregation(const Type& _rType) throw (RuntimeException, std::exception)
     118             : {
     119           0 :     Any aReturn = OControlModel::queryAggregation(_rType);
     120           0 :     if (!aReturn.hasValue())
     121           0 :         aReturn = ::cppu::queryInterface(_rType
     122             :             ,static_cast<XReset*>(this)
     123           0 :         );
     124             : 
     125           0 :     return aReturn;
     126             : }
     127             : 
     128             : // OComponentHelper
     129             : 
     130           0 : void OFileControlModel::disposing()
     131             : {
     132           0 :     OControlModel::disposing();
     133             : 
     134           0 :     EventObject aEvt(static_cast<XWeak*>(this));
     135           0 :     m_aResetListeners.disposeAndClear(aEvt);
     136           0 : }
     137             : 
     138             : 
     139           0 : Any OFileControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
     140             : {
     141           0 :     switch ( _nHandle )
     142             :     {
     143             :         case PROPERTY_ID_DEFAULT_TEXT:
     144           0 :             return makeAny( OUString() );
     145             :     }
     146           0 :     return OControlModel::getPropertyDefaultByHandle( _nHandle );
     147             : }
     148             : 
     149             : 
     150           0 : void OFileControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
     151             : {
     152           0 :     switch (nHandle)
     153             :     {
     154           0 :         case PROPERTY_ID_DEFAULT_TEXT : rValue <<= m_sDefaultValue; break;
     155             :         default:
     156           0 :             OControlModel::getFastPropertyValue(rValue, nHandle);
     157             :     }
     158           0 : }
     159             : 
     160             : 
     161           0 : void OFileControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception, std::exception)
     162             : {
     163           0 :     switch (nHandle)
     164             :     {
     165             :         case PROPERTY_ID_DEFAULT_TEXT :
     166             :             DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OFileControlModel::setFastPropertyValue_NoBroadcast : invalid type !" );
     167           0 :             rValue >>= m_sDefaultValue;
     168           0 :             break;
     169             :         default:
     170           0 :             OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
     171             :     }
     172           0 : }
     173             : 
     174             : 
     175           0 : sal_Bool OFileControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
     176             :                             throw( IllegalArgumentException )
     177             : {
     178           0 :     switch (nHandle)
     179             :     {
     180             :         case PROPERTY_ID_DEFAULT_TEXT :
     181           0 :             return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sDefaultValue);
     182             :         default:
     183           0 :             return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
     184             :     }
     185             : }
     186             : 
     187             : 
     188           0 : void OFileControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     189             : {
     190           0 :     BEGIN_DESCRIBE_PROPERTIES( 2, OControlModel )
     191           0 :         DECL_PROP1(DEFAULT_TEXT,    OUString,    BOUND);
     192           0 :         DECL_PROP1(TABINDEX,        sal_Int16,          BOUND);
     193             :     END_DESCRIBE_PROPERTIES();
     194           0 : }
     195             : 
     196             : 
     197           0 : OUString SAL_CALL OFileControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     198             : {
     199           0 :     return OUString(FRM_COMPONENT_FILECONTROL);   // old (non-sun) name for compatibility !
     200             : }
     201             : 
     202             : 
     203           0 : void OFileControlModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
     204             : {
     205           0 :     OControlModel::write(_rxOutStream);
     206             : 
     207           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     208             : 
     209             :     // Version
     210           0 :     _rxOutStream->writeShort(0x0002);
     211             :     // Default-Wert
     212           0 :     _rxOutStream << m_sDefaultValue;
     213           0 :     writeHelpTextCompatibly(_rxOutStream);
     214           0 : }
     215             : 
     216             : 
     217           0 : void OFileControlModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
     218             : {
     219           0 :     OControlModel::read(_rxInStream);
     220           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     221             : 
     222             :     // Version
     223           0 :     sal_uInt16 nVersion = _rxInStream->readShort();
     224             :     // Default-Wert
     225           0 :     switch (nVersion)
     226             :     {
     227             :         case 1:
     228           0 :             _rxInStream >> m_sDefaultValue; break;
     229             :         case 2:
     230           0 :             _rxInStream >> m_sDefaultValue;
     231           0 :             readHelpTextCompatibly(_rxInStream);
     232           0 :             break;
     233             :         default:
     234             :             OSL_FAIL("OFileControlModel::read : unknown version !");
     235           0 :             m_sDefaultValue = OUString();
     236           0 :     }
     237             : 
     238             :     // Display default values after read
     239             : //  _reset();
     240           0 : }
     241             : 
     242             : 
     243           0 : void SAL_CALL OFileControlModel::reset() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     244             : {
     245           0 :     ::cppu::OInterfaceIteratorHelper aIter(m_aResetListeners);
     246           0 :     EventObject aEvt(static_cast<XWeak*>(this));
     247           0 :     sal_Bool bContinue = sal_True;
     248           0 :     while (aIter.hasMoreElements() && bContinue)
     249           0 :         bContinue =((XResetListener*)aIter.next())->approveReset(aEvt);
     250             : 
     251           0 :     if (bContinue)
     252             :     {
     253             :         {
     254             :             // If Models are threadSave
     255           0 :             ::osl::MutexGuard aGuard(m_aMutex);
     256           0 :             _reset();
     257             :         }
     258           0 :         m_aResetListeners.notifyEach( &XResetListener::resetted, aEvt );
     259           0 :     }
     260           0 : }
     261             : 
     262             : 
     263           0 : void OFileControlModel::addResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     264             : {
     265           0 :     m_aResetListeners.addInterface(_rxListener);
     266           0 : }
     267             : 
     268             : 
     269           0 : void OFileControlModel::removeResetListener(const Reference<XResetListener>& _rxListener) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     270             : {
     271           0 :     m_aResetListeners.removeInterface(_rxListener);
     272           0 : }
     273             : 
     274             : 
     275           0 : void OFileControlModel::_reset()
     276             : {
     277             :     {   // release our mutex once (it's acquired in the calling method !), as setting aggregate properties
     278             :         // may cause any uno controls belonging to us to lock the solar mutex, which is potentially dangerous with
     279             :         // our own mutex locked
     280           0 :         MutexRelease aRelease(m_aMutex);
     281           0 :         m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(m_sDefaultValue));
     282             :     }
     283           0 : }
     284             : 
     285             : 
     286             : }   // namespace frm
     287             : 
     288             : 
     289             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10