diff --git a/src/xenia/app/emulator_window.cc b/src/xenia/app/emulator_window.cc index ca50864b1..634c65803 100644 --- a/src/xenia/app/emulator_window.cc +++ b/src/xenia/app/emulator_window.cc @@ -266,6 +266,8 @@ bool EmulatorWindow::Initialize() { window_->Resize(1280, 720); + window_->DisableMainMenu(); + return true; } diff --git a/src/xenia/app/xenia_main.cc b/src/xenia/app/xenia_main.cc index 03664f4a9..b2cf33c9b 100644 --- a/src/xenia/app/xenia_main.cc +++ b/src/xenia/app/xenia_main.cc @@ -178,6 +178,9 @@ int xenia_main(const std::vector& args) { evt->Set(); }); + // Enable the main menu now that the emulator is properly loaded + emulator_window->window()->EnableMainMenu(); + // Grab path from the flag or unnamed argument. std::wstring path; if (!FLAGS_target.empty() || args.size() >= 2) { diff --git a/src/xenia/ui/menu_item.h b/src/xenia/ui/menu_item.h index e1364d6b6..4cdc5cca2 100644 --- a/src/xenia/ui/menu_item.h +++ b/src/xenia/ui/menu_item.h @@ -19,6 +19,8 @@ namespace xe { namespace ui { +class Window; + class MenuItem { public: typedef std::unique_ptr MenuItemPtr; @@ -51,6 +53,9 @@ class MenuItem { void RemoveChild(MenuItem* child_item); MenuItem* child(size_t index); + virtual void EnableMenuItem(Window& window) = 0; + virtual void DisableMenuItem(Window& window) = 0; + protected: MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey, std::function callback); diff --git a/src/xenia/ui/window.h b/src/xenia/ui/window.h index 107078be1..46d5389d3 100644 --- a/src/xenia/ui/window.h +++ b/src/xenia/ui/window.h @@ -44,6 +44,9 @@ class Window { OnMainMenuChange(); } + virtual void EnableMainMenu() = 0; + virtual void DisableMainMenu() = 0; + const std::wstring& title() const { return title_; } virtual bool set_title(const std::wstring& title) { if (title == title_) { diff --git a/src/xenia/ui/window_win.cc b/src/xenia/ui/window_win.cc index ba1ff0556..c5512dc60 100644 --- a/src/xenia/ui/window_win.cc +++ b/src/xenia/ui/window_win.cc @@ -163,6 +163,18 @@ void Win32Window::OnClose() { super::OnClose(); } +void Win32Window::EnableMainMenu() { + if (main_menu_) { + main_menu_->EnableMenuItem(*this); + } +} + +void Win32Window::DisableMainMenu() { + if (main_menu_) { + main_menu_->DisableMenuItem(*this); + } +} + bool Win32Window::set_title(const std::wstring& title) { if (!super::set_title(title)) { return false; @@ -628,6 +640,22 @@ Win32MenuItem::~Win32MenuItem() { } } +void Win32MenuItem::EnableMenuItem(Window& window) { + int i = 0; + for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) { + ::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_ENABLED); + } + DrawMenuBar((HWND)window.native_handle()); +} + +void Win32MenuItem::DisableMenuItem(Window& window) { + int i = 0; + for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) { + ::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_GRAYED); + } + DrawMenuBar((HWND)window.native_handle()); +} + void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) { auto child_item = static_cast(generic_child_item); diff --git a/src/xenia/ui/window_win.h b/src/xenia/ui/window_win.h index eae68b2ce..ef70ce40c 100644 --- a/src/xenia/ui/window_win.h +++ b/src/xenia/ui/window_win.h @@ -30,6 +30,9 @@ class Win32Window : public Window { NativeWindowHandle native_handle() const override { return hwnd_; } HWND hwnd() const { return hwnd_; } + void EnableMainMenu() override; + void DisableMainMenu() override; + bool set_title(const std::wstring& title) override; bool SetIcon(const void* buffer, size_t size) override; @@ -87,6 +90,9 @@ class Win32MenuItem : public MenuItem { HMENU handle() { return handle_; } + void EnableMenuItem(Window& window) override; + void DisableMenuItem(Window& window) override; + using MenuItem::OnSelected; protected: