Canvas Accept Focus doesn't work

I’m updating an old application, and want to add the ability to paste into a canvas. I’ve made a new subclass of the canvas with menu handlers to do this, but it appears that the canvas won’t accept focus in the first place. So the menu handlers never get called. I’ve set the following parameters in the canvas:
enabled = true
UseFocusRing = true
AcceptFocus = true
AcceptTabs = true

Still, when the application is running and I click on the canvas, nothing happens. No focus ring, No ability to paste.

What have I missed?

OS ?

http://documentation.xojo.com/topics/user_interface/desktop/desktop_controls/canvas.html#canvas-allowfocusRing Setting this property to True has no effect on Windows or Linux

[quote=487478:@Robert Weaver]I’ve set the following parameters in the canvas:
enabled = true
UseFocusRing = true
AcceptFocus = true
AcceptTabs = true

Still, when the application is running and I click on the canvas, nothing happens. No focus ring, No ability to paste.

What have I missed?[/quote]
In the following thread is a couple of code examples you can download for getting a Canvas to accept focus.
https://forum.xojo.com/57571-set-the-focus-to-a-canvas-by-click

Hopefully one or both of these help with getting your paste handler working. Good luck!

@Emile Schwarz I’m using MacOS Sierra and Xojo 2018r3.

@Scott Cadillac Thanks. I’ll check out that link.

FYI. I looked at another app that I wrote, and when you click on the canvas, it behaves as expected: It highlights, and you can copy the image from it. Comparing these two apps, I haven’t yet figured out what the difference is.

I’m too tired to think right now. I’ll have another look tomorrow.

[quote]enabled = true
UseFocusRing = true
AcceptFocus = true
AcceptTabs = true[/quote]

I may be confused but aren’t these properties:

Enabled
AllowFocusRing
AllowFocus
AllowTabs

At least in the more recent versions of Xojo.

This may be true but probably irrelevant as the old commands are only deprecated.

[quote]Still, when the application is running and I click on the canvas, nothing happens. No focus ring, No ability to paste.

What have I missed?[/quote]

Can you Tab to the Canvas?

What about creating a MouseEnter event or a MouseDown event and in that event fire off the method Me.SetFocus.

Does that do anything useful in your context?

I just tried this, and yes, I can tab into the canvas. The focus ring appears, and while it has focus, it does receive the menu events. So, now I just have to figure out why it won’t get focus when I click on it.

BTW, you’re correct that Enabled, AllowFocusRing, AllowFocus and AllowTabs are properties, not parameters, as I had said.

Well, this is bizarre. I turned off the Accept Tabs property, and now it gets focus when I click on it. Stranger still, is that with Accept Tabs=false, you can still tab into the canvas.

AcceptTabs (currently called AllowTabs) only refers to the behavior when in the control. It allows you to hit the Tab key and have it accepted as a keystroke rather than just moving to the next item in the Tab queue. In a canvas that has no use for a Tab keystroke, I cannot see that it makes any difference. In my experience, in a canvas. it just Tabs to the next object no matter whether the AcceptTabs /AllowTabs is set to True or False.

But it does not have anything to do with whether you can Tab into the control and I cannot see how it would influence whether the canvas gets the focus when being clicked on.

If you turn OFF AllowTabStop, then it just will not Tab there. Whether or not the Focus outline is set to be visible.

I have been unable to get the Canvas to get the focus with a Mouse click unless in the MouseDown event I include

Me.SetFocus()

So I am not sure why you report success by turning off AcceptTabs /AllowTabs

Problems perhaps similar to what your are having discussed in a previous forum post:

https://forum.xojo.com/57571-set-the-focus-to-a-canvas-by-click

Do you have in the MouseDown event: Me.SetFocus() ?

Please make a bug report

[quote=487639:@Robert Livingston]I have been unable to get the Canvas to get the focus with a Mouse click unless in the MouseDown event I include

Me.SetFocus()

So I am not sure why you report success by turning off AcceptTabs /AllowTabs[/quote]
After my initial problems, I did add a Me.SetFocus(), but still couldn’t get it work until I started going through the various control property settings and tried turning them on and of in various combinations, and then finding the combination that worked.

The various tab related properties have always been a source of confusion for me, because from their names it’s hard to tell whether they relate to navigating from control to control with the tab key, or whether they affect behaviour within the control when the tab key is pressed.

Anyway, it’s working now. Thank you. I appreciate your help.

Based on the above, I don’t think there is any bug to report. It was just my misunderstanding of the various properties.