The following is a cut-down version of my code:
Code: Select all
#include <wx/wx.h>
#include <wx/dialog.h>
#include <wx/button.h>
#include "wx/textctrl.h"
#include "duktape.h"
wxString textField;
void onDialogOK(wxCommandEvent & event){
wxString theData;
theData = textField;
// pause here to view theData
}
duk_ret_t duk_dialog(duk_context *ctx) { // provides wxWidgets dialogue
int button_ID;
wxTextCtrl* textCtrl;
wxBoxSizer* buttonBox;
wxButton* button;
// create the dialog
button_ID = 1000;
wxDialog *dialog = new wxDialog(NULL, wxID_ANY, wxT("JavaScript dialogue"), wxDefaultPosition, wxDefaultSize);
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); // A top-level sizer
buttonBox = new wxBoxSizer(wxHORIZONTAL);
dialog->SetSizer(topSizer);
textField = wxT("(Default text)");
textCtrl = new wxTextCtrl ( dialog, i, wxT(""), wxDefaultPosition, wxDefaultSize, 0 ,
wxTextValidator(wxFILTER_NONE, &textField));
boxSizer->Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
button = new wxButton ( dialog, button_ID, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 );
buttonBox->Add(button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
dialog->Bind(wxEVT_BUTTON, &onDialogOK, wxID_ANY);
// also tried button->Bind(wxEVT_BUTTON, &onDialogOK, wxID_ANY);
dialog->Show(true);
return 1;
}
When I click on the OK button, the handler onDialogOK is entered. I am testing under Xcode and have a breakpoint set on the // pause here line. theData is still set to the original default text.
It seems the changed data is not being transferred back to textField. Maybe the transferDataFromWindow function is not being called?
Any help on what else I need to do will be really appreciated.