diff --git a/Common/MenuTemplate.cpp b/Common/MenuTemplate.cpp new file mode 100644 index 00000000..6695dbff --- /dev/null +++ b/Common/MenuTemplate.cpp @@ -0,0 +1,63 @@ +/* + Copyright (C) 2012 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "MenuTemplate.h" + +HMENU MenuTemplate::CreateMenu(const MenuTemplate* items, UINT itemCount, GetStringFunc getString) +{ + UINT itemIndex = 0; + return CreateSubMenu(items, itemIndex, itemCount, getString); +} + +HMENU MenuTemplate::CreateSubMenu(const MenuTemplate* items, UINT& itemIndex, UINT itemCount, GetStringFunc getString) +{ + HMENU menu = CreatePopupMenu(); + + do + { + const MenuTemplate& item = items[itemIndex]; + ++itemIndex; + + UINT itemFlags = MF_STRING; + UINT_PTR itemId = item.id; + const WCHAR* itemText = item.idText ? getString(item.idText) : NULL; + + if (item.type == MenuItem_ItemGrayed) + { + itemFlags |= MF_GRAYED; + } + else if (item.type == MenuItem_Separator) + { + itemFlags = MF_SEPARATOR; + } + else if (item.type == MenuItem_SubMenuBegin) + { + itemFlags = MF_POPUP; + itemId = (UINT_PTR)CreateSubMenu(items, itemIndex, itemCount, getString); + } + else if (item.type == MenuItem_SubMenuEnd) + { + return menu; + } + + AppendMenu(menu, itemFlags, itemId, itemText); + } + while (itemIndex < itemCount); + + return menu; +} diff --git a/Common/MenuTemplate.h b/Common/MenuTemplate.h new file mode 100644 index 00000000..6dfc116f --- /dev/null +++ b/Common/MenuTemplate.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2012 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef RM_COMMON_MENUTEMPLATE_H_ +#define RM_COMMON_MENUTEMPLATE_H_ + +#include + +struct MenuTemplate +{ + BYTE type; + WORD id; + WORD idText; + + typedef WCHAR* (*GetStringFunc)(UINT id); + + static HMENU CreateMenu(const MenuTemplate* items, UINT itemCount, GetStringFunc getString); + +private: + static HMENU CreateSubMenu(const MenuTemplate* items, UINT& itemIndex, UINT itemCount, GetStringFunc getString); +}; + +enum MenuTemplateItem +{ + MenuItem_Item, + MenuItem_ItemGrayed, + MenuItem_Separator, + MenuItem_SubMenuBegin, + MenuItem_SubMenuEnd +}; + +#define MENU_ITEM(...) { MenuItem_Item, __VA_ARGS__ } +#define MENU_ITEM_GRAYED(...) { MenuItem_ItemGrayed, __VA_ARGS__ } +#define MENU_SEPARATOR() { MenuItem_Separator } +#define MENU_SUBMENU(idText, ...) { MenuItem_SubMenuBegin, 0, idText }, __VA_ARGS__, { MenuItem_SubMenuEnd } + +#endif diff --git a/Language/Resource.rc b/Language/Resource.rc index 00278f6e..b527e8d6 100644 --- a/Language/Resource.rc +++ b/Language/Resource.rc @@ -12,132 +12,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDR_CONTEXT_MENU MENU -{ - POPUP "Rainmeter" - { - MENUITEM STR_MANAGE, IDM_MANAGE - MENUITEM STR_ABOUT, IDM_ABOUT - MENUITEM STR_HELP, IDM_SHOW_HELP - MENUITEM SEPARATOR - POPUP STR_SKINS - { - MENUITEM STR_NOSKINS, 0, GRAYED - MENUITEM SEPARATOR - MENUITEM STR_OPENFOLDER, IDM_OPENSKINSFOLDER - MENUITEM STR_DISABLEDRAGGING, IDM_DISABLEDRAG - } - POPUP STR_THEMES - { - MENUITEM STR_NOTHEMES, 0, GRAYED - } - MENUITEM SEPARATOR - MENUITEM STR_EDITSETTINGS, IDM_EDITCONFIG - MENUITEM STR_REFRESHALL, IDM_REFRESH - MENUITEM SEPARATOR - POPUP STR_LOGGING - { - MENUITEM STR_SHOWLOGFILE, IDM_SHOWLOGFILE - MENUITEM SEPARATOR - MENUITEM STR_STARTLOGGING, IDM_STARTLOG - MENUITEM STR_STOPLOGGING, IDM_STOPLOG - MENUITEM SEPARATOR - MENUITEM STR_DELETELOGFILE, IDM_DELETELOGFILE - MENUITEM STR_DEBUGMODE, IDM_DEBUGLOG - } - MENUITEM SEPARATOR - MENUITEM STR_EXIT, IDM_QUIT - } -} - -IDR_SKIN_MENU MENU -{ - POPUP "Skin" - { - MENUITEM " ", IDM_SKIN_OPENSKINSFOLDER // " " is intentional - MENUITEM SEPARATOR - POPUP STR_VARIANTS - { - MENUITEM SEPARATOR // Dummy - } - MENUITEM SEPARATOR - POPUP STR_SETTINGS - { - POPUP STR_POSITION - { - POPUP STR_DISPLAYMONITOR - { - MENUITEM STR_USEDEFAULTMONITOR, IDM_SKIN_MONITOR_PRIMARY - MENUITEM STR_VIRTUALSCREEN, ID_MONITOR_FIRST - MENUITEM SEPARATOR - MENUITEM SEPARATOR - MENUITEM STR_AUTOSELECTMONITOR, IDM_SKIN_MONITOR_AUTOSELECT - } - MENUITEM SEPARATOR - MENUITEM STR_STAYTOPMOST, IDM_SKIN_VERYTOPMOST - MENUITEM STR_TOPMOST, IDM_SKIN_TOPMOST - MENUITEM STR_NORMAL, IDM_SKIN_NORMAL - MENUITEM STR_BOTTOM, IDM_SKIN_BOTTOM - MENUITEM STR_ONDESKTOP, IDM_SKIN_ONDESKTOP - MENUITEM SEPARATOR - MENUITEM STR_FROMRIGHT, IDM_SKIN_FROMRIGHT - MENUITEM STR_FROMBOTTOM, IDM_SKIN_FROMBOTTOM - MENUITEM STR_XASPERCENTAGE, IDM_SKIN_XPERCENTAGE - MENUITEM STR_YASPERCENTAGE, IDM_SKIN_YPERCENTAGE - } - POPUP STR_TRANSPARENCY - { - MENUITEM "0%", IDM_SKIN_TRANSPARENCY_0 - MENUITEM "10%", IDM_SKIN_TRANSPARENCY_10 - MENUITEM "20%", IDM_SKIN_TRANSPARENCY_20 - MENUITEM "30%", IDM_SKIN_TRANSPARENCY_30 - MENUITEM "40%", IDM_SKIN_TRANSPARENCY_40 - MENUITEM "50%", IDM_SKIN_TRANSPARENCY_50 - MENUITEM "60%", IDM_SKIN_TRANSPARENCY_60 - MENUITEM "70%", IDM_SKIN_TRANSPARENCY_70 - MENUITEM "80%", IDM_SKIN_TRANSPARENCY_80 - MENUITEM "90%", IDM_SKIN_TRANSPARENCY_90 - MENUITEM SEPARATOR - MENUITEM STR_FADEIN, IDM_SKIN_TRANSPARENCY_FADEIN - MENUITEM STR_FADEOUT, IDM_SKIN_TRANSPARENCY_FADEOUT - } - MENUITEM SEPARATOR - MENUITEM STR_HIDEONMOUSEOVER, IDM_SKIN_HIDEONMOUSE - MENUITEM STR_DRAGGABLE, IDM_SKIN_DRAGGABLE - MENUITEM STR_SAVEPOSITION, IDM_SKIN_REMEMBERPOSITION - MENUITEM STR_SNAPTOEDGES, IDM_SKIN_SNAPTOEDGES - MENUITEM STR_CLICKTHROUGH, IDM_SKIN_CLICKTHROUGH - MENUITEM STR_KEEPONSCREEN, IDM_SKIN_KEEPONSCREEN - } - MENUITEM SEPARATOR - MENUITEM STR_MANAGESKIN, IDM_SKIN_MANAGESKIN - MENUITEM STR_EDITSKIN, IDM_SKIN_EDITSKIN - MENUITEM STR_REFRESHSKIN, IDM_SKIN_REFRESH - MENUITEM SEPARATOR - MENUITEM STR_UNLOADSKIN, IDM_CLOSESKIN - } -} - -IDR_MANAGESKINS_MENU MENU -{ - POPUP "Folder" - { - MENUITEM STR_EXPAND, IDM_MANAGESKINSMENU_EXPAND - MENUITEM STR_OPENFOLDER, IDM_MANAGESKINSMENU_OPENFOLDER - } - POPUP "Item" - { - MENUITEM STR_LOAD, IDM_MANAGESKINSMENU_LOAD - MENUITEM STR_REFRESH, IDM_MANAGESKINSMENU_REFRESH - MENUITEM STR_EDIT, IDM_MANAGESKINSMENU_EDIT - } -} - ///////////////////////////////////////////////////////////////////////////// // // Dialog @@ -352,5 +226,54 @@ STRINGTABLE ID_STR_ABOUTRAINMETER, STR_ABOUTRAINMETER ID_STR_WELCOME, STR_WELCOME ID_STR_CLICKTOMANAGE, STR_CLICKTOMANAGE - ID_STR_CLICKTODOWNLOAD, STR_CLICKTODOWNLOAD + ID_STR_CLICKTODOWNLOAD, STR_VARIANTS + ID_STR_VARIANTS, STR_VARIANTS + ID_STR_POSITION, STR_POSITION + ID_STR_DISPLAYMONITOR, STR_DISPLAYMONITOR + ID_STR_USEDEFAULTMONITOR, STR_USEDEFAULTMONITOR + ID_STR_VIRTUALSCREEN, STR_VIRTUALSCREEN + ID_STR_AUTOSELECTMONITOR, STR_AUTOSELECTMONITOR + ID_STR_FROMRIGHT, STR_FROMRIGHT + ID_STR_FROMBOTTOM, STR_FROMBOTTOM + ID_STR_XASPERCENTAGE, STR_XASPERCENTAGE + ID_STR_YASPERCENTAGE, STR_YASPERCENTAGE + ID_STR_TRANSPARENCY, STR_TRANSPARENCY + ID_STR_HIDEONMOUSEOVER, STR_HIDEONMOUSEOVER + ID_STR_DRAGGABLE, STR_DRAGGABLE + ID_STR_SAVEPOSITION, STR_SAVEPOSITION + ID_STR_SNAPTOEDGES, STR_SNAPTOEDGES + ID_STR_CLICKTHROUGH, STR_CLICKTHROUGH + ID_STR_KEEPONSCREEN, STR_KEEPONSCREEN + ID_STR_MANAGESKIN, STR_MANAGESKIN + ID_STR_EDITSKIN, STR_EDITSKIN + ID_STR_REFRESHSKIN, STR_REFRESHSKIN + ID_STR_UNLOADSKIN, STR_UNLOADSKIN + ID_STR_REFRESH, STR_REFRESH + ID_STR_EDIT, STR_EDIT + ID_STR_EXPAND, STR_EXPAND + ID_STR_OPENFOLDER, STR_OPENFOLDER + ID_STR_0PERCENT, "0%" + ID_STR_10PERCENT, "10%" + ID_STR_20PERCENT, "20%" + ID_STR_30PERCENT, "30%" + ID_STR_40PERCENT, "40%" + ID_STR_50PERCENT, "50%" + ID_STR_60PERCENT, "60%" + ID_STR_70PERCENT, "70%" + ID_STR_80PERCENT, "80%" + ID_STR_90PERCENT, "90%" + ID_STR_MANAGE, STR_MANAGE + ID_STR_ABOUT, STR_ABOUT + ID_STR_HELP, STR_HELP + ID_STR_NOSKINS, STR_NOSKINS + ID_STR_NOTHEMES, STR_NOTHEMES + ID_STR_EDITSETTINGS, STR_EDITSETTINGS + ID_STR_REFRESHALL, STR_REFRESHALL + ID_STR_LOGGING, STR_LOGGING + ID_STR_SHOWLOGFILE, STR_SHOWLOGFILE + ID_STR_STARTLOGGING, STR_STARTLOGGING + ID_STR_STOPLOGGING, STR_STOPLOGGING + ID_STR_DELETELOGFILE, STR_DELETELOGFILE + ID_STR_DEBUGMODE, STR_DEBUGMODE + ID_STR_EXIT, STR_EXIT } \ No newline at end of file diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index c9389dff..9e070db1 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -17,6 +17,7 @@ */ #include "StdAfx.h" +#include "../Common/MenuTemplate.h" #include "Rainmeter.h" #include "System.h" #include "MeterWindow.h" @@ -1052,21 +1053,26 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam) case IDC_MANAGESKINS_DISPLAYMONITOR_BUTTON: { - HMENU menu = LoadMenu(Rainmeter->GetResourceInstance(), MAKEINTRESOURCE(IDR_SKIN_MENU)); + static const MenuTemplate s_Menu[] = + { + MENU_ITEM(IDM_SKIN_MONITOR_PRIMARY, ID_STR_USEDEFAULTMONITOR), + MENU_ITEM(ID_MONITOR_FIRST, ID_STR_VIRTUALSCREEN), + MENU_SEPARATOR(), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_MONITOR_AUTOSELECT, ID_STR_AUTOSELECTMONITOR) + }; + + HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); if (menu) { - HMENU subMenu = GetSubMenu(menu, 0); // Skin menu - subMenu = GetSubMenu(subMenu, 4); // Settings menu - subMenu = GetSubMenu(subMenu, 0); // Position menu - subMenu = GetSubMenu(subMenu, 0); // Display monitor menu - Rainmeter->CreateMonitorMenu(subMenu, m_SkinWindow); + Rainmeter->CreateMonitorMenu(menu, m_SkinWindow); RECT r; GetWindowRect((HWND)lParam, &r); // Show context menu TrackPopupMenu( - subMenu, + menu, TPM_RIGHTBUTTON | TPM_LEFTALIGN, (*GetString(ID_STR_ISRTL) == L'1') ? r.right : r.left, --r.bottom, @@ -1233,46 +1239,58 @@ INT_PTR CDialogManage::CTabSkins::OnNotify(WPARAM wParam, LPARAM lParam) tvi.hItem = TreeView_GetSelection(nm->hwndFrom); tvi.mask = TVIF_STATE; - HMENU menu = LoadMenu(Rainmeter->GetResourceInstance(), MAKEINTRESOURCE(IDR_MANAGESKINS_MENU)); - if (menu && TreeView_GetItem(nm->hwndFrom, &tvi)) + if (TreeView_GetItem(nm->hwndFrom, &tvi)) { - HMENU subMenu; + HMENU menu = NULL; MENUITEMINFO mii = {0}; mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_STRING; if (m_SkinFileName.empty()) { - // It's a folder - subMenu = GetSubMenu(menu, 0); - SetMenuDefaultItem(subMenu, IDM_MANAGESKINSMENU_EXPAND, MF_BYCOMMAND); + // Folder menu. + static const MenuTemplate s_Menu[] = + { + MENU_ITEM(IDM_MANAGESKINSMENU_EXPAND, ID_STR_EXPAND), + MENU_ITEM(IDM_MANAGESKINSMENU_OPENFOLDER, ID_STR_OPENFOLDER), + }; + + menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); + SetMenuDefaultItem(menu, IDM_MANAGESKINSMENU_EXPAND, MF_BYCOMMAND); if (tvi.state & TVIS_EXPANDED) { mii.dwTypeData = GetString(ID_STR_COLLAPSE); - SetMenuItemInfo(subMenu, IDM_MANAGESKINSMENU_EXPAND, MF_BYCOMMAND, &mii); + SetMenuItemInfo(menu, IDM_MANAGESKINSMENU_EXPAND, MF_BYCOMMAND, &mii); } } else { - // It's a skin - subMenu = GetSubMenu(menu, 1); - SetMenuDefaultItem(subMenu, IDM_MANAGESKINSMENU_LOAD, MF_BYCOMMAND); + // Skin menu. + static const MenuTemplate s_Menu[] = + { + MENU_ITEM(IDM_MANAGESKINSMENU_LOAD, ID_STR_LOAD), + MENU_ITEM(IDM_MANAGESKINSMENU_REFRESH, ID_STR_REFRESH), + MENU_ITEM(IDM_MANAGESKINSMENU_EDIT, ID_STR_EDIT), + }; + + menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); + SetMenuDefaultItem(menu, IDM_MANAGESKINSMENU_LOAD, MF_BYCOMMAND); if (m_SkinWindow) { mii.dwTypeData = GetString(ID_STR_UNLOAD); - SetMenuItemInfo(subMenu, IDM_MANAGESKINSMENU_LOAD, MF_BYCOMMAND, &mii); + SetMenuItemInfo(menu, IDM_MANAGESKINSMENU_LOAD, MF_BYCOMMAND, &mii); } else { - EnableMenuItem(subMenu, IDM_MANAGESKINSMENU_REFRESH, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(menu, IDM_MANAGESKINSMENU_REFRESH, MF_BYCOMMAND | MF_GRAYED); } } // Show context menu TrackPopupMenu( - subMenu, + menu, TPM_RIGHTBUTTON | TPM_LEFTALIGN, pt.x, pt.y, diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index 85d22742..86f1fde9 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -185,6 +185,7 @@ + Use @@ -390,6 +391,7 @@ + diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index 23fa0d1d..0ecf1d9d 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -25,6 +25,9 @@ {5866a61e-ec27-469c-a8f0-2a45ce141f60} + + {3fcdd272-ad7a-4e06-a1bc-ff114498ccee} + @@ -321,6 +324,9 @@ Source Files + + Common + @@ -554,6 +560,9 @@ Header Files + + Common + diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index a7d9d1c1..49a8368e 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -17,6 +17,7 @@ */ #include "StdAfx.h" +#include "../Common/MenuTemplate.h" #include "Rainmeter.h" #include "TrayWindow.h" #include "System.h" @@ -2862,138 +2863,162 @@ int CRainmeter::ShowMessage(HWND parent, const WCHAR* text, UINT type) */ void CRainmeter::ShowContextMenu(POINT pos, CMeterWindow* meterWindow) { + static const MenuTemplate s_Menu[] = + { + MENU_ITEM(IDM_MANAGE, ID_STR_MANAGE), + MENU_ITEM(IDM_ABOUT, ID_STR_ABOUT), + MENU_ITEM(IDM_SHOW_HELP, ID_STR_HELP), + MENU_SEPARATOR(), + MENU_SUBMENU(ID_STR_SKINS, + MENU_ITEM_GRAYED(0, ID_STR_NOTHEMES), + MENU_SEPARATOR(), + MENU_ITEM(IDM_OPENSKINSFOLDER, ID_STR_REFRESHSKIN), + MENU_ITEM(IDM_DISABLEDRAG, ID_STR_REFRESHSKIN)), + MENU_SUBMENU(ID_STR_THEMES, + MENU_ITEM_GRAYED(0, ID_STR_STAYTOPMOST)), + MENU_SEPARATOR(), + MENU_ITEM(IDM_EDITCONFIG, ID_STR_EDITSETTINGS), + MENU_ITEM(IDM_REFRESH, ID_STR_REFRESHALL), + MENU_SEPARATOR(), + MENU_SUBMENU(ID_STR_LOGGING, + MENU_ITEM(IDM_SHOWLOGFILE, ID_STR_SHOWLOGFILE), + MENU_SEPARATOR(), + MENU_ITEM(IDM_STARTLOG, ID_STR_STARTLOGGING), + MENU_ITEM(IDM_STOPLOG, ID_STR_STOPLOGGING), + MENU_SEPARATOR(), + MENU_ITEM(IDM_DELETELOGFILE, ID_STR_DELETELOGFILE), + MENU_ITEM(IDM_DEBUGLOG, ID_STR_DEBUGMODE)), + MENU_SEPARATOR(), + MENU_ITEM(IDM_QUIT, ID_STR_EXIT) + }; + if (!m_MenuActive) { m_MenuActive = true; // Show context menu, if no actions were executed - HMENU menu = LoadMenu(m_ResourceInstance, MAKEINTRESOURCE(IDR_CONTEXT_MENU)); - + HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); if (menu) { - HMENU subMenu = GetSubMenu(menu, 0); - if (subMenu) + SetMenuDefaultItem(menu, IDM_MANAGE, MF_BYCOMMAND); + + if (_waccess(m_LogFile.c_str(), 0) == -1) { - SetMenuDefaultItem(subMenu, IDM_MANAGE, MF_BYCOMMAND); + EnableMenuItem(menu, IDM_SHOWLOGFILE, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(menu, IDM_DELETELOGFILE, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(menu, IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED); + } + else + { + EnableMenuItem(menu, (m_Logging) ? IDM_STARTLOG : IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED); + } - if (_waccess(m_LogFile.c_str(), 0) == -1) + if (m_Debug) + { + CheckMenuItem(menu, IDM_DEBUGLOG, MF_BYCOMMAND | MF_CHECKED); + } + + HMENU allSkinsMenu = GetSubMenu(menu, 4); + if (allSkinsMenu) + { + if (!m_SkinFolders.empty()) { - EnableMenuItem(subMenu, IDM_SHOWLOGFILE, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(subMenu, IDM_DELETELOGFILE, MF_BYCOMMAND | MF_GRAYED); - EnableMenuItem(subMenu, IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED); - } - else - { - EnableMenuItem(subMenu, (m_Logging) ? IDM_STARTLOG : IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED); + DeleteMenu(allSkinsMenu, 0, MF_BYPOSITION); // "No skins available" menuitem + CreateAllSkinsMenu(allSkinsMenu); } - if (m_Debug) + if (m_DisableDragging) { - CheckMenuItem(subMenu, IDM_DEBUGLOG, MF_BYCOMMAND | MF_CHECKED); - } - - HMENU skinMenu = GetSubMenu(subMenu, 4); - if (skinMenu) - { - if (!m_SkinFolders.empty()) - { - DeleteMenu(skinMenu, 0, MF_BYPOSITION); // "No skins available" menuitem - CreateAllSkinsMenu(skinMenu); - } - - if (m_DisableDragging) - { - CheckMenuItem(skinMenu, IDM_DISABLEDRAG, MF_BYCOMMAND | MF_CHECKED); - } - } - - HMENU layoutMenu = GetSubMenu(subMenu, 5); - if (layoutMenu) - { - if (!m_Layouts.empty()) - { - DeleteMenu(layoutMenu, 0, MF_BYPOSITION); // "No layouts available" menuitem - CreateLayoutMenu(layoutMenu); - } - } - - if (meterWindow) - { - HMENU rainmeterMenu = subMenu; - subMenu = CreateSkinMenu(meterWindow, 0, skinMenu); - - WCHAR buffer[256]; - GetMenuString(menu, 0, buffer, 256, MF_BYPOSITION); - - InsertMenu(subMenu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)rainmeterMenu, buffer); - InsertMenu(subMenu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_SEPARATOR, 0, NULL); - } - else - { - InsertMenu(subMenu, 12, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); - - // Create a menu for all active skins - int index = 0; - std::map::const_iterator iter = m_MeterWindows.begin(); - for (; iter != m_MeterWindows.end(); ++iter) - { - CMeterWindow* mw = ((*iter).second); - HMENU menu = CreateSkinMenu(mw, index, skinMenu); - InsertMenu(subMenu, 12, MF_BYPOSITION | MF_POPUP, (UINT_PTR)menu, mw->GetFolderPath().c_str()); - ++index; - } - - // Add update notification item - if (m_NewVersion) - { - InsertMenu(subMenu, 0, MF_BYPOSITION, IDM_NEW_VERSION, GetString(ID_STR_UPDATEAVAILABLE)); - HiliteMenuItem(GetTrayWindow()->GetWindow(), subMenu, 0, MF_BYPOSITION | MF_HILITE); - InsertMenu(subMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); - } - } - - HWND hWnd = WindowFromPoint(pos); - if (hWnd != NULL) - { - CMeterWindow* mw = GetMeterWindow(hWnd); - if (mw) - { - // Cancel the mouse event beforehand - mw->SetMouseLeaveEvent(true); - } - } - - // Set the window to foreground - hWnd = meterWindow ? meterWindow->GetWindow() : m_TrayWindow->GetWindow(); - HWND hWndForeground = GetForegroundWindow(); - if (hWndForeground != hWnd) - { - DWORD foregroundThreadID = GetWindowThreadProcessId(hWndForeground, NULL); - DWORD currentThreadID = GetCurrentThreadId(); - AttachThreadInput(currentThreadID, foregroundThreadID, TRUE); - SetForegroundWindow(hWnd); - AttachThreadInput(currentThreadID, foregroundThreadID, FALSE); - } - - // Show context menu - TrackPopupMenu( - subMenu, - TPM_RIGHTBUTTON | TPM_LEFTALIGN | (*GetString(ID_STR_ISRTL) == L'1' ? TPM_LAYOUTRTL : 0), - pos.x, - pos.y, - 0, - hWnd, - NULL); - - if (meterWindow) - { - DestroyMenu(subMenu); + CheckMenuItem(allSkinsMenu, IDM_DISABLEDRAG, MF_BYCOMMAND | MF_CHECKED); } } - DestroyMenu(menu); + HMENU layoutMenu = GetSubMenu(menu, 5); + if (layoutMenu) + { + if (!m_Layouts.empty()) + { + DeleteMenu(layoutMenu, 0, MF_BYPOSITION); // "No layouts available" menuitem + CreateLayoutMenu(layoutMenu); + } + } + + if (meterWindow) + { + HMENU rainmeterMenu = menu; + menu = CreateSkinMenu(meterWindow, 0, allSkinsMenu); + + WCHAR buffer[256]; + GetMenuString(menu, 0, buffer, 256, MF_BYPOSITION); + + InsertMenu(menu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)rainmeterMenu, buffer); + InsertMenu(menu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_SEPARATOR, 0, NULL); + } + else + { + InsertMenu(menu, 12, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); + + // Create a menu for all active skins + int index = 0; + std::map::const_iterator iter = m_MeterWindows.begin(); + for (; iter != m_MeterWindows.end(); ++iter) + { + CMeterWindow* mw = ((*iter).second); + HMENU skinMenu = CreateSkinMenu(mw, index, allSkinsMenu); + InsertMenu(menu, 12, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetFolderPath().c_str()); + ++index; + } + + // Add update notification item + if (m_NewVersion) + { + InsertMenu(menu, 0, MF_BYPOSITION, IDM_NEW_VERSION, GetString(ID_STR_UPDATEAVAILABLE)); + HiliteMenuItem(GetTrayWindow()->GetWindow(), menu, 0, MF_BYPOSITION | MF_HILITE); + InsertMenu(menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); + } + } + + HWND hWnd = WindowFromPoint(pos); + if (hWnd != NULL) + { + CMeterWindow* mw = GetMeterWindow(hWnd); + if (mw) + { + // Cancel the mouse event beforehand + mw->SetMouseLeaveEvent(true); + } + } + + // Set the window to foreground + hWnd = meterWindow ? meterWindow->GetWindow() : m_TrayWindow->GetWindow(); + HWND hWndForeground = GetForegroundWindow(); + if (hWndForeground != hWnd) + { + DWORD foregroundThreadID = GetWindowThreadProcessId(hWndForeground, NULL); + DWORD currentThreadID = GetCurrentThreadId(); + AttachThreadInput(currentThreadID, foregroundThreadID, TRUE); + SetForegroundWindow(hWnd); + AttachThreadInput(currentThreadID, foregroundThreadID, FALSE); + } + + // Show context menu + TrackPopupMenu( + menu, + TPM_RIGHTBUTTON | TPM_LEFTALIGN | (*GetString(ID_STR_ISRTL) == L'1' ? TPM_LAYOUTRTL : 0), + pos.x, + pos.y, + 0, + hWnd, + NULL); + + if (meterWindow) + { + DestroyMenu(menu); + } } + DestroyMenu(menu); + m_MenuActive = false; } } @@ -3054,16 +3079,62 @@ int CRainmeter::CreateAllSkinsMenuRecursive(HMENU skinMenu, int index) HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU menu) { - HMENU skinMenu = LoadMenu(m_ResourceInstance, MAKEINTRESOURCE(IDR_SKIN_MENU)); - - if (skinMenu) + static const MenuTemplate s_Menu[] = { - HMENU subSkinMenu = GetSubMenu(skinMenu, 0); - RemoveMenu(skinMenu, 0, MF_BYPOSITION); - DestroyMenu(skinMenu); - skinMenu = subSkinMenu; - } + MENU_ITEM(IDM_SKIN_OPENSKINSFOLDER, 0), + MENU_SEPARATOR(), + MENU_SUBMENU(ID_STR_VARIANTS, + MENU_SEPARATOR()), + MENU_SEPARATOR(), + MENU_SUBMENU(ID_STR_SETTINGS, + MENU_SUBMENU(ID_STR_POSITION, + MENU_SUBMENU(ID_STR_DISPLAYMONITOR, + MENU_ITEM(IDM_SKIN_MONITOR_PRIMARY, ID_STR_USEDEFAULTMONITOR), + MENU_ITEM(ID_MONITOR_FIRST, ID_STR_VIRTUALSCREEN), + MENU_SEPARATOR(), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_MONITOR_AUTOSELECT, ID_STR_AUTOSELECTMONITOR)), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_VERYTOPMOST, ID_STR_STAYTOPMOST), + MENU_ITEM(IDM_SKIN_TOPMOST, ID_STR_TOPMOST), + MENU_ITEM(IDM_SKIN_NORMAL, ID_STR_NORMAL), + MENU_ITEM(IDM_SKIN_BOTTOM, ID_STR_BOTTOM), + MENU_ITEM(IDM_SKIN_ONDESKTOP, ID_STR_ONDESKTOP), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_FROMRIGHT, ID_STR_FROMRIGHT), + MENU_ITEM(IDM_SKIN_FROMBOTTOM, ID_STR_FROMBOTTOM), + MENU_ITEM(IDM_SKIN_XPERCENTAGE, ID_STR_XASPERCENTAGE), + MENU_ITEM(IDM_SKIN_YPERCENTAGE, ID_STR_YASPERCENTAGE)), + MENU_SUBMENU(ID_STR_TRANSPARENCY, + MENU_ITEM(IDM_SKIN_TRANSPARENCY_0, ID_STR_0PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_10, ID_STR_10PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_20, ID_STR_20PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_30, ID_STR_30PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_40, ID_STR_40PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_50, ID_STR_50PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_60, ID_STR_60PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_70, ID_STR_70PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_80, ID_STR_80PERCENT), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_90, ID_STR_90PERCENT), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_FADEIN, ID_STR_FADEIN), + MENU_ITEM(IDM_SKIN_TRANSPARENCY_FADEOUT, ID_STR_FADEOUT)), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_HIDEONMOUSE, ID_STR_HIDEONMOUSEOVER), + MENU_ITEM(IDM_SKIN_DRAGGABLE, ID_STR_DRAGGABLE), + MENU_ITEM(IDM_SKIN_REMEMBERPOSITION, ID_STR_SAVEPOSITION), + MENU_ITEM(IDM_SKIN_SNAPTOEDGES, ID_STR_SNAPTOEDGES), + MENU_ITEM(IDM_SKIN_CLICKTHROUGH, ID_STR_CLICKTHROUGH), + MENU_ITEM(IDM_SKIN_KEEPONSCREEN, ID_STR_KEEPONSCREEN)), + MENU_SEPARATOR(), + MENU_ITEM(IDM_SKIN_MANAGESKIN, ID_STR_MANAGESKIN), + MENU_ITEM(IDM_SKIN_EDITSKIN, ID_STR_EDITSKIN), + MENU_ITEM(IDM_SKIN_REFRESH, ID_STR_REFRESHSKIN), + MENU_SEPARATOR(), + MENU_ITEM(IDM_CLOSESKIN, ID_STR_UNLOADSKIN) + }; + HMENU skinMenu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString); if (skinMenu) { // Tick the position diff --git a/Library/resource.h b/Library/resource.h index f1878f52..ccd329ee 100644 --- a/Library/resource.h +++ b/Library/resource.h @@ -5,9 +5,6 @@ #define IDC_STATIC -1 #define IDI_RAINMETER 100 #define IDI_TRAY 101 -#define IDR_CONTEXT_MENU 102 -#define IDR_SKIN_MENU 103 -#define IDR_MANAGESKINS_MENU 104 #define IDD_ABOUT_DIALOG 105 #define IDD_ABOUTLOG_DIALOG 106 #define IDD_ABOUTSKINS_DIALOG 107 @@ -145,6 +142,54 @@ #define ID_STR_WELCOME 2047 #define ID_STR_CLICKTOMANAGE 2048 #define ID_STR_CLICKTODOWNLOAD 2049 +#define ID_STR_VARIANTS 2050 +#define ID_STR_POSITION 2051 +#define ID_STR_USEDEFAULTMONITOR 2052 +#define ID_STR_VIRTUALSCREEN 2053 +#define ID_STR_AUTOSELECTMONITOR 2054 +#define ID_STR_FROMRIGHT 2055 +#define ID_STR_FROMBOTTOM 2056 +#define ID_STR_XASPERCENTAGE 2057 +#define ID_STR_YASPERCENTAGE 2058 +#define ID_STR_TRANSPARENCY 2059 +#define ID_STR_HIDEONMOUSEOVER 2060 +#define ID_STR_DRAGGABLE 2061 +#define ID_STR_SAVEPOSITION 2062 +#define ID_STR_SNAPTOEDGES 2063 +#define ID_STR_CLICKTHROUGH 2064 +#define ID_STR_KEEPONSCREEN 2065 +#define ID_STR_MANAGESKIN 2066 +#define ID_STR_EDITSKIN 2067 +#define ID_STR_REFRESHSKIN 2068 +#define ID_STR_UNLOADSKIN 2069 +#define ID_STR_REFRESH 2070 +#define ID_STR_EDIT 2071 +#define ID_STR_EXPAND 2072 +#define ID_STR_OPENFOLDER 2073 +#define ID_STR_0PERCENT 2074 +#define ID_STR_10PERCENT 2075 +#define ID_STR_20PERCENT 2076 +#define ID_STR_30PERCENT 2077 +#define ID_STR_40PERCENT 2078 +#define ID_STR_50PERCENT 2079 +#define ID_STR_60PERCENT 2080 +#define ID_STR_70PERCENT 2081 +#define ID_STR_80PERCENT 2082 +#define ID_STR_90PERCENT 2083 +#define ID_STR_MANAGE 2084 +#define ID_STR_ABOUT 2085 +#define ID_STR_HELP 2086 +#define ID_STR_NOSKINS 2087 +#define ID_STR_NOTHEMES 2088 +#define ID_STR_EDITSETTINGS 2089 +#define ID_STR_REFRESHALL 2090 +#define ID_STR_LOGGING 2091 +#define ID_STR_SHOWLOGFILE 2092 +#define ID_STR_STARTLOGGING 2093 +#define ID_STR_STOPLOGGING 2094 +#define ID_STR_DELETELOGFILE 2095 +#define ID_STR_DEBUGMODE 2096 +#define ID_STR_EXIT 2097 #define IDM_REFRESH 4001 #define IDM_QUIT 4002