From 1795ecdb780a11279d5de4ed6c343124f4bcee71 Mon Sep 17 00:00:00 2001 From: "Konstantin S. Matveyev" Date: Sun, 7 Jun 2020 17:21:35 +0200 Subject: [PATCH] Show the proposed drop index in the dataview sample This allows to check interactively that the proposed index is set correctly depending on the drop position. --- samples/dataview/dataview.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index c959eb5f52..e80295515c 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -1278,27 +1278,16 @@ void MyFrame::OnBeginDrag( wxDataViewEvent &event ) void MyFrame::OnDropPossible( wxDataViewEvent &event ) { - wxDataViewItem item( event.GetItem() ); - - // only allow drags for item or background, not containers - if ( item.IsOk() && m_music_model->IsContainer( item ) ) - event.Veto(); - if (event.GetDataFormat() != wxDF_UNICODETEXT) event.Veto(); + else + event.SetDropEffect(wxDragMove); // check 'move' drop effect } void MyFrame::OnDrop( wxDataViewEvent &event ) { wxDataViewItem item( event.GetItem() ); - // only allow drops for item, not containers - if ( item.IsOk() && m_music_model->IsContainer( item ) ) - { - event.Veto(); - return; - } - if (event.GetDataFormat() != wxDF_UNICODETEXT) { event.Veto(); @@ -1309,9 +1298,17 @@ void MyFrame::OnDrop( wxDataViewEvent &event ) obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() ); if ( item.IsOk() ) - wxLogMessage( "Text dropped on item %s: %s", m_music_model->GetTitle( item ), obj.GetText() ); + { + if (m_music_model->IsContainer(item)) + { + wxLogMessage("Text '%s' dropped in container '%s' (proposed index = %i)", + obj.GetText(), m_music_model->GetTitle(item), event.GetProposedDropIndex()); + } + else + wxLogMessage("Text '%s' dropped on item '%s'", obj.GetText(), m_music_model->GetTitle(item)); + } else - wxLogMessage( "Text dropped on background: %s", obj.GetText() ); + wxLogMessage("Text '%s' dropped on background (proposed index = %i)", obj.GetText(), event.GetProposedDropIndex()); } #endif // wxUSE_DRAG_AND_DROP