[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

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 ();
}
}