void wxGrid::Create()
{
m_created = FALSE; // set to TRUE by CreateGrid
- m_displayed = TRUE; // FALSE; // set to TRUE by OnPaint
m_table = (wxGridTableBase *) NULL;
m_ownTable = FALSE;
m_table->SetView( this );
m_ownTable = TRUE;
Init();
+ m_selection = new wxGridSelection( this, selmode );
m_created = TRUE;
}
- m_selection = new wxGridSelection( this, selmode );
return m_created;
}
-bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership )
+void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
+{
+ if ( !m_created )
+ {
+ wxFAIL_MSG( wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") );
+ }
+ else
+ m_selection->SetSelectionMode( selmode );
+}
+
+bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
+ wxGrid::wxGridSelectionModes selmode )
{
if ( m_created )
{
// View at runtime. Is there anything in the implmentation that would
// prevent this?
+ // At least, you now have to copy with m_selection
wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
return FALSE;
}
if (takeOwnership)
m_ownTable = TRUE;
Init();
+ m_selection = new wxGridSelection( this, selmode );
m_created = TRUE;
}
ClearSelection();
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 &&
YToEdgeOfRow(y) < 0 )
if ( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords )
{
- m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
- m_selectingTopLeft.GetCol(),
- m_selectingBottomRight.GetRow(),
- m_selectingBottomRight.GetCol() );
if (m_winCapture)
{
m_winCapture->ReleaseMouse();
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
}
else if ( type == wxEVT_GRID_RANGE_SELECT )
{
+ // Right now, it should _never_ end up here!
wxGridRangeSelectEvent gridEvt( GetId(),
type,
this,
m_selectingTopLeft,
m_selectingBottomRight,
+ TRUE,
mouseEv.ControlDown(),
mouseEv.ShiftDown(),
mouseEv.AltDown(),
type,
this,
row, col,
+ TRUE,
mouseEv.GetX(), mouseEv.GetY(),
mouseEv.ControlDown(),
mouseEv.ShiftDown(),
void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc( this );
-
- if ( m_currentCellCoords == wxGridNoCellCoords &&
- m_numRows && m_numCols )
- {
- m_currentCellCoords.Set(0, 0);
- ShowCellEditControl();
- }
-
- m_displayed = TRUE;
}
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
//
switch ( event.KeyCode() )
case WXK_UP:
if ( event.ControlDown() )
{
- MoveCursorUpBlock();
+ MoveCursorUpBlock( event.ShiftDown() );
}
else
{
- MoveCursorUp();
+ MoveCursorUp( event.ShiftDown() );
}
break;
case WXK_DOWN:
if ( event.ControlDown() )
{
- MoveCursorDownBlock();
+ MoveCursorDownBlock( event.ShiftDown() );
}
else
{
- MoveCursorDown();
+ MoveCursorDown( event.ShiftDown() );
}
break;
case WXK_LEFT:
if ( event.ControlDown() )
{
- MoveCursorLeftBlock();
+ MoveCursorLeftBlock( event.ShiftDown() );
}
else
{
- MoveCursorLeft();
+ MoveCursorLeft( event.ShiftDown() );
}
break;
case WXK_RIGHT:
if ( event.ControlDown() )
{
- MoveCursorRightBlock();
+ MoveCursorRightBlock( event.ShiftDown() );
}
else
{
- MoveCursorRight();
+ MoveCursorRight( event.ShiftDown() );
}
break;
}
else
{
- MoveCursorDown();
+ MoveCursorDown( event.ShiftDown() );
}
break;
+ case WXK_ESCAPE:
+ m_selection->ClearSelection();
+ break;
+
case WXK_TAB:
if (event.ShiftDown())
- MoveCursorLeft();
+ MoveCursorLeft( FALSE );
else
- MoveCursorRight();
+ MoveCursorRight( FALSE );
break;
case WXK_HOME:
MovePageDown();
break;
+#if 0
case WXK_SPACE:
if ( !IsEditable() )
{
- MoveCursorRight();
+ MoveCursorRight( FALSE );
break;
}
// Otherwise fall through to default
+#else
+ case WXK_SPACE:
+ m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
+ break;
+#endif
default:
// alphanumeric keys or F2 (special key just for this) enable
// 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() ||
event.MetaDown() ||
event.ControlDown()) &&
- (isalnum(event.KeyCode()) || event.KeyCode() == WXK_F2) &&
+ ((isalnum(event.KeyCode()) &&
+ (event.KeyCode() < 256 && event.KeyCode() >= 0)) ||
+ event.KeyCode() == WXK_F2) &&
!IsCellEditControlEnabled() &&
CanEnableCellControl() )
{
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 &&
- m_currentCellCoords != wxGridNoCellCoords )
+ if ( m_currentCellCoords != wxGridNoCellCoords )
{
HideCellEditControl();
DisableCellEditControl();
m_currentCellCoords = coords;
- if ( m_displayed )
- {
- wxClientDC dc(m_gridWin);
- PrepareDC(dc);
+ wxClientDC dc(m_gridWin);
+ PrepareDC(dc);
+
+ wxGridCellAttr* attr = GetCellAttr(coords);
+ DrawCellHighlight(dc, attr);
+ attr->DecRef();
- wxGridCellAttr* attr = GetCellAttr(coords);
- DrawCellHighlight(dc, attr);
- attr->DecRef();
#if 0
// SN: For my extended selection code, automatic
// deselection is definitely not a good idea.
if ( !GetBatchCount() ) m_gridWin->Refresh( FALSE, &r );
}
#endif
- }
}
void wxGrid::DrawHighlight(wxDC& dc)
{
+ // This if block was previously in wxGrid::OnPaint but that doesn't
+ // seem to get called under wxGTK - MB
+ //
+ if ( m_currentCellCoords == wxGridNoCellCoords &&
+ m_numRows && m_numCols )
+ {
+ m_currentCellCoords.Set(0, 0);
+ }
+
if ( IsCellEditControlEnabled() )
{
// don't show highlight when the edit control is shown
// ------ Grid cursor movement functions
//
-bool wxGrid::MoveCursorUp()
+bool wxGrid::MoveCursorUp( bool expandSelection )
{
if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetRow() > 0 )
{
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
+
MakeCellVisible( m_currentCellCoords.GetRow() - 1,
m_currentCellCoords.GetCol() );
SetCurrentCell( m_currentCellCoords.GetRow() - 1,
m_currentCellCoords.GetCol() );
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
return TRUE;
}
}
-bool wxGrid::MoveCursorDown()
+bool wxGrid::MoveCursorDown( bool expandSelection )
{
- // TODO: allow for scrolling
- //
if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetRow() < m_numRows-1 )
{
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
+
MakeCellVisible( m_currentCellCoords.GetRow() + 1,
m_currentCellCoords.GetCol() );
SetCurrentCell( m_currentCellCoords.GetRow() + 1,
m_currentCellCoords.GetCol() );
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
return TRUE;
}
}
-bool wxGrid::MoveCursorLeft()
+bool wxGrid::MoveCursorLeft( bool expandSelection )
{
if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetCol() > 0 )
{
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
+
MakeCellVisible( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() - 1 );
SetCurrentCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() - 1 );
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
return TRUE;
}
}
-bool wxGrid::MoveCursorRight()
+bool wxGrid::MoveCursorRight( bool expandSelection )
{
if ( m_currentCellCoords != wxGridNoCellCoords &&
m_currentCellCoords.GetCol() < m_numCols - 1 )
{
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
+
MakeCellVisible( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() + 1 );
SetCurrentCell( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol() + 1 );
+ if ( expandSelection )
+ m_selection->SelectCell( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol() );
return TRUE;
}
return FALSE;
}
-bool wxGrid::MoveCursorUpBlock()
+bool wxGrid::MoveCursorUpBlock( bool expandSelection )
{
if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords &&
}
MakeCellVisible( row, col );
+ if ( expandSelection )
+ m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol(),
+ row, col );
SetCurrentCell( row, col );
return TRUE;
return FALSE;
}
-bool wxGrid::MoveCursorDownBlock()
+bool wxGrid::MoveCursorDownBlock( bool expandSelection )
{
if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords &&
}
MakeCellVisible( row, col );
+ if ( expandSelection )
+ m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol(),
+ row, col );
SetCurrentCell( row, col );
return TRUE;
return FALSE;
}
-bool wxGrid::MoveCursorLeftBlock()
+bool wxGrid::MoveCursorLeftBlock( bool expandSelection )
{
if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords &&
}
MakeCellVisible( row, col );
+ if ( expandSelection )
+ m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol(),
+ row, col );
SetCurrentCell( row, col );
return TRUE;
return FALSE;
}
-bool wxGrid::MoveCursorRightBlock()
+bool wxGrid::MoveCursorRightBlock( bool expandSelection )
{
if ( m_table &&
m_currentCellCoords != wxGridNoCellCoords &&
}
MakeCellVisible( row, col );
+ if ( expandSelection )
+ m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol(),
+ row, col );
SetCurrentCell( row, col );
return TRUE;
m_selection->ClearSelection();
m_selection->SelectRow( row );
-
- wxGridRangeSelectEvent gridEvt( GetId(),
- wxEVT_GRID_RANGE_SELECT,
- this,
- wxGridCellCoords( row, 0 ),
- wxGridCellCoords( row, m_numCols - 1 ) );
-
- GetEventHandler()->ProcessEvent(gridEvt);
}
m_selection->ClearSelection();
m_selection->SelectCol( col );
-
- wxGridRangeSelectEvent gridEvt( GetId(),
- wxEVT_GRID_RANGE_SELECT,
- this,
- wxGridCellCoords( 0, col ),
- wxGridCellCoords( m_numRows - 1, col ) );
-
- GetEventHandler()->ProcessEvent(gridEvt);
}
m_gridWin->Refresh( FALSE, &(rect[i]) );
}
- // only generate an event if the block is not being selected by
- // dragging the mouse (in which case the event will be generated in
- // the mouse event handler)
- if ( !m_isDragging )
- {
- wxGridRangeSelectEvent gridEvt( GetId(),
- wxEVT_GRID_RANGE_SELECT,
- this,
- m_selectingTopLeft,
- m_selectingBottomRight );
-
- GetEventHandler()->ProcessEvent(gridEvt);
- }
+ // never generate an event as it will be generated from
+ // wxGridSelection::SelectBlock!
}
void wxGrid::SelectAll()
IMPLEMENT_DYNAMIC_CLASS( wxGridEvent, wxEvent )
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 )
: wxNotifyEvent( type, id )
{
m_col = col;
m_x = x;
m_y = y;
+ m_selecting = sel;
m_control = control;
m_shift = shift;
m_alt = alt;
wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
const wxGridCellCoords& topLeft,
const wxGridCellCoords& bottomRight,
- bool control, bool shift, bool alt, bool meta )
+ bool sel, bool control,
+ bool shift, bool alt, bool meta )
: wxNotifyEvent( type, id )
{
m_topLeft = topLeft;
m_bottomRight = bottomRight;
+ m_selecting = sel;
m_control = control;
m_shift = shift;
m_alt = alt;