class MyMusicModel: public wxDataViewModel
{
public:
+
+ // constructor
+
MyMusicModel()
{
m_idCounter = 0;
m_classicalMusicIsKnownToControl = false;
}
+ // helper methods to change the model
+
void AddToClassical( const wxString &title, const wxString &artist, const wxString &year )
{
// add to data
ItemAdded( parent, child );
}
}
+
+ void Delete( const wxDataViewItem &item )
+ {
+ MyMusicModelNode *node = FindNode( item );
+ node->GetParent()->GetChildren().Remove( node );
+ delete node;
+
+ // notify control
+ ItemDeleted( item );
+ }
+
+ // implementation of base class virtuals to define model
virtual unsigned int GetColumnCount() const
{
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnAdd(wxCommandEvent& event);
+ void OnDelete(wxCommandEvent& event);
private:
wxDataViewCtrl* m_dataview;
ID_EXIT = wxID_EXIT,
ID_ADD = 100,
+ ID_DELETE = 101,
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
EVT_MENU( ID_EXIT, MyFrame::OnQuit )
EVT_BUTTON( ID_ADD, MyFrame::OnAdd )
+ EVT_BUTTON( ID_DELETE, MyFrame::OnDelete )
END_EVENT_TABLE()
MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
button_sizer->Add( new wxButton( this, ID_ADD, "Add Mozart"), 0, wxALL, 10 );
+ button_sizer->Add( new wxButton( this, ID_DELETE, "Delete selected"), 0, wxALL, 10 );
main_sizer->Add( button_sizer, 0, 0, 0 );
Close(true);
}
-void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event) )
+void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event) )
{
-#if 0
- // ignore selection, do something better later
wxDataViewItem item = m_dataview->GetSelection();
if (item.IsOk())
- {
- if (m_model->HasChildren(item))
- {
- }
- else
- {
- }
- }
-#endif
-
+ m_model->Delete( item );
+}
+
+void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event) )
+{
m_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", "1787" );
}
GtkWxTreeModel* GetOwner() { return m_owner; }
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
+ bool ItemDeleted( const wxDataViewItem &item );
protected:
void InitTree();
return true;
}
+bool wxGtkTreeModel::ItemDeleted( const wxDataViewItem &item )
+{
+ wxGtkTreeModelNode *node = FindNode( item );
+ wxGtkTreeModelNode *parent = node->GetParent();
+ parent->GetChildren().Remove( node );
+ delete node;
+
+ return true;
+}
+
gboolean wxGtkTreeModel::get_iter( GtkTreeIter *iter, GtkTreePath *path )
{
int depth = gtk_tree_path_get_depth( path );
GTK_TREE_MODEL(m_wxgtk_model), path );
gtk_tree_path_free (path);
+ m_wxgtk_model->model->ItemDeleted( item );
+
return true;
}