Page 1 of 1

Dialogs in 2.8

Posted: Fri Dec 15, 2006 1:33 pm
by weeks
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.

Posted: Fri Dec 15, 2006 1:43 pm
by der.micky
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

Posted: Fri Dec 15, 2006 2:14 pm
by weeks
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

Posted: Fri Dec 15, 2006 5:55 pm
by S.Volkenandt
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();
}

Posted: Fri Dec 15, 2006 6:33 pm
by weeks
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)

Posted: Sat Dec 16, 2006 7:13 am
by tierra
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().