Skip to content

Commit

Permalink
Merge pull request #4363 from lioncash/wx-menu
Browse files Browse the repository at this point in the history
DolphinWX: Move main menu creation into a wxMenuBar subclass
  • Loading branch information
JosJuice committed Oct 21, 2016
2 parents d62a036 + 42e1daf commit a2644cd
Show file tree
Hide file tree
Showing 9 changed files with 792 additions and 738 deletions.
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/CMakeLists.txt
Expand Up @@ -53,6 +53,7 @@ set(GUI_SRCS
LogConfigWindow.cpp
LogWindow.cpp
Main.cpp
MainMenuBar.cpp
MemcardManager.cpp
PatchAddEdit.cpp
PostProcessingConfigDiag.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinWX/DolphinWX.vcxproj
Expand Up @@ -107,6 +107,7 @@
<ClCompile Include="LogConfigWindow.cpp" />
<ClCompile Include="LogWindow.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="MainMenuBar.cpp" />
<ClCompile Include="MainNoGUI.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
Expand Down Expand Up @@ -173,6 +174,7 @@
<ClInclude Include="LogConfigWindow.h" />
<ClInclude Include="LogWindow.h" />
<ClInclude Include="Main.h" />
<ClInclude Include="MainMenuBar.h" />
<ClInclude Include="MemcardManager.h" />
<ClInclude Include="PatchAddEdit.h" />
<ClInclude Include="SoftwareVideoConfigDialog.h" />
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DolphinWX/DolphinWX.vcxproj.filters
Expand Up @@ -148,6 +148,9 @@
<ClCompile Include="LogWindow.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="MainMenuBar.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="MemcardManager.cpp">
<Filter>GUI</Filter>
</ClCompile>
Expand Down Expand Up @@ -324,6 +327,9 @@
<ClInclude Include="LogWindow.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="MainMenuBar.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="MemcardManager.h">
<Filter>GUI</Filter>
</ClInclude>
Expand Down
100 changes: 11 additions & 89 deletions Source/Core/DolphinWX/Frame.cpp
Expand Up @@ -220,96 +220,17 @@ bool CRenderFrame::ShowFullScreen(bool show, long style)
return result;
}

// event tables
// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
// help button.

wxDEFINE_EVENT(wxEVT_HOST_COMMAND, wxCommandEvent);
wxDEFINE_EVENT(DOLPHIN_EVT_LOCAL_INI_CHANGED, wxCommandEvent);

// Event tables
BEGIN_EVENT_TABLE(CFrame, CRenderFrame)

// Menu bar
EVT_MENU(wxID_OPEN, CFrame::OnOpen)
EVT_MENU(wxID_EXIT, CFrame::OnQuit)
EVT_MENU(IDM_HELP_WEBSITE, CFrame::OnHelp)
EVT_MENU(IDM_HELP_ONLINE_DOCS, CFrame::OnHelp)
EVT_MENU(IDM_HELP_GITHUB, CFrame::OnHelp)
EVT_MENU(wxID_ABOUT, CFrame::OnHelp)
EVT_MENU(wxID_REFRESH, CFrame::OnRefresh)
EVT_MENU(IDM_PLAY, CFrame::OnPlay)
EVT_MENU(IDM_STOP, CFrame::OnStop)
EVT_MENU(IDM_RESET, CFrame::OnReset)
EVT_MENU(IDM_RECORD, CFrame::OnRecord)
EVT_MENU(IDM_PLAY_RECORD, CFrame::OnPlayRecording)
EVT_MENU(IDM_RECORD_EXPORT, CFrame::OnRecordExport)
EVT_MENU(IDM_RECORD_READ_ONLY, CFrame::OnRecordReadOnly)
EVT_MENU(IDM_TAS_INPUT, CFrame::OnTASInput)
EVT_MENU(IDM_TOGGLE_PAUSE_MOVIE, CFrame::OnTogglePauseMovie)
EVT_MENU(IDM_SHOW_LAG, CFrame::OnShowLag)
EVT_MENU(IDM_SHOW_FRAME_COUNT, CFrame::OnShowFrameCount)
EVT_MENU(IDM_SHOW_INPUT_DISPLAY, CFrame::OnShowInputDisplay)
EVT_MENU(IDM_SHOW_RTC_DISPLAY, CFrame::OnShowRTCDisplay)
EVT_MENU(IDM_FRAMESTEP, CFrame::OnFrameStep)
EVT_MENU(IDM_SCREENSHOT, CFrame::OnScreenshot)
EVT_MENU(IDM_TOGGLE_DUMP_FRAMES, CFrame::OnToggleDumpFrames)
EVT_MENU(IDM_TOGGLE_DUMP_AUDIO, CFrame::OnToggleDumpAudio)
EVT_MENU(wxID_PREFERENCES, CFrame::OnConfigMain)
EVT_MENU(IDM_CONFIG_GFX_BACKEND, CFrame::OnConfigGFX)
EVT_MENU(IDM_CONFIG_AUDIO, CFrame::OnConfigAudio)
EVT_MENU(IDM_CONFIG_CONTROLLERS, CFrame::OnConfigControllers)
EVT_MENU(IDM_CONFIG_HOTKEYS, CFrame::OnConfigHotkey)

