Add possibility to set item background in generic wxDataViewCtrl.

Added wxDataViewItemAttr::SetBackgroundColour() and code to honour it in the
generic implementation of wxDataViewCtrl.

Closes #12621.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70050 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-12-19 12:54:38 +00:00
parent 02106526ea
commit 1c959a62ce
6 changed files with 63 additions and 2 deletions

View File

@@ -712,6 +712,8 @@ private:
wxDataViewColumn *FindColumnForEditing(const wxDataViewItem& item, wxDataViewCellMode mode);
void DrawCellBackground( wxDataViewRenderer* cell, wxDC& dc, const wxRect& rect );
private:
wxDataViewCtrl *m_owner;
int m_lineHeight;
@@ -1935,6 +1937,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
cell_rect.y = GetLineStart( item );
cell_rect.height = GetLineHeight( item );
// draw the background
bool selected = m_selection.Index( item ) != wxNOT_FOUND;
if ( !selected )
DrawCellBackground( cell, dc, cell_rect );
// deal with the expander
int indent = 0;
if ((!IsList()) && (col == expander))
@@ -1988,7 +1995,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
continue;
int state = 0;
if (m_hasFocus && (m_selection.Index(item) != wxNOT_FOUND))
if (m_hasFocus && selected)
state |= wxDATAVIEW_CELL_SELECTED;
// TODO: it would be much more efficient to create a clipping
@@ -2007,6 +2014,28 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
}
}
void wxDataViewMainWindow::DrawCellBackground( wxDataViewRenderer* cell, wxDC& dc, const wxRect& rect )
{
wxRect rectBg( rect );
// don't overlap the horizontal rules
if ( m_owner->HasFlag(wxDV_HORIZ_RULES) )
{
rectBg.x++;
rectBg.width--;
}
// don't overlap the vertical rules
if ( m_owner->HasFlag(wxDV_VERT_RULES) )
{
rectBg.y++;
rectBg.height--;
}
cell->RenderBackground(&dc, rectBg);
}
void wxDataViewMainWindow::OnRenameTimer()
{
// We have to call this here because changes may just have