I have a feeling that I'm missing something obvious but I can't figure this out. I have a panel that has 3 text controls and 2 combo boxs and I want to catch 'enter' key from any of these controls. The text control works fine, but for the life of me I cannot catch 'enter' from the two combo boxs.
My desired behavior is this:
Tab key - navigate to next control
Enter key - Process the event
With my code as is; if I set wxTE_PROCESS_ENTER on the combo boxes when I tab through or press enter, they just beep. If I set no style (0); then they tab through correctly but, on enter, also just tab to the next control.
I'd be grateful for any help!
My code is as follows:
Code: Select all
//Header
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/panel.h>
#else
#include <wx/wxprec.h>
#endif
#include <wx/event.h>
#include <wx/combobox.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#include <wx/sizer.h>
class pnlTodoItem : public wxPanel
{
public:
pnlTodoItem(todoItem* t_data, wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString &name = wxT("Todo item"));
virtual ~pnlTodoItem();
private:
//Data
todoItem* data;
wxArrayString categoryArray;
//Callbacks
void OnEnter(wxCommandEvent& event );
DECLARE_EVENT_TABLE();
wxComboBox *drpStatus;
wxTextCtrl *inpTodo;
wxComboBox *drpCategory;
wxTextCtrl *inpDue;
wxTextCtrl *inpCreated;
wxBoxSizer *szRoot;
enum
{
ID_INPCREATED = 1004,
ID_INPDUE = 1005,
ID_DRPCATEGORY = 1006,
ID_INPTODO = 1007,
ID_DRPSTATUS = 1008
};
void CreateGUIControls();
};
Code: Select all
// Implementation
#include "pnlTodoItem.h"
BEGIN_EVENT_TABLE(pnlTodoItem, wxPanel)
//Combo
EVT_TEXT_ENTER(ID_DRPSTATUS, pnlTodoItem::OnEnter)
EVT_TEXT_ENTER(ID_DRPCATEGORY, pnlTodoItem::OnEnter)
//Text controls
EVT_TEXT_ENTER(ID_INPCREATED, pnlTodoItem::OnEnter)
EVT_TEXT_ENTER(ID_INPDUE, pnlTodoItem::OnEnter)
EVT_TEXT_ENTER(ID_INPTODO, pnlTodoItem::OnEnter)
/*
//Works fine but with EVT_TEXT_ENTER there seems to be some interaction happening
EVT_COMBOBOX(ID_DRPCATEGORY, pnlTodoItem::OnEnter)
EVT_COMBOBOX(ID_DRPSTATUS, pnlTodoItem::OnEnter)
*/
END_EVENT_TABLE()
pnlTodoItem::pnlTodoItem(todoItem* t_data, wxWindow *parent, wxWindowID id, const wxPoint &position, const wxSize& size, long style, const wxString &name)
: wxPanel(parent, id, position, size, style, name)
{
this->data = t_data;
CreateGUIControls();
}
pnlTodoItem::~pnlTodoItem()
{
}
void pnlTodoItem::CreateGUIControls()
{
szRoot = new wxBoxSizer(wxHORIZONTAL);
this->SetSizer(szRoot);
this->SetAutoLayout(true);
//Data
wxArrayString statusStates;
statusStates.Add(wxT("Open"));
statusStates.Add(wxT("Done"));
//Controls
inpCreated = new wxTextCtrl(this, ID_INPCREATED, this->data->created, wxPoint(1,1), wxSize(60,21),
wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("inpCreated"));
inpDue = new wxTextCtrl(this, ID_INPDUE, this->data->required, wxPoint(63,1), wxSize(60,21),
wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("inpDue"));
//If wxTE_PROCESS_ENTER is set; then combobox beeps on tab and enter; otherwise does nothing
drpCategory = new wxComboBox (this, ID_DRPCATEGORY, this->data->category, wxPoint(125,1), wxSize(102,21),
categoryArray, wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("drpCategory"));
inpTodo = new wxTextCtrl(this, ID_INPTODO,this->data->todo, wxPoint(229,1), wxSize(461,21),
wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("inpTodo"));
//Ditto drpCategory
drpStatus = new wxComboBox (this, ID_DRPSTATUS, this->data->status, wxPoint(692,1), wxSize(87,21),
statusStates, wxTE_PROCESS_ENTER, wxDefaultValidator, wxT("drpStatus"));
szRoot->Add(inpCreated,0, wxALIGN_CENTER | wxALL, 1);
szRoot->Add(inpDue,0, wxALIGN_CENTER | wxALL, 1);
szRoot->Add(drpCategory,0, wxALIGN_CENTER | wxALL, 1);
szRoot->Add(inpTodo,0, wxEXPAND | wxALL, 1);
szRoot->Add(drpStatus,0, wxALIGN_CENTER | wxALL, 1);
}
void pnlTodoItem::OnEnter(wxCommandEvent& event )
{
wxMessageDialog(this, wxT("Got an enter"), wxT("Notice"), wxOK | wxICON_INFORMATION ).ShowModal();
event.Skip();
}