- 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,22 +3289,29 @@ void CRainmeter::CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow)
void CRainmeter::ChangeSkinIndex(HMENU menu, int index) void CRainmeter::ChangeSkinIndex(HMENU menu, int index)
{ {
int count = GetMenuItemCount(menu); if (index > 0)
for (int i = 0; i < count; ++i)
{ {
HMENU subMenu = GetSubMenu(menu, i); int count = GetMenuItemCount(menu);
if (subMenu)
for (int i = 0; i < count; ++i)
{ {
ChangeSkinIndex(subMenu, index); HMENU subMenu = GetSubMenu(menu, i);
} if (subMenu)
else {
{ ChangeSkinIndex(subMenu, index);
WCHAR buffer[256]; }
GetMenuString(menu, i, buffer, 256, MF_BYPOSITION); else
UINT id = GetMenuItemID(menu, i); {
UINT flags = GetMenuState(menu, i, MF_BYPOSITION); MENUITEMINFO mii = {sizeof(MENUITEMINFO)};
ModifyMenu(menu, i, MF_BYPOSITION | flags, id | (index << 16), buffer); mii.fMask = MIIM_FTYPE | MIIM_ID;
GetMenuItemInfo(menu, i, TRUE, &mii);
if ((mii.fType & MFT_SEPARATOR) == 0)
{
mii.wID |= (index << 16);
mii.fMask = MIIM_ID;
SetMenuItemInfo(menu, i, TRUE, &mii);
}
}
} }
} }
} }

View File

@ -509,41 +509,46 @@ 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)
{
int pos = (wParam & 0x0ffff) - ID_THEME_FIRST;
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
if (pos >= 0 && pos < (int)layouts.size())
{
Rainmeter->LoadLayout(layouts[pos]);
}
}
else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST)
{
std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex((UINT)(wParam & 0x0ffff));
if (indexes.first != -1 && indexes.second != -1)
{
Rainmeter->ToggleSkin(indexes.first, indexes.second);
}
}
else else
{ {
// Forward the message to correct window UINT mID = wParam & 0x0FFFF;
int index = (int)(wParam >> 16);
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
if (index < (int)windows.size()) if (mID >= ID_THEME_FIRST && mID <= ID_THEME_LAST)
{ {
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin(); int pos = mID - ID_THEME_FIRST;
for ( ; iter != windows.end(); ++iter)
const std::vector<std::wstring>& layouts = Rainmeter->GetAllLayouts();
if (pos >= 0 && pos < (int)layouts.size())
{ {
--index; Rainmeter->LoadLayout(layouts[pos]);
if (index < 0) }
}
else if (mID >= ID_CONFIG_FIRST && mID <= ID_CONFIG_LAST)
{
std::pair<int, int> indexes = Rainmeter->GetMeterWindowIndex(mID);
if (indexes.first != -1 && indexes.second != -1)
{
Rainmeter->ToggleSkin(indexes.first, indexes.second);
}
}
else
{
// Forward the message to correct window
int index = (int)(wParam >> 16);
const std::map<std::wstring, CMeterWindow*>& windows = Rainmeter->GetAllMeterWindows();
if (index < (int)windows.size())
{
std::map<std::wstring, CMeterWindow*>::const_iterator iter = windows.begin();
for ( ; iter != windows.end(); ++iter)
{ {
CMeterWindow* meterWindow = (*iter).second; --index;
SendMessage(meterWindow->GetWindow(), WM_COMMAND, wParam & 0x0FFFF, NULL); if (index < 0)
break; {
CMeterWindow* meterWindow = (*iter).second;
SendMessage(meterWindow->GetWindow(), WM_COMMAND, mID, NULL);
break;
}
} }
} }
} }