0

I've a weird issue,

I've a table with 2 columns and 3 rows each cell text can be edited at run time, when I edit the cell in the 3rd row second column I get the upper cell modified too with the same text this only occurs on redhat6 . works fine with rhe5 and rhe4 editor of type TextCellEditor;

  TableItem item = table.getItem(textEditor.getControl().getLocation());

getItem method implementation in Table.class is :

public TableItem getItem (Point point) {
    checkWidget();
    if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
     int /*long*/ [] path = new int /*long*/ [1];
    OS.gtk_widget_realize (handle);
     if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, path,null, null, null)) return null;
    if (path [0] == 0) return null;
    int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]);
    TableItem item = null;
    if (indices != 0) {
        int [] index = new int [1];
        OS.memmove (index, indices, 4);
        item = _getItem (index [0]);
    }
    OS.gtk_tree_path_free (path [0]);
    return item;
}

I thought it might be my GTK library . I have GTK2 lib installed.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
becks
  • 2,656
  • 8
  • 35
  • 64

1 Answers1

1

I think this error is triggered because the Text inside the TextEditorField field has some margins or minimum size that does not fit in the cell, or the row height is calculated incorrectly.

However, I suggest that you do not try to find the table item that the text editor is pointing at by using the getItem(Point), as there are probably other kinds of issues too, and this kind of behaviour cannot generally be guaranteed. I'd say that should be chiefly used to find "the one item that is being pointed to at by mouse." as in this question here. Actually you could be count yourself being lucky that you actually find out this bug.


The quick-and-dirty solution would be to calculate the center of the Text.getBounds() and use that to find the item, that is:

Rectangle bounds = textEditor.getControl().getBounds();
Point location = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
table.getItem(location);

But the better alternative, if you're running SWT >= 3.3, to use the TableViewerColumn.setEditingSupport(EditingSupport) to set the EditingSupport for each column, because with EditingSupport you can make the editor knowledgeable of which item it is editing within the table.

Community
  • 1
  • 1