Bug 7101 - DCR ability to receive scroll events (e.g. scrollwheel) from Scrollable
Summary: DCR ability to receive scroll events (e.g. scrollwheel) from Scrollable
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 major with 11 votes (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 47775 50404 73276 (view as bug list)
Depends on: 5634
Blocks: 16987 36705 36706 62188
  Show dependency tree
 
Reported: 2001-12-19 11:34 EST by Randy Hudson CLA
Modified: 2005-01-24 19:59 EST (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Hudson CLA 2001-12-19 11:34:15 EST
Within a single SWT Canvas, I have several lightweight objects that resemble 
SWT Scrollables, but are not themselves widgets at all. If I scroll the 
scrollwheel, scroll events go to the canvas.   I wish to intercept the events 
at the canvas, and redirect them to the lightweight objects based on either:
    a) they are under the mouse
    b) they have "focus", as defined in my lightweight focusing system.

This appears to be technically possible, at least on windows.  I have seen
where the new JDK 1.4 supports scrollwheels on Swing components, which are
identical to what I have in that they are lightweight objects on a single
heavyweight OS window.

The preferred implementation would be identical to Mouse events.  I would add a 
ScrollListener to a Canvas (or Scrollable, in this level genericness can be 
supported).  My ScrollListener would be notified of ScrollEvents when the OS 
sends scroll messages to the window for whatever reason (most likely a 
scrollwheel).  If possible, the event should contain the x,y location, if not, 
I'll query it from the Display.

Requirement:
I need to be able to add such a listener (and have it notified) even without 
constructing a Canvas with SWT.H_SCROLL or V_SCROLL flags.  It appears that 
Swing is able to do this on Windows.  Run the Swingset2 demo on JDK 1.4.  Go to 
the JList tab, and notice that scrollwheel works, and there doesn't **appear** 
to be any OS Controls with scrolling enabled.
Comment 1 Randy Hudson CLA 2001-12-19 11:37:13 EST
On the ScrollEvent, if I set the doit field to false, I would like to "consume" 
the event, preventing the Scrollable from handling the scroll in the default 
manner.
Comment 2 Mike Wilson CLA 2002-05-24 20:12:54 EDT
To be considered post-R2.0.
Comment 3 Randy Hudson CLA 2002-08-09 12:03:42 EDT
This is pretty important to GEF.  For example in the Palette, we have multiple 
drawers.  The User may have 2 drawers open, and wish to use the scrollwheel to 
scroll through the available items.  The entire palette is a single Canvas.

It seems like a new ScrollWheelListener could be added and listeners notified 
in Scrollable.WM_MOUSEWHEEL(...).  I would need to be able to consume the 
event, meaning don't forward the scroll to the scrollbar.  I would need the 
mouse x,y location to process the ScrollWheelEvent.

Also, is it possible to get this event even if the H/V_SCROLL style is not 
set?  just wondering, because I don't need native scrollbars in the Palette 
anywhere.  I suppose I could hide them, and just ignore them.
Comment 4 Mike Wilson CLA 2002-08-09 14:00:55 EDT
We should try and make this happen.
Comment 5 Randy Hudson CLA 2002-11-11 10:26:31 EST
We need this to happen in 2.1.
Comment 6 Randy Hudson CLA 2003-01-08 11:37:04 EST
Can this be priority 2?
Comment 7 Steve Northover CLA 2003-01-23 09:51:16 EST
Sorry Randy, we did not get to this.  It's not clear that this can be done on 
Motif as there is no scroll wheel API in X.  Needs more investigation.
Comment 8 Greg Adams CLA 2003-01-28 12:20:55 EST
We also require this capability for our application. Primarily for quick zoom 
in and out ability. In visualizations zooming is a common task so this is 
important.

The fact that it is not supported on motif seems secondary because we should 
support it on windows, and on motif applications could do graceful degradation 
and use a menu or other approach.

Does GTK support it?
Comment 9 Randy Hudson CLA 2003-01-30 10:16:29 EST
The event need not be fired on Motif. Since even some Windows users don't have 
a Scrollwheel, there *will* be alternatives to the scrollwheel.
Comment 10 Nobody - feel free to take it CLA 2003-02-20 12:35:13 EST
I am also in need of a fix. Does anyone have a workaround in the meantime? I 
could subclass the widget I wanted to capture the event from and implement 
windowProc on a stand alone SWT app (looking for OS.WM_MOUSEWHEEL) but this 
doesn't seem to work when I take the same widget and move it to an eclipse 
view. 
Comment 11 java designer CLA 2003-04-20 21:04:40 EDT
I need this too. I need to zoom-in/out the contents of the canvas
in my SWT app based on the mouse wheel.

BTW, scroll wheels work on Windows AND Macintoshes (including 
OS X) ! That's 99.9% of the GUI market right there.

--j
Comment 12 David J. Orme CLA 2003-04-21 10:31:20 EDT
>>Does GTK support it?

