Which I guess is a declaration that they’re not going to fix this. Which is a shame, because it breaks consistency both with Carbon and with other desktop platforms, and completely breaks a large ERP app for my biggest client.
If they’re able to draw a focus ring for a Canvas and a Listbox, I’m pretty sure they could draw a focus ring around a TextArea if they tried hard enough. But I doubt that will ever happen. So it’s up to all of us to come up with our own work-arounds.
Interestingly, this page explains how easy it is to implement a focus ring for any control in 10.7 or later.
Easy, that is, if you’re programming in Swift/Cocoa, and can make a subclass of your control type so that you can override a couple of methods. For us, with only declares, I don’t think that’s possible. (Though I could be wrong I’m no guru of Cocoa declares.)
OK, in theory it is possible, using class_addMethod to hack the required methods in (see this StackOverflow page).
However, I haven’t been able to get it to work. I’ve got focusRingMaskBounds and drawFocusRingMask methods implemented exactly as in Apple’s Q&A, but whether I add them to the XOJTextView or the XOJScroller, no focus rings appear. But clearly, other people have gotten focus rings in NSTextViews to work see here and here), at least in Objective-C. So I don’t understand why it doesn’t work in Xojo. Possibly I’m doing it wrong, though the methods are quite simple; possibly something else about the view hierarchy or Xojo’s NSTextView subclass makes it not work; or maybe it’s something else.
Just rest the TextArea smack in the center on top of a Canvas 4 pixels wider and taller. Then you can do something like this
Add a boolean property TAhasfocus that will keep track of the TextArea focused state
In Canvas1 :
Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
if TAhasfocus then
g.ForeColor = &c0F7FFE00
g.FillRect(0,0,me.width,me.height)
end if
End Sub
In TextArea1:
Sub GotFocus() Handles GotFocus
TAhasfocus = True
Canvas1.Invalidate
End Sub
Sub LostFocus() Handles LostFocus
TAhasfocus = False
Canvas1.Invalidate
End Sub
You can create a custom control with a ContainerControl if you need the focus ring more often, but that is the principle.
Well, that won’t match the “real” focus rings appearing around other controls, which do a little animation to get your attention when they gain the focus. But it might be better than nothing, in at least some cases. Thank you for jumping in!
You seem to be suggesting that, when the TextArea gets the focus, it should set the focus to the Canvas, wait until after it’s shown the focus ring (which would be of the wrong size), then take the focus back itself, while the Canvas then just draws a pseudo-focus ring (of the correct size). 10/10 for creativity, but… yuck. I am skeptical that this could be made to work reliably.
And diving into declares is what I’ve been doing. I’m still hopeful there is some way to make that work, but at the moment I’m stumped.
[quote=358378:@Joseph Strout]You seem to be suggesting that, when the TextArea gets the focus, it should set the focus to the Canvas, wait until after it’s shown the focus ring (which would be of the wrong size), then take the focus back itself, while the Canvas then just draws a pseudo-focus ring (of the correct size). 10/10 for creativity, but… yuck. I am skeptical that this could be made to work reliably.
And diving into declares is what I’ve been doing. I’m still hopeful there is some way to make that work, but at the moment I’m stumped.[/quote]
Joseph, no offense, but if you start by dismissing ideas without even trying, why do you even ask in forum ? If you wanted only a declare, you should have said it upfront.
Please help me … Thank you but, no, the buoy is not the right color. I rather sink…
It does not look that complicated on macOS: FocusRing Mac.
Looks like setting the FocusRingType property is enough, at least for a TextArea (the left Canvas uses DrawFocusRingMask in its Paint Event just to see how that might look).
Brilliant! This appears to do exactly what I wanted.
I confess I never tried simply setting the FocusRingType property I assumed that was what Xojo was already doing when you set FocusRing=true, and that the “MacOS does not support” claim in the docs meant that this didn’t work. Don’t I feel silly.
Ulrich, thanks a million. If we ever bump into each other, please allow me to buy you a beverage.
Ulrich, I hope one day I’ll be able to understand what you did or how you make it work. Just started coding with Xojo after more than 25 years since college with Quickbasic, Foxbase and some Pascal. It is really amazing what others can do with Xojo.