#pragma once template // 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.) // 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 { void (handler_class::* m_method)(wxCommandEvent&); int m_winid; handler_class* m_handler = nullptr; wxMenu* m_menu =nullptr; wxMenuItem* m_menuItem = nullptr;; public: MenuLink( void (handler_class::* method)(wxCommandEvent&)) : m_method{ method }, m_winid{ wxWindow::NewControlId()} {} MenuLink( void (handler_class::* method)(wxCommandEvent&), MyIDs winid) : m_method{ method }, m_winid{ winid } {} ~MenuLink() { if (m_menu != nullptr) { m_menu->Unbind(wxEVT_MENU, m_method, m_handler, m_winid); m_menu->Destroy(m_menuItem); } } auto Append( wxMenu* menu, handler_class* handler, const wxString& item = wxEmptyString, const wxString& helpString = wxEmptyString ) { m_menu = menu; m_handler = handler; m_menuItem = menu->Append(m_winid, item, helpString); menu->Bind(wxEVT_MENU, m_method, handler, m_winid); return m_menuItem; } void queue_event() { if (m_menu != nullptr) { auto event = new wxCommandEvent(wxEVT_MENU, m_winid); wxQueueEvent(m_menu, event); } else throw MyException("Event sent to uninitialized Menu item"); } }; class Frame : public wxFrame { public: wxLogWindow*m_pLogWindow{ nullptr }; std::unique_ptrm_pLogNull{ nullptr }; Frame(wxString); ~Frame(); wxFileName m_LastUsedSqlite; private: typedef MenuLink MenuLink; wxPanel* m_panel; //The once current child panel. void StorePositionToConfig(void); void RestorePositionFromConfig(const wxSize&); void OnExit(wxCommandEvent&); void OnClose(wxCloseEvent&); void OnAbout(wxCommandEvent&); void OnDeleteConfiguration(wxCommandEvent&); public: void OnSaveNew(wxCommandEvent&); void NewWalletNewSecret(wxCommandEvent&); void RecreateWalletFromExistingSecret(wxCommandEvent&); void OnFileOpen(wxCommandEvent&); private: void OnDelete(wxCommandEvent&); void OnMenuOpen(wxMenuEvent&); void OnDeleteSubwindow(wxCommandEvent&); MenuLink menu_OnDeleteSubwindow = MenuLink(&Frame::OnDeleteSubwindow); void OnDeleteLastSubwindow(wxCommandEvent&); void OnAddSubwindow(wxCommandEvent&); public: void OnFirstUse(wxCommandEvent&); public: // MenuLink menu_OnFirstUse = // MenuLink(&Frame::OnFirstUse, myID_WELCOME_TO_ROCOIN); }; inline Frame* singletonFrame(nullptr);