[EXPLORER] Add missing 'break' statements. Spotted by mudhead. CORE-14518
[reactos.git] / base / shell / explorer / syspager.cpp
index 32d4b45..5340ba4 100644 (file)
@@ -78,6 +78,8 @@ private:
     static UINT WINAPI WatcherThread(_In_opt_ LPVOID lpParam);
 };
 
+class CNotifyToolbar;
+
 class CBalloonQueue
 {
 public:
@@ -114,7 +116,7 @@ private:
 
     CAtlList<Info> m_queue;
 
-    CToolbar<InternalIconData> * m_toolbar;
+    CNotifyToolbar * m_toolbar;
 
     InternalIconData * m_current;
     bool m_currentClosed;
@@ -124,7 +126,7 @@ private:
 public:
     CBalloonQueue();
 
-    void Init(HWND hwndParent, CToolbar<InternalIconData> * toolbar, CTooltips * balloons);
+    void Init(HWND hwndParent, CNotifyToolbar * toolbar, CTooltips * balloons);
     void Deinit();
 
     bool OnTimer(int timerId);
@@ -137,7 +139,7 @@ private:
     int IndexOf(InternalIconData * pdata);
     void SetTimer(int length);
     void Show(Info& info);
-    void Close(IN OUT InternalIconData * notifyItem);
+    void Close(IN OUT InternalIconData * notifyItem, IN UINT uReason);
 };
 
 class CNotifyToolbar :
@@ -160,6 +162,7 @@ public:
     BOOL UpdateButton(IN CONST NOTIFYICONDATA *iconData);
     BOOL RemoveButton(IN CONST NOTIFYICONDATA *iconData);
     VOID ResizeImagelist();
+    bool SendNotifyCallback(InternalIconData* notifyItem, UINT uMsg);
 
 private:
     VOID SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wParam);
@@ -329,7 +332,7 @@ bool CIconWatcher::AddIconToWatcher(_In_ CONST NOTIFYICONDATA *iconData)
 
     IconWatcherData *Icon = new IconWatcherData(iconData);
     Icon->hProcess = hProcess;
-    Icon->ProcessId;
+    Icon->ProcessId = ProcessId;
 
     bool Added = false;
     EnterCriticalSection(&m_ListLock);
@@ -410,7 +413,7 @@ UINT WINAPI CIconWatcher::WatcherThread(_In_opt_ LPVOID lpParam)
         ASSERT(Size <= MAXIMUM_WAIT_OBJECTS);
 
         if (WatchList)
-            delete WatchList;
+            delete[] WatchList;
         WatchList = new HANDLE[Size];
         WatchList[0] = This->m_WakeUpEvent;
 
@@ -476,7 +479,7 @@ UINT WINAPI CIconWatcher::WatcherThread(_In_opt_ LPVOID lpParam)
     }
 
     if (WatchList)
-        delete WatchList;
+        delete[] WatchList;
 
     return 0;
 }
@@ -495,7 +498,7 @@ CBalloonQueue::CBalloonQueue() :
 {
 }
 
-void CBalloonQueue::Init(HWND hwndParent, CToolbar<InternalIconData> * toolbar, CTooltips * balloons)
+void CBalloonQueue::Init(HWND hwndParent, CNotifyToolbar * toolbar, CTooltips * balloons)
 {
     m_hwndParent = hwndParent;
     m_toolbar = toolbar;
@@ -520,7 +523,7 @@ bool CBalloonQueue::OnTimer(int timerId)
 
     if (m_current && !m_currentClosed)
     {
-        Close(m_current);
+        Close(m_current, NIN_BALLOONTIMEOUT);
     }
     else
     {
@@ -556,13 +559,13 @@ void CBalloonQueue::UpdateInfo(InternalIconData * notifyItem)
     }
     else
     {
-        Close(notifyItem);
+        Close(notifyItem, NIN_BALLOONHIDE);
     }
 }
 
 void CBalloonQueue::RemoveInfo(InternalIconData * notifyItem)
 {
-    Close(notifyItem);
+    Close(notifyItem, NIN_BALLOONHIDE);
 
     POSITION position = m_queue.GetHeadPosition();
     while(position != NULL)
@@ -578,7 +581,9 @@ void CBalloonQueue::RemoveInfo(InternalIconData * notifyItem)
 void CBalloonQueue::CloseCurrent()
 {
     if (m_current != NULL)
-        Close(m_current);
+    {
+        Close(m_current, NIN_BALLOONTIMEOUT);
+    }
 }
 
 int CBalloonQueue::IndexOf(InternalIconData * pdata)
@@ -621,14 +626,18 @@ void CBalloonQueue::Show(Info& info)
     if (timeout > MaxTimeout) timeout = MaxTimeout;
 
     SetTimer(timeout);
+
+    m_toolbar->SendNotifyCallback(m_current, NIN_BALLOONSHOW);
 }
 
