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

Generated by: LCOV version 1.11