Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Win] Accessibility: e.childID broken for Tree control (Snippet291) #645

Open
tmssngr opened this issue Apr 26, 2023 · 0 comments
Open

[Win] Accessibility: e.childID broken for Tree control (Snippet291) #645

tmssngr opened this issue Apr 26, 2023 · 0 comments

Comments

@tmssngr
Copy link
Contributor

tmssngr commented Apr 26, 2023

Describe the bug
Judging from the original Snippet291 example code, it looks like for TreeItems the handle is used as childID. This is broken, because the long handle of a TreeItem does not fit into the int of AccessibleEvent.childID.

To Reproduce
Please run the below (modified) snippet 291

import org.eclipse.swt.*;
import org.eclipse.swt.accessibility.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet291 {
	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Snippet 291");
		shell.setLayout(new FillLayout());
		final Tree tree = new Tree(shell, SWT.BORDER);
		for (int i = 0; i < 5; i++) {
			TreeItem treeItem = new TreeItem (tree, SWT.NONE);
			treeItem.setText ("item" + i);
			for (int j = 0; j < 3; j++) {
				TreeItem subItem = new TreeItem(treeItem, SWT.NONE);
				subItem.setText("item" + i + j);
			}
		}
		tree.getAccessible().addAccessibleListener(new AccessibleAdapter() {
			@Override
			public void getName(AccessibleEvent e) {
				if (e.childID == ACC.CHILDID_SELF) {
					e.result = "This is the Accessible Name for the Tree";
				} else {
					TreeItem item = (TreeItem)display.findWidget(tree, e.childID);
					if (item != null) {
						e.result = "This is the Accessible Name for the TreeItem: " + item.getText();
					}
					else {
						System.out.println("getName: no item found for " + Long.toHexString(e.childID));
					}
				}
			}
		});
		tree.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
			@Override
			public void getChildAtPoint(AccessibleControlEvent e) {
				final Point location = tree.toControl(e.x, e.y);
				final TreeItem item = tree.getItem(location);
				if (item != null) {
					System.out.println("getChildAtPoint " + Long.toHexString(item.handle));
				}
			}
		});
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
}

while a screenreader like NVDA is running. Moving the mouse over the tree items should speak something like "This is the Accessible Name for the TreeItem", but it doesn't. As you can see from the console, the long value of the handle is cut-off:

getName: no item found for ffffffffd929c800
getName: no item found for ffffffffd929c800
getName: no item found for ffffffffd929c800
getChildAtPoint 1fad929c800
getChildAtPoint 1fad929c800
getChildAtPoint 1fad929c800
...

Expected behavior
Well, AccessibleControlEvent.childID should be large enough to fit the control handle inside. Looks like it needs to be changed from int to long.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Only tried on Windows 11 so far.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant