Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Making Controls out of existing native components


See http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm

NOTE: The article talks about creating controls in C, but doesn't address mouse or keyboard events.  The safest way to create a native control is to write your own native library instead of accessing the private classes in org.eclipse.swt.internal.* and subpackages (yes, they aren't real subpackages because Java doesn't have that).  Adding yourself to the package exposes you to the implementation details of the toolkit and makes your code fragile.  Having said all that, we haven't redesigned the platform interface (PI) for a while now.

It's a problem.  On Windows, OLE uses a HHOOK to see keys meant for OLE controls and deliver them to SWT composites.  Recently, the browser was rewritten to use DOM events for mouse and keyboard because we couldn't get the low level equivalents to Windows HHOOK's to work on all the platforms.  Specifically, Safari (written in cocoa) didn't play nice.

Rather than add API to wrap every single native handle that might be inside a C control that you wrap, I'd investigate operating system hooks and try to get mouse and keyboard that way.  We failed, but you might succeed.



Scott Kovatch <skovatch@xxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

03/28/2008 07:49 PM

Please respond to
"Eclipse Platform SWT component developers list."        <platform-swt-dev@xxxxxxxxxxx>

To
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
cc
Subject
[platform-swt-dev] Making Controls out of existing native components





Hello,

A coworker came up with an interesting problem. We are embedding a natively-created HIView into an SWT Canvas. Our HIView displays but doesn't receive mouse or key events because the SWT doesn't deliver events to HIViewRefs that it doesn't know about (i.e., that it created.)

The solution should be this: Create a subclass of Control that takes an int as a parameter, where the int is the handle to the pre-created native object. Instances of this subclass own the native control passed in at creation time, and will dispose of it when disposed. createHandle() is overridden to just stuff the int passed in at creation time into the 'handle', and then it gets registered with Display, and hookEvents() hangs the OS event handlers on the control.

Is it okay to subclass Control in this way? createHandle() is package private, so I don't see a good way to do this cleanly without putting the class in the SWT package. I'd like to avoid that if possible.

Scott

------------------
Scott Kovatch

Cupertino, CA

skovatch@xxxxxxx


_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top