Accessibility for custom controls (RectControl > Canvas)


We’re making progress with automated testing in our app and our testing solution relies on the Accessibility framework to locate UI elements in the view hierarchy and work with them.

Common controls (Buttons, Labels, …) show up properly when we look with Accessibility Inspector, but custom controls (e.g. based on Canvas) do not. This is not unexpected.

If I were using Interface Builder, I would set the accessibility attributes right there in the UI, but I see no corresponding Xojo UI. There are also Cocoa methods to do it, but of course they do not work from Xojo.

Question: is there another way to set accessibility attributes in Xojo? Would that be possible through the Plugin API?

How do you handle accessibility issues in Xojo?

(Note: I found a plugin from Monkeybread Software that claims to be able to do this, but I can’t make heads or tails of it…)

Why do the Cocoa methods not work from Xojo? Should be possible to declare them.

Good point! Something like this?

declare sub NSView_accessibilitySetOverrideValue lib "Cocoa" selector "accessibilitySetOverrideValue:forAttribute:" ( handle as integer, overrideVal as Ptr, attributeVal as Ptr ) As Boolean NSView_accessibilitySetOverrideValue(self.Canvas9.Handle, app.MakeCFString("AXButton"), app.MakeCFString("AXRole")) NSView_accessibilitySetOverrideValue(self.Canvas9.Handle, Ptr(self.handle), app.MakeCFString("AXWindow"))

In theory that should be enough to tell the OS that Canvas9 (a Canvas object) is a button, and is rooted in the window (self.handle).

However, running with Accessibility Inspector stubbornly refuses to create an entry for Canvas9…

If you had a custom Canvas class, how could you make it accessible?

I‘m afraid that’s over my head. I haven’t played with the accessibility framework.
From the Apple docs, I see that the method above was deprecated and replaced by other methods in OS X 10.10.
But I am afraid that’s all I can tell.


We’re still linking against the 10.9 SDK on the Cocoa side so it’s OK. But I was mostly wondering if anyone had done accessibility stuff with Xojo. Perhaps I’m overlooking something obvious?

Only thing that comes to mind is – if I understood you correctly – you are using a Canvas as a base class for a custom control created by declares and tweaking the canvas’ view to show the control, yes?
In that case, should you address the canvas handle or not rather the id of the inserted control?
(But again, I have no experience with accessibilities)

BTW, could I ask you how you created the MakeCFString method? Usually there is the CFStringRef serving this purpose, but I am trying to put a pointer to a String into a Core.MutableMemoryblock that knows no CSTRingRef value. And I can’t figure out how to convert it – the CFStringGetCharactersPtr which I suspected to be the right one returns 0 always …

Here’s what we use…

[code]MakeCFString(text as String) as Ptr
declare function CFStringCreateWithCString lib “CoreFoundation” ( alloc as ptr, cStr as CString, encoding as integer ) as ptr
const kCFStringEncodingUTF8 = &h08000100

return CFStringCreateWithCString( nil, text, kCFStringEncodingUTF8 )[/code]

Thanks a lot! That is almost what I tried except for I passed CFSTringgetfastestEncoding which wasn’t successful, as it seems.

Glad it helped!