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
All (GUI):
- Added wxFilePickerCtrl::SetInitialDirectory().
All (GUI):
- 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)
void SetColour(const wxColour& colour) { m_colour = colour; }
void SetBold( bool set ) { m_bold = set; }
void SetItalic( bool set ) { m_italic = set; }
void SetColour(const wxColour& colour) { m_colour = colour; }
void SetBold( bool set ) { m_bold = set; }
void SetItalic( bool set ) { m_italic = set; }
+ void SetBackgroundColour(const wxColour& colour) { m_bgColour = colour; }
// accessors
bool HasColour() const { return m_colour.IsOk(); }
// accessors
bool HasColour() const { return m_colour.IsOk(); }
bool GetBold() const { return m_bold; }
bool GetItalic() const { return m_italic; }
bool GetBold() const { return m_bold; }
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.
wxFont GetEffectiveFont(const wxFont& font) const;
// Return the font based on the given one with this attribute applied to it.
wxFont GetEffectiveFont(const wxFont& font) const;
wxColour m_colour;
bool m_bold;
bool m_italic;
wxColour m_colour;
bool m_bold;
bool m_italic;
// platform-specific classes.
virtual wxDC *GetDC() = 0;
// platform-specific classes.
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().
void WXCallRender(wxRect rect, wxDC *dc, int state);
// Prepare DC to use attributes and call Render().
void WXCallRender(wxRect rect, wxDC *dc, int state);
*/
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.
*/
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
wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
{
void
wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
{
wxDataViewColumn *FindColumnForEditing(const wxDataViewItem& item, wxDataViewCellMode mode);
wxDataViewColumn *FindColumnForEditing(const wxDataViewItem& item, wxDataViewCellMode mode);
+ void DrawCellBackground( wxDataViewRenderer* cell, wxDC& dc, const wxRect& rect );
+
private:
wxDataViewCtrl *m_owner;
int m_lineHeight;
private:
wxDataViewCtrl *m_owner;
int m_lineHeight;
cell_rect.y = GetLineStart( item );
cell_rect.height = GetLineHeight( item );
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))
// deal with the expander
int indent = 0;
if ((!IsList()) && (col == expander))
- 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
state |= wxDATAVIEW_CELL_SELECTED;
// TODO: it would be much more efficient to create a clipping
+
+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
void wxDataViewMainWindow::OnRenameTimer()
{
// We have to call this here because changes may just have