Bug 99718 - [CCombo] Very long text in CCombo causes vertical scroll bar to disappear
Summary: [CCombo] Very long text in CCombo causes vertical scroll bar to disappear
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.2 M7   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact: Carolyn MacLeod CLA
URL:
Whiteboard:
Keywords:
: 308083 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-13 12:24 EDT by Alex Bernstein CLA
Modified: 2012-04-30 13:12 EDT (History)
6 users (show)

See Also:


Attachments
test snippet for CCombo (1.06 KB, text/java)
2009-03-26 09:55 EDT, Lakshmi P Shanmugam CLA
no flags Details
patch with code changes (2.33 KB, patch)
2009-04-06 10:54 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff
new patch with code changes (2.73 KB, patch)
2009-04-08 14:42 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff
patch (2.01 KB, patch)
2012-04-30 06:54 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Bernstein CLA 2005-06-13 12:24:40 EDT
If there are very long text in the CCombo, the vertical scrollbar of dropdown 
listbox disappears beyond the edge of the screen. I have seen defects 37329 and 
7946, but this is different, as it is not related to Properties view.
Comment 1 Alex Bernstein CLA 2005-06-15 14:40:41 EDT
The CCombo in question has GridData with FILL_BOTH attribute, and CCOmbo's 
parent has GridLayout.
Comment 2 Lakshmi P Shanmugam CLA 2009-03-26 09:55:43 EDT
Created attachment 129961 [details]
test snippet for CCombo

Created a snippet to understand the problem.

It has a very long text as one of the items in the List.

On running the snippet, we can see that the vertical drop-down arrow and part of the window is out of the screen.
We can either maximize the window or drag the window to bring the drop-down arrow into view. But, I'm not sure if this is a problem. I saw the same behavior with native Combo on windows. 
Carolyn, please tell me if this behavior has to be fixed?

The real problem I think is that when we click on the drop-down, the items are not in view and there is no horizontal scrollbar to bring them back into view and no way to scroll through the entire long String.
This scenario works fine for native Combo, the list items are in view and a horizontal scroll-bar is created.
Comment 3 Carolyn MacLeod CLA 2009-03-26 17:27:48 EDT
I agree that we do not need to fix the drop-down arrow being off to the side.
In addition to dragging or maximizing the window, the user can type ALT+down arrow to drop down the list.

However, as you noticed, there is no horizontal scroll bar. I think we should add one when it is needed, to be consistent with Combo. A work-around is for the user to select the item, and then they can see the entire text of the item by drag-scrolling in the CCombo. However, having an "as-needed" horizontal scrollbar is the best solution.

Here's a new snippet (I had to make the text longer because I have a fairly large monitor <g>). Please make sure that the horizontal scrollbar works with SWT.READ_ONLY style as well - thanks!

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class CComboTest {
    public static void main(String args[]) {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new GridLayout());
	
//	CCombo ccombo = new CCombo(shell, SWT.BORDER);
	CCombo ccombo = new CCombo(shell, SWT.READ_ONLY | SWT.BORDER);
//	Combo ccombo = new Combo(shell, SWT.BORDER);
//	Combo ccombo = new Combo(shell, SWT.READ_ONLY | SWT.BORDER);
	ccombo.setLayoutData(new GridData(GridData.FILL_BOTH));
	for (int i = 0; i < 6; i++) {
		ccombo.add("CCombo item" + i);
	}
	ccombo.add("verylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextaaaaddddddaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajjjjjjjjjjjjjjjjjjjjjjjjjjjjaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaend");
	ccombo.setText("CCombo item0");
	
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
    }
}
Comment 4 Lakshmi P Shanmugam CLA 2009-04-06 10:54:39 EDT
Created attachment 130999 [details]
patch with code changes

Created patch with the changes for the fix.

