5

Is there an easy way to handle when a user clicks on a wxTextCtrl? After reading the docs wxTextCtrl I see that there isn't a click or double click event. I understand that there is no such thing as "click" events in wxWidgets from the question wxWidgets: Detecting click event on custom controls, so a simple mouse down event will do.

Example answer:

From: wx wiki

    textCtrl->Connect(wxEVT_LEFT_DOWN,
              wxMouseEventHandler(MyClass::OnClick), NULL, this );
Community
  • 1
  • 1
Chris Andrews
  • 1,881
  • 3
  • 21
  • 31

1 Answers1

4

Have you tried to handle the wxEVT_LEFT_DOWN and wxEVT_LEFT_UP events for your text control? Either by adding them to the static message map, or by calling Connect() for the handler methods.

Edit:

Not all events are listed in the documentation of a class. You need to go up in the hierarchy as well, from wxTextCtrl to wxControl to wxWindow. Unfortunately I can find the documentation for the mouse events in neither class. It should still be possible to handle them, even if it is not clearly documented.

mghie
  • 32,028
  • 6
  • 87
  • 129
  • No, I don't see that event listed at http://docs.wxwidgets.org/2.8.4/wx_wxtextctrl.html. Are those event for hooking mouse events in general via the wxMouseEvent class or is there event there, but just hidden? I'm using Code::Blocks for the GUI designer and it doesn't show any events for the mouse i.e. "selected" or "activated." Where should I go from there? I have no problem writing the code without the designer. Thanks. – Chris Andrews May 19 '09 at 17:57
  • Can you show me an example Connect() call? My connect line looks like this: Connect (IS_TEXTCTRL1, wxEVT_LEFT_DOWN, (wxObjectEventFunction) & MyClass::OnTextMouseDown); Everything compiles just fine but MyClass::OnTextMouseDown never gets called. Thanks for the help. – Chris Andrews May 19 '09 at 18:46
  • IS_TEXTCTRL1 should be ID_TEXTCTRL1 – Chris Andrews May 19 '09 at 18:47
  • I should also point out that MyClass::OnTextMouseDown is defined as void MyClass::OnTextMouseDown( wxMouseEvent& event), which may or may not be incorrect – Chris Andrews May 19 '09 at 18:49
  • It looks like you have made it to work, great. There are several ways to use the dynamic event handling, unfortunately the event sample is a little dated and doesn't show everything. Documentation is scarce, and may even be wrong (see http://wiki.wxwidgets.org/Using_Connect_To_Add_Events_To_An_Existing_Class) - I have found it best to read the wxWidgets source and header files. – mghie May 19 '09 at 19:49