Recent

Author Topic: More drag/drop pecularties..  (Read 1136 times)

Birger52

  • Full Member
  • ***
  • Posts: 198
More drag/drop pecularties..
« on: May 26, 2020, 10:38:49 am »
Wanted to hear, if anybody has experienced something like this - and has an explanation or a workaround.

The problem is, that when I call BeginDrag of a given control, dragging operation is actually initiated - mouse is captured by the dragging object (default TDragObject); no regular mouse-processing is happening (ie MouseMove over other controls is not called), but no DragCursor is shown, no DragOver is called, neither is DragDrop - but when mouse button is released (Dragged object dropped) EndDrag IS called.

It is for a Custom control, that should display an image (a thumbnail) and some data in connection with it, on a list.
The control (container) is derived from TPanel (so it is actually the TPanel version of BeginDrag, that initiates dragging system). It has a label and a scrollbar and another Panel that displays the list, and each entry in the list is a TPanel with a TImage and a TLabel. All customized.
All functionality is in the container, and all components are created at run time - except for the container itself of course - and it is (for now) all based an a list of filenames (same folder for now).
I want / need to drag the container (it knows what item is being dragged) - as well as I want it to be the container that the receives drops.

But dragging the container, does not seem to be possible...
« Last Edit: May 26, 2020, 11:41:58 am by Birger52 »
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #1 on: May 26, 2020, 12:41:34 pm »
I tried to change the dragged object to be the panel containing the image and label - it starts dragging, show the cursor (Accept=false) but then immediately stops dragging again, apparently for no reason....
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #2 on: May 26, 2020, 05:14:41 pm »
I believe you need to initiate the drag from the top level control.

meaning, if you have a Timage on the panel as a child control, then you should be initiating a drag from there.
that is, if you actually hit that one.

 I don't know why you are having such an issue, I just did a short drag drop unrelated to your problems and it works as expected.

  I think maybe you are expecting something else to happen ?

 if you are covering the panel with child controls then all of the child controls also need to accept the drag.
 actually thinking about it, if the panel is covered then technically it shouldn't be a valid drag..

 maybe you are using the wrong approach.

 Have you looked at using a TDrawGrid as the supporting parent control instead ?
The only true wisdom is knowing you know nothing

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #3 on: May 26, 2020, 06:10:25 pm »
I don't believe, the hierarchy should have any influence.
You call BeginDrag, on the Control you want to "drag". It will create a DragObject (or DragControlObject), that should be dragged from the current mouse position, until the drag is stopped by either releasing the button that started the drag or pressing Esc.
A DragObject has no physical representation apart from the cursor, and is not part of the Owner or parent hierarchy. It grabs Mouse-messages, and should "drag" until cancelled or a drop is performed.

Accept should indicate whether the dragged-over control can accept the dragged control or not.
And what actually happens, when dropping, is determined by DragDrop.
So hierarchy is irrelevant.

TControl implements a simple DragOver - sets Accept to false unless OnDragOver is assigned, in which case Accept is set to true. And no matter what my code returns in Accept, the drag should not be terminated. (Onless an exception occurs - but that is not what is happening - at least none is raised...).

I create all but the container at runtime - so the logic, would be, that the container is the control to drag and the one that determines Accept in DragOver, and what happens at DragDrop, as it is the only one available at designtime.

That at least is the way almost a weeks attempts to make this function and studies of available documentation, has taught me.
But maybe I'm wrong - 'cause that is definitely not what is happening.

I guess a simpler version of this, would be:
"What can terminate a dragging operation, besides a cancellation or a drop?"


« Last Edit: May 26, 2020, 06:12:40 pm by Birger52 »
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #4 on: May 26, 2020, 08:37:33 pm »
Please show us your TDragControlObject that you created in the OnStartDrag event..

You can create a custom one which maybe is what you did but that object holds all that is be known at the end and during dragging.

 For example during the OnStartDrag event you can do something simple like this..

 DragObject := TDragControlObject.Create(TControl(Sender))

 That will create the drag object and place the control instance in it..

 so for example while I am dragging over other controls using the OnDragOver events

 The "Source" is this drag object ..

 Caption := Source.Control.Caption;
for example

 and in the OnDrop event, its the same object but the question here is do you really need to free the object?
 
 Delphi specifies that it gets freed automatically but If you were to do this yourself in your code I things best to FreeAndNil it just in case.

 Btw.you can make your own dragging object that does all of this for with images etc, you need to tell it to update the display as its dragging using the ondragOver or implement your own class based from this one where it can automatically do this when the X,Y positions change..

 This is the idea, build your own dragging display system as long as it is based from the TDragObject etc.

The only true wisdom is knowing you know nothing

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #5 on: May 27, 2020, 11:54:43 am »
I'm not creating my own TDragObject.
I tried that earlier - https://forum.lazarus.freepascal.org/index.php/topic,49739.0.html

Now relying on the built in functionality - only changing the cursor, to indicate move copy or exchange, through the dragged controls DragCursor property.
And that part is functioning with other controls, at least...


I have tried to attach here my test / development project.
And please bear with me - it is a test and development, and as such a work in progress.
The problem is in the playcontainer.
Project has one list on the left - showing a simple list of filenames, but TableContainer can do a lot more, and do a lot more in the app I am needing this for.
The PlayContainer in the middle with the problem is showing the same list, in a more elaborate way.
Goal is to be able to Move, Copy and Exchange elements in the underlying list, through dragging in or between the two lists.
On the right is a label inside three panels - it and the panel holding it, can be dragged, and the dragged control is the panel holding the others (ie - not the control you actually use to start the dragging operation). Showing that what I try to do with PlayContainer, is actually possible - just can't put my finger on WHAT is going wrong.
Bottom right is a panel that accepts dropping, and tells you what "control" is dropped, and what operation was used (drag with no button will Move, holding Ctrl will Copy and holding Alt will Exchange).

