[EXPLORER-NEW]
authorDavid Quintana <gigaherz@gmail.com>
Mon, 3 Nov 2014 04:16:56 +0000 (04:16 +0000)
committerDavid Quintana <gigaherz@gmail.com>
Mon, 3 Nov 2014 04:16:56 +0000 (04:16 +0000)
* Rename a few I<x>Impl to C<x>
* Refactor the toolbar code of notification area into its own class.
* Also refactor away the code specific to the toolbar control into a CToolbar class. Todo: move the CToolbar class into some header file.

svn path=/branches/shell-experiments/; revision=65209

base/shell/explorer-new/taskband.cpp
base/shell/explorer-new/tbsite.cpp
base/shell/explorer-new/trayntfy.cpp
base/shell/explorer-new/traywnd.cpp

index 3c0df86..91228b2 100644 (file)
@@ -26,8 +26,8 @@
 
 const GUID CLSID_ITaskBand = { 0x68284FAA, 0x6A48, 0x11D0, { 0x8C, 0x78, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0xB4 } };
 
-class ITaskBandImpl :
-    public CComCoClass<ITaskBandImpl>,
+class CTaskBand :
+    public CComCoClass<CTaskBand>,
     public CComObjectRootEx<CComMultiThreadModelNoCS>,
     public IObjectWithSite,
     public ITaskBand,
@@ -44,14 +44,14 @@ class ITaskBandImpl :
     DWORD dwBandID;
 
 public:
-    ITaskBandImpl() :
+    CTaskBand() :
         hWnd(NULL),
         dwBandID(0)
     {
 
     }
 
-    virtual ~ITaskBandImpl() { }
+    virtual ~CTaskBand() { }
 
     virtual HRESULT STDMETHODCALLTYPE GetRebarBandID(
         OUT DWORD *pdwBandID)
@@ -386,10 +386,10 @@ public:
         return S_OK;
     }
 
-    DECLARE_NOT_AGGREGATABLE(ITaskBandImpl)
+    DECLARE_NOT_AGGREGATABLE(CTaskBand)
 
     DECLARE_PROTECT_FINAL_CONSTRUCT()
-    BEGIN_COM_MAP(ITaskBandImpl)
+    BEGIN_COM_MAP(CTaskBand)
         COM_INTERFACE_ENTRY2_IID(IID_IOleWindow, IOleWindow, IDeskBand)
         COM_INTERFACE_ENTRY_IID(IID_IDeskBand, IDeskBand)
         COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
@@ -404,7 +404,7 @@ ITaskBand * CreateTaskBand(IN OUT ITrayWindow *Tray)
 {
     HRESULT hr;
 
-    ITaskBandImpl * tb = new CComObject<ITaskBandImpl>();
+    CTaskBand * tb = new CComObject<CTaskBand>();
 
     if (!tb)
         return NULL;
index b75e343..98ab1cf 100644 (file)
@@ -30,7 +30,7 @@
 
 // WARNING: Can't use ATL for this class due to our ATL not fully supporting the AGGREGATION functions needed for this class to be an "outer" class
 // it works just fine this way.
-class ITrayBandSiteImpl :
+class CTrayBandSite :
     public ITrayBandSite,
     public IBandSite,
     public IBandSiteStreamCallback
@@ -109,13 +109,13 @@ public:
     }
 
 public:
-    ITrayBandSiteImpl() :
+    CTrayBandSite() :
         m_RefCount(0),
         hWndRebar(NULL)
     {
     }
 