Yes.
Comment 13 Randy Hudson CLA 2003-08-29 10:29:12 EDT
Any news for 3.0?
Comment 14 Grant Gayed CLA 2003-12-01 13:19:54 EST
*** Bug 47775 has been marked as a duplicate of this bug. ***
Comment 15 David J. Orme CLA 2004-01-26 10:26:45 EST
*** Bug 50404 has been marked as a duplicate of this bug. ***
Comment 16 Grant Gayed CLA 2004-09-07 19:13:41 EDT
*** Bug 73276 has been marked as a duplicate of this bug. ***
Comment 17 David J. Orme CLA 2004-09-08 09:52:37 EDT
BTW, how does StyledText get scroll wheel events?  Can anyone point me at the
appropriate place in the source?

(The Eclipse editors respect scroll wheel events, so it must be possible...)
Comment 18 Jonathan Edwards CLA 2004-09-08 10:02:38 EDT
Scrollable converts WM_MOUSEWHEEL messsages into WM_VSCROLL and WM_HSCROLL
Comment 19 Jonathan Edwards CLA 2004-09-08 10:06:38 EDT
Since my bug 73276 was merged with this,let me add here what wasn't a duplicate.
We also need the ability to handle the extra mouse buttons, like the
Forward/Back thumb buttons on many modern mice. This is particularly annoying in
Eclipse itself, which has Forward/Backward actions but can't respond to the
mouse buttons like all the web browsers do.
Comment 20 Felipe Heidrich CLA 2004-10-19 18:17:24 EDT
One alternative is to send a MouseDown event when any of button of 7-buttons 
mice is pressed. The button field should be filled according with:
1 - left button
2 - middle button
3 - right button
4 - wheel up
5 - wheel down
6 - back button
7 - forward button


On Windows button 4 and 5 are sent via WM_MOUSEWHEEL, 6 and 7 via WM_XBUTTON.

Inside Scrollable this OS message (WM_MOUSEWHEEL) is translate into a 
SWT.Selection event for the vertical scrollbar (if it exist), or for the 
horizontal scrollbar (if it exist).

SWT does not listen for WM_XBUTTON. On Windows is not possible to implement 
MouseUp for buttons 4 and 5 (the wheel).

On X, all the buttons of the mice generate a XButtonEvent, the button field of 
this structure already has the right number for us (4 for wheel up, etc).
On motif, we can implement MouseDown and MouseUp for all the buttons.

On GDK, if during a ButtonPress the button is 4, 5, 6, or 7 the XButtonEvent 
event is converted into GdkScrollEvent with the detail GDK_SCROLL_UP, 
GDK_SCROLL_DOWN, GDK_SCROLL_LEFT, GDK_SCROLL_RIGTH respectively.

On GtkScrolledWindow the GdkScrollEvent is converted into value_changed 
signal, 4 and 5 change the vertical scrollbar, 6 and 7 change the horizontal 
scrollbar.

The GdkScrollEvent is send to widget, so we could use them to simulate 
MouseDown, the problem would be how to do MouseUp for buttons 4,5,6, and 7 
since GDK ate the events.

I did not see what Carbon does.
Comment 21 Felipe Heidrich CLA 2004-10-20 11:45:33 EDT
So, when buttons 4,5,6 and 7 are pressed SWT will fire two events a MouseDown 
for the Control and a Selection for the ScrollBar (if exist).

The problem are: (a) In some places we can't implement MouseUp, (b) These 
extra Mouse events can break existent code.

Comment 22 Randy Hudson CLA 2004-10-20 12:11:43 EDT
> SWT will fire two events...

No.  SWT needs to first fire the Scrollwheel event.  Then, iff Event.doit is 
still TRUE after listeners have been notified, then the Scrollbar will be 
scrolled, and fire widgetSelected.  If doit==FALSE, the scrollbar must not 
change.

I agree that poorly written code will be problematic when MouseDown buttons 4-7 
occur. Note that MouseUp is not guaranteed even for buttons 1-3.  For example, 
if focus is lost, or with context menus or mouse dragging outside the control 
on Linux.

MouseEvent API already mentions the possibility for additional buttons beyond 3:
"2 for the second button, and 3 for the third button, etc."

I think "etc." is pretty clear ;-)
However, what will the statemask contain?  SWT.BUTTON_4-7?

The safest choice might be to add MouseNavigationEvent or MouseListener2, or 
something.
Comment 23 Felipe Heidrich CLA 2004-10-20 13:10:27 EDT
"I agree that poorly written code will be problematic when MouseDown buttons 4-
7 occur."
Yes, Check the Tree widget in Motif, rotating the wheel cause the selection to 
change to the item under the cursor :-) You can test in the Package or Outline 
view.

Not sure how to implement the mask, Windows does not provide mask for the 
wheel. X and GDK provide mask for BUTTON1 to BUTTON5.
Comment 24 Felipe Heidrich CLA 2004-11-29 18:04:22 EST
Reassigning pr.
Comment 25 Felipe Heidrich CLA 2004-11-29 21:07:13 EST
Fixed > 20041129 (not in this week integration)

