Changing drag cursor in VirtualTreeView

c++builder, delphi, virtualtreeview

Solution

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;

Problem

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.

Original source