-    virtual ~ITrayBandSiteImpl() { }
+    virtual ~CTrayBandSite() { }
 
     virtual HRESULT STDMETHODCALLTYPE OnLoad(
         IN OUT IStream *pStm,
@@ -816,7 +816,7 @@ OUT HWND *phWndTaskSwitch)
 {
     HRESULT hr;
 
-    ITrayBandSiteImpl * tb = new ITrayBandSiteImpl();
+    CTrayBandSite * tb = new CTrayBandSite();
 
     if (!tb)
         return NULL;
index 87b6902..189b46f 100644 (file)
@@ -28,14 +28,6 @@ typedef unsigned short USHORT;
  */
 static const WCHAR szSysPagerWndClass [] = TEXT("SysPager");
 
-typedef struct _NOTIFY_ITEM
-{
-    struct _NOTIFY_ITEM *next;
-    INT Index;
-    INT IconIndex;
-    NOTIFYICONDATA iconData;
-} NOTIFY_ITEM, *PNOTIFY_ITEM, **PPNOTIFY_ITEM;
-
 // Data comes from shell32/systray.cpp -> TrayNotifyCDS_Dummy
 typedef struct _SYS_PAGER_COPY_DATA
 {
@@ -44,235 +36,281 @@ typedef struct _SYS_PAGER_COPY_DATA
     NOTIFYICONDATA  nicon_data;
 } SYS_PAGER_COPY_DATA, *PSYS_PAGER_COPY_DATA;
 
-class CSysPagerWnd :
-    public CComObjectRootEx<CComMultiThreadModelNoCS>,
-    public CWindowImpl < CSysPagerWnd, CWindow, CControlWinTraits >
+template<typename TItemData>
+class CToolbar :
+    public CWindowImpl < CToolbar<TItemData>, CWindow, CControlWinTraits>
 {
-    CContainedWindow NotificationBar;
-
-    HWND hWndToolbar;
-    HIMAGELIST SysIcons;
-    PNOTIFY_ITEM NotifyItems;
-    INT ButtonCount;
-    INT VisibleButtonCount;
 
 public:
-    CSysPagerWnd() :
-        NotificationBar(this, 1),
-        hWndToolbar(NULL),
-        SysIcons(NULL),
-        NotifyItems(NULL),
-        ButtonCount(0),
-        VisibleButtonCount(0)
+    int GetItemCount()
     {
+        return SendMessage(TB_BUTTONCOUNT);
     }
-    virtual ~CSysPagerWnd() { }
 
-    PNOTIFY_ITEM CreateNotifyItemData()
+    DWORD GetButton(int index, TBBUTTON * btn)
     {
-        PNOTIFY_ITEM *findNotifyPointer = &NotifyItems;
-        PNOTIFY_ITEM notifyItem;
+        return SendMessage(TB_GETBUTTON, index, (LPARAM)btn);
+    }
 
-        notifyItem = (PNOTIFY_ITEM) HeapAlloc(hProcessHeap, HEAP_ZERO_MEMORY, sizeof(*notifyItem));
-        if (notifyItem == NULL)
-            return NULL;
+    DWORD AddButton(TBBUTTON * btn)
+    {
+        return SendMessage(TB_ADDBUTTONS, 1, (LPARAM) btn);
+    }
 
-        notifyItem->next = NULL;
+    DWORD AddButtons(int count, TBBUTTON * buttons)
+    {
+        return SendMessage(TB_ADDBUTTONS, count, (LPARAM) btn);
+    }
 
-        while (*findNotifyPointer != NULL)
-        {
-            findNotifyPointer = &(*findNotifyPointer)->next;
-        }
+    DWORD InsertButton(int insertAt, TBBUTTON * btn)
+    {
+        return SendMessage(TB_INSERTBUTTON, insertAt, (LPARAM) btn);
+    }
 
-        *findNotifyPointer = notifyItem;
+    DWORD MoveButton(int oldIndex, int newIndex)
+    {
+        return SendMessage(TB_MOVEBUTTON, oldIndex, newIndex);
+    }
 
-        return notifyItem;
+    DWORD DeleteButton(int index)
+    {
+        return SendMessage(TB_DELETEBUTTON, index, 0);
     }
 
-    PPNOTIFY_ITEM FindPPNotifyItemByIconData(IN CONST NOTIFYICONDATA *iconData)
+    DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
+    {
+        return SendMessage(TB_GETBUTTONINFO, cmdId, (LPARAM) info);
+    }
+    
+    DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
     {
-        PPNOTIFY_ITEM findNotifyPointer = &NotifyItems;
+        return SendMessage(TB_SETBUTTONINFO, cmdId, (LPARAM) info);
+    }
 
-        while (*findNotifyPointer != NULL)
-        {
-            if ((*findNotifyPointer)->iconData.hWnd == iconData->hWnd &&
-                (*findNotifyPointer)->iconData.uID == iconData->uID)
-            {
-                return findNotifyPointer;
-            }
-            findNotifyPointer = &(*findNotifyPointer)->next;
-        }
+public:
+    DWORD SetButtonSize(int w, int h)
+    {
+        return SendMessage(TB_SETBUTTONSIZE, 0, MAKELONG(w, h));
+    }
+
+public:
+    DWORD AutoSize()
+    {
+        return SendMessage(TB_AUTOSIZE);
+    }
+
+public:
+    TItemData * GetItemData(int index)
+    {
+        TBBUTTON btn;
+        GetButton(index, &btn);
+        return (TItemData*) btn.dwData;
+    }
+
+    DWORD SetItemData(int index, TItemData * data)
+    {
+        TBBUTTONINFO info = { 0 };
+        info.cbSize = sizeof(info);
+        info.dwMask = TBIF_BYINDEX | TBIF_LPARAM;
+        info.lParam = (DWORD_PTR) data;
+        return SetButtonInfo(index, &info);
+    }
+};
+
+class CNotifyToolbar :
+    public CToolbar<NOTIFYICONDATA>
+{
+    const int ICON_SIZE = 16;
+
+    HIMAGELIST SysIcons;
+    int VisibleButtonCount;
 
-        return NULL;
+public:
+    CNotifyToolbar() :
+        SysIcons(NULL),
+        VisibleButtonCount(0)
+    {
+    }
+
+    ~CNotifyToolbar()
+    {
+    }
+
+    int GetVisibleItemCount()
+    {
+        return VisibleButtonCount;
     }
 
-    PPNOTIFY_ITEM FindPPNotifyItemByIndex(IN WORD wIndex)
+    int FindItemByIconData(IN CONST NOTIFYICONDATA *iconData, NOTIFYICONDATA ** pdata)
     {
-        PPNOTIFY_ITEM findNotifyPointer = &NotifyItems;
+        int count = GetItemCount();
 
-        while (*findNotifyPointer != NULL)
+        for (int i = 0; i < count; i++)
         {
-            if ((*findNotifyPointer)->Index == wIndex)
+            NOTIFYICONDATA * data;
+
+            data = GetItemData(i);
+
+            if (data->hWnd == iconData->hWnd &&
+                data->uID == iconData->uID)
             {
-                return findNotifyPointer;
+                if (pdata)
+                    *pdata = data;
+                return i;
             }
-            findNotifyPointer = &(*findNotifyPointer)->next;
         }
 
-        return NULL;
+        return -1;
     }
 
-    VOID UpdateButton(IN CONST NOTIFYICONDATA *iconData)
+    VOID AddButton(IN CONST NOTIFYICONDATA *iconData)
     {
-        TBBUTTONINFO tbbi = { 0 };
-        PNOTIFY_ITEM notifyItem;
-        PPNOTIFY_ITEM NotifyPointer;
+        TBBUTTON tbBtn;
+        NOTIFYICONDATA * notifyItem;
+        WCHAR text [] = TEXT("");
 
-        NotifyPointer = FindPPNotifyItemByIconData(iconData);
-        notifyItem = *NotifyPointer;
+        notifyItem = new NOTIFYICONDATA();
+        ZeroMemory(notifyItem, sizeof(*notifyItem));
 
-        tbbi.cbSize = sizeof(tbbi);
-        tbbi.dwMask = TBIF_BYINDEX | TBIF_COMMAND;
-        tbbi.idCommand = notifyItem->Index;
+        notifyItem->hWnd = iconData->hWnd;
+        notifyItem->uID = iconData->uID;
+
+        tbBtn.fsState = TBSTATE_ENABLED;
+        tbBtn.fsStyle = BTNS_NOPREFIX;
+        tbBtn.dwData = (DWORD_PTR)notifyItem;
+        tbBtn.iString = (INT_PTR) text;
+        tbBtn.idCommand = GetItemCount();
 
         if (iconData->uFlags & NIF_MESSAGE)
         {
-            notifyItem->iconData.uCallbackMessage = iconData->uCallbackMessage;
+            notifyItem->uCallbackMessage = iconData->uCallbackMessage;
         }
 
         if (iconData->uFlags & NIF_ICON)
         {
-            tbbi.dwMask |= TBIF_IMAGE;
-            notifyItem->IconIndex = tbbi.iImage = ImageList_AddIcon(SysIcons, iconData->hIcon);
+            tbBtn.iBitmap = ImageList_AddIcon(SysIcons, iconData->hIcon);
         }
 
         if (iconData->uFlags & NIF_TIP)
         {
-            StringCchCopy(notifyItem->iconData.szTip, _countof(notifyItem->iconData.szTip), iconData->szTip);
+            StringCchCopy(notifyItem->szTip, _countof(notifyItem->szTip), iconData->szTip);
         }
 
+        VisibleButtonCount++;
         if (iconData->uFlags & NIF_STATE)
         {
-            if (iconData->dwStateMask & NIS_HIDDEN &&
-                (notifyItem->iconData.dwState & NIS_HIDDEN) != (iconData->dwState & NIS_HIDDEN))
+            notifyItem->dwState &= ~iconData->dwStateMask;
+            notifyItem->dwState |= (iconData->dwState & iconData->dwStateMask);
+            if (notifyItem->dwState & NIS_HIDDEN)
             {
-                tbbi.dwMask |= TBIF_STATE;
-                if (iconData->dwState & NIS_HIDDEN)
-                {
-                    tbbi.fsState |= TBSTATE_HIDDEN;
-                    VisibleButtonCount--;
-                }
-                else
-                {
-                    tbbi.fsState &= ~TBSTATE_HIDDEN;
-                    VisibleButtonCount++;
-                }
+                tbBtn.fsState |= TBSTATE_HIDDEN;
+                VisibleButtonCount--;
             }
 
-            notifyItem->iconData.dwState &= ~iconData->dwStateMask;
-            notifyItem->iconData.dwState |= (iconData->dwState & iconData->dwStateMask);
         }
 
         /* TODO: support NIF_INFO, NIF_GUID, NIF_REALTIME, NIF_SHOWTIP */
 
-        NotificationBar.SendMessageW(TB_SETBUTTONINFO, (WPARAM) notifyItem->Index, (LPARAM) &tbbi);
+        CToolbar::AddButton(&tbBtn);
+        SetButtonSize(ICON_SIZE, ICON_SIZE);
     }
 
-    VOID AddButton(IN CONST NOTIFYICONDATA *iconData)
+    VOID UpdateButton(IN CONST NOTIFYICONDATA *iconData)
     {
-        TBBUTTON tbBtn;
-        PNOTIFY_ITEM notifyItem;
-        WCHAR text [] = TEXT("");
-
-        notifyItem = CreateNotifyItemData();
-
-        notifyItem->next = NULL;
-        notifyItem->Index = ButtonCount;
-        ButtonCount++;
-        VisibleButtonCount++;
+        NOTIFYICONDATA * notifyItem;
+        TBBUTTONINFO tbbi = { 0 };
 
-        notifyItem->iconData.hWnd = iconData->hWnd;
-        notifyItem->iconData.uID = iconData->uID;
+        int index = FindItemByIconData(iconData, &notifyItem);
+        if (index < 0)
+        {
+            AddButton(iconData);
+            return;
+        }
 
-        tbBtn.fsState = TBSTATE_ENABLED;
-        tbBtn.fsStyle = BTNS_NOPREFIX;
-        tbBtn.dwData = notifyItem->Index;
+        tbbi.cbSize = sizeof(tbbi);
+        tbbi.dwMask = TBIF_BYINDEX | TBIF_STATE;
+        GetButtonInfo(index, &tbbi);
 
-        tbBtn.iString = (INT_PTR) text;
-        tbBtn.idCommand = notifyItem->Index;
+        tbbi.dwMask = TBIF_BYINDEX | TBIF_COMMAND;
+        tbbi.idCommand = index;
 
         if (iconData->uFlags & NIF_MESSAGE)
         {
-            notifyItem->iconData.uCallbackMessage = iconData->uCallbackMessage;
+            notifyItem->uCallbackMessage = iconData->uCallbackMessage;
         }
 
         if (iconData->uFlags & NIF_ICON)
         {
-            notifyItem->IconIndex = tbBtn.iBitmap = ImageList_AddIcon(SysIcons, iconData->hIcon);
+            tbbi.dwMask |= TBIF_IMAGE;
+            tbbi.iImage = ImageList_AddIcon(SysIcons, iconData->hIcon);
         }
 
-        /* TODO: support NIF_TIP */
+        if (iconData->uFlags & NIF_TIP)
+        {
+            StringCchCopy(notifyItem->szTip, _countof(notifyItem->szTip), iconData->szTip);
+        }
 
         if (iconData->uFlags & NIF_STATE)
         {
-            notifyItem->iconData.dwState &= ~iconData->dwStateMask;
-            notifyItem->iconData.dwState |= (iconData->dwState & iconData->dwStateMask);
-            if (notifyItem->iconData.dwState & NIS_HIDDEN)
+            if (iconData->dwStateMask & NIS_HIDDEN &&
+                (notifyItem->dwState & NIS_HIDDEN) != (iconData->dwState & NIS_HIDDEN))
             {
-                tbBtn.fsState |= TBSTATE_HIDDEN;
-                VisibleButtonCount--;
+                tbbi.dwMask |= TBIF_STATE;
+                if (iconData->dwState & NIS_HIDDEN)
+                {
+                    if ((tbbi.fsState & TBSTATE_HIDDEN) == 0)
+                    {
+                        tbbi.fsState |= TBSTATE_HIDDEN;
+                        VisibleButtonCount--;
+                    }
+                }
+                else
+                {
+                    if ((tbbi.fsState & TBSTATE_HIDDEN) != 0)
+                    {
+                        tbbi.fsState &= ~TBSTATE_HIDDEN;
+                        VisibleButtonCount++;
+                    }
+                }
             }
 
+            notifyItem->dwState &= ~iconData->dwStateMask;
+            notifyItem->dwState |= (iconData->dwState & iconData->dwStateMask);
         }
 
         /* TODO: support NIF_INFO, NIF_GUID, NIF_REALTIME, NIF_SHOWTIP */
 
-        NotificationBar.SendMessageW(TB_INSERTBUTTON, notifyItem->Index, (LPARAM) &tbBtn);
-
-        NotificationBar.SendMessageW(TB_SETBUTTONSIZE, 0, MAKELONG(16, 16));
+        SetButtonInfo(index, &tbbi);
     }
 
     VOID RemoveButton(IN CONST NOTIFYICONDATA *iconData)
     {
-        PPNOTIFY_ITEM NotifyPointer;
-
-        NotifyPointer = FindPPNotifyItemByIconData(iconData);
-        if (NotifyPointer)
-        {
-            PNOTIFY_ITEM deleteItem;
-            PNOTIFY_ITEM updateItem;
-            deleteItem = *NotifyPointer;
-
-            NotificationBar.SendMessageW(TB_DELETEBUTTON, deleteItem->Index, 0);
-
-            *NotifyPointer = updateItem = deleteItem->next;
+        NOTIFYICONDATA * notifyItem;
+        TBBUTTONINFO tbbi = { 0 };
 
-            if (!(deleteItem->iconData.dwState & NIS_HIDDEN))
-                VisibleButtonCount--;
-            HeapFree(hProcessHeap,
-                0,
-                deleteItem);
-            ButtonCount--;
+        int index = FindItemByIconData(iconData, &notifyItem);
+        if (index < 0)
+            return;
 
-            while (updateItem != NULL)
-            {
-                TBBUTTONINFO tbbi;
-                updateItem->Index--;
-                tbbi.cbSize = sizeof(tbbi);
-                tbbi.dwMask = TBIF_BYINDEX | TBIF_COMMAND;
-                tbbi.idCommand = updateItem->Index;
+        DeleteButton(index);
+        delete notifyItem;
+    }
 
-                NotificationBar.SendMessageW(TB_SETBUTTONINFO, updateItem->Index, (LPARAM) &tbbi);
+    VOID GetTooltip(int index, LPTSTR szTip, DWORD cchTip)
+    {
+        NOTIFYICONDATA * notifyItem;
+        notifyItem = GetItemData(index);
 
-                updateItem = updateItem->next;
-            }
+        if (notifyItem)
+        {
+            StringCchCopy(szTip, cchTip, notifyItem->szTip);
         }
     }
 
+private:
+
     VOID SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wParam)
     {
-        PPNOTIFY_ITEM NotifyPointer;
-
         static LPCWSTR eventNames [] = {
             L"WM_MOUSEMOVE",
             L"WM_LBUTTONDOWN",
@@ -290,66 +328,63 @@ public:
             L"WM_XBUTTONDBLCLK"
         };
 
-        NotifyPointer = FindPPNotifyItemByIndex(wIndex);
-        if (!NotifyPointer)
-            return;
-
-        PNOTIFY_ITEM notifyItem = *NotifyPointer;
+        NOTIFYICONDATA * notifyItem = GetItemData(wIndex);
 
-        if (!::IsWindow(notifyItem->iconData.hWnd))
+        if (!::IsWindow(notifyItem->hWnd))
             return;
 
         if (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST)
         {
             DbgPrint("Sending message %S from button %d to %p (msg=%x, w=%x, l=%x)...\n",
                      eventNames[uMsg - WM_MOUSEFIRST], wIndex,
-                     notifyItem->iconData.hWnd, notifyItem->iconData.uCallbackMessage, notifyItem->iconData.uID, uMsg);
+                     notifyItem->hWnd, notifyItem->uCallbackMessage, notifyItem->uID, uMsg);
         }
 
         DWORD pid;
-        GetWindowThreadProcessId(notifyItem->iconData.hWnd, &pid);
+        GetWindowThreadProcessId(notifyItem->hWnd, &pid);
 
         if (pid == GetCurrentProcessId() ||
             (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST))
         {
-            PostMessage(notifyItem->iconData.hWnd,
-                notifyItem->iconData.uCallbackMessage,
-                notifyItem->iconData.uID,
-                uMsg);
+            PostMessage(notifyItem->hWnd,
+                        notifyItem->uCallbackMessage,
+                        notifyItem->uID,
+                        uMsg);
         }
         else
         {
-            SendMessage(notifyItem->iconData.hWnd,
-                notifyItem->iconData.uCallbackMessage,
-                notifyItem->iconData.uID,
-                uMsg);
+            SendMessage(notifyItem->hWnd,
+                        notifyItem->uCallbackMessage,
+                        notifyItem->uID,
+                        uMsg);
         }
     }
 
-    LRESULT DrawBackground(HDC hdc)
+    LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
     {
-        RECT rect;
-
-        GetClientRect(&rect);
-        DrawThemeParentBackground(m_hWnd, hdc, &rect);
+        POINT pt;
+        INT iBtn;
 
-        return TRUE;
-    }
+        pt.x = LOWORD(lParam);
+        pt.y = HIWORD(lParam);
 
-    LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        HDC hdc = (HDC) wParam;
+        iBtn = (INT) SendMessageW(TB_HITTEST, 0, (LPARAM) &pt);
 
-        if (!IsAppThemed())
+        if (iBtn >= 0)
         {
-            bHandled = FALSE;
-            return 0;
+            SendMouseEvent(iBtn, uMsg, wParam);
         }
 
-        return DrawBackground(hdc);
+        bHandled = FALSE;
+        return FALSE;
     }
 
