Bug 528155 - [GTK] Table/Tree forgets to set SWT.SELECTED bit on PaintItem
Summary: [GTK] Table/Tree forgets to set SWT.SELECTED bit on PaintItem
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.7.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.7.3   Edit
Assignee: Eric Williams CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2017-12-05 09:56 EST by Thomas Singer CLA
Modified: 2018-02-23 15:18 EST (History)
2 users (show)

See Also:


Attachments
Sample code (3.17 KB, text/plain)
2017-12-05 09:57 EST, Thomas Singer CLA
no flags Details
wrong foreground color (unfocused) (9.00 KB, image/png)
2017-12-05 09:58 EST, Thomas Singer CLA
no flags Details
wrong foreground color (focused) (9.46 KB, image/png)
2017-12-05 09:58 EST, Thomas Singer CLA
no flags Details
Windows 10 - tree focused (4.46 KB, image/png)
2018-01-03 01:54 EST, Thomas Singer CLA
no flags Details
Windows 10 - table focused (4.72 KB, image/png)
2018-01-03 01:54 EST, Thomas Singer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Singer CLA 2017-12-05 09:56:48 EST
Please launch the attached sample code on Windows and Linux. It sets non-standard colors for tree and table cells. To make the table cell use the selected background color, the line

   event.detail &= ~SWT.SELECTED;

has to be added to the SWT.EraseItem listener. Unfortunately, this option is not set again in the SWT.PaintItem any more, so the foreground color cannot be set correctly. The commented code provides a work-around, but it depends on the event order and I'm not sure whether this is guaranteed to always be the case.
Comment 1 Thomas Singer CLA 2017-12-05 09:57:25 EST
Created attachment 271782 [details]
Sample code
Comment 2 Thomas Singer CLA 2017-12-05 09:58:00 EST
Created attachment 271783 [details]
wrong foreground color (unfocused)
Comment 3 Thomas Singer CLA 2017-12-05 09:58:20 EST
Created attachment 271784 [details]
wrong foreground color (focused)
Comment 4 Eric Williams CLA 2018-01-02 15:43:11 EST
I can reproduce the issue. It happens on GTK3.12+. This is with 4.8 master as of today.
Comment 5 Eric Williams CLA 2018-01-02 15:58:43 EST
Thomas could you attach a screenshot of your snippet running on Windows? So I have a reference of what the correct colours should be.
Comment 6 Eric Williams CLA 2018-01-02 16:19:57 EST
(In reply to Eric Williams from comment #4)
> I can reproduce the issue. It happens on GTK3.12+. This is with 4.8 master
> as of today.

Correction: 3.14+.
Comment 7 Thomas Singer CLA 2018-01-03 01:54:33 EST
Created attachment 272095 [details]
Windows 10 - tree focused
Comment 8 Thomas Singer CLA 2018-01-03 01:54:55 EST
Created attachment 272096 [details]
Windows 10 - table focused
Comment 9 Eric Williams CLA 2018-01-03 12:16:20 EST
Thanks for the windows screenshots. It turns out this bug happens on all GTK versions. I originally thought it didn't happen on 3.14- but as it turns out the platform default selection foreground for those versions happens to be black. This was causing me not to notice the bug.

I'll continue to investigate.
Comment 10 Eric Williams CLA 2018-01-04 10:51:16 EST
Thomas, in the snippet you provided I see that you are clearing the SWT.SELECTED bit for the Table EraseItem listener, but not the Tree EraseItem listener.

Is this not required for both? Reading this article: http://www.eclipse.org/articles/Article-CustomDrawingTableAndTreeItems/customDraw.htm#_tr30C

It says that the SWT.SELECTED bit should be cleared to ensure that the default selection background isn't drawn.

If you clear the SWT.SELECTED bit for both the Table and the Tree, then the bug manifests itself in both widgets.
Comment 11 Thomas Singer CLA 2018-01-04 13:10:27 EST
You are right, when adding the line

  event.detail &= ~SWT.SELECTED;

also to the tree's EraseItem listener, the "Windows 10 - table focused" image would show just one gray instead of the 2 grays.
Comment 12 Eric Williams CLA 2018-01-04 14:05:58 EST
(In reply to Thomas Singer from comment #11)
> You are right, when adding the line
> 
>   event.detail &= ~SWT.SELECTED;
> 
> also to the tree's EraseItem listener, the "Windows 10 - table focused"
> image would show just one gray instead of the 2 grays.

Okay. So both Table and Tree are broken on GTK.
Comment 13 Eclipse Genie CLA 2018-01-04 14:20:57 EST
New Gerrit change created: https://git.eclipse.org/r/114957
Comment 15 Eric Williams CLA 2018-01-04 14:46:48 EST
(In reply to Eclipse Genie from comment #14)
> Gerrit change https://git.eclipse.org/r/114957 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=ca42124d01c6987adde92880f9ba6d7d97f9f982

Bug snippet committed. Thanks again Thomas for providing excellent reproducer snippets!
Comment 16 Eclipse Genie CLA 2018-01-04 15:30:59 EST
New Gerrit change created: https://git.eclipse.org/r/114961
Comment 17 Eric Williams CLA 2018-01-04 15:36:08 EST
(In reply to Eclipse Genie from comment #16)
> New Gerrit change created: https://git.eclipse.org/r/114961

I have a proposed patch: Thomas please review.
Comment 18 Thomas Singer CLA 2018-01-05 03:55:05 EST
Looks similar to my work-around.
Comment 19 Eric Williams CLA 2018-01-05 10:32:05 EST
(In reply to Thomas Singer from comment #18)
> Looks similar to my work-around.

Yes, there is a corner case when having an EraseItem listener and PaintItem listener that deals with selection drawn. After the EraseItem is sent the drawState is cleared of the SWT.SELECTED bit.

I will continue to test and will merge if I don't find any issues.
Comment 21 Eric Williams CLA 2018-01-05 13:32:43 EST
(In reply to Eclipse Genie from comment #20)
> Gerrit change https://git.eclipse.org/r/114961 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=ac74a09868e8b5887cede3661179712181968312

Patch is in master.
Comment 22 Eclipse Genie CLA 2018-01-10 03:46:45 EST
New Gerrit change created: https://git.eclipse.org/r/115150
Comment 23 Andrey Loskutov CLA 2018-01-10 03:51:10 EST
Backport patch for 4.7.3: https://git.eclipse.org/r/#/c/115150/
Comment 25 Eric Williams CLA 2018-01-10 09:12:10 EST
(In reply to Eclipse Genie from comment #24)
> Gerrit change https://git.eclipse.org/r/115150 was merged to
> [R4_7_maintenance].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=2a77f729c852f703fea77d9c38322bafb65efae3

Patch backported.
Comment 26 Eric Williams CLA 2018-02-15 11:35:56 EST
Verified in M20180214-1700.