Welcome to xMule: A P2P Client derived from eMule BerliOS Developer LogoSourceForge.net Logo


Links
- Visit the Forums!
- SF.net Project Page
- xMule Screenshots

Modules
· Home
· Content
· Downloads
· Recommend Us
· Search
· Statistics
· Top
· Topics
· Your Account

Who's Online
There are currently, 2 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here

 
Tutorials Tutorials: Custom wxWidgets Events
Posted by HopeSeekr on Tuesday, August 03 @ 05:45:00 CDT
Contributed by HopeSeekr

One of the scarier parts of wx seems to be custom events. After all, what's friendly about macro functions?! Fortunately, creating brand-new events isn't that difficult at all. This tutorial will show you steps I used to create EVT_ROOT_EXPANDING in wxTreeMultiCtrl, hope(TM)fully in a way that will help you understand how to create custom events in general.

Step 1: n your header you need to declare your custom event type. It needs to be outside the class {}; declaration and probably near the top of the file. extern const wxEventType wxEVT_NODE_EXPANDED Similarly, in the file's cpp file, you need: const wxEventType wxEVT_NODE_EXPANDED = wxNewEventType(); Step 2: You need to declare EVT_ROOT_EXPANDED for use in the stock BEGIN_EVENT_TABLE() / END_EVENT_TABLE() macros. In the header, stick an edited version of this in there, below the code for Step 1: #define EVT_NODE_EXPANDED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_NODE_EXPANDED, id, -1, (wxObjectEventFunction)(wxEventFunction)(wxNotifyEventFunction)&fn, (wxObject *) NULL ), Step 3: Create and post your custom event in your source code. For instance, I wanted to post an event whenever the control's root was expanded, so i used the following code: wxNotifyEvent event(wxEVT_ROOT_EXPANDED); wxPostEvent(this, event); Step 4 (optional): For really unique events, the stock event class, wxNotifyEvent and wxCommandEvent just won't provide you with what you want. Say you want a custom value that is associated with your custom control, for instance. In my case, I wanted the wxTreeMultiItem of the root node that was being expanded. For situations such as these, you must create a custom event class. class wxTreeMultiEvent: public wxNotifyEvent { private: wxTreeMultiItem m_item; public: wxTreeMultiEvent(const wxEventType& event): wxNotifyEvent(event) { } virtual wxEvent *Clone() const { return new wxTreeMultiEvent(*this); } wxTreeMultiItem GetItem() const { return m_item; } wxString GetLabel() const { return m_item.GetLabel(); } void SetItem(wxTreeMultiItem item) { m_item = item; } }; Right before your work in Step 2, you should place: typedef void (wxEvtHandler::*wxTreeMultiEventFunction)(wxTreeMultiEvent&); Then, you must change line 4 of Step 2 to (wxObjectEventFunction)(wxEventFunction)(wxTreeMultiEventFunction)&fn, You must also pass the event in Step 3 any additional information, such as in the following code: wxTreeMultiEvent event(wxEVT_ROOT_EXPANDED); event.SetItem(item); wxPostEvent(this, event); That's pretty much it. Leave me a note if this is helpful :-)
-hope

I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man.
-Thomas Jefferson


 
Login
Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Related Links
· More about Tutorials
· News by HopeSeekr


Most read story about Tutorials:
Using xMule's CVS


Article Rating
Average Score: 3.83
Votes: 18


Please take a second and vote for this article:

Excellent
Very Good
Good
Regular
Bad


Options

 Printer Friendly Printer Friendly


Associated Topics

Coding Blog

"Custom wxWidgets Events" | Login/Create an Account | 4 comments | Search Discussion
The comments are owned by the poster. We aren't responsible for their content.

No Comments Allowed for Anonymous, please register

Re: Custom wxWidgets Events (Score: 0)
by Anonymous on Wednesday, August 04 @ 08:43:39 CDT
Thanks, I used this tonight when implementing a custom event. Very helpful indeed. - ajjl




Re: Custom wxWidgets Events (Score: 0)
by Anonymous on Tuesday, November 09 @ 12:56:22 CST
Thanks! This tutorial got me goin' on the right path!




Re: Custom wxWidgets Events (Score: 0)
by Anonymous on Monday, January 03 @ 12:47:01 CST
In Step 2: The for the "More Stuff Next Line" is missing. At least in Firefox.

Other than that, great article. Thanks.





PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL.
PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.06 Seconds