Can't capture Enter in a dialog with wxComboBox (OSX, 2.9.5)

71 views
Skip to first unread message

paulc...@gmail.com

unread,
Apr 23, 2013, 5:57:29 PM4/23/13
to wx-u...@googlegroups.com
Hi All,
 
I've been trying to handle Enter in a dialog with wxComboBox and ran into issues on OSX that I can't resolve or find a workaround for.
 
(1) wxComboBox doesn't handle Enter or other key-related events; seems to be a known defect (http://trac.wxwidgets.org/ticket/15003 and http://trac.wxwidgets.org/ticket/13672). It also doesn't seem to generate EVT_COMMAND_TEXT_ENTER when Enter is presed.
 
(2) Using EVT_CHAR_HOOK doesn't work on OSX cocoa; this has been discussed 2.5years ago, but as far as I can tell, this is still the case: http://wxwidgets.10942.n7.nabble.com/Capturing-Enter-Return-key-in-dialog-td31996.html
 
(3) SetDefault() is not working on OSX (contrary to what's noted in #12386, although I didn't test on that particular example: http://trac.wxwidgets.org/ticket/12386). In fact, it's not only not working, but breaks a hotkey associated with the button I put it on. For example, my "&Find" button can be triggered when I use Cmd-F. When I use SetDefault on it, not only this doesn't activate it using Enter (as I'd expect), but it also breaks Cmd-F (as it now activates a global shortcut instead of the button on the dialog).
 
Any suggestions for a workaround or a fix? I only need to capture Enter to trigger an action associated with a button.
 
Paul.
 

Dion Whittaker

unread,
Apr 26, 2013, 1:20:26 AM4/26/13
to wx-u...@googlegroups.com
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to wx-users+u...@googlegroups.com
or visit http://groups.google.com/group/wx-users
 
 

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Hi,

I ran into the same problem a while ago. I developed a work around, it's a bit ugly and I suspect highly wxWidgets version dependent, but it has been working reliably so far. I am using wxWidgets 2.9.4 so your mileage may vary.

I found you had to set the wxTE_PROCESS_ENTER style flag for the wxComboBox in order for the wxEVT_COMMAND_TEXT_ENTER to be generated.

However I also found that a wxEVT_COMMAND_TEXT_ENTER was generated when a new value was selected in the wxComboBox using the drop down, which was immediately followed by the wxEVT_COMMAND_COMBOBOX_SELECTED.

So what I ended up doing was enabling wxTE_PROCESS_ENTER in the OSX Cocoa build, and binding functions to both wxEVT_COMMAND_COMBOBOX_SELECTED and wxEVT_COMMAND_TEXT_ENTER. Then when I get a wxEVT_COMMAND_TEXT_ENTER message from the wxComboBox I set a flag indicating I got an Enter key press and start a wxTimer which times out after 1ms.

If I get wxEVT_COMMAND_COMBOBOX_SELECTED before the timer times out I clear the flag. Once the timer times out I check the flag, and if it is still set I send a wxEVT_COMMAND_BUTTON_CLICKED to the button I want activated.

The code required to implement this is short and straight forward, and possibly easier to understand than my explanation. If you want me to post it let me know.

Hope this is of some help.
Dion



paulc...@gmail.com

unread,
Apr 26, 2013, 12:54:19 PM4/26/13
to wx-u...@googlegroups.com, dwhit...@cnsvs.com
Dion:
 
> I found you had to set the wxTE_PROCESS_ENTER style flag for the wxComboBox in order for the wxEVT_COMMAND_TEXT_ENTER to be generated.
Thank you very much for the hint. I did get it to work. I didn't pay much attention to wxTE_PROCESS_ENTER as the documentation says "Windows only.":
 
  • wxTE_PROCESS_ENTER:
    The control will generate the event wxEVT_TEXT_ENTER (otherwise pressing Enter key is either processed internally by the control or used for navigation between dialog controls). Windows only.
 
*Vadim*, this is probably something that should be fixed if this is no longer limited to Windows...
 
Paul.

Vadim Zeitlin

unread,
Apr 26, 2013, 2:57:25 PM4/26/13
to wx-u...@googlegroups.com
On Fri, 26 Apr 2013 09:54:19 -0700 (PDT) wrote:

> Dion:
>
> > I found you had to set the wxTE_PROCESS_ENTER style flag for the
> wxComboBox in order for the wxEVT_COMMAND_TEXT_ENTER to be generated.
> Thank you very much for the hint. I did get it to work. I didn't pay much
> attention to wxTE_PROCESS_ENTER as the documentation says "Windows only.":
>
> wxTE_PROCESS_ENTER:
> The control will generate the event wxEVT_TEXT_ENTER (otherwise pressing
> Enter key is either processed internally by the control or used for
> navigation between dialog controls). Windows only.
>
> Vadim, this is probably something that should be fixed if this is no
> longer limited to Windows...

Yes, it definitely works in wxGTK too. But I'm rather confused by this
thread as it seems to imply that it works in wxOSX too, yet I see no
mention of wxTE_PROCESS_ENTER style in combobox-related OS X files. I
wonder what am I missing...

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Paul K

unread,
Apr 26, 2013, 3:06:19 PM4/26/13
to wx-u...@googlegroups.com
Vadim:

> Yes, it definitely works in wxGTK too. But I'm rather confused by this
thread as it seems to imply that it works in wxOSX too, yet I see no
mention of wxTE_PROCESS_ENTER style in combobox-related OS X files. I
wonder what am I missing...

I can't comment on that as I haven't checked the source, but I can
confirm that it does work on OSX and as far as I remember it didn't
work without wxTE_PROCESS_ENTER few days ago when I tried the same
thing (meaning I wasn't getting wxEVT_COMMAND_TEXT_ENTER events for my
comboboxes).

Paul.

Vadim Zeitlin

unread,
Apr 26, 2013, 3:42:19 PM4/26/13
to wx-u...@googlegroups.com
On Fri, 26 Apr 2013 12:06:19 -0700 Paul K wrote:

PK> I can't comment on that as I haven't checked the source, but I can
PK> confirm that it does work on OSX and as far as I remember it didn't
PK> work without wxTE_PROCESS_ENTER few days ago when I tried the same
PK> thing (meaning I wasn't getting wxEVT_COMMAND_TEXT_ENTER events for my
PK> comboboxes).

OK, I've tested this myself and it does work. I don't know what am I
overlooking but I guess that as long as it works unexpectedly instead of
not working, it doesn't really matter.

I've removed the "Windows only" mention from the docs in r73869, thanks,
Reply all
Reply to author
Forward
0 new messages