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

Bug 461616

Summary: [GTK3] Combo improvements in background/foreground for gtk3
Product: [Eclipse Project] Platform Reporter: Leo Ufimtsev <lufimtse>
Component: SWTAssignee: Leo Ufimtsev <lufimtse>
Status: RESOLVED FIXED QA Contact: Leo Ufimtsev <lufimtse>
Severity: normal    
Priority: P3 CC: akurtako, akurtakov, Lars.Vogel, platform-swt-inbox
Version: 4.4   
Target Milestone: 4.5 M7   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/43481
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=f33dffd35460bbb5ed61c774ae7f89f06ed9eb7f
https://git.eclipse.org/r/45415
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=41bdd68738c0b4aa849e6a0d483da956ec49ea3d
https://bugs.eclipse.org/bugs/show_bug.cgi?id=531573
Whiteboard:
Bug Depends on:    
Bug Blocks: 464228    
Attachments:
Description Flags
Screenshot none

Description Leo Ufimtsev CLA 2015-03-06 14:04:16 EST
Combo's background JUnit test fails in GTK3 and foreground in GTK3 didn't work properly. 

I'll be submitting 2 patches to fix these shortly.
Comment 1 Leo Ufimtsev CLA 2015-03-09 17:21:40 EDT
Submitted single patch that addresses both as functionality was very similar. 

Incremental change to make Combo use rgba for foreground on Gtk3.
This also fixes combo's background for Gtk3, so that the Junit test now
works in gtk3.

object_set_..rgba required special attention. I added a line to os.h so
that it would also compile on gtk2 (as the GdkRGBA in the paramater list
is gtk3 only).  (As per suggestion of Alex.K)

Also introducing PRE_GTK3 constant for code clarity and readability.

Please review:
https://git.eclipse.org/r/43481
Comment 2 Leo Ufimtsev CLA 2015-03-10 15:41:26 EDT
Removed code from the patch that wasn't directly related to the fix.
Comment 4 Leo Ufimtsev CLA 2015-03-12 09:59:51 EDT
patch was merged.
Comment 5 Lars Vogel CLA 2015-03-18 08:30:14 EDT
(In reply to Leo Ufimtsev from comment #4)
> patch was merged.

I think this does not work. Here is a small snippet to check that the background of the combo is not set:

/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * CCombo example snippet: create a CCombo (read-only, flat)
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet39 {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new GridLayout());
		
		Combo combo = new Combo(shell, SWT.READ_ONLY | SWT.FLAT | SWT.BORDER);
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		for (int i = 0; i < 5; i++) {
			combo.add("item" + i);
		}
		combo.setText("item0");
		Color red = new Color (Display.getCurrent(), 255, 0, 0);
		combo.setBackground(red);

		combo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Item selected");
			}
		});

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}
Comment 6 Lars Vogel CLA 2015-03-18 08:30:52 EDT
Created attachment 251695 [details]
Screenshot
Comment 7 Alexander Kurtakov CLA 2015-03-18 09:10:10 EDT
Aha, the problem is visible for read only combos. It works for non-readonly.
Comment 8 Leo Ufimtsev CLA 2015-03-19 09:48:29 EDT
I'll investigate
Comment 9 Leo Ufimtsev CLA 2015-04-02 14:56:09 EDT
It seems that an SWT.Combo READ_ONLY is made up of nested Gtk Widgets:
GtkComboBoxText and inside it a: 
  GtkToggleButton

Applying a color to GtkComboBoxText doesn't perculate down to the GtkToggleButton inside. 

A fix would be to manually force it down to it's children like:
GtkComboBoxText GtkToggleButton { 
 background: yellow;
}

I wonder if this is a Gtk bug.

I'll continue to research this.
Comment 10 Eclipse Genie CLA 2015-04-07 15:24:03 EDT
New Gerrit change created: https://git.eclipse.org/r/45415
Comment 11 Leo Ufimtsev CLA 2015-04-07 17:18:26 EDT
I wrote patch #2:
https://git.eclipse.org/r/#/c/45415/

This fixes background for
- read-only combos
- partially colors the background in the drop down menu.

Now Eclipse looks like this with Dark OS theme and Dark Eclipse theme:
- Dark buttons
- Dark Read-only combo-boxes
https://coffeeorientedprogramming.files.wordpress.com/2015/04/eclipse-dark-looks.png

Limitations:
  - That said, GtkComboBoxText is composed of multiple widgets and some of those are tucked away in a private struct. As such, we can't style all of SWT combo. 
For instance we can style the Entry and the background of the text in the menu, but we can't style the down-button and can't style the menu background of the pop-up menu. Those can only be styled by global CSS. So if combo's menu/button doesn't look right, the OS's CSS needs to be changed.

I wrote an elaborate article on this for those interested in the details:
https://coffeeorientedprogramming.wordpress.com/2015/04/07/eclipse-dark-theme-and-gtk-what-eclipse-can-theme-and-what-needs-to-be-themed-by-the-os/

Any feedback is appreciated.
Comment 12 Lars Vogel CLA 2015-04-07 17:24:34 EDT
(In reply to Leo Ufimtsev from comment #11)
> I wrote patch #2:
> https://git.eclipse.org/r/#/c/45415/
> 
> This fixes background for
> - read-only combos
> - partially colors the background in the drop down menu.
> 
> Now Eclipse looks like this with Dark OS theme and Dark Eclipse theme:
> - Dark buttons
> - Dark Read-only combo-boxes
> https://coffeeorientedprogramming.files.wordpress.com/2015/04/eclipse-dark-
> looks.png

Beautiful. Please merge this, this is an amazing enhancement.
Comment 14 Alexander Kurtakov CLA 2015-04-08 08:21:35 EDT
Nice one. In master now.