Drag Manager not managing drags... lazarus / 61-Beginners ---------------------------------------------------------------------- Birger52 · 2020-07-25 19:02 Having a lot of problems after updating  to Lazarus 2.0.10 FPC 3.2 So I decided to redesign one of my own controls. Here's the test project. (May actually be more than needed - an exe can be found at http://2.110.131.196/FPS/project1.exe) Form has a Panel that engulfs all controls - Panel1. There are 1 of my table control at each side, and a panel with a memo between them. At the top is an Edit - write the name of any folder, and the table to the left will be filled with filenames from that folder. There is also a label to right, that displays the Name of the last control for which OnDragMove was called. Only texts from the left table can be dragged. The memo and the table to the right will accept drops. Dragging a text seems to function. If you do it slowly, you can even see the label chow Panel1, while dragging to the right - then Memo1, Panel1 again, TableContainer2, and finally Panel1 again. There is only default cursor - nothing fancy, but this way it acts perfectly. Now - if you drag a text out of the top of the table, one should expect, that the label changes to Panel1 and the drag cursor to crNoDrop. But it doesn't happen. In fact, if you drag across the square at the top of the scrollbar, the cursor will change to crSizeWE. This is caused by the Controls MouseOver - that is not called, as the DragManager is supposed to be in control when dragging (ie calling DragOver of controls that is dragged over). Dragging a text to the Memo will change the label to say Memo1 - dragging the text further out the top of the memo, label and cursor should reflect the crNoDrop of Panel1 - and it don't. Same thing with the table on the right - dragging the text into it, changes Label to TableContainer2 and cursor AllowDrop - but dragging the text out of the top of it, will not change neither label, nor cursor. Cursor will not change to WE here tho... So it is only when dragging over Table1, DragManager calls MouseOver instead of DragOver - not table 2. One more "feature" about Table2 If you drag the text to the Memo, and then out the top, right to be over Table 2, and then down into table 2, the label and the cursor does not change until you are over the second line (The first of the white). (When dragging over the header line, it is actually programmed, so it will scroll the view, if there are more lines than can be seen, as long as the scrollbar position > min. This is done in the DragOver procedure - and it may seem to be correct, that it doesn't change the text/cursor; but the DragOver procedure is for some reason never called when dragging over the header! All contens in the table is user-drawn in the column, which is a TCustomControl descendant.) The real oddity is, that if you drag the text out of the bottom (or sides) of any of the three controls (tables or memo) everything functions just as it should! - Label changes to Panel1 and cursor to NoDrop. One could think, that this has to do with my component - but it also happens for the Memo - and actually the panel that holds the memo as well. Playing around, you can actually drop a text on the edit line, and have it be "dropped" in either memo or the right table. Or actually drop it in the memo, and have it "actually dropped to" the table - or vice versa. I'm taking a long break... ---------------------------------------------------------------------- jamie · 2020-07-25 23:22 If you are looking for help, you need to provide a working test application that shows the issue you believe Is at fault and thus has changed since the prior release of Lazarus..  This has to be done using stock components that come with Lazarus or maybe even some default packages that are not yet installed but package with the release.  Since this is all about the drag manager the demo app should be able to display the issue you are having using any one of the visual components on the toolbar since most of those have a drag option..  If you can find any one of those demonstrating the faulty issues then please give us that simple app. ---------------------------------------------------------------------- Martin_fr · 2020-07-25 23:53 1) Your Sig is applying? Windows? 2) Did you test, if 2.0.10 with 3.0.4 also exposes this behaviour? 3) Just a hunch - especially should it be 3.0.2 only - Does the problem happen with -O- (including for LCL, and packages)? ---------------------------------------------------------------------- Martin_fr · 2020-07-26 00:04 QuoteNow - if you drag a text out of the top of the table, one should expect, that the label changes to Panel1 and the drag cursor to crNoDrop. But it doesn't happen. In fact, if you drag across the square at the top of the scrollbar, the cursor will change to crSizeWE.This could be an issue with MouseCapture / SetCaptureControl. Capture should be set during dragging, so the dragmanager gets mouse messages. If it is set, then mouse messages should not get to the other controls. Your description says other controls get messages => maybe capture failed. --- Your attachments probably contain the files from the packages, but they do not have a package file. Easiest would be, if all files were in one project. As long as one does not try to edit the form (and ignores the warning about that), the components do (afaik) not need to be installed in the IDE, they only need to be compiled in the project. (afaik) --- Just did copy then all together. unit BSThumbCont is missing, but seems not needed. (compiles without). It does not load files for me.... EDIT: you did not mention jpg only.... --- Quote one should expect, that the label changes to Panel1There sure is no label.... ---------------------------------------------------------------------- Martin_fr · 2020-07-26 00:40 Tested with 2.0.10 3.2.0 2.0.10 3.0.4 2.1  3.2.0 If I drag text from the left table, the mouse cursor changes as expect: can drop to the memo, can drop to the right table. It also changes to no-drop if I go to the panel (empty space) below the tables. But: If I go to the panel area above the tables => it remains whatever it was (no changing to resize). There is some spot where it changes, probably some part of the edit field. But not yet sure.. Odd. Windows 10 64bit -- Edit: I get the resize cursor for the table corner that acts as splitter. And the same here, when I move the mouse up, it does not change back. It keeps splitter-resize. --- Seems to be   if Cursor = crDefault then  inherited MouseMove(aShift, aX, aY); So if you have a drag cursor, the parent is not called => the dragmanager never knows the mouse moves. --- Edit: Also think about, for the splitter cursor TabelControl.Cursor := instead of SetCursor() should take away the worries of disturbing any other cursor ---------------------------------------------------------------------- jamie · 2020-07-26 01:11 as much as I love finding code issues, because I don't want them in my app, I can't find anything wrong with the drag operation doing basic test in the 2.0.10 ---------------------------------------------------------------------- Birger52 · 2020-07-26 09:36 @martin_fr A couple of thoughts - and please correct me if I'm wrong. Quoteuse TabelControl.Cursor := instead of SetCursor() I'm setting the cursor in the class by directly assigning Cursor := crSizeWE This is the same as Assigning it to an instantiated object of the class? And even so, it will internally call SetCursor()? And - the cursor is set, in regular mouse-handling, that shouldn't be called when a drag is in progress. Quote  if Cursor = crDefault then  inherited MouseMove(aShift, aX, aY);Well - yes, the DragManager wouldn't know of the moving of the mouse. But the line of code is in the MouseMove of the class/control - which (again) should never be called while a drag is in progress? (And - well; the cursor is actually <> crDefault... - it is either a drag cursor or a resize cursor... Actually added a MouseLeave procedure, that sets Cursor := crDefault, and resets other variables connected to resizing - it makes no difference.) QuoteSo if you have a drag cursor, the parent is not called => the dragmanager never knows the mouse moves.Hopefully, it is not the cursor that determines if a drag operation is in progress. And if the drag operation was cancelled because of the resize cursor, the table should actually be resized. Which it doesn't - and moving the mouse to memo or table, cursor changes to what it should be, and an actual drop can be performed, so a drag is halfway in progress... I checked the involved procedures - and the only call out of the drag operation, is when the line dragged over is drawn with the drag-over color. And it doesn't seem to have any disturbing effect on the actual drag - the drop is performed as it should. Other stuff - Yes Sig is correct. Lazarus 2.0.10 FPC 3.2 I did try to compile with different optimizations - and it seems to make no difference. ---------------------------------------------------------------------- Birger52 · 2020-07-26 10:59 So... My Container is derived from TPanel. It contains a scrollbar, and a number of Columns, that is a class of its own derived from TCustomControl in which Strings are drawn. Each column detects mouse movement, but calls the BeginDrag of the Container (it's Parent). I'm not sure - but this may be what causes the problems. I have tried to change it to be the column itself - but it calls its own DragOver once, and then the drag is terminated/cancelled (at least drag cursor is removed), tho no call from anywhere is done to do so. (Drag cursor is replaced by the default arrow for the TCustomControl - and it keeps this, even when dragged over the memo where it should otherwise be the text cursor (caret), until mouse button is released - no drop is performed (Memo1.OnDragDrop is not called)). So dragging from a TCumstomControl (or derived) does not seem to be possible - not sure how to show this, without using custom classes... Apart from this, calling BeginDrag on the Container, simplifies DragMove and DragDrop procedures - the Source of these, is the Control initiating the drag, which is simple if it is one container, rather than one of a number of possible columns... ---------------------------------------------------------------------- Birger52 · 2020-07-26 16:00 Just an observation. If I change the call to start the Drag from being the Parent to being the Owner, then dragging behaves as it should - at least the cursors do. It can of course not be used for anything, as the Source in all DragOver and DragDrop procedures is the form, and there is no way of knowing, what is actually dragged or dropped - at least not if it is possible to drag from more than one Source. ---------------------------------------------------------------------- Birger52 · 2020-07-26 18:57 So ... Was looking for a way to use the forms BeginDrag, StartDrag or whatever - seems it doesn't have any, tho help actually points them out (TControl). Doesn't seem to be en EndDrag either. Added a TNotifyEvent OnSetDrag to my Container. Added a FDragSource : TObject var to the Form. Defined an EventHandler Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.TableContainer1SetDrag(Sender: TObject);begin  FDragSource := Sender;end;  Changed the code that initiates the drag in the Column from Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TTableContainer(Parent).BeginDrag(true)toCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if Assigned(aCont.OnSetDrag) then aCont.OnSetDrag(aCont);TForm(Owner).BeginDrag(true);  In all DragOver and DragDrop procedures, Source is replaced with FDragSource. It is also necessary to add a procedure to Clean up drag vars; setting FDragSource := nil and reset vars of the Container (such as the line number dragged, and used mouse coordinates in Columns) - this is called at the end of the Drop procedures - may have a problem cleaning up after cancelling (Dropping where not accepted). Well - not really sure, this is actually nescessary, as they will be initiated, when/if another drag is initiated. But for now this actually functions - despite the odd behavior of the DragManager. ---------------------------------------------------------------------- Martin_fr · 2020-07-26 19:35 First of all, I looked through the commit log / patches => I can not find a drag related change between 2.0.8 and 2.0.10. Quote from: Birger52 on July 26, 2020, 11:36:35 amQuoteuse TabelControl.Cursor := instead of SetCursor() I'm setting the cursor in the class by directly assigning Cursor := crSizeWE This is the same as Assigning it to an instantiated object of the class? And even so, it will internally call SetCursor()? And - the cursor is set, in regular mouse-handling, that shouldn't be called when a drag is in progress. I have not tested it lately. But TControl.Cursor := ... should update the screen cursor immediately, if the controls cursor should be visible. Dragging means the control cursor is not visible. Just test it, in an onKeyPress, or OnTimer event. QuoteQuote  if Cursor = crDefault then  inherited MouseMove(aShift, aX, aY);Well - yes, the DragManager wouldn't know of the moving of the mouse. But the line of code is in the MouseMove of the class/control - which (again) should never be called while a drag is in progress? MouseCapture is set to the control that did BeginDrag. (So the table from which you do drag). That table then sees all mouse move/button message, even if the mouse is outside that control. Even if the mouse is outside the form. That has afaik always be the case. Quote(And - well; the cursor is actually <> crDefault... - it is either a drag cursor or a resize cursor... The screen (temp or OS?) cursor. But not TControl.Cursor. The cursor handed to the OS is updated inside one of the messages send by the OS (or by the app itself, if it wants an immediate update). Afaik / Check sources to be sure: It will first check global overrides, temp screen cursors, maybe screen.cursor ??, and if none of them is set, then it looks up the current control. I know you said it used to work. I do not know how that may have worked in the past. I could not find related changes in the LCL. (If you can, please share) But the code looks suspicious enough, so that I believe it was never correct (even if by change it did work on your PC) On the other hand, I did not spent to much time on it, and do not indent to do so. You can follow the path TDefaultDragManager,BeginDrag  from TControl.BeginDrag. SetCaptureControl => force all mouse msgs independent of x,y to go to that control only. QuoteQuoteSo if you have a drag cursor, the parent is not called => the dragmanager never knows the mouse moves.Hopefully, it is not the cursor that determines if a drag operation is in progress. Its not. (afaik) TControl.Dragging and DragManager.Dragging / IsDragging But => if you call beginDrag(False) / not immediate, then the above return true. That is waiting for the mouse to move far enough to trigger dragging, is returning true. If TControl.Dragging then you must call inherited, so the dragmanager get called by MouseMove (and other mouse msgs). QuoteEach column detects mouse movement, but calls the BeginDrag of the Container (it's Parent). I'm not sure - but this may be what causes the problems.That would be the Table's BeginDrag? That is correct, And after that all mouse messages go to that table, and that must deliver them to the drag manager. QuoteIf I change the call to start the Drag from being the Parent to being the Owner, then dragging behaves as it should - at least the cursors do.That would be the Form? And the form does not interfere with MouseMove msgs. ---------------------------------------------------------------------- Birger52 · 2020-07-27 00:45 https://lazarus-ccr.sourceforge.io/docs/lcl/controls/tdragmanager.html As I understand it, the MouseCapture is set to the DragManager, when a drag is initiated. The DragManager has it's own Mouse handling procedures, and once the drag is initiated, these are handling inputs until mousebutton is released, so no other mouse-handling is called, while a drag is active. Cursor during a drag, is determined by the dragged Controls DragCursor. Nowhere in the documentation I have seen, does it say anything about "handing mouse event to DragManager". Drag manager does that on it's own. On the contrary, all documentation tells how simple it is - assign DragOver, assign DragDrop, and call BeginDrag.. (And well - obviously it is not that simple). Think Maybe I'll study implementation of TDragManagerDefault, if I can find it - and if it is called like that in Lazarus... ---------------------------------------------------------------------- Martin_fr · 2020-07-27 01:16 AFAIK the implementation is (and was) that the capture is set to the control. Quoteprocedure CaptureChanged(); virtual; abstract;   Aborts the dragging operation, when the capturing control really has changed.TDragManager is not a Control.... So it cannot refer to that. It has a MouseMove, but does not say how that is called... Other than that, I have not checked what Delphi does, or if for this or other reasons the doc or the implementation is correct. (The doc could definitely be more verbose) I did read your post, assuming that there is a possible regression. Since I know a bit of the implementation of DragManager I thought I check what may cause it. I could not find any pointer to any regression. (But there are few commits between 2.0.8 and 2.0.10, so if you believe there is, please find the revision.) As for general "how should drag-manager work", I have unfortunately not the time to look into that myself. As for getting it fixed. I shared whatever knowledge I have. For anything on top of that someone else will have to take a look. ---------------------------------------------------------------------- Birger52 · 2020-07-27 10:34 I have got that all wrong it seems. Problem is- was - that I used MouseUp and MouseMove directly for the things I needed done, rather than implementing event in Container for things happening in Column(s). DragManager actually do set Capture to the control that is being dragged (not directly, but through the TDragObject, as I recall). Anyhow - My versions of MouseDown and MouseMove, do not call the inherited (I thought they were simply calling event handlers) - so the dragging is interrupted, and cause for all my problems. (TDrag Manage has a Mouse Move, but doesn't say how it is called, indeed - it is called form TControl.MouseMove. Same thing with MouseDown, actually). Corrected this - and dragging functions as it was intended to - I think  Thx for pulling the wool form my eyes! ---------------------------------------------------------------------- Martin_fr · 2020-07-27 11:25 You are welcome. And make sure you also check the different use of TControl.Cursor TScreen.Cursor TScreen.RealCursor TScreen.BeginTempCursor / EndTempCursor SetCursor (direct OS) See procedure TWindowProcHelper.HandleSetCursor; for how they work