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

Bug 75284

Summary: Inconsistant getBounds() or fillRectangle() behaviour between linux and windows
Product: [Eclipse Project] Platform Reporter: Stephen Rowles <rowles>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: grant_gayed
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
windows correctly highlighting the grey cell
none
linux-gtk incorrectly highlighting the grey-cell
none
Incorrect alignment of cell in a table (as opposed to TableViewer)
none
Source code for modified SampleView.java none

Description Stephen Rowles CLA 2004-09-29 10:21:14 EDT
I use a TableViewer to create a table containing several rows of data.
As part of this I wish to "grey out" some selected cells in the table.

To do this I use a new GC placed on the table, and get the location of the cell
to draw a rectangle on by calling the getBounds(index) on the table item in the
table.

On windows this produces the correct behaviour, and the grey cell is perfectly
aligned with the required cell. On linux-gtk, the bound box appears to be out by
the size of the column heading titles. Additionally if you use a 
table, rather than a TableViewer() the cells almost line up but they appear
to be out by a few pixels on linux (see tablebug_linux.jpg attached file). It
would appear that the getBounds(index) call is not returning the correct
bounding rectangle in either case.

Below is the code needed to draw a simple table, it should highlight the cell
containing the words "item 1 col 1" as seen in the windows screen shot, but
on linux it draws the box in completely the wrong place.

Windows eclipse: 3.0.0 - 200406192000
Linux   eclipse: 3.0.1 - 200409161125

To re-create do the following:

1) Create a simple plugin, using the plugin with view wizard
2) replace the SampleView code with the code attached to the bug

Relevant painting section of the code is below:

  private void paintGreyCells() {
    // For each row...
    for (int i = 0; i < viewer.getTable().getItemCount(); i++) {
      // Get the table item, and check text to see if we grey it out
      TableItem tableItem = viewer.getTable().getItem(i);
      if (tableItem.getText(1).equals("item 1 col 1")) {
        tableItemGC.fillRectangle(tableItem.getBounds(1));
      }
    }
  }
Comment 1 Stephen Rowles CLA 2004-09-29 10:22:10 EDT
Created attachment 14883 [details]
windows correctly highlighting the grey cell
Comment 2 Stephen Rowles CLA 2004-09-29 10:22:43 EDT
Created attachment 14884 [details]
linux-gtk incorrectly highlighting the grey-cell
Comment 3 Stephen Rowles CLA 2004-09-29 10:24:14 EDT
Created attachment 14886 [details]
Incorrect alignment of cell in a table (as opposed to TableViewer)
Comment 4 Stephen Rowles CLA 2004-09-29 10:25:19 EDT
Created attachment 14890 [details]
Source code for modified SampleView.java
Comment 5 Grant Gayed CLA 2004-09-30 13:05:03 EDT
Note that there's new api on TableItem in 3.0 for setting an individual cell's
foreground, background and font.  This might be an easier approach.


*** This bug has been marked as a duplicate of 42416 ***