Allow dropping data outside of item area in wxDataViewCtrl.

Implement this change for the generic and the native GTK versions and document
it.

Closes #16152.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76416 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-04-27 22:41:40 +00:00
parent 555e57912e
commit cbe6495307
5 changed files with 36 additions and 39 deletions

View File

@ -36,6 +36,7 @@ All (GUI):
- Add wxFD_NO_FOLLOW style for wxFileDialog (Luca Bacci).
- Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif).
- Add support for sorting wxDataViewCtrl by multiple columns (Trigve).
- Allow dropping data on wxDataViewCtrl background (Laurent Poujoulat).
- Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr).
- Add default ctor and Create() to wxContextHelpButton (Hanmac).
- Send events when toggling wxPropertyGrid nodes from keyboard (Armel Asselin).

View File

@ -3483,7 +3483,13 @@ public:
/**
Returns the item affected by the event.
Notice that for @c wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE and @c
wxEVT_DATAVIEW_ITEM_DROP event handlers, the item may be invalid,
indicating that the drop is about to happen outside of the item area.
*/
wxDataViewItem GetItem() const;
void SetItem( const wxDataViewItem &item );
void SetEditCanceled(bool editCancelled);

View File

@ -862,8 +862,8 @@ void MyFrame::OnDropPossible( wxDataViewEvent &event )
{
wxDataViewItem item( event.GetItem() );
// only allow drags for item, not containers
if (m_music_model->IsContainer( item ) )
// only allow drags for item or background, not containers
if ( item.IsOk() && m_music_model->IsContainer( item ) )
event.Veto();
if (event.GetDataFormat() != wxDF_UNICODETEXT)
@ -875,7 +875,7 @@ void MyFrame::OnDrop( wxDataViewEvent &event )
wxDataViewItem item( event.GetItem() );
// only allow drops for item, not containers
if (m_music_model->IsContainer( item ) )
if ( item.IsOk() && m_music_model->IsContainer( item ) )
{
event.Veto();
return;
@ -890,7 +890,10 @@ void MyFrame::OnDrop( wxDataViewEvent &event )
wxTextDataObject obj;
obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() );
wxLogMessage( "Text dropped: %s", obj.GetText() );
if ( item.IsOk() )
wxLogMessage( "Text dropped on item %s: %s", m_music_model->GetTitle( item ), obj.GetText() );
else
wxLogMessage( "Text dropped on background: %s", obj.GetText() );
}
#endif // wxUSE_DRAG_AND_DROP

View File

@ -1608,13 +1608,10 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x,
m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
unsigned int row = GetLineAt( yy );
if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
{
RemoveDropHint();
return wxDragNone;
}
wxDataViewItem item;
wxDataViewItem item = GetItemByRow( row );
if ( row < GetRowCount() && xx <= GetEndOfLastCol() )
item = GetItemByRow( row );
wxDataViewModel *model = GetModel();
@ -1624,25 +1621,25 @@ wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x,
event.SetModel( model );
event.SetDataFormat( format );
event.SetDropEffect( def );
if (!m_owner->HandleWindowEvent( event ))
if ( !m_owner->HandleWindowEvent( event ) || !event.IsAllowed() )
{
RemoveDropHint();
return wxDragNone;
}
if (!event.IsAllowed())
if ( item.IsOk() )
{
if (m_dropHint && (row != m_dropHintLine))
RefreshRow( m_dropHintLine );
m_dropHint = true;
m_dropHintLine = row;
RefreshRow( row );
}
else
{
RemoveDropHint();
return wxDragNone;
}
if (m_dropHint && (row != m_dropHintLine))
RefreshRow( m_dropHintLine );
m_dropHint = true;
m_dropHintLine = row;
RefreshRow( row );
return def;
}
@ -1655,10 +1652,10 @@ bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y )
m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
unsigned int row = GetLineAt( yy );
if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
return false;
wxDataViewItem item;
wxDataViewItem item = GetItemByRow( row );
if ( row < GetRowCount() && xx <= GetEndOfLastCol())
item = GetItemByRow( row );
wxDataViewModel *model = GetModel();
@ -1667,10 +1664,7 @@ bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y )
event.SetItem( item );
event.SetModel( model );
event.SetDataFormat( format );
if (!m_owner->HandleWindowEvent( event ))
return false;
if (!event.IsAllowed())
if (!m_owner->HandleWindowEvent( event ) || !event.IsAllowed())
return false;
return true;
@ -1684,10 +1678,10 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo
m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
unsigned int row = GetLineAt( yy );
if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
return wxDragNone;
wxDataViewItem item;
wxDataViewItem item = GetItemByRow( row );
if ( row < GetRowCount() && xx <= GetEndOfLastCol() )
item = GetItemByRow( row );
wxDataViewModel *model = GetModel();
@ -1701,10 +1695,7 @@ wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoo
event.SetDataSize( obj->GetSize() );
event.SetDataBuffer( obj->GetData() );
event.SetDropEffect( def );
if (!m_owner->HandleWindowEvent( event ))
return wxDragNone;
if (!event.IsAllowed())
if ( !m_owner->HandleWindowEvent( event ) || !event.IsAllowed() )
return wxDragNone;
return def;

View File

@ -3562,8 +3562,6 @@ wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest),
GtkSelectionData *selection_data)
{
wxDataViewItem item(GetOwner()->GTKPathToItem(path));
if ( !item )
return FALSE;
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP, m_owner->GetId() );
event.SetEventObject( m_owner );
@ -3587,8 +3585,6 @@ wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest),
GtkSelectionData *selection_data)
{
wxDataViewItem item(GetOwner()->GTKPathToItem(path));
if ( !item )
return FALSE;
wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
event.SetEventObject( m_owner );