Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351494 - List is not displayed when using GridLayout on Linux with GTK+ >=2.18.4
Summary: List is not displayed when using GridLayout on Linux with GTK+ >=2.18.4
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.2   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.8 M1   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-07 17:35 EDT by Julio C. Chavez CLA
Modified: 2011-07-19 11:37 EDT (History)
2 users (show)

See Also:


Attachments
SWT Shell with a Grid Layout containing a List (806 bytes, text/x-java)
2011-07-07 17:35 EDT, Julio C. Chavez CLA
no flags Details
one line fix for List (976 bytes, patch)
2011-07-14 16:53 EDT, Felipe Heidrich CLA
no flags Details | Diff
patch fix 0x0 (780 bytes, patch)
2011-07-14 16:56 EDT, Felipe Heidrich CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julio C. Chavez CLA 2011-07-07 17:35:38 EDT
Created attachment 199302 [details]
SWT Shell with a Grid Layout containing a List

An org.eclipse.swt.widgets.List is not displayed when using in  an org.eclipse.swt.layout.GridLayout on Linux with GTK+ >=2.18.4 as it does in Windows (any) or other components in Linux (Text, Combo, etc.)

It requires to set explicitly the hints.

Having in a class:

:
private List list = null;
:
:	
shell = new Shell();
:
shell.setLayout(new GridLayout());
list = new List(shell, SWT.NONE);


Adds the List to the Shell, but is not displayed in Linux as it does in Windows.
Comment 1 Julio C. Chavez CLA 2011-07-07 17:39:42 EDT
Tested on Windows XP/7 (successfully)
Failing in Ubuntu 10.04 (GTK+ 2.20.1) and RHEL 6.1 (GTK+ 2.18.4).
Comment 2 Felipe Heidrich CLA 2011-07-11 09:38:29 EDT
okay, there is bug in your code.
You set the size to the shell (and the layout) before you add the list.
You can either 
- add a shell.layout() before calling shell.open();
- remove teh call to shell.setSize()
- move the call to shell.setSize() just before shell.open().

closing as not eclipse.
please reopen the bug if the above does not fix the problem.
Comment 3 Julio C. Chavez CLA 2011-07-11 10:43:00 EDT
None of the provided solutions worked. I also tried to add the list before the size was set, obtaining the same behavior (Verified in RH and Ubuntu)

The only solution I had found is to set manually the size.

Also, it's important to notice that the behavior in Windows and Linux is different, which is my major concern.

In case this differentiated behavior is expected, confirm to act subsequently.
Comment 4 Felipe Heidrich CLA 2011-07-11 10:57:55 EDT
does it work if you add a new items to the list ?

Try this
public class Test {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Test");
		shell.setLayout(new GridLayout());
		List list = new List(shell, SWT.NONE);
		list.add("Test");
		
