LCOV - code coverage report
Current view: top level - forms/source/component - Pattern.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 40 86 46.5 %
Date: 2014-11-03 Functions: 13 20 65.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 "Pattern.hxx"
      21             : #include "comphelper/processfactory.hxx"
      22             : 
      23             : 
      24             : namespace frm
      25             : {
      26             : 
      27             : 
      28             :     using ::com::sun::star::uno::Reference;
      29             :     using ::com::sun::star::lang::XMultiServiceFactory;
      30             :     using ::com::sun::star::uno::Sequence;
      31             :     using ::com::sun::star::uno::Type;
      32             :     using ::com::sun::star::uno::XComponentContext;
      33             :     using ::com::sun::star::beans::Property;
      34             :     using ::com::sun::star::uno::Exception;
      35             :     using ::com::sun::star::uno::XInterface;
      36             :     using ::com::sun::star::uno::Any;
      37             :     using ::com::sun::star::uno::makeAny;
      38             :     using ::com::sun::star::sdbc::XRowSet;
      39             :     using ::com::sun::star::uno::UNO_QUERY;
      40             : 
      41             :     namespace FormComponentType = ::com::sun::star::form::FormComponentType;
      42             : 
      43          12 : OPatternControl::OPatternControl(const Reference<XComponentContext>& _rxFactory)
      44          12 :     :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
      45             : {
      46          12 : }
      47             : 
      48             : 
      49          12 : InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      50             : {
      51          12 :     return *(new OPatternControl( comphelper::getComponentContext(_rxFactory) ));
      52             : }
      53             : 
      54             : 
      55           0 : Sequence<Type> OPatternControl::_getTypes()
      56             : {
      57           0 :     return OBoundControl::_getTypes();
      58             : }
      59             : 
      60             : 
      61           0 : StringSequence OPatternControl::getSupportedServiceNames() throw(std::exception)
      62             : {
      63           0 :     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
      64           0 :     aSupported.realloc(aSupported.getLength() + 1);
      65             : 
      66           0 :     OUString*pArray = aSupported.getArray();
      67           0 :     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_PATTERNFIELD;
      68           0 :     return aSupported;
      69             : }
      70             : 
      71             : 
      72             : // OPatternModel
      73             : 
      74             : 
      75          18 : InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      76             : {
      77          18 :     return *(new OPatternModel( comphelper::getComponentContext(_rxFactory) ));
      78             : }
      79             : 
      80             : 
      81           0 : Sequence<Type> OPatternModel::_getTypes()
      82             : {
      83           0 :     return OEditBaseModel::_getTypes();
      84             : }
      85             : 
      86             : 
      87             : 
      88          18 : OPatternModel::OPatternModel(const Reference<XComponentContext>& _rxFactory)
      89          18 :     :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, false, false )
      90             :                                     // use the old control name for compytibility reasons
      91             : {
      92             : 
      93          18 :     m_nClassId = FormComponentType::PATTERNFIELD;
      94          18 :     initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
      95          18 : }
      96             : 
      97             : 
      98           2 : OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
      99           2 :     :OEditBaseModel( _pOriginal, _rxFactory )
     100             : {
     101           2 : }
     102             : 
     103             : 
     104          40 : OPatternModel::~OPatternModel()
     105             : {
     106          40 : }
     107             : 
     108             : // XCloneable
     109             : 
     110           2 : IMPLEMENT_DEFAULT_CLONING( OPatternModel )
     111             : 
     112             : // XServiceInfo
     113             : 
     114          16 : StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw(std::exception)
     115             : {
     116          16 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
     117          16 :     aSupported.realloc(aSupported.getLength() + 2);
     118             : 
     119          16 :     OUString*pArray = aSupported.getArray();
     120          16 :     pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
     121          16 :     pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD;
     122          16 :     return aSupported;
     123             : }
     124             : 
     125             : 
     126             : 
     127          22 : void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     128             : {
     129          22 :     BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
     130          22 :         DECL_PROP2(DEFAULT_TEXT,    OUString,    BOUND, MAYBEDEFAULT);
     131          22 :         DECL_BOOL_PROP1(EMPTY_IS_NULL,                  BOUND);
     132          22 :         DECL_PROP1(TABINDEX,        sal_Int16,          BOUND);
     133          22 :         DECL_PROP2(FILTERPROPOSAL,  sal_Bool,           BOUND, MAYBEDEFAULT);
     134             :     END_DESCRIBE_PROPERTIES();
     135          22 : }
     136             : 
     137             : 
     138           2 : OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     139             : {
     140           2 :     return OUString(FRM_COMPONENT_PATTERNFIELD);  // old (non-sun) name for compatibility !
     141             : }
     142             : 
     143             : 
     144           0 : bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     145             : {
     146           0 :     Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     147             : 
     148           0 :     if ( aNewValue != m_aLastKnownValue )
     149             :     {
     150           0 :         OUString sNewValue;
     151           0 :         aNewValue >>= sNewValue;
     152             : 
     153           0 :         if  (   !aNewValue.hasValue()
     154           0 :             ||  (   sNewValue.isEmpty()         // an empty string
     155           0 :                 &&  m_bEmptyIsNull              // which should be interpreted as NULL
     156             :                 )
     157             :             )
     158             :         {
     159           0 :             m_xColumnUpdate->updateNull();
     160             :         }
     161             :         else
     162             :         {
     163             :             OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
     164           0 :             if ( !m_pFormattedValue.get() )
     165           0 :                 return false;
     166             : 
     167           0 :             if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
     168           0 :                 return false;
     169             :         }
     170             : 
     171           0 :         m_aLastKnownValue = aNewValue;
     172             :     }
     173             : 
     174           0 :     return true;
     175             : }
     176             : 
     177             : 
     178           0 : void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
     179             : {
     180           0 :     OEditBaseModel::onConnectedDbColumn( _rxForm );
     181             : 
     182           0 :     Reference< XPropertySet > xField( getField() );
     183           0 :     if ( !xField.is() )
     184           0 :         return;
     185             : 
     186           0 :     m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
     187             : }
     188             : 
     189             : 
     190           0 : void OPatternModel::onDisconnectedDbColumn()
     191             : {
     192           0 :     OEditBaseModel::onDisconnectedDbColumn();
     193           0 :     m_pFormattedValue.reset();
     194           0 : }
     195             : 
     196             : // XPropertyChangeListener
     197             : 
     198           0 : Any OPatternModel::translateDbColumnToControlValue()
     199             : {
     200             :     OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
     201             : 
     202           0 :     if ( m_pFormattedValue.get() )
     203             :     {
     204           0 :         OUString sValue( m_pFormattedValue->getFormattedValue() );
     205           0 :         if  (   sValue.isEmpty()
     206           0 :             &&  m_pFormattedValue->getColumn().is()
     207           0 :             &&  m_pFormattedValue->getColumn()->wasNull()
     208             :             )
     209             :         {
     210           0 :             m_aLastKnownValue.clear();
     211             :         }
     212             :         else
     213             :         {
     214           0 :             m_aLastKnownValue <<= sValue;
     215           0 :         }
     216             :     }
     217             :     else
     218           0 :         m_aLastKnownValue.clear();
     219             : 
     220           0 :     return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( OUString() );
     221             :         // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
     222             : }
     223             : 
     224             : // XReset
     225             : 
     226          24 : Any OPatternModel::getDefaultForReset() const
     227             : {
     228          24 :     return makeAny( m_aDefaultText );
     229             : }
     230             : 
     231             : 
     232          24 : void OPatternModel::resetNoBroadcast()
     233             : {
     234          24 :     OEditBaseModel::resetNoBroadcast();
     235          24 :     m_aLastKnownValue.clear();
     236          24 : }
     237             : 
     238             : 
     239             : }   // namespace frm
     240             : 
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10