Minor keyboard focus issues


#1
  1. When we show a dialog box with DialogWindow::showModalDialog() the contentComponent do not have keyboard focus: User need to perform a mouse click to obtain it.
    It’s because TempDialogWindow inherit form TopLevelWindow who does a setWantsKeyboardFocus (true) in its constructor.
    A way to fix it is to setWantsKeyboardFocus (false) on the TempDialogWindow constructor or directly in DialogWindow::showModalDialog().

  2. Another minor Keyboard focus issue is related to AlertWindow :
    By default TextEditor created by AlertWindow::addTextEditor can have keyboard focus.
    But non editable ComboBox created by AlertWindow::addComboBox cannot.
    So the user can navigate between TextEditors with [tab] key but cannot do it with ComboBox components.
    For example, it can be usefull when user what to change ComboBox selection with arrow keys.

It’s because ComboBox do not have setWantsKeyboardFocus (true) in it’s constructor like TextEditor class.
I understand that ComboBox::setEditableText behavior was an explanation of this exception.

I think it can be cool that AlertWindow::addComboBox activate the keyboard focus on non editable ComboBox by default,
preventing developer to add the following code in it’s AlertWindow child class.

addComboBox("name", theStringArray, "onScreenLabel");
getComboBoxComponent("name")->setWantsKeyboardFocus(true);

Do you think so?
Thanks for reading this huge post full of minor things…


#2

Hmm. I think that might just be something missing in the ComboBox::lookAndFeelChanged method. does it help to add this change at line 435:

addAndMakeVisible (label); setWantsKeyboardFocus (! label->isEditable());
?


#3

You are totally right.
Your code change fix the issue N°2) perfectly.

Thanks for this.


#4

No problem, thanks for spotting it and letting me know!


#5

Do not forget the N°1) TempDialogWindow related issue.
Next time I will send two different post to be more clear.

Thanks in advance.


#6

But how can I setup a combobox that is not editable and does not want focus and resists to the lookAndFeelChanged() forced reset?


#7

Disabling edition is relatively simple:

I think that the proper way to skip focus on enabled components is to overload this method:


#8

I meant how to define a combobox that does not receive focus.
I can call SetWantsKeyboardFocus(false) after the ComboBox creation, but then if for any reason a lookAndFeelChanged() is issued, that setting is reverted to true.
Using a specialized focus traverser seems a bit too much for this. I’m currently calling SetWantsKeyboardFocus(false) again after a look and feel change, but it’s not an optimal solution.


#9

Hi, poping up in this thread because:

  • I updated from juce v2 (one year old) to juce v3 (tip)
  • I don’t want keyboard focus on the combobox
  • The keyboard focus is there even if I declare setEditableText(false) and setWantsKeyboardFocus(false) on the ComboBox (using own LNF)

I don’t know what could have changed between v2 where it worked and v3 where it does not work anymore.

I discovered that It was solved by commenting out setWantsKeyboardFocus (! label->isEditable()); — just like hladik wrote.

You might want to have editable text but no keyboard focus, like in AAX plug-ins (tab, return and space must be transmitted to the host because this are DAW shortcuts). So, as these properties “editable” and “focus” are unrelated, I’d advise decoupling it. cc: Jules :slight_smile: