Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » carbon event handling
carbon event handling [message #441622] Tue, 17 August 2004 17:00 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.physarum.net

This is a multi-part message in MIME format.
--------------080409060703080105070404
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi, I'm wondering if somebody can help:

The code below installs a carbon event handler for mouse-down events,
using native methods from org.eclipse.swt.internal.carbon.*. The strange
thing is that it doesn't seem to receive mouse-down events from
left-clicks (primary button?), but it works for right-clicks.

The reason I'm using carbon events instead of SWT's is that I'm planning
to interface with a mac tablet (wacom) driver, which generates Carbon
tablet events. So I'll be adding constants like:

public static final int kEventClassTablet = ('t'<<24) + ('b'<<16) +
('l'<<8) + 't';

, and use them with OS.InstallEventHandler, etc.

---

/* snip */

Object target = new Object() {
int mouseProc(int nextHandler, int theEvent, int userData) {
switch (OS.GetEventKind(theEvent)) {
case OS.kEventMouseDown:
System.out.println("Mouse Down");
return OS.eventNotHandledErr;
}
return OS.eventNotHandledErr;
}};

final Callback mouseCallback = new Callback(target, "mouseProc", 3);
int mouseProc = mouseCallback.getAddress();
if (mouseProc == 0) {
mouseCallback.dispose();
return;
}

int[] mask = new int[] { OS.kEventClassMouse, OS.kEventMouseDown };
OS.InstallEventHandler(OS.GetApplicationEventTarget(), mouseProc,
mask.length/2, mask, 0, null);

/* snip */

(Full code attached).

Thanks,
stan

--------------080409060703080105070404
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name="MouseEvents.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MouseEvents.java"

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

import org.eclipse.swt.internal.carbon.*;
import org.eclipse.swt.internal.Callback;

public class MouseEvents
{
public static void main (String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(500, 500);

Object target = new Object() {
int mouseProc(int nextHandler, int theEvent, int userData) {
switch (OS.GetEventKind(theEvent)) {
case OS.kEventMouseDown:
System.out.println("Mouse Down");
return OS.eventNotHandledErr;
}
return OS.eventNotHandledErr;
}};

final Callback mouseCallback = new Callback(target, "mouseProc", 3);
int mouseProc = mouseCallback.getAddress();
if (mouseProc == 0) {
mouseCallback.dispose();
return;
}

int[] mask = new int[] { OS.kEventClassMouse, OS.kEventMouseDown };
OS.InstallEventHandler(OS.GetApplicationEventTarget(),
mouseProc, mask.length/2, mask, 0, null);

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

--------------080409060703080105070404--
Re: carbon event handling [message #441626 is a reply to message #441622] Tue, 17 August 2004 20:47 Go to previous messageGo to next message
Silenio Quarti is currently offline Silenio QuartiFriend
Messages: 31
Registered: July 2009
Member
Try adding the mouse down handler to the window too. I am not sure why,
but I believe this is necessary. See Shell.hookEvents() for an example.

....
int windowTarget = OS.GetWindowEventTarget (shellHandle);
OS.InstallEventHandler (windowTarget, windowProc, mask1.length / 2, mask1,
shellHandle, null);
int [] mask2 = new int [] {
OS.kEventClassMouse, OS.kEventMouseDown,
OS.kEventClassMouse, OS.kEventMouseDragged,
// OS.kEventClassMouse, OS.kEventMouseEntered,
// OS.kEventClassMouse, OS.kEventMouseExited,
OS.kEventClassMouse, OS.kEventMouseMoved,
OS.kEventClassMouse, OS.kEventMouseUp,
OS.kEventClassMouse, OS.kEventMouseWheelMoved,
};
OS.InstallEventHandler (windowTarget, mouseProc, mask2.length / 2, mask2,
shellHandle, null);
....

Silenio


Stanley Gunawan wrote:

> Hi, I'm wondering if somebody can help:

> The code below installs a carbon event handler for mouse-down events,
> using native methods from org.eclipse.swt.internal.carbon.*. The strange
> thing is that it doesn't seem to receive mouse-down events from
> left-clicks (primary button?), but it works for right-clicks.

> The reason I'm using carbon events instead of SWT's is that I'm planning
> to interface with a mac tablet (wacom) driver, which generates Carbon
> tablet events. So I'll be adding constants like:

> public static final int kEventClassTablet = ('t'<<24) + ('b'<<16) +
> ('l'<<8) + 't';

> , and use them with OS.InstallEventHandler, etc.

> ---

> /* snip */

> Object target = new Object() {
> int mouseProc(int nextHandler, int theEvent, int userData) {
> switch (OS.GetEventKind(theEvent)) {
> case OS.kEventMouseDown:
> System.out.println("Mouse Down");
> return OS.eventNotHandledErr;
> }
> return OS.eventNotHandledErr;
> }};

> final Callback mouseCallback = new Callback(target, "mouseProc", 3);
> int mouseProc = mouseCallback.getAddress();
> if (mouseProc == 0) {
> mouseCallback.dispose();
> return;
> }

> int[] mask = new int[] { OS.kEventClassMouse, OS.kEventMouseDown };
> OS.InstallEventHandler(OS.GetApplicationEventTarget(), mouseProc,
> mask.length/2, mask, 0, null);

> /* snip */

> (Full code attached).

> Thanks,
> stan
Re: carbon event handling [message #441628 is a reply to message #441626] Tue, 17 August 2004 22:55 Go to previous messageGo to next message
Brion Vibber is currently offline Brion VibberFriend
Messages: 21
Registered: July 2009
Junior Member
Silenio Quarti wrote:
> Try adding the mouse down handler to the window too. I am not sure why,
> but I believe this is necessary. See Shell.hookEvents() for an example.

IIRC events propagate from specific to general, so if there's already a
window event handler eating the events you won't see them in the
application handler.

See
http://developer.apple.com/documentation/Carbon/Conceptual/C arbon_Event_Manager/Concept/chapter_17_section_2.html

-- brion vibber (brion @ pobox.com)
Re: carbon event handling [message #441630 is a reply to message #441628] Wed, 18 August 2004 03:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.physarum.net

Thanks,

Although the second thing that I was about to ask was that:

OS.GetWindowEventTarget(shell.handle)

doesn't seen work (i.e. returns 0), although in Shell.java
(createHandle()), OS.GetWindowEventTarget() clearly gets used on a shell
handle (the result of creating a new window, a local var called
shellHandle). And yes, the value of shell.handle itself seems valid.

Thanks,
stan

Brion Vibber wrote:
> Silenio Quarti wrote:
>
>> Try adding the mouse down handler to the window too. I am not sure why,
>> but I believe this is necessary. See Shell.hookEvents() for an example.
>
>
> IIRC events propagate from specific to general, so if there's already a
> window event handler eating the events you won't see them in the
> application handler.
>
> See
> http://developer.apple.com/documentation/Carbon/Conceptual/C arbon_Event_Manager/Concept/chapter_17_section_2.html
>
>
> -- brion vibber (brion @ pobox.com)
Re: carbon event handling [message #441633 is a reply to message #441630] Wed, 18 August 2004 06:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.physarum.net

Stanley Gunawan wrote:

> Thanks,
>
> Although the second thing that I was about to ask was that:
>
> OS.GetWindowEventTarget(shell.handle)
>
> doesn't seen work (i.e. returns 0), although in Shell.java
> (createHandle()), OS.GetWindowEventTarget() clearly gets used on a shell
> handle (the result of creating a new window, a local var called
> shellHandle). And yes, the value of shell.handle itself seems valid.
>

Sorry, I forgot to mention that OS.GetControlEventTarget(shell.handle)
seems to work, but when passed to OS.InstallEventHandler, no events seem
to get noticed.
Interestingly, so does doing that to a button, e.g.:

Button button = new Button(shell, SWT.PUSH); button.setText("Push me!");
OS.InstallEventHandler(OS.GetControlEventTarget(button.handl e), ....);
etc.

So, it seems only GetApplicationEventTarget() works...

Any idea?

Thanks,
stan

> Thanks,
> stan
Re: carbon event handling [message #441634 is a reply to message #441633] Wed, 18 August 2004 07:08 Go to previous messageGo to next message
Silenio Quarti is currently offline Silenio QuartiFriend
Messages: 31
Registered: July 2009
Member
You need to pass "shellHandle" (which is a window handle) and not
"shell.handle" (which is a control handle). The problem is that
Shell.shellHandle is not public, but you can get the window handle given a
control handle with the following code:

int control = shell.handle;
int shellHandle = OS.GetControlOwner (control);

Silenio


Stanley Gunawan wrote:

> Stanley Gunawan wrote:

> > Thanks,
> >
> > Although the second thing that I was about to ask was that:
> >
> > OS.GetWindowEventTarget(shell.handle)
> >
> > doesn't seen work (i.e. returns 0), although in Shell.java
> > (createHandle()), OS.GetWindowEventTarget() clearly gets used on a shell
> > handle (the result of creating a new window, a local var called
> > shellHandle). And yes, the value of shell.handle itself seems valid.
> >

> Sorry, I forgot to mention that OS.GetControlEventTarget(shell.handle)
> seems to work, but when passed to OS.InstallEventHandler, no events seem
> to get noticed.
> Interestingly, so does doing that to a button, e.g.:

> Button button = new Button(shell, SWT.PUSH); button.setText("Push me!");
> OS.InstallEventHandler(OS.GetControlEventTarget(button.handl e), ....);
> etc.

> So, it seems only GetApplicationEventTarget() works...

> Any idea?

> Thanks,
> stan

> > Thanks,
> > stan
Re: carbon event handling [message #441636 is a reply to message #441634] Wed, 18 August 2004 07:30 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse.physarum.net

Silenio Quarti wrote:

> You need to pass "shellHandle" (which is a window handle) and not
> "shell.handle" (which is a control handle). The problem is that
> Shell.shellHandle is not public, but you can get the window handle given a
> control handle with the following code:
>

Thanks!! That fixed everything! =)

--
stan

> int control = shell.handle;
> int shellHandle = OS.GetControlOwner (control);
>
> Silenio
>
>
> Stanley Gunawan wrote:
>
>
>>Stanley Gunawan wrote:
>
>
>>>Thanks,
>>>
>>>Although the second thing that I was about to ask was that:
>>>
>>>OS.GetWindowEventTarget(shell.handle)
>>>
>>>doesn't seen work (i.e. returns 0), although in Shell.java
>>>(createHandle()), OS.GetWindowEventTarget() clearly gets used on a shell
>>>handle (the result of creating a new window, a local var called
>>>shellHandle). And yes, the value of shell.handle itself seems valid.
>>>
>
>
>>Sorry, I forgot to mention that OS.GetControlEventTarget(shell.handle)
>>seems to work, but when passed to OS.InstallEventHandler, no events seem
>>to get noticed.
>>Interestingly, so does doing that to a button, e.g.:
>
>
>>Button button = new Button(shell, SWT.PUSH); button.setText("Push me!");
>> OS.InstallEventHandler(OS.GetControlEventTarget(button.handl e), ....);
>>etc.
>
>
>>So, it seems only GetApplicationEventTarget() works...
>
>
>>Any idea?
>
>
>>Thanks,
>>stan
>
>
>>>Thanks,
>>>stan
>
>
>
Previous Topic:Flash Animation
Next Topic:Embedding MSWord with OLE
Goto Forum:
  


Current Time: Mon Sep 23 10:31:05 GMT 2024

Powered by FUDForum. Page generated in 0.04305 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top