diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-19 12:39:41 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-19 12:39:41 +0100 |
commit | 903ddf534a9a71cb54867d7c40eedf456acb018a (patch) | |
tree | 6950546524d2bd9af234fa1a4d16aea741afa475 /svtools/source | |
parent | e8f649b5ad64a2a3f07dfab1a52033d126da211b (diff) |
gridsort: introduce XGridColumn::DataModelIndex. this allows for column removal/insertion at the GridColumnModel, without the need to touch the GridDataModel
Diffstat (limited to 'svtools/source')
-rw-r--r-- | svtools/source/table/tablecontrol.cxx | 6 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.cxx | 13 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.hxx | 2 | ||||
-rw-r--r-- | svtools/source/uno/svtxgridcontrol.cxx | 15 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.cxx | 49 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.hxx | 10 | ||||
-rwxr-xr-x | svtools/source/uno/unogridcolumnfacade.cxx | 34 | ||||
-rwxr-xr-x | svtools/source/uno/unogridcolumnfacade.hxx | 12 |
8 files changed, 104 insertions, 37 deletions
diff --git a/svtools/source/table/tablecontrol.cxx b/svtools/source/table/tablecontrol.cxx index 448da7c9395b..4cccc3843adf 100644 --- a/svtools/source/table/tablecontrol.cxx +++ b/svtools/source/table/tablecontrol.cxx @@ -249,12 +249,6 @@ namespace svt { namespace table } // ----------------------------------------------------------------------------------------------------------------- - void TableControl::InvalidateDataWindow( RowPos const i_firstRow, RowPos const i_lastRow ) - { - m_pImpl->invalidateRowRange( i_firstRow, i_lastRow ); - } - - // ----------------------------------------------------------------------------------------------------------------- ITableControl& TableControl::getTableControlInterface() { return *m_pImpl; diff --git a/svtools/source/table/tablecontrol_impl.cxx b/svtools/source/table/tablecontrol_impl.cxx index 53ff00756d98..e47419f2ea52 100755 --- a/svtools/source/table/tablecontrol_impl.cxx +++ b/svtools/source/table/tablecontrol_impl.cxx @@ -670,14 +670,12 @@ namespace svt { namespace table } //------------------------------------------------------------------------------------------------------------------ - void TableControl_Impl::cellsUpdated( ColPos firstCol, ColPos lastCol, RowPos firstRow, RowPos lastRow ) + void TableControl_Impl::cellsUpdated( ColPos const i_firstCol, ColPos i_lastCol, RowPos const i_firstRow, RowPos const i_lastRow ) { - OSL_ENSURE( false, "TableControl_Impl::cellsUpdated: not implemented!" ); - // there's no known implementation (yet) which calls this method - OSL_UNUSED( firstCol ); - OSL_UNUSED( lastCol ); - OSL_UNUSED( firstRow ); - OSL_UNUSED( lastRow ); + invalidateRowRange( i_firstRow, i_lastRow ); + + OSL_UNUSED( i_firstCol ); + OSL_UNUSED( i_lastCol ); } //------------------------------------------------------------------------------------------------------------------ @@ -1966,7 +1964,6 @@ namespace svt { namespace table m_pDataWindow->Invalidate(_rCellRect); } //------------------------------------------------------------------------------------------------------------------ - //this method is to be called, when a new row is added void TableControl_Impl::invalidateRowRange( RowPos const i_firstRow, RowPos const i_lastRow ) { if ( m_nCursorHidden == 2 ) diff --git a/svtools/source/table/tablecontrol_impl.hxx b/svtools/source/table/tablecontrol_impl.hxx index 747ffc8a36fa..dfc8141fa0e9 100755 --- a/svtools/source/table/tablecontrol_impl.hxx +++ b/svtools/source/table/tablecontrol_impl.hxx @@ -312,7 +312,7 @@ namespace svt { namespace table virtual void columnInserted( ColPos const i_colIndex ); virtual void columnRemoved( ColPos const i_colIndex ); virtual void allColumnsRemoved(); - virtual void cellsUpdated( ColPos firstCol, ColPos lastCol, RowPos firstRow, RowPos lastRow ); + virtual void cellsUpdated( ColPos const i_firstCol, ColPos i_lastCol, RowPos const i_firstRow, RowPos const i_lastRow ); virtual void columnChanged( ColPos const i_column, ColumnAttributeGroup const i_attributeGroup ); virtual void tableMetricsChanged(); diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index 14ac857179b1..d61a983b309b 100644 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -536,18 +536,12 @@ void SAL_CALL SVTXGridControl::dataChanged( const GridDataEvent& i_event ) throw { ::vos::OGuard aGuard( GetMutex() ); - TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); - ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::dataChanged: no control (anymore)!" ); - - // TODO: Our UnoControlTableModel should be a listener at the data model, and multiplex those events, - // so the TableControl/_Impl can react on it. - if ( i_event.FirstRow == -1 ) - pTable->InvalidateDataWindow( 0, m_pTableModel->getRowCount() ); - else - pTable->InvalidateDataWindow( i_event.FirstRow, i_event.LastRow ); + m_pTableModel->notifyDataChanged( i_event ); // if the data model is sortable, a dataChanged event is also fired in case the sort order changed. - // So, invalidate the column header area, too. + // So, just in case, invalidate the column header area, too. + TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); + ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::dataChanged: no control (anymore)!" ); pTable->getTableControlInterface().invalidate( TableAreaColumnHeaders ); } @@ -564,7 +558,6 @@ void SAL_CALL SVTXGridControl::rowHeadingChanged( const GridDataEvent& i_event ) pTable->getTableControlInterface().invalidate( TableAreaRowHeaders ); } - //---------------------------------------------------------------------------------------------------------------------- void SAL_CALL SVTXGridControl::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException) { diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx index ae4de7c36809..b6d4d0f1e451 100644 --- a/svtools/source/uno/unocontroltablemodel.cxx +++ b/svtools/source/uno/unocontroltablemodel.cxx @@ -523,12 +523,18 @@ namespace svt { namespace table { DBG_CHECK_ME(); + o_cellContent.clear(); try { Reference< XGridDataModel > const xDataModel( m_pImpl->m_aDataModel ); - ENSURE_OR_THROW( xDataModel.is(), "no data model anymore!" ); + ENSURE_OR_RETURN_VOID( xDataModel.is(), "UnoControlTableModel::getCellContent: no data model anymore!" ); + + PColumnModel const pColumn = getColumnModel( i_col ); + UnoGridColumnFacade* pColumnImpl = dynamic_cast< UnoGridColumnFacade* >( pColumn.get() ); + ENSURE_OR_RETURN_VOID( pColumnImpl != NULL, "UnoControlTableModel::getCellContent: no (valid) column at this position!" ); + sal_Int32 const nDataColumnIndex = pColumnImpl->getDataColumnIndex() >= 0 ? pColumnImpl->getDataColumnIndex() : i_col; - if ( i_col >= xDataModel->getColumnCount() ) + if ( nDataColumnIndex >= xDataModel->getColumnCount() ) { // this is allowed, in case the column model has been dynamically extended, but the data model does // not (yet?) know about it. @@ -540,11 +546,10 @@ namespace svt { namespace table "UnoControlTableModel::getCellContent: request a column's value which the ColumnModel doesn't know about!" ); } #endif - o_cellContent.clear(); } else { - o_cellContent = xDataModel->getCellData( i_col, i_row ); + o_cellContent = xDataModel->getCellData( nDataColumnIndex, i_row ); } } catch( const Exception& ) @@ -803,7 +808,7 @@ namespace svt { namespace table } //------------------------------------------------------------------------------------------------------------------ - void UnoControlTableModel::notifyRowsInserted( GridDataEvent const & i_event ) + void UnoControlTableModel::notifyRowsInserted( GridDataEvent const & i_event ) const { // check sanity of the event ENSURE_OR_RETURN_VOID( i_event.FirstRow >= 0, "UnoControlTableModel::notifyRowsInserted: invalid first row!" ); @@ -840,9 +845,8 @@ namespace svt { namespace table } //------------------------------------------------------------------------------------------------------------------ - void UnoControlTableModel::notifyRowsRemoved( GridDataEvent const & i_event ) + void UnoControlTableModel::notifyRowsRemoved( GridDataEvent const & i_event ) const { - // multiplex the event to our own listeners ModellListeners aListeners( m_pImpl->m_aListeners ); for ( ModellListeners::const_iterator loop = aListeners.begin(); loop != aListeners.end(); @@ -853,6 +857,37 @@ namespace svt { namespace table } } + //------------------------------------------------------------------------------------------------------------------ + void UnoControlTableModel::notifyDataChanged( ::com::sun::star::awt::grid::GridDataEvent const & i_event ) const + { + ColPos const firstCol = i_event.FirstColumn == -1 ? 0 : i_event.FirstColumn; + ColPos const lastCol = i_event.FirstColumn == -1 ? getColumnCount() - 1 : i_event.LastColumn; + RowPos const firstRow = i_event.FirstRow == -1 ? 0 : i_event.FirstRow; + RowPos const lastRow = i_event.FirstRow == -1 ? getRowCount() - 1 : i_event.LastRow; + + ModellListeners aListeners( m_pImpl->m_aListeners ); + for ( ModellListeners::const_iterator loop = aListeners.begin(); + loop != aListeners.end(); + ++loop + ) + { + (*loop)->cellsUpdated( firstCol, lastCol, firstRow, lastRow ); + } + } + + //------------------------------------------------------------------------------------------------------------------ + void UnoControlTableModel::notifyAllDataChanged() const + { + ModellListeners aListeners( m_pImpl->m_aListeners ); + for ( ModellListeners::const_iterator loop = aListeners.begin(); + loop != aListeners.end(); + ++loop + ) + { + (*loop)->cellsUpdated( 0, getColumnCount() - 1, 0, getRowCount() - 1 ); + } + } + // ..................................................................................................................... } } // svt::table // ..................................................................................................................... diff --git a/svtools/source/uno/unocontroltablemodel.hxx b/svtools/source/uno/unocontroltablemodel.hxx index 32930a64326d..537c3d9a5249 100644 --- a/svtools/source/uno/unocontroltablemodel.hxx +++ b/svtools/source/uno/unocontroltablemodel.hxx @@ -137,8 +137,9 @@ namespace svt { namespace table void setVerticalAlign(::com::sun::star::style::VerticalAlignment _rAlign); // multiplexing of XGridDataListener events - void notifyRowsInserted( ::com::sun::star::awt::grid::GridDataEvent const & i_event ); - void notifyRowsRemoved( ::com::sun::star::awt::grid::GridDataEvent const & i_event ); + void notifyRowsInserted( ::com::sun::star::awt::grid::GridDataEvent const & i_event ) const; + void notifyRowsRemoved( ::com::sun::star::awt::grid::GridDataEvent const & i_event ) const; + void notifyDataChanged( ::com::sun::star::awt::grid::GridDataEvent const & i_event ) const; /// retrieves the index of a column within the model ColPos getColumnPos( UnoGridColumnFacade const & i_column ) const; @@ -146,6 +147,11 @@ namespace svt { namespace table /// notifies a change in a column belonging to the model void notifyColumnChange( ColPos const i_columnPos, ColumnAttributeGroup const i_attributeGroup ) const; + /** notifies a change in all data represented by the model. To be used if you cannot specified the changed data + in more detail. + */ + void notifyAllDataChanged() const; + #ifdef DBG_UTIL const char* checkInvariants() const; #endif diff --git a/svtools/source/uno/unogridcolumnfacade.cxx b/svtools/source/uno/unogridcolumnfacade.cxx index 00fa72199815..98078b1fb2d4 100755 --- a/svtools/source/uno/unogridcolumnfacade.cxx +++ b/svtools/source/uno/unogridcolumnfacade.cxx @@ -148,6 +148,14 @@ namespace svt { namespace table //------------------------------------------------------------------------------------------------------------------ void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException) { + if ( i_event.AttributeName.equalsAscii( "DataColumnIndex" ) ) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + if ( m_pColumnImplementation != NULL ) + m_pColumnImplementation->dataColumnIndexChanged(); + return; + } + ColumnAttributeGroup nChangedAttributes( COL_ATTRS_NONE ); if ( i_event.AttributeName.equalsAscii( "HorizontalAlign" ) ) @@ -182,9 +190,11 @@ namespace svt { namespace table UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn ) :m_pOwner( &i_owner ) ,m_xGridColumn( i_gridColumn, UNO_QUERY_THROW ) + ,m_nDataColumnIndex( -1 ) ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) ) { m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer.get() ); + impl_updateDataColumnIndex_nothrow(); } //------------------------------------------------------------------------------------------------------------------ @@ -206,6 +216,30 @@ namespace svt { namespace table } //------------------------------------------------------------------------------------------------------------------ + void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow() + { + m_nDataColumnIndex = -1; + ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" ); + try + { + m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //------------------------------------------------------------------------------------------------------------------ + void UnoGridColumnFacade::dataColumnIndexChanged() + { + DBG_TESTSOLARMUTEX(); + impl_updateDataColumnIndex_nothrow(); + if ( m_pOwner != NULL ) + m_pOwner->notifyAllDataChanged(); + } + + //------------------------------------------------------------------------------------------------------------------ void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup const i_attributeGroup ) { DBG_TESTSOLARMUTEX(); diff --git a/svtools/source/uno/unogridcolumnfacade.hxx b/svtools/source/uno/unogridcolumnfacade.hxx index 6f606bb6f86b..11d40afa2984 100755 --- a/svtools/source/uno/unogridcolumnfacade.hxx +++ b/svtools/source/uno/unogridcolumnfacade.hxx @@ -90,11 +90,19 @@ namespace svt { namespace table */ void dispose(); - // callback for the XGridColumnListener + sal_Int32 + getDataColumnIndex() const { return m_nDataColumnIndex; } + + // callbacks for the XGridColumnListener void columnChanged( ColumnAttributeGroup const i_attributeGroup ); + void dataColumnIndexChanged(); + + private: + void impl_updateDataColumnIndex_nothrow(); private: - const UnoControlTableModel* m_pOwner; + UnoControlTableModel const * m_pOwner; + sal_Int32 m_nDataColumnIndex; ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > m_xGridColumn; ::rtl::Reference< ColumnChangeMultiplexer > m_pChangeMultiplexer; }; |