EVT_MENU(IDM_SAVE_PERSPECTIVE, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_EDIT_PERSPECTIVES, CFrame::OnPerspectiveMenu)
// Drop down
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_TOP, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_BOTTOM, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_LEFT, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_RIGHT, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_CENTER, CFrame::OnPerspectiveMenu)
EVT_MENU_RANGE(IDM_PERSPECTIVES_0, IDM_PERSPECTIVES_100, CFrame::OnSelectPerspective)
EVT_MENU(IDM_ADD_PERSPECTIVE, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_TAB_SPLIT, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_NO_DOCKING, CFrame::OnPerspectiveMenu)
// Drop down float
// Debugger pane context menu
EVT_MENU_RANGE(IDM_FLOAT_LOG_WINDOW, IDM_FLOAT_CODE_WINDOW, CFrame::OnFloatWindow)

EVT_MENU(IDM_NETPLAY, CFrame::OnNetPlay)
EVT_MENU(IDM_MEMCARD, CFrame::OnMemcard)
EVT_MENU(IDM_IMPORT_SAVE, CFrame::OnImportSave)
EVT_MENU(IDM_EXPORT_ALL_SAVE, CFrame::OnExportAllSaves)
EVT_MENU(IDM_CHEATS, CFrame::OnShowCheatsWindow)
EVT_MENU(IDM_CHANGE_DISC, CFrame::OnChangeDisc)
EVT_MENU(IDM_MENU_INSTALL_WAD, CFrame::OnInstallWAD)
// Game list context menu
EVT_MENU(IDM_LIST_INSTALL_WAD, CFrame::OnInstallWAD)
EVT_MENU(IDM_LOAD_WII_MENU, CFrame::OnLoadWiiMenu)
EVT_MENU(IDM_FIFOPLAYER, CFrame::OnFifoPlayer)

EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
EVT_MENU(IDM_TOGGLE_DUAL_CORE, CFrame::OnToggleDualCore)
EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
EVT_MENU_RANGE(IDM_LOG_WINDOW, IDM_VIDEO_WINDOW, CFrame::OnToggleWindow)
EVT_MENU_RANGE(IDM_SHOW_SYSTEM, IDM_SHOW_STATE, CFrame::OnChangeColumnsVisible)

EVT_MENU(IDM_PURGE_GAME_LIST_CACHE, CFrame::GameListChanged)