-void CBalloonQueue::Close(IN OUT InternalIconData * notifyItem)
+void CBalloonQueue::Close(IN OUT InternalIconData * notifyItem, IN UINT uReason)
 {
     TRACE("HideBalloonTip called\n");
 
     if (m_current == notifyItem && !m_currentClosed)
     {
+        m_toolbar->SendNotifyCallback(m_current, uReason);
+
         // Prevent Re-entry
         m_currentClosed = true;
         m_tooltips->TrackDeactivate();
@@ -695,7 +704,7 @@ int CNotifyToolbar::FindExistingSharedIcon(HICON handle)
 
 BOOL CNotifyToolbar::AddButton(_In_ CONST NOTIFYICONDATA *iconData)
 {
-    TBBUTTON tbBtn;
+    TBBUTTON tbBtn = { 0 };
     InternalIconData * notifyItem;
     WCHAR text[] = L"";
 
@@ -1006,27 +1015,8 @@ VOID CNotifyToolbar::ResizeImagelist()
     SetButtonSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
 }
 
-VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wParam)
+bool CNotifyToolbar::SendNotifyCallback(InternalIconData* notifyItem, UINT uMsg)
 {
-    static LPCWSTR eventNames [] = {
-        L"WM_MOUSEMOVE",
-        L"WM_LBUTTONDOWN",
-        L"WM_LBUTTONUP",
-        L"WM_LBUTTONDBLCLK",
-        L"WM_RBUTTONDOWN",
-        L"WM_RBUTTONUP",
-        L"WM_RBUTTONDBLCLK",
-        L"WM_MBUTTONDOWN",
-        L"WM_MBUTTONUP",
-        L"WM_MBUTTONDBLCLK",
-        L"WM_MOUSEWHEEL",
-        L"WM_XBUTTONDOWN",
-        L"WM_XBUTTONUP",
-        L"WM_XBUTTONDBLCLK"
-    };
-
-    InternalIconData * notifyItem = GetItemData(wIndex);
-
     if (!::IsWindow(notifyItem->hWnd))
     {
         // We detect and destroy icons with invalid handles only on mouse move over systray, same as MS does.
@@ -1039,14 +1029,7 @@ VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wPar
         NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN};
         GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh);
 
-        return;
-    }
-
-    if (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST)
-    {
-        TRACE("Sending message %S from button %d to %p (msg=%x, w=%x, l=%x)...\n",
-                    eventNames[uMsg - WM_MOUSEFIRST], wIndex,
-                    notifyItem->hWnd, notifyItem->uCallbackMessage, notifyItem->uID, uMsg);
+        return true;
     }
 
     DWORD pid;
@@ -1056,9 +1039,9 @@ VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wPar
         (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST))
     {
         ::PostMessage(notifyItem->hWnd,
-                        notifyItem->uCallbackMessage,
-                        notifyItem->uID,
-                        uMsg);
+                      notifyItem->uCallbackMessage,
+                      notifyItem->uID,
+                      uMsg);
     }
     else
     {
@@ -1067,6 +1050,38 @@ VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wPar
                     notifyItem->uID,
                     uMsg);
     }
+    return false;
+}
+
+VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wParam)
+{
+    static LPCWSTR eventNames [] = {
+        L"WM_MOUSEMOVE",
+        L"WM_LBUTTONDOWN",
+        L"WM_LBUTTONUP",
+        L"WM_LBUTTONDBLCLK",
+        L"WM_RBUTTONDOWN",
+        L"WM_RBUTTONUP",
+        L"WM_RBUTTONDBLCLK",
+        L"WM_MBUTTONDOWN",
+        L"WM_MBUTTONUP",
+        L"WM_MBUTTONDBLCLK",
+        L"WM_MOUSEWHEEL",
+        L"WM_XBUTTONDOWN",
+        L"WM_XBUTTONUP",
+        L"WM_XBUTTONDBLCLK"
+    };
+
+    InternalIconData * notifyItem = GetItemData(wIndex);
+
+    if (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST)
+    {
+        TRACE("Sending message %S from button %d to %p (msg=%x, w=%x, l=%x)...\n",
+            eventNames[uMsg - WM_MOUSEFIRST], wIndex,
+            notifyItem->hWnd, notifyItem->uCallbackMessage, notifyItem->uID, uMsg);
+    }
+
+    SendNotifyCallback(notifyItem, uMsg);
 }
 
 LRESULT CNotifyToolbar::OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -1192,6 +1207,7 @@ void CNotifyToolbar::Initialize(HWND hWndParent, CBalloonQueue * queue)
 const WCHAR szSysPagerWndClass[] = L"SysPager";
 
 CSysPagerWnd::CSysPagerWnd() {}
+
 CSysPagerWnd::~CSysPagerWnd() {}
 
 LRESULT CSysPagerWnd::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -1267,9 +1283,11 @@ BOOL CSysPagerWnd::NotifyIcon(DWORD dwMessage, _In_ CONST NOTIFYICONDATA *iconDa
             (void)AddIconToWatcher(iconData);
         }
         break;
+
     case NIM_MODIFY:
         ret = Toolbar.UpdateButton(iconData);
         break;
+
     case NIM_DELETE:
         ret = Toolbar.RemoveButton(iconData);
         if (ret == TRUE)
@@ -1277,11 +1295,16 @@ BOOL CSysPagerWnd::NotifyIcon(DWORD dwMessage, _In_ CONST NOTIFYICONDATA *iconDa
             (void)RemoveIconFromWatcher(iconData);
         }
         break;
+
     case NIM_SETFOCUS:
         Toolbar.SetFocus();
         ret = TRUE;
+        break;
+
     case NIM_SETVERSION:
         ret = Toolbar.SwitchVersion(iconData);
+        break;
+
     default:
         TRACE("NotifyIcon received with unknown code %d.\n", dwMessage);
         return FALSE;