wxDialog::OnOK in wxWidgets 2.7

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
spidertp
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Oct 20, 2006 9:08 am

wxDialog::OnOK in wxWidgets 2.7

Post by spidertp »

Where is wxDialog::OnOK in wxWidgets 2.7?
In help file for wxWidgets 2.7 it's defined. I found needed function in wx/univ/dialog.h but not in wx/dialog.h.
If I include file from univ directory I got a lot of "second time defined" classess...

Any help would be appreciated
Tomek
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Simply add

Code: Select all

#include <wx/dialog.h>
at the top of your source file (.h or .cpp).
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

Actually, all the OnOK/OnCancel type functions are in the middle of being removed in favor of the single EndDialog(int id) (not EndModal) function. It makes a little more sense since for stuff like wxStdDialogButtonSizer, some of those buttons are labeled differently on other platforms.

It looks like this was something that wasn't finished when the 2.7.1 release was made because EndDialog still isn't documented yet, that or it was forgotten about. It's also possible that I'm wrong as I haven't read anything on wx-dev about this taking place, but I've found that EndDialog works just as well as a replacement.
jb_coder
Super wx Problem Solver
Super wx Problem Solver
Posts: 267
Joined: Mon Oct 18, 2004 10:55 am

Post by jb_coder »

Would it make sense to have a deprecated function wxDialog::OnOK in 2.7.1 that was just

Code: Select all

wxDialog::OnOK()
{
  EndDialog(wxID_OK);
}
Otherwise you need #ifdefs to separate code for 2.6.x and 2.7.x (since the EndDialog function isn't present in the 2.6.x branch). I could be mistaken, but I thought that the usual practice was to have the old function present at the same time as the new function for at least a couple releases to allow for user migration.
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

jb_coder wrote:Would it make sense to have a deprecated function wxDialog::OnOK in 2.7.1
On further inspection, it looks like OnOK (along with others) used to be defined separately by each port. Vadim aparently noticed this, and made a commit taking out the functions about 2 months ago with a note explaining that they were to be moved to the base class, but I don't see the addition of the functions to the base class. I'll bring this up on the wx-dev list.
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

You can find the reply here:
http://thread.gmane.org/gmane.comp.lib. ... ocus=79043

So it aparently looks like these are just going to be removed for good, no deprecation.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 550
Joined: Fri Nov 03, 2006 2:00 pm

Post by stahta01 »

jb_coder wrote:Would it make sense to have a deprecated function wxDialog::OnOK in 2.7.1 that was just

Code: Select all

wxDialog::OnOK()
{
  EndDialog(wxID_OK);
}
Otherwise you need #ifdefs to separate code for 2.6.x and 2.7.x (since the EndDialog function isn't present in the 2.6.x branch). I could be mistaken, but I thought that the usual practice was to have the old function present at the same time as the new function for at least a couple releases to allow for user migration.

Code: Select all

void SubClassOf_wxDialog::OnOK(wxCommandEvent& /*event*/) 
{
    this->wxDialog::SetAffirmativeId(wxID_OK);
    this->wxDialog::AcceptAndClose();
}
Is my above code OK for 2.7.1 as a replacement of OnOK in a class that is a subclass of wxDialog?

Tim S
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

stahta01 wrote:

Code: Select all

void SubClassOf_wxDialog::OnOK(wxCommandEvent& /*event*/) 
{
    this->wxDialog::SetAffirmativeId(wxID_OK);
    this->wxDialog::AcceptAndClose();
}
Is my above code OK for 2.7.1 as a replacement of OnOK in a class that is a subclass of wxDialog?
What Vadim was saying in the thread on the mailing list is that if you are using the default wxID_OK for your OK button (and your code indicates you are), and you don't need to do anything special before closing the dialog, then you don't need to write an OnOK event handler. Also, if you do use a different ID other than wxID_OK, you can still just use the new SetAffirmativeId() function when you setup your dialog, and still not have to write an OnOK handler. So basically, the replacement would be to take out the handler altogether. If you do still need one, just call event.Skip(), and nothing else is needed.
Post Reply