#include "wxMain.h"
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame("Serial Graph");
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
wxMenu* menuFile = new wxMenu;
menuFile->Append(wxID_OPEN, "&Open\tCtrl-O", "Open a file");
menuFile->Append(wxID_SAVE, "&Save\tCtrl-S", "Save the file");
menuFile->AppendSeparator();
menuFile->Append(ID_QUIT, "E&xit\tAlt-X", "프로그램 종료");
wxMenu* menuOptions = new wxMenu;
menuOptions->Append(ID_Settings, "&Options", "Options Setting");
wxMenuBar* menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
menuBar->Append(menuOptions, "&Options");
SetMenuBar(menuBar);
textControl = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
// sizer를 생성하여 텍스트 컨트롤의 크기를 조정합니다.
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(textControl, 1, wxEXPAND | wxALL, 0); // wxEXPAND는 컨트롤이 sizer의 가능한 모든 공간을 차지하도록 합니다. 1은 비율을 의미하며, 이 경우 다른 컨트롤이 없으므로 전체 크기를 차지합니다.
// 프레임에 sizer를 설정합니다.
this->SetSizer(sizer);
this->Layout(); // sizer를 강제로 다시 계산하여 적용합니다.
CreateStatusBar();
SetStatusText("Ready");
// 이벤트 핸들러 연결
Bind(wxEVT_MENU, &MyFrame::OnQuit, this, ID_QUIT);
Bind(wxEVT_MENU, &MyFrame::OnOpen, this, wxID_OPEN);
Bind(wxEVT_MENU, &MyFrame::OnSave, this, wxID_SAVE);
Bind(wxEVT_MENU, &MyFrame::OnSettings, this, ID_Settings);
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
Close(true);
}
void MyFrame::OnOpen(wxCommandEvent& event)
{
wxFileDialog openFileDialog(this, _("Open TXT file"), "", "",
"TXT files (*.txt)|*.txt", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL)
return; // 사용자가 취소했을 때
// 파일을 열고 텍스트 컨트롤에 내용을 로드합니다.
textControl->LoadFile(openFileDialog.GetPath());
}
void MyFrame::OnSave(wxCommandEvent& event)
{
wxFileDialog saveFileDialog(this, _("Save TXT file"), "", "",
"TXT files (*.txt)|*.txt", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (saveFileDialog.ShowModal() == wxID_CANCEL)
return; // 사용자가 취소했을 때
// 현재 텍스트 컨트롤의 내용을 파일에 저장합니다.
textControl->SaveFile(saveFileDialog.GetPath());
}
void MyFrame::OnSettings(wxCommandEvent& event)
{
SettingsDialog dialog(this, wxID_ANY, "Settings");
if (dialog.ShowModal() == wxID_OK)
{
// 사용자가 설정을 변경하고 OK를 클릭했을 때의 처리
SetStatusText("Settings Updated");
}
}