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.
This commit is contained in:
Konstantin S. Matveyev 2020-06-07 17:21:35 +02:00 committed by Vadim Zeitlin
parent 7338f30167
commit 1795ecdb78

View File

@ -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