summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorFrank Schoenheit [fs] <frank.schoenheit@oracle.com>2011-01-10 15:47:51 +0100
committerFrank Schoenheit [fs] <frank.schoenheit@oracle.com>2011-01-10 15:47:51 +0100
commit34f93e97f28bdfc6ee731fd7213588fe505cbd2f (patch)
tree914b7edb5fd227cbeb167f33d4bd912ae4edec60 /toolkit
parent6b67bdb0ef37852d056dc9f1796ece3911921ab9 (diff)
gridsort: XGridDataModel: moved modifying functionality into XMutableGridDataModel.
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/source/controls/grid/defaultgriddatamodel.cxx341
-rw-r--r--toolkit/source/controls/grid/defaultgriddatamodel.hxx43
-rw-r--r--toolkit/source/controls/grid/gridcontrol.cxx17
-rwxr-xr-xtoolkit/source/controls/grid/grideventforwarder.cxx16
-rwxr-xr-xtoolkit/source/controls/grid/grideventforwarder.hxx5
5 files changed, 276 insertions, 146 deletions
diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx
index 8e12260be7d2..698e64c4429c 100644
--- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx
+++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx
@@ -28,21 +28,23 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_toolkit.hxx"
#include "defaultgriddatamodel.hxx"
-#include <comphelper/sequence.hxx>
+
+#include <comphelper/stlunosequence.hxx>
#include <toolkit/helper/servicenames.hxx>
+#include <tools/diagnose_ex.h>
#include <rtl/ref.hxx>
+#include <algorithm>
+
using ::rtl::OUString;
+using ::comphelper::stl_begin;
+using ::comphelper::stl_end;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::awt::grid;
using namespace ::com::sun::star::lang;
-#define ROWHEADERS ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowHeaders" ))
-#define CELLUPDATED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "CellUpdated" ))
-#define ROWUPDATED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowUpdated" ))
-
//......................................................................................................................
namespace toolkit
//......................................................................................................................
@@ -68,6 +70,7 @@ namespace toolkit
:DefaultGridDataModel_Base()
,MutexAndBroadcastHelper()
,m_aRowHeaders()
+ ,m_nColumnCount(0)
{
}
@@ -86,196 +89,304 @@ namespace toolkit
}
//------------------------------------------------------------------------------------------------------------------
- void DefaultGridDataModel::broadcast( broadcast_type eType, const GridDataEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException)
+ namespace
{
- ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridDataListener::static_type() );
- if( pIter )
+ Sequence< sal_Int32 > lcl_buildSingleElementSequence( sal_Int32 const i_index )
{
- ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
- while(aListIter.hasMoreElements())
- {
- XGridDataListener* pListener = static_cast<XGridDataListener*>(aListIter.next());
- switch( eType )
- {
- case row_added: pListener->rowAdded(aEvent); break;
- case row_removed: pListener->rowRemoved(aEvent); break;
- case data_changed: pListener->dataChanged(aEvent); break;
- }
- }
+ Sequence< sal_Int32 > aIndexes(1);
+ aIndexes[0] = i_index;
+ return aIndexes;
}
- }
+ Sequence< sal_Int32 > lcl_buildIndexSequence( sal_Int32 const i_start, sal_Int32 const i_end )
+ {
+ Sequence< sal_Int32 > aIndexes;
+ ENSURE_OR_RETURN( i_end >= i_start, "lcl_buildIndexSequence: illegal indexes!", aIndexes );
- //------------------------------------------------------------------------------------------------------------------
- void DefaultGridDataModel::broadcast_changed( ::rtl::OUString name, sal_Int32 index, Any oldValue, Any newValue) throw (::com::sun::star::uno::RuntimeException)
- {
- Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
- GridDataEvent aEvent( xSource, name, oldValue, newValue, index, ::rtl::OUString(), Sequence< Any >());
- broadcast( data_changed, aEvent);
- }
+ aIndexes.realloc( i_end - i_start + 1 );
+ for ( sal_Int32 i = i_start; i <= i_end; ++i )
+ aIndexes[ i - i_start ] = i;
- //------------------------------------------------------------------------------------------------------------------
- void DefaultGridDataModel::broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName,
- ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException)
- {
- Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
- GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, (const ::com::sun::star::uno::Sequence< Any >&)rowData );
- broadcast( row_added, aEvent);
+ return aIndexes;
+ }
}
//------------------------------------------------------------------------------------------------------------------
- void DefaultGridDataModel::broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName,
- ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException)
+ void DefaultGridDataModel::broadcast( GridDataEvent const & i_event,
+ void ( SAL_CALL XGridDataListener::*i_listenerMethod )( GridDataEvent const & ), ::osl::ClearableMutexGuard & i_instanceLock )
{
- Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
- GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, rowData );
- broadcast( row_removed, aEvent);
+ ::cppu::OInterfaceContainerHelper* pListeners = BrdcstHelper.getContainer( XGridDataListener::static_type() );
+ if ( !pListeners )
+ return;
+
+ i_instanceLock.clear();
+ pListeners->notifyEach( i_listenerMethod, i_event );
}
//------------------------------------------------------------------------------------------------------------------
::sal_Int32 SAL_CALL DefaultGridDataModel::getRowCount() throw (::com::sun::star::uno::RuntimeException)
{
+ ::osl::MutexGuard aGuard( GetMutex() );
return m_aData.size();
}
//------------------------------------------------------------------------------------------------------------------
::sal_Int32 SAL_CALL DefaultGridDataModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException)
{
- if ( m_aData.empty() )
- return 0;
- return m_aData[0].size();
+ ::osl::MutexGuard aGuard( GetMutex() );
+ return m_nColumnCount;
}
//------------------------------------------------------------------------------------------------------------------
- ::rtl::OUString SAL_CALL DefaultGridDataModel::getRowTitle( ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
+ Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
{
::osl::MutexGuard aGuard( GetMutex() );
- if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aRowHeaders.size() ) )
+ if ( ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() )
+ || ( i_column < 0 ) || ( i_column > m_nColumnCount )
+ )
throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
- return m_aRowHeaders[ i_row ];
+ ::std::vector< Any > const & rRow( m_aData[ i_row ] );
+ if ( size_t( i_column ) < rRow.size() )
+ return rRow[ i_column ];
+
+ return Any();
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & i_rowHeaders ) throw (::com::sun::star::uno::RuntimeException)
+ ::rtl::OUString SAL_CALL DefaultGridDataModel::getRowTitle( ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
{
- ::com::sun::star::uno::Sequence< ::rtl::OUString > oldValue( comphelper::containerToSequence( m_aRowHeaders ) );
-
- const sal_Int32 sequenceSize = i_rowHeaders.getLength();
+ ::osl::MutexGuard aGuard( GetMutex() );
- sal_Int32 i = 0;
- for ( std::vector< rtl::OUString >::iterator iterator = m_aRowHeaders.begin();
- iterator != m_aRowHeaders.end();
- ++iterator, ++i
- )
- {
- if ( sequenceSize > i )
- *iterator = i_rowHeaders[i];
- else
- *iterator = ::rtl::OUString();
- }
+ if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aRowHeaders.size() ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
- broadcast_changed( ROWHEADERS, 0, Any( oldValue ), Any( comphelper::containerToSequence( m_aRowHeaders ) ) );
+ return m_aRowHeaders[ i_row ];
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< Any > & rRowdata) throw (::com::sun::star::uno::RuntimeException)
+ void SAL_CALL DefaultGridDataModel::addRow( const ::rtl::OUString& i_title, const Sequence< Any >& i_data ) throw (RuntimeException)
{
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ sal_Int32 const columnCount = i_data.getLength();
+
// store header name
- m_aRowHeaders.push_back(headername);
+ m_aRowHeaders.push_back( i_title );
// store row m_aData
- std::vector< Any > newRow;
- for ( int i = 0; i < rRowdata.getLength();i++)
- {
- newRow.push_back(rRowdata[i]);
- }
-
+ ::std::vector< Any > newRow( columnCount );
+ ::std::copy( i_data.getConstArray(), i_data.getConstArray() + columnCount, newRow.begin() );
m_aData.push_back( newRow );
- broadcast_add( m_aData.size()-1, headername, comphelper::containerToSequence(newRow));
+ // update column count
+ if ( columnCount > m_nColumnCount )
+ m_nColumnCount = columnCount;
+ broadcast(
+ GridDataEvent( *this, Sequence< sal_Int32 >(), lcl_buildSingleElementSequence( m_aData.size() - 1 ) ),
+ &XGridDataListener::rowsAdded,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::removeRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException)
+ void SAL_CALL DefaultGridDataModel::addRows( const Sequence< ::rtl::OUString >& i_titles, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException)
{
- if ( index >= 0 && index <= getRowCount()-1)
+ if ( i_titles.getLength() != i_data.getLength() )
+ throw IllegalArgumentException( ::rtl::OUString(), *this, -1 );
+
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ sal_Int32 const rowCount = i_titles.getLength();
+ if ( rowCount == 0 )
+ return;
+
+ // determine max col count in the new data
+ sal_Int32 maxColCount = 0;
+ for ( sal_Int32 row=0; row<rowCount; ++row )
+ if ( i_data[row].getLength() > maxColCount )
+ maxColCount = i_data[row].getLength();
+
+ if ( maxColCount < m_nColumnCount )
+ maxColCount = m_nColumnCount;
+
+ for ( sal_Int32 row=0; row<rowCount; ++row )
{
- ::rtl::OUString headerName( (::rtl::OUString) m_aRowHeaders[index] );
- m_aRowHeaders.erase(m_aRowHeaders.begin() + index);
+ m_aRowHeaders.push_back( i_titles[row] );
- Sequence< Any >& rowData ( (Sequence< Any >&)m_aData[index] );
- m_aData.erase(m_aData.begin() + index);
- broadcast_remove( index, headerName, rowData);
+ ::std::vector< Any > newRow( maxColCount );
+ Sequence< Any > const & rRowData = i_data[row];
+ ::std::copy( rRowData.getConstArray(), rRowData.getConstArray() + rRowData.getLength(), newRow.begin() );
+ m_aData.push_back( newRow );
}
- else
- return;
+
+ if ( maxColCount > m_nColumnCount )
+ m_nColumnCount = maxColCount;
+
+ broadcast(
+ GridDataEvent( *this, Sequence< sal_Int32 >(), lcl_buildIndexSequence( m_aData.size() - rowCount, m_aData.size() - 1 ) ),
+ &XGridDataListener::rowsAdded,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
+ void SAL_CALL DefaultGridDataModel::removeRow( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException)
{
- ::osl::MutexGuard aGuard( GetMutex() );
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
- if ( ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() ) )
+ if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
- ::std::vector< Any > const & rRow( m_aData[ i_row ] );
+ m_aRowHeaders.erase( m_aRowHeaders.begin() + i_rowIndex );
+ m_aData.erase( m_aData.begin() + i_rowIndex );
- if ( ( i_column < 0 ) || ( size_t( i_column ) > rRow.size() ) )
- throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
-
- return rRow[ i_column ];
+ broadcast(
+ GridDataEvent( *this, Sequence< sal_Int32 >(), lcl_buildSingleElementSequence( i_rowIndex ) ),
+ &XGridDataListener::rowsRemoved,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::addGridDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException)
+ void SAL_CALL DefaultGridDataModel::removeRows( const Sequence< ::sal_Int32 >& i_rowIndexes ) throw (IndexOutOfBoundsException, RuntimeException)
{
- BrdcstHelper.addListener( XGridDataListener::static_type(), xListener );
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ sal_Int32 const rowCount = i_rowIndexes.getLength();
+ if ( rowCount == 0 )
+ return;
+
+ for ( sal_Int32 row=0; row<rowCount; ++row )
+ {
+ if ( ( i_rowIndexes[row] < 0 ) || ( size_t( i_rowIndexes[row] ) >= m_aData.size() ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+ }
+
+ Sequence< sal_Int32 > rowIndexes( i_rowIndexes );
+ ::std::sort( stl_begin( rowIndexes ), stl_end( rowIndexes ) );
+
+ for ( sal_Int32 row = rowCount; row > 0; )
+ {
+ sal_Int32 const rowIndex = rowIndexes[--row];
+ m_aRowHeaders.erase( m_aRowHeaders.begin() + rowIndex );
+ m_aData.erase( m_aData.begin() + rowIndex );
+ }
+
+ broadcast(
+ GridDataEvent( *this, Sequence< sal_Int32 >(), rowIndexes ),
+ &XGridDataListener::rowsRemoved,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::removeGridDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException)
+ void SAL_CALL DefaultGridDataModel::removeAllRows( ) throw (RuntimeException)
{
- BrdcstHelper.removeListener( XGridDataListener::static_type(), xListener );
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ m_aRowHeaders.clear();
+ m_aData.clear();
+
+ broadcast(
+ GridDataEvent( *this, Sequence< sal_Int32 >(), Sequence< sal_Int32 >() ),
+ &XGridDataListener::rowsRemoved,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::removeAll() throw (RuntimeException)
+ void SAL_CALL DefaultGridDataModel::updateCell( ::sal_Int32 i_rowIndex, ::sal_Int32 i_columnIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException)
{
- m_aRowHeaders.clear();
- m_aData.clear();
- broadcast_remove( -1, ::rtl::OUString(), 0);
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() )
+ || ( i_columnIndex < 0 ) || ( i_columnIndex >= m_nColumnCount )
+ )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+
+ ::std::vector< Any >& rRowData( m_aData[ i_rowIndex ] );
+ if ( size_t( i_columnIndex ) >= rRowData.size() )
+ rRowData.resize( i_columnIndex + 1 );
+ rRowData[ i_columnIndex ] = i_value;
+
+ broadcast(
+ GridDataEvent( *this, lcl_buildSingleElementSequence( i_columnIndex ), lcl_buildSingleElementSequence( i_rowIndex ) ),
+ &XGridDataListener::dataChanged,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::updateCell(::sal_Int32 row, ::sal_Int32 column, const Any& value) throw (::com::sun::star::uno::RuntimeException)
+ void SAL_CALL DefaultGridDataModel::updateRow( const Sequence< ::sal_Int32 >& i_columnIndexes, ::sal_Int32 i_rowIndex, const Sequence< Any >& i_values ) throw (IndexOutOfBoundsException, IllegalArgumentException, RuntimeException)
{
- if(row >= 0 && row < (signed)m_aData.size())
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+
+ if ( i_columnIndexes.getLength() != i_values.getLength() )
+ throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
+
+ sal_Int32 const columnCount = i_columnIndexes.getLength();
+ if ( columnCount == 0 )
+ return;
+
+ for ( sal_Int32 col = 0; col < columnCount; ++col )
+ {
+ if ( ( i_columnIndexes[col] < 0 ) || ( i_columnIndexes[col] > m_nColumnCount ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+ }
+
+ ::std::vector< Any >& rDataRow = m_aData[ i_rowIndex ];
+ for ( sal_Int32 col = 0; col < columnCount; ++col )
{
- if(column >= 0 && column < (signed)m_aData[0].size())
- {
- m_aData[row][column] = value;
- Sequence< Any >dataSeq(comphelper::containerToSequence(m_aData[row]));
- broadcast_changed( CELLUPDATED, row, Any(column), value );
- }
+ sal_Int32 const columnIndex = i_columnIndexes[ col ];
+ if ( size_t( columnIndex ) >= rDataRow.size() )
+ rDataRow.resize( columnIndex + 1 );
+
+ rDataRow[ columnIndex ] = i_values[ col ];
}
+
+ // by definition, the indexes in the notified sequences shall be sorted
+ Sequence< sal_Int32 > columnIndexes( i_columnIndexes );
+ ::std::sort( stl_begin( columnIndexes ), stl_end( columnIndexes ) );
+
+ broadcast(
+ GridDataEvent( *this, columnIndexes, lcl_buildSingleElementSequence( i_rowIndex ) ),
+ &XGridDataListener::dataChanged,
+ aGuard
+ );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL DefaultGridDataModel::updateRow(::sal_Int32 row, const ::com::sun::star::uno::Sequence< ::sal_Int32 > & columns, const ::com::sun::star::uno::Sequence< Any > & values) throw (::com::sun::star::uno::RuntimeException)
+ void SAL_CALL DefaultGridDataModel::setRowTitle( ::sal_Int32 i_rowIndex, const ::rtl::OUString& i_title ) throw (IndexOutOfBoundsException, RuntimeException)
{
- if(row >= 0 && row < (signed)m_aData.size())
- {
- if(columns.getLength() == values.getLength())
- {
- for(int i = 0; i < columns.getLength(); i++)
- m_aData[row][i] = values[i];
- Sequence< Any >dataSeq(comphelper::containerToSequence(m_aData[row]));
- broadcast_changed( ROWUPDATED, row, Any(columns), Any(values) );
- }
- }
+ ::osl::ClearableMutexGuard aGuard( GetMutex() );
+
+ if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
+ throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
+
+ m_aRowHeaders[ i_rowIndex ] = i_title;
+
+ broadcast(
+ GridDataEvent( *this, Sequence< sal_Int32 >(), lcl_buildSingleElementSequence( i_rowIndex ) ),
+ &XGridDataListener::rowTitleChanged,
+ aGuard
+ );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL DefaultGridDataModel::addGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException)
+ {
+ BrdcstHelper.addListener( XGridDataListener::static_type(), i_listener );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL DefaultGridDataModel::removeGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException)
+ {
+ BrdcstHelper.removeListener( XGridDataListener::static_type(), i_listener );
}
//------------------------------------------------------------------------------------------------------------------
@@ -313,7 +424,7 @@ namespace toolkit
}
//------------------------------------------------------------------------------------------------------------------
- ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL DefaultGridDataModel::getSupportedServiceNames( ) throw (RuntimeException)
+ Sequence< ::rtl::OUString > SAL_CALL DefaultGridDataModel::getSupportedServiceNames( ) throw (RuntimeException)
{
static const OUString aServiceName( OUString::createFromAscii( szServiceName_DefaultGridDataModel ) );
static const Sequence< OUString > aSeq( &aServiceName, 1 );
diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.hxx b/toolkit/source/controls/grid/defaultgriddatamodel.hxx
index c44c02fb0227..6dd81b8453ae 100644
--- a/toolkit/source/controls/grid/defaultgriddatamodel.hxx
+++ b/toolkit/source/controls/grid/defaultgriddatamodel.hxx
@@ -27,7 +27,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_toolkit.hxx"
-#include <com/sun/star/awt/grid/XGridDataModel.hpp>
+#include <com/sun/star/awt/grid/XMutableGridDataModel.hpp>
#include <com/sun/star/awt/grid/GridDataEvent.hpp>
#include <com/sun/star/awt/grid/XGridDataListener.hpp>
#include <com/sun/star/awt/XControl.hpp>
@@ -52,7 +52,7 @@ namespace toolkit
enum broadcast_type { row_added, row_removed, data_changed};
-typedef ::cppu::WeakImplHelper2< XGridDataModel, XServiceInfo > DefaultGridDataModel_Base;
+typedef ::cppu::WeakImplHelper2< XMutableGridDataModel, XServiceInfo > DefaultGridDataModel_Base;
class DefaultGridDataModel : public DefaultGridDataModel_Base,
public MutexAndBroadcastHelper
{
@@ -61,19 +61,23 @@ public:
DefaultGridDataModel( DefaultGridDataModel const & i_copySource );
virtual ~DefaultGridDataModel();
+ // XMutableGridDataModel
+ virtual void SAL_CALL addRow( const ::rtl::OUString& Title, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL addRows( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& Titles, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeRows( const ::com::sun::star::uno::Sequence< ::sal_Int32 >& RowIndexes ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeAllRows( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL updateCell( ::sal_Int32 RowIndex, ::sal_Int32 ColumnIndex, const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL updateRow( const ::com::sun::star::uno::Sequence< ::sal_Int32 >& ColumnIndexes, ::sal_Int32 RowIndex, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setRowTitle( ::sal_Int32 RowIndex, const ::rtl::OUString& Title ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL addGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL removeGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
+
// XGridDataModel
virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException);
- virtual ::rtl::OUString SAL_CALL getRowTitle( ::sal_Int32 Row ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & value) throw (::com::sun::star::uno::RuntimeException);
- virtual ::com::sun::star::uno::Any SAL_CALL getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException);
- virtual void SAL_CALL addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< Any > & _aData) throw (::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL removeRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL addGridDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException);
- virtual void SAL_CALL removeGridDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException);
- virtual void SAL_CALL removeAll() throw (RuntimeException);
- virtual void SAL_CALL updateCell( ::sal_Int32 row, ::sal_Int32 column, const ::com::sun::star::uno::Any& value ) throw (::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL updateRow( ::sal_Int32 row, const ::com::sun::star::uno::Sequence< ::sal_Int32 >& columns, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& values ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Any SAL_CALL getCellData( ::sal_Int32 Column, ::sal_Int32 Row ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getRowTitle( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
// XComponent
virtual void SAL_CALL dispose( ) throw (RuntimeException);
@@ -89,14 +93,15 @@ public:
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
private:
+ void broadcast(
+ GridDataEvent const & i_event,
+ void ( SAL_CALL ::com::sun::star::awt::grid::XGridDataListener::*i_listenerMethod )( ::com::sun::star::awt::grid::GridDataEvent const & ),
+ ::osl::ClearableMutexGuard & i_instanceLock
+ );
- void broadcast( broadcast_type eType, const GridDataEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
- void broadcast_changed( ::rtl::OUString name, sal_Int32 index, Any oldValue, Any newValue ) throw (::com::sun::star::uno::RuntimeException);
- void broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException);
- void broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< Any > rowData ) throw (::com::sun::star::uno::RuntimeException);
-
- std::vector< std::vector < Any > > m_aData;
- std::vector< ::rtl::OUString > m_aRowHeaders;
+ ::std::vector< ::std::vector < Any > > m_aData;
+ ::std::vector< ::rtl::OUString > m_aRowHeaders;
+ sal_Int32 m_nColumnCount;
};
}
diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx
index 76bf33768776..b2322b69df69 100644
--- a/toolkit/source/controls/grid/gridcontrol.cxx
+++ b/toolkit/source/controls/grid/gridcontrol.cxx
@@ -34,6 +34,7 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/view/SelectionType.hpp>
#include <com/sun/star/awt/grid/XGridDataModel.hpp>
+#include <com/sun/star/awt/grid/XMutableGridDataModel.hpp>
#include <com/sun/star/awt/grid/XGridColumnModel.hpp>
#include <toolkit/helper/unopropertyarrayhelper.hxx>
#include <toolkit/helper/property.hxx>
@@ -293,7 +294,7 @@ namespace
try
{
- const Reference< XContainer > xColModel(
+ Reference< XContainer > const xColModel(
xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ColumnModel" ) ) ),
UNO_QUERY_THROW );
if ( i_add )
@@ -301,14 +302,18 @@ namespace
else
xColModel->removeContainerListener( i_listener.get() );
- const Reference< XGridDataModel > xDataModel(
+ Reference< XGridDataModel > const xDataModel(
xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GridDataModel" ) ) ),
UNO_QUERY_THROW
);
- if ( i_add )
- xDataModel->addGridDataListener( i_listener.get() );
- else
- xDataModel->removeGridDataListener( i_listener.get() );
+ Reference< XMutableGridDataModel > const xMutableDataModel( xDataModel, UNO_QUERY );
+ if ( xMutableDataModel.is() )
+ {
+ if ( i_add )
+ xMutableDataModel->addGridDataListener( i_listener.get() );
+ else
+ xMutableDataModel->removeGridDataListener( i_listener.get() );
+ }
}
catch( const Exception& )
{
diff --git a/toolkit/source/controls/grid/grideventforwarder.cxx b/toolkit/source/controls/grid/grideventforwarder.cxx
index 2c99acb86959..b3d17a897bad 100755
--- a/toolkit/source/controls/grid/grideventforwarder.cxx
+++ b/toolkit/source/controls/grid/grideventforwarder.cxx
@@ -81,19 +81,19 @@ namespace toolkit
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL GridEventForwarder::rowAdded( const GridDataEvent& i_event ) throw (RuntimeException)
+ void SAL_CALL GridEventForwarder::rowsAdded( const GridDataEvent& i_event ) throw (RuntimeException)
{
Reference< XGridDataListener > xPeer( m_parent.getPeer(), UNO_QUERY );
if ( xPeer.is() )
- xPeer->rowAdded( i_event );
+ xPeer->rowsAdded( i_event );
}
//------------------------------------------------------------------------------------------------------------------
- void SAL_CALL GridEventForwarder::rowRemoved( const GridDataEvent& i_event ) throw (RuntimeException)
+ void SAL_CALL GridEventForwarder::rowsRemoved( const GridDataEvent& i_event ) throw (RuntimeException)
{
Reference< XGridDataListener > xPeer( m_parent.getPeer(), UNO_QUERY );
if ( xPeer.is() )
- xPeer->rowRemoved( i_event );
+ xPeer->rowsRemoved( i_event );
}
//------------------------------------------------------------------------------------------------------------------
@@ -105,6 +105,14 @@ namespace toolkit
}
//------------------------------------------------------------------------------------------------------------------
+ void SAL_CALL GridEventForwarder::rowTitleChanged( const GridDataEvent& i_event ) throw (RuntimeException)
+ {
+ Reference< XGridDataListener > xPeer( m_parent.getPeer(), UNO_QUERY );
+ if ( xPeer.is() )
+ xPeer->rowTitleChanged( i_event );
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridEventForwarder::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException)
{
Reference< XContainerListener > xPeer( m_parent.getPeer(), UNO_QUERY );
diff --git a/toolkit/source/controls/grid/grideventforwarder.hxx b/toolkit/source/controls/grid/grideventforwarder.hxx
index 93905b06f492..c0c09a7cc95d 100755
--- a/toolkit/source/controls/grid/grideventforwarder.hxx
+++ b/toolkit/source/controls/grid/grideventforwarder.hxx
@@ -61,9 +61,10 @@ namespace toolkit
virtual void SAL_CALL release() throw();
// XGridDataListener
- virtual void SAL_CALL rowAdded( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL rowRemoved( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL rowsAdded( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL rowsRemoved( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL dataChanged( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL rowTitleChanged( const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
// XContainerListener
virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);