We added SWT.MouseWheel in Control.
The fields in the event that are relevant are:
detail - can be SCROLL_PAGE or SCROLL_LINE
count - indicates how many lines or pages should be scrolled (can be negative)
doit - set to false if, for example, the control also has scrollbar and the 
application don't want the scrollbar to move when the wheel rotates.

We also added MouseDown and MouseUp for buttons 4 and 5 (plus mask for both 
buttons).

Comment 26 Randy Hudson CLA 2004-11-30 10:16:55 EST
It sounds like only vertical scrollwheel events have been added.  What about 
horizontal? Thinkpads have had 4-way scrolling for at least 5 years now. New 
mice have 4-way scrollwheels too.
Comment 27 Steve Northover CLA 2004-11-30 10:32:42 EST
We simply don't have the hardware to try it.  Can you confirm that the native 
windows controls such as the tree respect wheel direction? 
Comment 28 Randy Hudson CLA 2004-11-30 11:04:07 EST
Every SWT Control with an enabled horizontal scrollbar will scroll horizontally 
just fine. Come one, Steve, you guys have to have a T2x, T30, or T40 somewhere 
in Ottawa. I would have a harder time getting a pencil down here :-). You hold 
the blue button in the middle.

I don't really see us using the horizontal axis immediately, but if your going 
to add interfaces/constants and such you might want to do it all-at-once.
Comment 29 Steve Northover CLA 2004-11-30 11:09:13 EST
I agree.  FH to find the hardware and check it out.  Like I said, I don't have 
one and none of the desktop machines here have one either.
Comment 30 Felipe Heidrich CLA 2004-11-30 11:47:09 EST
We have added support for one axis wheel only. The problem for adding 4-way 
wheel was not only hardware (cause that is easy to get), it was cause the only 
platform where the support for it was obvious is Mac OS.
I looked in MSDN and I couldn't find how to do it for Windows (WM_MOUSEWHEEL 
is not the answer). In X and GTK it is much worse, to have one axis wheel 
working was hard (and hacky) enough.
Comment 31 Randy Hudson CLA 2004-11-30 13:05:06 EST
How ironic, given that the Mac ships with the most incapable mouse of any PC 
sold in the last 20 years.
Comment 32 Stefan Zeiger CLA 2004-11-30 14:25:38 EST
Here's an MSDN article which shows how to handle horizontal scrolling, both on
Longhorn (with WM_MOUSEHWHEEL) and on 2000/XP (with IntelliMouse messages):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/BestPracticesforSupportingMicrosoftMouseandKeyboardDevices.asp
Comment 33 Felipe Heidrich CLA 2004-11-30 14:46:50 EST
Thanks for the article, interesting:
"Currently, there is no operating system support for the tilt wheel. Microsoft 
IntelliType Pro or IntelliPoint software—for keyboards and mouse devices, 
respectively—must be installed to enable this functionality. With the software 
installed, horizontal scrolling works for many applications."
...
"The upcoming Microsoft operating system, code-named "Longhorn," will 
implement the WM_MOUSEHWHEEL message to support tilt wheels."

Comment 34 Pratik Shah CLA 2005-01-24 16:59:13 EST
If I understand this correctly, whenever the user uses the mouse wheel, SWT 
will fire a mouseDown event (with button == SWT.BUTTON4 or BUTTON5)?  Is that 
right?  I've written a simple snippet which launches an SWT control and prints 
out some text when the mouseDown event is fired.  Nothing is printed out when 
I use the mouse wheel.
Comment 35 Steve Northover CLA 2005-01-24 17:02:31 EST
Nope.  Look for SWT.MouseWheel.
Comment 36 Pratik Shah CLA 2005-01-24 17:28:21 EST
Aaaah.  Thanks, Steve.  So, now what are SWT.BUTTON4 and SWT.BUTTON5 used for?
Comment 37 Pratik Shah CLA 2005-01-24 17:29:33 EST
Nevermind.  I figured it out.
Comment 38 Randy Hudson CLA 2005-01-24 19:59:09 EST
The IBM trackpad does not generate the new scroll events. It doesn't actually 
simulate a scrollwheel, but sends WM_SCROLL events directly to the canvas.  
Here's partial stacktrace when the trackpad causes scrollbar to fire selection 
changed:

FigureCanvas(Scrollable).wmScroll(ScrollBar, boolean, int, int, int, int) line: 
389
FigureCanvas(Scrollable).WM_VSCROLL(int, int) line: 336
FigureCanvas(Control).windowProc(int, int, int, int) line: 3089
Display.windowProc(int, int, int, int) line: 3370
OS.PeekMessageW(MSG, int, int, int, int) line: not available [native method]
OS.PeekMessage(MSG, int, int, int, int) line: 1994
Display.readAndDispatch() line: 2443

So is it possible to hook in at the WM_VSCROLL point and intercept the message 
and do something else with it? How can you tell it apart from when the user 
clicks on the scrollbar?  Swing *does* work with the trackpad scrolling, but 
only vertically.