PCSX2 Documentation/WxWidgets Coding Strategies: Difference between revisions
PCSX2 Documentation/WxWidgets Coding Strategies (view source)
Revision as of 23:36, 8 January 2015
, 8 January 2015→Be Careful when Sending Events to Other Windows
Line 57: | Line 57: | ||
==Be Careful when Sending Events to Other Windows== | ==Be Careful when Sending Events to Other Windows== | ||
'''TODO : obsolete. Replace with a link to documented use of th new pxEvent system.''' | |||
There are several ways to send events between windows in wxWidgets, and only one of them is typically the | There are several ways to send events between windows in wxWidgets, and only one of them is typically the ''correct'' way: | ||
<nowiki> | |||
// This method ensures cross-platform consistency and thread safety, but cannot be | // This method ensures cross-platform consistency and thread safety, but cannot be | ||
// used to get a return code. | // used to get a return code. | ||
Line 72: | Line 72: | ||
wxGetApp()->AddPendingEvent( evt ); // safe from any thread | wxGetApp()->AddPendingEvent( evt ); // safe from any thread | ||
wxGetApp()->ProcessEvent( evt ); // safe form GUI thread only | wxGetApp()->ProcessEvent( evt ); // safe form GUI thread only | ||
</nowiki> | |||
This can be a bit confusing because wx has several other options for sending events, and most of them have caveats as noted below: | This can be a bit confusing because wx has several other options for sending events, and most of them have caveats as noted below: | ||
<nowiki> | |||
// This one works but is depreciated, and can lead to cross-platform inconsistencies: | // This one works but is depreciated, and can lead to cross-platform inconsistencies: | ||
myWidget->AddPendingEvent( evt ); | myWidget->AddPendingEvent( evt ); | ||
Line 84: | Line 84: | ||
// example of myWidget->GetEventHandler()->AddPendingEvent( evt ); | // example of myWidget->GetEventHandler()->AddPendingEvent( evt ); | ||
wxPostEvent( myWidget->GetEventHandler(), evt ); | wxPostEvent( myWidget->GetEventHandler(), evt ); | ||
</nowiki> | |||
... So the moral of the story is: Use `GetEventHandler()` when possible (basically anything except the `wxApp` object), and use `AddPendingEvent()` unless you need a return code _and_ know you're on the main GUI thread. | ... So the moral of the story is: Use `GetEventHandler()` when possible (basically anything except the `wxApp` object), and use `AddPendingEvent()` unless you need a return code _and_ know you're on the main GUI thread. | ||