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:
@@ -451,6 +451,8 @@ Major new features in this release
|
|||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
- Added wxFilePickerCtrl::SetInitialDirectory().
|
- Added wxFilePickerCtrl::SetInitialDirectory().
|
||||||
|
- Added wxDataViewItemAttr::SetBackgroundColour() and implemented it in generic
|
||||||
|
wxDataViewCtrl (Andrew Xu).
|
||||||
|
|
||||||
|
|
||||||
2.9.3: (released 2011-12-14)
|
2.9.3: (released 2011-12-14)
|
||||||
|
@@ -143,6 +143,7 @@ public:
|
|||||||
void SetColour(const wxColour& colour) { m_colour = colour; }
|
void SetColour(const wxColour& colour) { m_colour = colour; }
|
||||||
void SetBold( bool set ) { m_bold = set; }
|
void SetBold( bool set ) { m_bold = set; }
|
||||||
void SetItalic( bool set ) { m_italic = set; }
|
void SetItalic( bool set ) { m_italic = set; }
|
||||||
|
void SetBackgroundColour(const wxColour& colour) { m_bgColour = colour; }
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
bool HasColour() const { return m_colour.IsOk(); }
|
bool HasColour() const { return m_colour.IsOk(); }
|
||||||
@@ -152,7 +153,10 @@ public:
|
|||||||
bool GetBold() const { return m_bold; }
|
bool GetBold() const { return m_bold; }
|
||||||
bool GetItalic() const { return m_italic; }
|
bool GetItalic() const { return m_italic; }
|
||||||
|
|
||||||
bool IsDefault() const { return !(HasColour() || HasFont()); }
|
bool HasBackgroundColour() const { return m_bgColour.IsOk(); }
|
||||||
|
const wxColour& GetBackgroundColour() const { return m_bgColour; }
|
||||||
|
|
||||||
|
bool IsDefault() const { return !(HasColour() || HasFont() || HasBackgroundColour()); }
|
||||||
|
|
||||||
// Return the font based on the given one with this attribute applied to it.
|
// Return the font based on the given one with this attribute applied to it.
|
||||||
wxFont GetEffectiveFont(const wxFont& font) const;
|
wxFont GetEffectiveFont(const wxFont& font) const;
|
||||||
@@ -161,6 +165,7 @@ private:
|
|||||||
wxColour m_colour;
|
wxColour m_colour;
|
||||||
bool m_bold;
|
bool m_bold;
|
||||||
bool m_italic;
|
bool m_italic;
|
||||||
|
wxColour m_bgColour;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -290,6 +290,9 @@ public:
|
|||||||
// platform-specific classes.
|
// platform-specific classes.
|
||||||
virtual wxDC *GetDC() = 0;
|
virtual wxDC *GetDC() = 0;
|
||||||
|
|
||||||
|
// To draw background use the background colour in wxDataViewItemAttr
|
||||||
|
virtual void RenderBackground(wxDC* dc, const wxRect& rect);
|
||||||
|
|
||||||
// Prepare DC to use attributes and call Render().
|
// Prepare DC to use attributes and call Render().
|
||||||
void WXCallRender(wxRect rect, wxDC *dc, int state);
|
void WXCallRender(wxRect rect, wxDC *dc, int state);
|
||||||
|
|
||||||
|
@@ -580,6 +580,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void SetColour(const wxColour& colour);
|
void SetColour(const wxColour& colour);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Call this to set the background colour to use.
|
||||||
|
|
||||||
|
Currently this attribute is only supported in the generic version of
|
||||||
|
wxDataViewCtrl and ignored by the native GTK+ and OS X implementations.
|
||||||
|
|
||||||
|
@since 2.9.4
|
||||||
|
*/
|
||||||
|
void SetBackgroundColour(const wxColour& colour);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Call this to indicate that the item shall be displayed in italic text.
|
Call this to indicate that the item shall be displayed in italic text.
|
||||||
*/
|
*/
|
||||||
|
@@ -822,6 +822,18 @@ bool wxDataViewCustomRendererBase::ActivateCell(const wxRect& cell,
|
|||||||
return Activate(cell, model, item, col);
|
return Activate(cell, model, item, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDataViewCustomRendererBase::RenderBackground(wxDC* dc, const wxRect& rect)
|
||||||
|
{
|
||||||
|
if ( !m_attr.HasBackgroundColour() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
const wxColour& colour = m_attr.GetBackgroundColour();
|
||||||
|
wxDCPenChanger changePen(*dc, colour);
|
||||||
|
wxDCBrushChanger changeBrush(*dc, colour);
|
||||||
|
|
||||||
|
dc->DrawRectangle(rect);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
|
wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
|
||||||
{
|
{
|
||||||
|
@@ -712,6 +712,8 @@ private:
|
|||||||
|
|
||||||
wxDataViewColumn *FindColumnForEditing(const wxDataViewItem& item, wxDataViewCellMode mode);
|
wxDataViewColumn *FindColumnForEditing(const wxDataViewItem& item, wxDataViewCellMode mode);
|
||||||
|
|
||||||
|
void DrawCellBackground( wxDataViewRenderer* cell, wxDC& dc, const wxRect& rect );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewCtrl *m_owner;
|
wxDataViewCtrl *m_owner;
|
||||||
int m_lineHeight;
|
int m_lineHeight;
|
||||||
@@ -1935,6 +1937,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
cell_rect.y = GetLineStart( item );
|
cell_rect.y = GetLineStart( item );
|
||||||
cell_rect.height = GetLineHeight( 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
|
// deal with the expander
|
||||||
int indent = 0;
|
int indent = 0;
|
||||||
if ((!IsList()) && (col == expander))
|
if ((!IsList()) && (col == expander))
|
||||||
@@ -1988,7 +1995,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
int state = 0;
|
int state = 0;
|
||||||
if (m_hasFocus && (m_selection.Index(item) != wxNOT_FOUND))
|
if (m_hasFocus && selected)
|
||||||
state |= wxDATAVIEW_CELL_SELECTED;
|
state |= wxDATAVIEW_CELL_SELECTED;
|
||||||
|
|
||||||
// TODO: it would be much more efficient to create a clipping
|
// 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()
|
void wxDataViewMainWindow::OnRenameTimer()
|
||||||
{
|
{
|
||||||
// We have to call this here because changes may just have
|
// We have to call this here because changes may just have
|
||||||
|
Reference in New Issue
Block a user