I need to create a simple dialog with some textCtrl and "save" button; a simple edit-dialog. I've already do this but now it don't work; when I try to get the label of textctrl (GetLabelText() or GetLabel()), the string returned is always the default string that I put on the constructor of the textctrl. This is the essential code:
P.S. cBook is a clas that contains 3 wxString and 1 eBookTypes (that is an enum) and it work perfectly.
Constructor:
Code: Select all
cEditBookDialog::cEditBookDialog(cBook* pBook, wxWindow* parent, wxString caption)
: wxDialog(parent, -1, caption, wxDefaultPosition, wxSize(350, 370)), pBook(book), sFilePath("")
{
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxScrolledWindow* scroll = new wxScrolledWindow(this, -1, wxDefaultPosition, this -> GetSize());
this -> CenterOnScreen();
wxStaticText** vTitles = new wxStaticText*[2];
vTitles[0] = new wxStaticText(scroll, -1, "Name:");
vTitles[1] = new wxStaticText(scroll, -1, "Info:");
pName = new wxTextCtrl (scroll, -1, pBook -> GetName(), wxDefaultPosition, wxSize(this -> GetSize().x - 30, -1));
pComment = new wxTextCtrl (scroll, -1, pBook -> GetComment(), wxDefaultPosition, wxSize(this -> GetSize().x - 30, 70), wxTE_MULTILINE);
pName -> SetMaxLength(100);
pComment -> SetMaxLength(65535);
wxBoxSizer** subsizers = new wxBoxSizer*[3];
for (int i(0); i < 2; ++i)
{
vTitles[i] -> Wrap(this -> GetSize().x - 30);
subsizers[i] = new wxBoxSizer(wxVERTICAL);
subsizers[i] -> Add(vTitles[i], 0, wxALL, 5);
}
subsizers[0] -> Add(pName, 0, wxALL, 5);
subsizers[1] -> Add(pComment, 0, wxALL, 5);
subsizers[2] -> Add(new wxButton (scroll, eebdID_SELECT_DOCUMENT, "Select"), 0, wxALL, 5);
for (int i(0); i < 3; ++i)
{
sizer -> Add(subsizers[i], 0, wxALL, 5);
sizer -> AddSpacer(20);
}
wxBoxSizer* actions = new wxBoxSizer(wxHORIZONTAL);
actions -> Add(new wxButton(scroll, eebdID_SAVE, "Save"), wxSizerFlags().Left());
actions -> AddSpacer(80);
actions -> Add(new wxButton(scroll, eebdID_CANCEL, "Cancel"), wxSizerFlags().Right());
sizer -> Add(actions, 0, wxALL, 9);
scroll -> SetSizer(sizer);
scroll -> SetAutoLayout(true);
scroll -> FitInside();
scroll -> SetScrollRate(20, 20);
scroll -> SetSize(sizer -> GetSize() + wxSize(20, 50));
this -> SetSize(scroll -> GetSize());
}
Code: Select all
void cEditBookDialog::OnSaveDocument(wxCommandEvent& WXUNUSED(event))
{
wxString name, comment;
name = pName -> GetLabelText();
comment = pComment -> GetLabelText();
if (name.IsEmpty())
{
wxMessageBox("Insert name!", "Attenzione", wxICON_EXCLAMATION | wxOK);
return;
}
if (comment.IsEmpty())
{
wxMessageBox("Insert comment!", "Attenzione", wxICON_EXCLAMATION | wxOK);
return;
}
pBook -> SetName (name);
pBook -> SetComment (comment);
this -> EndModal(wxID_OK);
}
I don't find the problem. How can I solve it?
Thank you