[EXPLORER-NEW]
[reactos.git] / base / shell / explorer-new / trayntfy.c
index 2f156d4..49d4687 100644 (file)
@@ -44,6 +44,13 @@ typedef struct _SYS_PAGER_DATA
     INT VisibleButtonCount;
 } SYS_PAGER_WND_DATA, *PSYS_PAGER_WND_DATA;
 
+// Data comes from shell32/systray.cpp -> TrayNotifyCDS_Dummy
+typedef struct _SYS_PAGER_COPY_DATA
+{
+    DWORD           cookie;
+    DWORD           notify_code;
+    NOTIFYICONDATA  nicon_data;
+} SYS_PAGER_COPY_DATA, *PSYS_PAGER_COPY_DATA;
 
 static PNOTIFY_ITEM
 SysPagerWnd_CreateNotifyItemData(IN OUT PSYS_PAGER_WND_DATA This)
@@ -110,7 +117,7 @@ static VOID
 SysPagerWnd_UpdateButton(IN OUT PSYS_PAGER_WND_DATA This,
                          IN CONST NOTIFYICONDATA *iconData)
 {
-    TBBUTTONINFO tbbi;
+    TBBUTTONINFO tbbi = {0};
     PNOTIFY_ITEM notifyItem;
     PPNOTIFY_ITEM NotifyPointer;
 
@@ -132,7 +139,10 @@ SysPagerWnd_UpdateButton(IN OUT PSYS_PAGER_WND_DATA This,
         notifyItem->IconIndex = tbbi.iImage = ImageList_AddIcon(This->SysIcons, iconData->hIcon);
     }
 
-    /* TODO: support NIF_TIP */
+    if (iconData->uFlags & NIF_TIP)
+    {
+        StringCchCopy(notifyItem->iconData.szTip, _countof(notifyItem->iconData.szTip), iconData->szTip);
+    }
 
     if (iconData->uFlags & NIF_STATE)
     {
@@ -343,10 +353,10 @@ SysPagerWnd_ToolbarSubclassedProc(IN HWND hWnd,
     {
         HWND parent = GetParent(hWnd);
 
-        if (!parent)
-            return 0;
-
-        return SendMessage(parent, msg, wParam, lParam);
+        if (parent)
+        {
+            SendMessage(parent, msg, wParam, lParam);
+        }
     }
 
     return DefSubclassProc(hWnd, msg, wParam, lParam);
@@ -355,13 +365,16 @@ SysPagerWnd_ToolbarSubclassedProc(IN HWND hWnd,
 static VOID
 SysPagerWnd_Create(IN OUT PSYS_PAGER_WND_DATA This)
 {
-    This->hWndToolbar = CreateWindowEx(0,
+    DWORD styles = 
+        WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN |
+        TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | TBSTYLE_TRANSPARENT |
+        CCS_TOP | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER;
+    DWORD exStyles = WS_EX_TOOLWINDOW;
+
+    This->hWndToolbar = CreateWindowEx(exStyles,
                                        TOOLBARCLASSNAME,
                                        NULL,
-                                       WS_CHILD | WS_VISIBLE  | WS_CLIPCHILDREN |
-                                           TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE |
-                                           TBSTYLE_TRANSPARENT |
-                                           CCS_TOP | CCS_NORESIZE | CCS_NODIVIDER,
+                                       styles,
                                        0,
                                        0,
                                        0,
@@ -418,7 +431,7 @@ SysPagerWnd_NotifyMsg(IN HWND hwnd,
     PCOPYDATASTRUCT cpData = (PCOPYDATASTRUCT)lParam;
     if (cpData->dwData == 1)
     {
-        DWORD trayCommand;
+        SYS_PAGER_COPY_DATA * data;
         NOTIFYICONDATA *iconData;
         HWND parentHWND;
         RECT windowRect;
@@ -426,15 +439,15 @@ SysPagerWnd_NotifyMsg(IN HWND hwnd,
         parentHWND = GetParent(parentHWND);
         GetClientRect(parentHWND, &windowRect);
 
-        /* FIXME: ever heard of "struct"? */
-        trayCommand = *(DWORD *) (((BYTE *)cpData->lpData) + 4);
-        iconData = (NOTIFYICONDATA *) (((BYTE *)cpData->lpData) + 8);
+        data = (PSYS_PAGER_COPY_DATA) cpData->lpData;
+        iconData = &data->nicon_data;
 
-        switch (trayCommand)
+        switch (data->notify_code)
         {
             case NIM_ADD:
             {
                 PPNOTIFY_ITEM NotifyPointer;
+
                 NotifyPointer = SysPagerWnd_FindPPNotifyItemByIconData(This,
                                                                        iconData);
                 if (!NotifyPointer)
@@ -446,6 +459,7 @@ SysPagerWnd_NotifyMsg(IN HWND hwnd,
             case NIM_MODIFY:
             {
                 PPNOTIFY_ITEM NotifyPointer;
+
                 NotifyPointer = SysPagerWnd_FindPPNotifyItemByIconData(This,
                                                                        iconData);
                 if (!NotifyPointer)
@@ -463,6 +477,9 @@ SysPagerWnd_NotifyMsg(IN HWND hwnd,
                 SysPagerWnd_RemoveButton(This, iconData);
                 break;
             }
+            default:
+                TRACE("NotifyMessage received with unknown code %d.\n", data->notify_code);
+                break;
         }
         SendMessage(parentHWND,
                     WM_SIZE,
@@ -527,8 +544,11 @@ SysPagerWndProc(IN HWND hwnd,
         switch (uMsg)
         {
             case WM_ERASEBKGND:
-                SysPagerWnd_DrawBackground(hwnd,(HDC)wParam);
-                return 0;
+                if (!IsAppThemed())
+                    break;
+
+                SysPagerWnd_DrawBackground(hwnd, (HDC) wParam);
+                return TRUE;
 
             case WM_NCCREATE:
             {
@@ -539,9 +559,7 @@ SysPagerWndProc(IN HWND hwnd,
                 This->ButtonCount = 0;
                 This->VisibleButtonCount = 0;
 
-                SetWindowLongPtr(hwnd,
-                                 0,
-                                 (LONG_PTR)This);
+                SetWindowLongPtr(hwnd, 0, (LONG_PTR) This);
 
                 return TRUE;
             }
@@ -552,28 +570,49 @@ SysPagerWndProc(IN HWND hwnd,
                 SysPagerWnd_NCDestroy(This);
                 break;
 
+            case WM_NOTIFY:
+            {
+                const NMHDR * nmh = (const NMHDR *) lParam;
+                if (nmh->code == TBN_GETINFOTIPW)
+                {
+                    NMTBGETINFOTIP * nmtip = (NMTBGETINFOTIP *) lParam;
+                    PPNOTIFY_ITEM ptr = SysPagerWnd_FindPPNotifyItemByIndex(This, nmtip->iItem);
+                    if (ptr)
+                    {
+                        PNOTIFY_ITEM item = *ptr;
+                        StringCchCopy(nmtip->pszText, nmtip->cchTextMax, item->iconData.szTip);
+                    }
+                }
+                else if (nmh->code == NM_CUSTOMDRAW)
+                {
+                    NMCUSTOMDRAW * cdraw = (NMCUSTOMDRAW *) lParam;
+                    switch (cdraw->dwDrawStage)
+                    {
+                    case CDDS_PREPAINT:
+                        return CDRF_NOTIFYITEMDRAW;
+
+                    case CDDS_ITEMPREPAINT:
+                        return TBCDRF_NOBACKGROUND | TBCDRF_NOEDGES | TBCDRF_NOOFFSET | TBCDRF_NOMARK | TBCDRF_NOETCHEDEFFECT;
+                    }
+                }
+
+                break;
+            }
+
             case WM_SIZE:
             {
                 SIZE szClient;
                 szClient.cx = LOWORD(lParam);
                 szClient.cy = HIWORD(lParam);
 
-                Ret = DefWindowProc(hwnd,
-                                    uMsg,
-                                    wParam,
-                                    lParam);
-
+                Ret = DefWindowProc(hwnd, uMsg, wParam, lParam);
 
                 if (This->hWndToolbar != NULL && This->hWndToolbar != hwnd)
                 {
-                    SetWindowPos(This->hWndToolbar,
-                                 NULL,
-                                 0,
-                                 0,
-                                 szClient.cx,
-                                 szClient.cy,
-                                 SWP_NOZORDER);
+                    SetWindowPos(This->hWndToolbar, NULL, 0, 0, szClient.cx, szClient.cy, SWP_NOZORDER);
                 }
+
+                return Ret;
             }
 
             default:
@@ -598,15 +637,11 @@ SysPagerWndProc(IN HWND hwnd,
                     return 0;
                 }
 
-                Ret = DefWindowProc(hwnd,
-                                    uMsg,
-                                    wParam,
-                                    lParam);
                 break;
         }
     }
 
-    return Ret;
+    return DefWindowProc(hwnd, uMsg, wParam, lParam);
 }
 
 static HWND
@@ -1211,7 +1246,6 @@ TrayClockWndProc(IN HWND hwnd,
                  IN LPARAM lParam)
 {
     PTRAY_CLOCK_WND_DATA This = NULL;
-    LRESULT Ret = FALSE;
 
     if (uMsg != WM_NCCREATE)
     {
@@ -1227,8 +1261,11 @@ TrayClockWndProc(IN HWND hwnd,
                 TrayClockWnd_UpdateTheme(This);
                 break;
             case WM_ERASEBKGND:
-                TrayClockWnd_DrawBackground(hwnd, (HDC)wParam);
-                break;
+                if (!IsAppThemed())
+                    break;
+
+                TrayClockWnd_DrawBackground(hwnd, (HDC) wParam);
+                return TRUE;
             case WM_PAINT:
             case WM_PRINTCLIENT:
             {
@@ -1237,19 +1274,16 @@ TrayClockWndProc(IN HWND hwnd,
 
                 if (wParam == 0)
                 {
-                    hDC = BeginPaint(This->hWnd,
-                                     &ps);
+                    hDC = BeginPaint(This->hWnd, &ps);
                 }
 
                 if (hDC != NULL)
                 {
-                    TrayClockWnd_Paint(This,
-                                       hDC);
+                    TrayClockWnd_Paint(This, hDC);
 
                     if (wParam == 0)
                     {
-                        EndPaint(This->hWnd,
-                                 &ps);
+                        EndPaint(This->hWnd, &ps);
                     }
                 }
                 break;
@@ -1270,23 +1304,18 @@ TrayClockWndProc(IN HWND hwnd,
 
             case WM_NCHITTEST:
                 /* We want the user to be able to drag the task bar when clicking the clock */
-                Ret = HTTRANSPARENT;
-                break;
+                return HTTRANSPARENT;
 
             case TCWM_GETMINIMUMSIZE:
             {
                 This->IsHorizontal = (BOOL)wParam;
 
-                Ret = (LRESULT)TrayClockWnd_GetMinimumSize(This,
-                                                           (BOOL)wParam,
-                                                           (PSIZE)lParam) != 0;
-                break;
+                return (LRESULT) TrayClockWnd_GetMinimumSize(This, (BOOL) wParam, (PSIZE) lParam) != 0;
             }
 
             case TCWM_UPDATETIME:
             {
-                Ret = (LRESULT)TrayClockWnd_ResetTime(This);
-                break;
+                return (LRESULT)TrayClockWnd_ResetTime(This);
             }
 
             case WM_NCCREATE:
@@ -1296,9 +1325,7 @@ TrayClockWndProc(IN HWND hwnd,
                 This->hWnd = hwnd;
                 This->hWndNotify = CreateStruct->hwndParent;
 
-                SetWindowLongPtr(hwnd,
-                                 0,
-                                 (LONG_PTR)This);
+                SetWindowLongPtr(hwnd, 0, (LONG_PTR) This);
                 TrayClockWnd_UpdateTheme(This);
 
                 return TRUE;
@@ -1336,17 +1363,10 @@ TrayClockWndProc(IN HWND hwnd,
                                TRUE);
                 break;
             }
-
-            default:
-                Ret = DefWindowProc(hwnd,
-                                    uMsg,
-                                    wParam,
-                                    lParam);
-                break;
         }
     }
 
-    return Ret;
+    return DefWindowProc(hwnd, uMsg, wParam, lParam);
 }
 
 static HWND
@@ -1651,22 +1671,17 @@ TrayNotifyWnd_Size(IN OUT PTRAY_NOTIFY_WND_DATA This,
     }
 }
 
-static LRESULT
+static VOID
 TrayNotifyWnd_DrawBackground(IN HWND hwnd,
-                             IN UINT uMsg,
-                             IN WPARAM wParam,
-                             IN LPARAM lParam)
+                             IN HDC hdc)
 {
     PTRAY_NOTIFY_WND_DATA This = (PTRAY_NOTIFY_WND_DATA)GetWindowLongPtr(hwnd, 0);
     RECT rect;
-    HDC hdc = (HDC)wParam;
 
     GetClientRect(hwnd, &rect);
 
     DrawThemeParentBackground(hwnd, hdc, &rect);
     DrawThemeBackground(This->TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0);
-
-    return 0;
 }
 
 VOID
@@ -1683,6 +1698,17 @@ TrayNotify_NotifyMsg(IN HWND hwnd,
     }
 }
 
+BOOL
+TrayNotify_GetClockRect(IN HWND hwnd,
+                        OUT PRECT rcClock)
+{
+    PTRAY_NOTIFY_WND_DATA This = (PTRAY_NOTIFY_WND_DATA)GetWindowLongPtr(hwnd, 0);
+    if (!IsWindowVisible(This->hWndTrayClock))
+        return FALSE;
+
+    return GetWindowRect(This->hWndTrayClock, rcClock);
+}
+
 static LRESULT CALLBACK
 TrayNotifyWndProc(IN HWND hwnd,
                   IN UINT uMsg,
@@ -1690,12 +1716,10 @@ TrayNotifyWndProc(IN HWND hwnd,
                   IN LPARAM lParam)
 {
     PTRAY_NOTIFY_WND_DATA This = NULL;
-    LRESULT Ret = FALSE;
 
     if (uMsg != WM_NCCREATE)
     {
-        This = (PTRAY_NOTIFY_WND_DATA)GetWindowLongPtr(hwnd,
-                                                       0);
+        This = (PTRAY_NOTIFY_WND_DATA)GetWindowLongPtr(hwnd, 0);
     }
 
     if (This != NULL || uMsg == WM_NCCREATE)
@@ -1706,16 +1730,13 @@ TrayNotifyWndProc(IN HWND hwnd,
                 TrayNotifyWnd_UpdateTheme(This);
                 return 0;
             case WM_ERASEBKGND:
-                return TrayNotifyWnd_DrawBackground(hwnd,
-                                                    uMsg,
-                                                    wParam,
-                                                    lParam);
+                if (!This->TrayTheme)
+                    break;
+                TrayNotifyWnd_DrawBackground(hwnd, (HDC) wParam);
+                return 0;
             case TNWM_GETMINIMUMSIZE:
             {
-                Ret = (LRESULT)TrayNotifyWnd_GetMinimumSize(This,
-                                                            (BOOL)wParam,
-                                                            (PSIZE)lParam);
-                break;
+                return (LRESULT) TrayNotifyWnd_GetMinimumSize(This, (BOOL) wParam, (PSIZE) lParam);
             }
 
             case TNWM_UPDATETIME:
@@ -1723,12 +1744,9 @@ TrayNotifyWndProc(IN HWND hwnd,
                 if (This->hWndTrayClock != NULL)
                 {
                     /* Forward the message to the tray clock window procedure */
-                    Ret = TrayClockWndProc(This->hWndTrayClock,
-                                           TCWM_UPDATETIME,
-                                           wParam,
-                                           lParam);
+                    return TrayClockWndProc(This->hWndTrayClock, TCWM_UPDATETIME, wParam, lParam);
                 }
-                break;
+                return 0;
             }
 
             case WM_SIZE:
@@ -1738,17 +1756,14 @@ TrayNotifyWndProc(IN HWND hwnd,
                 szClient.cx = LOWORD(lParam);
                 szClient.cy = HIWORD(lParam);
 
-                TrayNotifyWnd_Size(This,
-                                   &szClient);
-                break;
+                TrayNotifyWnd_Size(This, &szClient);
+                return 0;
             }
 
             case WM_NCHITTEST:
                 /* We want the user to be able to drag the task bar when clicking the
                    tray notification window */
-                Ret = HTTRANSPARENT;
-                break;
-
+                return HTTRANSPARENT;
             case TNWM_SHOWCLOCK:
             {
                 BOOL PrevHidden = This->HideClock;
@@ -1760,8 +1775,7 @@ TrayNotifyWndProc(IN HWND hwnd,
                                This->HideClock ? SW_HIDE : SW_SHOW);
                 }
 
-                Ret = (LRESULT)(!PrevHidden);
-                break;
+                return (LRESULT) (!PrevHidden);
             }
 
             case WM_NOTIFY:
@@ -1771,12 +1785,9 @@ TrayNotifyWndProc(IN HWND hwnd,
                 if (nmh->hwndFrom == This->hWndTrayClock)
                 {
                     /* Pass down notifications */
-                    Ret = SendMessage(This->hWndNotify,
-                                      WM_NOTIFY,
-                                      wParam,
-                                      lParam);
+                    return SendMessage(This->hWndNotify, WM_NOTIFY, wParam, lParam);
                 }
-                break;
+                return 0;
             }
 
             case WM_SETFONT:
@@ -1788,7 +1799,7 @@ TrayNotifyWndProc(IN HWND hwnd,
                                 wParam,
                                 lParam);
                 }
-                goto HandleDefaultMessage;
+                break;
             }
 
             case WM_NCCREATE:
@@ -1798,32 +1809,22 @@ TrayNotifyWndProc(IN HWND hwnd,
                 This->hWnd = hwnd;
                 This->hWndNotify = CreateStruct->hwndParent;
 
-                SetWindowLongPtr(hwnd,
-                                 0,
-                                 (LONG_PTR)This);
+                SetWindowLongPtr(hwnd, 0, (LONG_PTR) This);
 
                 return TRUE;
             }
 
             case WM_CREATE:
                 TrayNotifyWnd_Create(This);
-                break;
+                return 0;
 
             case WM_NCDESTROY:
                 TrayNotifyWnd_NCDestroy(This);
-                break;
-
-            default:
-HandleDefaultMessage:
-                Ret = DefWindowProc(hwnd,
-                                    uMsg,
-                                    wParam,
-                                    lParam);
-                break;
+                return 0;
         }
     }
 
-    return Ret;
+    return DefWindowProc(hwnd, uMsg, wParam, lParam);
 }
 
 HWND