4
votes

When using VirtualTreeView drag operation by default is [doCopy,doMove]. Move operation is indicated by arrow pointer with small box and Copy operation is indicated by same pointer icon but with added [+] next to it.

By default VT uses copy operation and if you press modifier key (SHIFT key) it modifies operation to move therefore removing the [+] from pointer.

Here is what I need:

  • reverse the operations (default would be move, with modifier key pressed - copy) and thus reverse pointer arrow too
  • replace modifier key - CTRL instead of SHIFT
  • read in an event which of the two operations occurred and start copy or move operation

Any pointers into right direction(s) appreciated.

1
Wait, by default VT uses move operation, doesn't it ? That + sign appears when you press Shift or am I wrong ?TLama
No, copy is default operation (which is logical for most but not all uses), that is why I want to reverse that. + sign disappears when you press Shift indicating operation is then move. Presence of + indicates copy operation.Coder12345
Then it's IMHO a bug (don't know about setting that would affect this behavior), but the Shift modifier should be used for copy operation. But it's pretty easy to modify (fix) the behavior to what you need by changing the drop effect in OnDragOver event (see below).TLama

1 Answers

5
votes

More than change a modifier, you should in the OnDragOver event handler change the operation you'll be going to perform. So, to add a CTRL key as a copy operation modifier you would write something like follows. The Effect parameter value set in this event also changes the drag cursor, depending on the chosen operation. Except that is that value passed to the OnDragDrop event, where you can according that 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 handler 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;