From c0579e3b2492731b84a54724248caaf29ec66f63 Mon Sep 17 00:00:00 2001 From: spx Date: Fri, 19 Aug 2011 03:12:01 +0000 Subject: [PATCH] Relocated some context menu items to the resource file. --- Library/Library.rc | 23 +++- Library/Rainmeter.cpp | 243 +++++++++++++++++++++--------------------- Library/Rainmeter.h | 4 +- 3 files changed, 146 insertions(+), 124 deletions(-) diff --git a/Library/Library.rc b/Library/Library.rc index 65fd04cc..deb70811 100644 --- a/Library/Library.rc +++ b/Library/Library.rc @@ -73,8 +73,20 @@ BEGIN POPUP "Context" BEGIN MENUITEM "About...", ID_CONTEXT_ABOUT + MENUITEM "Downloads", ID_CONTEXT_DOWNLOADS MENUITEM "Help", ID_CONTEXT_SHOW_HELP MENUITEM SEPARATOR + POPUP "Configs" + BEGIN + MENUITEM SEPARATOR + MENUITEM "Open Skins' Folder", ID_CONTEXT_OPENSKINSFOLDER + MENUITEM "Disable Dragging", ID_CONTEXT_DISABLEDRAG + MENUITEM "Manage Skins...", ID_CONTEXT_MANAGESKINS + END + POPUP "Themes" + BEGIN + MENUITEM "Manage Themes...", ID_CONTEXT_MANAGETHEMES + END MENUITEM SEPARATOR MENUITEM "Edit Settings...", ID_CONTEXT_EDITCONFIG MENUITEM "Refresh All", ID_CONTEXT_REFRESH @@ -98,14 +110,21 @@ IDR_SKIN_MENU MENU DISCARDABLE BEGIN POPUP "Skin Menu" BEGIN + MENUITEM " ", ID_CONTEXT_SKINMENU_OPENSKINSFOLDER + MENUITEM SEPARATOR + POPUP "Variants" + BEGIN + MENUITEM " ", 0, GRAYED // DUMMY + END + MENUITEM SEPARATOR POPUP "Settings" BEGIN POPUP "Position" BEGIN POPUP "Display Monitor" BEGIN - MENUITEM "Use default: Primary monitor", ID_CONTEXT_SKINMENU_MONITOR_PRIMARY - MENUITEM "@0: Virtual screen", ID_MONITOR_FIRST + MENUITEM "Use default: Primary monitor", ID_CONTEXT_SKINMENU_MONITOR_PRIMARY + MENUITEM "@0: Virtual screen", ID_MONITOR_FIRST MENUITEM SEPARATOR MENUITEM SEPARATOR MENUITEM "Auto-select based on window position", ID_CONTEXT_SKINMENU_MONITOR_AUTOSELECT diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 9aa72744..14eccf7e 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -3869,7 +3869,7 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) { // Disable Quit/Logging if ran as a Litestep plugin EnableMenuItem(subMenu, ID_CONTEXT_QUIT, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(subMenu, 7, MF_BYPOSITION | MF_GRAYED); // "Logging" menu + EnableMenuItem(subMenu, 10, MF_BYPOSITION | MF_GRAYED); // "Logging" menu } else { @@ -3890,26 +3890,24 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) } } - HMENU configMenu = CreateConfigMenu(m_ConfigMenu); - if (!configMenu) - { - configMenu = CreatePopupMenu(); - AppendMenu(configMenu, MF_GRAYED, 0, L"No configs available"); - } + HMENU configMenu = GetSubMenu(subMenu, 4); if (configMenu) { - AppendMenu(configMenu, MF_SEPARATOR, 0, NULL); - AppendMenu(configMenu, 0, ID_CONTEXT_OPENSKINSFOLDER, L"Open Skins\' Folder"); - AppendMenu(configMenu, (m_DisableDragging) ? MF_CHECKED : MF_UNCHECKED, ID_CONTEXT_DISABLEDRAG, L"Disable Dragging"); - AppendMenu(configMenu, 0, ID_CONTEXT_MANAGESKINS, L"Manage Skins..."); + if (!CreateConfigMenu(configMenu, m_ConfigMenu)) + { + InsertMenu(configMenu, 0, MF_BYPOSITION | MF_GRAYED, 0, L"No configs available"); + } - InsertMenu(subMenu, 3, MF_BYPOSITION | MF_POPUP, (UINT_PTR)configMenu, L"Configs"); + if (m_DisableDragging) + { + CheckMenuItem(configMenu, ID_CONTEXT_DISABLEDRAG, MF_BYCOMMAND | MF_CHECKED); + } } - HMENU themeMenu = CreateThemeMenu(); + HMENU themeMenu = GetSubMenu(subMenu, 5); if (themeMenu) { - InsertMenu(subMenu, 4, MF_BYPOSITION | MF_POPUP, (UINT_PTR)themeMenu, L"Themes"); + CreateThemeMenu(themeMenu); } if (meterWindow) @@ -3918,10 +3916,12 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) subMenu = CreateSkinMenu(meterWindow, 0, configMenu); InsertMenu(subMenu, 9, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); InsertMenu(subMenu, 10, MF_BYPOSITION | MF_POPUP, (UINT_PTR)rainmeterMenu, L"Rainmeter Menu"); + + RemoveMenu(rainmeterMenu, ID_CONTEXT_DOWNLOADS, MF_BYCOMMAND); } else { - InsertMenu(subMenu, 11, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); + InsertMenu(subMenu, 12, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); // Create a menu for all active configs std::map::const_iterator iter = Rainmeter->GetAllMeterWindows().begin(); @@ -3931,12 +3931,10 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) { CMeterWindow* mw = ((*iter).second); HMENU skinMenu = CreateSkinMenu(mw, index, configMenu); - InsertMenu(subMenu, 11, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetSkinName().c_str()); + InsertMenu(subMenu, 12, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetSkinName().c_str()); ++index; } - InsertMenu(subMenu, 1, MF_BYPOSITION, ID_CONTEXT_DOWNLOADS, L"Downloads"); - // Put Update notifications in the Tray menu if (m_NewVersion) { @@ -3994,15 +3992,16 @@ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) } -HMENU CRainmeter::CreateConfigMenu(std::vector& configMenuData) +HMENU CRainmeter::CreateConfigMenu(HMENU configMenu, std::vector& configMenuData) { - HMENU configMenu = NULL; - if (!configMenuData.empty()) { - configMenu = CreatePopupMenu(); - bool item = false; + if (!configMenu) + { + configMenu = CreatePopupMenu(); + } + bool item = false; for (int i = 0, j = 0, isize = (int)configMenuData.size(); i < isize; ++i) { if (configMenuData[i].index == -1) @@ -4015,7 +4014,7 @@ HMENU CRainmeter::CreateConfigMenu(std::vector& configMenuData) item = false; } - HMENU submenu = CreateConfigMenu(configMenuData[i].children); + HMENU submenu = CreateConfigMenu(NULL, configMenuData[i].children); if (submenu) { InsertMenu(configMenu, i + j, MF_BYPOSITION | MF_POPUP, (UINT_PTR)submenu, configMenuData[i].name.c_str()); @@ -4028,27 +4027,24 @@ HMENU CRainmeter::CreateConfigMenu(std::vector& configMenuData) item = true; } } + + return configMenu; } - return configMenu; + + return NULL; } -HMENU CRainmeter::CreateThemeMenu() +void CRainmeter::CreateThemeMenu(HMENU themeMenu) { - HMENU themeMenu = CreatePopupMenu(); - - for (size_t i = 0, isize = m_Themes.size(); i < isize; ++i) - { - AppendMenu(themeMenu, 0, ID_THEME_FIRST + i, m_Themes[i].c_str()); - } - if (!m_Themes.empty()) { - AppendMenu(themeMenu, MF_SEPARATOR, 0, NULL); + InsertMenu(themeMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); + + for (size_t i = 0, isize = m_Themes.size(); i < isize; ++i) + { + InsertMenu(themeMenu, i, MF_BYPOSITION, ID_THEME_FIRST + i, m_Themes[i].c_str()); + } } - - AppendMenu(themeMenu, 0, ID_CONTEXT_MANAGETHEMES, L"Manage Themes..."); - - return themeMenu; } HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu) @@ -4066,7 +4062,7 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU con if (skinMenu) { // Tick the position - HMENU settingsMenu = GetSubMenu(skinMenu, 0); + HMENU settingsMenu = GetSubMenu(skinMenu, 4); if (settingsMenu) { HMENU posMenu = GetSubMenu(settingsMenu, 0); @@ -4110,102 +4106,110 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU con CreateMonitorMenu(monitorMenu, meterWindow); } } - } - // Tick the transparency - if (!meterWindow->GetNativeTransparency()) - { - EnableMenuItem(settingsMenu, 1, MF_BYPOSITION | MF_GRAYED); // "Transparency" menu - EnableMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_CLICKTHROUGH, MF_BYCOMMAND | MF_GRAYED); - } - else - { - HMENU alphaMenu = GetSubMenu(settingsMenu, 1); - if (alphaMenu) + // Tick the transparency + if (!meterWindow->GetNativeTransparency()) { - int value = (int)(10 - meterWindow->GetAlphaValue() / 25.5); - value = min(9, value); - value = max(0, value); - CheckMenuItem(alphaMenu, value, MF_BYPOSITION | MF_CHECKED); + EnableMenuItem(settingsMenu, 1, MF_BYPOSITION | MF_GRAYED); // "Transparency" menu + EnableMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_CLICKTHROUGH, MF_BYCOMMAND | MF_GRAYED); + } + else + { + HMENU alphaMenu = GetSubMenu(settingsMenu, 1); + if (alphaMenu) + { + int value = (int)(10 - meterWindow->GetAlphaValue() / 25.5); + value = min(9, value); + value = max(0, value); + CheckMenuItem(alphaMenu, value, MF_BYPOSITION | MF_CHECKED); - if (meterWindow->GetWindowHide() == HIDEMODE_FADEIN) - { - CheckMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_CHECKED); - EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED); - } - else if (meterWindow->GetWindowHide() == HIDEMODE_FADEOUT) - { - CheckMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_CHECKED); - EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED); - } - else if (meterWindow->GetWindowHide() == HIDEMODE_HIDE) - { - EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED); + if (meterWindow->GetWindowHide() == HIDEMODE_FADEIN) + { + CheckMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_CHECKED); + EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED); + } + else if (meterWindow->GetWindowHide() == HIDEMODE_FADEOUT) + { + CheckMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_CHECKED); + EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED); + } + else if (meterWindow->GetWindowHide() == HIDEMODE_HIDE) + { + EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEIN, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(alphaMenu, ID_CONTEXT_SKINMENU_TRANSPARENCY_FADEOUT, MF_BYCOMMAND | MF_GRAYED); + } } } + + // Tick the configs + if (meterWindow->GetWindowHide() == HIDEMODE_HIDE) + { + CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_HIDEONMOUSE, MF_BYCOMMAND | MF_CHECKED); + } + else if (meterWindow->GetWindowHide() != HIDEMODE_NONE) + { + EnableMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_HIDEONMOUSE, MF_BYCOMMAND | MF_GRAYED); + } + + if (meterWindow->GetSnapEdges()) + { + CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_SNAPTOEDGES, MF_BYCOMMAND | MF_CHECKED); + } + + if (meterWindow->GetSavePosition()) + { + CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_REMEMBERPOSITION, MF_BYCOMMAND | MF_CHECKED); + } + + if (m_DisableDragging) + { + EnableMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_DRAGGABLE, MF_BYCOMMAND | MF_GRAYED); + } + else if (meterWindow->GetWindowDraggable()) + { + CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_DRAGGABLE, MF_BYCOMMAND | MF_CHECKED); + } + + if (meterWindow->GetClickThrough()) + { + CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_CLICKTHROUGH, MF_BYCOMMAND | MF_CHECKED); + } + + if (meterWindow->GetKeepOnScreen()) + { + CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_KEEPONSCREEN, MF_BYCOMMAND | MF_CHECKED); + } } - // Tick the configs - if (meterWindow->GetWindowHide() == HIDEMODE_HIDE) - { - CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_HIDEONMOUSE, MF_BYCOMMAND | MF_CHECKED); - } - else if (meterWindow->GetWindowHide() != HIDEMODE_NONE) - { - EnableMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_HIDEONMOUSE, MF_BYCOMMAND | MF_GRAYED); - } - - if (meterWindow->GetSnapEdges()) - { - CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_SNAPTOEDGES, MF_BYCOMMAND | MF_CHECKED); - } - - if (meterWindow->GetSavePosition()) - { - CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_REMEMBERPOSITION, MF_BYCOMMAND | MF_CHECKED); - } - - if (m_DisableDragging) - { - EnableMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_DRAGGABLE, MF_BYCOMMAND | MF_GRAYED); - } - else if (meterWindow->GetWindowDraggable()) - { - CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_DRAGGABLE, MF_BYCOMMAND | MF_CHECKED); - } - - if (meterWindow->GetClickThrough()) - { - CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_CLICKTHROUGH, MF_BYCOMMAND | MF_CHECKED); - } - - if (meterWindow->GetKeepOnScreen()) - { - CheckMenuItem(settingsMenu, ID_CONTEXT_SKINMENU_KEEPONSCREEN, MF_BYCOMMAND | MF_CHECKED); - } - - // Add the name of the Skin to the menu and disable the item + // Add the name of the Skin to the menu const std::wstring& skinName = meterWindow->GetSkinName(); - InsertMenu(skinMenu, 0, MF_BYPOSITION, ID_CONTEXT_SKINMENU_OPENSKINSFOLDER, skinName.c_str()); - InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); - SetMenuDefaultItem(skinMenu, 0, MF_BYPOSITION); + ModifyMenu(skinMenu, ID_CONTEXT_SKINMENU_OPENSKINSFOLDER, MF_BYCOMMAND, ID_CONTEXT_SKINMENU_OPENSKINSFOLDER, skinName.c_str()); + SetMenuDefaultItem(skinMenu, ID_CONTEXT_SKINMENU_OPENSKINSFOLDER, FALSE); + // Remove dummy menuitem from the variants menu + HMENU variantsMenu = GetSubMenu(skinMenu, 2); + if (variantsMenu) + { + RemoveMenu(variantsMenu, 0, MF_BYPOSITION); + } + + // Give the menuitem the unique id that depends on the skin ChangeSkinIndex(skinMenu, index); // Add the variants menu - for (int i = 0, isize = (int)m_ConfigStrings.size(); i < isize; ++i) + if (variantsMenu) { - const CONFIG& config = m_ConfigStrings[i]; - if (_wcsicmp(config.config.c_str(), skinName.c_str()) == 0) + for (int i = 0, isize = (int)m_ConfigStrings.size(); i < isize; ++i) { - HMENU variantsMenu = CreatePopupMenu(); - for (int j = 0, jsize = (int)config.iniFiles.size(); j < jsize; ++j) + const CONFIG& config = m_ConfigStrings[i]; + if (_wcsicmp(config.config.c_str(), skinName.c_str()) == 0) { - InsertMenu(variantsMenu, j, MF_BYPOSITION | ((config.active == j + 1) ? MF_CHECKED : MF_UNCHECKED), config.commands[j], config.iniFiles[j].c_str()); + for (int j = 0, jsize = (int)config.iniFiles.size(); j < jsize; ++j) + { + InsertMenu(variantsMenu, j, MF_BYPOSITION | ((config.active == j + 1) ? MF_CHECKED : MF_UNCHECKED), config.commands[j], config.iniFiles[j].c_str()); + } + break; } - InsertMenu(skinMenu, 2, MF_BYPOSITION | MF_POPUP, (UINT_PTR)variantsMenu, L"Variants"); - break; } } @@ -4234,7 +4238,6 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU con 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; } diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 093f0e92..b358ca30 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -272,8 +272,8 @@ private: HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu); void ChangeSkinIndex(HMENU subMenu, int index); int ScanForConfigsRecursive(const std::wstring& path, std::wstring base, int index, std::vector& menu, bool DontRecurse); - HMENU CreateConfigMenu(std::vector& configMenuData); - HMENU CreateThemeMenu(); + HMENU CreateConfigMenu(HMENU configMenu, std::vector& configMenuData); + void CreateThemeMenu(HMENU themeMenu); void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow); void CreateDefaultConfigFile(const std::wstring& strFile); void SetLogging(bool logging);