Dialogs in 2.8 Topic is solved

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
weeks
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Oct 27, 2006 5:40 pm

Dialogs in 2.8

Post by weeks » Fri Dec 15, 2006 1:33 pm

Alright so up to now I was using

wxDialog::OnCancel(); and wxDialog::OnOK(), now these are gone in 2.8 I looked through the samples and in place they use wxDialog::EndModal() this however this is not working for me it destroys my dialog without validation. It says in the documentation to use wxDialog::SetAffirmativeId(), I changed all my dialog OK and Cancel buttons to be using wxID_OK and wxID_CANCEL as well, is the wxDialogSetAffirmativeId() supposed to be used in the init dialog to make the dialog know that the particular id is the OK button? A code snippit of the new way to handle OnOK and OnCancel would be really helpful, anybody have any suggestions?

thanks.

der.micky
Earned a small fee
Earned a small fee
Posts: 19
Joined: Fri Sep 09, 2005 4:24 pm
Location: Berlin, Germany
Contact:

Post by der.micky » Fri Dec 15, 2006 1:43 pm

Hi there,

I'm currently migrating my projects to 2.8.0 and the following worked fine for me:

Code: Select all

void bgIDialog::onOk(wxCommandEvent& event){

  DoSomeFinalStuffHere(...);

// old code:
//   wxDialog::OnOK(event);
// new code:
   if ( Validate() && TransferDataFromWindow() ){
     if ( IsModal() )
         EndModal(wxID_OK);
     else{
         SetReturnCode(wxID_OK);
         this->Show(false);
     }
   }
}
hope that helps,
-Micky

weeks
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Oct 27, 2006 5:40 pm

Post by weeks » Fri Dec 15, 2006 2:14 pm

der.micky wrote:Hi there,

I'm currently migrating my projects to 2.8.0 and the following worked fine for me:

Code: Select all

void bgIDialog::onOk(wxCommandEvent& event){

  DoSomeFinalStuffHere(...);

// old code:
//   wxDialog::OnOK(event);
// new code:
   if ( Validate() && TransferDataFromWindow() ){
     if ( IsModal() )
         EndModal(wxID_OK);
     else{
         SetReturnCode(wxID_OK);
         this->Show(false);
     }
   }
}
hope that helps,
-Micky

hey Micky,

I used that code you sent, the call to Validate() && TransferDataFromWindow() is good and I get into the first if statement and EndModal() is called, my dialog goes away but still the message that its "OK" still doesn't seem to be routed. So things in my dialog that set values in my application are not set as they should be. :?

thanks,

Gavin

S.Volkenandt
Knows some wx things
Knows some wx things
Posts: 26
Joined: Tue Nov 14, 2006 1:51 pm
Location: Duesseldorf, Germany

Post by S.Volkenandt » Fri Dec 15, 2006 5:55 pm

Since I started with wxWidgets only after 2.7, I can't say how it was before, however, when I connect an event handler to wxID_OK and call event.Skip() after doint my own stuff, I don't need to do anything to close the dialog myself. Maybe this helps...

Code: Select all

void MyDialog::OnOk( wxCommandEvent& event ) {
  // some stuff here
  if ( Validate() && TransferDataFromWindow() )
    event.Skip();
}

weeks
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Oct 27, 2006 5:40 pm

Post by weeks » Fri Dec 15, 2006 6:33 pm

S.Volkenandt wrote:Since I started with wxWidgets only after 2.7, I can't say how it was before, however, when I connect an event handler to wxID_OK and call event.Skip() after doint my own stuff, I don't need to do anything to close the dialog myself. Maybe this helps...

Code: Select all

void MyDialog::OnOk( wxCommandEvent& event ) {
  // some stuff here
  if ( Validate() && TransferDataFromWindow() )
    event.Skip();
}

Thank you very much it solved my problem. 8)

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

Post by tierra » Sat Dec 16, 2006 7:13 am

S.Volkenandt wrote:

Code: Select all

void MyDialog::OnOk( wxCommandEvent& event ) {
  // some stuff here
  if ( Validate() && TransferDataFromWindow() )
    event.Skip();
}
You should be able to just call event.Skip() without needing the 'if' statement here. So long as you are using wxID_OK, the default event handler will do validation. If you aren't using wxID_OK, that's when you need to use SetAffirmativeId().

Post Reply