Connect Event - File Exit

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
guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Connect Event - File Exit

Post by guzzi_jones »

I am attempting to learn how wxwidgets events are handled. Where do i get a list of wxEventTypes to use in :
void Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
I finally found the wxEventType is needed buried in a forum, but there MUST be a list of these somewhere?

I suppose they would be in the menu class?

Pardon my newbness. I am learning through vim and command line so that i really learn. I found that worked the past few months to learn c++;
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Connect Event - File Exit

Post by DavidHart »

Hi,
Where do i get a list of wxEventTypes
There's a list on wxWiki.
I suppose they would be in the menu class
Most are in include/wx/event.h, but others are in class-specific headers e.g. wxTreeCtrl ones in include/wx/treebase.h.

Regards,

David
guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Re: Connect Event - File Exit

Post by guzzi_jones »

Thank you for the list. Now I just need to untangle the rest of the logic on how to connect events.
Event programming is still a black box to me.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Connect Event - File Exit

Post by DavidHart »

Now I just need to untangle the rest of the logic on how to connect events.
The important thing to understand is very simple: you need to connect the origin of the event to its destination. It's amazing how often people manage get it wrong; especially with Connect(); if you are using wx3, I strongly suggest using the new safer alternative: wxEvtHandler::Bind.

Supose you want to connect an event generated in a wxTreeCtrl, 'tree', to a wxTextCtrl, 'text'. Then the general format must be:
tree->Connect(....., &MyTextCtrl::SomeFunction, NULL, text);
or, with Bind():
tree->Bind(..., &MyTextCtrl::SomeFunction, text, ... );
Note that the eventSink parameter must be a pointer to the MyTextCtrl class.

Some compilers can't cope with ' &MyTextCtrl::SomeFunction', in which case you should instead use:
tree->Bind(..., wxCommandEventHandler(MyTextCtrl::SomeFunction), text, ... );
(or wxKeyEventHandler() or wxCharEventHandler() or ....).
Post Reply