Recent

Author Topic: How to capture horizontal mouse scroll event?  (Read 19790 times)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
How to capture horizontal mouse scroll event?
« on: April 25, 2011, 12:39:29 am »
I am trying to figure out how to get an image to scroll horizontally as well as vertically using a mouse trackball (actually an Apple Magic Mouse).

So I'm looking for an event that sends a horizontal scroll delta. An OnMouseWheel event sends vertical deltas, but not horizontal deltas. I assume it must be possible because the Lazarus editor scrolls horizontally using the mouse.

I'd greatly appreciate any hints.

Cheers,
Frederick
 
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to capture horizontal mouse scroll event?
« Reply #1 on: April 25, 2011, 12:44:37 am »
SynEdit scrolls horizontally using the mouse, but ScrollBar control does not.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #2 on: April 25, 2011, 12:47:55 am »
Thanks typo.

Any idea how SynEdit captures the event?
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to capture horizontal mouse scroll event?
« Reply #3 on: April 25, 2011, 01:05:23 am »
You can see it by yourself on SynEdit.pas, line 4614.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: How to capture horizontal mouse scroll event?
« Reply #4 on: April 25, 2011, 01:07:10 am »
SynEdit uses the notification that comes from the scrollbar...

But there still is code, how to do it by wheel
search for WM_Mousewheel


But you can also see if you component has a mousewheel event => or hook .


(WheelDelta div 120) is one scroll unit. Some mouses can provide half scrolls, or any fraction. So you must accumulate.


Not sure where, but there is sa setting, what the system pref is, for how many lines (eg text lines) to scroll per wheel click (per 120 delta)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to capture horizontal mouse scroll event?
« Reply #5 on: April 25, 2011, 01:18:16 am »
Sorry, line 7018.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #6 on: April 25, 2011, 01:58:37 am »
SynEdit uses the notification that comes from the scrollbar...

But there still is code, how to do it by wheel
search for WM_Mousewheel


But you can also see if you component has a mousewheel event => or hook .


(WheelDelta div 120) is one scroll unit. Some mouses can provide half scrolls, or any fraction. So you must accumulate.


Not sure where, but there is sa setting, what the system pref is, for how many lines (eg text lines) to scroll per wheel click (per 120 delta)

Thanks Martin,

I'm using a TPaintBox with two TScrollbars. I could use a notification from a scrollbar if it responds, but don't see a suitable event. What scrollbar event does SynEdit respond to?

Regards,
Frederick




“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #7 on: April 25, 2011, 01:59:27 am »
Sorry, line 7018.

typo,

I'm looking in synedit.pp in Lazarus components to see if I can figure anything out. Line 7018 doesn't seem to apply, maybe I'm looking in the wrong file?

Regards,
Frederick




“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to capture horizontal mouse scroll event?
« Reply #8 on: April 25, 2011, 02:17:24 am »
Code: [Select]
TCustomSynEdit = class(TSynEditBase)   
private
  {...}
  procedure WMMouseWheel(var Msg: TMessage); message WM_MOUSEWHEEL; 
  {...}

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9909
  • Debugger - SynEdit - and more
    • wiki
Re: How to capture horizontal mouse scroll event?
« Reply #9 on: April 25, 2011, 02:32:37 am »
It's in an {$IFNDEF SYN_LAZARUS} block. So it isn't used. It may still be working code though.

SynEdit uses     
    procedure WMVScroll(var Msg: TLMScroll); message WM_VSCROLL;

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #10 on: April 25, 2011, 02:51:08 am »
Code: [Select]
TCustomSynEdit = class(TSynEditBase)   
private
  {...}
  procedure WMMouseWheel(var Msg: TMessage); message WM_MOUSEWHEEL; 
  {...}

typo,

I have the code in front of me now, thank you.

Regards,
Frederick
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #11 on: April 25, 2011, 03:04:04 am »
It's in an {$IFNDEF SYN_LAZARUS} block. So it isn't used. It may still be working code though.

SynEdit uses     
    procedure WMVScroll(var Msg: TLMScroll); message WM_VSCROLL;


Martin,

That may be a clue to get me pointed in the right direction. I'm guessing I need to figure out WMHScroll as well.

I need to break for the night though. Many thanks.

Regards,
Frederick
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #12 on: April 27, 2011, 01:45:26 am »
After poking around a little, I realized that a TScrollBox responds to WM_VSCROLL and WM_HSCROLL events. Testing it out shows that it does correctly respond to a Magic Mouse, and I assume trackball/trackpad, horizontal scrolls.

This seemed promising and simpler, so I decided to work on this. The problem is that I want the TScrollBox to simply report scroll changes, so I can properly redraw the TPaintBox (I'm scrolling a TGRABitmap following circular's method). Unfortunately a TScrollBox does not have OnChange or OnScroll events.

While it is possible to set TScrollBox.AutoScroll off (since I don't want it to actually scroll the TPaintBox), it still sends OnPaint events, even if the TPaintBox is not a child control. So when I zoom the TPaintBox in code, and try to update the scrollbars it repaints again.

When using a normal TScrollBar I could avoid the call back by setting TScrollBar.OnChange = nil temporarily while updating it, but TScrollBox uses TControlScrollBar which don't have OnChange handlers.

Before I tried this, I also tried implementing these methods following Martin:

Code: [Select]
TForm1 = class(TForm)
  ...
   procedure   WMHScroll(var Msg: TLMScroll); message LM_HSCROLL;
   procedure   WMVScroll(var Msg: TLMScroll); message LM_VSCROLL;
  ...

but they never get called. I imagine I am just doing something incorrectly. I hope that all makes sense. Any comments appreciated!

Cheers,
Frederick
« Last Edit: April 27, 2011, 02:03:52 am by Frederick »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: How to capture horizontal mouse scroll event?
« Reply #13 on: December 11, 2018, 01:38:12 am »
Wrapping up a very old thread, but I only discovered the answer today.

MouseWheel event handles vertical scrolling.

MouseWheelHorz event handles horizontal scrolling.

Not sure when the latter was introduced, I don't think it was there when I asked the question. Thanks to the devs in any case.

It would be great to have one that did both, as when scrolling an image using the mouse wheel (trackpad) I need to redraw an image twice. Other than that it works very well.
« Last Edit: December 11, 2018, 01:42:27 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: How to capture horizontal mouse scroll event?
« Reply #14 on: December 11, 2018, 02:38:26 am »
Assuming the messages received should be back to back

Try this..

When you enter the OnMouseVertical scroll for example, you test for a global flag to see if the OnMouseHorizontalscroll
is already in play, if not then set this variable to the Vertical Mode with its details and then the next line use the
Applciation.ProcessMessages.

  Doing this will look at the message que and thus then fire the other event, now you have both directions before you
even draw the image.

 So basically this is a synchronizing way of capturing both events before drawing..

 and if the other message isn't in the que in that order, then you can simply reset those settings to see if they
got changed from the second event, if not then you do the single event drawing..

 I have done this in windows because I've found in most cases the messags are back to bacl..

I can't say how that works in other targets
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018