EVT_MENU(IDM_SAVE_FIRST_STATE, CFrame::OnSaveFirstState)
EVT_MENU(IDM_UNDO_LOAD_STATE, CFrame::OnUndoLoadState)
EVT_MENU(IDM_UNDO_SAVE_STATE, CFrame::OnUndoSaveState)
EVT_MENU(IDM_LOAD_STATE_FILE, CFrame::OnLoadStateFromFile)
EVT_MENU(IDM_SAVE_STATE_FILE, CFrame::OnSaveStateToFile)
EVT_MENU(IDM_SAVE_SELECTED_SLOT, CFrame::OnSaveCurrentSlot)
EVT_MENU(IDM_LOAD_SELECTED_SLOT, CFrame::OnLoadCurrentSlot)

EVT_MENU_RANGE(IDM_LOAD_SLOT_1, IDM_LOAD_SLOT_10, CFrame::OnLoadState)
EVT_MENU_RANGE(IDM_LOAD_LAST_1, IDM_LOAD_LAST_10, CFrame::OnLoadLastState)
EVT_MENU_RANGE(IDM_SAVE_SLOT_1, IDM_SAVE_SLOT_10, CFrame::OnSaveState)
EVT_MENU_RANGE(IDM_SELECT_SLOT_1, IDM_SELECT_SLOT_10, CFrame::OnSelectSlot)
EVT_MENU_RANGE(IDM_DRIVE1, IDM_DRIVE24, CFrame::OnBootDrive)
EVT_MENU_RANGE(IDM_CONNECT_WIIMOTE1, IDM_CONNECT_BALANCEBOARD, CFrame::OnConnectWiimote)
EVT_MENU_RANGE(IDM_LIST_WAD, IDM_LIST_DRIVES, CFrame::GameListChanged)

// Other
EVT_ACTIVATE(CFrame::OnActive)
Expand Down Expand Up @@ -375,6 +296,8 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo
UseDebugger(use_debugger), m_bBatchMode(batch_mode),
m_toolbar_bitmap_size(FromDIP(wxSize(32, 32)))
{
BindMenuBarEvents();

for (int i = 0; i <= IDM_CODE_WINDOW - IDM_LOG_WINDOW; i++)
bFloatWindow[i] = false;

Expand All @@ -398,8 +321,7 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo
GetStatusBar()->Hide();

// Give it a menu bar
wxMenuBar* menubar_active = CreateMenuBar();
SetMenuBar(menubar_active);
SetMenuBar(CreateMenuBar());
// Create a menubar to service requests while the real menubar is hidden from the screen
m_menubar_shadow = CreateMenuBar();

Expand Down Expand Up @@ -941,7 +863,7 @@ static bool IsHotkey(int id, bool held = false)
return HotkeyManagerEmu::IsPressed(id, held);
}

