Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 403474 - [GTK3] Problems setting background on latest
Summary: [GTK3] Problems setting background on latest
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 340067
  Show dependency tree
 
Reported: 2013-03-15 10:34 EDT by Silenio Quarti CLA
Modified: 2013-05-24 09:25 EDT (History)
1 user (show)

See Also:


Attachments
work in progress (2.83 KB, patch)
2013-03-26 12:02 EDT, Silenio Quarti CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Silenio Quarti CLA 2013-03-15 10:34:24 EDT
The changes in: 

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=7c1b8eca79b80c0d72e829a1c54df2844c3fbc3c

caused several problems:

1) NullPointerException when setting the color to null (should reset to default)

- Run ControlExample
- Check "Background Color" in the "Background Mode on Parent" group
- Uncheck same box

2) Every time the code in Control.setBackgroundColor (int, GdkColor) runs a new provider is created and added to the GtkStyleContext. I suspect this is a leak and not optimal. 

3) Controls are not inheriting the background image anymore since the code that was setting the alpha value was removed.

- run ControlExample
- Check "Background Image" in the "Background Mode on Parent" group
- Select SWT.INHERIT_DEFAULT
- The Button groups do not show the image background
Comment 1 Alexander Kurtakov CLA 2013-03-15 11:26:51 EDT
Silenio, I start to feel lost here. So function to set color doesn't work, if I have to respect background I would have to fetch it from style and construct a css that sets it too but I'm pretty sure we would face a case where smth else settable via css (e.g. font ) is lost as we override it in general. 
Any ideas on how this can be resolved if the function call simply doesn't work for us?
Comment 2 Alexander Kurtakov CLA 2013-03-15 11:27:45 EDT
Submited too fast. 
Maybe keeping a property of the full css per component which we modify and apply ?
Comment 3 Silenio Quarti CLA 2013-03-15 12:05:46 EDT
(In reply to comment #2)
> Submited too fast. 
> Maybe keeping a property of the full css per component which we modify and
> apply ?

I think that could work. We would have to stop using all gtk_widget_override_XXX in favor of our on style provider.   I am not sure how we would set the font though. Serializing it in CSS seems wrong. I think we would have to write our own GtkStyleProvider instead of using GtkCssProvider.

How can I reproduce the original problem you are trying to fix?
Comment 4 Alexander Kurtakov CLA 2013-03-15 12:38:39 EDT
The following snippet:
public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	Text text = new Text (shell, SWT.BORDER | SWT.V_SCROLL| SWT.SINGLE);
	text.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
	Rectangle clientArea = shell.getClientArea ();
	text.setBounds ( clientArea.x + 10, clientArea.y + 10, 200, 200);
	shell.open ();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}

Note on gtk 2.x the background is properly set to blue, while on gtk 3.x it's not.
Comment 5 Silenio Quarti CLA 2013-03-26 12:02:18 EDT
Created attachment 229049 [details]
work in progress

The GtkEntry background-color property in CSS is used as the selection color.  We can see this in the snippet by typing some test and selecting it.  It seems that the only way to change the background of a GtkEntry is to change its background-image property.  This patch changes the background-image with a linear gradient that is actualy a solid color.  It works on Fedora 17 and 18. It has an issue on Ubuntu 12.04: the selection color also changes.

The patch handles properly problems 1) and 2) of comment#0.  3) works for most widgets on Fedora 17, but fails for GtkEntry.   On Fedora 18, 3) does not work at all (see bug#404163).   The only pratical solution I see for bug#404163 is for us to implement our own GtkStyleProvider that has similar functionality as the gtk_widget_override_XXX functions, but also provides a way to override the background_image.  If we implement our own provide, this patch will probably have to be modified.

Note that the patch does not fix Spinner (need to run same code).
Comment 6 Silenio Quarti CLA 2013-03-26 12:42:32 EDT
(In reply to comment #5)

> It has an issue on Ubuntu 12.04: the selection color also changes.

This is not an issue at all. I did not reliaze that I was changing the background to some color that was very close to the default selection color on Ubuntu (orange color).
Comment 7 Silenio Quarti CLA 2013-04-03 11:08:12 EDT
See bug#404163 for more info on implementing our own GtkStyleProvider.  I have cleaned up this patch and released it since it is an improvement.

Fixed

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=d039075da3f3215b34e155a4c18404920facdf22