DolphinWX: Kill off trivial event tables

Also fixes some of the wonky stuff in Main where we would fire an event to do post-init stuff which isn't necessary anymore.
This commit is contained in:
Lioncash
2014-11-08 19:26:20 -05:00
parent 2a79d2343d
commit ac387031a4
17 changed files with 234 additions and 334 deletions

View File

@ -28,18 +28,13 @@
#include "DolphinWX/PatchAddEdit.h"
#include "DolphinWX/WxUtils.h"
BEGIN_EVENT_TABLE(CPatchAddEdit, wxDialog)
EVT_BUTTON(wxID_OK, CPatchAddEdit::SavePatchData)
EVT_BUTTON(ID_ENTRY_ADD, CPatchAddEdit::AddRemoveEntry)
EVT_BUTTON(ID_ENTRY_REMOVE, CPatchAddEdit::AddRemoveEntry)
EVT_SPIN(ID_ENTRY_SELECT, CPatchAddEdit::ChangeEntry)
END_EVENT_TABLE()
CPatchAddEdit::CPatchAddEdit(int _selection, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
selection = _selection;
CreateGUIControls(selection);
Bind(wxEVT_BUTTON, &CPatchAddEdit::SavePatchData, this, wxID_OK);
}
CPatchAddEdit::~CPatchAddEdit()
@ -64,25 +59,35 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
itCurEntry = tempEntries.begin();
wxBoxSizer* sEditPatch = new wxBoxSizer(wxVERTICAL);
wxStaticText* EditPatchNameText = new wxStaticText(this, ID_EDITPATCH_NAME_TEXT, _("Name:"));
EditPatchName = new wxTextCtrl(this, ID_EDITPATCH_NAME);
wxStaticText* EditPatchNameText = new wxStaticText(this, wxID_ANY, _("Name:"));
EditPatchName = new wxTextCtrl(this, wxID_ANY);
EditPatchName->SetValue(currentName);
wxStaticText* EditPatchOffsetText = new wxStaticText(this, ID_EDITPATCH_OFFSET_TEXT, _("Offset:"));
EditPatchOffset = new wxTextCtrl(this, ID_EDITPATCH_OFFSET);
wxStaticText* EditPatchOffsetText = new wxStaticText(this, wxID_ANY, _("Offset:"));
EditPatchOffset = new wxTextCtrl(this, wxID_ANY);
EditPatchOffset->SetValue(wxString::Format("%08X", tempEntries.at(0).address));
EntrySelection = new wxSpinButton(this, ID_ENTRY_SELECT);
EntrySelection = new wxSpinButton(this);
EntrySelection->Bind(wxEVT_SPIN, &CPatchAddEdit::ChangeEntry, this);
EntrySelection->SetRange(0, (int)tempEntries.size()-1);
EntrySelection->SetValue((int)tempEntries.size()-1);
wxArrayString wxArrayStringFor_EditPatchType;
for (int i = 0; i < 3; ++i)
wxArrayStringFor_EditPatchType.Add(StrToWxStr(PatchEngine::PatchTypeStrings[i]));
EditPatchType = new wxRadioBox(this, ID_EDITPATCH_TYPE, _("Type"), wxDefaultPosition, wxDefaultSize, wxArrayStringFor_EditPatchType, 3, wxRA_SPECIFY_COLS);
EditPatchType = new wxRadioBox(this, wxID_ANY, _("Type"), wxDefaultPosition, wxDefaultSize, wxArrayStringFor_EditPatchType, 3, wxRA_SPECIFY_COLS);
EditPatchType->SetSelection((int)tempEntries.at(0).type);
wxStaticText* EditPatchValueText = new wxStaticText(this, ID_EDITPATCH_VALUE_TEXT, _("Value:"));
EditPatchValue = new wxTextCtrl(this, ID_EDITPATCH_VALUE);
wxStaticText* EditPatchValueText = new wxStaticText(this, wxID_ANY, _("Value:"));
EditPatchValue = new wxTextCtrl(this, wxID_ANY);
EditPatchValue->SetValue(wxString::Format("%0*X", PatchEngine::GetPatchTypeCharLength(tempEntries.at(0).type), tempEntries.at(0).value));
wxButton *EntryAdd = new wxButton(this, ID_ENTRY_ADD, _("Add"));
EntryRemove = new wxButton(this, ID_ENTRY_REMOVE, _("Remove"));
EntryAdd = new wxButton(this, wxID_ANY, _("Add"));
EntryAdd->Bind(wxEVT_BUTTON, &CPatchAddEdit::AddEntry, this);
EntryRemove = new wxButton(this, wxID_ANY, _("Remove"));
EntryRemove->Bind(wxEVT_BUTTON, &CPatchAddEdit::RemoveEntry, this);
if ((int)tempEntries.size() <= 1)
EntryRemove->Disable();
@ -92,6 +97,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
sEditPatch->Add(sEditPatchName, 0, wxEXPAND);
sbEntry = new wxStaticBoxSizer(wxVERTICAL, this, wxString::Format(_("Entry 1/%d"), (int)tempEntries.size()));
currentItem = 1;
wxGridBagSizer* sgEntry = new wxGridBagSizer(0, 0);
sgEntry->Add(EditPatchType, wxGBPosition(0, 0), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
sgEntry->Add(EditPatchOffsetText, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
@ -100,6 +106,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
sgEntry->Add(EditPatchValue, wxGBPosition(2, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
sgEntry->Add(EntrySelection, wxGBPosition(0, 2), wxGBSpan(3, 1), wxEXPAND|wxALL, 5);
sgEntry->AddGrowableCol(1);
wxBoxSizer* sEntryAddRemove = new wxBoxSizer(wxHORIZONTAL);
sEntryAddRemove->Add(EntryAdd, 0, wxALL, 5);
sEntryAddRemove->Add(EntryRemove, 0, wxALL, 5);
@ -146,51 +153,44 @@ void CPatchAddEdit::SavePatchData(wxCommandEvent& event)
event.Skip();
}
void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event)
void CPatchAddEdit::AddEntry(wxCommandEvent& event)
{
switch (event.GetId())
if (!UpdateTempEntryData(itCurEntry))
return;
PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000);
++itCurEntry;
currentItem++;
itCurEntry = tempEntries.insert(itCurEntry, peEmptyEntry);
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1);
UpdateEntryCtrls(*itCurEntry);
EntryRemove->Enable();
EntrySelection->Enable();
}
void CPatchAddEdit::RemoveEntry(wxCommandEvent& event)
{
itCurEntry = tempEntries.erase(itCurEntry);
if (itCurEntry != tempEntries.begin())
{
case ID_ENTRY_ADD:
{
if (!UpdateTempEntryData(itCurEntry))
break;
--itCurEntry;
currentItem--;
}
else
{
EntrySelection->SetValue(EntrySelection->GetValue() - 1);
}
PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000);
++itCurEntry;
currentItem++;
itCurEntry = tempEntries.insert(itCurEntry, peEmptyEntry);
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() - 1);
UpdateEntryCtrls(*itCurEntry);
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1);
UpdateEntryCtrls(*itCurEntry);
EntryRemove->Enable();
EntrySelection->Enable();
}
break;
case ID_ENTRY_REMOVE:
{
itCurEntry = tempEntries.erase(itCurEntry);
if (itCurEntry != tempEntries.begin())
{
--itCurEntry;
currentItem--;
}
else
{
EntrySelection->SetValue(EntrySelection->GetValue() - 1);
}
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() - 1);
UpdateEntryCtrls(*itCurEntry);
if ((int)tempEntries.size() <= 1)
{
EntryRemove->Disable();
EntrySelection->Disable();
}
}
break;
if ((int)tempEntries.size() <= 1)
{
EntryRemove->Disable();
EntrySelection->Disable();
}
}