- Fixed that invalid skin context action is executed when executing action from tray context menu.

- Minor tweaks.
This commit is contained in:
spx 2012-10-03 14:59:49 -07:00
parent 7e6249f797
commit 40e7617ecc
3 changed files with 66 additions and 54 deletions

View File

@ -3344,14 +3344,14 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
int position = (int)wParam - IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + 1; int position = (int)wParam - IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + 1;
if (position == 1) if (position == 1)
{ {
action = m_Parser.ReadString(L"Rainmeter", L"ContextAction", L""); action = m_Parser.ReadString(L"Rainmeter", L"ContextAction", L"", false);
} }
else else
{ {
WCHAR buffer[128]; WCHAR buffer[128];
_snwprintf_s(buffer, _TRUNCATE, L"ContextAction%i", position); _snwprintf_s(buffer, _TRUNCATE, L"ContextAction%i", position);
action = m_Parser.ReadString(L"Rainmeter", buffer, L""); action = m_Parser.ReadString(L"Rainmeter", buffer, L"", false);
} }
if (!action.empty()) if (!action.empty())

View File

@ -3160,7 +3160,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
} }
} }
// Add custom actions to the context menu. // Add custom actions to the context menu
if (meterWindow->HasCustomContextMenu()) if (meterWindow->HasCustomContextMenu())
{ {
// Read context menu titles (also read the actions) // Read context menu titles (also read the actions)
@ -3170,14 +3170,14 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
WCHAR buffer[128]; WCHAR buffer[128];
int i = 1; int i = 1;
while(!contextTitle.empty() && while (!contextTitle.empty() &&
(!contextAction.empty() || _wcsicmp(contextTitle.c_str(), L"SEPARATOR") == 0) && (!contextAction.empty() || _wcsicmp(contextTitle.c_str(), L"SEPARATOR") == 0) &&
(IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i - 1) <= IDM_SKIN_CUSTOMCONTEXTMENU_LAST) // Set maximum context items in resource.h (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i - 1) <= IDM_SKIN_CUSTOMCONTEXTMENU_LAST) // Set maximum context items in resource.h
{ {
// Trim long titles // Trim long titles
if (contextTitle.size() > 30) if (contextTitle.size() > 30)
{ {
contextTitle = contextTitle.substr(0, 27) + L"..."; contextTitle.replace(27, contextTitle.size() - 27, L"...");
} }
cTitles.push_back(contextTitle); cTitles.push_back(contextTitle);
@ -3192,7 +3192,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
size_t titleSize = cTitles.size(); size_t titleSize = cTitles.size();
if (titleSize <= 3) if (titleSize <= 3)
{ {
for (size_t i = 0; i < titleSize; i++) for (size_t i = 0; i < titleSize; ++i)
{ {
if (_wcsicmp(cTitles[i].c_str(), L"SEPARATOR") == 0) if (_wcsicmp(cTitles[i].c_str(), L"SEPARATOR") == 0)
{ {
@ -3200,7 +3200,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
} }
else else
{ {
InsertMenu(skinMenu, i + 1, MF_BYPOSITION | MF_STRING, IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i, cTitles[i].c_str()); InsertMenu(skinMenu, i + 1, MF_BYPOSITION | MF_STRING, (index << 16) | (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i), cTitles[i].c_str());
} }
} }
} }
@ -3209,7 +3209,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
HMENU customMenu = CreatePopupMenu(); HMENU customMenu = CreatePopupMenu();
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)customMenu, L"Skin Actions"); InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)customMenu, L"Skin Actions");
for (size_t i = 0; i < titleSize; i++) for (size_t i = 0; i < titleSize; ++i)
{ {
if (_wcsicmp(cTitles[i].c_str(), L"SEPARATOR") == 0) if (_wcsicmp(cTitles[i].c_str(), L"SEPARATOR") == 0)
{ {
@ -3217,7 +3217,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
} }
else else
{ {
AppendMenu(customMenu, MF_BYPOSITION | MF_STRING, IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i, cTitles[i].c_str()); AppendMenu(customMenu, MF_BYPOSITION | MF_STRING, (index << 16) | (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i), cTitles[i].c_str());
} }
} }
} }
@ -3289,6 +3289,8 @@ void CRainmeter::CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow)
void CRainmeter::ChangeSkinIndex(HMENU menu, int index) void CRainmeter::ChangeSkinIndex(HMENU menu, int index)
{ {
if (index > 0)
{
int count = GetMenuItemCount(menu); int count = GetMenuItemCount(menu);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
@ -3300,11 +3302,16 @@ void CRainmeter::ChangeSkinIndex(HMENU menu, int index)
} }
else else
{ {
WCHAR buffer[256]; MENUITEMINFO mii = {sizeof(MENUITEMINFO)};
GetMenuString(menu, i, buffer, 256, MF_BYPOSITION); mii.fMask = MIIM_FTYPE | MIIM_ID;
UINT id = GetMenuItemID(menu, i); GetMenuItemInfo(menu, i, TRUE, &mii);
UINT flags = GetMenuState(menu, i, MF_BYPOSITION); if ((mii.fType & MFT_SEPARATOR) == 0)
ModifyMenu(menu, i, MF_BYPOSITION | flags, id | (index << 16), buffer); {
mii.wID |= (index << 16);
mii.fMask = MIIM_ID;
SetMenuItemInfo(menu, i, TRUE, &mii);
}
}
} }
} }
} }

View File

@ -509,9 +509,13 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{ {
Rainmeter->OpenSkinFolder(); Rainmeter->OpenSkinFolder();
} }
else if ((wParam & 0x0ffff) >= ID_THEME_FIRST && (wParam & 0x0ffff) <= ID_THEME_LAST) else
{ {
int pos = (wParam & 0x0ffff) - ID_THEME_FIRST; UINT mID = wParam & 0x0FFFF;
if (mID >= ID_THEME_FIRST && mID <= ID_THEME_LAST)
{
int pos = mID - ID_THEME_FIRST;
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts(); const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
if (pos >= 0 && pos < (int)layouts.size()) if (pos >= 0 && pos < (int)layouts.size())
@ -519,9 +523,9 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
Rainmeter->LoadLayout(layouts[pos]); Rainmeter->LoadLayout(layouts[pos]);
} }
} }
else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST) else if (mID >= ID_CONFIG_FIRST && mID <= ID_CONFIG_LAST)
{ {
std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex((UINT)(wParam & 0x0ffff)); std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex(mID);
if (indexes.first != -1 && indexes.second != -1) if (indexes.first != -1 && indexes.second != -1)
{ {
Rainmeter->ToggleSkin(indexes.first, indexes.second); Rainmeter->ToggleSkin(indexes.first, indexes.second);
@ -542,12 +546,13 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
if (index < 0) if (index < 0)
{ {
CMeterWindow* meterWindow = (*iter).second; CMeterWindow* meterWindow = (*iter).second;
SendMessage(meterWindow->GetWindow(), WM_COMMAND, wParam & 0x0FFFF, NULL); SendMessage(meterWindow->GetWindow(), WM_COMMAND, mID, NULL);
break; break;
} }
} }
} }
} }
}
return 0; // Don't send WM_COMMANDS any further return 0; // Don't send WM_COMMANDS any further
case WM_TRAY_NOTIFYICON: case WM_TRAY_NOTIFYICON: