Emulating cancel button

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
Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Emulating cancel button

Post by Raghu » Mon Feb 27, 2006 10:41 am

I have a frame which takes multiple text inputs and has OK and CANCEL button. If the user changes any of the text and clicks OK it will be updated in a structure and the frame is hidden. On clicking CANCEL button the changes are not updated. But the problem is whatever changes user has made to the text boxes will be retained. Ideally on clicking CANCEL all the updated changes should revert back to the previous values. How could I solve this?

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Mon Feb 27, 2006 10:58 am

Maybe:
http://www.wxwidgets.org/manuals/2.6.2/ ... fromwindow

If I get you correctly, you want the values to be written to the internal data structure only when OK is pressed? I assume the dialog closes on OK and on CANCEL? What I always do;

Code: Select all

MyDialog *dlg = new MyDialog(...);
dlg->TransferDataToDlg(PtrToClass);
if(dlg->ShowModal() == wxID_OK)
  dlg->TransferDlgToData(PtrToClass);
dlg->Destroy();
The two functions are own made, I always keep data in classes, so that I can send around pointers that will relect the data in the dialog. This way when the user enters cancel, the class is not updated.

In the dialog, simply move the class contents to the proper GUI elements and back;

Code: Select all

TransferDataToDlg(const MyClass *ptr)
{
  m_someTextCtrl->SetValue(ptr->GetTextValue());
  m_someCheckBox->SetValue(ptr->IsOptionTrue());
}
And back;

Code: Select all

TransferDlgToData(MyClass *ptr)
{
  ptr->SetTextValue(m_someTextCtrl->GetValue());
  SetOptionTrue(m_someCheckBox->GetValue());
}
If this is not what you meant, please be more specific about the flow of the dlg and your problem.

Regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Post by Raghu » Mon Feb 27, 2006 11:46 am

Is there any way of getting the previous set value in the text ctrl rather than reading from the internal structure.
Consider
A text ctrl with value user123
If this is changed to user456 and then clicked CANCEL, it should revert back to user123 rather than displaying user456.

I mean instead of TransferDataToDlg() can I get the previous set value somehow?

Post Reply