Add wxGrid::RefreshBlock() helper
This simple function combines BlockToDeviceRect() and wxWindow::Refresh() calls and allows to avoid the ugly casts in wxGridSelection code as well as making the code slightly shorter and more clear. No real changes.
This commit is contained in:
committed by
Vadim Zeitlin
parent
cf3709147a
commit
00224e3f30
@@ -1112,6 +1112,11 @@ public:
|
||||
const wxArrayString& lines,
|
||||
long *width, long *height ) const;
|
||||
|
||||
void RefreshBlock(const wxGridCellCoords& topLeft,
|
||||
const wxGridCellCoords& bottomRight);
|
||||
|
||||
void RefreshBlock(int topRow, int leftCol,
|
||||
int bottomRow, int rightCol);
|
||||
|
||||
// ------
|
||||
// Code that does a lot of grid modification can be enclosed
|
||||
|
@@ -4913,6 +4913,22 @@ void wxGrid::Refresh(bool eraseb, const wxRect* rect)
|
||||
}
|
||||
}
|
||||
|
||||
void wxGrid::RefreshBlock(const wxGridCellCoords& topLeft,
|
||||
const wxGridCellCoords& bottomRight)
|
||||
{
|
||||
RefreshBlock(topLeft.GetRow(), topLeft.GetCol(),
|
||||
bottomRight.GetRow(), bottomRight.GetCol());
|
||||
}
|
||||
|
||||
void wxGrid::RefreshBlock(int topRow, int leftCol,
|
||||
int bottomRow, int rightCol)
|
||||
{
|
||||
const wxRect rect = BlockToDeviceRect(wxGridCellCoords(topRow, leftCol),
|
||||
wxGridCellCoords(bottomRow, rightCol));
|
||||
if ( !rect.IsEmpty() )
|
||||
m_gridWin->Refresh(false, &rect);
|
||||
}
|
||||
|
||||
void wxGrid::OnSize(wxSizeEvent& WXUNUSED(event))
|
||||
{
|
||||
if (m_targetWindow != this) // check whether initialisation has been done
|
||||
@@ -5317,10 +5333,7 @@ wxGrid::UpdateBlockBeingSelected(int topRow, int leftCol,
|
||||
if ( m_selectedBlockTopLeft == wxGridNoCellCoords ||
|
||||
m_selectedBlockBottomRight == wxGridNoCellCoords )
|
||||
{
|
||||
wxRect rect;
|
||||
rect = BlockToDeviceRect( wxGridCellCoords ( topRow, leftCol ),
|
||||
wxGridCellCoords ( bottomRow, rightCol ) );
|
||||
m_gridWin->Refresh( false, &rect );
|
||||
RefreshBlock(topRow, leftCol, bottomRow, rightCol);
|
||||
}
|
||||
|
||||
// Now handle changing an existing selection area.
|
||||
@@ -5330,13 +5343,6 @@ wxGrid::UpdateBlockBeingSelected(int topRow, int leftCol,
|
||||
// Compute two optimal update rectangles:
|
||||
// Either one rectangle is a real subset of the
|
||||
// other, or they are (almost) disjoint!
|
||||
wxRect rect[4];
|
||||
bool need_refresh[4];
|
||||
need_refresh[0] =
|
||||
need_refresh[1] =
|
||||
need_refresh[2] =
|
||||
need_refresh[3] = false;
|
||||
int i;
|
||||
|
||||
// Store intermediate values
|
||||
wxCoord oldLeft = m_selectedBlockTopLeft.GetCol();
|
||||
@@ -5358,46 +5364,29 @@ wxGrid::UpdateBlockBeingSelected(int topRow, int leftCol,
|
||||
{
|
||||
// Refresh the newly selected or deselected
|
||||
// area to the left of the old or new selection.
|
||||
need_refresh[0] = true;
|
||||
rect[0] = BlockToDeviceRect(
|
||||
wxGridCellCoords( oldTop, oldLeft ),
|
||||
wxGridCellCoords( oldBottom, leftCol - 1 ) );
|
||||
RefreshBlock(oldTop, oldLeft, oldBottom, leftCol - 1);
|
||||
}
|
||||
|
||||
if ( oldTop < topRow )
|
||||
{
|
||||
// Refresh the newly selected or deselected
|
||||
// area above the old or new selection.
|
||||
need_refresh[1] = true;
|
||||
rect[1] = BlockToDeviceRect(
|
||||
wxGridCellCoords( oldTop, leftCol ),
|
||||
wxGridCellCoords( topRow - 1, rightCol ) );
|
||||
RefreshBlock(oldTop, leftCol, topRow - 1, rightCol);
|
||||
}
|
||||
|
||||
if ( oldRight > rightCol )
|
||||
{
|
||||
// Refresh the newly selected or deselected
|
||||
// area to the right of the old or new selection.
|
||||
need_refresh[2] = true;
|
||||
rect[2] = BlockToDeviceRect(
|
||||
wxGridCellCoords( oldTop, rightCol + 1 ),
|
||||
wxGridCellCoords( oldBottom, oldRight ) );
|
||||
RefreshBlock(oldTop, rightCol + 1, oldBottom, oldRight);
|
||||
}
|
||||
|
||||
if ( oldBottom > bottomRow )
|
||||
{
|
||||
// Refresh the newly selected or deselected
|
||||
// area below the old or new selection.
|
||||
need_refresh[3] = true;
|
||||
rect[3] = BlockToDeviceRect(
|
||||
wxGridCellCoords( bottomRow + 1, leftCol ),
|
||||
wxGridCellCoords( oldBottom, rightCol ) );
|
||||
RefreshBlock(bottomRow + 1, leftCol, oldBottom, rightCol);
|
||||
}
|
||||
|
||||
// various Refresh() calls
|
||||
for (i = 0; i < 4; i++ )
|
||||
if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
|
||||
m_gridWin->Refresh( false, &(rect[i]) );
|
||||
}
|
||||
|
||||
// change selection
|
||||
@@ -9077,20 +9066,13 @@ wxArrayInt wxGrid::GetSelectedCols() const
|
||||
|
||||
void wxGrid::ClearSelection()
|
||||
{
|
||||
wxRect r1 = BlockToDeviceRect(m_selectedBlockTopLeft,
|
||||
m_selectedBlockBottomRight);
|
||||
wxRect r2 = BlockToDeviceRect(m_currentCellCoords,
|
||||
m_selectedBlockCorner);
|
||||
RefreshBlock(m_selectedBlockTopLeft, m_selectedBlockBottomRight);
|
||||
RefreshBlock(m_currentCellCoords, m_selectedBlockCorner);
|
||||
|
||||
m_selectedBlockTopLeft =
|
||||
m_selectedBlockBottomRight =
|
||||
m_selectedBlockCorner = wxGridNoCellCoords;
|
||||
|
||||
if ( !r1.IsEmpty() )
|
||||
RefreshRect(r1, false);
|
||||
if ( !r2.IsEmpty() )
|
||||
RefreshRect(r2, false);
|
||||
|
||||
if ( m_selection )
|
||||
m_selection->ClearSelection();
|
||||
}
|
||||
|
@@ -259,9 +259,7 @@ void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd)
|
||||
// Update View:
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
|
||||
wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(row, 0, row, m_grid->GetNumberCols() - 1);
|
||||
}
|
||||
|
||||
// Send Event
|
||||
@@ -353,9 +351,7 @@ void wxGridSelection::SelectCol(int col, const wxKeyboardState& kbd)
|
||||
// Update View:
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
|
||||
wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(0, col, m_grid->GetNumberRows() - 1, col);
|
||||
}
|
||||
|
||||
// Send Event
|
||||
@@ -572,9 +568,7 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol,
|
||||
// Update View:
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( topRow, leftCol ),
|
||||
wxGridCellCoords( bottomRow, rightCol ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(topRow, leftCol, bottomRow, rightCol);
|
||||
}
|
||||
|
||||
// Send Event, if not disabled.
|
||||
@@ -621,10 +615,7 @@ void wxGridSelection::SelectCell( int row, int col,
|
||||
// Update View:
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
wxRect r = m_grid->BlockToDeviceRect(
|
||||
selectedTopLeft,
|
||||
selectedBottomRight );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(selectedTopLeft, selectedBottomRight);
|
||||
}
|
||||
|
||||
// Send event
|
||||
@@ -674,8 +665,7 @@ wxGridSelection::ToggleCellSelection(int row, int col,
|
||||
m_cellSelection.RemoveAt(n);
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
wxRect r = m_grid->BlockToDeviceRect( coords, coords );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(coords, coords);
|
||||
}
|
||||
|
||||
// Send event
|
||||
@@ -810,10 +800,7 @@ wxGridSelection::ToggleCellSelection(int row, int col,
|
||||
{
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect(
|
||||
wxGridCellCoords( row, col ),
|
||||
wxGridCellCoords( row, col ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(row, col, row, col);
|
||||
}
|
||||
|
||||
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
|
||||
@@ -839,10 +826,7 @@ wxGridSelection::ToggleCellSelection(int row, int col,
|
||||
{
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect(
|
||||
wxGridCellCoords( row, colFrom ),
|
||||
wxGridCellCoords( row, colTo-1 ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(row, colFrom, row, colTo - 1);
|
||||
}
|
||||
|
||||
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
|
||||
@@ -872,10 +856,7 @@ wxGridSelection::ToggleCellSelection(int row, int col,
|
||||
{
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect(
|
||||
wxGridCellCoords( rowFrom, col ),
|
||||
wxGridCellCoords( rowTo - 1, col ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(rowFrom, col, rowTo - 1, col);
|
||||
}
|
||||
|
||||
wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
|
||||
@@ -911,8 +892,7 @@ void wxGridSelection::ClearSelection()
|
||||
m_cellSelection.RemoveAt(n);
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect( coords1, coords1 );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(coords1, coords1);
|
||||
|
||||
#ifdef __WXMAC__
|
||||
m_grid->UpdateGridWindows();
|
||||
@@ -931,8 +911,7 @@ void wxGridSelection::ClearSelection()
|
||||
m_blockSelectionBottomRight.RemoveAt(n);
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect( coords1, coords2 );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(coords1, coords2);
|
||||
|
||||
#ifdef __WXMAC__
|
||||
m_grid->UpdateGridWindows();
|
||||
@@ -950,9 +929,7 @@ void wxGridSelection::ClearSelection()
|
||||
m_rowSelection.RemoveAt(n);
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
|
||||
wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(row, 0, row, m_grid->GetNumberCols() - 1);
|
||||
|
||||
#ifdef __WXMAC__
|
||||
m_grid->UpdateGridWindows();
|
||||
@@ -971,9 +948,7 @@ void wxGridSelection::ClearSelection()
|
||||
m_colSelection.RemoveAt(n);
|
||||
if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
|
||||
wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
|
||||
((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
|
||||
m_grid->RefreshBlock(0, col, m_grid->GetNumberRows() - 1, col);
|
||||
|
||||
#ifdef __WXMAC__
|
||||
m_grid->UpdateGridWindows();
|
||||
|
Reference in New Issue
Block a user