# HG changeset patch # User viric # Date 1297582064 -3600 # Node ID a3d29fb016c3f666271a3a0f6c91d108b37051a3 # Parent 01dafa022fa1a4e34b77b425e6310e178e8e39e6 Adding handling of tab and enter diff -r 01dafa022fa1 -r a3d29fb016c3 cpp/CMakeLists.txt --- a/cpp/CMakeLists.txt Sun Feb 13 08:11:31 2011 +0100 +++ b/cpp/CMakeLists.txt Sun Feb 13 08:27:44 2011 +0100 @@ -9,5 +9,7 @@ ADD_EXECUTABLE(lingvigilo main.cpp - MainWindow.cpp) + MainWindow.cpp MainWindow.hpp + TextBox.cpp TextBox.hpp + ) TARGET_LINK_LIBRARIES(lingvigilo ${wxWidgets_LIBRARIES}) diff -r 01dafa022fa1 -r a3d29fb016c3 cpp/MainWindow.cpp --- a/cpp/MainWindow.cpp Sun Feb 13 08:11:31 2011 +0100 +++ b/cpp/MainWindow.cpp Sun Feb 13 08:27:44 2011 +0100 @@ -1,6 +1,7 @@ #include #include #include "MainWindow.hpp" +#include "TextBox.hpp" MainWindow::MainWindow() :wxFrame(0, wxID_ANY, _("Lingvigilo"), wxDefaultPosition) @@ -8,7 +9,7 @@ wxBoxSizer *s = new wxBoxSizer(wxVERTICAL); wxStaticText *label = new wxStaticText(this, wxID_ANY, _("Introdueix la frase:")); - wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY); + wxTextBox *text = new wxTextBox(this, wxID_ANY); s->Add(label); s->Add(text); diff -r 01dafa022fa1 -r a3d29fb016c3 cpp/TextBox.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cpp/TextBox.cpp Sun Feb 13 08:27:44 2011 +0100 @@ -0,0 +1,27 @@ +#include +#include "TextBox.hpp" + +BEGIN_EVENT_TABLE (wxTextBox, wxTextCtrl) + EVT_CHAR (wxTextBox::OnKeyEvent) +END_EVENT_TABLE () + + +wxTextBox::wxTextBox(wxWindow *parent, int id, wxString text) + :wxTextCtrl(parent, id, text, wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB) +{ +} + +void wxTextBox::OnKeyEvent(wxKeyEvent &e) +{ + if (e.GetKeyCode() == WXK_TAB) + { + std::cerr << "TAB pressed" << std::endl; + } + else if (e.GetKeyCode() == WXK_RETURN) + { + std::cerr << "ENTER pressed" << std::endl; + } + else + e.Skip(); +} diff -r 01dafa022fa1 -r a3d29fb016c3 cpp/TextBox.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cpp/TextBox.hpp Sun Feb 13 08:27:44 2011 +0100 @@ -0,0 +1,13 @@ +#include +#include + +class wxTextBox : public wxTextCtrl +{ + private: + void OnKeyEvent(wxKeyEvent &e); + + public: + wxTextBox(wxWindow *parent, int id, wxString text = _T("")); + + DECLARE_EVENT_TABLE(); +}; diff -r 01dafa022fa1 -r a3d29fb016c3 cpp/main.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cpp/main.hpp Sun Feb 13 08:27:44 2011 +0100 @@ -0,0 +1,4 @@ +#include +#include + +extern std::vector words;