Tidy up the previous commit slightly

Declare the variables just before using them (and also initialize them
at the same time); use more readable variable names; fix braces style
and add a comment explaining why do we do all this in the first place.

No real changes.
This commit is contained in:
Vadim Zeitlin
2017-12-10 19:18:57 +01:00
parent 57bdd372fb
commit c85da939e5

View File

@@ -2005,10 +2005,6 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
(int)(GetRowCount( ) - item_start)); (int)(GetRowCount( ) - item_start));
unsigned int item_last = item_start + item_count; unsigned int item_last = item_start + item_count;
unsigned int line_start = GetLineStart(item_start);
unsigned int cell_height;
unsigned int ty;
// Send the event to wxDataViewCtrl itself. // Send the event to wxDataViewCtrl itself.
wxDataViewEvent cache_event(wxEVT_DATAVIEW_CACHE_HINT, m_owner, NULL); wxDataViewEvent cache_event(wxEVT_DATAVIEW_CACHE_HINT, m_owner, NULL);
cache_event.SetCache(item_start, item_last - 1); cache_event.SetCache(item_start, item_last - 1);
@@ -2052,6 +2048,13 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
x_last += col->GetWidth(); x_last += col->GetWidth();
} }
// Instead of calling GetLineStart() for each line from the first to the
// last one, we will compute the starts of the lines as we iterate over
// them starting from this one, as this is much more efficient when using
// wxDV_VARIABLE_LINE_HEIGHT (and doesn't really change anything when not
// using it, so there is no need to use two different approaches).
const unsigned int first_line_start = GetLineStart(item_start);
// Draw background of alternate rows specially if required // Draw background of alternate rows specially if required
if ( m_owner->HasFlag(wxDV_ROW_LINES) ) if ( m_owner->HasFlag(wxDV_ROW_LINES) )
{ {
@@ -2074,18 +2077,15 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
// We only need to draw the visible part, so limit the rectangle to it. // We only need to draw the visible part, so limit the rectangle to it.
const int xRect = m_owner->CalcUnscrolledPosition(wxPoint(0, 0)).x; const int xRect = m_owner->CalcUnscrolledPosition(wxPoint(0, 0)).x;
const int widthRect = size.x; const int widthRect = size.x;
ty = line_start; unsigned int cur_line_start = first_line_start;
for (unsigned int item = item_start; item < item_last; item++) for (unsigned int item = item_start; item < item_last; item++)
{ {
cell_height = GetLineHeight(item); const int h = GetLineHeight(item);
if ( item % 2 ) if ( item % 2 )
{ {
dc.DrawRectangle(xRect, dc.DrawRectangle(xRect, cur_line_start, widthRect, h);
ty,
widthRect,
GetLineHeight(item));
} }
ty += cell_height; cur_line_start += h;
} }
} }
@@ -2095,12 +2095,12 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.SetPen(m_penRule); dc.SetPen(m_penRule);
dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxTRANSPARENT_BRUSH);
ty = line_start; unsigned int cur_line_start = first_line_start;
for (unsigned int i = item_start; i <= item_last; i++) for (unsigned int i = item_start; i <= item_last; i++)
{ {
cell_height = GetLineHeight(i); const int h = GetLineHeight(i);
dc.DrawLine(x_start, ty, x_last, ty); dc.DrawLine(x_start, cur_line_start, x_last, cur_line_start);
ty += cell_height; cur_line_start += h;
} }
} }
@@ -2125,22 +2125,22 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
x += col->GetWidth(); x += col->GetWidth();
dc.DrawLine(x, line_start, dc.DrawLine(x, first_line_start,
x, line_last); x, line_last);
} }
} }
// redraw the background for the items which are selected/current // redraw the background for the items which are selected/current
ty = line_start; unsigned int cur_line_start = first_line_start;
for (unsigned int item = item_start; item < item_last; item++) for (unsigned int item = item_start; item < item_last; item++)
{ {
bool selected = m_selection.IsSelected(item); bool selected = m_selection.IsSelected(item);
cell_height = GetLineHeight(item); const int line_height = GetLineHeight(item);
if (selected || item == m_currentRow) if (selected || item == m_currentRow)
{ {
wxRect rowRect( x_start, ty, wxRect rowRect( x_start, cur_line_start,
x_last - x_start, cell_height ); x_last - x_start, line_height );
bool renderColumnFocus = false; bool renderColumnFocus = false;
@@ -2239,7 +2239,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
); );
} }
} }
ty += cell_height; cur_line_start += line_height;
} }
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
@@ -2268,19 +2268,20 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
if ( col->IsHidden() || cell_rect.width <= 0 ) if ( col->IsHidden() || cell_rect.width <= 0 )
continue; // skip it! continue; // skip it!
cell_rect.y = line_start; cell_rect.y = first_line_start;
for (unsigned int item = item_start; item < item_last; item++) for (unsigned int item = item_start; item < item_last; item++)
{ {
// get the cell value and set it into the renderer // get the cell value and set it into the renderer
wxDataViewTreeNode *node = NULL; wxDataViewTreeNode *node = NULL;
wxDataViewItem dataitem; wxDataViewItem dataitem;
cell_height = GetLineHeight(item); const int line_height = GetLineHeight(item);
if (!IsVirtualList()) if (!IsVirtualList())
{ {
node = GetTreeNodeByRow(item); node = GetTreeNodeByRow(item);
if (node == NULL) { if (node == NULL)
cell_rect.y += cell_height; {
cell_rect.y += line_height;
continue; continue;
} }
@@ -2290,8 +2291,9 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
// column itself unless HasContainerColumns() overrides this. // column itself unless HasContainerColumns() overrides this.
if ( col != expander && if ( col != expander &&
model->IsContainer(dataitem) && model->IsContainer(dataitem) &&
!model->HasContainerColumns(dataitem) ) { !model->HasContainerColumns(dataitem) )
cell_rect.y += cell_height; {
cell_rect.y += line_height;
continue; continue;
} }
} }
@@ -2301,7 +2303,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
} }
// update cell_rect // update cell_rect
cell_rect.height = cell_height; cell_rect.height = line_height;
bool selected = m_selection.IsSelected(item); bool selected = m_selection.IsSelected(item);
@@ -2365,9 +2367,10 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
item_rect.x += indent; item_rect.x += indent;
item_rect.width -= indent; item_rect.width -= indent;
if ( item_rect.width <= 0 ) { if ( item_rect.width <= 0 )
cell_rect.y += cell_height; {
continue; cell_rect.y += line_height;
continue;
} }
// TODO: it would be much more efficient to create a clipping // TODO: it would be much more efficient to create a clipping
@@ -2381,7 +2384,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
cell->WXCallRender(item_rect, &dc, state); cell->WXCallRender(item_rect, &dc, state);
cell_rect.y += cell_height; cell_rect.y += line_height;
} }
cell_rect.x += cell_rect.width; cell_rect.x += cell_rect.width;