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

Generated by: LCOV version 1.10