mirror of
https://github.com/reactos/reactos.git
synced 2024-10-01 23:14:53 +00:00
[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
This commit is contained in:
parent
287232ea2f
commit
d13b13ec76
|
@ -17,8 +17,8 @@ BEGIN
|
||||||
//Power related strings
|
//Power related strings
|
||||||
IDS_PWR_PROPERTIES "&Adjust Power Properties"
|
IDS_PWR_PROPERTIES "&Adjust Power Properties"
|
||||||
IDS_PWR_METER "&Open Power Meter"
|
IDS_PWR_METER "&Open Power Meter"
|
||||||
IDS_PWR_PERCENT_REMAINING "%1!u!%% remaining"
|
IDS_PWR_PERCENT_REMAINING "%.2f%% remaining"
|
||||||
IDS_PWR_CHARGING " (charging)"
|
IDS_PWR_CHARGING "%.2f%% and charging"
|
||||||
IDS_PWR_UNKNOWN_REMAINING "Unknown remaining"
|
IDS_PWR_UNKNOWN_REMAINING "Unknown remaining"
|
||||||
IDS_PWR_AC "On AC power"
|
IDS_PWR_AC "On AC power"
|
||||||
IDS_PWR_HOURS_REMAINING "%1!u!:%2!02u! hours (%3!u!%%) remaining"
|
IDS_PWR_HOURS_REMAINING "%1!u!:%2!02u! hours (%3!u!%%) remaining"
|
||||||
|
|
|
@ -18,13 +18,11 @@
|
||||||
|
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
#include <mmddk.h>
|
#include <mmddk.h>
|
||||||
|
#include <atlstr.h>
|
||||||
|
|
||||||
#define GBS_HASBATTERY 0x1
|
#define GBS_HASBATTERY 0x1
|
||||||
#define GBS_ONBATTERY 0x2
|
#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);
|
WINE_DEFAULT_DEBUG_CHANNEL(stobject);
|
||||||
|
|
||||||
int br_icons[5] = { IDI_BATTCAP0, IDI_BATTCAP1, IDI_BATTCAP2, IDI_BATTCAP3, IDI_BATTCAP4 };
|
int br_icons[5] = { IDI_BATTCAP0, IDI_BATTCAP1, IDI_BATTCAP2, IDI_BATTCAP3, IDI_BATTCAP4 };
|
||||||
|
@ -37,10 +35,9 @@ typedef struct _PWRSCHEMECONTEXT
|
||||||
UINT uiLast;
|
UINT uiLast;
|
||||||
} PWRSCHEMECONTEXT, *PPWRSCHEMECONTEXT;
|
} PWRSCHEMECONTEXT, *PPWRSCHEMECONTEXT;
|
||||||
|
|
||||||
|
CString g_strTooltip;
|
||||||
static float g_batCap = 0;
|
static float g_batCap = 0;
|
||||||
static HICON g_hIconBattery = NULL;
|
static HICON g_hIconBattery = NULL;
|
||||||
static HICON g_hIconAC = NULL;
|
|
||||||
|
|
||||||
static BOOL g_IsRunning = FALSE;
|
static BOOL g_IsRunning = FALSE;
|
||||||
|
|
||||||
/*** This function enumerates the available battery devices and provides the remaining capacity
|
/*** This function enumerates the available battery devices and provides the remaining capacity
|
||||||
|
@ -168,6 +165,11 @@ static UINT Quantize(float p, UINT lvl = 10)
|
||||||
return i - 1;
|
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)
|
static HICON DynamicLoadIcon(HINSTANCE hinst)
|
||||||
{
|
{
|
||||||
HICON hBatIcon;
|
HICON hBatIcon;
|
||||||
|
@ -175,49 +177,55 @@ static HICON DynamicLoadIcon(HINSTANCE hinst)
|
||||||
DWORD dw = 0;
|
DWORD dw = 0;
|
||||||
UINT index = -1;
|
UINT index = -1;
|
||||||
HRESULT hr = GetBatteryState(cap, dw);
|
HRESULT hr = GetBatteryState(cap, dw);
|
||||||
|
|
||||||
if (!FAILED(hr) && (dw & GBS_HASBATTERY))
|
if (!FAILED(hr) && (dw & GBS_HASBATTERY))
|
||||||
{
|
{
|
||||||
index = Quantize(cap, 4);
|
index = Quantize(cap, 4);
|
||||||
g_batCap = cap;
|
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)
|
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
|
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;
|
return hBatIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE Power_Init(_In_ CSysTray * pSysTray)
|
HRESULT STDMETHODCALLTYPE Power_Init(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
WCHAR strTooltip[128];
|
|
||||||
HICON icon;
|
|
||||||
|
|
||||||
TRACE("Power_Init\n");
|
TRACE("Power_Init\n");
|
||||||
|
|
||||||
g_hIconBattery = DynamicLoadIcon(g_hInstance);
|
g_hIconBattery = DynamicLoadIcon(g_hInstance);
|
||||||
swprintf(strTooltip, L"%.2f %% Remaining", g_batCap);
|
|
||||||
g_IsRunning = TRUE;
|
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)
|
HRESULT STDMETHODCALLTYPE Power_Update(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Power_Update\n");
|
TRACE("Power_Update\n");
|
||||||
|
|
||||||
WCHAR strTooltip[128];
|
|
||||||
g_hIconBattery = DynamicLoadIcon(g_hInstance);
|
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)
|
HRESULT STDMETHODCALLTYPE Power_Shutdown(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Power_Shutdown\n");
|
TRACE("Power_Shutdown\n");
|
||||||
|
|
||||||
g_IsRunning = FALSE;
|
g_IsRunning = FALSE;
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_POWER, NULL, NULL);
|
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_POWER, NULL, NULL);
|
||||||
|
@ -230,22 +238,18 @@ static void _RunPower()
|
||||||
|
|
||||||
static void _ShowContextMenu(CSysTray * pSysTray)
|
static void _ShowContextMenu(CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
WCHAR strOpen[128];
|
CString strOpen((LPCSTR)IDS_PWR_PROPERTIES);
|
||||||
|
|
||||||
LoadStringW(g_hInstance, IDS_PWR_PROPERTIES, strOpen, _countof(strOpen));
|
|
||||||
|
|
||||||
HMENU hPopup = CreatePopupMenu();
|
HMENU hPopup = CreatePopupMenu();
|
||||||
AppendMenuW(hPopup, MF_STRING, IDS_PWR_PROPERTIES, strOpen);
|
AppendMenuW(hPopup, MF_STRING, IDS_PWR_PROPERTIES, strOpen);
|
||||||
|
|
||||||
DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN;
|
|
||||||
DWORD msgPos = GetMessagePos();
|
|
||||||
|
|
||||||
SetForegroundWindow(pSysTray->GetHWnd());
|
SetForegroundWindow(pSysTray->GetHWnd());
|
||||||
DWORD id = TrackPopupMenuEx(hPopup, flags,
|
DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN;
|
||||||
GET_X_LPARAM(msgPos), GET_Y_LPARAM(msgPos),
|
POINT pt;
|
||||||
pSysTray->GetHWnd(), NULL);
|
GetCursorPos(&pt);
|
||||||
|
|
||||||
DestroyMenu(hPopup);
|
DWORD id = TrackPopupMenuEx(hPopup, flags,
|
||||||
|
pt.x, pt.y,
|
||||||
|
pSysTray->GetHWnd(), NULL);
|
||||||
|
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
|
@ -253,6 +257,7 @@ static void _ShowContextMenu(CSysTray * pSysTray)
|
||||||
_RunPower();
|
_RunPower();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
DestroyMenu(hPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -287,8 +292,8 @@ ShowPowerSchemesPopupMenu(
|
||||||
{
|
{
|
||||||
PWRSCHEMECONTEXT PowerSchemeContext = {NULL, 0, 0};
|
PWRSCHEMECONTEXT PowerSchemeContext = {NULL, 0, 0};
|
||||||
UINT uiActiveScheme;
|
UINT uiActiveScheme;
|
||||||
DWORD id, msgPos;
|
DWORD id;
|
||||||
|
POINT pt;
|
||||||
PowerSchemeContext.hPopup = CreatePopupMenu();
|
PowerSchemeContext.hPopup = CreatePopupMenu();
|
||||||
EnumPwrSchemes(PowerSchemesEnumProc, (LPARAM)&PowerSchemeContext);
|
EnumPwrSchemes(PowerSchemesEnumProc, (LPARAM)&PowerSchemeContext);
|
||||||
|
|
||||||
|
@ -301,13 +306,13 @@ ShowPowerSchemesPopupMenu(
|
||||||
MF_BYCOMMAND);
|
MF_BYCOMMAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
msgPos = GetMessagePos();
|
|
||||||
|
|
||||||
SetForegroundWindow(pSysTray->GetHWnd());
|
SetForegroundWindow(pSysTray->GetHWnd());
|
||||||
|
GetCursorPos(&pt);
|
||||||
|
|
||||||
id = TrackPopupMenuEx(PowerSchemeContext.hPopup,
|
id = TrackPopupMenuEx(PowerSchemeContext.hPopup,
|
||||||
TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN,
|
TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN,
|
||||||
GET_X_LPARAM(msgPos),
|
pt.x,
|
||||||
GET_Y_LPARAM(msgPos),
|
pt.y,
|
||||||
pSysTray->GetHWnd(),
|
pSysTray->GetHWnd(),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ IDR_SYSTRAY REGISTRY "resources/rgs/systray.rgs"
|
||||||
#include <reactos/manifest_dll.rc>
|
#include <reactos/manifest_dll.rc>
|
||||||
|
|
||||||
// Strings common to all languages
|
// Strings common to all languages
|
||||||
STRINGTABLE
|
/*STRINGTABLE
|
||||||
BEGIN
|
BEGIN
|
||||||
// Power related strings
|
// Power related strings
|
||||||
IDS_PWR_RUN "shell32.dll,Control_RunDLL PowerCfg.cpl"
|
IDS_PWR_RUN "shell32.dll,Control_RunDLL PowerCfg.cpl"
|
||||||
|
@ -41,7 +41,7 @@ BEGIN
|
||||||
|
|
||||||
// Volume related strings
|
// Volume related strings
|
||||||
IDS_VOL_RUN "SNDVOL32.EXE"
|
IDS_VOL_RUN "SNDVOL32.EXE"
|
||||||
END
|
END*/
|
||||||
|
|
||||||
/* UTF-8 */
|
/* UTF-8 */
|
||||||
#pragma code_page(65001)
|
#pragma code_page(65001)
|
||||||
|
|
|
@ -243,11 +243,12 @@ static void _ShowContextMenu(CSysTray * pSysTray)
|
||||||
AppendMenuW(hPopup, MF_STRING, IDS_VOL_ADJUST, strAdjust);
|
AppendMenuW(hPopup, MF_STRING, IDS_VOL_ADJUST, strAdjust);
|
||||||
|
|
||||||
DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN;
|
DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN;
|
||||||
DWORD msgPos = GetMessagePos();
|
POINT pt;
|
||||||
|
|
||||||
SetForegroundWindow(pSysTray->GetHWnd());
|
SetForegroundWindow(pSysTray->GetHWnd());
|
||||||
|
GetCursorPos(&pt);
|
||||||
|
|
||||||
DWORD id = TrackPopupMenuEx(hPopup, flags,
|
DWORD id = TrackPopupMenuEx(hPopup, flags,
|
||||||
GET_X_LPARAM(msgPos), GET_Y_LPARAM(msgPos),
|
pt.x, pt.y,
|
||||||
pSysTray->GetHWnd(), NULL);
|
pSysTray->GetHWnd(), NULL);
|
||||||
|
|
||||||
DestroyMenu(hPopup);
|
DestroyMenu(hPopup);
|
||||||
|
|
Loading…
Reference in a new issue