LCOV - code coverage report
Current view: top level - forms/source/component - CheckBox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 120 0.0 %
Date: 2014-04-14 Functions: 0 17 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 "CheckBox.hxx"
      21             : #include "property.hxx"
      22             : #include "property.hrc"
      23             : #include "services.hxx"
      24             : #include <tools/debug.hxx>
      25             : #include <comphelper/basicio.hxx>
      26             : #include <comphelper/processfactory.hxx>
      27             : 
      28             : 
      29             : namespace frm
      30             : {
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::sdb;
      33             : using namespace ::com::sun::star::sdbc;
      34             : using namespace ::com::sun::star::sdbcx;
      35             : using namespace ::com::sun::star::beans;
      36             : using namespace ::com::sun::star::container;
      37             : using namespace ::com::sun::star::form;
      38             : using namespace ::com::sun::star::awt;
      39             : using namespace ::com::sun::star::io;
      40             : using namespace ::com::sun::star::lang;
      41             : using namespace ::com::sun::star::util;
      42             : using namespace ::com::sun::star::form::binding;
      43             : 
      44             : 
      45             : //= OCheckBoxControl
      46             : 
      47             : 
      48             : 
      49           0 : OCheckBoxControl::OCheckBoxControl(const Reference<XComponentContext>& _rxFactory)
      50           0 :     :OBoundControl(_rxFactory, VCL_CONTROL_CHECKBOX)
      51             : {
      52           0 : }
      53             : 
      54             : 
      55           0 : InterfaceRef SAL_CALL OCheckBoxControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
      56             : {
      57           0 :     return *(new OCheckBoxControl( comphelper::getComponentContext(_rxFactory) ));
      58             : }
      59             : 
      60             : 
      61           0 : StringSequence SAL_CALL OCheckBoxControl::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, 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_CHECKBOX;
      68           0 :     return aSupported;
      69             : }
      70             : 
      71             : 
      72             : //= OCheckBoxModel
      73             : 
      74             : 
      75             : 
      76           0 : InterfaceRef SAL_CALL OCheckBoxModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException)
      77             : {
      78           0 :     return *(new OCheckBoxModel( comphelper::getComponentContext(_rxFactory) ));
      79             : }
      80             : 
      81             : 
      82             : 
      83           0 : OCheckBoxModel::OCheckBoxModel(const Reference<XComponentContext>& _rxFactory)
      84           0 :     :OReferenceValueComponent( _rxFactory, VCL_CONTROLMODEL_CHECKBOX, FRM_SUN_CONTROL_CHECKBOX, sal_True )
      85             :                     // use the old control name for compytibility reasons
      86             : {
      87             : 
      88           0 :     m_nClassId = FormComponentType::CHECKBOX;
      89           0 :     initValueProperty( PROPERTY_STATE, PROPERTY_ID_STATE );
      90           0 : }
      91             : 
      92             : 
      93           0 : OCheckBoxModel::OCheckBoxModel( const OCheckBoxModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
      94           0 :     :OReferenceValueComponent( _pOriginal, _rxFactory )
      95             : {
      96           0 : }
      97             : 
      98             : 
      99           0 : OCheckBoxModel::~OCheckBoxModel()
     100             : {
     101           0 : }
     102             : 
     103             : 
     104           0 : IMPLEMENT_DEFAULT_CLONING( OCheckBoxModel )
     105             : 
     106             : // XServiceInfo
     107             : 
     108           0 : StringSequence SAL_CALL OCheckBoxModel::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception)
     109             : {
     110           0 :     StringSequence aSupported = OReferenceValueComponent::getSupportedServiceNames();
     111             : 
     112           0 :     sal_Int32 nOldLen = aSupported.getLength();
     113           0 :     aSupported.realloc( nOldLen + 8 );
     114           0 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
     115             : 
     116           0 :     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
     117           0 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     118           0 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     119             : 
     120           0 :     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
     121           0 :     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
     122             : 
     123           0 :     *pStoreTo++ = FRM_SUN_COMPONENT_CHECKBOX;
     124           0 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CHECKBOX;
     125           0 :     *pStoreTo++ = BINDABLE_DATABASE_CHECK_BOX;
     126             : 
     127           0 :     return aSupported;
     128             : }
     129             : 
     130             : 
     131           0 : void OCheckBoxModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     132             : {
     133           0 :     BEGIN_DESCRIBE_PROPERTIES( 1, OReferenceValueComponent )
     134           0 :         DECL_PROP1(TABINDEX,        sal_Int16,          BOUND);
     135             :     END_DESCRIBE_PROPERTIES();
     136           0 : }
     137             : 
     138             : 
     139           0 : OUString SAL_CALL OCheckBoxModel::getServiceName() throw(RuntimeException, std::exception)
     140             : {
     141           0 :     return OUString(FRM_COMPONENT_CHECKBOX);  // old (non-sun) name for compatibility !
     142             : }
     143             : 
     144             : 
     145           0 : void SAL_CALL OCheckBoxModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream)
     146             :     throw(stario::IOException, RuntimeException, std::exception)
     147             : {
     148           0 :     OReferenceValueComponent::write(_rxOutStream);
     149             : 
     150             :     // Version
     151           0 :     _rxOutStream->writeShort(0x0003);
     152             :     // Properties
     153           0 :     _rxOutStream << getReferenceValue();
     154           0 :     _rxOutStream << (sal_Int16)getDefaultChecked();
     155           0 :     writeHelpTextCompatibly(_rxOutStream);
     156             :     // from version 0x0003 : common properties
     157           0 :     writeCommonProperties(_rxOutStream);
     158           0 : }
     159             : 
     160             : 
     161           0 : void SAL_CALL OCheckBoxModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw(stario::IOException, RuntimeException, std::exception)
     162             : {
     163           0 :     OReferenceValueComponent::read(_rxInStream);
     164           0 :     osl::MutexGuard aGuard(m_aMutex);
     165             : 
     166             :     // Version
     167           0 :     sal_uInt16 nVersion = _rxInStream->readShort();
     168             : 
     169           0 :     OUString sReferenceValue;
     170           0 :     sal_Int16       nDefaultChecked( 0 );
     171           0 :     switch ( nVersion )
     172             :     {
     173             :         case 0x0001:
     174           0 :             _rxInStream >> sReferenceValue;
     175           0 :             nDefaultChecked = _rxInStream->readShort();
     176           0 :             break;
     177             :         case 0x0002:
     178           0 :             _rxInStream >> sReferenceValue;
     179           0 :             _rxInStream >> nDefaultChecked;
     180           0 :             readHelpTextCompatibly( _rxInStream );
     181           0 :             break;
     182             :         case 0x0003:
     183           0 :             _rxInStream >> sReferenceValue;
     184           0 :             _rxInStream >> nDefaultChecked;
     185           0 :             readHelpTextCompatibly(_rxInStream);
     186           0 :             readCommonProperties(_rxInStream);
     187           0 :             break;
     188             :         default:
     189             :             OSL_FAIL("OCheckBoxModel::read : unknown version !");
     190           0 :             defaultCommonProperties();
     191           0 :             break;
     192             :     }
     193           0 :     setReferenceValue( sReferenceValue );
     194           0 :     setDefaultChecked( static_cast< ToggleState >( nDefaultChecked ) );
     195             : 
     196             :     // After reading in, display the default values
     197           0 :     if ( !getControlSource().isEmpty() )
     198             :         // (not if we don't have a control source - the "State" property acts like it is persistent, then
     199           0 :         resetNoBroadcast();
     200           0 : }
     201             : 
     202           0 : bool OCheckBoxModel::DbUseBool()
     203             : {
     204           0 :     if ( ! (getReferenceValue().isEmpty() && getNoCheckReferenceValue().isEmpty()) )
     205           0 :         return false;
     206           0 :     return true;
     207             : }
     208             : 
     209             : 
     210           0 : Any OCheckBoxModel::translateDbColumnToControlValue()
     211             : {
     212           0 :     Any aValue;
     213             : 
     214             : 
     215             :     // Set value in ControlModel
     216           0 :     bool bValue = bool(); // avoid warning
     217           0 :     if(DbUseBool())
     218             :     {
     219           0 :         bValue = m_xColumn->getBoolean();
     220             :     }
     221             :     else
     222             :     {
     223           0 :         const OUString sVal(m_xColumn->getString());
     224           0 :         if (sVal == getReferenceValue())
     225           0 :             bValue = true;
     226           0 :         else if (sVal == getNoCheckReferenceValue())
     227           0 :             bValue = false;
     228             :         else
     229           0 :             aValue <<= static_cast<sal_Int16>(getDefaultChecked());
     230             :     }
     231           0 :     if ( m_xColumn->wasNull() )
     232             :     {
     233           0 :         sal_Bool bTriState = sal_True;
     234           0 :         if ( m_xAggregateSet.is() )
     235           0 :             m_xAggregateSet->getPropertyValue( PROPERTY_TRISTATE ) >>= bTriState;
     236           0 :         aValue <<= (sal_Int16)( bTriState ? TRISTATE_INDET : getDefaultChecked() );
     237             :     }
     238           0 :     else if ( !aValue.hasValue() )
     239             :     {
     240             :         // Since above either bValue is initialised, either aValue.hasValue(),
     241             :         // bValue cannot be used uninitialised here.
     242             :         // But GCC does not see/understand that, which breaks -Werror builds,
     243             :         // so we explicitly default-initialise it.
     244           0 :         aValue <<= (sal_Int16)( bValue ? TRISTATE_TRUE : TRISTATE_FALSE );
     245             :     }
     246             : 
     247           0 :     return aValue;
     248             : }
     249             : 
     250             : 
     251           0 : sal_Bool OCheckBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     252             : {
     253             :     OSL_PRECOND( m_xColumnUpdate.is(), "OCheckBoxModel::commitControlValueToDbColumn: not bound!" );
     254           0 :     if ( m_xColumnUpdate.is() )
     255             :     {
     256           0 :         Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
     257             :         try
     258             :         {
     259           0 :             sal_Int16 nValue = TRISTATE_INDET;
     260           0 :             aControlValue >>= nValue;
     261           0 :             switch (nValue)
     262             :             {
     263             :                 case TRISTATE_INDET:
     264           0 :                     m_xColumnUpdate->updateNull();
     265           0 :                     break;
     266             :                 case TRISTATE_TRUE:
     267           0 :                     if (DbUseBool())
     268           0 :                         m_xColumnUpdate->updateBoolean( sal_True );
     269             :                     else
     270           0 :                         m_xColumnUpdate->updateString( getReferenceValue() );
     271           0 :                     break;
     272             :                 case TRISTATE_FALSE:
     273           0 :                     if (DbUseBool())
     274           0 :                         m_xColumnUpdate->updateBoolean( sal_False );
     275             :                     else
     276           0 :                         m_xColumnUpdate->updateString( getNoCheckReferenceValue() );
     277           0 :                     break;
     278             :                 default:
     279             :                     OSL_FAIL("OCheckBoxModel::commitControlValueToDbColumn: invalid value !");
     280             :             }
     281             :         }
     282           0 :         catch(const Exception&)
     283             :         {
     284             :             OSL_FAIL("OCheckBoxModel::commitControlValueToDbColumn: could not commit !");
     285           0 :         }
     286             :     }
     287           0 :     return sal_True;
     288             : }
     289             : 
     290             : 
     291             : }
     292             : 
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10