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

Generated by: LCOV version 1.10