-    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+public:
+    BEGIN_MSG_MAP(CNotifyToolbar)
+        MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent)
+    END_MSG_MAP()
+
+    void Initialize(HWND hWndParent)
     {
         DWORD styles =
             WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN |
@@ -357,37 +392,75 @@ public:
             CCS_TOP | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER;
         DWORD exStyles = WS_EX_TOOLWINDOW;
 
-        hWndToolbar = CreateWindowEx(exStyles,
-            TOOLBARCLASSNAME,
-            NULL,
-            styles,
-            0,
-            0,
-            0,
-            0,
-            m_hWnd,
-            NULL,
-            hExplorerInstance,
-            NULL);
+        HWND hWndToolbar = CreateWindowEx(exStyles,
+                                          TOOLBARCLASSNAME,
+                                          NULL,
+                                          styles,
+                                          0,
+                                          0,
+                                          0,
+                                          0,
+                                          hWndParent,
+                                          NULL,
+                                          hExplorerInstance,
+                                          NULL);
         if (hWndToolbar != NULL)
         {
-            SIZE BtnSize;
-
-            NotificationBar.SubclassWindow(hWndToolbar);
+            SubclassWindow(hWndToolbar);
 
             SetWindowTheme(hWndToolbar, L"TrayNotify", NULL);
 
             /* Identify the version we're using */
-            NotificationBar.SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
+            SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
 
             SysIcons = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1000);
-            NotificationBar.SendMessageW(TB_SETIMAGELIST, 0, (LPARAM) SysIcons);
+            SendMessageW(TB_SETIMAGELIST, 0, (LPARAM) SysIcons);
 
-            BtnSize.cx = BtnSize.cy = 18;
-            NotificationBar.SendMessageW(TB_SETBUTTONSIZE, 0, MAKELONG(BtnSize.cx, BtnSize.cy));
+            SetButtonSize(ICON_SIZE, ICON_SIZE);
+        }
+    }
+};
 
