// wxwidgets test program, for #5574
//
// On linux:
// gcc -o wxtest ./wxtest.cpp -lstdc++ `wx-config --unicode --cxxflags --libs`
#include <vector>
#include <wx/wx.h>
enum
{
ID_ViewerAnimationStr = 1,
ID_ViewerAnimationWStr
};
class MyApp: public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
wxPanel* m_ViewerPanel;
void OnSelectAnim(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
};
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_CHOICE(ID_ViewerAnimationStr, MyFrame::OnSelectAnim)
EVT_CHOICE(ID_ViewerAnimationWStr, MyFrame::OnSelectAnim)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame("string vs wstring", wxPoint(250, 250), wxSize(450, 340));
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
m_ViewerPanel = new wxPanel(this, wxID_ANY);
wxSizer* viewerAnimSizer = new wxStaticBoxSizer(wxVERTICAL, m_ViewerPanel, _("Animation"));
// std::string
{
wxArrayString animChoices;
std::vector<std::string> anims = { "apple", "banana", "carrot" };
for (std::string a : anims)
animChoices.Add(wxString(a));
wxChoice* viewerAnimSelector = new wxChoice(m_ViewerPanel, ID_ViewerAnimationStr, wxDefaultPosition, wxDefaultSize, animChoices);
viewerAnimSelector->SetSelection(0);
viewerAnimSizer->Add(viewerAnimSelector, wxSizerFlags().Expand());
}
// std::wstring
{
wxArrayString animChoices;
std::vector<std::wstring> anims = { L"caramel", L"fudge", L"toffee" };
for (std::wstring a : anims)
animChoices.Add(wxString(a));
wxChoice* viewerAnimSelector = new wxChoice(m_ViewerPanel, ID_ViewerAnimationWStr, wxDefaultPosition, wxDefaultSize, animChoices);
viewerAnimSelector->SetSelection(0);
viewerAnimSizer->Add(viewerAnimSelector, wxSizerFlags().Expand());
}
m_ViewerPanel->SetSizer(viewerAnimSizer);
CreateStatusBar();
SetStatusText("Top: std::string; Bottom: std::wstring");
}
void MyFrame::OnSelectAnim(wxCommandEvent& event)
{
wxMessageBox(event.GetString(), "Selected Value", wxOK | wxICON_INFORMATION);
}