The horizontal scroll-bar was not showing up because:
1) The SWT.H_SCROLL style-bit was not being set for the List in CCombo. 
Patch fixes this by setting the SWT.H_SCROLL for the list by default. The user cannot set or unset this style-bit for CCombo (similar to Combo).

2) The size of combo is computed based on the size of the list and so that it fits into the screen. When user selects the drop-down list, the size of the list is computed again and its width is set to max of list width and combo width. So, for long text, the list goes out of the screen and the horizontal scroll-bar is not shown. 
Patch fixes this by setting the width of the pop-up list equal to the Combo width. Now, the pop-up list will not show-up wider than the Combo. Also, horizontal scroll-bar will show-up when required.
Comment 5 Carolyn MacLeod CLA 2009-04-06 13:02:02 EDT
This is good, but when the CCombo's width is set small, then the list is too small, and it does not have to be.

Notice that Combo behaves in a nice way when text in the list is wide, but not wider than the screen. To see this, here is a slightly modified snippet that sets the size of a Combo instead of letting it take its preferred size:

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class CComboTest {
    public static void main(String args[]) {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new GridLayout());
	
//	CCombo ccombo = new CCombo(shell, SWT.BORDER);
//	CCombo ccombo = new CCombo(shell, SWT.READ_ONLY | SWT.BORDER);
	Combo ccombo = new Combo(shell, SWT.BORDER);
//	Combo ccombo = new Combo(shell, SWT.READ_ONLY | SWT.BORDER);
//	ccombo.setLayoutData(new GridData(GridData.FILL_BOTH));
	ccombo.setLayoutData(new GridData(100, SWT.DEFAULT));
	for (int i = 0; i < 6; i++) {
		ccombo.add("CCombo item" + i);
	}
	ccombo.add("verylongtextverylongtextverylongtextverylongtextverylongtextend");
//	ccombo.add("verylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextaaaaddddddaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajjjjjjjjjjjjjjjjjjjjjjjjjjjjaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaend");
	ccombo.setText("CCombo item0");
	
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
    }
}
Comment 6 Lakshmi P Shanmugam CLA 2009-04-08 14:42:22 EDT
Created attachment 131322 [details]
new patch with code changes

Attached the modified patch.

I checked the behavior of native Combo in Windows and how the drop-down list width is computed for Combo in Windows. 

In Windows native Combo, 
1)The list appears without scroll-bar if its width less than "max width". 
2)Horizontal scroll-bar is shown only when list width is greater than combo width and "max width".
3)"max width" is computed based on the monitor width.
4)Combo width is used for list width if it is bigger than the list width.
Modified the patch to compute the drop-down list of CCombo similarly. 

There is one difference. In native Combo, when list width is greater than combo width and "max width" and horizontal scroll-bar appears, list width is set to width of the second widest item in the list.
But, in the patch, for the same case, horizontal scroll-bar appears and list width is set to "max width". 
I think getting the above behavior of Combo in CCombo will require more computations during each drop-down action.
Comment 7 Lakshmi P Shanmugam CLA 2012-04-30 04:10:59 EDT
*** Bug 308083 has been marked as a duplicate of this bug. ***
Comment 8 Lakshmi P Shanmugam CLA 2012-04-30 06:54:23 EDT
Created attachment 214792 [details]
patch

I'm fixing Bug 377155 so thought of fixing this too as its in the same code.

The native Combo behavior on Windows seems to have changed on Windows 7, the horizontal scrollbar doesn't appear for long text and it behaves like CCombo.

The fix just shows the horizontal scrollbar when the list exceeds the screen width.
Comment 9 Lakshmi P Shanmugam CLA 2012-04-30 13:11:39 EDT
The fix is similar to patch in comment#6, but uses the display width instead of max width.
Fixed in master --> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=76d87459485522b738a95727f71967c4ec0ae0c0

and R3_8_maintenance --> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?h=R3_8_maintenance&id=8fca564c7eabdd6cfc889b64b319cd266157d621