Support or disable "insert" for drag/drop wxDataViewCtrl on OSX
see #18167
This commit is contained in:
		@@ -846,7 +846,8 @@ public:
 | 
			
		||||
        m_dataBuffer(event.m_dataBuffer),
 | 
			
		||||
        m_dataSize(event.m_dataSize),
 | 
			
		||||
        m_dragFlags(event.m_dragFlags),
 | 
			
		||||
        m_dropEffect(event.m_dropEffect)
 | 
			
		||||
        m_dropEffect(event.m_dropEffect),
 | 
			
		||||
        m_proposedDropIndex(event.m_proposedDropIndex)
 | 
			
		||||
#endif
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
@@ -889,6 +890,10 @@ public:
 | 
			
		||||
    int GetDragFlags() const { return m_dragFlags; }
 | 
			
		||||
    void SetDropEffect( wxDragResult effect ) { m_dropEffect = effect; }
 | 
			
		||||
    wxDragResult GetDropEffect() const { return m_dropEffect; }
 | 
			
		||||
    // for plaforms (currently only OSX) that support Drag/Drop insertion of items,
 | 
			
		||||
	// this is the proposed child index for the insertion
 | 
			
		||||
	void SetProposedDropIndex(int index) { m_proposedDropIndex = index; }
 | 
			
		||||
	int GetProposedDropIndex() const { return m_proposedDropIndex;}
 | 
			
		||||
#endif // wxUSE_DRAG_AND_DROP
 | 
			
		||||
 | 
			
		||||
    virtual wxEvent *Clone() const wxOVERRIDE { return new wxDataViewEvent(*this); }
 | 
			
		||||
@@ -928,6 +933,7 @@ protected:
 | 
			
		||||
 | 
			
		||||
    int                 m_dragFlags;
 | 
			
		||||
    wxDragResult        m_dropEffect;
 | 
			
		||||
    int                 m_proposedDropIndex;
 | 
			
		||||
#endif // wxUSE_DRAG_AND_DROP
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 
 | 
			
		||||
@@ -1683,6 +1683,7 @@ void wxDataViewEvent::Init(wxDataViewCtrlBase* dvc,
 | 
			
		||||
    m_dataSize = 0;
 | 
			
		||||
    m_dragFlags = 0;
 | 
			
		||||
    m_dropEffect = wxDragNone;
 | 
			
		||||
    m_proposedDropIndex = -1;
 | 
			
		||||
#endif // wxUSE_DRAG_AND_DROP
 | 
			
		||||
 | 
			
		||||
    SetEventObject(dvc);
 | 
			
		||||
 
 | 
			
		||||
@@ -539,9 +539,8 @@ outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
    item:(id)item childIndex:(NSInteger)index
 | 
			
		||||
{
 | 
			
		||||
    wxUnusedVar(outlineView);
 | 
			
		||||
    wxUnusedVar(index);
 | 
			
		||||
    
 | 
			
		||||
    return [self setupAndCallDataViewEvents:wxEVT_DATAVIEW_ITEM_DROP dropInfo:info item:item] != NSDragOperationNone;
 | 
			
		||||
    return [self setupAndCallDataViewEvents:wxEVT_DATAVIEW_ITEM_DROP dropInfo:info item:item proposedChildIndex:index] != NSDragOperationNone;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-(id) outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
@@ -680,10 +679,11 @@ outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
    wxUnusedVar(outlineView);
 | 
			
		||||
    wxUnusedVar(index);
 | 
			
		||||
 | 
			
		||||
    return [self setupAndCallDataViewEvents:wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE dropInfo:info item:item];
 | 
			
		||||
    return [self setupAndCallDataViewEvents:wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE dropInfo:info item:item proposedChildIndex:index];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-(NSDragOperation) callDataViewEvents:(wxEventType)eventType dataObjects:(wxDataObjectComposite*)dataObjects item:(id)item
 | 
			
		||||
                   proposedChildIndex:(NSInteger)index
 | 
			
		||||
{
 | 
			
		||||
    NSDragOperation dragOperation = NSDragOperationNone;
 | 
			
		||||
    wxDataViewCtrl* const dvc(implementation->GetDataViewCtrl());
 | 
			
		||||
@@ -693,7 +693,20 @@ outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
        // copy data into data object:
 | 
			
		||||
        event.SetDataObject(dataObjects);
 | 
			
		||||
        event.SetDataFormat(implementation->GetDnDDataFormat(dataObjects));
 | 
			
		||||
        event.SetDropEffect(wxDragCopy);
 | 
			
		||||
        event.SetProposedDropIndex(index);
 | 
			
		||||
        if (index == -1)
 | 
			
		||||
        {
 | 
			
		||||
            event.SetDropEffect(wxDragCopy);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            //if index is not -1, we're going to set the default
 | 
			
		||||
            //for the drop effect to None to be compatible with
 | 
			
		||||
            //the other wxPlatforms that don't support it.  In the
 | 
			
		||||
            //user code for for the event, they can set this to
 | 
			
		||||
            //copy/move or similar to support it.
 | 
			
		||||
            event.SetDropEffect(wxDragNone);
 | 
			
		||||
        }
 | 
			
		||||
        wxDataFormatId formatId = event.GetDataFormat().GetType();
 | 
			
		||||
        wxMemoryBuffer buffer;
 | 
			
		||||
        
 | 
			
		||||
@@ -745,6 +758,7 @@ outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-(NSDragOperation) setupAndCallDataViewEvents:(wxEventType)eventType dropInfo:(id<NSDraggingInfo>)info item:(id)item
 | 
			
		||||
                           proposedChildIndex:(NSInteger)index
 | 
			
		||||
{
 | 
			
		||||
    NSArray* supportedTypes(
 | 
			
		||||
                            [NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil]
 | 
			
		||||
@@ -774,7 +788,7 @@ outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
        {
 | 
			
		||||
            wxDataObjectComposite* dataObjects(implementation->GetDnDDataObjects((NSData*)[dataArray objectAtIndex:indexDraggedItem]));
 | 
			
		||||
            
 | 
			
		||||
            dragOperation = [self callDataViewEvents:eventType dataObjects:dataObjects item:item];
 | 
			
		||||
            dragOperation = [self callDataViewEvents:eventType dataObjects:dataObjects item:item proposedChildIndex:index];
 | 
			
		||||
            
 | 
			
		||||
            if ( dragOperation != NSDragOperationNone )
 | 
			
		||||
                ++indexDraggedItem;
 | 
			
		||||
@@ -806,7 +820,7 @@ outlineView:(NSOutlineView*)outlineView
 | 
			
		||||
            delete textDataObject;
 | 
			
		||||
        // send event if data could be copied:
 | 
			
		||||
        
 | 
			
		||||
        dragOperation = [self callDataViewEvents:eventType dataObjects:dataObjects item:item];
 | 
			
		||||
        dragOperation = [self callDataViewEvents:eventType dataObjects:dataObjects item:item proposedChildIndex:index];
 | 
			
		||||
 | 
			
		||||
        // clean up:
 | 
			
		||||
        ::CFRelease(osxData);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user