+
+// ----------------------------------------------------------------------------
+// MyFrame - event handlers for the first page
+// ----------------------------------------------------------------------------
+
+void MyFrame::OnBeginDrag( wxDataViewEvent &event )
+{
+ wxDataViewItem item( event.GetItem() );
+
+ // only allow drags for item, not containers
+ if (m_music_model->IsContainer( item ) )
+ {
+ event.Veto();
+ return;
+ }
+
+ MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
+ wxTextDataObject *obj = new wxTextDataObject;
+ obj->SetText( node->m_title );
+ event.SetDataObject( obj );
+}
+
+void MyFrame::OnDropPossible( wxDataViewEvent &event )
+{
+ wxDataViewItem item( event.GetItem() );
+
+ // only allow drags for item, not containers
+ if (m_music_model->IsContainer( item ) )
+ event.Veto();
+
+ if (event.GetDataFormat() != wxDF_UNICODETEXT)
+ event.Veto();
+}
+
+void MyFrame::OnDrop( wxDataViewEvent &event )
+{
+ wxDataViewItem item( event.GetItem() );
+
+ // only allow drops for item, not containers
+ if (m_music_model->IsContainer( item ) )
+ {
+ event.Veto();
+ return;
+ }
+
+ if (event.GetDataFormat() != wxDF_UNICODETEXT)
+ {
+ event.Veto();
+ return;
+ }
+
+ wxTextDataObject obj;
+ obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() );
+
+ wxLogMessage( "Text dropped: %s", obj.GetText() );
+}
+
+void MyFrame::OnAddMozart( wxCommandEvent& WXUNUSED(event) )
+{
+ m_music_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", 1787 );
+}
+
+void MyFrame::OnDeleteMusic( wxCommandEvent& WXUNUSED(event) )
+{
+ wxDataViewItemArray items;
+ int len = m_ctrl[0]->GetSelections( items );
+ for( int i = 0; i < len; i ++ )
+ if (items[i].IsOk())
+ m_music_model->Delete( items[i] );
+}
+
+void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) )
+{
+ m_ctrl[0]->DeleteColumn( m_ctrl[0]->GetColumn( 2 ) );
+ FindWindow( ID_DELETE_YEAR )->Disable();
+}
+
+void MyFrame::OnSelectNinth( wxCommandEvent& WXUNUSED(event) )
+{
+ if (!m_music_model->GetNinthItem().IsOk())
+ {
+ wxLogError( "Cannot select the ninth symphony: it was removed!" );
+ return;
+ }
+
+ m_ctrl[0]->Select( m_music_model->GetNinthItem() );
+}
+
+void MyFrame::OnCollapse( wxCommandEvent& WXUNUSED(event) )
+{
+ wxDataViewItem item = m_ctrl[0]->GetSelection();
+ if (item.IsOk())
+ m_ctrl[0]->Collapse( item );
+}
+
+void MyFrame::OnExpand( wxCommandEvent& WXUNUSED(event) )
+{
+ wxDataViewItem item = m_ctrl[0]->GetSelection();
+ if (item.IsOk())
+ m_ctrl[0]->Expand( item );
+}
+
+void MyFrame::OnValueChanged( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %d; Column: %d",
+ event.GetItem().GetID(), event.GetColumn() );
+}
+
+void MyFrame::OnActivated( wxDataViewEvent &event )
+{
+ if(!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s", title );
+
+ if (m_ctrl[0]->IsExpanded( event.GetItem() ))
+ wxLogMessage( "Item: %s is expanded", title );
+}
+
+void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
+{
+ if(!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ if (title.empty())
+ title = "None";
+
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s", title );
+}
+
+void MyFrame::OnExpanding( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s", title );
+}
+
+
+void MyFrame::OnStartEditing( wxDataViewEvent &event )
+{
+ wxString artist = m_music_model->GetArtist( event.GetItem() );
+ if (artist == "Ludwig van Beethoven")
+ {
+ event.Veto();
+
+ if (!m_log)
+ return;
+
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING vetoed, Item: %s", artist );
+ }
+}
+
+void MyFrame::OnEditingStarted( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s", title );
+}
+
+void MyFrame::OnEditingDone( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s", title );
+}
+
+void MyFrame::OnExpanded( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s", title );
+}
+
+void MyFrame::OnCollapsing( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s", title );
+}
+
+void MyFrame::OnCollapsed( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title );
+}
+
+void MyFrame::OnContextMenu( wxDataViewEvent &event )
+{
+ if (!m_log)
+ return;
+
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s", title );
+
+ wxMenu menu;
+ menu.Append( 1, "menuitem 1" );
+ menu.Append( 2, "menuitem 2" );
+ menu.Append( 3, "menuitem 3" );
+
+ m_ctrl[0]->PopupMenu(&menu);
+}
+
+void MyFrame::OnHeaderClick( wxDataViewEvent &event )
+{
+ // we need to skip the event to let the default behaviour of sorting by
+ // this column when it is clicked to take place
+ event.Skip();
+
+ if (!m_log)
+ return;
+
+ int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
+ wxLogMessage( "Column width: %d", event.GetDataViewColumn()->GetWidth() );
+}
+
+void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
+{
+ if(!m_log)
+ return;
+
+ int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d", pos );
+}
+
+void MyFrame::OnSorted( wxDataViewEvent &event )
+{
+ if(!m_log)
+ return;
+
+ int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d", pos );
+}
+
+void MyFrame::OnRightClick( wxMouseEvent &event )
+{
+ if(!m_log)
+ return;
+
+ wxLogMessage( "wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d",
+ event.GetX(), event.GetY() );
+}
+
+
+// ----------------------------------------------------------------------------
+// MyFrame - event handlers for the second page
+// ----------------------------------------------------------------------------
+
+void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
+{
+ m_list_model->Prepend("Test");
+}
+
+void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
+{
+ wxDataViewItemArray items;
+ int len = m_ctrl[1]->GetSelections( items );
+ if (len > 0)
+ m_list_model->DeleteItems( items );
+}
+
+void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewItem item = m_list_model->GetItem( 50 );
+ m_ctrl[1]->EnsureVisible(item,m_col);
+}
+
+void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event))
+{
+ m_list_model->AddMany();
+}
+