TextArea’s Focus Ring _ON_ ?

I checked with Xojo 2017r2 (’still 90 minutes to go to finish Xojo 2017r2.1 upload…) and I get the same result:

no focus ring around my TextArea while UseFocusRing is ON !

10 TextFields with a FocusRing and two TextArea that does not have the FocusRing ???

What is your experience with TextArea AND FocusRing ?

Edit: MacOS X (El Capitan)…

According to the UseFocusRing docs:

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.

Anybody else bothered by this limitation?

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!

Note that the canvas itself can get focus and animate, then hand focus to the TextArea and just paint the color.

You got to make due with what is available.

Or dive into declares…

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.

Poke @Sam Rowlands
If I recall correctly, Sam knows some things about how TextArea works.

It was asked in another conversation, but, from the LR:

Unfortunately, a Focus Ring does not appear on Windows or Linux when a Canvas control gets the focus

a Canvas does not have a FocusRing on Linux and Windows.

[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…

Yuck yourself.

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.

I’ll surely do! Glad I could help, Joseph!

Edit: A feature request to add the declare natively: <https://xojo.com/issue/50314>

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.

Thanks, Alberto! It’s really not so difficult. Jim once wrote a brilliant introduction that helped me understand declare basics:
Cocoa Declares