| Summary: | [Widgets] ExpandBar 'expanded' field negated AFTER firing ExpandEvent | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Graham Briggs <graham> |
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | Felipe Heidrich <eclipse.felipe> |
| Severity: | normal | ||
| Priority: | P3 | CC: | mccarl, Michael.Valenta, veronika_irvine |
| Version: | 3.2 | Keywords: | triaged |
| Target Milestone: | --- | ||
| Hardware: | Power PC | ||
| OS: | Windows All | ||
| Whiteboard: | stalebug | ||
Veronika has fixed this for me. Note: during the collapse the item has expand==true, and during the expand callback expand==false. This consistency with Tree widget. All platforms send the Expand and Collapse events before the state change occurs. This is consistent with the way the OS messages are sent and the way that the Tree Expand/Collapse Events behave.
The difference between Tree and ExpandBar is that in Tree, if you change the state during the event, the state change is respected (i.e. if in the Expand event you all TreeItem.setExpanded(true) the item remains expanded). On ExpandBar the state change is flippped (i.e. if in the Expand event you call ExpandItem.setExpanded(true) then the item will not be expanded when the event is finished)
See this example:
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
Tree tree = new Tree(shell, SWT.BORDER);
for (int i = 0; i < 10; i++) {
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText("item "+i);
for (int j = 0; j < 10; j++) {
TreeItem subItem = new TreeItem(item, SWT.NONE);
subItem.setText("item "+j);
for (int k = 0; k < 10; k++) {
TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
subsubItem.setText("item "+k);
}
}
}
tree.addListener(SWT.Expand, new Listener() {
public void handleEvent(Event e) {
TreeItem item = (TreeItem)e.item;
System.out.println("Expand Tree "+item+" "+item.getExpanded());
item.setExpanded(true);
System.out.println("Expand Tree 2 "+item+" "+item.getExpanded());
}
});
tree.addListener(SWT.Collapse, new Listener() {
public void handleEvent(Event e) {
TreeItem item = (TreeItem)e.item;
System.out.println("Collapse Tree "+item+" "+item.getExpanded());
item.setExpanded(false);
System.out.println("Collapse Tree 2 "+item+" "+item.getExpanded());
}
});
ExpandBar bar = new ExpandBar(shell, SWT.NONE);
ExpandItem item = new ExpandItem(bar, SWT.NONE);
item.setText("Item 1");
item = new ExpandItem(bar, SWT.NONE);
item.setText("Item 2");
bar.addListener(SWT.Expand, new Listener() {
public void handleEvent(Event e) {
ExpandItem item = (ExpandItem)e.item;
System.out.println("Expand ExpandBar "+item+" "+item.getExpanded());
item.setExpanded(true);
System.out.println("Expand ExpandBar 2 "+item+" "+item.getExpanded());
}
});
bar.addListener(SWT.Collapse, new Listener() {
public void handleEvent(Event e) {
ExpandItem item = (ExpandItem)e.item;
System.out.println("Collapse ExpandBar "+item+" "+item.getExpanded());
item.setExpanded(false);
System.out.println("Collapse ExpandBar 2 "+item+" "+item.getExpanded());
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
*** Bug 132021 has been marked as a duplicate of this bug. *** SelectionEvent.doit does not seem to work for ExpandEvent http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/events/class-use/ExpandEvent.html I use the workaround described in Comment #2, but sometimes I get a screen flicker while the state is temporarily set to collapsed. bar.addExpandListener(new ExpandListener(){ @Override public void itemCollapsed(ExpandEvent e) { if(boolExpandItemsLockedOpen){ //I would prefer this, but it doesn't work e.doit=false; //This is what I use so the state is toggled back to open ((ExpandItem)e.item).setExpanded(false); } } } Your bug has been moved to triage, visit http://www.eclipse.org/swt/triage.php for more info. This is a one-off bulk update. (The last one in the triage migration). Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process: https://wiki.eclipse.org/SWT/Devel/Triage See Bug 518478 for details. Tag for notification/mail filters: @TriageBulkUpdate 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. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. 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. -- The automated Eclipse Genie. |
In methods: LRESULT WM_KEYDOWN (...) {...} LRESULT WM_LBUTTONUP (...) {...} the ordering in the win32 codebase is: sendEvent (item.expanded ? SWT.Collapse : SWT.Expand, event); item.expanded = !item.expanded; this means that in your event handler code, if you try to get the status of the ExpandItem, or try to do resizing of components containing the ExpandBar, you will get an inconsistent result compared to other platforms. The ordering of the commands should be: item.expanded = !item.expanded; sendEvent (item.expanded ? SWT.Collapse : SWT.Expand, event); so that you get consistent results with other platforms, and what is naturally expected when you've received an ExpandEvent (namely that if it is an SWT.Expand event, then the relevant ExpandItem should already have expanded set to true).