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

Generated by: LCOV version 1.11