// wxwidgets test program, for #5574 // // On linux: // gcc -o wxtest ./wxtest.cpp -lstdc++ `wx-config --cxxflags --libs` #include #include enum { ID_ViewerAnimationStr = 1, ID_ViewerAnimationChar, ID_ViewerAnimationWStr, ID_ViewerAnimationWChar, }; 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(); }; BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_CHOICE(ID_ViewerAnimationStr, MyFrame::OnSelectAnim) EVT_CHOICE(ID_ViewerAnimationChar, MyFrame::OnSelectAnim) EVT_CHOICE(ID_ViewerAnimationWStr, MyFrame::OnSelectAnim) EVT_CHOICE(ID_ViewerAnimationWChar, MyFrame::OnSelectAnim) END_EVENT_TABLE() wxIMPLEMENT_APP(MyApp); bool MyApp::OnInit() { MyFrame* frame = new MyFrame("string type imports", 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 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()); } // char { wxArrayString animChoices; std::vector anims = { "doughnut", "egg", "fudge" }; for (std::string a : anims) animChoices.Add(wxString(a.c_str())); wxChoice* viewerAnimSelector = new wxChoice(m_ViewerPanel, ID_ViewerAnimationChar, wxDefaultPosition, wxDefaultSize, animChoices); viewerAnimSelector->SetSelection(0); viewerAnimSizer->Add(viewerAnimSelector, wxSizerFlags().Expand()); } // std::wstring { wxArrayString animChoices; std::vector anims = { L"grapefuit", L"horseradish", L"icecream" }; 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()); } // wchar { wxArrayString animChoices; std::vector anims = { L"jam", L"kitkat", L"loaf" }; for (std::wstring a : anims) animChoices.Add(wxString(a.c_str())); wxChoice* viewerAnimSelector = new wxChoice(m_ViewerPanel, ID_ViewerAnimationChar, wxDefaultPosition, wxDefaultSize, animChoices); viewerAnimSelector->SetSelection(0); viewerAnimSizer->Add(viewerAnimSelector, wxSizerFlags().Expand()); } m_ViewerPanel->SetSizer(viewerAnimSizer); } void MyFrame::OnSelectAnim(wxCommandEvent& event) { wxMessageBox(event.GetString(), "Selected Value", wxOK | wxICON_INFORMATION); }