+class CSysPagerWnd :
+    public CComObjectRootEx<CComMultiThreadModelNoCS>,
+    public CWindowImpl < CSysPagerWnd, CWindow, CControlWinTraits >
+{
+    CNotifyToolbar * Toolbar;
+
+public:
+    CSysPagerWnd() :
+        Toolbar(NULL)
+    {
+    }
+    virtual ~CSysPagerWnd() { }
+
+    LRESULT DrawBackground(HDC hdc)
+    {
+        RECT rect;
+
+        GetClientRect(&rect);
+        DrawThemeParentBackground(m_hWnd, hdc, &rect);
+
+        return TRUE;
+    }
+
+    LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+    {
+        HDC hdc = (HDC) wParam;
+
+        if (!IsAppThemed())
+        {
+            bHandled = FALSE;
+            return 0;
         }
 
+        return DrawBackground(hdc);
+    }
+
+    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+    {
+        Toolbar = new CNotifyToolbar();
+        Toolbar->Initialize(m_hWnd);
         return TRUE;
     }
 
@@ -411,33 +484,17 @@ public:
             {
             case NIM_ADD:
             {
-                PPNOTIFY_ITEM NotifyPointer;
-
-                NotifyPointer = FindPPNotifyItemByIconData(iconData);
-                if (!NotifyPointer)
-                {
-                    AddButton(iconData);
-                }
+                Toolbar->AddButton(iconData);
                 break;
             }
             case NIM_MODIFY:
             {
-                PPNOTIFY_ITEM NotifyPointer;
-
-                NotifyPointer = FindPPNotifyItemByIconData(iconData);
-                if (!NotifyPointer)
-                {
-                    AddButton(iconData);
-                }
-                else
-                {
-                    UpdateButton(iconData);
-                }
+                Toolbar->UpdateButton(iconData);
                 break;
             }
             case NIM_DELETE:
             {
-                RemoveButton(iconData);
+                Toolbar->RemoveButton(iconData);
                 break;
             }
             default:
@@ -458,6 +515,7 @@ public:
     {
         INT rows = 0;
         TBMETRICS tbm;
+        int VisibleButtonCount = Toolbar->GetVisibleItemCount();
 
         if (wParam) /* horizontal */
         {
@@ -480,23 +538,13 @@ public:
         tbm.cxButtonSpacing = 0;
         tbm.cyButtonSpacing = 0;
 
-        NotificationBar.SendMessageW(TB_SETMETRICS, 0, (LPARAM) &tbm);
-    }
-
-    LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        return TRUE;
+        Toolbar->SendMessageW(TB_SETMETRICS, 0, (LPARAM) &tbm);
     }
 
     LRESULT OnGetInfoTip(INT uCode, LPNMHDR hdr, BOOL& bHandled)
     {
         NMTBGETINFOTIPW * nmtip = (NMTBGETINFOTIPW *) hdr;
-        PPNOTIFY_ITEM ptr = FindPPNotifyItemByIndex(nmtip->iItem);
-        if (ptr)
-        {
-            PNOTIFY_ITEM item = *ptr;
-            StringCchCopy(nmtip->pszText, nmtip->cchTextMax, item->iconData.szTip);
-        }
+        Toolbar->GetTooltip(nmtip->iItem, nmtip->pszText, nmtip->cchTextMax);
         return TRUE;
     }
 
@@ -523,43 +571,25 @@ public:
 
         Ret = DefWindowProc(uMsg, wParam, lParam);
 
-        if (hWndToolbar != NULL && hWndToolbar != m_hWnd)
+        if (Toolbar)
         {
-            NotificationBar.SetWindowPos(NULL, 0, 0, szClient.cx, szClient.cy, SWP_NOZORDER);
+            Toolbar->SetWindowPos(NULL, 0, 0, szClient.cx, szClient.cy, SWP_NOZORDER);
 
-            NotificationBar.SendMessageW(TB_AUTOSIZE);
+            Toolbar->AutoSize();
 
             RECT rc;
-            NotificationBar.GetClientRect(&rc);
+            Toolbar->GetClientRect(&rc);
 
             SIZE szBar = { rc.right - rc.left, rc.bottom - rc.top };
 
             INT xOff = (szClient.cx - szBar.cx) / 2;
             INT yOff = (szClient.cy - szBar.cy) / 2;
 
-            NotificationBar.SetWindowPos(NULL, xOff, yOff, szBar.cx, szBar.cy, SWP_NOZORDER);
+            Toolbar->SetWindowPos(NULL, xOff, yOff, szBar.cx, szBar.cy, SWP_NOZORDER);
         }
         return Ret;
     }
 
-    LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        POINT pt;
-        INT iBtn;
-
-        pt.x = LOWORD(lParam);
-        pt.y = HIWORD(lParam);
-
-        iBtn = (INT) NotificationBar.SendMessageW(TB_HITTEST, 0, (LPARAM) &pt);
-
-        if (iBtn >= 0)
-        {
-            SendMouseEvent(iBtn, uMsg, wParam);
-        }
-
-        return FALSE;
-    }
-
     DECLARE_WND_CLASS_EX(szSysPagerWndClass, CS_DBLCLKS, COLOR_3DFACE)
 
     BEGIN_MSG_MAP(CTaskSwitchWnd)