This test, creates a StringList of filenames, in the subfolder given in the edit.
I will upload a list of small images, that can be used for this in another comment - too big and too many for this - or you can use some of your own. (List limits display to 120x120 pix - slow if you use big images)...

In the actual app, dragging will be required between several of these controls.
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #6 on: May 27, 2020, 03:21:55 pm »
I had issues compiling your example because you have those controls installed already by the looks of it..

 Anyways I prepared a small demo of image dragging and changing the Cursor shape while dragging.

 I used the stock cursors for now but if you add cursors you need to add them to the Screen.Cursors list and then use the index before it will work..

 Stock values are most likely the (-) range while your custom one's should be in the (+) range..

 Also, I had to replace a part of your code because you didn't include your StringProc unit.
but that's ok because I use the String helpers for that..

  For fStr in Str.Split(',') do AddStrings(fStr);

 which seems to give the same results... Just a hint..
I'll attach my little demo
The only true wisdom is knowing you know nothing

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #7 on: May 27, 2020, 07:15:07 pm »
Sorry about that.
Seems I also forgot to share the images.
Here they are, should you want to try again.

Will look at your project...
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #8 on: May 27, 2020, 07:50:13 pm »
Thx for your effort.
Spinning cursor when dragging images.
Not really adressing the problem of what can make dragging terminate, oter than cancelling or dropping...
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #9 on: May 27, 2020, 11:28:30 pm »
Ok, I was able to get it to compile and run...

yes you have some quirks in the dragging..

I am not sure if it is by design but on your left that list the file names I need to move the mouse left or right while the mouse is down to start a drag. When I do that,  drag cursor comes on and I can move it all over the form..

 Btw, you should be running Heaptrc, you are loaded with leaks.. you need to get the leaks out not because you know you are not cleaning up some code on exit which isn't a real big deal while you are developing but some of those leaks could be coming from memory splatter and that will give you random results, if not crashes..

 Its important to track these down so you can have a clean exit with the code..

 I have been editing your code here and there so I can get it to work a little better.
 
 i'll play with it some more but I think you have some logic in there that is whacking you...

 btw, one of your leaks at at the end of your OnCreate for the form where you load in the resources for your cursors. you didn't free the class you created there.

But that is only one >:(
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #10 on: May 28, 2020, 01:15:38 am »
I got  your app to exit clean without any leaks.

There were many classes you didn't free up..

I did notice I am not getting the cursors you loaded from Resource although the CUR class reports a valid image each time, I'll look into that.

 btw, in the future please try to use  *.RES resource files not the lrs, cause those are more or less outdated.
The only true wisdom is knowing you know nothing

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #11 on: May 28, 2020, 01:55:22 am »
Functionality is the prime goal.
Not sure how to use Heapctr, but will look into that.

Resources...
I use GLazres to create them - not sure how to get .res
Tried to include resources through project/options/resources menu - and from that all you get is errors - named resources can't be found.
.lrs functions just fine here.
Tried to use the .rc way explained @https://wiki.freepascal.org/Lazarus_Resources - and it gives windres compiling errors.
So right now, the only way that is actually functioning, is GLazres, and the created .lrs file...
« Last Edit: May 28, 2020, 02:36:49 am by Birger52 »
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #12 on: May 28, 2020, 02:40:15 am »
Ok, it appears with what I have now the dragging seems to operate as how I remember it with the cursors.

 But there is an issue that has always been there and that is when you change your cursor the image will not take effect until you move the mouse.

  There could be a way around that I am not sure at the moment.. Its time for you to turn in, I'll most likely post back your files compressed for you to look at later..


The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 3096
Re: More drag/drop pecularties..
« Reply #13 on: May 28, 2020, 02:44:54 pm »
Hmm, Lets see If I can attached a minimum...
The only true wisdom is knowing you know nothing

Birger52

  • Full Member
  • ***
  • Posts: 198
Re: More drag/drop pecularties..
« Reply #14 on: May 28, 2020, 06:18:16 pm »
I havent had the time to investigate your code. But it doesn't drag from PlayContainer as it should, either.
Will look closer, later.

Have cleaned my own code some.
Original approach was to treat mouse and drag/drop events, kind of like bubbeling - but not by assigning events, but rather by calling the controls MouseDown, MouseMove, MouseUp, DragOver and DragDrop procedures directly - except for the main container (PlayContainer), where event handlers are set at designtime.
This did not function.
I have now redesigned so the involved controls do what special they need to do (if any), and then call the eventhandler attached to the main container, rather than letting the event "bubble" in the chain of controls.
This does not function either.

Calling the main containers BeginDrag, calls the default DragManager, initiates a default DragObject - but a drag cursor is never shown.
One can move the mouse around the screen - no regular mouse over events are called (DragManager has grabbed mouse capture), but no DragOver event handlers are called either. No DragDrop eventhandlers are called when the mousebutton is released - but the EndDrag (main container) IS called (target is nill and not the control dropped on, as it should be).

From the leftmost list of filenames, can be dragged - and it can also be dropped on the PlayContainer (the one with images), and the expected functionality is functioning (Move - Copy - Exchange).
The label and Panel on the right can be dragged over as well - but none of the lists will accept dropping of the label.
So - it's not the DragOver functionality that is a problem - it works when other controls are dragged over.
(PlayContainer is still missing the option to scroll content, when dragging over header og exposed bottom or top/bottom of scrollbar - this is not expected to be a problem).
« Last Edit: May 28, 2020, 06:21:04 pm by Birger52 »
Lazarus 2.08 FPC 3.04
Win7
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018