Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 287083

Summary: [GTK] KeyListener on Table doesn't receive KeyEvents
Product: [Eclipse Project] Platform Reporter: Mitchell Johnson <ehntoo>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Bogdan Gheorghe <gheorghe>
Severity: normal    
Priority: P3 CC: ericwill, pinnamur, Silenio_Quarti
Version: 3.5Keywords: helpwanted, triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard: stalebug

Description Mitchell Johnson CLA 2009-08-19 10:55:42 EDT
On Fedora 11, GTK 2.16.5

The following example creates a shell with a table with a few items in it and adds a KeyListener.  The keyPressed and keyReleased methods do not get called, with the exception of keyPressed for the first character typed and keyReleased for ESC.

--------------------------------------

import java.util.regex.Pattern;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class TableExample {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        table.setLinesVisible(true);
        for (int i = 0; i < 2; i++) {
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setWidth(100);
        }
        String[] itemsToAdd = new String[] {
                "Cheese", "Potatoes", "Rocks", "Bacon", "Tree", "Forest", "Chocolate", "Broccoli", "Turnip",
                "Squash", "Carrot"
        };
        int i = 0;
        for (String s : itemsToAdd) {
            TableItem item = new TableItem(table, SWT.NONE);
            item.setText(new String[] {
                    s, "" + i++
            });
        }
        table.addKeyListener(new KeyListener() {
            public void keyPressed(KeyEvent e) {
                System.out.println(e.character);
            }

            public void keyReleased(KeyEvent e) {
                System.out.println(e.character);
            }
        });
        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}
Comment 1 Mitchell Johnson CLA 2009-08-22 18:43:19 EDT
After some more tests, bug is also reproducible in SWT 3.5
Comment 2 Praveen CLA 2009-11-02 02:06:12 EST
When any text is typed on Tree widget, GtkTreeView pops up an entry widget for displaying search text. Thus, all the characters entered are filled into the entry widget and thus, GtkTreeView has no knowledge on the keys pressed.

I think we can workaround to get the key press/release on tree widget though the search entry captures the key events using search positioning callback functions. Bogdan, since this is the native behavior, do we still need to implement this (to prevent the incosistency), or is it expensive way of achieving this ?
Comment 3 Mitchell Johnson CLA 2010-02-13 11:15:57 EST
(In reply to comment #2)
> When any text is typed on Tree widget, GtkTreeView pops up an entry widget for
> displaying search text. Thus, all the characters entered are filled into the
> entry widget and thus, GtkTreeView has no knowledge on the keys pressed.
> 
> I think we can workaround to get the key press/release on tree widget though
> the search entry captures the key events using search positioning callback
> functions. Bogdan, since this is the native behavior, do we still need to
> implement this (to prevent the incosistency), or is it expensive way of
> achieving this ?

In any case, I haven't found any other method to extract key events from a table, which is hindering my progress.  If I could somehow interact with the entry widget that pops up, that would be even better in my case.
Comment 4 Eric Williams CLA 2017-06-30 09:56:59 EDT
This bug is reproducible on Eclipse 4.7, Fedora 25 with GTK3.22.15.

Bug triaged, visit https://wiki.eclipse.org/SWT/Devel/Triage for more
inforamation.
Comment 5 Eclipse Genie CLA 2020-06-22 16:42:04 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.