[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Mouse scroll leads to different event raised on windows and MAC platform

Hi, sorry for the late response,

I see the difference that you describe.  The problem is that the mouse wheel
event that is received from Carbon on OSX does not contain information
indicating the magnitude that a mouse wheel scroll represents, so
PAGE_UP/PAGE_DOWN are just default guesses.  On Windows you see
ARROW_UP/ARROW_DOWN by default, but these are not always the case, because
there is a Windows setting that you can use to make your scroll wheel scroll
per-page, in which case the Selection event details will match between
Windows and OSX by coincidence.

That being said, relying on the Selection event's detail is not adequate
even if the default detail on OSX is changed to ARROW_UP/ARROW_DOWN.  For
example, these events can come with detail SWT.NONE if the user right-clicks
in a scrollbar trough and selects "Scroll Here" (XP and Vista).  As of 3.4
this detail can also indicate a per-pixel scroll (Vista).  So in general,
the best way to react to scrollbar Selection events is to just invoke
scrollbar.getSelection() to get the new value, and if you need to know how
much the selection changed by then remember it each time and subtract.  The
emulated Table and Tree that are in swt's motif port demonstrate this.

Grant


"Wang Wei" <wangwcdl@xxxxxxxxxx> wrote in message
news:baefcdfd19c5f4aee0b3a4d7ed028ed7$1@xxxxxxxxxxxxxxxxxx
> I've written a snippet to demonstrate the platform difference existing on
> the two platforms. I've created a canvas on a shell and added selection
> listener to the canvas' vertical scrollbar. On MAC platform, selection
> event's detail is SWT.PAGE_UP or SWT.PAGE_DOWN when scrolling the mouse
> while on windows platform, selection event's detail is SWT.ARROW_UP or
> SWT.ARROW_DOWN.
>
> In our custom table control, we draw the content on a canvas and add a
> selection listener to table's vertical scrollbar. As SWT.PAGE_DOWN is sent
> to this listener when mouse scrolls on MAC platform, table's content
> scrolls to another page. This behaviour is not what the user wants.
> Although we could capture SWT.MOUSE_WHEEL event, I don't know how to
> establish the relationship between mouse wheel event and scrollbar's
> selection events.
>
> As a matter of fact, I think this is a bug of SWT on MAC platform. When
> mouse wheel is moved, I think it's not quite reasonable to send
> SWT.PAGE_UP/SWT.PAGE_DOWN events.
>
> The following is the snippet I've written.
>
> package snippets;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.events.SelectionListener;
> import org.eclipse.swt.widgets.Canvas;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> public class ScrollBarTest {
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
>
> final Canvas canvas = new Canvas(shell, SWT.BORDER | SWT.V_SCROLL);
> canvas.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
> canvas.setSize(280, 700);
>
> if(canvas.getVerticalBar() != null) {
> canvas.getVerticalBar().addSelectionListener(new SelectionListener(){
>
> public void widgetDefaultSelected(SelectionEvent e) {
> }
>
> public void widgetSelected(SelectionEvent e) {
> switch(e.detail) {
> case SWT.PAGE_DOWN:
> System.out.println("Selection event detail is page down. ");
> break;
> case SWT.PAGE_UP:
> System.out.println("Selection event detail is page up. ");
> break;
> case SWT.ARROW_DOWN:
> System.out.println("Selection event detail is arrow down. ");
> break;
> case SWT.ARROW_UP:
> System.out.println("Selection event detail is arrow up. ");
> break;
> };
>
> }});
> }
>
> shell.setSize(300, 200);
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
> }
>