+void Playlist::OnDragItemBegin( wxTreeEvent& event )
+{
+ event.Allow();
+ draged_tree_item = event.GetItem();
+}
+
+void Playlist::OnDragItemEnd( wxTreeEvent& event )
+{
+ wxTreeItemId dest_tree_item = event.GetItem();
+
+ if( !dest_tree_item.IsOk() ) return;
+
+ /* check that we're not trying to move a node into one of its children */
+ wxTreeItemId parent = dest_tree_item;
+ while( parent != treectrl->GetRootItem() )
+ {
+ if( draged_tree_item == parent ) return;
+ parent = treectrl->GetItemParent( parent );
+ }
+
+ LockPlaylist( p_intf->p_sys, p_playlist );
+
+ PlaylistItem *p_wxdrageditem =
+ (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
+ PlaylistItem *p_wxdestitem =
+ (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
+ if( !p_wxdrageditem || !p_wxdestitem )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ return;
+ }
+
+ playlist_item_t *p_drageditem =
+ playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, true );
+ playlist_item_t *p_destitem =
+ playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, true );
+ if( !p_drageditem || !p_destitem )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ return;
+ }
+
+ if( p_destitem->i_children == -1 )
+ /* this is a leaf */
+ {
+ parent = treectrl->GetItemParent( dest_tree_item );
+ PlaylistItem *p_parent =
+ (PlaylistItem *)treectrl->GetItemData( parent );
+ if( !p_parent )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ return;
+ }
+ playlist_item_t *p_destitem2 =
+ playlist_ItemGetById( p_playlist, p_parent->i_id, true );
+ if( !p_destitem2 )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ return;
+ }
+ int i;
+ for( i = 0; i < p_destitem2->i_children; i++ )
+ {
+ if( p_destitem2->pp_children[i] == p_destitem ) break;
+ }
+ playlist_TreeMove( p_playlist, p_drageditem, p_destitem2, i );
+ }
+ else
+ /* this is a node */
+ {
+ playlist_TreeMove( p_playlist, p_drageditem, p_destitem, 0 );
+ }
+
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+
+ /* FIXME: having this Rebuild() is dirty */
+ Rebuild( true );
+}
+
+#if wxUSE_DRAG_AND_DROP
+PlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}
+
+/********************************************************************
+ * File Drag And Drop handling
+ ********************************************************************/
+bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
+ const wxArrayString& filenames )