From 5ed5803deb61011a8dd2e8c8cfc4557db5141a8b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 10 Dec 2021 19:34:54 +0000 Subject: [PATCH] Undo the now unnecessary change to the sample The previously working code should continue to work, so keep the original version now that it does work after the changes of the previous commit. Just mention in the comment that te data object can also be retrieved directly. --- samples/dataview/dataview.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index b679cf91c0..3e66aa0155 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -1430,20 +1430,26 @@ void MyFrame::OnDrop( wxDataViewEvent &event ) return; } - const wxTextDataObject* const obj = static_cast(event.GetDataObject()); + // Note that instead of recreating a new data object here we could also + // retrieve the data object from the event, using its GetDataObject() + // method. This would be more efficient as it would avoid copying the text + // one more time, but would require a cast in the code and we don't really + // care about efficiency here. + wxTextDataObject obj; + obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() ); if ( item.IsOk() ) { 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()); + obj.GetText(), m_music_model->GetTitle(item), event.GetProposedDropIndex()); } else - wxLogMessage("Text '%s' dropped on item '%s'", obj->GetText(), m_music_model->GetTitle(item)); + wxLogMessage("Text '%s' dropped on item '%s'", obj.GetText(), m_music_model->GetTitle(item)); } else - wxLogMessage("Text '%s' dropped on background (proposed index = %i)", obj->GetText(), event.GetProposedDropIndex()); + wxLogMessage("Text '%s' dropped on background (proposed index = %i)", obj.GetText(), event.GetProposedDropIndex()); } #endif // wxUSE_DRAG_AND_DROP