Setting/unsetting the focus in a textfield object

Jan 26, 2011 at 7:20am

Setting/unsetting the focus in a textfield object

I am working on an UI object with textfield and I am stuck on a feature that should be pretty simple to implement but I can’t figure out how.
How can I set/unset the focus of an UI external by sending it a message?
In other words, I would like my t_jbox to grab the focus without the need of being clicked on. And in the same fashion I would like to programmatically deselect my t_jbox. (get rid of the focus)

I see a jbox_grabfocus() function in jpatcher_api.h, but the following is written:
“Calling this method should be considered exceptional, and its use is discouraged.”
Does this mean it’s not safe to use jbox_grabfocus() and – if not – is
there another way to grab/ungrab focus without clicking ?

I also checked the uitextfield.c code in the SDK and the following is done:

t_object *p = NULL;
object_obex_lookup(x,gensym("#P"), &p);
if (p) {
    t_atom rv;
    long ac = 1;
    t_atom av[1];
    atom_setobj(av, x);
    object_method_typed(p, gensym("selectbox"), ac, av, &rv);

However, even if the above code does put the focus on the box, it also selects the content of the textfield, which I don’t want to do. I just want to set/unset the focus…

Any ideas?

Thank you.

- Luigi


You must be logged in to reply to this topic.