Events don't work as I expect. tab makes save sentence, while enter should be
authorviric <viriketo@gmail.com>
Sun, 13 Feb 2011 08:43:06 +0100
changeset 5 f2a2f64eb682
parent 4 a3d29fb016c3
child 6 66becdcbe5d9
Events don't work as I expect. tab makes save sentence, while enter should be doing that.
cpp/MainWindow.cpp
cpp/MainWindow.hpp
cpp/TextBox.cpp
--- a/cpp/MainWindow.cpp	Sun Feb 13 08:27:44 2011 +0100
+++ b/cpp/MainWindow.cpp	Sun Feb 13 08:43:06 2011 +0100
@@ -1,10 +1,17 @@
 #include <wx/wx.h>
 #include <wx/image.h>
+#include <iostream>
 #include "MainWindow.hpp"
 #include "TextBox.hpp"
 
+BEGIN_EVENT_TABLE (MainWindow, wxFrame)
+    EVT_COMMAND (wxID_ANY, ID_SKIP_QUESTION, MainWindow::OnSkipQuestion )
+    EVT_COMMAND (wxID_ANY, ID_SAVE_SENTENCE, MainWindow::OnSaveSentence )
+END_EVENT_TABLE ()
+
 MainWindow::MainWindow()
-    :wxFrame(0, wxID_ANY, _("Lingvigilo"), wxDefaultPosition)
+    :wxFrame(0, wxID_ANY, _("Lingvigilo"), wxDefaultPosition, wxDefaultSize,
+            wxSTAY_ON_TOP)
 {
     wxBoxSizer *s = new wxBoxSizer(wxVERTICAL);
     wxStaticText *label = new wxStaticText(this, wxID_ANY,
@@ -17,3 +24,15 @@
 
     SetSizerAndFit(s);
 }
+
+void
+MainWindow::OnSkipQuestion(wxCommandEvent &e)
+{
+    std::cerr << "Skip Question" << std::endl;
+}
+
+void
+MainWindow::OnSaveSentence(wxCommandEvent &e)
+{
+    std::cerr << "Save Sentence" << std::endl;
+}
--- a/cpp/MainWindow.hpp	Sun Feb 13 08:27:44 2011 +0100
+++ b/cpp/MainWindow.hpp	Sun Feb 13 08:43:06 2011 +0100
@@ -2,11 +2,23 @@
 #define _HEADER_MAINWINDOW_HPP_
 
 #include <wx/wx.h>
+#include <wx/event.h>
 
 class MainWindow : public wxFrame
 {
-public:
-    MainWindow();
+    public:
+        enum
+        {
+            ID_SKIP_QUESTION,
+            ID_SAVE_SENTENCE
+        };
+
+        MainWindow();
+
+        void OnSkipQuestion(wxCommandEvent &e);
+        void OnSaveSentence(wxCommandEvent &e);
+
+    DECLARE_EVENT_TABLE();
 };
 
 #endif /* _HEADER_MAINWINDOW_HPP_ */
--- a/cpp/TextBox.cpp	Sun Feb 13 08:27:44 2011 +0100
+++ b/cpp/TextBox.cpp	Sun Feb 13 08:43:06 2011 +0100
@@ -1,5 +1,6 @@
 #include <iostream>
 #include "TextBox.hpp"
+#include "MainWindow.hpp"
 
 BEGIN_EVENT_TABLE (wxTextBox, wxTextCtrl)
     EVT_CHAR (wxTextBox::OnKeyEvent)
@@ -17,10 +18,14 @@
     if (e.GetKeyCode() == WXK_TAB)
     {
         std::cerr << "TAB pressed" << std::endl;
+        wxCommandEvent ce(MainWindow::ID_SKIP_QUESTION);
+        AddPendingEvent(ce);
     }
     else if (e.GetKeyCode() == WXK_RETURN)
     {
         std::cerr << "ENTER pressed" << std::endl;
+        wxCommandEvent ce(MainWindow::ID_SAVE_SENTENCE);
+        AddPendingEvent(ce);
     }
     else
         e.Skip();