TextArea’s Focus Ring _ON_ ?

  1. 2 months ago

    Emile S

    Sep 12 Europe (France, Strasbourg)
    Edited 2 months ago

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

  2. 2 weeks ago

    Joseph S

    Nov 8 Pre-Release Testers

    According to the UseFocusRing docs :

    NOTE: MacOS does not support focus rings for TextArea controls, so setting UseFocusRing to True has no effect in macOS builds. This is not a bug in the TextArea control.

    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.

  3. Joseph S

    Nov 8 Pre-Release Testers

    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.)

  4. last week

    Joseph S

    Nov 9 Pre-Release Testers

    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?

  5. Michel B

    Nov 9 Pre-Release Testers, Xojo Pro

    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.

  6. Joseph S

    Nov 9 Pre-Release Testers

    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!

  7. Michel B

    Nov 9 Pre-Release Testers, Xojo Pro

    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...

  8. Joseph S

    Nov 9 Pre-Release Testers

    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.

  9. Tim P

    Nov 9 Pre-Release Testers, Xojo Pro ⭐️

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

  10. Emile S

    Nov 10 Europe (France, Strasbourg)

    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.

  11. Michel B

    Nov 10 Pre-Release Testers, Xojo Pro
    Edited last week

    @Joseph S 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.

    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.

  12. Ulrich B

    Nov 10 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @Joseph S 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.

    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).

  13. Joseph S

    Nov 10 Pre-Release Testers

    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.

  14. Ulrich B

    Nov 10 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...
    Edited last week

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

    Edit: A feature request to add the declare natively: Feedback Case #50314

  15. Alberto D

    Nov 10 Pre-Release Testers

    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.

  16. Ulrich B

    Nov 10 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

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

or Sign Up to reply!