Bug 169552 - Not easily possible to programmatically scroll a Scrollable
Summary: Not easily possible to programmatically scroll a Scrollable
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-04 10:16 EST by Benjamin Pasero CLA
Modified: 2007-03-13 18:15 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Pasero CLA 2007-01-04 10:16:23 EST
Eclipse 3.2/3.3
OS: Windows

I would like to programmatically send a Mouse-Wheel-Event to a different Scrollable. The idea is to scroll a Scrollable, even if its not having focus (note that Linux provides this for free). Consider this snippet:

public class Main {
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Table t = new Table(shell, SWT.None);
    for (int i = 0; i < 100; i++) {
      new TableItem(t, SWT.None).setText("Hello World");
    }

    t = new Table(shell, SWT.None);
    for (int i = 0; i < 100; i++) {
      new TableItem(t, SWT.None).setText("Hello World");
    }

    display.addFilter(SWT.MouseWheel, new Listener() {
      public void handleEvent(final Event event) {
        final Control cursorControl = display.getCursorControl();
        if (!cursorControl.isFocusControl()) {
          event.doit = false;
          cursorControl.setFocus();

          event.widget = cursorControl;

          cursorControl.notifyListeners(SWT.MouseWheel, event);
          display.post(event);
        }
      }
    });

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
}

Move the mouse over the second Table to the right and begin scrolling. As you can see, the Table gets focus and begins scrolling, but only for the second scroll-event, not the first one. While its possible to ignore the event for the first Table (event.doit = false), its not possible to send it to the second Table (see my two proposed solutions in lines 26 and 27). It would be cool for this "feature" (I know its working around common OS behavior at least on windows, but tons of people have asked me about it), if also the first mouse-wheel-event is resulting in the second Table to scroll accordingly.

Ben
Comment 1 Benjamin Pasero CLA 2007-01-05 03:33:25 EST
Of course, if it was possible to send this event to the second table, the call to control.setFocus() is no longer necessary (which is a lot better to the current solution).

Ben
Comment 2 Benjamin Pasero CLA 2007-01-30 09:41:28 EST
See also Bug 172167
Comment 3 Benjamin Pasero CLA 2007-03-13 17:17:49 EDT
I think this is fixed in recent builds, right steve?
Comment 4 Steve Northover CLA 2007-03-13 18:02:09 EDT
Yes.  Display.post() accepts SWT.MouseWheel, however, you probably should not be overriding the mouse wheel behavior of the operating system.  Close?
Comment 5 Benjamin Pasero CLA 2007-03-13 18:09:55 EDT
Ok with me.
Comment 6 Steve Northover CLA 2007-03-13 18:15:22 EDT
Ok, WONTFIX this.