views:

829

answers:

1

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 );
+2  A: 

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
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
Can you show me an example Connect() call? My connect line looks like this: Connect (IS_TEXTCTRL1, wxEVT_LEFT_DOWN, (wxObjectEventFunction) Everything compiles just fine but MyClass::OnTextMouseDown never gets called. Thanks for the help.
Chris Andrews
IS_TEXTCTRL1 should be ID_TEXTCTRL1
Chris Andrews
Chris Andrews
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