2022-02-16 00:53:01 -05:00
|
|
|
|
#pragma once
|
2023-11-08 02:23:12 -05:00
|
|
|
|
// wxWidgets has drop down menus, wxMenu, owned by the wxMenuBar,
|
|
|
|
|
// which is owned by the Frame window, but menus subject to replacement need
|
|
|
|
|
// to be destroyed by the child window.
|
|
|
|
|
// wxMenuOwner tracks a drop down menu that might be at a location in
|
|
|
|
|
// the menubar, places it in that location in the menubar on demand,
|
|
|
|
|
// and on destruction destroys it
|
|
|
|
|
// If, on destruction wxMenuBar is still pointing to this wxMenu, it
|
|
|
|
|
// replaces it with the default (empty) menu for that location.
|
|
|
|
|
// and disables it.
|
|
|
|
|
// We maintain an array of default empty wxMenu menus that are nullptr for
|
|
|
|
|
// locations not subject to replacement, and are the disabled initial and final
|
|
|
|
|
// wxMenuBar values for locations in the Menubar where the real drop down
|
|
|
|
|
// in the menubar will be installed by wxMenuTracker.
|
|
|
|
|
struct wxMenuTracker {
|
|
|
|
|
wxMenuTracker(int);
|
|
|
|
|
void Replace();
|
|
|
|
|
~wxMenuTracker() noexcept;
|
|
|
|
|
// Non nullptr members of InitialAndFinal have to be explicitly initially placed
|
|
|
|
|
// in the menubar in the frame constructor and explicitly disabled in
|
|
|
|
|
// the frame initializer. In the debug build, congruence between the menu bar
|
|
|
|
|
// and InitialAndFinal should be checked with assert.
|
|
|
|
|
static wxMenu* InitialAndFinal[3];
|
2023-11-10 07:00:15 -05:00
|
|
|
|
static void check_dynamic_menus_absent();
|
2023-11-08 02:23:12 -05:00
|
|
|
|
wxMenuTracker(wxMenuTracker&&) = delete; // Move constructor
|
|
|
|
|
wxMenuTracker(const wxMenuTracker&) = delete; // Copy constructor
|
|
|
|
|
wxMenuTracker& operator=(wxMenuTracker&&) = delete; // Move assignment.
|
|
|
|
|
wxMenuTracker& operator=(const wxMenuTracker&) = delete; // Copy assignment.
|
|
|
|
|
bool operator==(const wxMenuTracker&) const = delete;
|
|
|
|
|
auto operator<=>(const wxMenuTracker&) const = delete;
|
|
|
|
|
wxMenu* Menu;
|
|
|
|
|
const int MenuPosition;
|
|
|
|
|
// The menu title is defined elsewhere as an array
|
|
|
|
|
// of const strings
|
|
|
|
|
// menu_strings[MenuPosition].head
|
|
|
|
|
};
|
|
|
|
|
|
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
|
2022-05-23 02:06:01 -04:00
|
|
|
|
// the corresponding item from the drop down menu when the handler is destroyed.
|
2022-03-07 23:46:14 -05:00
|
|
|
|
// (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
|
2023-10-18 06:23:55 -04:00
|
|
|
|
{ int m_TipOfTheDayIndex;
|
|
|
|
|
int m_FileDialogFilterIndex;
|
2022-02-16 00:53:01 -05:00
|
|
|
|
public:
|
2023-10-18 06:23:55 -04:00
|
|
|
|
bool m_showTipsAtStartup;
|
|
|
|
|
wxFileName m_LastUsedWallet;
|
|
|
|
|
wxFileName m_DefaultWalletLocation;
|
|
|
|
|
Frame(const wxString& title);
|
|
|
|
|
virtual ~Frame();
|
2022-02-16 00:53:01 -05:00
|
|
|
|
wxLogWindow*m_pLogWindow{ nullptr };
|
|
|
|
|
std::unique_ptr<wxLogNull>m_pLogNull{ nullptr };
|
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 OnAbout(wxCommandEvent&);
|
|
|
|
|
void OnDeleteConfiguration(wxCommandEvent&);
|
2022-05-22 05:36:23 -04:00
|
|
|
|
void OnMyCloseMPanel(wxCommandEvent&);
|
2022-05-20 06:12:37 -04:00
|
|
|
|
|
2022-02-16 00:53:01 -05:00
|
|
|
|
public:
|
|
|
|
|
void OnSaveNew(wxCommandEvent&);
|
2022-04-14 05:17:18 -04:00
|
|
|
|
void NewWallet(wxFileName&, ristretto255::hash<256>&);
|
2022-02-16 00:53:01 -05:00
|
|
|
|
void RecreateWalletFromExistingSecret(wxCommandEvent&);
|
|
|
|
|
void OnFileOpen(wxCommandEvent&);
|
2022-05-22 05:36:23 -04:00
|
|
|
|
void OnClose(wxCloseEvent& event);
|
2022-02-16 00:53:01 -05:00
|
|
|
|
private:
|
|
|
|
|
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;
|