Lazarus

Programming => LCL => Topic started by: j111 on May 03, 2012, 12:03:11 pm

Title: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: j111 on May 03, 2012, 12:03:11 pm
Hello.

I need to detect mouse movement in FormMouseMove event for all form globally even mouse pointer is over form controls.
For keyboard event it is posible by using KeyPreview property of the form.

What should i do to catch mouse events globally?
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: KpjComp on May 03, 2012, 12:13:02 pm
mouse.CursorPos
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: User137 on May 03, 2012, 12:16:54 pm
mouse.CursorPos
That goes along with a TTimer or thread then.
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: KpjComp on May 03, 2012, 12:28:15 pm
That goes along with a TTimer or thread then.

TTimer should be fine,  Thread probably not a good idea.

edit: Unless you Syncrhonized within the Thread of course.
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: Martin_fr on May 03, 2012, 12:39:46 pm
Application.UserInput (or similar)

search UserInput in ide/sourceeditor.pp (trunk / snapshot)
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: j111 on May 03, 2012, 01:59:28 pm
So. The following code works great, but how to recognize only mouse events with Msg param of MyInput procedure.

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.AddOnUserInputHandler(@MyInput, True);
end;   

procedure TForm1.MyInput(Sender: TObject; Msg: Cardinal);
begin
    Form1.caption := IntToStr(Mouse.CursorPos.X)+':'+IntToStr(Mouse.CursorPos.Y);
end;   
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: KpjComp on May 03, 2012, 02:18:18 pm
if Msg = LM_MOUSEMOVE
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: Martin_fr on May 03, 2012, 08:30:31 pm
On windows (windows only, use IFDEF) also WM_NCMOUSEMOVE

That is used, if the mouse is over the window border, or if the form itself has scrollbars, over the scrollbar....

To test, if it is over your windows
    if PtInRect(form.BoundsRect, Mouse.CursorPos) then
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: j111 on May 04, 2012, 10:54:11 am
With this code i hightligth controls when mouse move over them.
And main goal of the job is drop files from Dolphin to application.

Unfortunately OnDropFiles event disables mouse tracking and I cant visually indicate mouse movement while dragging selected files over form.
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: User137 on May 04, 2012, 01:38:04 pm
You can use the PtInRect() method above for each valid control on form. Going through the array in a loop.
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: j111 on May 04, 2012, 03:10:03 pm
Why user input frozen while dragging files on a form?

UserInputHandler continue working only after files was dropped.
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: Martin_fr on May 04, 2012, 03:18:56 pm
What about the OnDragOver event?

I haven't tested, it may only fire over the form, not over the children. But then

Code: [Select]
For i:- 0 to form.ControlCount-1 do form.controls[i].OnDragOver := form.OnDragOver;
Title: Re: Detect mouse movement in FormMouseMove handler when pointer isover form controls
Post by: j111 on May 04, 2012, 03:30:42 pm
I'v tried.
As a result OnDragOver fires when Automatic drag mode is set ON and nothing happens while dragging files.

This is very similar to WM_DROPFILES message for windows - program can recognize that files were dragged only when files were droped.

On Windows in this case possible to use OLE drag and drop where are possibilities to control all proccess from start to drop.

But I dont known such mechanism on Linux.
TinyPortal © 2005-2018