		shell.setSize(300, 200);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 5 Arun Thondapu CLA 2011-07-12 07:46:16 EDT
(In reply to comment #4)
> does it work if you add a new items to the list ?

I tested this out and it works.

> 
> Try this
> public class Test {
> 
>     public static void main(String[] args) {
>         Display display = new Display();
>         Shell shell = new Shell(display);
>         shell.setText("Test");
>         shell.setLayout(new GridLayout());
>         List list = new List(shell, SWT.NONE);
>         list.add("Test");
> 
>         shell.setSize(300, 200);
>         shell.open();
> 
>         while (!shell.isDisposed()) {
>             if (!display.readAndDispatch())
>                 display.sleep();
>         }
>         display.dispose();
>     }
> }
Comment 6 Felipe Heidrich CLA 2011-07-12 09:28:43 EDT
(In reply to comment #5)
> (In reply to comment #4)
> > does it work if you add a new items to the list ?
> I tested this out and it works.

Please Arun check if computeSize for List returns 0,0 when the list is empty.
-than compare that to windows (I believe win32 returns 64,64 for a empty list)
-repease the same test for Table and Tree

Thank you
Comment 7 Arun Thondapu CLA 2011-07-13 08:36:37 EDT
(In reply to comment #6)
> 
> Please Arun check if computeSize for List returns 0,0 when the list is empty.
> -than compare that to windows (I believe win32 returns 64,64 for a empty list)
> -repease the same test for Table and Tree

Here are my observations:

1) computeSize() for empty List indeed returns 0,0 when the style is set to SWT.NONE. However, if the style is changed to SWT.DEFAULT, computeSize() returns non-zero values and the List is displayed as expected.

2) For empty Table and Tree, computeSize() always returns non-zero values and they are always displayed.

3) On Windows, computeSize() for empty List didn't return 0,0 but it wasn't 64,64
either. It was returning some non-zero values based on the style and layout selected.

4) I'm not completely sure whether computeSize returning 0,0 is the problem here
because I tried with an empty Combo and it was displayed though computeSize
returned 0,0 for it (both with SWT.NONE and SWT.DEFAULT).
Comment 8 Felipe Heidrich CLA 2011-07-13 10:37:16 EDT
Arun, SWT.DEFAULT is not valid style to create a widget. (it has the value of -1, it means all style bits are set).

In gtk, the computeSize of table and list are the same, can you tell why list returns 0,0 while table returns some non-zero result.


------------
Julio

In your app you should not relie on the size computeSize() returns for a empty list/table/tree. It will not be right size for the UI. You could:

- set the griddata in the list so it fills some space in the ui, or set hHint/vHint
- maybe you are missing a parent.layout() after adding items to the list
Comment 9 Arun Thondapu CLA 2011-07-14 10:51:01 EDT
(In reply to comment #8)
> Arun, SWT.DEFAULT is not valid style to create a widget. (it has the value of
> -1, it means all style bits are set).
> 
> In gtk, the computeSize of table and list are the same, can you tell why list
> returns 0,0 while table returns some non-zero result.

From what I see, it looks like this is a problem in GTK. If that is the case,
we might have to override the computeSize() method for List to return non-zero values?

> - set the griddata in the list so it fills some space in the ui, or set
> hHint/vHint

Setting griddata in the List does solve the problem but setting hHint or vHint in computeSize() didn't seem to fix it for me.
Comment 10 Felipe Heidrich CLA 2011-07-14 16:50:27 EDT
(In reply to comment #9)
> From what I see, it looks like this is a problem in GTK. If that is the case,
> we might have to override the computeSize() method for List to return non-zero
> values?

In GTK, List, Table and Tree are implemented using the same native control: 
GtkTreeView.
By default Table and Tree have scrollbars, List does not.
That explain why computeSize of Table and Tree return a size bigger than the computeSize of List.

On Windows, what I get for List/Table/Tree is 64x64 plus trim
List=67x64, Table=81x81, Tree=81x81

On Linux, what I get for List/Table/Tree is 0x0(*) plus trim
List=-1x0 (*), Table=18x18, Tree=18x18

- note width == -1 for List, this is bug that only happens for List.
I see that we fix this bug by adding this one line to List#createHandle
OS.gtk_tree_view_column_set_min_width (columnHandle, 0);
(note that Table and Tree have this line in their createHandle)
In my testcase, this is also causing this warning:
(SWT:18546): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -1 and height 0
Because setSize() gets called with -1x0

Also note that 18 is the size of the scrollbar (in my system), we you added my fix for List in your workspace and use SWT.NO_SCROLL to Table and Tree you will get all the computeSize()s to return 0x0. Likewise, if you can use SWT.V_SCROLL | SWT.H_SCROLL for List you will get them all to return 18x18.
Try this:
public class PR351494 {
public static void main(String[] args) {
	final Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new GridLayout());
	List list = new List(shell, SWT.NONE);
	System.out.println(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	Table table = new Table (shell, SWT.NO_SCROLL); 
	System.out.println(table.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	Tree tree = new Tree(shell, SWT.NO_SCROLL); 
	System.out.println(tree.computeSize(SWT.DEFAULT, SWT.DEFAULT));

	
	List list1 = new List(shell, SWT.V_SCROLL | SWT.H_SCROLL);
	System.out.println(list1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	Table table1 = new Table (shell, SWT.NONE); 
	System.out.println(table1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	Tree tree1 = new Tree(shell, SWT.NONE); 
	System.out.println(tree1.computeSize(SWT.DEFAULT, SWT.DEFAULT));

	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
}

should print:
Point {0, 0}
Point {0, 0}
Point {0, 0}
Point {18, 18}
Point {18, 18}
Point {18, 18}


> Setting griddata in the List does solve the problem but setting hHint or vHint
> in computeSize() didn't seem to fix it for me.

Sure, changing the grid data will not change the result of computeSize. But it will make the list visible in the parent.
Comment 11 Felipe Heidrich CLA 2011-07-14 16:53:16 EDT
Created attachment 199709 [details]
one line fix for List

This one liner fixes the -1 i'm getting from computeSize()
Comment 12 Felipe Heidrich CLA 2011-07-14 16:56:57 EDT
Created attachment 199711 [details]
patch fix 0x0

This patch changes computeSize to return 64x64 instead of 0x0 for empty controls.
This makes the code more consistent with windows.

----
Julio, I don't mind making this change, but I still expect that 64x64 is the wrong size for a control in your UI...
Comment 13 Felipe Heidrich CLA 2011-07-14 16:58:21 EDT
After applying both patches and running again the test case in comment 10 I got the following output:
Point {64, 64}
Point {64, 64}
Point {64, 64}
Point {82, 82}
Point {82, 82}
Point {82, 82}


Arun, can you please verify all the changes ? Thank you.
Comment 14 Arun Thondapu CLA 2011-07-15 10:49:31 EDT
(In reply to comment #13)
> 
> Arun, can you please verify all the changes ? Thank you.

I get a very similar output too:

Point {64, 64}
Point {64, 64}
Point {64, 64}
Point {80, 80}
Point {80, 80}
Point {80, 80}

This should fix all issues now including being consistent with Windows.
Thanks!