Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Cocoa SWT: Access to mouse wheel / multitouch events? (continued from SWT Dev List)
Cocoa SWT: Access to mouse wheel / multitouch events? (continued from SWT Dev List) [message #493814] |
Wed, 28 October 2009 07:49 |
Stefan Muller Arisona Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Hi,
Is there a way to get mouse wheel or multitouch events into an Cocoa
SWT application? I know we get "ordinary" mouse wheel events. But how
would I obtain horizontal "wheel" information of a mightymouse's
scrollball? In additional Apple defined new events in 10.6 for
multitouch gestures, see:
http://developer.apple.com/mac/library/documentation/Cocoa/R eference/ApplicationKit/Classes/NSResponder_Class/Reference/ Reference.html
More generally, any plans/strategies for SWT to support this sort of
features across multiple platforms in future (e.g. windows 7
multitouch, if there is such a thing)?
Cheers /Stefan
See SWT#MouseHorizontalWheel
Added in Eclipse 3.6 M2
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=279884 for touch events.
Please, use the newsgroup for user questions in future.
Regards,
Felipe
Ok sorry, moved it to the forum.
Thus, is there any chance to achieve this in Eclipse 3.5? For example, could I somehow hook into the native (cocoa) Event processing mechanism?
Cheers /Stefan
|
|
|
Re: Cocoa SWT: Access to mouse wheel / multitouch events? (continued from SWT Dev List) [message #494240 is a reply to message #493814] |
Thu, 29 October 2009 16:46 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
"Stefan Muller Arisona" <sma@corebounce.org> wrote in message
news:hc8t2o$fk8$1@build.eclipse.org...
....
>
> Thus, is there any chance to achieve this in Eclipse 3.5? For example,
could I somehow hook into the native (cocoa) Event processing mechanism?
>
I don't know the full set of changes that was made for this, but on Cocoa I
think they were relatively straight-forward. If you browse references to
SWT.MouseHorizontalWheel you'll find three places, and these are most of the
changes. Cocoa just has one scroll wheel event that comes with horizontal
and vertical values, so I don't think any additional native listeners were
required.
There isn't an easy way to get this functionality without changing swt. I
tried a quick experiment of using Cocoa natives to get the SWTCanvasView
class and replaced its scrollWheel implementation with a locally-defined
callback to handle wheel events, but this only worked if swt's scrollWheel
implementation was commented out. Cocoa's class_replaceMethod native could
probably be used to replace swt's implementation, but class_replaceMethod is
not in swt, so you would have to compile it natively. I don't think it's
worth the effort to make this scenario work, but in case you feel like
playing, here's the stuff I hacked as a starting point.
public class Main {
static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int
/*long*/ theEvent) {
NSEvent nsEvent = new NSEvent(theEvent);
System.out.println("mouseWheel deltaY=" + nsEvent.deltaY() + " deltaX="
+ nsEvent.deltaX());
return 0;
}
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
event.gc.drawString("hi", 0, 0);
}
});
int /*long*/ cls = OS.objc_getClass("SWTCanvasView");
int /*long*/ oldImpl = OS.class_getMethodImplementation(cls,
OS.sel_scrollWheel_); // useful?
Callback windowCallback3 = new Callback(Main.class, "windowProc", 3);
// the next line fails if swt's scroll_wheel selector is already added
to cls
boolean success = OS.class_addMethod(cls, OS.sel_scrollWheel_,
windowCallback3.getAddress(), "@:@");
System.out.println("method added? " + success);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
windowCallback3.dispose();
display.dispose();
}
}
Grant
|
|
|
Goto Forum:
Current Time: Fri Apr 26 07:45:57 GMT 2024
Powered by FUDForum. Page generated in 0.02834 seconds
|