+ // third page of the notebook
+ // ---------------------------
+
+ wxPanel *thirdPanel = new wxPanel( m_notebook, wxID_ANY );
+
+ BuildDataViewCtrl(thirdPanel, 2); // sets m_ctrl[2]
+
+ wxSizer *thirdPanelSz = new wxBoxSizer( wxVERTICAL );
+ thirdPanelSz->Add(m_ctrl[2], 1, wxGROW|wxALL, 5);
+ thirdPanel->SetSizerAndFit(thirdPanelSz);
+
+
+ // fourth page of the notebook
+ // ---------------------------
+
+ wxPanel *fourthPanel = new wxPanel( m_notebook, wxID_ANY );
+
+ BuildDataViewCtrl(fourthPanel, 3); // sets m_ctrl[3]
+ // Buttons
+ wxBoxSizer *button_sizer4 = new wxBoxSizer( wxHORIZONTAL );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_DELETE_TREE_ITEM, "Delete Selected"), 0, wxALL, 10 );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_DELETE_ALL_TREE_ITEMS, "Delete All"), 0, wxALL, 10 );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_ADD_TREE_ITEM, "Add Item"), 0, wxALL, 10 );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_ADD_TREE_CONTAINER_ITEM, "Add Container"), 0, wxALL, 10 );
+
+ wxSizer *fourthPanelSz = new wxBoxSizer( wxVERTICAL );
+ fourthPanelSz->Add(m_ctrl[3], 1, wxGROW|wxALL, 5);
+ fourthPanelSz->Add(button_sizer4);
+ fourthPanel->SetSizerAndFit(fourthPanelSz);
+
+
+
+ // complete GUI
+ // ------------
+
+ m_notebook->AddPage(firstPanel, "MyMusicTreeModel");
+ m_notebook->AddPage(secondPanel, "MyListModel");
+ m_notebook->AddPage(thirdPanel, "wxDataViewListCtrl");
+ m_notebook->AddPage(fourthPanel, "wxDataViewTreeCtrl");
+
+ wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
+
+ mainSizer->Add( m_notebook, 1, wxGROW );
+ mainSizer->Add( m_log, 0, wxGROW );
+
+ SetSizerAndFit(mainSizer);
+}
+
+MyFrame::~MyFrame()
+{
+ delete wxLog::SetActiveTarget(m_logOld);
+}
+
+void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned long style)
+{
+ switch (nPanel)
+ {
+ case 0:
+ {
+ wxASSERT(!m_ctrl[0] && !m_music_model);
+ m_ctrl[0] =
+ new wxDataViewCtrl( parent, ID_MUSIC_CTRL, wxDefaultPosition,
+ wxDefaultSize, style );
+ m_ctrl[0]->Connect(wxEVT_CHAR,
+ wxKeyEventHandler(MyFrame::OnDataViewChar),
+ NULL, this);
+
+ m_music_model = new MyMusicTreeModel;
+ m_ctrl[0]->AssociateModel( m_music_model.get() );
+
+#if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
+ m_ctrl[0]->EnableDragSource( wxDF_UNICODETEXT );
+ m_ctrl[0]->EnableDropTarget( wxDF_UNICODETEXT );
+#endif // wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
+
+ // column 0 of the view control:
+
+ wxDataViewTextRenderer *tr =
+ new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_INERT );
+ wxDataViewColumn *column0 =
+ new wxDataViewColumn( "title", tr, 0, 200, wxALIGN_LEFT,
+ wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE );
+ m_ctrl[0]->AppendColumn( column0 );
+#if 0
+ // Call this and sorting is enabled
+ // immediatly upon start up.
+ column0->SetAsSortKey();
+#endif
+
+ // column 1 of the view control:
+
+ tr = new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_EDITABLE );
+ wxDataViewColumn *column1 =
+ new wxDataViewColumn( "artist", tr, 1, 150, wxALIGN_LEFT,
+ wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE |
+ wxDATAVIEW_COL_RESIZABLE );
+ column1->SetMinWidth(150); // this column can't be resized to be smaller
+ m_ctrl[0]->AppendColumn( column1 );
+
+ // column 2 of the view control:
+
+ 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;
+ 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, ID_ATTR_CTRL, wxDefaultPosition,
+ wxDefaultSize, style );
+
+ m_list_model = new MyListModel;
+ m_ctrl[1]->AssociateModel( m_list_model.get() );
+
+ // the various columns
+ m_ctrl[1]->AppendTextColumn("editable string",
+ MyListModel::Col_EditableText,
+ wxDATAVIEW_CELL_EDITABLE,
+ wxCOL_WIDTH_AUTOSIZE);
+ m_ctrl[1]->AppendIconTextColumn("icon",
+ MyListModel::Col_IconText,
+ wxDATAVIEW_CELL_EDITABLE,
+ wxCOL_WIDTH_AUTOSIZE);
+
+ m_attributes =
+ new wxDataViewColumn("attributes",
+ new wxDataViewTextRenderer,
+ MyListModel::Col_TextWithAttr,
+ wxCOL_WIDTH_AUTOSIZE,
+ wxALIGN_RIGHT,
+ wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
+ m_ctrl[1]->AppendColumn( m_attributes );
+
+ m_ctrl[1]->AppendColumn(
+ new wxDataViewColumn("custom renderer",
+ new MyCustomRenderer,
+ MyListModel::Col_Custom)
+ );
+ }
+ break;
+
+ case 2:
+ {
+ wxASSERT(!m_ctrl[2]);
+ wxDataViewListCtrl* lc =
+ new wxDataViewListCtrl( parent, wxID_ANY, wxDefaultPosition,
+ wxDefaultSize, style );
+ m_ctrl[2] = lc;
+
+ MyListStoreDerivedModel* page2_model = new MyListStoreDerivedModel();
+ lc->AssociateModel(page2_model);
+ page2_model->DecRef();
+
+ 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 | wxDV_NO_HEADER );
+ m_ctrl[3] = tc;
+
+ wxImageList *ilist = new wxImageList( 16, 16 );
+ ilist->Add( wxIcon(wx_small_xpm) );
+ tc->AssignImageList( 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;
+ }