project64/Source/Project64/UserInterface/MenuClass.cpp

72 lines
2.0 KiB
C++
Raw Normal View History

#include "stdafx.h"
2015-11-13 21:15:20 +00:00
CBaseMenu::CBaseMenu() :
m_MenuHandle((HMENU)CreateMenu())
{
}
2015-11-13 21:15:20 +00:00
bool CBaseMenu::AddMenu(HMENU hMenu, MenuItemList Items)
{
if (Items.begin() == Items.end()) { return false; }
2015-11-13 21:15:20 +00:00
UINT ItemID, uFlags;
std::wstring Text, String;
for (MenuItemList::iterator MenuItem = Items.begin(); MenuItem != Items.end(); MenuItem++)
{
2015-11-13 21:15:20 +00:00
ItemID = MenuItem->ID();
uFlags = MF_STRING;
Text = g_Lang->GetString(MenuItem->Title()).c_str();
2015-11-13 21:15:20 +00:00
if (MenuItem->Title() == EMPTY_STRING && MenuItem->ManualString().length() > 0)
{
2015-11-13 21:15:20 +00:00
Text = MenuItem->ManualString();
}
if (ItemID == SPLITER)
{
2015-11-13 21:15:20 +00:00
uFlags |= MF_SEPARATOR;
}
if (MenuItem->ItemTicked())
{
2015-11-13 21:15:20 +00:00
uFlags |= MFS_CHECKED;
}
if (MenuItem->ItemEnabled())
{
2015-11-13 21:15:20 +00:00
uFlags |= MFS_ENABLED;
}
else
{
2015-11-13 21:15:20 +00:00
uFlags |= MFS_DISABLED;
}
MenuItemList * SubMenu = (MenuItemList *)MenuItem->SubMenu();
if (ItemID == SUB_MENU && HIWORD(SubMenu) != 0 && (SubMenu->begin() != SubMenu->end()))
{
2015-11-13 21:15:20 +00:00
ItemID = (UINT)CreatePopupMenu();
uFlags |= MF_POPUP;
AddMenu((HMENU)ItemID, *SubMenu);
}
2015-11-13 21:15:20 +00:00
if (ItemID == ID_PLUGIN_MENU)
{
2015-11-13 21:15:20 +00:00
ItemID = (UINT)MenuItem->SubMenu();
uFlags |= MF_POPUP;
MENUITEMINFO lpmii;
lpmii.cbSize = sizeof(MENUITEMINFO);
lpmii.fMask = MIIM_STATE;
lpmii.fState = 0;
SetMenuItemInfo((HMENU)ItemID, (DWORD)MenuItem->SubMenu(), FALSE, &lpmii);
}
2015-11-13 21:15:20 +00:00
if (MenuItem->ShortCut().empty() == false)
{
String = Text;
String += L"\t";
String += MenuItem->ShortCut();
Text = String;
}
AppendMenuW(hMenu, uFlags, ItemID, Text.c_str());
}
return true;
}