Author: ssawant
Date: Tue Jul 25 21:48:51 2017
New Revision: 75405

URL: http://svn.reactos.org/svn/reactos?rev=75405&view=rev
Log:
[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.

Modified:
    branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/lang/en-US.rc
    branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/power.cpp
    branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/stobject.rc
    branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/volume.cpp

Modified: 
branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/lang/en-US.rc
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/lang/en-US.rc?rev=75405&r1=75404&r2=75405&view=diff
==============================================================================
--- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/lang/en-US.rc     
[iso-8859-1] (original)
+++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/lang/en-US.rc     
[iso-8859-1] Tue Jul 25 21:48:51 2017
@@ -17,8 +17,8 @@
     //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"

Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/power.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/power.cpp?rev=75405&r1=75404&r2=75405&view=diff
==============================================================================
--- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/power.cpp 
[iso-8859-1] (original)
+++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/power.cpp 
[iso-8859-1] Tue Jul 25 21:48:51 2017
@@ -18,12 +18,10 @@
 
 #include <mmsystem.h>
 #include <mmddk.h>
+#include <atlstr.h>
 
 #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);
 
@@ -37,10 +35,9 @@
     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 @@
         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");    
-
+{ 
+    TRACE("Power_Init\n");
+    g_hIconBattery = DynamicLoadIcon(g_hInstance);
+    g_IsRunning = TRUE;
+    
+    return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_POWER, g_hIconBattery, 
g_strTooltip);
+}
+
+HRESULT STDMETHODCALLTYPE Power_Update(_In_ CSysTray * pSysTray)
+{
+    TRACE("Power_Update\n");    
     g_hIconBattery = DynamicLoadIcon(g_hInstance);    
-    swprintf(strTooltip, L"%.2f %% Remaining", g_batCap);    
-    g_IsRunning = TRUE;
-
-    return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_POWER, g_hIconBattery, 
strTooltip);
-}
-
-HRESULT STDMETHODCALLTYPE Power_Update(_In_ CSysTray * pSysTray)
-{
-    TRACE("Power_Update\n");
-
-    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 _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);
-
+    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;
-    DWORD msgPos = GetMessagePos();
-
-    SetForegroundWindow(pSysTray->GetHWnd());
+    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 @@
             _RunPower();
             break;
     }
+    DestroyMenu(hPopup);
 }
 
 static
@@ -287,8 +292,8 @@
 {
     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 @@
                            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 @@
                     break;
 
                 case WM_RBUTTONUP:
-                    _ShowContextMenu(pSysTray);
+                    _ShowContextMenu(pSysTray);                    
                     break;
 
                 case WM_RBUTTONDBLCLK:

Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/stobject.rc
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/stobject.rc?rev=75405&r1=75404&r2=75405&view=diff
==============================================================================
--- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/stobject.rc       
[iso-8859-1] (original)
+++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/stobject.rc       
[iso-8859-1] Tue Jul 25 21:48:51 2017
@@ -31,7 +31,7 @@
 #include <reactos/manifest_dll.rc>
 
 // Strings common to all languages
-STRINGTABLE
+/*STRINGTABLE
 BEGIN
     // Power related strings
     IDS_PWR_RUN         "shell32.dll,Control_RunDLL PowerCfg.cpl"
@@ -41,7 +41,7 @@
 
     // Volume related strings
     IDS_VOL_RUN         "SNDVOL32.EXE"
-END
+END*/
 
 /* UTF-8 */
 #pragma code_page(65001)

Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/volume.cpp
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/volume.cpp?rev=75405&r1=75404&r2=75405&view=diff
==============================================================================
--- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/volume.cpp        
[iso-8859-1] (original)
+++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/volume.cpp        
[iso-8859-1] Tue Jul 25 21:48:51 2017
@@ -243,11 +243,12 @@
     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);


Reply via email to