diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 1b1b0b4e09..df5b0c69b1 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1468,7 +1468,8 @@ public: // Returns the topmost row of the current visible area. int GetFirstFullyVisibleRow() const; - + // Returns the leftmost column of the current visible area. + int GetFirstFullyVisibleColumn() const; // ------ grid cursor movement functions // diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 74a8812580..52c966122b 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -4835,6 +4835,11 @@ public: Returns -1 if the grid doesn't have any rows. */ int GetFirstFullyVisibleRow() const; + /** + Returns the leftmost column of the current visible area. + Returns -1 if the grid doesn't have any columns. + */ + int GetFirstFullyVisibleColumn() const; /** Sets the number of pixels per horizontal scroll increment. diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 8aea66a5b8..f35a8f79a7 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3691,10 +3691,15 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo case WXGRID_CURSOR_SELECT_ROW: { + if ( !m_selection || m_numRows == 0 || m_numCols == 0 ) + break; + if ( (row = YToRow( pos.y )) >= 0 ) { - if ( m_selection ) - m_selection->SelectRow(row, event); + m_selection->ExtendOrCreateCurrentBlock( + wxGridCellCoords(m_currentCellCoords.GetRow(), 0), + wxGridCellCoords(row, GetNumberCols() - 1), + event); } } break; @@ -3736,12 +3741,14 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo if ( row >= 0 && !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) ) { - if ( !event.ShiftDown() && !event.CmdDown() ) - ClearSelection(); - if ( m_selection ) + if ( m_selection && m_numRows > 0 && m_numCols > 0 ) { - if ( event.ShiftDown() ) + bool selectNewRow = false; + + if ( event.ShiftDown() && !event.CmdDown() ) { + // Continue editing the current selection and don't + // move the grid cursor. m_selection->ExtendOrCreateCurrentBlock ( wxGridCellCoords(m_currentCellCoords.GetRow(), 0), @@ -3750,9 +3757,25 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo ); MakeCellVisible(row, -1); } + else if ( event.CmdDown() && !event.ShiftDown() ) + { + if ( GetSelectedRows().Index(row) != wxNOT_FOUND ) + DeselectRow(row); + else + selectNewRow = true; + } else { + ClearSelection(); + selectNewRow = true; + } + + if ( selectNewRow ) + { + // Select the new row. m_selection->SelectRow(row, event); + + SetCurrentCell(row, GetFirstFullyVisibleColumn()); } } @@ -7853,6 +7876,40 @@ int wxGrid::GetFirstFullyVisibleRow() const return row; } +int wxGrid::GetFirstFullyVisibleColumn() const +{ + if ( m_numCols == 0 ) + return -1; + + int col; + if ( GetNumberFrozenCols() > 0 ) + { + col = 0; + } + else + { + int x; + CalcGridWindowUnscrolledPosition(0, 0, + &x, NULL, + m_gridWin); + + col = XToCol(x, true, m_gridWin); + + // If the column is not fully visible. + if ( GetColLeft(col) < x ) + { + // Use the next visible column. + for ( ; col < m_numCols; ++col ) + { + if ( IsColShown(GetColAt(col)) ) + break; + } + } + } + + return col; +} + // // ------ Grid cursor movement functions //