Make generic wxDataViewProgressRenderer fill the entire cell.

After the fixes in the previous commit it is finally possibly to make the
progress renderer expand to the entire cell area instead of taking a
fixed width, it is enough to simply override RenderWithAttr() instead of
Render() and ignore the alignment as this avoids the use of (arbitrary and
hardcoded) wxDataViewProgressRenderer::GetSize().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-10-12 22:44:09 +00:00
parent a6f1201f97
commit 3e60a3c147
2 changed files with 39 additions and 22 deletions

View File

@@ -93,12 +93,23 @@ public:
// implementation // implementation
int CalculateAlignment() const; int CalculateAlignment() const;
protected:
// This is just a convenience for the derived classes overriding
// RenderWithAttr() to avoid repeating the same wxFAIL_MSG() in all of them
bool DummyRender(wxRect WXUNUSED(cell),
wxDC * WXUNUSED(dc),
int WXUNUSED(state))
{
wxFAIL_MSG("shouldn't be called at all, use RenderWithAttr() instead");
return false;
}
private: private:
wxDC *m_dc; wxDC *m_dc;
int m_align; int m_align;
wxDataViewCellMode m_mode; wxDataViewCellMode m_mode;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer) DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
}; };
@@ -149,12 +160,9 @@ public:
int align, int align,
const wxDataViewItemAttr *attr, const wxDataViewItemAttr *attr,
int state); int state);
virtual bool Render(wxRect WXUNUSED(cell), virtual bool Render(wxRect cell, wxDC *dc, int state)
wxDC * WXUNUSED(dc),
int WXUNUSED(state))
{ {
wxFAIL_MSG("only RenderWithAttr() should be called"); return DummyRender(cell, dc, state);
return false;
} }
wxSize GetSize() const; wxSize GetSize() const;
@@ -234,12 +242,19 @@ public:
const wxString &varianttype = wxT("long"), const wxString &varianttype = wxT("long"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT ); int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewProgressRenderer();
bool SetValue( const wxVariant &value ); bool SetValue( const wxVariant &value );
bool GetValue( wxVariant& value ) const; bool GetValue( wxVariant& value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state ); virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
virtual wxSize GetSize() const; virtual wxSize GetSize() const;
private: private:

View File

@@ -938,10 +938,6 @@ wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
m_value = 0; m_value = 0;
} }
wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
{
}
bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
{ {
m_value = (long) value; m_value = (long) value;
@@ -958,18 +954,24 @@ bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
return true; return true;
} }
bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) bool wxDataViewProgressRenderer::RenderWithAttr(wxDC& dc,
const wxRect& rect,
int WXUNUSED(align),
const wxDataViewItemAttr *attr,
int WXUNUSED(state))
{ {
double pct = (double)m_value / 100.0; // deflat the rect to leave a small border between bars in adjacent rows
wxRect bar = cell; wxRect bar = rect.Deflate(0, 1);
bar.width = (int)(cell.width * pct);
dc->SetPen( *wxTRANSPARENT_PEN );
dc->SetBrush( *wxBLUE_BRUSH );
dc->DrawRectangle( bar );
dc->SetBrush( *wxTRANSPARENT_BRUSH ); dc.SetBrush( *wxTRANSPARENT_BRUSH );
dc->SetPen( *wxBLACK_PEN ); dc.SetPen( *wxBLACK_PEN );
dc->DrawRectangle( cell ); dc.DrawRectangle( bar );
bar.width = (int)(bar.width * m_value / 100.);
dc.SetPen( *wxTRANSPARENT_PEN );
dc.SetBrush( attr && attr->HasColour() ? wxBrush(attr->GetColour())
: *wxBLUE_BRUSH );
dc.DrawRectangle( bar );
return true; return true;
} }