Changing the drag pointer in VirtualTreeView

When using the drag and drop operation, VirtualTreeView uses [doCopy,doMove] by default. The move operation is indicated by the arrow pointer with a small field, and the copy operation is indicated by the same pointer icon, but with the addition of [+].

By default, VT uses the copy operation, and if you press the modifier key ( SHIFT key), it changes the move operation, so remove the [+] pointer from the pointer.

This is what I need:

  • cancel the operation (by default it will move, the modifier key is pressed - copy) and, thus, vice versa, arrow pointer arrows
  • replace modifier key - CTRL instead of SHIFT
  • read in the event which of the two operations was performed, and start copying or moving.

Any pointers to the right are appreciated.

+4
source share
1 answer

More than modifying the modifier, you must change the operation you are about to perform in the OnDragOver event handler. So, to add the CTRL key as a modifier of the copy operation, you should write something like the following. The value of the Effect parameter set in this case also changes the drag cursor depending on the selected operation. Except that this value is passed to the OnDragDrop event, where you can determine what to do with the dropped source:

 procedure TForm1.VirtualStringTree1DragOver(Sender: TBaseVirtualTree; Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode; var Effect: Integer; var Accept: Boolean); begin Accept := True; if Shift = [ssCtrl] then Effect := DROPEFFECT_COPY; end; 

In the OnDragDrop event OnDragDrop you can determine the effect that was used:

 procedure TForm1.VirtualStringTree1DragDrop(Sender: TBaseVirtualTree; Source: TObject; DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode); begin case Effect of DROPEFFECT_COPY: ShowMessage('DROPEFFECT_COPY'); DROPEFFECT_MOVE: ShowMessage('DROPEFFECT_MOVE'); end; end; 
+5
source

Source: https://habr.com/ru/post/1441020/


All Articles