Where is EVT_TEXT_ENTER?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Where is EVT_TEXT_ENTER?

Post by ninja9578 » Tue Feb 10, 2009 7:55 pm

I'm created a program that needs a text entry box occasionally, so I made one.

I want to call the finishing up method on the enter key, but it doesn't let me do that. The compiler comes back with a EVT_TEXT_ENTER undeclared errors

Here is my class

Code: Select all

#include "TextEntry.h"

TextEntry::TextEntry(wxWindow * parent, wxString& value, const wxPoint& pos, const wxSize& size):wxDialog(parent, -1, _T(""), pos, size, wxNO_BORDER){
     textctrl = new wxTextCtrl(this, -1, value, wxPoint(0, 0), size, wxTE_PROCESS_ENTER); 
     Connect(EVT_TEXT_ENTER, wxCommandEventHandler(TextEntry::Done));                               
}

TextEntry::~TextEntry(void){
     if (textctrl) delete textctrl;               
}

void TextEntry::Done(wxCommandEvent& WXUNUSED(event)){
     EndModal(1);             
}
this is the header file

Code: Select all

#ifndef TEXT_ENTRY_H
#define TEXT_ENTRY_H

#include <wx/textctrl.h>
#include <wx/wx.h>

class TextEntry: public wxDialog{
      public:
             TextEntry(wxWindow * parent, wxString& value, const wxPoint& pos, const wxSize& size);
             ~TextEntry(void);   
      private:
             void Done(wxCommandEvent& WXUNUSED(event)); 
             wxTextCtrl * textctrl;  
};

#endif
I'm using version 2.6.1. Please don't ask me to upgrade, I've tried many times and the dev-pak always fails. That's not the problem, the old documentation includes that event too.

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Re: Where is EVT_TEXT_ENTER?

Post by Disch » Tue Feb 10, 2009 8:13 pm

ninja9578 wrote:

Code: Select all

     Connect(EVT_TEXT_ENTER, wxCommandEventHandler(TextEntry::Done));                               
Unless I'm mistaken... EVT_TEXT_ENTER is the event table macro, not the event ID. You probably want wxEVT_COMMAND_TEXT_ENTER here instead.

Code: Select all

TextEntry::~TextEntry(void){
     if (textctrl) delete textctrl;               
}
Do not delete child controls or child windows. Wx does this automatically when the parent window is destroyed.

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Tue Feb 10, 2009 8:21 pm

Hi,

As Disch says, you need to use wxEVT_COMMAND_TEXT_ENTER instead, but watch the event sink.

I think the line you want looks like this:

Code: Select all

textctrl->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(TextEntry::Done),NULL, this); 
This enables your TextEntry object to handle the wxTextCtrl event in its own context.

Hope that helps,

Jim
OS: Vista SP1, wxWidgets 2.8.7.

Post Reply