LCOV - code coverage report
Current view: top level - toolkit/source/controls/grid - defaultgriddatamodel.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 157 191 82.2 %
Date: 2014-11-03 Functions: 31 37 83.8 %
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 <com/sun/star/awt/grid/XMutableGridDataModel.hpp>
      21             : #include <com/sun/star/lang/XServiceInfo.hpp>
      22             : #include <com/sun/star/uno/XComponentContext.hpp>
      23             : 
      24             : #include <comphelper/componentguard.hxx>
      25             : #include <cppuhelper/basemutex.hxx>
      26             : #include <cppuhelper/compbase2.hxx>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : #include <toolkit/helper/servicenames.hxx>
      29             : #include <tools/diagnose_ex.h>
      30             : #include <toolkit/helper/mutexandbroadcasthelper.hxx>
      31             : 
      32             : #include <algorithm>
      33             : #include <functional>
      34             : #include <vector>
      35             : #include <boost/bind.hpp>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::awt;
      40             : using namespace ::com::sun::star::awt::grid;
      41             : using namespace ::com::sun::star::lang;
      42             : 
      43             : namespace {
      44             : 
      45             : enum broadcast_type { row_added, row_removed, data_changed};
      46             : 
      47             : typedef ::cppu::WeakComponentImplHelper2    <   XMutableGridDataModel
      48             :                                             ,   XServiceInfo
      49             :                                             >   DefaultGridDataModel_Base;
      50             : 
      51             : class DefaultGridDataModel  :public ::cppu::BaseMutex
      52             :                             ,public DefaultGridDataModel_Base
      53             : {
      54             : public:
      55             :     DefaultGridDataModel();
      56             :     DefaultGridDataModel( DefaultGridDataModel const & i_copySource );
      57             :     virtual ~DefaultGridDataModel();
      58             : 
      59             :     // XMutableGridDataModel
      60             :     virtual void SAL_CALL addRow( const Any& i_heading, const css::uno::Sequence< css::uno::Any >& Data ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      61             :     virtual void SAL_CALL addRows( const css::uno::Sequence< css::uno::Any>& Headings, const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& Data ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      62             :     virtual void SAL_CALL insertRow( ::sal_Int32 i_index, const css::uno::Any& i_heading, const css::uno::Sequence< css::uno::Any >& Data ) throw (css::uno::RuntimeException, css::lang::IndexOutOfBoundsException, std::exception) SAL_OVERRIDE;
      63             :     virtual void SAL_CALL insertRows( ::sal_Int32 i_index, const css::uno::Sequence< css::uno::Any>& Headings, const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& Data ) throw (css::lang::IllegalArgumentException, css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             :     virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      65             :     virtual void SAL_CALL removeAllRows(  ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      66             :     virtual void SAL_CALL updateCellData( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const css::uno::Any& Value ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             :     virtual void SAL_CALL updateRowData( const css::uno::Sequence< ::sal_Int32 >& ColumnIndexes, ::sal_Int32 RowIndex, const css::uno::Sequence< css::uno::Any >& Values ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      68             :     virtual void SAL_CALL updateRowHeading( ::sal_Int32 RowIndex, const css::uno::Any& Heading ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      69             :     virtual void SAL_CALL updateCellToolTip( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const css::uno::Any& Value ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      70             :     virtual void SAL_CALL updateRowToolTip( ::sal_Int32 RowIndex, const css::uno::Any& Value ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      71             :     virtual void SAL_CALL addGridDataListener( const css::uno::Reference< css::awt::grid::XGridDataListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      72             :     virtual void SAL_CALL removeGridDataListener( const css::uno::Reference< css::awt::grid::XGridDataListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      73             : 
      74             :     // XGridDataModel
      75             :     virtual ::sal_Int32 SAL_CALL getRowCount() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      76             :     virtual ::sal_Int32 SAL_CALL getColumnCount() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      77             :     virtual css::uno::Any SAL_CALL getCellData( ::sal_Int32 Column, ::sal_Int32 Row ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      78             :     virtual css::uno::Any SAL_CALL getCellToolTip( ::sal_Int32 Column, ::sal_Int32 Row ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      79             :     virtual css::uno::Any SAL_CALL getRowHeading( ::sal_Int32 RowIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      80             :     virtual css::uno::Sequence< css::uno::Any > SAL_CALL getRowData( ::sal_Int32 RowIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      81             : 
      82             :     // OComponentHelper
      83             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
      84             : 
      85             :     // XCloneable
      86             :     virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone(  ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      87             : 
      88             :     // XServiceInfo
      89             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      90             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      91             :     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      92             : 
      93             : private:
      94             :     typedef ::std::pair< Any, Any >     CellData;
      95             :     typedef ::std::vector< CellData >   RowData;
      96             :     typedef ::std::vector< RowData >    GridData;
      97             : 
      98             :     void broadcast(
      99             :         GridDataEvent const & i_event,
     100             :         void ( SAL_CALL css::awt::grid::XGridDataListener::*i_listenerMethod )( css::awt::grid::GridDataEvent const & ),
     101             :         ::comphelper::ComponentGuard & i_instanceLock
     102             :     );
     103             : 
     104             :     void    impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount = -1 );
     105             : 
     106        1130 :     ::sal_Int32 impl_getRowCount_nolck() const { return sal_Int32( m_aData.size() ); }
     107             : 
     108             :     CellData const &    impl_getCellData_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex ) const;
     109             :     CellData&           impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex );
     110             :     RowData&            impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount );
     111             : 
     112             :     GridData m_aData;
     113             :     ::std::vector< css::uno::Any > m_aRowHeaders;
     114             :     sal_Int32 m_nColumnCount;
     115             : };
     116             : 
     117          22 :     DefaultGridDataModel::DefaultGridDataModel()
     118             :         :DefaultGridDataModel_Base( m_aMutex )
     119             :         ,m_aRowHeaders()
     120          22 :         ,m_nColumnCount(0)
     121             :     {
     122          22 :     }
     123             : 
     124             : 
     125           2 :     DefaultGridDataModel::DefaultGridDataModel( DefaultGridDataModel const & i_copySource )
     126             :         :cppu::BaseMutex()
     127             :         ,DefaultGridDataModel_Base( m_aMutex )
     128             :         ,m_aData( i_copySource.m_aData )
     129             :         ,m_aRowHeaders( i_copySource.m_aRowHeaders )
     130           2 :         ,m_nColumnCount( i_copySource.m_nColumnCount )
     131             :     {
     132           2 :     }
     133             : 
     134             : 
     135          28 :     DefaultGridDataModel::~DefaultGridDataModel()
     136             :     {
     137          28 :     }
     138             : 
     139             : 
     140          48 :     void DefaultGridDataModel::broadcast( GridDataEvent const & i_event,
     141             :         void ( SAL_CALL XGridDataListener::*i_listenerMethod )( GridDataEvent const & ), ::comphelper::ComponentGuard & i_instanceLock )
     142             :     {
     143          48 :         ::cppu::OInterfaceContainerHelper* pListeners = rBHelper.getContainer( cppu::UnoType<XGridDataListener>::get() );
     144          48 :         if ( !pListeners )
     145          52 :             return;
     146             : 
     147          44 :         i_instanceLock.clear();
     148          44 :         pListeners->notifyEach( i_listenerMethod, i_event );
     149             :     }
     150             : 
     151             : 
     152        1106 :     ::sal_Int32 SAL_CALL DefaultGridDataModel::getRowCount() throw (::com::sun::star::uno::RuntimeException, std::exception)
     153             :     {
     154        1106 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     155        1106 :         return impl_getRowCount_nolck();
     156             :     }
     157             : 
     158             : 
     159          42 :     ::sal_Int32 SAL_CALL DefaultGridDataModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException, std::exception)
     160             :     {
     161          42 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     162          42 :         return m_nColumnCount;
     163             :     }
     164             : 
     165             : 
     166         886 :     DefaultGridDataModel::CellData const & DefaultGridDataModel::impl_getCellData_throw( sal_Int32 const i_column, sal_Int32 const i_row ) const
     167             :     {
     168        1772 :         if  (   ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() )
     169        1772 :             ||  ( i_column < 0 ) || ( i_column > m_nColumnCount )
     170             :             )
     171           0 :             throw IndexOutOfBoundsException( OUString(), *const_cast< DefaultGridDataModel* >( this ) );
     172             : 
     173         886 :         RowData const & rRow( m_aData[ i_row ] );
     174         886 :         if ( size_t( i_column ) < rRow.size() )
     175         886 :             return rRow[ i_column ];
     176             : 
     177           0 :         static CellData s_aEmpty;
     178           0 :         return s_aEmpty;
     179             :     }
     180             : 
     181             : 
     182          44 :     DefaultGridDataModel::RowData& DefaultGridDataModel::impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount )
     183             :     {
     184             :         OSL_ENSURE( i_requiredColumnCount <= size_t( m_nColumnCount ), "DefaultGridDataModel::impl_getRowDataAccess_throw: invalid column count!" );
     185          44 :         if  ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
     186           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     187             : 
     188          44 :         RowData& rRowData( m_aData[ i_rowIndex ] );
     189          44 :         if ( rRowData.size() < i_requiredColumnCount )
     190           0 :             rRowData.resize( i_requiredColumnCount );
     191          44 :         return rRowData;
     192             :     }
     193             : 
     194             : 
     195           8 :     DefaultGridDataModel::CellData& DefaultGridDataModel::impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex )
     196             :     {
     197           8 :         if  ( ( i_columnIndex < 0 ) || ( i_columnIndex >= m_nColumnCount ) )
     198           2 :             throw IndexOutOfBoundsException( OUString(), *this );
     199             : 
     200           6 :         RowData& rRowData( impl_getRowDataAccess_throw( i_rowIndex, size_t( i_columnIndex + 1 ) ) );
     201           6 :         return rRowData[ i_columnIndex ];
     202             :     }
     203             : 
     204             : 
     205         886 :     Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
     206             :     {
     207         886 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     208         886 :         return impl_getCellData_throw( i_column, i_row ).first;
     209             :     }
     210             : 
     211             : 
     212           0 :     Any SAL_CALL DefaultGridDataModel::getCellToolTip( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
     213             :     {
     214           0 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     215           0 :         return impl_getCellData_throw( i_column, i_row ).second;
     216             :     }
     217             : 
     218             : 
     219         156 :     Any SAL_CALL DefaultGridDataModel::getRowHeading( ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
     220             :     {
     221         156 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     222             : 
     223         156 :         if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aRowHeaders.size() ) )
     224           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     225             : 
     226         156 :         return m_aRowHeaders[ i_row ];
     227             :     }
     228             : 
     229             : 
     230          38 :     Sequence< Any > SAL_CALL DefaultGridDataModel::getRowData( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     231             :     {
     232          38 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     233             : 
     234          38 :         Sequence< Any > resultData( m_nColumnCount );
     235          38 :         RowData& rRowData = impl_getRowDataAccess_throw( i_rowIndex, m_nColumnCount );
     236             : 
     237             :         ::std::transform( rRowData.begin(), rRowData.end(), resultData.getArray(),
     238          38 :                           boost::bind(&CellData::first,_1));
     239          38 :         return resultData;
     240             :     }
     241             : 
     242             : 
     243          66 :     void DefaultGridDataModel::impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount )
     244             :     {
     245             :         OSL_PRECOND( ( i_assumedColCount <= 0 ) || ( i_assumedColCount >= i_rowData.getLength() ),
     246             :             "DefaultGridDataModel::impl_insertRow: invalid column count!" );
     247             : 
     248             :         // insert heading
     249          66 :         m_aRowHeaders.insert( m_aRowHeaders.begin() + i_position, i_heading );
     250             : 
     251             :         // create new data row
     252          66 :         RowData newRow( i_assumedColCount > 0 ? i_assumedColCount : i_rowData.getLength() );
     253          66 :         RowData::iterator cellData = newRow.begin();
     254         314 :         for ( const Any* pData = i_rowData.begin(); pData != i_rowData.end(); ++pData, ++cellData )
     255         248 :             cellData->first = *pData;
     256             : 
     257             :         // insert data row
     258          66 :         m_aData.insert( m_aData.begin() + i_position, newRow );
     259          66 :     }
     260             : 
     261             : 
     262          12 :     void SAL_CALL DefaultGridDataModel::addRow( const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, std::exception)
     263             :     {
     264          12 :         insertRow( getRowCount(), i_heading, i_data );
     265          12 :     }
     266             : 
     267             : 
     268          10 :     void SAL_CALL DefaultGridDataModel::addRows( const Sequence< Any >& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException, std::exception)
     269             :     {
     270          10 :         insertRows( getRowCount(), i_headings, i_data );
     271           8 :     }
     272             : 
     273             : 
     274          14 :     void SAL_CALL DefaultGridDataModel::insertRow( ::sal_Int32 i_index, const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
     275             :     {
     276          14 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     277             : 
     278          14 :         if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
     279           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     280             : 
     281             :         // actually insert the row
     282          14 :         impl_insertRow( i_index, i_heading, i_data );
     283             : 
     284             :         // update column count
     285          14 :         sal_Int32 const columnCount = i_data.getLength();
     286          14 :         if ( columnCount > m_nColumnCount )
     287           8 :             m_nColumnCount = columnCount;
     288             : 
     289             :         broadcast(
     290             :             GridDataEvent( *this, -1, -1, i_index, i_index ),
     291             :             &XGridDataListener::rowsInserted,
     292             :             aGuard
     293          14 :         );
     294          14 :     }
     295             : 
     296             : 
     297          14 :     void SAL_CALL DefaultGridDataModel::insertRows( ::sal_Int32 i_index, const Sequence< Any>& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException, std::exception)
     298             :     {
     299          14 :         if ( i_headings.getLength() != i_data.getLength() )
     300           4 :             throw IllegalArgumentException( OUString(), *this, -1 );
     301             : 
     302          10 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     303             : 
     304          10 :         if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
     305           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     306             : 
     307          10 :         sal_Int32 const rowCount = i_headings.getLength();
     308          10 :         if ( rowCount == 0 )
     309          10 :             return;
     310             : 
     311             :         // determine max col count in the new data
     312          10 :         sal_Int32 maxColCount = 0;
     313          62 :         for ( sal_Int32 row=0; row<rowCount; ++row )
     314          52 :             if ( i_data[row].getLength() > maxColCount )
     315          10 :                 maxColCount = i_data[row].getLength();
     316             : 
     317          10 :         if ( maxColCount < m_nColumnCount )
     318           0 :             maxColCount = m_nColumnCount;
     319             : 
     320          62 :         for ( sal_Int32 row=0; row<rowCount;  ++row )
     321             :         {
     322          52 :             impl_insertRow( i_index + row, i_headings[row], i_data[row], maxColCount );
     323             :         }
     324             : 
     325          10 :         if ( maxColCount > m_nColumnCount )
     326           4 :             m_nColumnCount = maxColCount;
     327             : 
     328             :         broadcast(
     329          10 :             GridDataEvent( *this, -1, -1, i_index, i_index + rowCount - 1 ),
     330             :             &XGridDataListener::rowsInserted,
     331             :             aGuard
     332          20 :         );
     333             :     }
     334             : 
     335             : 
     336          12 :     void SAL_CALL DefaultGridDataModel::removeRow( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     337             :     {
     338          12 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     339             : 
     340          12 :         if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
     341           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     342             : 
     343          12 :         m_aRowHeaders.erase( m_aRowHeaders.begin() + i_rowIndex );
     344          12 :         m_aData.erase( m_aData.begin() + i_rowIndex );
     345             : 
     346             :         broadcast(
     347             :             GridDataEvent( *this, -1, -1, i_rowIndex, i_rowIndex ),
     348             :             &XGridDataListener::rowsRemoved,
     349             :             aGuard
     350          12 :         );
     351          12 :     }
     352             : 
     353             : 
     354           2 :     void SAL_CALL DefaultGridDataModel::removeAllRows(  ) throw (RuntimeException, std::exception)
     355             :     {
     356           2 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     357             : 
     358           2 :         m_aRowHeaders.clear();
     359           2 :         m_aData.clear();
     360             : 
     361             :         broadcast(
     362             :             GridDataEvent( *this, -1, -1, -1, -1 ),
     363             :             &XGridDataListener::rowsRemoved,
     364             :             aGuard
     365           2 :         );
     366           2 :     }
     367             : 
     368             : 
     369           8 :     void SAL_CALL DefaultGridDataModel::updateCellData( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     370             :     {
     371           8 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     372             : 
     373           8 :         impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).first = i_value;
     374             : 
     375             :         broadcast(
     376             :             GridDataEvent( *this, i_columnIndex, i_columnIndex, i_rowIndex, i_rowIndex ),
     377             :             &XGridDataListener::dataChanged,
     378             :             aGuard
     379           6 :         );
     380           6 :     }
     381             : 
     382             : 
     383           6 :     void SAL_CALL DefaultGridDataModel::updateRowData( const Sequence< ::sal_Int32 >& i_columnIndexes, ::sal_Int32 i_rowIndex, const Sequence< Any >& i_values ) throw (IndexOutOfBoundsException, IllegalArgumentException, RuntimeException, std::exception)
     384             :     {
     385           6 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     386             : 
     387           6 :         if  ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
     388           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     389             : 
     390           6 :         if ( i_columnIndexes.getLength() != i_values.getLength() )
     391           2 :             throw IllegalArgumentException( OUString(), *this, 1 );
     392             : 
     393           4 :         sal_Int32 const columnCount = i_columnIndexes.getLength();
     394           4 :         if ( columnCount == 0 )
     395           2 :             return;
     396             : 
     397          10 :         for ( sal_Int32 col = 0; col < columnCount; ++col )
     398             :         {
     399           8 :             if ( ( i_columnIndexes[col] < 0 ) || ( i_columnIndexes[col] > m_nColumnCount ) )
     400           2 :                 throw IndexOutOfBoundsException( OUString(), *this );
     401             :         }
     402             : 
     403           2 :         RowData& rDataRow = m_aData[ i_rowIndex ];
     404           8 :         for ( sal_Int32 col = 0; col < columnCount; ++col )
     405             :         {
     406           6 :             sal_Int32 const columnIndex = i_columnIndexes[ col ];
     407           6 :             if ( size_t( columnIndex ) >= rDataRow.size() )
     408           0 :                 rDataRow.resize( columnIndex + 1 );
     409             : 
     410           6 :             rDataRow[ columnIndex ].first = i_values[ col ];
     411             :         }
     412             : 
     413           2 :         sal_Int32 const firstAffectedColumn = *::std::min_element( i_columnIndexes.begin(), i_columnIndexes.end() );
     414           2 :         sal_Int32 const lastAffectedColumn = *::std::max_element( i_columnIndexes.begin(), i_columnIndexes.end() );
     415             :         broadcast(
     416             :             GridDataEvent( *this, firstAffectedColumn, lastAffectedColumn, i_rowIndex, i_rowIndex ),
     417             :             &XGridDataListener::dataChanged,
     418             :             aGuard
     419           2 :         );
     420             :     }
     421             : 
     422             : 
     423           2 :     void SAL_CALL DefaultGridDataModel::updateRowHeading( ::sal_Int32 i_rowIndex, const Any& i_heading ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     424             :     {
     425           2 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     426             : 
     427           2 :         if  ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aRowHeaders.size() ) )
     428           0 :             throw IndexOutOfBoundsException( OUString(), *this );
     429             : 
     430           2 :         m_aRowHeaders[ i_rowIndex ] = i_heading;
     431             : 
     432             :         broadcast(
     433             :             GridDataEvent( *this, -1, -1, i_rowIndex, i_rowIndex ),
     434             :             &XGridDataListener::rowHeadingChanged,
     435             :             aGuard
     436           2 :         );
     437           2 :     }
     438             : 
     439             : 
     440           0 :     void SAL_CALL DefaultGridDataModel::updateCellToolTip( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     441             :     {
     442           0 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     443           0 :         impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).second = i_value;
     444           0 :     }
     445             : 
     446             : 
     447           0 :     void SAL_CALL DefaultGridDataModel::updateRowToolTip( ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     448             :     {
     449           0 :         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
     450             : 
     451           0 :         RowData& rRowData = impl_getRowDataAccess_throw( i_rowIndex, m_nColumnCount );
     452           0 :         for ( RowData::iterator cell = rRowData.begin(); cell != rRowData.end(); ++cell )
     453           0 :             cell->second = i_value;
     454           0 :     }
     455             : 
     456             : 
     457          16 :     void SAL_CALL DefaultGridDataModel::addGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException, std::exception)
     458             :     {
     459          16 :         rBHelper.addListener( cppu::UnoType<XGridDataListener>::get(), i_listener );
     460          16 :     }
     461             : 
     462             : 
     463           8 :     void SAL_CALL DefaultGridDataModel::removeGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException, std::exception)
     464             :     {
     465           8 :         rBHelper.removeListener( cppu::UnoType<XGridDataListener>::get(), i_listener );
     466           8 :     }
     467             : 
     468             : 
     469          14 :     void SAL_CALL DefaultGridDataModel::disposing()
     470             :     {
     471          14 :         ::com::sun::star::lang::EventObject aEvent;
     472          14 :         aEvent.Source.set( *this );
     473          14 :         rBHelper.aLC.disposeAndClear( aEvent );
     474             : 
     475          28 :         ::osl::MutexGuard aGuard( m_aMutex );
     476          28 :         GridData aEmptyData;
     477          14 :         m_aData.swap( aEmptyData );
     478             : 
     479          28 :         ::std::vector< Any > aEmptyRowHeaders;
     480          14 :         m_aRowHeaders.swap( aEmptyRowHeaders );
     481             : 
     482          28 :         m_nColumnCount = 0;
     483          14 :     }
     484             : 
     485             : 
     486           0 :     OUString SAL_CALL DefaultGridDataModel::getImplementationName(  ) throw (RuntimeException, std::exception)
     487             :     {
     488           0 :         return OUString("stardiv.Toolkit.DefaultGridDataModel");
     489             :     }
     490             : 
     491           0 :     sal_Bool SAL_CALL DefaultGridDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     492             :     {
     493           0 :         return cppu::supportsService(this, ServiceName);
     494             :     }
     495             : 
     496           0 :     Sequence< OUString > SAL_CALL DefaultGridDataModel::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     497             :     {
     498           0 :         static const OUString aServiceName("com.sun.star.awt.grid.DefaultGridDataModel");
     499           0 :         static const Sequence< OUString > aSeq( &aServiceName, 1 );
     500           0 :         return aSeq;
     501             :     }
     502             : 
     503             : 
     504           2 :     Reference< css::util::XCloneable > SAL_CALL DefaultGridDataModel::createClone(  ) throw (RuntimeException, std::exception)
     505             :     {
     506           2 :         return new DefaultGridDataModel( *this );
     507             :     }
     508             : 
     509             : }
     510             : 
     511             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     512          22 : stardiv_Toolkit_DefaultGridDataModel_get_implementation(
     513             :     css::uno::XComponentContext *,
     514             :     css::uno::Sequence<css::uno::Any> const &)
     515             : {
     516          22 :     return cppu::acquire(new DefaultGridDataModel());
     517        1227 : }
     518             : 
     519             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10