m_ctrl[1]->AssociateModel( m_list_model.get() );
// the various columns
- m_ctrl[1]->AppendTextColumn("editable string", 0, wxDATAVIEW_CELL_EDITABLE);
- m_ctrl[1]->AppendIconTextColumn("icon", 1, wxDATAVIEW_CELL_EDITABLE);
+ m_ctrl[1]->AppendTextColumn("editable string",
+ MyListModel::Col_EditableText,
+ wxDATAVIEW_CELL_EDITABLE);
+ m_ctrl[1]->AppendIconTextColumn("icon",
+ MyListModel::Col_IconText,
+ wxDATAVIEW_CELL_EDITABLE);
m_ctrl[1]->AppendColumn(
- new wxDataViewColumn("attributes", new wxDataViewTextRenderer, 2 ));
+ new wxDataViewColumn("attributes",
+ new wxDataViewTextRenderer,
+ MyListModel::Col_TextWithAttr)
+ );
}
break;
void MyListModel::GetValueByRow( wxVariant &variant,
unsigned int row, unsigned int col ) const
{
- if (col==0)
- {
- if (row >= m_textColValues.GetCount())
- variant = wxString::Format( "virtual row %d", row );
- else
- variant = m_textColValues[ row ];
- }
- else if (col==1)
+ switch ( col )
{
- wxString text;
- if ( row >= m_iconColValues.GetCount() )
- text = "virtual icon";
- else
- text = m_iconColValues[row];
+ case Col_EditableText:
+ if (row >= m_textColValues.GetCount())
+ variant = wxString::Format( "virtual row %d", row );
+ else
+ variant = m_textColValues[ row ];
+ break;
- variant << wxDataViewIconText(text, m_icon[row % 2]);
- }
- else if (col==2)
- {
- static const char *labels[5] =
- {
- "blue", "green", "red", "bold cyan", "default",
- };
+ case Col_IconText:
+ {
+ wxString text;
+ if ( row >= m_iconColValues.GetCount() )
+ text = "virtual icon";
+ else
+ text = m_iconColValues[row];
+
+ variant << wxDataViewIconText(text, m_icon[row % 2]);
+ }
+ break;
+
+ case Col_TextWithAttr:
+ {
+ static const char *labels[5] =
+ {
+ "blue", "green", "red", "bold cyan", "default",
+ };
+
+ variant = labels[row % 5];
+ }
+ break;
- variant = labels[row % 5];
+ case Col_Max:
+ wxFAIL_MSG( "invalid column" );
}
}
{
switch ( col )
{
- case 0:
+ case Col_EditableText:
return false;
- case 1:
+ case Col_IconText:
if ( !(row % 2) )
return false;
attr.SetColour(*wxLIGHT_GREY);
break;
- case 2:
+ case Col_TextWithAttr:
// do what the labels defined above hint at
switch ( row % 5 )
{
return false;
}
break;
+
+ case Col_Max:
+ wxFAIL_MSG( "invalid column" );
}
return true;
{
switch ( col )
{
- case 0:
- case 1:
+ case Col_EditableText:
+ case Col_IconText:
if (row >= m_textColValues.GetCount())
{
// the item is not in the range of the items
return false;
}
- if ( col == 0 )
+ if ( col == Col_EditableText )
{
m_textColValues[row] = variant.GetString();
}
- else // col == 1
+ else // col == Col_IconText
{
wxDataViewIconText iconText;
iconText << variant;
m_iconColValues[row] = iconText.GetText();
}
- break;
+ return true;
- default:
+ case Col_TextWithAttr:
wxLogError("Cannot edit the column %d", col);
- return false;
+ break;
+
+ case Col_Max:
+ wxFAIL_MSG( "invalid column" );
}
- return true;
+ return false;
}