diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-18 11:49:19 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-18 11:49:19 +0100 |
commit | 4a593d1851b4673f7b9a68c7f336f182fc6b43bb (patch) | |
tree | 9164cb3c0aba98c493220ca36b18e1907b11e3df /svtools/source/table | |
parent | dc971d000d15cbf5d19119cf54c44aafaff88c50 (diff) |
gridsort: initial support for sorting the table data (unfinished)
What's there is a IMouseFunction implementation which cares for sorting the ITableModel's data,
by the column whose header was clicked. This is dependent on the model declaring support for sorting,
by exposing a ITableSort interface.
Missing pieces:
- no UNO equivalent, yet (neither as design nor as implementation)
- visualization of the current sort order/column
Diffstat (limited to 'svtools/source/table')
-rw-r--r-- | svtools/source/table/defaultinputhandler.cxx | 1 | ||||
-rwxr-xr-x | svtools/source/table/mousefunction.cxx | 74 | ||||
-rwxr-xr-x | svtools/source/table/mousefunction.hxx | 21 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.cxx | 16 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.hxx | 2 |
5 files changed, 97 insertions, 17 deletions
diff --git a/svtools/source/table/defaultinputhandler.cxx b/svtools/source/table/defaultinputhandler.cxx index 0870fac86087..e2706a37a715 100644 --- a/svtools/source/table/defaultinputhandler.cxx +++ b/svtools/source/table/defaultinputhandler.cxx @@ -59,6 +59,7 @@ namespace svt { namespace table { m_pImpl->aMouseFunctions.push_back( new ColumnResize ); m_pImpl->aMouseFunctions.push_back( new RowSelection ); + m_pImpl->aMouseFunctions.push_back( new ColumnSortHandler ); } //------------------------------------------------------------------------------------------------------------------ diff --git a/svtools/source/table/mousefunction.cxx b/svtools/source/table/mousefunction.cxx index f5e6080f9ddd..e3a47057423f 100755 --- a/svtools/source/table/mousefunction.cxx +++ b/svtools/source/table/mousefunction.cxx @@ -120,8 +120,7 @@ namespace svt { namespace table return ContinueFunction; } - Point const aPoint = i_event.GetPosPixel(); - TableCell const tableCell( i_tableControl.hitTest( aPoint ) ); + TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) ); if ( tableCell.nRow == ROW_COL_HEADERS ) { if ( ( tableCell.nColumn != COL_INVALID ) @@ -205,8 +204,7 @@ namespace svt { namespace table { bool handled = false; - Point const aPoint = i_event.GetPosPixel(); - TableCell const tableCell( i_tableControl.hitTest( aPoint ) ); + TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) ); if ( tableCell.nRow >= 0 ) { bool bSetCursor = false; @@ -228,7 +226,7 @@ namespace svt { namespace table if ( bSetCursor ) { - i_tableControl.activateCellAt( aPoint ); + i_tableControl.activateCell( tableCell.nColumn, tableCell.nRow ); handled = true; } } @@ -241,8 +239,8 @@ namespace svt { namespace table //------------------------------------------------------------------------------------------------------------------ FunctionResult RowSelection::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ) { - Point const aPoint = i_event.GetPosPixel(); - if ( i_tableControl.getRowAtPoint( aPoint ) >= 0 ) + TableCell const tableCell = i_tableControl.hitTest( i_event.GetPosPixel() ); + if ( tableCell.nRow >= 0 ) { if ( i_tableControl.getSelEngine()->GetSelectionMode() != NO_SELECTION ) { @@ -257,6 +255,68 @@ namespace svt { namespace table return SkipFunction; } + //================================================================================================================== + //= ColumnSortHandler + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + FunctionResult ColumnSortHandler::handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event ) + { + OSL_UNUSED( i_tableControl ); + OSL_UNUSED( i_event ); + return SkipFunction; + } + + //------------------------------------------------------------------------------------------------------------------ + FunctionResult ColumnSortHandler::handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event ) + { + if ( m_nActiveColumn != COL_INVALID ) + { + OSL_ENSURE( false, "ColumnSortHandler::handleMouseDown: called while already active - suspicious!" ); + return ContinueFunction; + } + + if ( i_tableControl.getModel()->getSortAdapter() == NULL ) + // no sorting support at the model + return SkipFunction; + + TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) ); + if ( ( tableCell.nRow != ROW_COL_HEADERS ) || ( tableCell.nColumn < 0 ) ) + return SkipFunction; + + // TODO: ensure the column header is rendered in some special way, indicating its current state + + m_nActiveColumn = tableCell.nColumn; + return ActivateFunction; + } + + //------------------------------------------------------------------------------------------------------------------ + FunctionResult ColumnSortHandler::handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ) + { + if ( m_nActiveColumn == COL_INVALID ) + return SkipFunction; + + TableCell const tableCell( i_tableControl.hitTest( i_event.GetPosPixel() ) ); + if ( ( tableCell.nRow != ROW_COL_HEADERS ) || ( tableCell.nColumn != m_nActiveColumn ) ) + // mouse was pressed on a column header, but released outside of it. + // => just deactivate, without sorting + return DeactivateFunction; + + ITableDataSort* pSort = i_tableControl.getModel()->getSortAdapter(); + ENSURE_OR_RETURN( pSort != NULL, "ColumnSortHandler::handleMouseUp: somebody is mocking with us!", DeactivateFunction ); + // in handleMousButtonDown, the model claimed to have sort support ... + + ColumnSortDirection eSortDirection = ColumnSortAscending; + ColumnSort const aCurrentSort = pSort->getCurrentSortOrder(); + if ( aCurrentSort.nColumnPos == m_nActiveColumn ) + // invert existing sort order + eSortDirection = ( aCurrentSort.eSortDirection == ColumnSortAscending ) ? ColumnSortDescending : ColumnSortAscending; + + pSort->sortByColumn( m_nActiveColumn, eSortDirection ); + + m_nActiveColumn = COL_INVALID; + return DeactivateFunction; + } + //...................................................................................................................... } } // namespace svt::table //...................................................................................................................... diff --git a/svtools/source/table/mousefunction.hxx b/svtools/source/table/mousefunction.hxx index dccd013e5680..2149026a0923 100755 --- a/svtools/source/table/mousefunction.hxx +++ b/svtools/source/table/mousefunction.hxx @@ -133,6 +133,27 @@ namespace svt { namespace table bool m_bActive; }; + //================================================================================================================== + //= ColumnSortHandler + //================================================================================================================== + class ColumnSortHandler : public MouseFunction + { + public: + ColumnSortHandler() + :m_nActiveColumn( COL_INVALID ) + { + } + + public: + // IMouseFunction + virtual FunctionResult handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event ); + virtual FunctionResult handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event ); + virtual FunctionResult handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ); + + private: + ColPos m_nActiveColumn; + }; + //...................................................................................................................... } } // namespace svt::table //...................................................................................................................... diff --git a/svtools/source/table/tablecontrol_impl.cxx b/svtools/source/table/tablecontrol_impl.cxx index dcd169381aef..8e995babb36f 100755 --- a/svtools/source/table/tablecontrol_impl.cxx +++ b/svtools/source/table/tablecontrol_impl.cxx @@ -200,6 +200,10 @@ namespace svt { namespace table { return com::sun::star::style::VerticalAlignment(0); } + virtual ITableDataSort* getSortAdapter() + { + return NULL; + } virtual void getCellContent( ColPos const i_col, RowPos const i_row, ::com::sun::star::uno::Any& o_cellContent ) { (void)i_row; @@ -1907,18 +1911,12 @@ namespace svt { namespace table } //------------------------------------------------------------------------------------------------------------------ - void TableControl_Impl::activateCellAt(const Point& rPoint) + bool TableControl_Impl::activateCell( ColPos const i_col, RowPos const i_row ) { DBG_CHECK_ME(); - - RowPos const newRowPos = getRowAtPoint( rPoint ); - ColPos const newColPos = getColAtPoint( rPoint ); - - if ( ( newRowPos >= 0 ) && ( newColPos >= 0 ) ) - { // don't activate invalid or header cells - goTo( newColPos, newRowPos ); - } + return goTo( i_col, i_row ); } + //------------------------------------------------------------------------------------------------------------------ void TableControl_Impl::invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow, Rectangle& _rCellRect) { diff --git a/svtools/source/table/tablecontrol_impl.hxx b/svtools/source/table/tablecontrol_impl.hxx index a6aebbaa6cc4..0975368a88a2 100755 --- a/svtools/source/table/tablecontrol_impl.hxx +++ b/svtools/source/table/tablecontrol_impl.hxx @@ -277,6 +277,7 @@ namespace svt { namespace table virtual PTableModel getModel() const; virtual ColPos getCurrentColumn() const; virtual RowPos getCurrentRow() const; + virtual bool activateCell( ColPos const i_col, RowPos const i_row ); virtual ::Size getTableSizePixel() const; virtual void setPointer( Pointer const & i_pointer ); virtual void captureMouse(); @@ -285,7 +286,6 @@ namespace svt { namespace table virtual long pixelWidthToAppFont( long const i_pixels ) const; virtual void hideTracking(); virtual void showTracking( Rectangle const & i_location, sal_uInt16 const i_flags ); - virtual void activateCellAt( const Point& rPoint ); virtual RowPos getRowAtPoint( const Point& rPoint ) const; virtual ColPos getColAtPoint( const Point& rPoint ) const; virtual TableCell hitTest( const Point& rPoint ) const; |