Add custom renderer column to the list model example in dataview sample.
Add a column using custom renderer to the example using a list model with attributes to test attributes support -- currently they are ignored, but this will be fixed soon. Also make the custom renderer display somewhat more clear as previously it didn't depend at all on its value. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62588 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -150,15 +150,25 @@ private:
|
|||||||
class MyCustomRenderer: public wxDataViewCustomRenderer
|
class MyCustomRenderer: public wxDataViewCustomRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCustomRenderer( wxDataViewCellMode mode, int alignment ) :
|
MyCustomRenderer()
|
||||||
wxDataViewCustomRenderer( wxString("long"), mode, alignment )
|
: wxDataViewCustomRenderer("string",
|
||||||
{ m_height = 25; }
|
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->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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,20 +192,19 @@ public:
|
|||||||
|
|
||||||
virtual wxSize GetSize() const
|
virtual wxSize GetSize() const
|
||||||
{
|
{
|
||||||
//return wxSize(60,m_height);
|
|
||||||
return wxSize(60,20);
|
return wxSize(60,20);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool SetValue( const wxVariant &value )
|
virtual bool SetValue( const wxVariant &value )
|
||||||
{
|
{
|
||||||
m_height = value;
|
m_value = value.GetString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
|
virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long m_height;
|
wxString m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -523,7 +532,7 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
|||||||
|
|
||||||
// column 5 of the view control:
|
// column 5 of the view control:
|
||||||
|
|
||||||
MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT );
|
MyCustomRenderer *cr = new MyCustomRenderer;
|
||||||
wxDataViewColumn *column5 =
|
wxDataViewColumn *column5 =
|
||||||
new wxDataViewColumn( "custom", cr, 5, -1, wxALIGN_LEFT,
|
new wxDataViewColumn( "custom", cr, 5, -1, wxALIGN_LEFT,
|
||||||
wxDATAVIEW_COL_RESIZABLE );
|
wxDATAVIEW_COL_RESIZABLE );
|
||||||
@@ -556,6 +565,12 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
|||||||
new wxDataViewTextRenderer,
|
new wxDataViewTextRenderer,
|
||||||
MyListModel::Col_TextWithAttr)
|
MyListModel::Col_TextWithAttr)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
m_ctrl[1]->AppendColumn(
|
||||||
|
new wxDataViewColumn("custom renderer",
|
||||||
|
new MyCustomRenderer,
|
||||||
|
MyListModel::Col_Custom)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -203,18 +203,13 @@ void MyMusicTreeModel::GetValue( wxVariant &variant,
|
|||||||
variant = node->m_quality;
|
variant = node->m_quality;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// wxMac doesn't conceal the popularity progress renderer, return 0 for containers
|
variant = 80L; // all music is very 80% popular
|
||||||
if (IsContainer(item))
|
|
||||||
variant = (long) 0;
|
|
||||||
else
|
|
||||||
variant = (long) 80; // all music is very 80% popular
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// Make size of red square depend on year
|
|
||||||
if (GetYear(item) < 1900)
|
if (GetYear(item) < 1900)
|
||||||
variant = (long) 35;
|
variant = "old";
|
||||||
else
|
else
|
||||||
variant = (long) 25;
|
variant = "new";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -436,6 +431,10 @@ void MyListModel::GetValueByRow( wxVariant &variant,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Col_Custom:
|
||||||
|
variant = wxString::Format("%d", row % 100);
|
||||||
|
break;
|
||||||
|
|
||||||
case Col_Max:
|
case Col_Max:
|
||||||
wxFAIL_MSG( "invalid column" );
|
wxFAIL_MSG( "invalid column" );
|
||||||
}
|
}
|
||||||
@@ -456,7 +455,8 @@ bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Col_TextWithAttr:
|
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 )
|
switch ( row % 5 )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -517,6 +517,7 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case Col_TextWithAttr:
|
case Col_TextWithAttr:
|
||||||
|
case Col_Custom:
|
||||||
wxLogError("Cannot edit the column %d", col);
|
wxLogError("Cannot edit the column %d", col);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -193,6 +193,7 @@ public:
|
|||||||
Col_EditableText,
|
Col_EditableText,
|
||||||
Col_IconText,
|
Col_IconText,
|
||||||
Col_TextWithAttr,
|
Col_TextWithAttr,
|
||||||
|
Col_Custom,
|
||||||
Col_Max
|
Col_Max
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user