Recent

Author Topic: DragDrop - changing cursor  (Read 4655 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 309
DragDrop - changing cursor
« on: May 10, 2020, 02:59:05 pm »
Have some controls - derived from TCustomControl - that I need to exchange data.
Sometimes moving and sometimes copying. If Ctrl pressed Copy if not Move.

(Everything is functioning.
I had some trouble, because when Dropping - releasing mouse button - the DragOver is actually called with state dsDragLeave before DragDrop, which could result in the drop not being accepted even when it should.
Nowhere in documentation is mentioned that a drop will call the DragOver procedure, to determine acceptance.)

Using only Free pascals version (BeginDrag - DragOver and DragDrop procedures), there seem to be no way - and no Icon - to distinguish between these two.

I can program the difference - but I cant seem to find a way to change icon for the dragging operation..

Any solutions to this?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: DragDrop - changing cursor
« Reply #1 on: May 10, 2020, 08:55:37 pm »
I think you should report that one of state of confusion.

It looks like maybe the wording is a little incorrect, even for the Delphi doc..

dsDragLeave = "The Mouse is Leaving the control"

that does not mean it has left, it only means that its getting ready to leave and has disengaged its operations..
 
    If the mouse has actually left, you wouldn't receive any dragover messages.

The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: DragDrop - changing cursor
« Reply #2 on: May 11, 2020, 11:34:06 am »
So ...

In DragOver, there is no way to determine if there is a drop or the dragging is simply leaving the control.
What is the purpose of passing the state, then?

And how, do I change the cursor to indicate copying rather than moving data?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: DragDrop - changing cursor
« Reply #3 on: May 11, 2020, 12:55:31 pm »
Sure there is ways. You wont get a drag over message if the control isn't in aight.
Leaving means its ending its drag over operation. Because there is no message if there is no dragging.
Also there is no dropping.
If u let go of the drag operation early there should be no drop events
I dont even read those states . Just process the events.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: DragDrop - changing cursor
« Reply #4 on: May 11, 2020, 01:00:20 pm »
In DragOver, there is no way to determine if there is a drop or the dragging is simply leaving the control.

That is precisely why DragLeave exists: it's a warning that if you keep "DragOvering" in some direction you'll leave the control, i.e. basically that you 're close to one of the borders.

Note also that after a Drop there should be no more DragOver's, since a Drop, naturally enough, ends the Drag/Drop operation.
« Last Edit: May 11, 2020, 01:06:42 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: DragDrop - changing cursor
« Reply #5 on: May 11, 2020, 01:48:10 pm »
The attached project shows how to do simple drag and drop from a listbox to a listview, distinguishing copying from moving an item with a cursor change.
With multiple controls, or dragging between forms it gets more complicated, but the simple approach may be all you need.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: DragDrop - changing cursor
« Reply #6 on: May 16, 2020, 04:59:11 pm »
A way to use windows cursor for dragging?
I Know how to select which to use - how do I include Windows drag-cursors in the FDragImageList?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: DragDrop - changing cursor
« Reply #7 on: May 16, 2020, 05:43:19 pm »
Hi!

I don't know if it is possible with FDragImageList, but you can put your cursors into a ressource and include it in your  app. I did for the hourglass Here is my code:

Code: Pascal  [Select][+][-]
  1. const crRealHourGlass   =  1;
  2. ...
  3. procedure TForm1.FormCreate(Sender: TObject);
  4. begin
  5. Screen.Cursors[crRealHourGlass]:=LoadCursorFromLazarusResource('hourglass');
  6. end;
  7.  
  8.  
  9. Procedure TForm1.OnSomeEvent(Sender : TObject);
  10. begin
  11. Screen.Cursor := crRealHourGlass;
  12. end;
  13.  
  14.  
  15.  

Winni

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: DragDrop - changing cursor
« Reply #8 on: May 16, 2020, 07:47:11 pm »
Thx for the suggestion.

Seems that no matter how I add my "cursors" I get a "resource not found" error.

I've tried adding them as .png, .bmp, and .cur files, and set types to icon, bitmap and cursor for all of them.
It does not seem to matter tho.
Nothing added in the Resources section of the project options, actually seems to be added as a resource...

Info in .lpi file is correct.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: DragDrop - changing cursor
« Reply #9 on: May 16, 2020, 08:00:51 pm »
Tried using glazres to convert .cur files to .res, and include them in project through options....

It makes no difference.

Project Resources can import quite a lot of file types as default - but not.res files?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: DragDrop - changing cursor
« Reply #10 on: May 16, 2020, 08:12:19 pm »
Hi!

On the console you do:

*
Code: Bash  [Select][+][-]
  1. lazres cursor.lrs MyDragCursor.cur
* copy the cursor.lrs to your source directory
* In your MainUnit you insert:

Code: Pascal  [Select][+][-]
  1. initialization
  2. {$I cursor.lrs}
  3.  

That's all.

Winni

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: DragDrop - changing cursor
« Reply #11 on: May 17, 2020, 12:37:49 am »
Hi!

On the console you do:

*
Code: Bash  [Select][+][-]
  1. lazres cursor.lrs MyDragCursor.cur
* copy the cursor.lrs to your source directory
* In your MainUnit you insert:

Code: Pascal  [Select][+][-]
  1. initialization
  2. {$I cursor.lrs}
  3.  

That's all.

Winni

Please do not use old Lazarus resource format, use newer FPC resource format instead.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: DragDrop - changing cursor
« Reply #12 on: May 17, 2020, 01:09:59 am »
Hi!

No - the old format works perfect.

And the "new" Windows format brings nothing but trouble.

I am not the only one.

Winni

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: DragDrop - changing cursor
« Reply #13 on: May 17, 2020, 01:33:30 am »
Hi!

No - the old format works perfect.

And the "new" Windows format brings nothing but trouble.

I am not the only one.

Winni

What kind of troubles the new format brings?

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: DragDrop - changing cursor
« Reply #14 on: May 17, 2020, 02:09:30 am »
Thx Wiinni.
Got your suggestion functioning, as long as showing the images when Dragging
But hotspots for these images is way off. So will have to get them into the DragImageList somehow.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018