Adding handling of tab and enter
authorviric <viriketo@gmail.com>
Sun, 13 Feb 2011 08:27:44 +0100
changeset 4 a3d29fb016c3
parent 3 01dafa022fa1
child 5 f2a2f64eb682
Adding handling of tab and enter
cpp/CMakeLists.txt
cpp/MainWindow.cpp
cpp/TextBox.cpp
cpp/TextBox.hpp
cpp/main.hpp
--- 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})
--- 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 <wx/wx.h>
 #include <wx/image.h>
 #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);
 
--- /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 <iostream>
+#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();
+}
--- /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 <wx/textctrl.h>
+#include <wx/event.h>
+
+class wxTextBox : public wxTextCtrl
+{
+    private:
+        void OnKeyEvent(wxKeyEvent &e);
+
+    public:
+        wxTextBox(wxWindow *parent, int id, wxString text = _T(""));
+
+    DECLARE_EVENT_TABLE();
+};
--- /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 <vector>
+#include <string>
+
+extern std::vector<std::string> words;