+ wxDataViewSpinRenderer *sr =
+ new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
+ wxDataViewColumn *column2 =
+ new wxDataViewColumn( "year", sr, 2, 60, wxALIGN_LEFT,
+ wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE );
+ m_ctrl[0]->AppendColumn( column2 );
+
+ // column 3 of the view control:
+
+ wxArrayString choices;
+ choices.Add( "good" );
+ choices.Add( "bad" );
+ choices.Add( "lousy" );
+ wxDataViewChoiceRenderer *c =
+ new wxDataViewChoiceRenderer( choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
+ wxDataViewColumn *column3 =
+ new wxDataViewColumn( "rating", c, 3, 100, wxALIGN_LEFT,
+ wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
+ m_ctrl[0]->AppendColumn( column3 );
+
+ // column 4 of the view control:
+
+ m_ctrl[0]->AppendProgressColumn( "popularity", 4, wxDATAVIEW_CELL_INERT, 80 );
+
+ // column 5 of the view control:
+
+ MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT );
+ wxDataViewColumn *column5 =
+ new wxDataViewColumn( "custom", cr, 5, -1, wxALIGN_LEFT,
+ wxDATAVIEW_COL_RESIZABLE );
+ m_ctrl[0]->AppendColumn( column5 );
+
+
+ // select initially the ninth symphony:
+ m_ctrl[0]->Select(m_music_model->GetNinthItem());
+ }
+ break;
+
+ case 1:
+ {
+ wxASSERT(!m_ctrl[1] && !m_list_model);
+ m_ctrl[1] = new wxDataViewCtrl( parent, wxID_ANY, wxDefaultPosition,
+ wxDefaultSize, style );
+
+ m_list_model = new MyListModel;
+ m_ctrl[1]->AssociateModel( m_list_model.get() );
+
+ // the various columns
+#if 1
+ m_ctrl[1]->AppendTextColumn("editable string", 0, wxDATAVIEW_CELL_EDITABLE, 120);
+ m_ctrl[1]->AppendIconTextColumn(wxIcon(wx_small_xpm), 1, wxDATAVIEW_CELL_INERT )->SetTitle( "icon");
+#else
+ m_ctrl[1]->AppendTextColumn("editable string", 0, wxDATAVIEW_CELL_EDITABLE);
+ m_ctrl[1]->AppendIconTextColumn("icon", 1, wxDATAVIEW_CELL_INERT);
+#endif
+ m_ctrl[1]->AppendColumn(
+ new wxDataViewColumn("attributes", new wxDataViewTextRendererAttr, 2 ));
+ }
+ break;
+
+ case 2:
+ {
+ wxASSERT(!m_ctrl[2]);
+ wxDataViewListCtrl* lc =
+ new wxDataViewListCtrl( parent, wxID_ANY, wxDefaultPosition,
+ wxDefaultSize, style );
+ m_ctrl[2] = lc;
+
+ lc->AppendToggleColumn( "Toggle" );
+ lc->AppendTextColumn( "Text" );
+ lc->AppendProgressColumn( "Progress" );
+
+ wxVector<wxVariant> data;
+ for (unsigned int i=0; i<10; i++)
+ {
+ data.clear();
+ data.push_back( (i%3) == 0 );
+ data.push_back( wxString::Format("row %d", i) );
+ data.push_back( long(5*i) );
+
+ lc->AppendItem( data );
+ }
+ }
+ break;
+
+ case 3:
+ {
+ wxASSERT(!m_ctrl[3]);
+ wxDataViewTreeCtrl* tc =
+ new wxDataViewTreeCtrl( parent, wxID_ANY, wxDefaultPosition,
+ wxDefaultSize, style );
+ m_ctrl[3] = tc;
+
+ wxImageList *ilist = new wxImageList( 16, 16 );
+ ilist->Add( wxIcon(wx_small_xpm) );
+ tc->SetImageList( ilist );
+
+ wxDataViewItem parent =
+ tc->AppendContainer( wxDataViewItem(0), "The Root", 0 );
+ tc->AppendItem( parent, "Child 1", 0 );
+ tc->AppendItem( parent, "Child 2", 0 );
+ tc->AppendItem( parent, "Child 3, very long, long, long, long", 0 );
+
+ wxDataViewItem cont =
+ tc->AppendContainer( parent, "Container child", 0 );
+ tc->AppendItem( cont, "Child 4", 0 );
+ tc->AppendItem( cont, "Child 5", 0 );
+
+ tc->Expand(cont);
+ }
+ break;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+// MyFrame - generic event handlers
+// ----------------------------------------------------------------------------
+
+void MyFrame::OnClearLog( wxCommandEvent& WXUNUSED(event) )
+{
+ m_log->Clear();
+}
+
+void MyFrame::OnPageChanged( wxBookCtrlEvent& WXUNUSED(event) )
+{
+ unsigned int nPanel = m_notebook->GetSelection();
+
+ GetMenuBar()->FindItem(ID_STYLE_MENU)->SetItemLabel(
+ wxString::Format("Style of panel #%d", nPanel+1));
+
+ for (unsigned int id = ID_MULTIPLE; id <= ID_VERT_RULES; id++)
+ {
+ unsigned long style = 0;
+ switch (id)
+ {
+ /*case ID_SINGLE:
+ style = wxDV_SINGLE;
+ break;*/
+ case ID_MULTIPLE:
+ style = wxDV_MULTIPLE;
+ break;
+ case ID_ROW_LINES:
+ style = wxDV_ROW_LINES;
+ break;
+ case ID_HORIZ_RULES:
+ style = wxDV_HORIZ_RULES;
+ break;
+ case ID_VERT_RULES:
+ style = wxDV_VERT_RULES;
+ break;
+ default:
+ wxFAIL;
+ }
+
+ GetMenuBar()->FindItem(id)->Check( m_ctrl[nPanel]->HasFlag(style) );
+ }
+}
+
+void MyFrame::OnStyleChange( wxCommandEvent& WXUNUSED(event) )
+{
+ unsigned int nPanel = m_notebook->GetSelection();
+
+ // build the style
+ unsigned long style = 0;
+ /*if (GetMenuBar()->FindItem(ID_SINGLE)->IsChecked())
+ style |= wxDV_SINGLE;*/
+ if (GetMenuBar()->FindItem(ID_MULTIPLE)->IsChecked())
+ style |= wxDV_MULTIPLE;
+ if (GetMenuBar()->FindItem(ID_ROW_LINES)->IsChecked())
+ style |= wxDV_ROW_LINES;
+ if (GetMenuBar()->FindItem(ID_HORIZ_RULES)->IsChecked())
+ style |= wxDV_HORIZ_RULES;
+ if (GetMenuBar()->FindItem(ID_VERT_RULES)->IsChecked())
+ style |= wxDV_VERT_RULES;
+
+ wxSizer* sz = m_ctrl[nPanel]->GetContainingSizer();
+ wxASSERT(sz);
+
+ sz->Detach(m_ctrl[nPanel]);
+ wxDELETE(m_ctrl[nPanel]);
+ m_ctrl[nPanel] = NULL;
+
+ if (nPanel == 0)
+ m_music_model.reset(NULL);
+ else if (nPanel == 1)
+ m_list_model.reset(NULL);
+
+ // rebuild the DVC for the selected panel:
+ BuildDataViewCtrl((wxPanel*)m_notebook->GetPage(nPanel), nPanel, style);
+
+ sz->Prepend(m_ctrl[nPanel], 1, wxGROW|wxALL, 5);
+ sz->Layout();