Recent

Author Topic: Problem porting app in delphi that used form onmousewheel  (Read 10027 times)

snorkel

  • Hero Member
  • *****
  • Posts: 817
Problem porting app in delphi that used form onmousewheel
« on: March 07, 2013, 06:12:29 pm »
Hi,
I have a app in delphi that uses the forms onmousewheel, now a Lazarus form also has this event, but it behaves differently.
On delphi if you drop a panel on the form and set it to align client the forms onmousewheel event will still fire, but on Lazarus it does not.
Is there any way to work around this issue?

I am using windows 7 by the way, the rest is in my sig.

Thanks,
« Last Edit: March 07, 2013, 06:24:11 pm by snorkel »
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

itmitica

  • Jr. Member
  • **
  • Posts: 85
Re: Problem porting app in delphi that used form onmousewheel
« Reply #1 on: March 07, 2013, 09:37:48 pm »
Use TApplicationProperties' OnUserInput event.

Here's a sample project: https://github.com/itmitica/lazarus-522-mouse-wheel

--
Mitică

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Problem porting app in delphi that used form onmousewheel
« Reply #2 on: March 07, 2013, 10:21:35 pm »
Hi,
I had already tried that, but the problem is I don't have access to the wheel delta using that method.
I didn't see anyway to tell what way the user was moving the mouse wheel.

In Delphi because the forms onmousewheel gets all the mouse wheel input you can use it to to scroll a tscrollbox that has a lot of controls on it that steal the mousewheel focus.

i.e.

procedure Tdataframe.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
 var
   msg: Cardinal;
  code: Cardinal;
  i, n: Integer;
begin
   if sbox = nil then
      exit;
   if not sbox.Focused then exit;
     Handled := true;
     If ssShift In Shift Then
        msg := WM_HSCROLL
            Else
                msg := WM_VSCROLL;
     If WheelDelta > 0 Then
        code := SB_LINEUP
             Else
                 code := SB_LINEDOWN;
     n:= Mouse.WheelScrollLines;

     For i:= 1 to n Do
         sbox.Perform( msg, code, 0 );
     sbox.Perform( msg, SB_ENDSCROLL, 0 );
end;
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

itmitica

  • Jr. Member
  • **
  • Posts: 85
Re: Problem porting app in delphi that used form onmousewheel
« Reply #3 on: March 07, 2013, 10:36:15 pm »
Add the OnMouseWheel to TPanel.

Right click the TPanel, open the extctrls.pp unit, add the OnMouseWheel properties, recompile Lazarus, use OnMouseWheel events for the new TPanel.

http://postimage.org/image/f8d2nar3p/

--
Mitică

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4692
  • I like bugs.
Re: Problem porting app in delphi that used form onmousewheel
« Reply #4 on: March 08, 2013, 12:00:01 am »
Add the OnMouseWheel to TPanel.

Better to use TScrollBox instead of TPanel.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

itmitica

  • Jr. Member
  • **
  • Posts: 85
Re: Problem porting app in delphi that used form onmousewheel
« Reply #5 on: March 08, 2013, 12:21:03 am »
Better to use TScrollBox instead of TPanel.

By default, some components, like TEdit, get in the way of form scrolling, on Win at least.

So I was showcasing how to make possible the mouse wheel event for components like TEdit or TPanel, components that block the form scroll on mouse wheel. I was not attempting a botched up TPanel for TScrollBox.

What's explicitly missing but heavily implied in my post is the appearance of the OnMouseWheel event for the TPanel component, and the possibility to assign a FormMouseWheel method to it.

--
Mitică

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Problem porting app in delphi that used form onmousewheel
« Reply #6 on: March 08, 2013, 12:21:36 am »
I tried tscrollbox and it has the same problem, when I embedd stuff in it I want to scroll like edit or label controls they steal the focus from
the scroll box and it won't scroll with the mouse wheel.

In Delphi I got around that by using the forms onmousewheel, so it would scroll no matter what control was in the tscrollbox.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

itmitica

  • Jr. Member
  • **
  • Posts: 85
Re: Problem porting app in delphi that used form onmousewheel
« Reply #7 on: March 08, 2013, 12:31:09 am »
I tried tscrollbox and it has the same problem, when I embedd stuff in it I want to scroll like edit or label controls they steal the focus from
the scroll box and it won't scroll with the mouse wheel.

Yes, because TEdit or TLabel don't have the OnMouseWheel event, but I gave you the solution.

Right click the TEdit or TLabel component, add the three properties OnMouseWheel, OnMouseWheelUp, OnMouseWheelDown.
Recompile Lazarus.
You now have the OnMouseWheel event for TEdit and you can assign FormMouseWheel method to it, so it will scroll even when the pointer sits over a TEdit or TLabel.

--
Mitică

itmitica

  • Jr. Member
  • **
  • Posts: 85
Re: Problem porting app in delphi that used form onmousewheel
« Reply #8 on: March 08, 2013, 12:46:23 am »
This is a screen cap: http://postimage.org/image/40lcjlyff/

On the left TEdit has no OnMouseWheel events.
After the modding of stdctrls.pp and after Lazarus rebuild, TEdit now has a OnMouseWheel event.

Just assign to it the
TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean)

method for the OnMouseWheel form's event.

It will now scroll the form even if the pointer is over TEdit components.

I would post a complete example, but I won't help much, since the whole deal is the modified stdctrls.pp file and the "forked" Lazarus.

Only in the binary you'll be able to test the difference. Let me know if you want me to provide one.

--
Mitică
« Last Edit: March 08, 2013, 12:48:03 am by itmitica »

itmitica

  • Jr. Member
  • **
  • Posts: 85
Re: Problem porting app in delphi that used form onmousewheel
« Reply #9 on: March 08, 2013, 01:15:36 am »
Here is a link to a Win binary: http://ge.tt/1wCfEPa/v/0?c
It's just a form and two TEdits, the first one with the AutoSize set to false.

You can mouse wheel scroll just fine over them.

--
Mitică

 

TinyPortal © 2005-2018