class MyCustomRenderer: public wxDataViewCustomRenderer
{
public:
- MyCustomRenderer( wxDataViewCellMode mode, int alignment ) :
- wxDataViewCustomRenderer( wxString("long"), mode, alignment )
- { m_height = 25; }
+ MyCustomRenderer()
+ : wxDataViewCustomRenderer("string",
+ wxDATAVIEW_CELL_ACTIVATABLE,
+ wxALIGN_CENTER)
+ { }
- virtual bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
+ virtual bool Render( wxRect rect, wxDC *dc, int state )
{
- dc->SetBrush( *wxRED_BRUSH );
+ dc->SetBrush( *wxLIGHT_GREY_BRUSH );
dc->SetPen( *wxTRANSPARENT_PEN );
- dc->DrawRectangle( rect.Deflate(2) );
+
+ rect.Deflate(2);
+ dc->DrawRoundedRectangle( rect, 5 );
+
+ RenderText(m_value,
+ 0, // no offset
+ wxRect(dc->GetTextExtent(m_value)).CentreIn(rect),
+ dc,
+ state);
return true;
}
virtual wxSize GetSize() const
{
- //return wxSize(60,m_height);
return wxSize(60,20);
}
virtual bool SetValue( const wxVariant &value )
{
- m_height = value;
+ m_value = value.GetString();
return true;
}
virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
private:
- long m_height;
+ wxString m_value;
};
// column 5 of the view control:
- MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT );
+ MyCustomRenderer *cr = new MyCustomRenderer;
wxDataViewColumn *column5 =
new wxDataViewColumn( "custom", cr, 5, -1, wxALIGN_LEFT,
wxDATAVIEW_COL_RESIZABLE );
new wxDataViewTextRenderer,
MyListModel::Col_TextWithAttr)
);
+
+ m_ctrl[1]->AppendColumn(
+ new wxDataViewColumn("custom renderer",
+ new MyCustomRenderer,
+ MyListModel::Col_Custom)
+ );
}
break;
variant = node->m_quality;
break;
case 4:
- // wxMac doesn't conceal the popularity progress renderer, return 0 for containers
- if (IsContainer(item))
- variant = (long) 0;
- else
- variant = (long) 80; // all music is very 80% popular
+ variant = 80L; // all music is very 80% popular
break;
case 5:
- // Make size of red square depend on year
if (GetYear(item) < 1900)
- variant = (long) 35;
+ variant = "old";
else
- variant = (long) 25;
+ variant = "new";
break;
default:
}
break;
+ case Col_Custom:
+ variant = wxString::Format("%d", row % 100);
+ break;
+
case Col_Max:
wxFAIL_MSG( "invalid column" );
}
break;
case Col_TextWithAttr:
- // do what the labels defined above hint at
+ case Col_Custom:
+ // do what the labels defined in GetValueByRow() hint at
switch ( row % 5 )
{
case 0:
return true;
case Col_TextWithAttr:
+ case Col_Custom:
wxLogError("Cannot edit the column %d", col);
break;