Skip to content

Commit

Permalink
[Imp] Show new toolbar visbility options in main menu as well.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22139 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 10, 2024
1 parent e6cb26b commit 13e9d06
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 44 deletions.
79 changes: 42 additions & 37 deletions mptrack/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ void CMainFrame::Initialize()
CreateTemplateModulesMenu();
UpdateMRUList();

auto [toolbarMenu, toolbarMenuStartPos] = FindMenuItemByCommand(*GetMenu(), ID_VIEW_TOOLBAR);
MPT_ASSERT(toolbarMenu);
if(toolbarMenu)
{
toolbarMenu->DeleteMenu(toolbarMenuStartPos, MF_BYPOSITION);
AddToolBarMenuEntries(*toolbarMenu);
}

#ifdef MPT_ENABLE_PLAYBACK_TEST_MENU
CMenu debugMenu;
debugMenu.CreatePopupMenu();
Expand Down Expand Up @@ -2517,23 +2525,30 @@ void CMainFrame::OnRButtonDown(UINT, CPoint pt)

void CMainFrame::ShowToolbarMenu(CPoint screenPt)
{
CMenu menu, subMenu;
if(!menu.CreatePopupMenu() || !subMenu.CreatePopupMenu())
CMenu menu;
if(!menu.CreatePopupMenu())
return;
AddToolBarMenuEntries(menu);
menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, screenPt.x, screenPt.y, this);
}


void CMainFrame::AddToolBarMenuEntries(CMenu &menu)
{
menu.AppendMenu(MF_STRING, ID_VIEW_TOOLBAR, m_InputHandler->GetMenuText(ID_VIEW_TOOLBAR));
menu.AppendMenu(MF_STRING, IDD_TREEVIEW, m_InputHandler->GetMenuText(IDD_TREEVIEW));

const FlagSet<MainToolBarItem> visibleItems = TrackerSettings::Instance().mainToolBarVisibleItems.Get();

CMenu subMenu;
VERIFY(subMenu.CreatePopupMenu());
subMenu.AppendMenu(MF_STRING | (visibleItems[MainToolBarItem::Octave] ? MF_CHECKED : 0), ID_MAINBAR_SHOW_OCTAVE, _T("Base &Octave"));
subMenu.AppendMenu(MF_STRING | (visibleItems[MainToolBarItem::Tempo] ? MF_CHECKED : 0), ID_MAINBAR_SHOW_TEMPO, _T("&Tempo"));
subMenu.AppendMenu(MF_STRING | (visibleItems[MainToolBarItem::Speed] ? MF_CHECKED : 0), ID_MAINBAR_SHOW_SPEED, _T("Ticks/&Row"));
subMenu.AppendMenu(MF_STRING | (visibleItems[MainToolBarItem::RowsPerBeat] ? MF_CHECKED : 0), ID_MAINBAR_SHOW_ROWSPERBEAT, _T("Rows Per &Beat"));
subMenu.AppendMenu(MF_STRING | (visibleItems[MainToolBarItem::GlobalVolume] ? MF_CHECKED : 0), ID_MAINBAR_SHOW_GLOBALVOLUME, _T("&Global Volume"));
subMenu.AppendMenu(MF_STRING | (visibleItems[MainToolBarItem::VUMeter] ? MF_CHECKED : 0), ID_MAINBAR_SHOW_VUMETER, _T("&VU Meters"));
menu.AppendMenu(MF_POPUP, reinterpret_cast<UINT_PTR>(subMenu.m_hMenu), _T("Main Toolbar &Items"));

menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, screenPt.x, screenPt.y, this);
menu.AppendMenu(MF_POPUP, reinterpret_cast<UINT_PTR>(subMenu.Detach()), _T("Main Toolbar &Items"));
}


Expand Down Expand Up @@ -3101,19 +3116,21 @@ void CMainFrame::CreateExampleModulesMenu()
}


// Hack-ish way to get the file menu (this is necessary because the MDI document icon next to the File menu is a sub menu, too).
CMenu *CMainFrame::GetFileMenu() const
std::pair<CMenu *, int> CMainFrame::FindMenuItemByCommand(CMenu &menu, UINT commandID)
{
CMenu *mainMenu = GetMenu();
CMenu *fileMenu = mainMenu ? mainMenu->GetSubMenu(0) : nullptr;
if(fileMenu)
const int numItems = menu.GetMenuItemCount();
for(int item = 0; item < numItems; item++)
{
if(fileMenu->GetMenuItemID(1) != ID_FILE_OPEN)
fileMenu = mainMenu->GetSubMenu(1);
ASSERT(fileMenu->GetMenuItemID(1) == ID_FILE_OPEN);
if(menu.GetMenuItemID(item) == commandID)
return {&menu, item};
CMenu *subMenu = menu.GetSubMenu(item);
if(subMenu != nullptr)
{
if(auto result = FindMenuItemByCommand(*subMenu, commandID); result.first != nullptr)
return result;
}
}
ASSERT(fileMenu);
return fileMenu;
return {};
}


Expand All @@ -3122,35 +3139,23 @@ void CMainFrame::CreateTemplateModulesMenu()
static_assert(nMaxItemsInTemplateModulesMenu == ID_FILE_OPENTEMPLATE_LASTINRANGE - ID_FILE_OPENTEMPLATE,
"Make sure that there's a proper range for menu commands in resources.");
HMENU hMenu = CreateFileMenu(nMaxItemsInTemplateModulesMenu, m_TemplateModulePaths, P_("TemplateModules\\"), ID_FILE_OPENTEMPLATE);
CMenu *pFileMenu = GetFileMenu();
if (hMenu && pFileMenu && m_InputHandler)
auto [fileMenu, position] = FindMenuItemByCommand(*GetMenu(), ID_FILE_OPEN);
if(hMenu && fileMenu && m_InputHandler)
{
VERIFY(pFileMenu->RemoveMenu(2, MF_BYPOSITION));
VERIFY(pFileMenu->InsertMenu(2, MF_BYPOSITION | MF_POPUP, (UINT_PTR)hMenu, m_InputHandler->GetMenuText(ID_FILE_OPENTEMPLATE)));
VERIFY(fileMenu->RemoveMenu(position + 1, MF_BYPOSITION));
VERIFY(fileMenu->InsertMenu(position + 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)hMenu, m_InputHandler->GetMenuText(ID_FILE_OPENTEMPLATE)));
}
else
ASSERT(false);
MPT_ASSERT_NOTREACHED();
}


void CMainFrame::UpdateMRUList()
{
CMenu *pMenu = GetFileMenu();
if(!pMenu) return;

static int firstMenu = -1;
if(firstMenu == -1)
{
int numMenus = pMenu->GetMenuItemCount();
for(int i = 0; i < numMenus; i++)
{
if(pMenu->GetMenuItemID(i) == ID_MRU_LIST_FIRST)
{
firstMenu = i;
break;
}
}
}
const auto [pMenu, firstMenu] = FindMenuItemByCommand(*GetMenu(), ID_MRU_LIST_FIRST);
MPT_ASSERT(pMenu);
if(!pMenu)
return;

for(int i = ID_MRU_LIST_FIRST; i <= ID_MRU_LIST_LAST; i++)
{
Expand Down
9 changes: 4 additions & 5 deletions mptrack/Mainbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,12 @@ void CMainToolBar::OnTbnDropDownToolBar(NMHDR *pNMHDR, LRESULT *pResult)
case ID_FILE_NEW:
{
auto *mainFrm = CMainFrame::GetMainFrame();
CMenu *newMenu = mainFrm->GetFileMenu()->GetSubMenu(0);
CMenu *templateMenu = mainFrm->GetFileMenu()->GetSubMenu(2);
const bool hasTemplates = templateMenu->GetMenuItemID(0) != 0;
if(hasTemplates)
auto [newMenu, newPos] = CMainFrame::FindMenuItemByCommand(*mainFrm->GetMenu(), ID_FILE_NEWIT);
auto [templateMenu, templatePos] = CMainFrame::FindMenuItemByCommand(*mainFrm->GetMenu(), ID_FILE_OPENTEMPLATE);
if(templateMenu)
newMenu->AppendMenu(MF_POPUP, reinterpret_cast<UINT_PTR>(templateMenu->m_hMenu), _T("&Templates"));
newMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pToolBar->rcButton.left, pToolBar->rcButton.bottom, this);
if(hasTemplates)
if(templateMenu)
newMenu->RemoveMenu(newMenu->GetMenuItemCount() - 1, MF_BYPOSITION);
}
break;
Expand Down
3 changes: 2 additions & 1 deletion mptrack/Mainfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class CMainFrame

void CreateExampleModulesMenu();
void CreateTemplateModulesMenu();
CMenu *GetFileMenu() const;
static std::pair<CMenu *, int> FindMenuItemByCommand(CMenu &menu, UINT commandID);

// Creates submenu whose items are filenames of files in both
// AppDirectory\folderName\ (usually C:\Program Files\OpenMPT\folderName\)
Expand Down Expand Up @@ -372,6 +372,7 @@ class CMainFrame
void OpenMenuItemFile(const UINT nId, const bool isTemplateFile);

void ShowToolbarMenu(CPoint screenPt);
static void AddToolBarMenuEntries(CMenu &menu);

void RecreateImageLists();

Expand Down
1 change: 0 additions & 1 deletion mptrack/mptrack.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,6 @@ BEGIN
POPUP "&Toolbars"
BEGIN
MENUITEM "&Main", ID_VIEW_TOOLBAR
MENUITEM "&Tree", IDD_TREEVIEW
END
MENUITEM SEPARATOR
MENUITEM "S&etup...", ID_VIEW_OPTIONS
Expand Down

0 comments on commit 13e9d06

Please sign in to comment.