Accept multiple data formats via drag-and-drop in wxDataViewCtrl
Allow specifying multiple formats to be accepted when dragging data to wxDataViewCtrl in the generic and Cocoa implementations. Add wxDataViewCtrlBase::EnableDropTarget() overload taking an array of wxDataFormats to support this at the API level. Add new DoEnableDropTarget() used by both EnableDropTarget() overloads and implement it in the generic and Cocoa ports. GTK implementation still uses only a single format, as before. Also refactor the Cocoa implementation: all operations using dragged data are now handled by wxDropTarget and unnecessary DataViewPboardType as removed. Update the dataview sample to show the new functionality.
This commit is contained in:
@@ -922,7 +922,6 @@ public:
|
||||
};
|
||||
|
||||
bool EnableDragSource( const wxDataFormat &format );
|
||||
bool EnableDropTarget( const wxDataFormat &format );
|
||||
|
||||
void RefreshDropHint();
|
||||
void RemoveDropHint();
|
||||
@@ -1032,8 +1031,6 @@ private:
|
||||
bool m_dragEnabled;
|
||||
wxDataFormat m_dragFormat;
|
||||
|
||||
bool m_dropEnabled;
|
||||
wxDataFormat m_dropFormat;
|
||||
DropItemInfo m_dropItemInfo;
|
||||
#endif // wxUSE_DRAG_AND_DROP
|
||||
|
||||
@@ -2076,7 +2073,6 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i
|
||||
m_dragStart = wxPoint(0,0);
|
||||
|
||||
m_dragEnabled = false;
|
||||
m_dropEnabled = false;
|
||||
m_dropItemInfo = DropItemInfo();
|
||||
#endif // wxUSE_DRAG_AND_DROP
|
||||
|
||||
@@ -2132,17 +2128,6 @@ bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat &format )
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat &format )
|
||||
{
|
||||
m_dropFormat = format;
|
||||
m_dropEnabled = format != wxDF_INVALID;
|
||||
|
||||
if (m_dropEnabled)
|
||||
SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format ), this ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxDataViewMainWindow::RefreshDropHint()
|
||||
{
|
||||
const unsigned row = m_dropItemInfo.m_row;
|
||||
@@ -2389,18 +2374,18 @@ bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y )
|
||||
return true;
|
||||
}
|
||||
|
||||
wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoord y,
|
||||
wxDragResult def )
|
||||
wxDragResult wxDataViewMainWindow::OnData(wxDataFormat format, wxCoord x, wxCoord y,
|
||||
wxDragResult def)
|
||||
{
|
||||
DropItemInfo dropItemInfo = GetDropItemInfo(x, y);
|
||||
|
||||
wxCustomDataObject *obj = (wxCustomDataObject *) GetDropTarget()->GetDataObject();
|
||||
wxDataObjectComposite *obj = static_cast<wxDataObjectComposite*>(GetDropTarget()->GetDataObject());
|
||||
|
||||
wxDataViewEvent event(wxEVT_DATAVIEW_ITEM_DROP, m_owner, dropItemInfo.m_item);
|
||||
event.SetProposedDropIndex(dropItemInfo.m_proposedDropIndex);
|
||||
event.SetDataFormat( format );
|
||||
event.SetDataSize( obj->GetSize() );
|
||||
event.SetDataBuffer( obj->GetData() );
|
||||
event.SetDataSize(obj->GetDataSize(format));
|
||||
event.SetDataObject(obj->GetObject(format));
|
||||
event.SetDropEffect( def );
|
||||
if ( !m_owner->HandleWindowEvent( event ) || !event.IsAllowed() )
|
||||
return wxDragNone;
|
||||
@@ -5816,9 +5801,17 @@ bool wxDataViewCtrl::EnableDragSource( const wxDataFormat &format )
|
||||
return m_clientArea->EnableDragSource( format );
|
||||
}
|
||||
|
||||
bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat &format )
|
||||
bool wxDataViewCtrl::DoEnableDropTarget( const wxDataFormatArray &formats )
|
||||
{
|
||||
return m_clientArea->EnableDropTarget( format );
|
||||
wxDataViewDropTarget* dt = NULL;
|
||||
if (wxDataObject* dataObject = CreateDataObject(formats))
|
||||
{
|
||||
dt = new wxDataViewDropTarget(dataObject, m_clientArea);
|
||||
}
|
||||
|
||||
m_clientArea->SetDropTarget(dt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_DRAG_AND_DROP
|
||||
|
||||
Reference in New Issue
Block a user