"Non-modal" PopupMenu?


#1

Hi,

Is there an easy way to show a PopupMenu without loosing a focus in current field?

In more details - I’m implementing an autocomplete combobox with drop-down list (see the http://www.rawmaterialsoftware.com/viewtopic.php?f=6&t=5829 for my original idea). And right now, when user is typing something in the texteditor (Label), depending on the content I want to show a PopupMenu with some dynamic set of choices. I have everything ready, and PopupMenu shown with proper set of items, but when it is shown - TextEditor looses the focus - user can not continue typing. I want to shown PopupMenu only as optional “hint” which user can use by mouse or by pressing key-down.

What will be your hints to achieve this? One way can be - reimplementing PopupMenu::Window (because it is private class - no way to use it directly for some needs). Another way can be using a ListBox for such menu.

Thanks!


#2

Have a look to

virtual bool 	canModalEventBeSentToComponent (const Component *targetComponent)
 	When a component is modal, this callback allows it to choose which other components can still receive events. 

Basically, you’ll subclass your TextEditor, and override this method.
When you show the combobox, you prevent it from grabbing keyboard focus, and in your MyTextEditor::canModalEventBeSentToComponent, answer true for the combobox.


#3

[quote=“X-Ryl669”]…
Basically, you’ll subclass your TextEditor, and override this method.
When you show the combobox, you prevent it from grabbing keyboard focus, and in your MyTextEditor::canModalEventBeSentToComponent, answer true for the combobox.[/quote]
I’m showing not the combobox, but a PopupMenu when user types something in the TextEditor (which is in the Label in the Combobox) with list of choices (that should be just visible and do not take the keyboard focus). And at the moment there is no way to control this behavior of the PopupMenu (it simply grabs all input and waits for the input).

As I understand you suggest to overwrite the canModalEventBeSentToComponent(…) in the Popup::Window class (because it is the modal after popup is shown, not the texteditor)? I suppose this will not help for to achieve what I’ve described above.


#4

No, you need to override it in the text editor of the combobox. The text editor in the combobox is modal.
By the way, it’s irrevelant to the issue, but why do you use a popup menu and not a listbox for the autocompletion ?


#5

[quote=“X-Ryl669”]No, you need to override it in the text editor of the combobox. The text editor in the combobox is modal.
By the way, it’s irrevelant to the issue, but why do you use a popup menu and not a listbox for the autocompletion ?[/quote]
Thanks for your hints. I switched to listbox already (because I didn’t find an easy way to use PopupMenu). And overwriting the canModalEventBeSentToComponent in the texteditor does another story (mostly used for mouse events). And I want to show popupmenu and KEEP textedit focused and receiving all KEYBOARD events from the user.

Reason why I was thinking about PopupMenu at the beginning - it is used internally in the ComboBox for showing a dropdown list. And my idea was to not change/write a lot - just extend already working component.

And right now I have completely working combobox with dropdown (listbox) and autocomplete (in texteditor).


#6

Here are 2 screenshots of the ComboExComponent (which I wanted to implement in Juce and how it is working right now).

[attachment=1]cbxex1.png[/attachment]

[attachment=0]cbxex2.png[/attachment]


#7

That’s really nice work. You can probably zip the archive and publish it on the “Useful tools and component” part of the forum if you want to share it.


#8

Zerg, the component you wrote seems to be exactly what I’d need now… are you willing to share the source code?