Embedding Cocoa control focus trouble
I don’t know if this is a issue of some sort of it I am doing something wrong. Issue is I am just embedding Cocoa control
in a small test, returning the handle of it and all that. I just put on simple NSButton to test.
Issue is no matter what I do I can always tab onto it and get focus.
I set setRefusesFirstResponder to YES
REAL Control flags are set as follows: REALenabledControl | REALcontrolIsHIViewCompatible,
Is there something I am missing here ?
Do you have this option on by chance?
No I don’t have that one, that was good and valid guess though !
It does not happen on Xojo buttons also.
Am just testing with NSButton since thats easy test case to test things before doing something bigger and more complex.
I just don’t know enough on cocoa to be sure if its something I am doing wrong or if its a bug in how Xojo handles embedding in the SDK.
I think this is handled by the SDK framework. Have a look at the docs:
flags: a bitmask specifying additional information about the control. The following flags are supported:
- REALcontrolAcceptFocus – this control can accept keyboard focus at any time.
controlAcceptFocus: This callback is called whenever the framework wishes to know whether your control can accept focus or not. If you have the REALcontrolAcceptFocus flag specified in the control definition, then this method is never called since it is assumed the control can always accept focus. Called only at runtime.
As a major plugin developer for Xojo then I obviously know those things.
From my post above then:
“REAL Control flags are set as follows: REALenabledControl | REALcontrolIsHIViewCompatible,”
So the focus flags are not on the control.
And this case is not about normal control anyhow, its about Embedding of native Cocoa control in which case in the SDK you pass the hands to Xojo and Xojo takes owner ownership.
Since REALcontrolAcceptFocus is not set, you must implement the controlAcceptFocus callback and return false.
That does actually work !
I didn’t know that one would wire into the native control.
It was implemented since it was copy paste of implementation of other non native control, but it was only connected to the enabled state of the control