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

Bug 312734

Summary: Incorrect GC colors on Table's PaintItem event when row selected + no EraseItem
Product: [Eclipse Project] Platform Reporter: ArronM <arronm>
Component: SWTAssignee: Grant Gayed <grant_gayed>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: grant_gayed, Silenio_Quarti, skovatch
Version: 3.6Flags: Silenio_Quarti: review+
skovatch: review+
Target Milestone: 3.6 RC2   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
patch none

Description ArronM CLA 2010-05-12 20:26:40 EDT
Build Identifier: SWT3647

When a table has a PaintItem listener but no EraseItem listener, the PaintItem's event.GC will not have the correct Foreground and Background color.

Run the snippet below and select the first row of each table.  When in focus, the table without the EraseItem will have wrong colors.

Reproducible: Always

Steps to Reproduce:
Snippet:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

public class testTableFG
{

	public static void main(String[] args) {
		Display display = new Display();
		Shell shellMain = new Shell(display, SWT.SHELL_TRIM);
		shellMain.setLayout(new FillLayout(SWT.VERTICAL));

		Table table = new Table(shellMain, SWT.BORDER);
		new TableColumn(table, SWT.RIGHT);
		new TableItem(table, SWT.NONE).setText("setText");
		table.getColumn(0).setWidth(300);

		table.addListener(SWT.PaintItem, new Listener() {
			public void handleEvent(Event event) {
				Rectangle bounds = ((TableItem) event.item).getBounds(event.index);
				event.gc.fillRectangle(bounds.x + 5, bounds.y, 10, bounds.height);
				event.gc.drawText("drawnText/No EraseItem", bounds.x + 20, bounds.y, true);
			}
		});
		
		/////////////////////

		Table table2 = new Table(shellMain, SWT.BORDER);
		new TableColumn(table2, SWT.RIGHT);
		new TableItem(table2, SWT.NONE).setText("setText");
		table2.getColumn(0).setWidth(300);

		table2.addListener(SWT.PaintItem, new Listener() {
			public void handleEvent(Event event) {
				Rectangle bounds = ((TableItem) event.item).getBounds(event.index);
				event.gc.fillRectangle(bounds.x + 5, bounds.y, 10, bounds.height);
				event.gc.drawText("drawnText/EraseItem", bounds.x + 20, bounds.y, true);
				
			}
		});
		
		table2.addListener(SWT.EraseItem, new Listener() {
			public void handleEvent(Event event) {
			}
		});

		////////////////
		
		shellMain.open();

		while (!shellMain.isDisposed()) {
			try {
				if (!display.readAndDispatch())
					display.sleep();
			} catch (Throwable t) {
				t.printStackTrace();
			}
		}
		display.dispose();
	}
}
Comment 1 ArronM CLA 2010-05-12 20:32:58 EDT
I haven't double checked, but I think I saw the same behavior on Tree widgets as well
Comment 2 Scott Kovatch CLA 2010-05-12 23:43:10 EDT
(In reply to comment #1)
> I haven't double checked, but I think I saw the same behavior on Tree widgets
> as well

That wouldn't surprise me. The implementations are very similar.
Comment 3 Grant Gayed CLA 2010-05-14 16:59:48 EDT
SSQ as part of Table revision 1.131 (no associated bug report) you added line "boolean hasFocus = hooksErase && hasFocus ();".  Do you remember if there was a reason for the hooksErase part?  hasFocus is only referenced in the block that immediately follows, and in a block further down where hooksErase is already known to be true, so I believe this fix is safe.
Comment 4 Grant Gayed CLA 2010-05-14 17:00:19 EDT
Created attachment 168613 [details]
patch
Comment 5 Grant Gayed CLA 2010-05-14 17:00:52 EDT
SSQ see comment 3.
Comment 6 Grant Gayed CLA 2010-05-18 11:16:03 EDT
Discussed with SSQ, he thinks having hooksErase there is wrong.
Comment 7 Scott Kovatch CLA 2010-05-18 12:42:22 EDT
Running the test with and without the patch so I can understand what's going on. Should have an answer shortly, but it looks good at first glance.
Comment 8 Scott Kovatch CLA 2010-05-18 12:58:22 EDT
Looks good. I'm building up my understanding of custom tree and table drawing, but I think this is the right change.
Comment 9 Grant Gayed CLA 2010-05-18 13:43:14 EDT
fixed > 20100518