diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-14 13:19:09 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-14 13:19:09 +0100 |
commit | f30518cc978f4f74a7e61d03872b913124e82f76 (patch) | |
tree | d5028c3b7bb3f801621e481bf0f9e1934afb725d /toolkit | |
parent | d0cdc38a6771473b81f002da6769b7b723d657ff (diff) |
gridsort: re-add tooltip support to X(Mutable)GridDataModel, this time more explicit, and less magical
Diffstat (limited to 'toolkit')
-rw-r--r-- | toolkit/source/controls/grid/defaultgriddatamodel.cxx | 86 | ||||
-rw-r--r-- | toolkit/source/controls/grid/defaultgriddatamodel.hxx | 19 |
2 files changed, 76 insertions, 29 deletions
diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx index 3d9b8324de81..693f86e187d9 100644 --- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx +++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx @@ -115,20 +115,47 @@ namespace toolkit } //------------------------------------------------------------------------------------------------------------------ - Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException) + DefaultGridDataModel::CellData const & DefaultGridDataModel::impl_getCellData_throw( sal_Int32 const i_column, sal_Int32 const i_row ) const { - ::osl::MutexGuard aGuard( GetMutex() ); - if ( ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() ) || ( i_column < 0 ) || ( i_column > m_nColumnCount ) ) - throw IndexOutOfBoundsException( ::rtl::OUString(), *this ); + throw IndexOutOfBoundsException( ::rtl::OUString(), *const_cast< DefaultGridDataModel* >( this ) ); - ::std::vector< Any > const & rRow( m_aData[ i_row ] ); + RowData const & rRow( m_aData[ i_row ] ); if ( size_t( i_column ) < rRow.size() ) return rRow[ i_column ]; - return Any(); + static CellData s_aEmpty; + return s_aEmpty; + } + + //------------------------------------------------------------------------------------------------------------------ + DefaultGridDataModel::CellData& DefaultGridDataModel::impl_getCellDataAccess_throw( sal_Int32 const i_column, sal_Int32 const i_row ) + { + if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aData.size() ) + || ( i_column < 0 ) || ( i_column >= m_nColumnCount ) + ) + throw IndexOutOfBoundsException( ::rtl::OUString(), *this ); + + RowData& rRowData( m_aData[ i_row ] ); + if ( size_t( i_column ) >= rRowData.size() ) + rRowData.resize( i_column + 1 ); + return rRowData[ i_column ]; + } + + //------------------------------------------------------------------------------------------------------------------ + Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + return impl_getCellData_throw( i_column, i_row ).first; + } + + //------------------------------------------------------------------------------------------------------------------ + Any SAL_CALL DefaultGridDataModel::getCellToolTip( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + return impl_getCellData_throw( i_column, i_row ).second; } //------------------------------------------------------------------------------------------------------------------ @@ -153,9 +180,7 @@ namespace toolkit m_aRowHeaders.push_back( i_title ); // store row m_aData - ::std::vector< Any > newRow( columnCount ); - ::std::copy( i_data.getConstArray(), i_data.getConstArray() + columnCount, newRow.begin() ); - m_aData.push_back( newRow ); + impl_addRow( i_data ); // update column count if ( columnCount > m_nColumnCount ) @@ -170,6 +195,20 @@ namespace toolkit } //------------------------------------------------------------------------------------------------------------------ + void DefaultGridDataModel::impl_addRow( Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount ) + { + OSL_PRECOND( ( i_assumedColCount <= 0 ) || ( i_assumedColCount >= i_rowData.getLength() ), + "DefaultGridDataModel::impl_addRow: invalid column count!" ); + + RowData newRow( i_assumedColCount > 0 ? i_assumedColCount : i_rowData.getLength() ); + RowData::iterator cellData = newRow.begin(); + for ( const Any* pData = stl_begin( i_rowData ); pData != stl_end( i_rowData ); ++pData, ++cellData ) + cellData->first = *pData; + + m_aData.push_back( newRow ); + } + + //------------------------------------------------------------------------------------------------------------------ void SAL_CALL DefaultGridDataModel::addRows( const Sequence< ::rtl::OUString >& i_titles, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException) { if ( i_titles.getLength() != i_data.getLength() ) @@ -193,11 +232,7 @@ namespace toolkit for ( sal_Int32 row=0; row<rowCount; ++row ) { m_aRowHeaders.push_back( i_titles[row] ); - - ::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 ); + impl_addRow( i_data[row], maxColCount ); } if ( maxColCount > m_nColumnCount ) @@ -250,15 +285,7 @@ namespace toolkit { ::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; + impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).first = i_value; broadcast( GridDataEvent( *this, i_columnIndex, i_columnIndex, i_rowIndex, i_rowIndex ), @@ -288,14 +315,14 @@ namespace toolkit throw IndexOutOfBoundsException( ::rtl::OUString(), *this ); } - ::std::vector< Any >& rDataRow = m_aData[ i_rowIndex ]; + RowData& rDataRow = m_aData[ i_rowIndex ]; for ( sal_Int32 col = 0; col < columnCount; ++col ) { sal_Int32 const columnIndex = i_columnIndexes[ col ]; if ( size_t( columnIndex ) >= rDataRow.size() ) rDataRow.resize( columnIndex + 1 ); - rDataRow[ columnIndex ] = i_values[ col ]; + rDataRow[ columnIndex ].first = i_values[ col ]; } sal_Int32 const firstAffectedColumn = *::std::min_element( stl_begin( i_columnIndexes ), stl_end( i_columnIndexes ) ); @@ -312,7 +339,7 @@ namespace toolkit { ::osl::ClearableMutexGuard aGuard( GetMutex() ); - if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) ) + if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aRowHeaders.size() ) ) throw IndexOutOfBoundsException( ::rtl::OUString(), *this ); m_aRowHeaders[ i_rowIndex ] = i_title; @@ -325,6 +352,13 @@ namespace toolkit } //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL DefaultGridDataModel::setCellToolTip( ::sal_Int32 i_rowIndex, ::sal_Int32 i_columnIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).second = i_value; + } + + //------------------------------------------------------------------------------------------------------------------ void SAL_CALL DefaultGridDataModel::addGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException) { BrdcstHelper.addListener( XGridDataListener::static_type(), i_listener ); diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.hxx b/toolkit/source/controls/grid/defaultgriddatamodel.hxx index 842e714c904c..acfb777ef5b0 100644 --- a/toolkit/source/controls/grid/defaultgriddatamodel.hxx +++ b/toolkit/source/controls/grid/defaultgriddatamodel.hxx @@ -69,6 +69,7 @@ public: 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 setCellToolTip( ::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 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); @@ -76,6 +77,7 @@ public: 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 ::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 ::com::sun::star::uno::Any SAL_CALL getCellToolTip( ::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 @@ -92,15 +94,26 @@ public: virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); private: + typedef ::std::pair< Any, Any > CellData; + typedef ::std::vector< CellData > RowData; + typedef ::std::vector< RowData > GridData; + 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 ); - ::std::vector< ::std::vector < Any > > m_aData; - ::std::vector< ::rtl::OUString > m_aRowHeaders; - sal_Int32 m_nColumnCount; + void impl_addRow( Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount = -1 ); + + CellData const & + impl_getCellData_throw( sal_Int32 const i_column, sal_Int32 const i_row ) const; + CellData& + impl_getCellDataAccess_throw( sal_Int32 const i_column, sal_Int32 const i_row ); + + GridData m_aData; + ::std::vector< ::rtl::OUString > m_aRowHeaders; + sal_Int32 m_nColumnCount; }; } |