+
+// ----------------------------------------------------------------------------
+// MyFrame - event handlers for the first page
+// ----------------------------------------------------------------------------
+
+#if wxUSE_DRAG_AND_DROP
+
+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 );
+ event.SetDragFlags(wxDrag_AllowMove); // allows both copy and move
+}
+
+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() );
+}
+
+#endif // wxUSE_DRAG_AND_DROP
+
+void MyFrame::OnAddMozart( wxCommandEvent& WXUNUSED(event) )
+{
+ m_music_model->AddToClassical( "Eine kleine Nachtmusik", "Wolfgang Mozart", 1787 );
+}
+
+void MyFrame::DeleteSelectedItems()
+{
+ 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::OnDeleteSelected( wxCommandEvent& WXUNUSED(event) )
+{
+ DeleteSelectedItems();
+}
+
+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::OnShowCurrent(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewItem item = m_ctrl[0]->GetCurrentItem();
+ if ( item.IsOk() )
+ {
+ wxLogMessage("Current item: \"%s\" by %s",
+ m_music_model->GetTitle(item),
+ m_music_model->GetArtist(item));
+ }
+ else
+ {
+ wxLogMessage("There is no current item.");
+ }
+
+ wxDataViewColumn *col = m_ctrl[0]->GetCurrentColumn();
+ if ( col )
+ {
+ wxLogMessage("Current column: %d",
+ m_ctrl[0]->GetColumnPosition(col));
+ }
+ else
+ {
+ wxLogMessage("There is no current column.");
+ }
+}
+
+void MyFrame::OnSetNinthCurrent(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewItem item(m_music_model->GetNinthItem());
+ if ( !item.IsOk() )
+ {
+ wxLogError( "Cannot make the ninth symphony current: it was removed!" );
+ return;
+ }
+
+ m_ctrl[0]->SetCurrentItem(item);
+}
+
+void MyFrame::OnValueChanged( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %s; Column: %d",
+ title, event.GetColumn() );
+}
+
+void MyFrame::OnActivated( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_ACTIVATED, Item: %s", title );
+
+ if (m_ctrl[0]->IsExpanded( event.GetItem() ))
+ {
+ wxLogMessage( "Item: %s is expanded", title );
+ }
+}
+
+void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ if (title.empty())
+ title = "None";
+
+ wxLogMessage( "wxEVT_DATAVIEW_SELECTION_CHANGED, First selected Item: %s", title );
+}
+
+void MyFrame::OnExpanding( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_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();
+
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_START_EDITING vetoed. Artist: %s", artist );
+ }
+ else
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_START_EDITING not vetoed. Artist: %s", artist );
+
+}
+
+void MyFrame::OnEditingStarted( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_EDITING_STARTED, Item: %s", title );
+}
+
+void MyFrame::OnEditingDone( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_EDITING_DONE, Item: %s", title );
+}
+
+void MyFrame::OnExpanded( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_EXPANDED, Item: %s", title );
+}
+
+void MyFrame::OnCollapsing( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_COLLAPSING, Item: %s", title );
+}
+
+void MyFrame::OnCollapsed( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_DATAVIEW_ITEM_COLLAPSED, Item: %s", title );
+}
+
+void MyFrame::OnContextMenu( wxDataViewEvent &event )
+{
+ wxString title = m_music_model->GetTitle( event.GetItem() );
+ wxLogMessage( "wxEVT_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::OnAttrHeaderClick( 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();
+
+ int pos = m_ctrl[1]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
+ wxLogMessage( "Column title: %s Column width: %d", event.GetDataViewColumn()->GetTitle(), event.GetDataViewColumn()->GetWidth() );
+}
+
+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();
+
+ int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
+ wxLogMessage( "Column width: %d", event.GetDataViewColumn()->GetWidth() );
+}
+
+void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
+{
+ int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d", pos );
+}
+
+void MyFrame::OnSorted( wxDataViewEvent &event )
+{
+ int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
+
+ wxLogMessage( "wxEVT_DATAVIEW_COLUMN_SORTED, Column position: %d", pos );
+}
+
+void MyFrame::OnDataViewChar(wxKeyEvent& event)
+{
+ if ( event.GetKeyCode() == WXK_DELETE )
+ DeleteSelectedItems();
+ else
+ event.Skip();
+}
+
+// ----------------------------------------------------------------------------
+// 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();
+}
+
+void MyFrame::OnHideAttributes(wxCommandEvent& WXUNUSED(event))
+{
+ m_attributes->SetHidden(true);
+}
+
+void MyFrame::OnShowAttributes(wxCommandEvent& WXUNUSED(event))
+{
+ m_attributes->SetHidden(false);
+}
+
+// ----------------------------------------------------------------------------
+// MyFrame - event handlers for the fourth page
+// ----------------------------------------------------------------------------
+
+void MyFrame::OnDeleteTreeItem(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
+ wxDataViewItem selected = ctrl->GetSelection();
+ if (!selected.IsOk())
+ return;
+
+ ctrl->DeleteItem(selected);
+}
+
+void MyFrame::OnDeleteAllTreeItems(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
+ ctrl->DeleteAllItems();
+}
+
+void MyFrame::OnAddTreeItem(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
+ wxDataViewItem selected = ctrl->GetSelection();
+ if (ctrl->IsContainer(selected)) {
+ wxDataViewItem newitem = ctrl->AppendItem( selected, "Item", 0 );
+ ctrl->Select(newitem);
+ ctrl->EditItem(newitem, ctrl->GetColumn(0));
+ }
+}
+
+void MyFrame::OnAddTreeContainerItem(wxCommandEvent& WXUNUSED(event))
+{
+ wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
+ wxDataViewItem selected = ctrl->GetSelection();
+ if (ctrl->IsContainer(selected))
+ ctrl->AppendContainer(selected, "Container", 0 );
+}
+