Bug 306051 - CTabFolder seems to eagerly select an item if a child control has focus set before it's attached to an item
Summary: CTabFolder seems to eagerly select an item if a child control has focus set b...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-16 13:23 EDT by Remy Suen CLA
Modified: 2019-11-14 03:23 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2010-03-16 13:23:34 EDT
That summary was a mouthful so here's the code to reproduce the problem. The idea here is that if you invoke setFocus() on a Control before it's set to a CTabItem, the folder will arbitrarily take that request and select the item at index 0.

--------------

Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(600, 400);
shell.open();

CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
for (int i = 0; i < 4; i++) {
  CTabItem item = new CTabItem(folder, SWT.CLOSE);
  item.setText("Item " + i);
  Text text = new Text(folder, SWT.MULTI);
  text.setText("Content for Item " + i);
  if (i == 3) {
    text.setFocus();
  }
  item.setControl(text);
}

shell.layout(true, true);

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

--------------

If setControl(Control) is invoked _before_ setFocus() is called on the control, then it will not eagerly select item 0.

--------------

Here's a stack trace of what I hit when debugging through e4 code.

	StackRenderer$5.widgetSelected(SelectionEvent) line: 409	
	TypedListener.handleEvent(Event) line: 228	
	EventTable.sendEvent(Event) line: 84	
	CTabFolder(Widget).sendEvent(Event) line: 1050	
	CTabFolder(Widget).sendEvent(int, Event, boolean) line: 1074	
	CTabFolder(Widget).sendEvent(int, Event) line: 1059	
	CTabFolder(Widget).notifyListeners(int, Event) line: 773	
	CTabFolder.setSelection(int, boolean) line: 2722	
	CTabFolder.onFocus(Event) line: 1306	
	CTabFolder$1.handleEvent(Event) line: 253	
	EventTable.sendEvent(Event) line: 84	
	CTabFolder(Widget).sendEvent(Event) line: 1050	
	CTabFolder(Widget).sendEvent(int, Event, boolean) line: 1074	
	CTabFolder(Widget).sendEvent(int) line: 1055	
	CTabFolder(Control).sendFocusEvent(int) line: 2597	
	CTabFolder(Widget).wmSetFocus(int, int, int) line: 2399	
	CTabFolder(Control).WM_SETFOCUS(int, int) line: 4771	
	CTabFolder(Control).windowProc(int, int, int, int) line: 4208	
	Display.windowProc(int, int, int, int) line: 4843	
	OS.SetFocus(int) line: not available [native method]	
	CTabFolder(Control).forceFocus() line: 978	
	CTabFolder(Control).setFixedFocus() line: 2959	
	CTabFolder(Composite).setFixedFocus() line: 1039	
	Composite(Control).fixFocus(Control) line: 936	
	Composite(Control).setVisible(boolean) line: 3386	
	CTabItem.setControl(Control) line: 301	
	StackRenderer.createTab(MElementContainer<MUIElement>, MUIElement) line: 277
Comment 1 Remy Suen CLA 2010-03-16 13:25:33 EDT
I forgot to mention that this problem is not "new" per se. It happens on M3 (I20091030-1201) and I20100309-0100.
Comment 2 Lars Vogel CLA 2019-11-14 03:23:15 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.