@@ -226,7 +226,6 @@ WAbstractItemView::WAbstractItemView()
226226 renderState_ (RenderState ::NeedRerender ),
227227 currentSortColumn_ (-1 ),
228228 dragEnabled_ (false),
229- dropsEnabled_ (false),
230229 selectionModel_ (new WItemSelectionModel ()),
231230 rowHeight_ (20 ),
232231 headerLineHeight_ (20 ),
@@ -575,10 +574,10 @@ void WAbstractItemView::dropEvent(const WDropEvent& e, const WModelIndex& index)
575574 * Here, we only handle standard drag&drop actions between abstract
576575 * item models.
577576 */
578- if (dropsEnabled_ ) {
577+ if (enabledDropLocations_ . test ( DropLocation :: OnItem ) ) {
579578 std ::vector < std ::string > acceptMimeTypes = model_ -> acceptDropMimeTypes ();
580579
581- for (unsigned i = 0 ; i < acceptMimeTypes .size (); ++ i )
580+ for (std :: size_t i = 0 ; i < acceptMimeTypes .size (); ++ i ) {
582581 if (acceptMimeTypes [i ] == e .mimeType ()) {
583582 // we define internal by sharing the same selection model...
584583 // currently selection models cannot be shared
@@ -587,15 +586,31 @@ void WAbstractItemView::dropEvent(const WDropEvent& e, const WModelIndex& index)
587586 DropAction action = internal ?
588587 DropAction ::Move : DropAction ::Copy ;
589588
590- // TODO: (later) we need to interpret the event location
591- // (e.mouseEvent().widget().y) For now we will implement to
592- // add as a sibling before the index
593589 model_ -> dropEvent (e , action ,
594590 index .row (), index .column (), index .parent ());
595591
596592 setSelectedIndexes (WModelIndexSet ());
597593 return ;
598594 }
595+ }
596+ }
597+
598+ WCompositeWidget ::dropEvent (e );
599+ }
600+
601+ void WAbstractItemView ::dropEvent (const WDropEvent & e , const WModelIndex & index , Side side )
602+ {
603+ if (enabledDropLocations_ .test (DropLocation ::BetweenRows )) {
604+ std ::vector < std ::string > acceptMimeTypes = model_ -> acceptDropMimeTypes ();
605+
606+ for (std ::size_t i = 0 ; i < acceptMimeTypes .size (); ++ i ) {
607+ if (acceptMimeTypes [i ] == e .mimeType ()) {
608+ model_ -> dropEvent (e , DropAction ::Move , index , side );
609+
610+ setSelectedIndexes (WModelIndexSet ());
611+ return ;
612+ }
613+ }
599614 }
600615
601616 WCompositeWidget ::dropEvent (e );
@@ -617,7 +632,7 @@ void WAbstractItemView::configureModelDragDrop()
617632 std ::vector < std ::string > acceptMimeTypes = model_ -> acceptDropMimeTypes ();
618633
619634 for (unsigned i = 0 ; i < acceptMimeTypes .size (); ++ i )
620- if (dropsEnabled_ )
635+ if (! enabledDropLocations_ . empty () )
621636 acceptDrops (acceptMimeTypes [i ], "Wt-drop-site" );
622637 else
623638 stopAcceptDrops (acceptMimeTypes [i ]);
@@ -626,11 +641,20 @@ void WAbstractItemView::configureModelDragDrop()
626641
627642void WAbstractItemView ::setDropsEnabled (bool enable )
628643{
629- if (dropsEnabled_ != enable ) {
630- dropsEnabled_ = enable ;
644+ if (enable )
645+ setEnabledDropLocations (DropLocation ::OnItem );
646+ else
647+ setEnabledDropLocations (None );
648+ }
631649
632- configureModelDragDrop ();
633- }
650+ void WAbstractItemView ::setEnabledDropLocations (WFlags < DropLocation > dropLocations ) {
651+ if (enabledDropLocations_ == dropLocations )
652+ return ;
653+
654+ enabledDropLocations_ = dropLocations ;
655+ configureModelDragDrop ();
656+
657+ scheduleRender ();
634658}
635659
636660void WAbstractItemView ::checkDragSelection ()
0 commit comments