Bug 404448 - [GTK3] Images of disabled buttons are not grayed out
Summary: [GTK3] Images of disabled buttons are not grayed out
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3.1   Edit
Assignee: Alexander Kurtakov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 340067
  Show dependency tree
 
Reported: 2013-03-27 10:25 EDT by Anatoly Spektor CLA
Modified: 2013-09-20 08:37 EDT (History)
4 users (show)

See Also:
Silenio_Quarti: review+


Attachments
Proposed fix (8.22 KB, patch)
2013-05-16 14:05 EDT, Arun Thondapu CLA
arunkumar.thondapu: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anatoly Spektor CLA 2013-03-27 10:25:06 EDT
Steps to reproduce:

1. Open Eclipse with GTK+3 
2. Create Sample project with sample class
3. Run it

Look into Console window - Terminate button is not faded even when the execution is over.
Comment 1 Anatoly Spektor CLA 2013-04-02 12:39:17 EDT
Snippet that shows the issue:

 (Run with both SWT_GTK3 = TRUE and SWT_GTK3 = FALSE and you will see the difference how disabled buttons are represented)



public class Snippet47 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);

	Image image = new Image (display, 20, 20);
	Color color = display.getSystemColor (SWT.COLOR_BLUE);
	GC gc = new GC (image);
	gc.setBackground (color);
	gc.fillRectangle (image.getBounds ());
	gc.dispose ();
	
	Image disabledImage = new Image (display, 20, 20);
	color = display.getSystemColor (SWT.COLOR_GREEN);
	gc = new GC (disabledImage);
	gc.setBackground (color);
	gc.fillRectangle (disabledImage.getBounds ());
	gc.dispose ();
	
	Image hotImage = new Image (display, 20, 20);
	color = display.getSystemColor (SWT.COLOR_RED);
	gc = new GC (hotImage);
	gc.setBackground (color);
	gc.fillRectangle (hotImage.getBounds ());
	gc.dispose ();
	
	ToolBar bar = new ToolBar (shell, SWT.BORDER | SWT.FLAT);
	Rectangle clientArea = shell.getClientArea ();
	bar.setBounds (clientArea.x, clientArea.y, 200, 32);
	for (int i=0; i<12; i++) {
		ToolItem item = new ToolItem (bar, 0);
		item.setImage (image);
		item.setDisabledImage (disabledImage);
		item.setHotImage (hotImage);
		if (i % 3 == 0) item.setEnabled (false);
	}
	
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	image.dispose ();
	disabledImage.dispose ();
	hotImage.dispose ();
	display.dispose ();
}
}
Comment 2 Arun Thondapu CLA 2013-05-16 14:05:22 EDT
Created attachment 231109 [details]
Proposed fix

It looks like this problem is caused by a GTK+ bug.
I have created the above patch based on the workaround described in this forum post - http://www.gtkforums.com/viewtopic.php?f=3&t=178411

I have done some testing and it is working well for me. I'll try to improve the patch with some documentation and I also need to add handling for setHotImage () and setDisabledImage ().

Silenio, kindly let me know what you think of these changes.

Thanks!
Comment 3 Silenio Quarti CLA 2013-05-21 11:09:18 EDT
(In reply to comment #2)
> I have done some testing and it is working well for me. I'll try to improve
> the patch with some documentation and I also need to add handling for
> setHotImage () and setDisabledImage ().

The patch works, but I am afraid it is leaking all images set in tool items. We would need to find a way of removing the buildin icon when it is not necessary anymore. I quickly searched and I could not find any way.
Comment 4 Alexander Kurtakov CLA 2013-07-29 08:28:33 EDT
After consulting with GTK developers we need to use the GIcon functions in order to enable shading. 
Patch pushed to master http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=c5d929b161f90dfb73413ce6147670bc8d05fb20
Comment 5 Silenio Quarti CLA 2013-07-29 16:09:46 EDT
These changes cause compilation errors while building are libraries.  GIcon is not available on RHEL 5 (GTK 2.10). I think we can just remove the cast since the native is dynamic.

  [sshexec] gcc -O -Wall -DSWT_VERSION=4402  -DLINUX -DGTK -I/bluebird/teamswt/swt-builddir/JDKs/x86/ibm-java2-i386-50/include -I/bluebird/teamswt/swt-builddir/JDKs/x86/ibm-java2-i386-50/include/linux -fPIC -m32 `pkg-config --cflags gtk+-2.0` -c os.c
  [sshexec] os.c: In function 'Java_org_eclipse_swt_internal_gtk_OS__1gtk_1image_1set_1from_1gicon':
  [sshexec] 
  [sshexec] os.c:11335: error: expected declaration specifiers or '...' before 'GIcon'
  [sshexec] 
  [sshexec] os.c:11335: error: 'GIcon' undeclared (first use in this function)
  [sshexec] 
  [sshexec] os.c:11335: error: (Each undeclared identifier is reported only once
  [sshexec] 
  [sshexec] os.c:11335: error: for each function it appears in.)
  [sshexec] 
  [sshexec] os.c:11335: error: expected expression before ')' token
  [sshexec] 
  [sshexec] make: *** [os.o] Error 1
Comment 6 Silenio Quarti CLA 2013-07-29 16:26:10 EDT
Took a closer look at the patch. We are passing a GdkPixbuf to a function that takes a GIcon. How does that work? Does gtk_image_set_from_gicon() converts the parameter?
Comment 7 Alexander Kurtakov CLA 2013-07-30 08:09:24 EDT
GIcon is an interface and GdkPixbuf implements it so we actually pass GIcon instance to the function. The cast to GIcon is dropped to fix compilation with GTK 2.10.
Comment 8 Alexander Kurtakov CLA 2013-07-30 08:58:05 EDT
Marking as fixed.
Comment 9 Silenio Quarti CLA 2013-07-30 09:53:42 EDT
(In reply to comment #7)
> GIcon is an interface and GdkPixbuf implements it so we actually pass GIcon
> instance to the function. The cast to GIcon is dropped to fix compilation
> with GTK 2.10.

Nice.
Comment 10 Alexander Kurtakov CLA 2013-08-13 15:39:54 EDT
Silenio, Ok to backport this for 4.3.1 too?
Comment 11 Silenio Quarti CLA 2013-08-14 13:19:06 EDT
Reopened to include in 4.3.1.

We usually only back port critical bugs like crashes and serious bugs that affect the usability of Eclipse.  I do not think this is the case for this bug, but it certainly improves the l&f of the GTK 3 port without affecting the GTK2 port. +1
Comment 12 Alexander Kurtakov CLA 2013-08-20 07:15:14 EDT
Backported 9e1e131..af26fb4  R4_3_maintenance -> R4_3_maintenance