Bug/FeatureReq? ListBox(Model) dropping "unused" keyPress


Hi Jules,

first thanks for this great framework. It really works like a charm.

There’s only one little thing which has come up recently. Some words to the background:

Used JUCE Version: 2.0.31
Platform: irrelevant but in case I’m using Windows

I’ve implemented a Filebrowser which shall be capable to switch to the parent directory on keypress: backspace (commonly used I think). This works so far on the level of the FileBrowserComponent level.
But as soon as an item inside the FileListComponent is selected all keypresses are handled by the ListBox(Model) calling the virtual method “deleteKeyPressed”. As this method is not used inside my FileListComponent this should return false to say “this is not handled here” but the method is defined as void. So the ListBox assumes that the key has been handled and drops the keypress for all parents.
Wouldn’t it be better to let the ListBoxModel implementations decide if the key has been handled or not and respect this inside of the keyPressed?

juce_ListBox.cpp -> ListBox::keyPressed -> model->deleteKeyPressed (lastRowSelected) -> FileListComponent::deleteKeyPressed (no return value, so no way to pass false back to the keyPressed)
could be changed to hold a flag inside of the keyPressed to determine if the key actually has been handled - if not a parent component could handle this (in my case the FileBrowser)

Maybe I’m missing something here? It’ld be great if you could fix this or come up with another solution for this problem :slight_smile:


I’ve worked around the problem by calling the parents keyPressed directly from the FileListComponents::deleteKeyPressed implementation.
Feels a bit like a nasty hack but for the moment it works. Nevertheless I think it’s still worth a deeper thought about the models specialized keyPressed method handling :-).


Hmm. It is a little tricky… You could also override the keyPressed method of your FileListComponent, e.g.

[code]bool MyListBox::keyPressed (const KeyPress& key)
if (key.isKeyCode (KeyPress::backspaceKey))
return false;

return ListBox::keyPressed (key);



Hi Jules,

yeah, this would also workaround the problem, thanks for pointing that out.

For my understanding of the API the keyPressed implementation should only return true if the key (really) has been handled. I think the calls to models void methods - eventually handling the keys - are breaking this concept as for the keyPressed method it’s impossible to check if the key has been handled.

Is this correct? ( I’m aware that changing this behaviour would be a substantial API change. Changing all ListBoxModel implementations would be no fun at all - especially for framework users which have implemented their own models. This is only for my understanding :wink: )



Yeah, I do agree that it would be better if deleteKeyPressed returned a bool, it’d just be a pain for everyone to have to change their code.