- Added config's root menu.

- Fixed a small issue on creating menu cache.
- Added workaround that the context menu is shown repeatedly by using menu bangs.
This commit is contained in:
spx 2010-07-18 21:35:52 +00:00
parent 5366da997d
commit eb536cde54
2 changed files with 151 additions and 95 deletions

View File

@ -1948,6 +1948,11 @@ int CRainmeter::ScanForConfigsRecursive(std::wstring& path, std::wstring base, i
{ {
if(hSearchIni == INVALID_HANDLE_VALUE) break; // No more files found if(hSearchIni == INVALID_HANDLE_VALUE) break; // No more files found
// Check whether the extension is ".ini"
std::wstring ext = fileDataIni.cFileName;
std::wstring::size_type pos = ext.find_last_of(L'.');
if (pos != std::wstring::npos && wcsicmp(&(ext.c_str()[pos]), L".ini") == 0)
{
CONFIGMENU menuItem; CONFIGMENU menuItem;
menuItem.name = fileDataIni.cFileName; menuItem.name = fileDataIni.cFileName;
menuItem.index = m_ConfigStrings.size(); menuItem.index = m_ConfigStrings.size();
@ -1955,7 +1960,7 @@ int CRainmeter::ScanForConfigsRecursive(std::wstring& path, std::wstring base, i
config.iniFiles.push_back(fileDataIni.cFileName); config.iniFiles.push_back(fileDataIni.cFileName);
config.commands.push_back(ID_CONFIG_FIRST + index++); config.commands.push_back(ID_CONFIG_FIRST + index++);
}
} while (FindNextFile(hSearchIni, &fileDataIni)); } while (FindNextFile(hSearchIni, &fileDataIni));
if (!config.iniFiles.empty()) if (!config.iniFiles.empty())
@ -1988,6 +1993,12 @@ int CRainmeter::ScanForConfigsRecursive(std::wstring& path, std::wstring base, i
{ {
std::vector<CONFIGMENU>::iterator iter = menu.end() - 1; std::vector<CONFIGMENU>::iterator iter = menu.end() - 1;
index = ScanForConfigsRecursive(path, base + fileData.cFileName, index, (*iter).children, false); index = ScanForConfigsRecursive(path, base + fileData.cFileName, index, (*iter).children, false);
// Remove menu item if it has no child
if ((*iter).children.empty())
{
menu.erase(iter);
}
} }
} }
} while(FindNextFile(hSearch, &fileData)); } while(FindNextFile(hSearch, &fileData));
@ -2856,6 +2867,12 @@ PLATFORM CRainmeter::IsNT()
*/ */
void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
{ {
static bool active = false;
if (!active)
{
active = true;
// Show context menu, if no actions were executed // Show context menu, if no actions were executed
HMENU menu = LoadMenu(m_Instance, MAKEINTRESOURCE(IDR_CONTEXT_MENU)); HMENU menu = LoadMenu(m_Instance, MAKEINTRESOURCE(IDR_CONTEXT_MENU));
@ -2914,9 +2931,9 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
if (meterWindow) if (meterWindow)
{ {
HMENU rainmeterMenu = subMenu; HMENU rainmeterMenu = subMenu;
subMenu = CreateSkinMenu(meterWindow, 0); subMenu = CreateSkinMenu(meterWindow, 0, configMenu);
InsertMenu(subMenu, 7, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); InsertMenu(subMenu, 9, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
InsertMenu(subMenu, 8, MF_BYPOSITION | MF_POPUP, (UINT_PTR)rainmeterMenu, L"Rainmeter Menu"); InsertMenu(subMenu, 10, MF_BYPOSITION | MF_POPUP, (UINT_PTR)rainmeterMenu, L"Rainmeter Menu");
} }
else else
{ {
@ -2929,7 +2946,7 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
for (; iter != Rainmeter->GetAllMeterWindows().end(); ++iter) for (; iter != Rainmeter->GetAllMeterWindows().end(); ++iter)
{ {
CMeterWindow* mw = ((*iter).second); CMeterWindow* mw = ((*iter).second);
HMENU skinMenu = CreateSkinMenu(mw, index); HMENU skinMenu = CreateSkinMenu(mw, index, configMenu);
InsertMenu(subMenu, 11, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetSkinName().c_str()); InsertMenu(subMenu, 11, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetSkinName().c_str());
++index; ++index;
} }
@ -2943,16 +2960,18 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
} }
} }
HWND hwnd = meterWindow ? meterWindow->GetWindow() : m_TrayWindow->GetWindow();
SetForegroundWindow(hwnd);
TrackPopupMenu( TrackPopupMenu(
subMenu, subMenu,
TPM_RIGHTBUTTON | TPM_LEFTALIGN, TPM_RIGHTBUTTON | TPM_LEFTALIGN,
pos.x, pos.x,
pos.y, pos.y,
0, 0,
meterWindow ? meterWindow->GetWindow() : m_TrayWindow->GetWindow(), hwnd,
NULL NULL
); );
PostMessage(hwnd, WM_NULL, 0L, 0L);
if (meterWindow) if (meterWindow)
{ {
@ -2962,6 +2981,9 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow)
DestroyMenu(menu); DestroyMenu(menu);
} }
active = false;
}
} }
@ -3017,7 +3039,7 @@ HMENU CRainmeter::CreateThemeMenu()
return themeMenu; return themeMenu;
} }
HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index) HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu)
{ {
HMENU skinMenu = LoadMenu(m_Instance, MAKEINTRESOURCE(IDR_SKIN_MENU)); HMENU skinMenu = LoadMenu(m_Instance, MAKEINTRESOURCE(IDR_SKIN_MENU));
@ -3175,6 +3197,40 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index)
break; break;
} }
} }
// Add config's root menu
int itemCount = GetMenuItemCount(configMenu) - 3; // Subtract 3 for appended menus
if (itemCount > 0)
{
std::wstring root = meterWindow->GetSkinName();
std::wstring::size_type pos = root.find_first_of(L'\\');
if (pos != std::wstring::npos)
{
root.erase(pos);
}
for (int i = 0; i < itemCount; ++i)
{
WCHAR buffer[MAX_PATH+1] = {0};
MENUITEMINFO itemInfo = {sizeof(MENUITEMINFO)};
itemInfo.fMask = MIIM_STRING;
itemInfo.dwTypeData = buffer;
itemInfo.cch = MAX_PATH;
if (GetMenuItemInfo(configMenu, (UINT)i, TRUE, &itemInfo))
{
if (wcsicmp(root.c_str(), buffer) == 0)
{
HMENU configRootMenu = GetSubMenu(configMenu, i);
if (configRootMenu)
{
InsertMenu(skinMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)configRootMenu, root.c_str());
InsertMenu(skinMenu, 4, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
}
break;
}
}
}
}
} }
return skinMenu; return skinMenu;

View File

@ -222,7 +222,7 @@ private:
int GetLoadOrder(const std::wstring& config); int GetLoadOrder(const std::wstring& config);
bool SetActiveConfig(std::wstring& skinName, std::wstring& skinIni); bool SetActiveConfig(std::wstring& skinName, std::wstring& skinIni);
void UpdateDesktopWorkArea(bool reset); void UpdateDesktopWorkArea(bool reset);
HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index); HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu);
void ChangeSkinIndex(HMENU subMenu, int index); void ChangeSkinIndex(HMENU subMenu, int index);
int ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector<CONFIGMENU>& menu, bool DontRecurse); int ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector<CONFIGMENU>& menu, bool DontRecurse);
HMENU CreateConfigMenu(std::vector<CONFIGMENU>& configMenuData); HMENU CreateConfigMenu(std::vector<CONFIGMENU>& configMenuData);