wxGridCellCoordsArray dirtyCells = m_owner->CalcCellsExposed( reg );
m_owner->DrawGridCellArea( dc, dirtyCells );
+ m_owner->DrawGridSpace( dc );
+
m_owner->DrawAllGridLines( dc, reg );
- m_owner->DrawGridSpace( dc );
m_owner->DrawHighlight( dc, dirtyCells );
}
wxGrid::~wxGrid()
{
+ // Ensure that the editor control is destroyed before the grid is,
+ // otherwise we crash later when the editor tries to do something with the
+ // half destroyed grid
+ HideCellEditControl();
+
// Must do this or ~wxScrollHelper will pop the wrong event handler
SetTargetWindow(this);
ClearAttrCache();
m_gridLineColour = wxColour( 192,192,192 );
m_gridLinesEnabled = true;
+ m_gridLinesClipHorz =
+ m_gridLinesClipVert = true;
m_cellHighlightColour = *wxBLACK;
m_cellHighlightPenWidth = 2;
m_cellHighlightROPenWidth = 1;
if ( (row = YToRow( y )) >= 0 )
{
if ( m_selection )
- {
- m_selection->SelectRow( row,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
- }
+ m_selection->SelectRow(row, event);
}
}
break;
{
if ( event.ShiftDown() )
{
- m_selection->SelectBlock( m_currentCellCoords.GetRow(),
- 0,
- row,
- GetNumberCols() - 1,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectBlock
+ (
+ m_currentCellCoords.GetRow(), 0,
+ row, GetNumberCols() - 1,
+ event
+ );
}
else
{
- m_selection->SelectRow( row,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectRow(row, event);
}
}
if ( (col = XToCol( x )) >= 0 )
{
if ( m_selection )
- {
- m_selection->SelectCol( col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
- }
+ m_selection->SelectCol(col, event);
}
}
break;
{
if ( event.ShiftDown() )
{
- m_selection->SelectBlock( 0,
- m_currentCellCoords.GetCol(),
- GetNumberRows() - 1, col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectBlock
+ (
+ 0, m_currentCellCoords.GetCol(),
+ GetNumberRows() - 1, col,
+ event
+ );
}
else
{
- m_selection->SelectCol( col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectCol(col, event);
}
}
{
if ( m_selection )
{
- m_selection->SelectBlock( m_currentCellCoords,
- coords,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectBlock(m_currentCellCoords, coords, event);
m_selectedBlockCorner = coords;
}
}
{
if ( m_selection )
{
- m_selection->ToggleCellSelection( coords,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->ToggleCellSelection(coords, event);
}
+
m_selectedBlockTopLeft = wxGridNoCellCoords;
m_selectedBlockBottomRight = wxGridNoCellCoords;
m_selectedBlockCorner = coords;
{
m_selection->SelectBlock( m_selectedBlockTopLeft,
m_selectedBlockBottomRight,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ event );
}
m_selectedBlockTopLeft = wxGridNoCellCoords;
rowOrCol,
mouseEv.GetX() + GetRowLabelSize(),
mouseEv.GetY() + GetColLabelSize(),
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
m_selectedBlockTopLeft,
m_selectedBlockBottomRight,
true,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
pos.x,
pos.y,
false,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
mouseEv.GetX() + GetRowLabelSize(),
mouseEv.GetY() + GetColLabelSize(),
false,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
m_selection->SelectBlock(
m_selectedBlockTopLeft,
m_selectedBlockBottomRight,
- event.ControlDown(),
- true,
- event.AltDown(),
- event.MetaDown() );
+ event);
}
}
//
void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
{
- if ( !m_gridLinesEnabled || !m_numRows || !m_numCols )
+ if ( !m_gridLinesEnabled )
return;
int top, bottom, left, right;
CalcUnscrolledPosition( cw, ch, &right, &bottom );
// avoid drawing grid lines past the last row and col
- //
- right = wxMin( right, GetColRight(GetColAt( m_numCols - 1 )) );
- bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
+ if ( m_gridLinesClipHorz )
+ {
+ if ( !m_numCols )
+ return;
+
+ const int lastColRight = GetColRight(GetColAt(m_numCols - 1));
+ if ( right > lastColRight )
+ right = lastColRight;
+ }
+
+ if ( m_gridLinesClipVert )
+ {
+ if ( !m_numRows )
+ return;
+
+ const int lastRowBottom = GetRowBottom(m_numRows - 1);
+ if ( bottom > lastRowBottom )
+ bottom = lastRowBottom;
+ }
// no gridlines inside multicells, clip them out
int leftCol = GetColPos( internalXToCol(left) );
{
m_gridLineColour = colour;
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- DrawAllGridLines( dc, wxRegion() );
+ if ( GridLinesEnabled() )
+ RedrawGridLines();
}
}
}
}
+void wxGrid::RedrawGridLines()
+{
+ // the lines will be redrawn when the window is thawn
+ if ( GetBatchCount() )
+ return;
+
+ if ( GridLinesEnabled() )
+ {
+ wxClientDC dc( m_gridWin );
+ PrepareDC( dc );
+ DrawAllGridLines( dc, wxRegion() );
+ }
+ else // remove the grid lines
+ {
+ m_gridWin->Refresh();
+ }
+}
+
void wxGrid::EnableGridLines( bool enable )
{
if ( enable != m_gridLinesEnabled )
{
m_gridLinesEnabled = enable;
- if ( !GetBatchCount() )
- {
- if ( enable )
- {
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- DrawAllGridLines( dc, wxRegion() );
- }
- else
- {
- m_gridWin->Refresh();
- }
- }
+ RedrawGridLines();
+ }
+}
+
+void wxGrid::DoClipGridLines(bool& var, bool clip)
+{
+ if ( clip != var )
+ {
+ var = clip;
+
+ if ( GridLinesEnabled() )
+ RedrawGridLines();
}
}
void wxGrid::SelectRow( int row, bool addToSelected )
{
- if ( IsSelection() && !addToSelected )
+ if ( !m_selection )
+ return;
+
+ if ( !addToSelected )
ClearSelection();
- if ( m_selection )
- m_selection->SelectRow( row, false, addToSelected );
+ m_selection->SelectRow(row);
}
void wxGrid::SelectCol( int col, bool addToSelected )
{
- if ( IsSelection() && !addToSelected )
+ if ( !m_selection )
+ return;
+
+ if ( !addToSelected )
ClearSelection();
- if ( m_selection )
- m_selection->SelectCol( col, false, addToSelected );
+ m_selection->SelectCol(col);
}
-void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
- bool addToSelected )
+void wxGrid::SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol,
+ bool addToSelected)
{
- if ( IsSelection() && !addToSelected )
+ if ( !m_selection )
+ return;
+
+ if ( !addToSelected )
ClearSelection();
- if ( m_selection )
- m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol,
- false, addToSelected );
+ m_selection->SelectBlock(topRow, leftCol, bottomRow, rightCol);
}
void wxGrid::SelectAll()
wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj,
int row, int col, int x, int y, bool sel,
bool control, bool shift, bool alt, bool meta )
- : wxNotifyEvent( type, id )
+ : wxNotifyEvent( type, id ),
+ wxKeyboardState(control, shift, alt, meta)
{
- m_row = row;
- m_col = col;
- m_x = x;
- m_y = y;
- m_selecting = sel;
- m_control = control;
- m_shift = shift;
- m_alt = alt;
- m_meta = meta;
+ Init(row, col, x, y, sel);
SetEventObject(obj);
}
-
IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent, wxNotifyEvent )
wxGridSizeEvent::wxGridSizeEvent( int id, wxEventType type, wxObject* obj,
int rowOrCol, int x, int y,
bool control, bool shift, bool alt, bool meta )
- : wxNotifyEvent( type, id )
+ : wxNotifyEvent( type, id ),
+ wxKeyboardState(control, shift, alt, meta)
{
- m_rowOrCol = rowOrCol;
- m_x = x;
- m_y = y;
- m_control = control;
- m_shift = shift;
- m_alt = alt;
- m_meta = meta;
+ Init(rowOrCol, x, y);
SetEventObject(obj);
}
const wxGridCellCoords& bottomRight,
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;
- m_meta = meta;
+ : wxNotifyEvent( type, id ),
+ wxKeyboardState(control, shift, alt, meta)
+{
+ Init(topLeft, bottomRight, sel);
SetEventObject(obj);
}