Recent

Author Topic: Cursor always crNoDrop during drag&drop  (Read 574 times)

grl

  • New Member
  • *
  • Posts: 38
Cursor always crNoDrop during drag&drop
« 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

howardpc

  • Hero Member
  • *****
  • Posts: 3550
Re: Cursor always crNoDrop during drag&drop
« Reply #1 on: May 24, 2020, 07:43:39 pm »
Does setting DragMode to dmAutomatic make a difference?

grl

  • New Member
  • *
  • Posts: 38
Re: Cursor always crNoDrop during drag&drop
« Reply #2 on: May 24, 2020, 11:04:13 pm »
Nope.
Tried setting one of the two to dmAutomatic and both.

No change.

Lukas

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 837
Re: Cursor always crNoDrop during drag&drop
« Reply #3 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
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

jamie

  • Hero Member
  • *****
  • Posts: 3651
Re: Cursor always crNoDrop during drag&drop
« Reply #4 on: May 25, 2020, 03:06:03 am »
How about this

BeginDrag(True);

?
The only true wisdom is knowing you know nothing

grl

  • New Member
  • *
  • Posts: 38
Re: Cursor always crNoDrop during drag&drop
« Reply #5 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

jamie

  • Hero Member
  • *****
  • Posts: 3651
Re: Cursor always crNoDrop during drag&drop
« Reply #6 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 ?
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 7630
Re: Cursor always crNoDrop during drag&drop
« Reply #7 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).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018