From d13b13ec763d5b0f62c4d9a8252c2f2d9bf2b4a1 Mon Sep 17 00:00:00 2001 From: Shriraj Sawant Date: Tue, 25 Jul 2017 21:48:51 +0000 Subject: [PATCH] [STOBJECT] -Fixed bugs related to strings and localization (needs further improvement). -Fixed ContextMenu Position bug (for both power and volume). -Now battery tooltip is as dynamic as its icon. svn path=/branches/GSoC_2017/shellext/; revision=75405 --- reactos/dll/shellext/stobject/lang/en-US.rc | 4 +- reactos/dll/shellext/stobject/power.cpp | 97 +++++++++++---------- reactos/dll/shellext/stobject/stobject.rc | 4 +- reactos/dll/shellext/stobject/volume.cpp | 7 +- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/reactos/dll/shellext/stobject/lang/en-US.rc b/reactos/dll/shellext/stobject/lang/en-US.rc index c4a2f48f1bb..2d168e75aa1 100644 --- a/reactos/dll/shellext/stobject/lang/en-US.rc +++ b/reactos/dll/shellext/stobject/lang/en-US.rc @@ -17,8 +17,8 @@ BEGIN //Power related strings IDS_PWR_PROPERTIES "&Adjust Power Properties" IDS_PWR_METER "&Open Power Meter" - IDS_PWR_PERCENT_REMAINING "%1!u!%% remaining" - IDS_PWR_CHARGING " (charging)" + IDS_PWR_PERCENT_REMAINING "%.2f%% remaining" + IDS_PWR_CHARGING "%.2f%% and charging" IDS_PWR_UNKNOWN_REMAINING "Unknown remaining" IDS_PWR_AC "On AC power" IDS_PWR_HOURS_REMAINING "%1!u!:%2!02u! hours (%3!u!%%) remaining" diff --git a/reactos/dll/shellext/stobject/power.cpp b/reactos/dll/shellext/stobject/power.cpp index 41c18cce850..b53f75e93a9 100644 --- a/reactos/dll/shellext/stobject/power.cpp +++ b/reactos/dll/shellext/stobject/power.cpp @@ -18,13 +18,11 @@ #include #include +#include #define GBS_HASBATTERY 0x1 #define GBS_ONBATTERY 0x2 -#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) -#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) - WINE_DEFAULT_DEBUG_CHANNEL(stobject); int br_icons[5] = { IDI_BATTCAP0, IDI_BATTCAP1, IDI_BATTCAP2, IDI_BATTCAP3, IDI_BATTCAP4 }; @@ -37,10 +35,9 @@ typedef struct _PWRSCHEMECONTEXT UINT uiLast; } PWRSCHEMECONTEXT, *PPWRSCHEMECONTEXT; +CString g_strTooltip; static float g_batCap = 0; static HICON g_hIconBattery = NULL; -static HICON g_hIconAC = NULL; - static BOOL g_IsRunning = FALSE; /*** This function enumerates the available battery devices and provides the remaining capacity @@ -168,56 +165,67 @@ static UINT Quantize(float p, UINT lvl = 10) return i - 1; } +/*** This function returns the respective icon as per the current battery capacity. + It also does the work of setting global parameters of battery capacity and tooltips. +@param hinst: instance handle +@return : icon handle +*/ static HICON DynamicLoadIcon(HINSTANCE hinst) -{ +{ HICON hBatIcon; float cap = 0; DWORD dw = 0; UINT index = -1; HRESULT hr = GetBatteryState(cap, dw); + if (!FAILED(hr) && (dw & GBS_HASBATTERY)) { index = Quantize(cap, 4); g_batCap = cap; } + else + { + g_batCap = 0; + hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_BATTCAP_ERR)); + g_strTooltip.LoadStringW(IDS_PWR_UNKNOWN_REMAINING); + return hBatIcon; + } if (dw & GBS_ONBATTERY) - hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(index<0 ? IDI_BATTCAP_ERR : br_icons[index])); + { + hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(br_icons[index])); + g_strTooltip.Format(IDS_PWR_PERCENT_REMAINING, cap); + + } else - hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(index<0 ? IDI_BATTCAP_ERR : bc_icons[index])); + { + hBatIcon = LoadIcon(hinst, MAKEINTRESOURCE(bc_icons[index])); + g_strTooltip.Format(IDS_PWR_CHARGING, cap); + } return hBatIcon; } HRESULT STDMETHODCALLTYPE Power_Init(_In_ CSysTray * pSysTray) -{ - WCHAR strTooltip[128]; - HICON icon; - - TRACE("Power_Init\n"); - - g_hIconBattery = DynamicLoadIcon(g_hInstance); - swprintf(strTooltip, L"%.2f %% Remaining", g_batCap); +{ + TRACE("Power_Init\n"); + g_hIconBattery = DynamicLoadIcon(g_hInstance); g_IsRunning = TRUE; - - return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_POWER, g_hIconBattery, strTooltip); + + return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_POWER, g_hIconBattery, g_strTooltip); } HRESULT STDMETHODCALLTYPE Power_Update(_In_ CSysTray * pSysTray) { - TRACE("Power_Update\n"); + TRACE("Power_Update\n"); + g_hIconBattery = DynamicLoadIcon(g_hInstance); - WCHAR strTooltip[128]; - g_hIconBattery = DynamicLoadIcon(g_hInstance); - swprintf(strTooltip, L"%.2f %% Remaining", g_batCap); - - return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_POWER, g_hIconBattery, strTooltip); + return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_POWER, g_hIconBattery, g_strTooltip); } HRESULT STDMETHODCALLTYPE Power_Shutdown(_In_ CSysTray * pSysTray) { TRACE("Power_Shutdown\n"); - g_IsRunning = FALSE; return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_POWER, NULL, NULL); @@ -230,22 +238,18 @@ static void _RunPower() static void _ShowContextMenu(CSysTray * pSysTray) { - WCHAR strOpen[128]; - - LoadStringW(g_hInstance, IDS_PWR_PROPERTIES, strOpen, _countof(strOpen)); - - HMENU hPopup = CreatePopupMenu(); - AppendMenuW(hPopup, MF_STRING, IDS_PWR_PROPERTIES, strOpen); - - DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN; - DWORD msgPos = GetMessagePos(); - + CString strOpen((LPCSTR)IDS_PWR_PROPERTIES); + HMENU hPopup = CreatePopupMenu(); + AppendMenuW(hPopup, MF_STRING, IDS_PWR_PROPERTIES, strOpen); + SetForegroundWindow(pSysTray->GetHWnd()); + DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN; + POINT pt; + GetCursorPos(&pt); + DWORD id = TrackPopupMenuEx(hPopup, flags, - GET_X_LPARAM(msgPos), GET_Y_LPARAM(msgPos), - pSysTray->GetHWnd(), NULL); - - DestroyMenu(hPopup); + pt.x, pt.y, + pSysTray->GetHWnd(), NULL); switch (id) { @@ -253,6 +257,7 @@ static void _ShowContextMenu(CSysTray * pSysTray) _RunPower(); break; } + DestroyMenu(hPopup); } static @@ -287,8 +292,8 @@ ShowPowerSchemesPopupMenu( { PWRSCHEMECONTEXT PowerSchemeContext = {NULL, 0, 0}; UINT uiActiveScheme; - DWORD id, msgPos; - + DWORD id; + POINT pt; PowerSchemeContext.hPopup = CreatePopupMenu(); EnumPwrSchemes(PowerSchemesEnumProc, (LPARAM)&PowerSchemeContext); @@ -301,13 +306,13 @@ ShowPowerSchemesPopupMenu( MF_BYCOMMAND); } - msgPos = GetMessagePos(); - SetForegroundWindow(pSysTray->GetHWnd()); + GetCursorPos(&pt); + id = TrackPopupMenuEx(PowerSchemeContext.hPopup, TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN, - GET_X_LPARAM(msgPos), - GET_Y_LPARAM(msgPos), + pt.x, + pt.y, pSysTray->GetHWnd(), NULL); @@ -363,7 +368,7 @@ HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPA break; case WM_RBUTTONUP: - _ShowContextMenu(pSysTray); + _ShowContextMenu(pSysTray); break; case WM_RBUTTONDBLCLK: diff --git a/reactos/dll/shellext/stobject/stobject.rc b/reactos/dll/shellext/stobject/stobject.rc index b42beb39cd5..6f99fefab9b 100644 --- a/reactos/dll/shellext/stobject/stobject.rc +++ b/reactos/dll/shellext/stobject/stobject.rc @@ -31,7 +31,7 @@ IDR_SYSTRAY REGISTRY "resources/rgs/systray.rgs" #include // Strings common to all languages -STRINGTABLE +/*STRINGTABLE BEGIN // Power related strings IDS_PWR_RUN "shell32.dll,Control_RunDLL PowerCfg.cpl" @@ -41,7 +41,7 @@ BEGIN // Volume related strings IDS_VOL_RUN "SNDVOL32.EXE" -END +END*/ /* UTF-8 */ #pragma code_page(65001) diff --git a/reactos/dll/shellext/stobject/volume.cpp b/reactos/dll/shellext/stobject/volume.cpp index f848468af19..3ca780b2001 100644 --- a/reactos/dll/shellext/stobject/volume.cpp +++ b/reactos/dll/shellext/stobject/volume.cpp @@ -243,11 +243,12 @@ static void _ShowContextMenu(CSysTray * pSysTray) AppendMenuW(hPopup, MF_STRING, IDS_VOL_ADJUST, strAdjust); DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN; - DWORD msgPos = GetMessagePos(); - + POINT pt; SetForegroundWindow(pSysTray->GetHWnd()); + GetCursorPos(&pt); + DWORD id = TrackPopupMenuEx(hPopup, flags, - GET_X_LPARAM(msgPos), GET_Y_LPARAM(msgPos), + pt.x, pt.y, pSysTray->GetHWnd(), NULL); DestroyMenu(hPopup);