2022-02-16 00:53:01 -05:00
|
|
|
|
#pragma once
|
2022-04-02 22:07:41 -04:00
|
|
|
|
template <typename T>
|
2022-03-07 23:46:14 -05:00
|
|
|
|
// This class exists to record the needed to unbind a drop down menu action and delete
|
|
|
|
|
// the corresponding item from the drop down menu when the handler is destroyed.
|
|
|
|
|
// (Because the handler is a method of an object that is about to be destroyed.)
|
2022-02-16 00:53:01 -05:00
|
|
|
|
// Also avoids the need for manually creating a new windowid to link each additional bind
|
|
|
|
|
// to each menu item, thus avoids the likelihood of mismatching binds and menu entries.
|
|
|
|
|
class MenuLink {
|
2022-04-02 22:07:41 -04:00
|
|
|
|
typedef void (T::* method_handler)(wxCommandEvent&);
|
|
|
|
|
// (thing.*p)(args) is how you use a pointer to method
|
|
|
|
|
T* m_handler = nullptr;
|
|
|
|
|
method_handler m_method;
|
2022-02-16 00:53:01 -05:00
|
|
|
|
int m_winid;
|
2022-04-02 22:07:41 -04:00
|
|
|
|
wxMenu* m_menu = nullptr;
|
|
|
|
|
wxMenuItem* m_menuItem = nullptr;
|
2022-02-16 00:53:01 -05:00
|
|
|
|
public:
|
2022-04-02 22:07:41 -04:00
|
|
|
|
MenuLink() = delete;
|
|
|
|
|
MenuLink(const MenuLink&) = default;
|
|
|
|
|
MenuLink(const MenuLink&&) = delete;
|
|
|
|
|
MenuLink& operator=(const MenuLink&) = delete;
|
|
|
|
|
MenuLink& operator=(MenuLink&) = delete;
|
|
|
|
|
MenuLink(T* handler, method_handler method) :
|
|
|
|
|
m_handler(handler), m_method{ method }, m_winid{ wxWindow::NewControlId() }{}
|
|
|
|
|
MenuLink(T* handler, method_handler method, MyIDs winid) :
|
|
|
|
|
m_handler(handler), m_method{ method }, m_winid{ winid } {}
|
2022-02-16 00:53:01 -05:00
|
|
|
|
~MenuLink() {
|
|
|
|
|
if (m_menu != nullptr) {
|
|
|
|
|
m_menu->Unbind(wxEVT_MENU, m_method, m_handler, m_winid);
|
|
|
|
|
m_menu->Destroy(m_menuItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-02 22:07:41 -04:00
|
|
|
|
wxMenuItem* Insert(
|
2022-02-16 00:53:01 -05:00
|
|
|
|
wxMenu* menu,
|
2022-04-02 22:07:41 -04:00
|
|
|
|
size_t pos,
|
|
|
|
|
const wxString& item,
|
|
|
|
|
const wxString& help = wxEmptyString
|
2022-02-16 00:53:01 -05:00
|
|
|
|
) {
|
2022-04-02 22:07:41 -04:00
|
|
|
|
if (m_menu == nullptr) m_menu = menu;
|
|
|
|
|
else {
|
|
|
|
|
assert(false);
|
|
|
|
|
throw MyException("Reinsertion of menu item");
|
|
|
|
|
}
|
|
|
|
|
m_menuItem = menu->Insert(pos, m_winid, item, help);
|
|
|
|
|
menu->Bind(wxEVT_MENU, m_method, m_handler, m_winid);
|
2022-02-16 00:53:01 -05:00
|
|
|
|
return m_menuItem;
|
|
|
|
|
}
|
|
|
|
|
void queue_event() {
|
|
|
|
|
if (m_menu != nullptr) {
|
|
|
|
|
auto event = new wxCommandEvent(wxEVT_MENU, m_winid);
|
|
|
|
|
wxQueueEvent(m_menu, event);
|
|
|
|
|
}
|
2022-04-02 22:07:41 -04:00
|
|
|
|
else {
|
|
|
|
|
assert(false);
|
|
|
|
|
throw MyException("Event sent to uninitialized Menu item");
|
|
|
|
|
}
|
2022-02-16 00:53:01 -05:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Frame : public wxFrame
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
wxLogWindow*m_pLogWindow{ nullptr };
|
|
|
|
|
std::unique_ptr<wxLogNull>m_pLogNull{ nullptr };
|
|
|
|
|
Frame(wxString);
|
|
|
|
|
~Frame();
|
|
|
|
|
wxFileName m_LastUsedSqlite;
|
2022-04-02 22:07:41 -04:00
|
|
|
|
wxPanel* m_panel{nullptr}; //The once current child panel.
|
2022-02-16 00:53:01 -05:00
|
|
|
|
private:
|
|
|
|
|
typedef MenuLink<Frame> MenuLink;
|
|
|
|
|
void StorePositionToConfig(void);
|
|
|
|
|
void RestorePositionFromConfig(const wxSize&);
|
|
|
|
|
void OnExit(wxCommandEvent&);
|
|
|
|
|
void OnClose(wxCloseEvent&);
|
|
|
|
|
void OnAbout(wxCommandEvent&);
|
|
|
|
|
void OnDeleteConfiguration(wxCommandEvent&);
|
2022-04-02 22:07:41 -04:00
|
|
|
|
void OnMyCloseMpanel(wxCommandEvent&);
|
|
|
|
|
|
2022-02-16 00:53:01 -05:00
|
|
|
|
public:
|
|
|
|
|
void OnSaveNew(wxCommandEvent&);
|
|
|
|
|
void NewWalletNewSecret(wxCommandEvent&);
|
|
|
|
|
void RecreateWalletFromExistingSecret(wxCommandEvent&);
|
|
|
|
|
void OnFileOpen(wxCommandEvent&);
|
2022-04-02 22:07:41 -04:00
|
|
|
|
|
2022-02-16 00:53:01 -05:00
|
|
|
|
private:
|
|
|
|
|
void OnDelete(wxCommandEvent&);
|
|
|
|
|
void OnMenuOpen(wxMenuEvent&);
|
|
|
|
|
public:
|
|
|
|
|
void OnFirstUse(wxCommandEvent&);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// MenuLink menu_OnFirstUse =
|
|
|
|
|
// MenuLink(&Frame::OnFirstUse, myID_WELCOME_TO_ROCOIN);
|
|
|
|
|
};
|
2022-04-02 22:07:41 -04:00
|
|
|
|
|
|
|
|
|
extern Frame* singletonFrame;
|
|
|
|
|
|