Improve handing of the enter key in wxComboBox control
* Copy-paste the code for OnChar in the wxTextCtrl. * This implements two features: 1. This adds support for the wxTE_PROCESS_ENTER style. 2. Support for pressing the default button in a dialog if there is one.
This commit is contained in:
parent
3d65840f8f
commit
158288cb35
@ -131,6 +131,7 @@ protected:
|
||||
virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE;
|
||||
|
||||
// callbacks
|
||||
void OnChar(wxKeyEvent& event); // Process 'enter' if required
|
||||
void OnKeyDown(wxKeyEvent& event); // Process clipboard shortcuts
|
||||
|
||||
// the subcontrols
|
||||
|
@ -16,11 +16,14 @@
|
||||
#include "wx/osx/private.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/button.h"
|
||||
#include "wx/toplevel.h"
|
||||
#endif
|
||||
|
||||
typedef wxWindowWithItems<wxControl, wxComboBoxBase> RealwxComboBoxBase;
|
||||
|
||||
wxBEGIN_EVENT_TABLE(wxComboBox, RealwxComboBoxBase)
|
||||
EVT_CHAR(wxComboBox::OnChar)
|
||||
EVT_KEY_DOWN(wxComboBox::OnKeyDown)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
@ -240,6 +243,52 @@ void wxComboBox::Dismiss()
|
||||
GetComboPeer()->Dismiss();
|
||||
}
|
||||
|
||||
void wxComboBox::OnChar(wxKeyEvent& event)
|
||||
{
|
||||
const int key = event.GetKeyCode();
|
||||
bool eat_key = false;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case WXK_RETURN:
|
||||
case WXK_NUMPAD_ENTER:
|
||||
if (m_windowStyle & wxTE_PROCESS_ENTER)
|
||||
{
|
||||
wxCommandEvent event(wxEVT_TEXT_ENTER, m_windowId);
|
||||
event.SetEventObject(this);
|
||||
event.SetString(GetValue());
|
||||
if (HandleWindowEvent(event))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
|
||||
if (tlw && tlw->GetDefaultItem())
|
||||
{
|
||||
wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
|
||||
if (def && def->IsEnabled())
|
||||
{
|
||||
wxCommandEvent event(wxEVT_BUTTON, def->GetId());
|
||||
event.SetEventObject(def);
|
||||
def->Command(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// this will make wxWidgets eat the ENTER key so that
|
||||
// we actually prevent line wrapping in a single line text control
|
||||
eat_key = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!eat_key)
|
||||
{
|
||||
// perform keystroke handling
|
||||
event.Skip(true);
|
||||
}
|
||||
}
|
||||
|
||||
void wxComboBox::OnKeyDown(wxKeyEvent& event)
|
||||
{
|
||||
if (event.GetModifiers() == wxMOD_CONTROL)
|
||||
|
Loading…
Reference in New Issue
Block a user