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.
viriketo@4
     1
#include <iostream>
viriketo@4
     2
#include "TextBox.hpp"
viriketo@5
     3
#include "MainWindow.hpp"
viriketo@4
     4
viriketo@4
     5
BEGIN_EVENT_TABLE (wxTextBox, wxTextCtrl)
viriketo@4
     6
    EVT_CHAR (wxTextBox::OnKeyEvent)
viriketo@4
     7
END_EVENT_TABLE ()
viriketo@4
     8
viriketo@4
     9
viriketo@4
    10
wxTextBox::wxTextBox(wxWindow *parent, int id, wxString text)
viriketo@4
    11
    :wxTextCtrl(parent, id, text, wxDefaultPosition, wxDefaultSize,
viriketo@4
    12
            wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB)
viriketo@4
    13
{
viriketo@4
    14
}
viriketo@4
    15
viriketo@4
    16
void wxTextBox::OnKeyEvent(wxKeyEvent &e)
viriketo@4
    17
{
viriketo@4
    18
    if (e.GetKeyCode() == WXK_TAB)
viriketo@4
    19
    {
viriketo@4
    20
        std::cerr << "TAB pressed" << std::endl;
viriketo@5
    21
        wxCommandEvent ce(MainWindow::ID_SKIP_QUESTION);
viriketo@5
    22
        AddPendingEvent(ce);
viriketo@4
    23
    }
viriketo@4
    24
    else if (e.GetKeyCode() == WXK_RETURN)
viriketo@4
    25
    {
viriketo@4
    26
        std::cerr << "ENTER pressed" << std::endl;
viriketo@5
    27
        wxCommandEvent ce(MainWindow::ID_SAVE_SENTENCE);
viriketo@5
    28
        AddPendingEvent(ce);
viriketo@4
    29
    }
viriketo@4
    30
    else
viriketo@4
    31
        e.Skip();
viriketo@4
    32
}