wallet/welcome_to_rhocoin.cpp
Cheng 137a78735b
Fixing window switches within the frame
Painfully discovered that wxWidgets does not like it
if you do not handle the close event.  Default
handling is broken, perhaps unavoidably because the base
object does not know about the derived object.
2022-04-03 12:07:41 +10:00

155 lines
4.5 KiB
C++

#include "stdafx.h"
template <typename T>class roFont : public wxFont {
public:
T* m_win;
roFont(T* win) :wxFont(win->GetFont()), m_win(win) {}
~roFont() { m_win->SetFont(*this); }
auto SetPointSize(int i) { wxFont::SetPointSize(i);
return m_win;
}
};
wxButton* welcome_to_rhocoin::AddButton(
wxString wxs,
void(Frame::* method)(wxCommandEvent&)
) {
auto button{
new wxButton(
this,
wxWindow::NewControlId(),
wxs,
wxDefaultPosition, wxDefaultSize, 0L, wxDefaultValidator,
wxs
)
};
Bind(wxEVT_BUTTON, method, singletonFrame, button->GetId());
return button;
}
// This routine exists to override wxWidgets overly clever translation of utf-8 to wxStrings.
wxButton* welcome_to_rhocoin::AddButton(
const char sz[],
void(Frame::* method)(wxCommandEvent&)
) {
return AddButton(_wx(sz), method);
}
welcome_to_rhocoin::welcome_to_rhocoin(
wxWindow* parent) : wxPanel(
parent,
myID_WELCOME_TO_ROCOIN,
wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL,
_wx(sz_NewWallet)
)
{ if (singletonWelcome != nullptr)singletonWelcome->Destroy();
auto sizer = new wxBoxSizer(wxVERTICAL); //Allocated on heap, eventually gets given to this window, which will delete it.
sizer->Add(
roFont(
new wxStaticText(
this,
wxID_ANY,
_wx(sz_welcome_to_rocoin),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE_HORIZONTAL | wxTE_MULTILINE
)
).SetPointSize(32),
42, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
sizer->Add(
roFont(
new wxStaticText(
this,
wxID_ANY,
_wx(sz_please_select_from_three_options),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE_HORIZONTAL | wxTE_MULTILINE
)
).SetPointSize(20),
12, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
auto sizerRow{ new wxGridSizer(3, 2, 2) };
sizerRow->Add(
new wxStaticText(
this,
wxID_ANY,
_wx(sz_create_a_new_wallet),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE_HORIZONTAL | wxTE_MULTILINE
),
40, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
sizerRow->Add(
new wxStaticText(
this,
wxID_ANY,
_wx(sz_recreate_wallet_from_old_secret),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE_HORIZONTAL | wxTE_MULTILINE
),
40, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
sizerRow->Add(
new wxStaticText(
this,
wxID_ANY,
_wx(sz_open_existing_wallet),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE_HORIZONTAL | wxTE_MULTILINE
),
40,
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
sizer->Add(sizerRow, 20, wxEXPAND | wxALL, 2);
wxButton * btn_default;
sizerRow = new wxGridSizer(3, 2, 2);
sizerRow->Add(
btn_default=AddButton(sz_new_wallet, &Frame::OnSaveNew),
40, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
2);
sizerRow->Add(
AddButton(sz_existing_secret, &Frame::RecreateWalletFromExistingSecret),
40, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
4);
sizerRow->Add(
AddButton(sz_existing_wallet, &Frame::OnFileOpen),
40, // make vertically stretchable
wxEXPAND | // make horizontally stretchable
wxALL, // and make border all around
4);
sizer->Add(sizerRow, 40, wxEXPAND | wxALL, 2);
btn_default->SetDefault();
SetSizer(sizer);
Bind(wxEVT_CLOSE_WINDOW, &welcome_to_rhocoin::OnClose, this);
assert(singletonWelcome == nullptr);
singletonWelcome = this;
}
welcome_to_rhocoin::~welcome_to_rhocoin() {
assert(singletonWelcome ==this);
singletonWelcome = nullptr;
}
void welcome_to_rhocoin::OnClose(wxCloseEvent& event) {
// This event gives you the opportunity to clean up anything that needs explicit cleanup, albeit if you have done your work right nothing should need explicit cleanup,
// and to object to the closing in a "file not saved" type situation.
// https://docs.wxwidgets.org/trunk/classwx_close_event.html
DestroyChildren();
Destroy(); //Default handler will destroy the window. This is our handler for the user calling close, replacing the default handler.
}