Improved handling of selection/deselection events.

Improved keyboard navigation.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2000-03-04 23:09:37 +00:00
parent 1f80a703f2
commit 5c8fc7c1de
5 changed files with 262 additions and 127 deletions

View File

@@ -998,8 +998,8 @@ public:
wxGridTableBase * GetTable() const { return m_table; } wxGridTableBase * GetTable() const { return m_table; }
bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE, bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectionModes selmode =
wxGrid::wxGridSelectCells ); wxGrid::wxGridSelectCells );
void ClearGrid(); void ClearGrid();
bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
@@ -1105,16 +1105,16 @@ public:
void SetGridCursor( int row, int col ) void SetGridCursor( int row, int col )
{ SetCurrentCell( wxGridCellCoords(row, col) ); } { SetCurrentCell( wxGridCellCoords(row, col) ); }
bool MoveCursorUp(); bool MoveCursorUp( bool expandSelection );
bool MoveCursorDown(); bool MoveCursorDown( bool expandSelection );
bool MoveCursorLeft(); bool MoveCursorLeft( bool expandSelection );
bool MoveCursorRight(); bool MoveCursorRight( bool expandSelection );
bool MovePageDown(); bool MovePageDown();
bool MovePageUp(); bool MovePageUp();
bool MoveCursorUpBlock(); bool MoveCursorUpBlock( bool expandSelection );
bool MoveCursorDownBlock(); bool MoveCursorDownBlock( bool expandSelection );
bool MoveCursorLeftBlock(); bool MoveCursorLeftBlock( bool expandSelection );
bool MoveCursorRightBlock(); bool MoveCursorRightBlock( bool expandSelection );
// ------ label and gridline formatting // ------ label and gridline formatting
@@ -1732,17 +1732,18 @@ class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
public: public:
wxGridEvent() wxGridEvent()
: wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1), : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
m_control(0), m_meta(0), m_shift(0), m_alt(0) m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0)
{ {
} }
wxGridEvent(int id, wxEventType type, wxObject* obj, wxGridEvent(int id, wxEventType type, wxObject* obj,
int row=-1, int col=-1, int x=-1, int y=-1, int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
virtual int GetRow() { return m_row; } virtual int GetRow() { return m_row; }
virtual int GetCol() { return m_col; } virtual int GetCol() { return m_col; }
wxPoint GetPosition() { return wxPoint( m_x, m_y ); } wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
bool Selecting() { return m_selecting; }
bool ControlDown() { return m_control; } bool ControlDown() { return m_control; }
bool MetaDown() { return m_meta; } bool MetaDown() { return m_meta; }
bool ShiftDown() { return m_shift; } bool ShiftDown() { return m_shift; }
@@ -1753,6 +1754,7 @@ protected:
int m_col; int m_col;
int m_x; int m_x;
int m_y; int m_y;
bool m_selecting;
bool m_control; bool m_control;
bool m_meta; bool m_meta;
bool m_shift; bool m_shift;
@@ -1802,6 +1804,7 @@ public:
{ {
m_topLeft = wxGridNoCellCoords; m_topLeft = wxGridNoCellCoords;
m_bottomRight = wxGridNoCellCoords; m_bottomRight = wxGridNoCellCoords;
m_selecting = FALSE;
m_control = FALSE; m_control = FALSE;
m_meta = FALSE; m_meta = FALSE;
m_shift = FALSE; m_shift = FALSE;
@@ -1811,6 +1814,7 @@ public:
wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
const wxGridCellCoords& topLeft, const wxGridCellCoords& topLeft,
const wxGridCellCoords& bottomRight, const wxGridCellCoords& bottomRight,
bool sel = TRUE,
bool control=FALSE, bool shift=FALSE, bool control=FALSE, bool shift=FALSE,
bool alt=FALSE, bool meta=FALSE); bool alt=FALSE, bool meta=FALSE);
@@ -1820,6 +1824,7 @@ public:
int GetBottomRow() { return m_bottomRight.GetRow(); } int GetBottomRow() { return m_bottomRight.GetRow(); }
int GetLeftCol() { return m_topLeft.GetCol(); } int GetLeftCol() { return m_topLeft.GetCol(); }
int GetRightCol() { return m_bottomRight.GetCol(); } int GetRightCol() { return m_bottomRight.GetCol(); }
bool Selecting() { return m_selecting; }
bool ControlDown() { return m_control; } bool ControlDown() { return m_control; }
bool MetaDown() { return m_meta; } bool MetaDown() { return m_meta; }
bool ShiftDown() { return m_shift; } bool ShiftDown() { return m_shift; }
@@ -1828,6 +1833,7 @@ public:
protected: protected:
wxGridCellCoords m_topLeft; wxGridCellCoords m_topLeft;
wxGridCellCoords m_bottomRight; wxGridCellCoords m_bottomRight;
bool m_selecting;
bool m_control; bool m_control;
bool m_meta; bool m_meta;
bool m_shift; bool m_shift;

View File

@@ -31,8 +31,10 @@ public:
void SetSelectionMode(wxGrid::wxGridSelectionModes selmode); void SetSelectionMode(wxGrid::wxGridSelectionModes selmode);
void SelectRow( int row, bool addToSelected = FALSE ); void SelectRow( int row, bool addToSelected = FALSE );
void SelectCol( int col, bool addToSelected = FALSE ); void SelectCol( int col, bool addToSelected = FALSE );
void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ); void SelectBlock( int topRow, int leftCol,
void SelectCell( int row, int col); int bottomRow, int rightCol,
wxMouseEvent* event = 0, bool sendEvent = TRUE );
void SelectCell( int row, int col, bool sendEvent = TRUE );
void ToggleCellSelection( int row, int col); void ToggleCellSelection( int row, int col);
void ClearSelection(); void ClearSelection();

View File

@@ -165,8 +165,8 @@ GridFrame::GridFrame()
wxMenu *selectionMenu = new wxMenu; wxMenu *selectionMenu = new wxMenu;
editMenu->Append( ID_CHANGESEL, "Change &selection mode", editMenu->Append( ID_CHANGESEL, "Change &selection mode",
selectionMenu, selectionMenu,
"Change selection mode" ); "Change selection mode" );
selectionMenu->Append( ID_SELCELLS, "Select &Cells" ); selectionMenu->Append( ID_SELCELLS, "Select &Cells" );
selectionMenu->Append( ID_SELROWS, "Select &Rows" ); selectionMenu->Append( ID_SELROWS, "Select &Rows" );
@@ -498,8 +498,8 @@ void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
if ( grid->IsSelection() ) if ( grid->IsSelection() )
{ {
for ( int n = 0; n < grid->GetNumberRows(); n++ ) for ( int n = 0; n < grid->GetNumberRows(); n++ )
if ( grid->IsInSelection( n , 0 ) ) if ( grid->IsInSelection( n , 0 ) )
grid->DeleteRows( n, 1 ); grid->DeleteRows( n, 1 );
} }
} }
@@ -509,8 +509,8 @@ void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
if ( grid->IsSelection() ) if ( grid->IsSelection() )
{ {
for ( int n = 0; n < grid->GetNumberCols(); n++ ) for ( int n = 0; n < grid->GetNumberCols(); n++ )
if ( grid->IsInSelection( 0 , n ) ) if ( grid->IsInSelection( 0 , n ) )
grid->DeleteCols( n, 1 ); grid->DeleteCols( n, 1 );
} }
} }
@@ -617,7 +617,11 @@ void GridFrame::OnColSize( wxGridSizeEvent& ev )
void GridFrame::OnSelectCell( wxGridEvent& ev ) void GridFrame::OnSelectCell( wxGridEvent& ev )
{ {
logBuf = ""; logBuf = "";
logBuf << "Selected cell at row " << ev.GetRow() if ( ev.Selecting() )
logBuf << "Selected ";
else
logBuf << "Deselected ";
logBuf << "cell at row " << ev.GetRow()
<< " col " << ev.GetCol(); << " col " << ev.GetCol();
wxLogMessage( "%s", logBuf.c_str() ); wxLogMessage( "%s", logBuf.c_str() );
@@ -629,10 +633,14 @@ void GridFrame::OnSelectCell( wxGridEvent& ev )
void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
{ {
logBuf = ""; logBuf = "";
logBuf << "Selected cells from row " << ev.GetTopRow() if ( ev.Selecting() )
<< " col " << ev.GetLeftCol() logBuf << "Selected ";
<< " to row " << ev.GetBottomRow() else
<< " col " << ev.GetRightCol(); logBuf << "Deselected ";
logBuf << "cells from row " << ev.GetTopRow()
<< " col " << ev.GetLeftCol()
<< " to row " << ev.GetBottomRow()
<< " col " << ev.GetRightCol();
wxLogMessage( "%s", logBuf.c_str() ); wxLogMessage( "%s", logBuf.c_str() );

View File

@@ -4324,7 +4324,10 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
ClearSelection(); ClearSelection();
if ( event.ShiftDown() ) if ( event.ShiftDown() )
{ {
SelectBlock( m_currentCellCoords, coords ); m_selection->SelectBlock( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
coords.GetRow(),
coords.GetCol() );
} }
else if ( XToEdgeOfCol(x) < 0 && else if ( XToEdgeOfCol(x) < 0 &&
YToEdgeOfRow(y) < 0 ) YToEdgeOfRow(y) < 0 )
@@ -4394,16 +4397,18 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
if ( m_selectingTopLeft != wxGridNoCellCoords && if ( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords ) m_selectingBottomRight != wxGridNoCellCoords )
{ {
m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
m_selectingTopLeft.GetCol(),
m_selectingBottomRight.GetRow(),
m_selectingBottomRight.GetCol() );
if (m_winCapture) if (m_winCapture)
{ {
m_winCapture->ReleaseMouse(); m_winCapture->ReleaseMouse();
m_winCapture = NULL; m_winCapture = NULL;
} }
SendEvent( wxEVT_GRID_RANGE_SELECT, -1, -1, event ); m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
m_selectingTopLeft.GetCol(),
m_selectingBottomRight.GetRow(),
m_selectingBottomRight.GetCol(),
& event );
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
} }
// Show the edit control, if it has been hidden for // Show the edit control, if it has been hidden for
@@ -4897,11 +4902,13 @@ bool wxGrid::SendEvent( const wxEventType type,
} }
else if ( type == wxEVT_GRID_RANGE_SELECT ) else if ( type == wxEVT_GRID_RANGE_SELECT )
{ {
// Right now, it should _never_ end up here!
wxGridRangeSelectEvent gridEvt( GetId(), wxGridRangeSelectEvent gridEvt( GetId(),
type, type,
this, this,
m_selectingTopLeft, m_selectingTopLeft,
m_selectingBottomRight, m_selectingBottomRight,
TRUE,
mouseEv.ControlDown(), mouseEv.ControlDown(),
mouseEv.ShiftDown(), mouseEv.ShiftDown(),
mouseEv.AltDown(), mouseEv.AltDown(),
@@ -4915,6 +4922,7 @@ bool wxGrid::SendEvent( const wxEventType type,
type, type,
this, this,
row, col, row, col,
false,
mouseEv.GetX(), mouseEv.GetY(), mouseEv.GetX(), mouseEv.GetY(),
mouseEv.ControlDown(), mouseEv.ControlDown(),
mouseEv.ShiftDown(), mouseEv.ShiftDown(),
@@ -5001,11 +5009,6 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) ) if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) )
{ {
// TODO: Should also support Shift-cursor keys for
// extending the selection. Maybe add a flag to
// MoveCursorXXX() and MoveCursorXXXBlock() and
// just send event.ShiftDown().
// try local handlers // try local handlers
// //
switch ( event.KeyCode() ) switch ( event.KeyCode() )
@@ -5013,44 +5016,44 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
case WXK_UP: case WXK_UP:
if ( event.ControlDown() ) if ( event.ControlDown() )
{ {
MoveCursorUpBlock(); MoveCursorUpBlock( event.ShiftDown() );
} }
else else
{ {
MoveCursorUp(); MoveCursorUp( event.ShiftDown() );
} }
break; break;
case WXK_DOWN: case WXK_DOWN:
if ( event.ControlDown() ) if ( event.ControlDown() )
{ {
MoveCursorDownBlock(); MoveCursorDownBlock( event.ShiftDown() );
} }
else else
{ {
MoveCursorDown(); MoveCursorDown( event.ShiftDown() );
} }
break; break;
case WXK_LEFT: case WXK_LEFT:
if ( event.ControlDown() ) if ( event.ControlDown() )
{ {
MoveCursorLeftBlock(); MoveCursorLeftBlock( event.ShiftDown() );
} }
else else
{ {
MoveCursorLeft(); MoveCursorLeft( event.ShiftDown() );
} }
break; break;
case WXK_RIGHT: case WXK_RIGHT:
if ( event.ControlDown() ) if ( event.ControlDown() )
{ {
MoveCursorRightBlock(); MoveCursorRightBlock( event.ShiftDown() );
} }
else else
{ {
MoveCursorRight(); MoveCursorRight( event.ShiftDown() );
} }
break; break;
@@ -5061,15 +5064,19 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
} }
else else
{ {
MoveCursorDown(); MoveCursorDown( event.ShiftDown() );
} }
break; break;
case WXK_ESCAPE:
m_selection->ClearSelection();
break;
case WXK_TAB: case WXK_TAB:
if (event.ShiftDown()) if (event.ShiftDown())
MoveCursorLeft(); MoveCursorLeft( FALSE );
else else
MoveCursorRight(); MoveCursorRight( FALSE );
break; break;
case WXK_HOME: case WXK_HOME:
@@ -5104,21 +5111,33 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
MovePageDown(); MovePageDown();
break; break;
#if 0
case WXK_SPACE: case WXK_SPACE:
if ( !IsEditable() ) if ( !IsEditable() )
{ {
MoveCursorRight(); MoveCursorRight( FALSE );
break; break;
} }
// Otherwise fall through to default // Otherwise fall through to default
#else
case WXK_SPACE:
m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
break;
#endif
default: default:
// alphanumeric keys or F2 (special key just for this) enable // alphanumeric keys or F2 (special key just for this) enable
// the cell edit control // the cell edit control
// On just Shift/Control I get values for event.KeyCode()
// that are outside the range where isalnum's behaviour is
// well defined, so do an additional sanity check.
if ( !(event.AltDown() || if ( !(event.AltDown() ||
event.MetaDown() || event.MetaDown() ||
event.ControlDown()) && event.ControlDown()) &&
(isalnum(event.KeyCode()) || event.KeyCode() == WXK_F2) && ((isalnum(event.KeyCode()) &&
(event.KeyCode() < 256 && event.KeyCode() >= 0)) ||
event.KeyCode() == WXK_F2) &&
!IsCellEditControlEnabled() && !IsCellEditControlEnabled() &&
CanEnableCellControl() ) CanEnableCellControl() )
{ {
@@ -5151,12 +5170,6 @@ void wxGrid::OnEraseBackground(wxEraseEvent&)
void wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
{ {
if ( SendEvent( wxEVT_GRID_SELECT_CELL, coords.GetRow(), coords.GetCol() ) )
{
// the event has been intercepted - do nothing
return;
}
if ( m_displayed && if ( m_displayed &&
m_currentCellCoords != wxGridNoCellCoords ) m_currentCellCoords != wxGridNoCellCoords )
{ {
@@ -6117,7 +6130,7 @@ void wxGrid::MakeCellVisible( int row, int col )
// ------ Grid cursor movement functions // ------ Grid cursor movement functions
// //
bool wxGrid::MoveCursorUp() bool wxGrid::MoveCursorUp( bool expandSelection )
{ {
if ( m_currentCellCoords != wxGridNoCellCoords && if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetRow() > 0 ) m_currentCellCoords.GetRow() > 0 )
@@ -6128,6 +6141,9 @@ bool wxGrid::MoveCursorUp()
SetCurrentCell( m_currentCellCoords.GetRow() - 1, SetCurrentCell( m_currentCellCoords.GetRow() - 1,
m_currentCellCoords.GetCol() ); m_currentCellCoords.GetCol() );
if ( expandSelection )
m_selection->SelectCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
return TRUE; return TRUE;
} }
@@ -6135,7 +6151,7 @@ bool wxGrid::MoveCursorUp()
} }
bool wxGrid::MoveCursorDown() bool wxGrid::MoveCursorDown( bool expandSelection )
{ {
// TODO: allow for scrolling // TODO: allow for scrolling
// //
@@ -6148,6 +6164,9 @@ bool wxGrid::MoveCursorDown()
SetCurrentCell( m_currentCellCoords.GetRow() + 1, SetCurrentCell( m_currentCellCoords.GetRow() + 1,
m_currentCellCoords.GetCol() ); m_currentCellCoords.GetCol() );
if ( expandSelection )
m_selection->SelectCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
return TRUE; return TRUE;
} }
@@ -6155,7 +6174,7 @@ bool wxGrid::MoveCursorDown()
} }
bool wxGrid::MoveCursorLeft() bool wxGrid::MoveCursorLeft( bool expandSelection )
{ {
if ( m_currentCellCoords != wxGridNoCellCoords && if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetCol() > 0 ) m_currentCellCoords.GetCol() > 0 )
@@ -6166,6 +6185,9 @@ bool wxGrid::MoveCursorLeft()
SetCurrentCell( m_currentCellCoords.GetRow(), SetCurrentCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() - 1 ); m_currentCellCoords.GetCol() - 1 );
if ( expandSelection )
m_selection->SelectCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
return TRUE; return TRUE;
} }
@@ -6173,7 +6195,7 @@ bool wxGrid::MoveCursorLeft()
} }
bool wxGrid::MoveCursorRight() bool wxGrid::MoveCursorRight( bool expandSelection )
{ {
if ( m_currentCellCoords != wxGridNoCellCoords && if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetCol() < m_numCols - 1 ) m_currentCellCoords.GetCol() < m_numCols - 1 )
@@ -6184,6 +6206,9 @@ bool wxGrid::MoveCursorRight()
SetCurrentCell( m_currentCellCoords.GetRow(), SetCurrentCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() + 1 ); m_currentCellCoords.GetCol() + 1 );
if ( expandSelection )
m_selection->SelectCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() );
return TRUE; return TRUE;
} }
@@ -6251,7 +6276,7 @@ bool wxGrid::MovePageDown()
return FALSE; return FALSE;
} }
bool wxGrid::MoveCursorUpBlock() bool wxGrid::MoveCursorUpBlock( bool expandSelection )
{ {
if ( m_table && if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords && m_currentCellCoords != wxGridNoCellCoords &&
@@ -6298,6 +6323,10 @@ bool wxGrid::MoveCursorUpBlock()
} }
MakeCellVisible( row, col ); MakeCellVisible( row, col );
if ( expandSelection )
m_selection->SelectBlock( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
row, col );
SetCurrentCell( row, col ); SetCurrentCell( row, col );
return TRUE; return TRUE;
@@ -6306,7 +6335,7 @@ bool wxGrid::MoveCursorUpBlock()
return FALSE; return FALSE;
} }
bool wxGrid::MoveCursorDownBlock() bool wxGrid::MoveCursorDownBlock( bool expandSelection )
{ {
if ( m_table && if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords && m_currentCellCoords != wxGridNoCellCoords &&
@@ -6353,6 +6382,10 @@ bool wxGrid::MoveCursorDownBlock()
} }
MakeCellVisible( row, col ); MakeCellVisible( row, col );
if ( expandSelection )
m_selection->SelectBlock( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
row, col );
SetCurrentCell( row, col ); SetCurrentCell( row, col );
return TRUE; return TRUE;
@@ -6361,7 +6394,7 @@ bool wxGrid::MoveCursorDownBlock()
return FALSE; return FALSE;
} }
bool wxGrid::MoveCursorLeftBlock() bool wxGrid::MoveCursorLeftBlock( bool expandSelection )
{ {
if ( m_table && if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords && m_currentCellCoords != wxGridNoCellCoords &&
@@ -6408,6 +6441,10 @@ bool wxGrid::MoveCursorLeftBlock()
} }
MakeCellVisible( row, col ); MakeCellVisible( row, col );
if ( expandSelection )
m_selection->SelectBlock( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
row, col );
SetCurrentCell( row, col ); SetCurrentCell( row, col );
return TRUE; return TRUE;
@@ -6416,7 +6453,7 @@ bool wxGrid::MoveCursorLeftBlock()
return FALSE; return FALSE;
} }
bool wxGrid::MoveCursorRightBlock() bool wxGrid::MoveCursorRightBlock( bool expandSelection )
{ {
if ( m_table && if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords && m_currentCellCoords != wxGridNoCellCoords &&
@@ -6463,6 +6500,10 @@ bool wxGrid::MoveCursorRightBlock()
} }
MakeCellVisible( row, col ); MakeCellVisible( row, col );
if ( expandSelection )
m_selection->SelectBlock( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
row, col );
SetCurrentCell( row, col ); SetCurrentCell( row, col );
return TRUE; return TRUE;
@@ -7454,14 +7495,6 @@ void wxGrid::SelectRow( int row, bool addToSelected )
m_selection->ClearSelection(); m_selection->ClearSelection();
m_selection->SelectRow( row ); m_selection->SelectRow( row );
wxGridRangeSelectEvent gridEvt( GetId(),
wxEVT_GRID_RANGE_SELECT,
this,
wxGridCellCoords( row, 0 ),
wxGridCellCoords( row, m_numCols - 1 ) );
GetEventHandler()->ProcessEvent(gridEvt);
} }
@@ -7471,14 +7504,6 @@ void wxGrid::SelectCol( int col, bool addToSelected )
m_selection->ClearSelection(); m_selection->ClearSelection();
m_selection->SelectCol( col ); m_selection->SelectCol( col );
wxGridRangeSelectEvent gridEvt( GetId(),
wxEVT_GRID_RANGE_SELECT,
this,
wxGridCellCoords( 0, col ),
wxGridCellCoords( m_numRows - 1, col ) );
GetEventHandler()->ProcessEvent(gridEvt);
} }
@@ -7601,19 +7626,8 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
m_gridWin->Refresh( FALSE, &(rect[i]) ); m_gridWin->Refresh( FALSE, &(rect[i]) );
} }
// only generate an event if the block is not being selected by // never generate an event as it will be generated from
// dragging the mouse (in which case the event will be generated in // wxGridSelection::SelectBlock!
// the mouse event handler)
if ( !m_isDragging )
{
wxGridRangeSelectEvent gridEvt( GetId(),
wxEVT_GRID_RANGE_SELECT,
this,
m_selectingTopLeft,
m_selectingBottomRight );
GetEventHandler()->ProcessEvent(gridEvt);
}
} }
void wxGrid::SelectAll() void wxGrid::SelectAll()
@@ -7700,7 +7714,7 @@ wxRect wxGrid::BlockToDeviceRect( const wxGridCellCoords &topLeft,
IMPLEMENT_DYNAMIC_CLASS( wxGridEvent, wxEvent ) IMPLEMENT_DYNAMIC_CLASS( wxGridEvent, wxEvent )
wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj, wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj,
int row, int col, int x, int y, int row, int col, int x, int y, bool sel,
bool control, bool shift, bool alt, bool meta ) bool control, bool shift, bool alt, bool meta )
: wxNotifyEvent( type, id ) : wxNotifyEvent( type, id )
{ {
@@ -7708,6 +7722,7 @@ wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj,
m_col = col; m_col = col;
m_x = x; m_x = x;
m_y = y; m_y = y;
m_selecting = sel;
m_control = control; m_control = control;
m_shift = shift; m_shift = shift;
m_alt = alt; m_alt = alt;
@@ -7741,11 +7756,13 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent, wxEvent )
wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
const wxGridCellCoords& topLeft, const wxGridCellCoords& topLeft,
const wxGridCellCoords& bottomRight, const wxGridCellCoords& bottomRight,
bool control, bool shift, bool alt, bool meta ) bool sel, bool control,
bool shift, bool alt, bool meta )
: wxNotifyEvent( type, id ) : wxNotifyEvent( type, id )
{ {
m_topLeft = topLeft; m_topLeft = topLeft;
m_bottomRight = bottomRight; m_bottomRight = bottomRight;
m_selecting = sel;
m_control = control; m_control = control;
m_shift = shift; m_shift = shift;
m_alt = alt; m_alt = alt;

View File

@@ -164,7 +164,8 @@ void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
m_blockSelectionTopLeft.RemoveAt(n); m_blockSelectionTopLeft.RemoveAt(n);
m_blockSelectionBottomRight.RemoveAt(n); m_blockSelectionBottomRight.RemoveAt(n);
SelectBlock( topRow, 0, SelectBlock( topRow, 0,
bottomRow, m_grid->GetNumberCols() - 1 ); bottomRow, m_grid->GetNumberCols() - 1,
0, FALSE );
} }
} }
else // selmode == wxGridSelectColumns) else // selmode == wxGridSelectColumns)
@@ -174,7 +175,8 @@ void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
m_blockSelectionTopLeft.RemoveAt(n); m_blockSelectionTopLeft.RemoveAt(n);
m_blockSelectionBottomRight.RemoveAt(n); m_blockSelectionBottomRight.RemoveAt(n);
SelectBlock( 0, leftCol, SelectBlock( 0, leftCol,
m_grid->GetNumberRows() - 1, rightCol ); m_grid->GetNumberRows() - 1, rightCol,
0, FALSE );
} }
} }
} }
@@ -260,8 +262,14 @@ void wxGridSelection::SelectRow( int row, bool addToSelected )
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r ); ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
// Possibly send event here? This would imply that no event is sent, // Send Event
// if the row already was part of the selection. wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECT,
m_grid,
wxGridCellCoords( row, 0 ),
wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
} }
void wxGridSelection::SelectCol( int col, bool addToSelected ) void wxGridSelection::SelectCol( int col, bool addToSelected )
@@ -342,13 +350,21 @@ void wxGridSelection::SelectCol( int col, bool addToSelected )
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r ); ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
// Possibly send event here? This would imply that no event is sent, // Send Event
// if the row already was part of the selection. wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECT,
m_grid,
wxGridCellCoords( 0, col ),
wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
} }
void wxGridSelection::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ) void wxGridSelection::SelectBlock( int topRow, int leftCol,
int bottomRow, int rightCol,
wxMouseEvent* mouseEv, bool sendEvent )
{ {
// Fix the coordinates of the block if potentially needed // Fix the coordinates of the block if needed.
if ( m_selectionMode == wxGrid::wxGridSelectRows ) if ( m_selectionMode == wxGrid::wxGridSelectRows )
{ {
leftCol = 0; leftCol = 0;
@@ -359,10 +375,23 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol, int bottomRow, int r
topRow = 0; topRow = 0;
bottomRow = m_grid->GetNumberRows() - 1; bottomRow = m_grid->GetNumberRows() - 1;
} }
if ( topRow > bottomRow )
{
int temp = topRow;
topRow = bottomRow;
bottomRow = temp;
}
if ( leftCol > rightCol )
{
int temp = leftCol;
leftCol = rightCol;
rightCol = temp;
}
// Handle single cell selection in SelectCell. // Handle single cell selection in SelectCell.
if ( topRow == bottomRow && leftCol == rightCol ) if ( topRow == bottomRow && leftCol == rightCol )
SelectCell( topRow, leftCol ); SelectCell( topRow, leftCol, sendEvent );
size_t count, n; size_t count, n;
// Remove single cells contained in newly selected block. // Remove single cells contained in newly selected block.
@@ -453,10 +482,36 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol, int bottomRow, int r
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r ); ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
// Possibly send event? // Send Event, if not disabled.
if ( sendEvent )
{
if ( mouseEv == 0)
{
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECT,
m_grid,
wxGridCellCoords( topRow, leftCol ),
wxGridCellCoords( bottomRow, rightCol ) );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
}
else
{
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECT,
m_grid,
wxGridCellCoords( topRow, leftCol ),
wxGridCellCoords( bottomRow, rightCol ),
TRUE,
mouseEv->ControlDown(),
mouseEv->ShiftDown(),
mouseEv->AltDown(),
mouseEv->MetaDown() );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
}
}
} }
void wxGridSelection::SelectCell( int row, int col) void wxGridSelection::SelectCell( int row, int col, bool sendEvent )
{ {
if ( m_selectionMode == wxGrid::wxGridSelectRows ) if ( m_selectionMode == wxGrid::wxGridSelectRows )
{ {
@@ -478,7 +533,12 @@ void wxGridSelection::SelectCell( int row, int col)
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r ); ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
// Possibly send event? // Send event
wxGridEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_SELECT_CELL,
m_grid,
row, col );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
} }
void wxGridSelection::ToggleCellSelection( int row, int col) void wxGridSelection::ToggleCellSelection( int row, int col)
@@ -515,6 +575,13 @@ void wxGridSelection::ToggleCellSelection( int row, int col)
if ( !m_grid->GetBatchCount() ) if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r ); ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
return; return;
// Send event
wxGridEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_SELECT_CELL,
m_grid,
row, col, -1, -1, FALSE );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
} }
} }
} }
@@ -558,16 +625,18 @@ void wxGridSelection::ToggleCellSelection( int row, int col)
if ( m_selectionMode != wxGrid::wxGridSelectColumns ) if ( m_selectionMode != wxGrid::wxGridSelectColumns )
{ {
if ( topRow < row ) if ( topRow < row )
SelectBlock( topRow, leftCol, row - 1, rightCol ); SelectBlock( topRow, leftCol,
row - 1, rightCol, 0, FALSE );
if ( bottomRow > row ) if ( bottomRow > row )
SelectBlock( row + 1, leftCol, bottomRow, rightCol ); SelectBlock( row + 1, leftCol,
bottomRow, rightCol, 0, FALSE );
} }
if ( m_selectionMode != wxGrid::wxGridSelectRows ) if ( m_selectionMode != wxGrid::wxGridSelectRows )
{ {
if ( leftCol < col ) if ( leftCol < col )
SelectBlock( row, leftCol, row, col - 1 ); SelectBlock( row, leftCol, row, col - 1, 0, FALSE );
if ( rightCol > col ) if ( rightCol > col )
SelectBlock( row, col + 1, row, rightCol ); SelectBlock( row, col + 1, row, rightCol, 0, FALSE );
} }
} }
} }
@@ -585,9 +654,11 @@ void wxGridSelection::ToggleCellSelection( int row, int col)
if (m_selectionMode == wxGrid::wxGridSelectCells) if (m_selectionMode == wxGrid::wxGridSelectCells)
{ {
if ( col > 0 ) if ( col > 0 )
SelectBlock( row, 0, row, col - 1 ); SelectBlock( row, 0, row, col - 1, 0, FALSE );
if ( col < m_grid->GetNumberCols() - 1 ) if ( col < m_grid->GetNumberCols() - 1 )
SelectBlock( row, col + 1, row, m_grid->GetNumberCols() - 1 ); SelectBlock( row, col + 1,
row, m_grid->GetNumberCols() - 1,
0, FALSE );
} }
} }
} }
@@ -606,34 +677,65 @@ void wxGridSelection::ToggleCellSelection( int row, int col)
if (m_selectionMode == wxGrid::wxGridSelectCells) if (m_selectionMode == wxGrid::wxGridSelectCells)
{ {
if ( row > 0 ) if ( row > 0 )
SelectBlock( 0, col, row - 1, col ); SelectBlock( 0, col, row - 1, col, 0, FALSE );
if ( row < m_grid->GetNumberRows() - 1 ) if ( row < m_grid->GetNumberRows() - 1 )
SelectBlock( row + 1, col, m_grid->GetNumberRows() - 1, col ); SelectBlock( row + 1, col,
m_grid->GetNumberRows() - 1, col,
0, FALSE );
} }
} }
} }
} }
// Refresh the screen; according to m_selectionMode, we // Refresh the screen and send the event; according to m_selectionMode,
// need to either update only the cell, or the whole row/column. // we need to either update only the cell, or the whole row/column.
wxRect r; wxRect r;
switch (m_selectionMode) switch (m_selectionMode)
{ {
case wxGrid::wxGridSelectCells: case wxGrid::wxGridSelectCells:
r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, col ), {
wxGridCellCoords( row, col ) ); r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, col ),
break; wxGridCellCoords( row, col ) );
if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
wxGridEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_SELECT_CELL,
m_grid,
row, col, -1, -1, FALSE );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
break;
}
case wxGrid::wxGridSelectRows: case wxGrid::wxGridSelectRows:
r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ), {
wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) ); r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
break; wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECT,
m_grid,
wxGridCellCoords( row, 0 ),
wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ),
FALSE );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
break;
}
case wxGrid::wxGridSelectColumns: case wxGrid::wxGridSelectColumns:
r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ), {
wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) ); r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
break; wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
wxEVT_GRID_RANGE_SELECT,
m_grid,
wxGridCellCoords( 0, col ),
wxGridCellCoords( m_grid->GetNumberRows() - 1, col ),
FALSE );
m_grid->GetEventHandler()->ProcessEvent(gridEvt);
break;
}
} }
if ( !m_grid->GetBatchCount() )
((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
} }
void wxGridSelection::ClearSelection() void wxGridSelection::ClearSelection()