Implement attributes support in generic wxDataViewIconTextRenderer.
Simply override RenderWithAttr() instead of Render(). Update the sample to show that this works now. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62395 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -275,12 +275,19 @@ public:
|
|||||||
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
|
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
|
||||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
int align = wxDVR_DEFAULT_ALIGNMENT );
|
int align = wxDVR_DEFAULT_ALIGNMENT );
|
||||||
virtual ~wxDataViewIconTextRenderer();
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
virtual bool HasEditorCtrl() const { return true; }
|
virtual bool HasEditorCtrl() const { return true; }
|
||||||
|
@@ -430,31 +430,42 @@ void MyListModel::GetValueByRow( wxVariant &variant,
|
|||||||
bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
|
bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
|
||||||
wxDataViewItemAttr &attr )
|
wxDataViewItemAttr &attr )
|
||||||
{
|
{
|
||||||
if (col != 2)
|
switch ( col )
|
||||||
return false;
|
|
||||||
|
|
||||||
// do what the labels defined above hint at
|
|
||||||
switch ( row % 5 )
|
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
attr.SetColour(*wxBLUE);
|
return false;
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
attr.SetColour(*wxGREEN);
|
if ( !(row % 2) )
|
||||||
|
return false;
|
||||||
|
attr.SetColour(*wxLIGHT_GREY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
attr.SetColour(*wxRED);
|
// do what the labels defined above hint at
|
||||||
break;
|
switch ( row % 5 )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
attr.SetColour(*wxBLUE);
|
||||||
|
break;
|
||||||
|
|
||||||
case 3:
|
case 1:
|
||||||
attr.SetColour(*wxCYAN);
|
attr.SetColour(*wxGREEN);
|
||||||
attr.SetBold(true);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
case 2:
|
||||||
return false;
|
attr.SetColour(*wxRED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
attr.SetColour(*wxCYAN);
|
||||||
|
attr.SetBold(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -1108,10 +1108,6 @@ const wxString &varianttype, wxDataViewCellMode mode, int align ) :
|
|||||||
SetAlignment(align);
|
SetAlignment(align);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
|
bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
|
||||||
{
|
{
|
||||||
m_value << value;
|
m_value << value;
|
||||||
@@ -1123,17 +1119,23 @@ bool wxDataViewIconTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
|
bool
|
||||||
|
wxDataViewIconTextRenderer::RenderWithAttr(wxDC& dc,
|
||||||
|
const wxRect& rect,
|
||||||
|
int align,
|
||||||
|
const wxDataViewItemAttr *attr,
|
||||||
|
int state)
|
||||||
{
|
{
|
||||||
int xoffset = 0;
|
int xoffset = 0;
|
||||||
const wxIcon &icon = m_value.GetIcon();
|
|
||||||
if (icon.IsOk())
|
const wxIcon& icon = m_value.GetIcon();
|
||||||
|
if ( icon.IsOk() )
|
||||||
{
|
{
|
||||||
dc->DrawIcon( icon, cell.x, cell.y + ((cell.height - icon.GetHeight()) / 2));
|
dc.DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetHeight())/2);
|
||||||
xoffset = icon.GetWidth()+4;
|
xoffset = icon.GetWidth()+4;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderText( m_value.GetText(), xoffset, cell, dc, state );
|
RenderText(dc, rect, align, m_value.GetText(), attr, state, xoffset);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user