Actually it seems I was wrong. I can test only on MSW but wxUIActionSimulator seems to work with wxMessageBox:
Code: Select all
#include <wx/wx.h>
#include <wx/uiaction.h>
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(600, 400))
{
wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL);
wxButton* button;
button = new wxButton(this, wxID_ANY, "Test OK");
bSizer->Add(button, 0, wxEXPAND | wxALL, 5);
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MyFrame::OnTestOK, this);
button = new wxButton(this, wxID_ANY, "Test Cancel");
bSizer->Add(button, 0, wxEXPAND | wxALL, 5);
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MyFrame::OnTestCancel, this);
wxTextCtrl* textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
bSizer->Add(textCtrl, 1, wxEXPAND | wxALL , 5);
wxLog::SetActiveTarget(new wxLogTextCtrl(textCtrl));
SetSizer(bSizer);
}
private:
void OnTestOK(wxCommandEvent&) { Test(true); }
void OnTestCancel(wxCommandEvent&) { Test(false); }
void Test(bool testOK)
{
wxUIActionSimulator sim;
wxString result;
int style = wxOK | wxCANCEL | wxICON_INFORMATION;
if ( testOK )
style |= wxOK_DEFAULT;
else
style |= wxCANCEL_DEFAULT;
sim.Char(WXK_RETURN);
switch ( wxMessageBox("Testing", wxT("Calibration"), style, this) )
{
case wxOK: result = "OK"; break;
case wxCANCEL: result = "Cancel"; break;
default: result = "Unknown return code";
}
wxLogMessage("Testing '%s', returned '%s'", testOK ? "OK" : "Cancel", result);
}
};
class MyApp : public wxApp
{
public:
bool OnInit()
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
Not sure how reliable (or portable) it is...