Updating to the Latest Version of wxWidgets
From WxWiki
Contents |
[edit] 2.6 to 2.8
These are possible candidates for updates to changes.txt. Upgrading from 2.6.x to 2.8.0 is fairly trouble free for most apps, in spite of many changes.
[edit] wxDialog::OnOk()
This function has now been removed for a couple reasons: 1) It was never needed in the first place, and 2) It's existence only encouraged wrong use and flow of wxDialog. Changes.txt suggests using SetAffirmativeId() instead. To elaborate a little more on this change since many are still confused: You never needed to call OnOK() from your own code even if you used a different ID other than the standard wxID_OK (to indicate a positive closing result, or otherwise), and should have been using wxDialog::SetAffirmativeId() for those cases anyway.
There are two methods that many developers have been known to abuse wxDialog::OnOK(). The first is by calling OnOK() from other event handlers or functions as the method of closing the dialog:
DoSomeStuff(); Dialog::OnOK( event );
Instead, you should be designing your dialogs to use the standard wxID_OK and wxID_CANCEL window IDs for wxButtons with labels that indicate the appropriate action. The above code promotes closing the dialog upon completion of some action separate of clicking an "OK" button, and this isn't the type of behavior users expect of dialogs, it should only close when they push the "OK" or "Cancel" buttons or the close button on the frame (which closes the dialog with wxID_CANCEL).
The second method of abuse is overriding OnOK in your derived wxDialog to perform additional actions before the dialog closes (any actions after it closes can be handled by the code that created the dialog in the first place). If you honestly have code that must be called before the dialog closes (ie: you do your own value validation instead of using wxValidators, or likewise), then you should implement a new button event handler tied to your wxID_OK button (you should have one of these buttons or you're guilty of both forms of abuse of wxDialog::OnOK()) which should look something like this:
void MyDialog::OnButtonOk( wxCommandEvent &event ) { if( DoSomeSpecializedStuff() ) { event.Skip(); } }
The "event.Skip()" call tells wxWidgets to continue processing the default behavior for wxID_OK (or another button ID if you like so long as you've called SetAffirmativeId() in your wxDialog constructor), which will call all wxValidators, handle any data transfer with those validators, and close the dialog.
See this wxForum discussion and this wx-dev mailing list post for additional information.
[edit] GetCount() Changes
GetCount() defined in many classes have changed from returning an int to a size_t (usually defined as an unsigned int on most platforms) as well as many other item index related functions. All virtual function implementations or function overrides will need to be updated to use size_t as well. Shouldn't cause any problems and is more of a semantic change.
[edit] wxSystemSettings::GetSystemColour()
This function has gone. Use GetColour() instead.
[edit] wxApp::GetTopWindow()
Previously code like:
wxTheApp->GetTopWindow()->SetTitle( MyString );
Would work whatever the top window. With 2.8.0 you should now dynamically cast the top window to a wxTopLevelWindow first. Perhaps GetTopWindow() should return a wxTopLevelWindow *, assuming that is the only thing it is allowed to return? On the other hand perhaps not, as not doing so encourages the writer of application code to check for a NULL value after doing the dynamic cast themselves.
