cpp/TextBox.cpp
author viric <viriketo@gmail.com>
Sun, 13 Feb 2011 08:43:06 +0100
changeset 5 f2a2f64eb682
parent 4 a3d29fb016c3
child 6 66becdcbe5d9
permissions -rw-r--r--
Events don't work as I expect. tab makes save sentence, while enter should be
doing that.
#include <iostream>
#include "TextBox.hpp"
#include "MainWindow.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;
        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();
}