@@ -568,18 +598,12 @@ public:
         MESSAGE_HANDLER(WM_SIZE, OnSize)
         NOTIFY_CODE_HANDLER(TBN_GETINFOTIPW, OnGetInfoTip)
         NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
-    ALT_MSG_MAP(1)
-        MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent)
     END_MSG_MAP()
 
     HWND _Init(IN HWND hWndParent, IN BOOL bVisible)
     {
         DWORD dwStyle;
 
-        NotifyItems = NULL;
-        ButtonCount = 0;
-        VisibleButtonCount = 0;
-
         /* Create the window. The tray window is going to move it to the correct
             position and resize it as needed. */
         dwStyle = WS_CHILD | WS_CLIPSIBLINGS;
index 9e8edd5..25f826c 100644 (file)
@@ -53,10 +53,10 @@ static const WCHAR szTrayWndClass [] = TEXT("Shell_TrayWnd");
 
 const GUID IID_IShellDesktopTray = { 0x213e2df9, 0x9a14, 0x4328, { 0x99, 0xb1, 0x69, 0x61, 0xf9, 0x14, 0x3c, 0xe9 } };
 
-class ITrayWindowImpl :
-    public CComCoClass<ITrayWindowImpl>,
+class CTrayWindow :
+    public CComCoClass<CTrayWindow>,
     public CComObjectRootEx<CComMultiThreadModelNoCS>,
-    public CWindowImpl < ITrayWindowImpl, CWindow, CControlWinTraits >,
+    public CWindowImpl < CTrayWindow, CWindow, CControlWinTraits >,
     public ITrayWindow,
     public IShellDesktopTray
 {
@@ -119,7 +119,7 @@ class ITrayWindowImpl :
     HDPA hdpaShellServices;
 
 public:
-    ITrayWindowImpl() :
+    CTrayWindow() :
         TaskbarTheme(NULL),
         hWndDesktop(NULL),
         hwndStart(NULL),
@@ -151,7 +151,7 @@ public:
         ZeroMemory(&MouseTrackingInfo, sizeof(MouseTrackingInfo));
     }
 
-    virtual ~ITrayWindowImpl()
+    virtual ~CTrayWindow()
     {
         (void) InterlockedExchangePointer((PVOID*) &m_hWnd, NULL);
 
@@ -1683,7 +1683,7 @@ SetStartBtnImage:
 
     static DWORD WINAPI s_TrayPropertiesThread(IN OUT PVOID pParam)
     {
-        ITrayWindowImpl *This = (ITrayWindowImpl*) pParam;
+        CTrayWindow *This = (CTrayWindow*) pParam;
 
         return This->TrayPropertiesThread();
     }
@@ -1950,7 +1950,7 @@ SetStartBtnImage:
 
     static DWORD WINAPI s_RunFileDlgThread(IN OUT PVOID pParam)
     {
-        ITrayWindowImpl * This = (ITrayWindowImpl*) pParam;
+        CTrayWindow * This = (CTrayWindow*) pParam;
         return This->RunFileDlgThread();
     }
 
@@ -2790,7 +2790,7 @@ HandleTrayContextMenu:
 
     DECLARE_WND_CLASS_EX(szTrayWndClass, CS_DBLCLKS, COLOR_3DFACE)
 
-    BEGIN_MSG_MAP(ITrayWindowImpl)
+    BEGIN_MSG_MAP(CTrayWindow)
         if (StartMenuBand != NULL)
         {
             MSG Msg;
@@ -2848,7 +2848,7 @@ HandleTrayContextMenu:
                                              IN PVOID *ppcmContext,
                                              IN PVOID Context OPTIONAL)
     {
-        ITrayWindowImpl *This = (ITrayWindowImpl *) Context;
+        CTrayWindow *This = (CTrayWindow *) Context;
         IContextMenu *pcm = NULL;
         HMENU hPopup;
 
@@ -2892,7 +2892,7 @@ HandleTrayContextMenu:
                                                IN PVOID pcmContext OPTIONAL,
                                                IN PVOID Context OPTIONAL)
     {
-        ITrayWindowImpl *This = (ITrayWindowImpl *) Context;
+        CTrayWindow *This = (CTrayWindow *) Context;
         IContextMenu *pcm = (IContextMenu *) pcmContext;
 
         if (uiCmdId != 0)
@@ -3035,21 +3035,21 @@ HandleTrayContextMenu:
         Position = (DWORD) -1;
     }
 
-    DECLARE_NOT_AGGREGATABLE(ITrayWindowImpl)
+    DECLARE_NOT_AGGREGATABLE(CTrayWindow)
 
     DECLARE_PROTECT_FINAL_CONSTRUCT()
-    BEGIN_COM_MAP(ITrayWindowImpl)
+    BEGIN_COM_MAP(CTrayWindow)
         /*COM_INTERFACE_ENTRY_IID(IID_ITrayWindow, ITrayWindow)*/
         COM_INTERFACE_ENTRY_IID(IID_IShellDesktopTray, IShellDesktopTray)
     END_COM_MAP()
 };
 
 const TRAYWINDOW_CTXMENU TrayWindowCtxMenu = {
-    ITrayWindowImpl::CreateTrayWindowContextMenu,
-    ITrayWindowImpl::OnTrayWindowContextMenuCommand
+    CTrayWindow::CreateTrayWindowContextMenu,
+    CTrayWindow::OnTrayWindowContextMenuCommand
 };
 
-ITrayWindowImpl * g_TrayWindow;
+CTrayWindow * g_TrayWindow;
 
 HRESULT
 Tray_OnStartMenuDismissed()
@@ -3060,7 +3060,7 @@ Tray_OnStartMenuDismissed()
 
 HRESULT CreateTrayWindow(ITrayWindow ** ppTray)
 {
-    CComPtr<ITrayWindowImpl> Tray = new CComObject<ITrayWindowImpl>();
+    CComPtr<CTrayWindow> Tray = new CComObject<CTrayWindow>();
     if (Tray == NULL)
         return E_OUTOFMEMORY;