Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Why doesn't my Composite receive Keyboard events even after I call setFocus?
icon5.gif  Why doesn't my Composite receive Keyboard events even after I call setFocus? [message #502292] Mon, 07 December 2009 15:59
François POYER is currently offline François POYERFriend
Messages: 6
Registered: December 2009
Junior Member
Hi,

I'm trying to embed a C++ widget into an RCP/SWT application.

Right now, I'm creating a Composite, and giving the value of its handle field to the C++ widget so that it can attach itself to it. This works pretty well, since I can see my drawing appear where I expect it, and it repaints and resize nicely.
Mouse events are sent directly to the C++ side (the thrid party graphic libray I'm using, old ILOG Views to name it, does plug itslef in the system event loop for that) and this works nicely too.

My trouble is with keyboard events:
Since my C++ widget doesn't ask directly system for the keyboard focus (I tried that already: it works perfectly under windows, but under Linux Redhat, which Imy application is suppose to work with, it messes up SWT handling of keyboard focus afterwards ...) I tried the following code (relevant parts only):

public class MyWidget extends EditorPart {

private Composite drawingArea;

public void createPartControl(Composite parent) {
    // Maybe I should use style SWT.NO_BACKGROUND here? Or SWT.EMBEDDED?
    this.drawingArea = new Composite(parent, SWT.NONE);
    // Send value of this.drawingArea.handle to C++ for creation of the C++ widget

    this.drawingArea.addKeyListener(new KeyListener() {
            @Override
            public void keyPressed(KeyEvent e) {
                System.err.println("key pressed " + e.toString());
                // Send key event top C++
            }

            @Override
            public void keyReleased(KeyEvent e) {
                System.err.println("key released " + e.toString());
                // Send key event to C++
            }
        });
}

private void called_from_c_plus_plus() {
    // this code is called through JNI by C++
    // when a click in the C++ widget is detected
    if ( this.drawingArea != null)
        this.drawingArea.setFocus();
}


But neither methods of my KeyListener is ever called... What I am doing wrong here?
Why is SWT not sending the key events to my listener?

[Updated on: Mon, 07 December 2009 15:59]

Report message to a moderator

Previous Topic:TreeViewer with special rendering for items
Next Topic:Need some help in creating desktop application using SWT
Goto Forum:
  


Current Time: Tue Apr 23 11:13:55 GMT 2024

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

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

Back to the top