2022-12-04 04:18:52 +00:00
|
|
|
/*
|
|
|
|
epple2
|
|
|
|
Copyright (C) 2022 by Christopher A. Mosher <cmosher01@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY, without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Created on December 3, 2022, 3:02 PM
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "E2wxFrame.h"
|
|
|
|
#include "E2wxApp.h"
|
2022-12-04 21:33:27 +00:00
|
|
|
#include "PreferencesDialog.h"
|
2022-12-05 03:45:35 +00:00
|
|
|
#include "gui.h"
|
2022-12-05 21:58:44 +00:00
|
|
|
#include <wx/menu.h>
|
2022-12-12 18:03:30 +00:00
|
|
|
#include <wx/accel.h>
|
2022-12-05 21:58:44 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2022-12-12 05:52:19 +00:00
|
|
|
#include <wx/event.h>
|
2022-12-04 04:18:52 +00:00
|
|
|
#include <wx/persist/toplevel.h>
|
|
|
|
|
2022-12-12 05:52:19 +00:00
|
|
|
|
2022-12-05 03:45:35 +00:00
|
|
|
enum E2MenuID {
|
2022-12-13 02:47:10 +00:00
|
|
|
ID_MENUITEM_POWER = wxID_HIGHEST+1,
|
|
|
|
ID_MENUITEM_CYCLE_MONITOR,
|
|
|
|
ID_MENUITEM_TOGGLE_FULL_SCREEN,
|
|
|
|
ID_MENUITEM_RESET,
|
|
|
|
ID_MENUITEM_SCREEN_SHOT,
|
|
|
|
ID_MENUITEM_TOGGLE_BUFFERED,
|
2022-12-05 03:45:35 +00:00
|
|
|
};
|
2022-12-04 04:18:52 +00:00
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(E2wxFrame, wxFrame)
|
2022-12-13 02:47:10 +00:00
|
|
|
EVT_CLOSE(E2wxFrame::HandleUserQuitRequest)
|
2022-12-04 04:18:52 +00:00
|
|
|
EVT_MENU(wxID_EXIT, E2wxFrame::OnExit)
|
|
|
|
EVT_MENU(wxID_PREFERENCES, E2wxFrame::OnPreferences)
|
|
|
|
EVT_MENU(wxID_ABOUT, E2wxFrame::OnAbout)
|
2022-12-05 03:45:35 +00:00
|
|
|
EVT_MENU(ID_MENUITEM_POWER, E2wxFrame::OnTogglePower)
|
2022-12-13 02:47:10 +00:00
|
|
|
EVT_MENU(ID_MENUITEM_CYCLE_MONITOR, E2wxFrame::OnCycleMonitor)
|
|
|
|
EVT_MENU(ID_MENUITEM_TOGGLE_FULL_SCREEN, E2wxFrame::OnToggleFullScreen)
|
|
|
|
EVT_MENU(ID_MENUITEM_RESET, E2wxFrame::OnReset)
|
|
|
|
EVT_MENU(wxID_PASTE, E2wxFrame::OnPaste)
|
|
|
|
EVT_MENU(ID_MENUITEM_SCREEN_SHOT, E2wxFrame::OnScreenShot)
|
|
|
|
EVT_MENU(ID_MENUITEM_TOGGLE_BUFFERED, E2wxFrame::OnToggleBuffered)
|
2022-12-04 04:18:52 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
E2wxFrame::E2wxFrame() : wxFrame(nullptr, wxID_ANY, "epple2") {
|
|
|
|
}
|
|
|
|
|
|
|
|
E2wxFrame::~E2wxFrame() {
|
|
|
|
}
|
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
|
|
|
|
|
2022-12-04 04:18:52 +00:00
|
|
|
void E2wxFrame::DoInit() {
|
|
|
|
InitMenuBar();
|
|
|
|
InitStatusBar();
|
|
|
|
|
|
|
|
if (!wxPersistentRegisterAndRestore(this, "main")) {
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void E2wxFrame::InitMenuBar() {
|
2022-12-05 21:58:44 +00:00
|
|
|
// TODO move menu def to xrc
|
2022-12-04 04:18:52 +00:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
wxMenu *menuFile = new wxMenu();
|
|
|
|
menuBar->Append(menuFile, "&File");
|
2022-12-12 18:03:30 +00:00
|
|
|
wxMenuItem *miExit = menuFile->Append(wxID_EXIT);
|
|
|
|
miExit->AddExtraAccel(wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F9));
|
2022-12-04 04:18:52 +00:00
|
|
|
|
|
|
|
wxMenu *menuEdit = new wxMenu();
|
|
|
|
menuBar->Append(menuEdit, "&Edit");
|
2022-12-12 18:03:30 +00:00
|
|
|
wxMenuItem *miPaste = menuEdit->Append(wxID_PASTE);
|
|
|
|
miPaste->AddExtraAccel(wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F7));
|
|
|
|
menuEdit->AppendSeparator();
|
2022-12-13 02:47:10 +00:00
|
|
|
wxMenuItem *miPrefs = menuEdit->Append(wxID_PREFERENCES);
|
|
|
|
miPrefs->SetAccel(new wxAcceleratorEntry(wxACCEL_CTRL, ','));
|
|
|
|
|
2022-12-04 04:18:52 +00:00
|
|
|
|
2022-12-05 03:45:35 +00:00
|
|
|
wxMenu *menuMachine = new wxMenu();
|
|
|
|
menuBar->Append(menuMachine, "&Machine");
|
2022-12-12 18:03:30 +00:00
|
|
|
wxMenuItem *miPower = menuMachine->Append(ID_MENUITEM_POWER, "Toggle Power");
|
|
|
|
miPower->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F1));
|
2022-12-13 02:47:10 +00:00
|
|
|
wxMenuItem *miReset = menuMachine->Append(ID_MENUITEM_RESET, "Reset");
|
|
|
|
miReset->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F6));
|
|
|
|
menuMachine->AppendSeparator();
|
|
|
|
wxMenuItem *miBuffered = menuMachine->Append(ID_MENUITEM_TOGGLE_BUFFERED, "Toggle Keyboard Buffer");
|
|
|
|
miBuffered->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F12));
|
|
|
|
|
|
|
|
wxMenu *menuMonitor = new wxMenu();
|
|
|
|
menuBar->Append(menuMonitor, "Mo&nitor");
|
|
|
|
wxMenuItem *miCycleMonitor = menuMonitor->Append(ID_MENUITEM_CYCLE_MONITOR, "Cycle Type");
|
|
|
|
miCycleMonitor->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F2));
|
|
|
|
wxMenuItem *miToggleFullScreen = menuMonitor->Append(ID_MENUITEM_TOGGLE_FULL_SCREEN, "Toggle Full Screen");
|
|
|
|
miToggleFullScreen->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F3));
|
|
|
|
menuMonitor->AppendSeparator();
|
|
|
|
wxMenuItem *miScreenShot = menuMonitor->Append(ID_MENUITEM_SCREEN_SHOT, "Screen Shot!");
|
|
|
|
miScreenShot->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F8));
|
2022-12-05 03:45:35 +00:00
|
|
|
|
2022-12-04 04:18:52 +00:00
|
|
|
wxMenu *menuHelp = new wxMenu();
|
|
|
|
menuBar->Append(menuHelp, "&Help");
|
|
|
|
menuHelp->Append(wxID_ABOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void E2wxFrame::InitStatusBar() {
|
|
|
|
CreateStatusBar();
|
2022-12-08 17:18:22 +00:00
|
|
|
SetStatusText("Welcome to "+wxGetApp().GetID());
|
2022-12-04 04:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
void E2wxFrame::HandleUserQuitRequest(wxCloseEvent& event) {
|
|
|
|
// TODO how to handle event.CanVeto() ? I'd like to auto-save everything
|
|
|
|
if (wxGetApp().EnsureCanQuit()) {
|
|
|
|
event.Skip();
|
|
|
|
} else {
|
|
|
|
event.Veto();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-04 04:18:52 +00:00
|
|
|
void E2wxFrame::OnExit(wxCommandEvent& event) {
|
2022-12-12 05:52:19 +00:00
|
|
|
Close(false);
|
2022-12-04 04:18:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
void E2wxFrame::OnPreferences(wxCommandEvent& event) {
|
|
|
|
PreferencesDialog *dlg = new PreferencesDialog(this);
|
|
|
|
dlg->OnInit();
|
|
|
|
dlg->ShowModal();
|
|
|
|
}
|
|
|
|
|
2022-12-04 04:18:52 +00:00
|
|
|
void E2wxFrame::OnAbout(wxCommandEvent& event) {
|
|
|
|
wxString msg = "";
|
|
|
|
|
2022-12-08 17:18:22 +00:00
|
|
|
msg += wxGetApp().GetID()+"\n";
|
2022-12-04 04:18:52 +00:00
|
|
|
|
2022-12-08 17:18:22 +00:00
|
|
|
msg += "version: "+wxGetApp().GetVersion()+"\n";
|
2022-12-04 04:18:52 +00:00
|
|
|
|
2022-12-08 17:18:22 +00:00
|
|
|
msg += "Current log file:\n";
|
2022-12-04 04:18:52 +00:00
|
|
|
msg += wxGetApp().GetLogFile().c_str();
|
|
|
|
|
2022-12-08 17:18:22 +00:00
|
|
|
wxMessageBox(msg, "About "+wxGetApp().GetID(), wxOK | wxICON_INFORMATION);
|
2022-12-04 04:18:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
void E2wxFrame::OnTogglePower(wxCommandEvent& event) {
|
|
|
|
GUI::queueTogglePower();
|
|
|
|
}
|
|
|
|
|
|
|
|
void E2wxFrame::OnCycleMonitor(wxCommandEvent& event) {
|
|
|
|
wxGetApp().CycleMonitor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void E2wxFrame::OnToggleFullScreen(wxCommandEvent& event) {
|
|
|
|
wxGetApp().ToggleFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void E2wxFrame::OnReset(wxCommandEvent& event) {
|
|
|
|
wxGetApp().Reset();
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:03:30 +00:00
|
|
|
void E2wxFrame::OnPaste(wxCommandEvent& event) {
|
|
|
|
wxGetApp().Paste();
|
|
|
|
}
|
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
void E2wxFrame::OnScreenShot(wxCommandEvent& event) {
|
|
|
|
wxGetApp().ScreenShot();
|
2022-12-04 04:18:52 +00:00
|
|
|
}
|
2022-12-05 03:45:35 +00:00
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
void E2wxFrame::OnToggleBuffered(wxCommandEvent& event) {
|
|
|
|
wxGetApp().ToggleBuffered();
|
2022-12-05 03:45:35 +00:00
|
|
|
}
|
2022-12-12 05:52:19 +00:00
|
|
|
|
2022-12-13 02:47:10 +00:00
|
|
|
|