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

Bug 464816

Summary: [Gtk3] Adding SWT.EraseItem listener and drawing background makes the TreeItem/TableItem text dissapear
Product: [Eclipse Project] Platform Reporter: Fabio Zadrozny <fabiofz>
Component: SWTAssignee: Sravan Kumar Lakkimsetti <sravankumarl>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: akurtakov, arunkumar.thondapu, daniel_megert, Lars.Vogel, lufimtse, niraj.modi, sravankumarl
Version: 4.5Flags: arunkumar.thondapu: review+
Target Milestone: 4.5 RC1   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/46731
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=c84205ca5d69149c76901442667dd91c7dbb3f53
Whiteboard:
Attachments:
Description Flags
Image showing issue none

Description Fabio Zadrozny CLA 2015-04-16 12:46:34 EDT
Currently adding an EraseItem listener makes the foreground of the item disappear on Linux (works on Windows).

Checked on VirtualBox with Ubuntu 12.04 and Eclipse 4.5m6.

Gtk version:
dpkg -s libgtk2.0-0|grep '^Version' 
has shown 2.24.10-0ubuntu6.1

To reproduce the issue I got the example from https://www.eclipse.org/articles/article.php?file=Article-CustomDrawingTableAndTreeItems/index.html (and just changed the Table for a Tree -- although I just checked the Table and it has exactly the same issue).

Code to reproduce the issue is below.

Display display = Display.getCurrent();
Shell shell = new Shell(display);
final Color red = display.getSystemColor(SWT.COLOR_RED);
final Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
final Tree tree = new Tree(shell, SWT.FULL_SELECTION);
tree.setHeaderVisible(true);
new TreeColumn(tree, SWT.NONE).setWidth(100);
new TreeColumn(tree, SWT.NONE).setWidth(100);
new TreeColumn(tree, SWT.NONE).setWidth(100);
for (int i = 0; i < 5; i++) {
    TreeItem item = new TreeItem(tree, SWT.NONE);
    item.setText(0, "item " + i + " col 0");
    item.setText(1, "item " + i + " col 1");
    item.setText(2, "item " + i + " col 2");
}
tree.pack();
tree.addListener(SWT.EraseItem, new Listener() {
    public void handleEvent(Event event) {
        event.detail &= ~SWT.HOT;
        if ((event.detail & SWT.SELECTED) == 0) {
            return; /* item not selected */
        }
        int clientWidth = tree.getClientArea().width;
        GC gc = event.gc;
        Color oldForeground = gc.getForeground();
        Color oldBackground = gc.getBackground();
        gc.setForeground(red);
        gc.setBackground(yellow);
        gc.fillGradientRectangle(0, event.y, clientWidth, event.height, false);
        gc.setForeground(oldForeground);
        gc.setBackground(oldBackground);
        event.detail &= ~SWT.SELECTED;
    }
});
shell.pack();
shell.open();
Comment 1 Fabio Zadrozny CLA 2015-04-16 12:46:57 EDT
Created attachment 252472 [details]
Image showing issue
Comment 2 Alexander Kurtakov CLA 2015-04-17 03:59:13 EDT
Which GTK 3 version is this ? On 3.16 I see the problem but also warnings about cell-background-gdk/foreground-gdk being deprecated. I'll investigate migrating to cell-background-rgba/foreground-rgba as noone really cares when feature deprecated 3 years ago (GTK 3.4) is no longer functioning properly.
Comment 3 Fabio Zadrozny CLA 2015-04-17 06:01:10 EDT
dpkg -s libgtk-3-0|grep '^Version'

Gives:

3.4.2-0ubuntu.8
Comment 4 Alexander Kurtakov CLA 2015-04-17 07:13:48 EDT
For full reference on GTK 3.16 all cells are empty as they are not recognized as pixbufs. Hardcoding it gives me same result as Fabio's image.
Comment 5 Sravan Kumar Lakkimsetti CLA 2015-04-24 04:10:19 EDT
This bug will take some more investigation so moving out of M7
Comment 6 Niraj Modi CLA 2015-04-29 01:58:17 EDT
Bug 427511 was RESOLVED_FIXED in 4.4-RC1, but surprisingly below commit was made against that bug 427511 in 4.5 time-frame, which is causing this bug 464816:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=77d858e5c6ed3ebe8fa843c1bb721ed789ee186a

Above commit removes some piece of code related to GTK3 w.r.t. "SWT.EraseItem" event in Tree#rendererRender() method.
Partially reverting above patch is fixing this bug 464816, refer associated Gerrit patch.
Comment 7 Eclipse Genie CLA 2015-04-29 01:59:03 EDT
New Gerrit change created: https://git.eclipse.org/r/46731
Comment 8 Sravan Kumar Lakkimsetti CLA 2015-04-29 02:31:11 EDT
The gerrit patch solves the problem for tree. but it still requres code changes for Table. Table also has the same issue
Comment 9 Arun Thondapu CLA 2015-05-07 07:10:17 EDT
Sravan, can you please mention in detail how the patch was tested (OS, GTK+ versions etc.) and also any regression testing?
Comment 10 Sravan Kumar Lakkimsetti CLA 2015-05-07 08:35:06 EDT
(In reply to Arun Thondapu from comment #9)
> Sravan, can you please mention in detail how the patch was tested (OS, GTK+
> versions etc.) and also any regression testing?

I used Fedora 19 with GTK3.8.8 and Ubuntu 14.04 with GTK 3.10 for testing.

Testing is done using the snippet provided and modified snippet for table as well. Ran the SWT Junit test cases. 

For regression testing used a self hosted eclipse and tested on multiple views like call hierarchy, Type hierarchy, etc. Verified that they are working fine.
Comment 12 Arun Thondapu CLA 2015-05-07 15:33:56 EDT
Pushed patch to master. Thanks Niraj and Sravan!
Comment 13 Sravan Kumar Lakkimsetti CLA 2015-05-14 09:09:15 EDT
verified in I20150513-2000 on linux 64bit