int GetCmdForHotkey(unsigned int key)
static int GetMenuIDFromHotkey(unsigned int key)
{
switch (key)
{
Expand Down Expand Up @@ -1363,11 +1285,11 @@ void CFrame::ParseHotkeys()

if (IsHotkey(i))
{
int cmd = GetCmdForHotkey(i);
if (cmd >= 0)
const int id = GetMenuIDFromHotkey(i);
if (id >= 0)
{
wxCommandEvent evt(wxEVT_MENU, cmd);
wxMenuItem* item = GetMenuBar()->FindItem(cmd);
wxCommandEvent evt(wxEVT_MENU, id);
wxMenuItem* item = GetMenuBar()->FindItem(id);
if (item && item->IsCheckable())
{
item->wxMenuItemBase::Toggle();
Expand Down
21 changes: 5 additions & 16 deletions Source/Core/DolphinWX/Frame.h
Expand Up @@ -106,7 +106,6 @@ class CFrame : public CRenderFrame
void DoFullscreen(bool bF);
void ToggleDisplayMode(bool bFullscreen);
void UpdateWiiMenuChoice(wxMenuItem* WiiMenuItem = nullptr);
void PopulateSavedPerspectives();
static void ConnectWiimote(int wm_idx, bool connect);
void UpdateTitle(const std::string& str);
void OpenGeneralConfiguration(int tab = -1);
Expand Down Expand Up @@ -199,21 +198,11 @@ class CFrame : public CRenderFrame

void PopulateToolbar(wxToolBar* toolBar);
void RecreateToolbar();
wxMenuBar* CreateMenuBar();
wxMenu* CreateFileMenu();
wxMenu* CreateEmulationMenu();
wxMenu* CreateMovieMenu();
wxMenu* CreateOptionsMenu();
wxMenu* CreateToolsMenu();
wxMenu* CreateViewMenu();
wxMenu* CreateJITMenu();
wxMenu* CreateDebugMenu();
wxMenu* CreateSymbolsMenu();
wxMenu* CreateProfilerMenu();
wxMenu* CreateHelpMenu();

wxMenuBar* CreateMenuBar() const;
void BindMenuBarEvents();

// Utility
wxString GetMenuLabel(int Id);
wxWindow* GetNotebookPageFromId(wxWindowID Id);
wxAuiNotebook* GetNotebookFromId(u32 NBId);
int GetNotebookCount();
Expand All @@ -236,6 +225,8 @@ class CFrame : public CRenderFrame
void SetPaneSize();
void TogglePaneStyle(bool On, int EventId);
void ToggleNotebookStyle(bool On, long Style);
void PopulateSavedPerspectives();

// Float window
void DoUnfloatPage(int Id);
void OnFloatingPageClosed(wxCloseEvent& event);
Expand Down Expand Up @@ -351,8 +342,6 @@ class CFrame : public CRenderFrame
DECLARE_EVENT_TABLE();
};

int GetCmdForHotkey(unsigned int key);

void OnAfterLoadCallback();
void OnStoppedCallback();

Expand Down
32 changes: 9 additions & 23 deletions Source/Core/DolphinWX/FrameAui.cpp
Expand Up @@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <algorithm>
#include <cstddef>
#include <string>
#include <vector>
Expand Down Expand Up @@ -36,6 +37,7 @@
#include "DolphinWX/Globals.h"
#include "DolphinWX/LogConfigWindow.h"
#include "DolphinWX/LogWindow.h"
#include "DolphinWX/MainMenuBar.h"
#include "DolphinWX/WxUtils.h"
#include "DolphinWX/Debugger/DebuggerUIUtil.h"

Expand Down Expand Up @@ -484,32 +486,16 @@ void CFrame::DoAddPage(wxWindow* Win, int i, bool Float)

void CFrame::PopulateSavedPerspectives()
{
// If the perspective submenu hasn't been created yet, return
if (!m_SavedPerspectives)
return;
std::vector<std::string> perspective_names(Perspectives.size());

// Delete all saved perspective menu items
while (m_SavedPerspectives->GetMenuItemCount() != 0)
{
// Delete the first menu item in the list (while there are menu items)
m_SavedPerspectives->Delete(m_SavedPerspectives->FindItemByPosition(0));
}

if (Perspectives.size() > 0)
{
for (u32 i = 0; i < Perspectives.size(); i++)
{
wxMenuItem* mItem = new wxMenuItem(m_SavedPerspectives, IDM_PERSPECTIVES_0 + i,
StrToWxStr(Perspectives[i].Name), "", wxITEM_CHECK);
std::transform(Perspectives.begin(), Perspectives.end(), perspective_names.begin(),
[](const auto& perspective) { return perspective.Name; });

m_SavedPerspectives->Append(mItem);
MainMenuBar::PopulatePerspectivesEvent event{GetId(), EVT_POPULATE_PERSPECTIVES_MENU,
std::move(perspective_names),
static_cast<int>(ActivePerspective)};

if (i == ActivePerspective)
{
mItem->Check(true);
}
}
}
wxPostEvent(GetMenuBar(), event);
}

void CFrame::OnPerspectiveMenu(wxCommandEvent& event)
Expand Down

0 comments on commit a2644cd

Please sign in to comment.