Lazarus

Programming => LCL => Topic started by: grl on May 24, 2020, 07:38:39 pm

Title: Cursor always crNoDrop during drag&drop
Post by: grl on May 24, 2020, 07:38:39 pm
Hi!

I have two TDBGrids and want to drag something from one grid to the other.
DragMode is set to dmManual everywhere, in the OnMouseDown-event of the source-grid I use BeginDrag(false);
In the target-grid the OnDragOver-event Accept is set to true, in the OnDragDrop-event the wanted steps are done to actually change the data in the grids.

So everything works as expected besides one thing:
When dragging the mouse cursor is always crNoDrop indicating that I can't drop here. But I'd prefer so show the user that a drop is actually possible here be changing the cursor to crDrag when hovering over the target-grid.

What do I do wrong?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.dbgSourceMouseDown(Sender: TObject;
  2.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   if Button=mbLeft then begin
  5.     dbgSource.BeginDrag(false);
  6.   end;
  7. end;
  8.  
  9. procedure TForm1.dbgTargetDragOver(Sender, Source: TObject;
  10.   X, Y: Integer; State: TDragState; var Accept: Boolean);
  11. begin
  12.   Accept:=True;
  13. end;
  14.  
  15. procedure TForm1.dbgTargetDragDrop(Sender, Source: TObject;
  16.   X, Y: Integer);
  17. begin
  18.   // do something which works as expeceted
  19. end;
  20.  

FPC 3.0.4, Lazarus 2.0.8, OS Debian Buster X64, gtk2


regards
Lukas
Title: Re: Cursor always crNoDrop during drag&drop
Post by: howardpc on May 24, 2020, 07:43:39 pm
Does setting DragMode to dmAutomatic make a difference?
Title: Re: Cursor always crNoDrop during drag&drop
Post by: grl on May 24, 2020, 11:04:13 pm
Nope.
Tried setting one of the two to dmAutomatic and both.

No change.

Lukas
Title: Re: Cursor always crNoDrop during drag&drop
Post by: Jurassic Pork on May 25, 2020, 01:45:14 am
hello,
have you other controls on your form (panel, pagecontrol ... ) ?
I have tried your code on Centos 8 Lazarus 2.0.8 gtk2 with a form with two tdbgrid inside. It works ! crDrag on Target.
Friendly, J.P
Title: Re: Cursor always crNoDrop during drag&drop
Post by: jamie on May 25, 2020, 03:06:03 am
How about this

BeginDrag(True);

?
Title: Re: Cursor always crNoDrop during drag&drop
Post by: grl on May 27, 2020, 12:40:14 pm
Tried setting BeginDrag(True), tried using Lazarus 2.1.0 trunk...

Still the same - the cursor does not change.

There is a third TDBGrid and some buttons on the form, was well as some TUniQueries and Datasources, but no Panels or pagecontrols...

Still no idea what might be the problem.

Lukas
Title: Re: Cursor always crNoDrop during drag&drop
Post by: jamie on May 27, 2020, 12:57:42 pm
BeginDrag isn't enough...

The OnStartDrag event gets triggered and you must answer "Accenpt := true"

Also, while dragging over other components, the OnDragOver event gets triggered for each component you drag over. In that event you answer Accept := True if. This will adjust the drag cursor as you go over.

 Also, are you creating a TDragObject on the initial start or are you just using the simplistic built in method ?
Title: Re: Cursor always crNoDrop during drag&drop
Post by: wp on May 27, 2020, 01:25:57 pm
Your code in the first post looks correct. Just to make sure I wrote the simple demo project attached where cells can be dropped from the top grid onto the bottom grid or on the "accept label", but not on the "not accept label". On Windows, the cursor changes as expected when the drop operation is allowed. Then I tried on Linux Mint/gtk2 and, indeed, I can confirm the behavior that you describe: the drag&drop process itself works, but the cursor is not updated when the drop is allowed. Finally I activated compilation for qt widgetset, and here again, I see the correct behavior (like on Windows).

Therefore, I am rather sure that this is a bug of the gtk2 widgetset. You should file a bug report (you can add my project as demonstration of the issue).
TinyPortal © 2005-2018