Author: dquintana
Date: Mon Nov  3 16:05:09 2014
New Revision: 65226
URL: 
http://svn.reactos.org/svn/reactos?rev=65226&view=rev
Log:
[EXPLORER-NEW]
* Move the CToolbar class into rosctrls.h, so we can make use of it in other parts of
reactos.
Modified:
    branches/shell-experiments/base/shell/explorer-new/precomp.h
    branches/shell-experiments/base/shell/explorer-new/trayntfy.cpp
    branches/shell-experiments/include/reactos/rosctrls.h
Modified: branches/shell-experiments/base/shell/explorer-new/precomp.h
URL:
http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/ex…
==============================================================================
--- branches/shell-experiments/base/shell/explorer-new/precomp.h        [iso-8859-1]
(original)
+++ branches/shell-experiments/base/shell/explorer-new/precomp.h        [iso-8859-1] Mon
Nov  3 16:05:09 2014
@@ -30,6 +30,7 @@
 #include <strsafe.h>
 #include <undocuser.h>
 #include <undocshell.h>
+#include <rosctrls.h>
 #include "tmschema.h"
 #include "resource.h"
Modified: branches/shell-experiments/base/shell/explorer-new/trayntfy.cpp
URL:
http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/ex…
==============================================================================
--- branches/shell-experiments/base/shell/explorer-new/trayntfy.cpp     [iso-8859-1]
(original)
+++ branches/shell-experiments/base/shell/explorer-new/trayntfy.cpp     [iso-8859-1] Mon
Nov  3 16:05:09 2014
@@ -21,8 +21,6 @@
 #include "precomp.h"
 //#include <docobj.h>
-typedef unsigned short USHORT;
-
 /*
  * SysPagerWnd
  */
@@ -36,87 +34,6 @@
     NOTIFYICONDATA  nicon_data;
 } SYS_PAGER_COPY_DATA, *PSYS_PAGER_COPY_DATA;
-template<typename TItemData>
-class CToolbar :
-    public CWindowImpl < CToolbar<TItemData>, CWindow, CControlWinTraits>
-{
-
-public:
-    int GetItemCount()
-    {
-        return this->SendMessageW(TB_BUTTONCOUNT);
-    }
-
-    DWORD GetButton(int index, TBBUTTON * btn)
-    {
-        return this->SendMessageW(TB_GETBUTTON, index, (LPARAM) btn);
-    }
-
-    DWORD AddButton(TBBUTTON * btn)
-    {
-        return this->SendMessageW(TB_ADDBUTTONS, 1, (LPARAM) btn);
-    }
-
-    DWORD AddButtons(int count, TBBUTTON * buttons)
-    {
-        return this->SendMessageW(TB_ADDBUTTONS, count, (LPARAM) buttons);
-    }
-
-    DWORD InsertButton(int insertAt, TBBUTTON * btn)
-    {
-        return this->SendMessageW(TB_INSERTBUTTON, insertAt, (LPARAM) btn);
-    }
-
-    DWORD MoveButton(int oldIndex, int newIndex)
-    {
-        return this->SendMessageW(TB_MOVEBUTTON, oldIndex, newIndex);
-    }
-
-    DWORD DeleteButton(int index)
-    {
-        return this->SendMessageW(TB_DELETEBUTTON, index, 0);
-    }
-
-    DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
-    {
-        return this->SendMessageW(TB_GETBUTTONINFO, cmdId, (LPARAM) info);
-    }
-
-    DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
-    {
-        return this->SendMessageW(TB_SETBUTTONINFO, cmdId, (LPARAM) info);
-    }
-
-public:
-    DWORD SetButtonSize(int w, int h)
-    {
-        return this->SendMessageW(TB_SETBUTTONSIZE, 0, MAKELONG(w, h));
-    }
-
-public:
-    DWORD AutoSize()
-    {
-        return this->SendMessageW(TB_AUTOSIZE);
-    }
-
-public:
-    TItemData * GetItemData(int index)
-    {
-        TBBUTTON btn;
-        GetButton(index, &btn);
-        return (TItemData*) btn.dwData;
-    }
-
-    DWORD SetItemData(int index, TItemData * data)
-    {
-        TBBUTTONINFOW 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>
 {
@@ -136,14 +53,14 @@
     {
     }
-    int GetVisibleItemCount()
+    int GetVisibleButtonCount()
     {
         return VisibleButtonCount;
     }
     int FindItemByIconData(IN CONST NOTIFYICONDATA *iconData, NOTIFYICONDATA ** pdata)
     {
-        int count = GetItemCount();
+        int count = GetButtonCount();
         for (int i = 0; i < count; i++)
         {
@@ -179,7 +96,7 @@
         tbBtn.fsStyle = BTNS_NOPREFIX;
         tbBtn.dwData = (DWORD_PTR)notifyItem;
         tbBtn.iString = (INT_PTR) text;
-        tbBtn.idCommand = GetItemCount();
+        tbBtn.idCommand = GetButtonCount();
         if (iconData->uFlags & NIF_MESSAGE)
         {
@@ -228,9 +145,6 @@
         }
         tbbi.cbSize = sizeof(tbbi);
-        tbbi.dwMask = TBIF_BYINDEX | TBIF_STATE;
-        GetButtonInfo(index, &tbbi);
-
         tbbi.dwMask = TBIF_BYINDEX | TBIF_COMMAND;
         tbbi.idCommand = index;
@@ -258,19 +172,13 @@
                 tbbi.dwMask |= TBIF_STATE;
                 if (iconData->dwState & NIS_HIDDEN)
                 {
-                    if ((tbbi.fsState & TBSTATE_HIDDEN) == 0)
-                    {
-                        tbbi.fsState |= TBSTATE_HIDDEN;
-                        VisibleButtonCount--;
-                    }
+                    tbbi.fsState |= TBSTATE_HIDDEN;
+                    VisibleButtonCount--;
                 }
                 else
                 {
-                    if ((tbbi.fsState & TBSTATE_HIDDEN) != 0)
-                    {
-                        tbbi.fsState &= ~TBSTATE_HIDDEN;
-                        VisibleButtonCount++;
-                    }
+                    tbbi.fsState &= ~TBSTATE_HIDDEN;
+                    VisibleButtonCount++;
                 }
             }
@@ -389,34 +297,15 @@
             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;
-
-        HWND hWndToolbar = CreateWindowEx(exStyles,
-                                          TOOLBARCLASSNAME,
-                                          NULL,
-                                          styles,
-                                          0,
-                                          0,
-                                          0,
-                                          0,
-                                          hWndParent,
-                                          NULL,
-                                          hExplorerInstance,
-                                          NULL);
-        if (hWndToolbar != NULL)
-        {
-            SubclassWindow(hWndToolbar);
-
-            SetWindowTheme(hWndToolbar, L"TrayNotify", NULL);
-
-            /* Identify the version we're using */
-            SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
-
-            SysIcons = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1000);
-            SendMessageW(TB_SETIMAGELIST, 0, (LPARAM) SysIcons);
-
-            SetButtonSize(ICON_SIZE, ICON_SIZE);
-        }
+
+        Create(hWndParent, styles);
+
+        SetWindowTheme(m_hWnd, L"TrayNotify", NULL);
+
+        SysIcons = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1000);
+        SetImageList(SysIcons);
+
+        SetButtonSize(ICON_SIZE, ICON_SIZE);
     }
 };
@@ -424,14 +313,11 @@
     public CComObjectRootEx<CComMultiThreadModelNoCS>,
     public CWindowImpl < CSysPagerWnd, CWindow, CControlWinTraits >
 {
-    CNotifyToolbar * Toolbar;
+    CNotifyToolbar Toolbar;
 public:
-    CSysPagerWnd() :
-        Toolbar(NULL)
-    {
-    }
-    virtual ~CSysPagerWnd() { }
+    CSysPagerWnd() {}
+    virtual ~CSysPagerWnd() {}
     LRESULT DrawBackground(HDC hdc)
     {
@@ -458,8 +344,7 @@
     LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
     {
-        Toolbar = new CNotifyToolbar();
-        Toolbar->Initialize(m_hWnd);
+        Toolbar.Initialize(m_hWnd);
         return TRUE;
     }
@@ -483,17 +368,17 @@
             {
             case NIM_ADD:
             {
-                Toolbar->AddButton(iconData);
+                Toolbar.AddButton(iconData);
                 break;
             }
             case NIM_MODIFY:
             {
-                Toolbar->UpdateButton(iconData);
+                Toolbar.UpdateButton(iconData);
                 break;
             }
             case NIM_DELETE:
             {
-                Toolbar->RemoveButton(iconData);
+                Toolbar.RemoveButton(iconData);
                 break;
             }
             default:
@@ -514,7 +399,7 @@
     {
         INT rows = 0;
         TBMETRICS tbm;
-        int VisibleButtonCount = Toolbar->GetVisibleItemCount();
+        int VisibleButtonCount = Toolbar.GetVisibleButtonCount();
         if (wParam) /* horizontal */
         {
@@ -537,13 +422,13 @@
         tbm.cxButtonSpacing = 0;
         tbm.cyButtonSpacing = 0;
-        Toolbar->SendMessageW(TB_SETMETRICS, 0, (LPARAM) &tbm);
+        Toolbar.SetMetrics(&tbm);
     }
     LRESULT OnGetInfoTip(INT uCode, LPNMHDR hdr, BOOL& bHandled)
     {
         NMTBGETINFOTIPW * nmtip = (NMTBGETINFOTIPW *) hdr;
-        Toolbar->GetTooltip(nmtip->iItem, nmtip->pszText, nmtip->cchTextMax);
+        Toolbar.GetTooltip(nmtip->iItem, nmtip->pszText, nmtip->cchTextMax);
         return TRUE;
     }
@@ -572,19 +457,18 @@
         if (Toolbar)
         {
-            Toolbar->SetWindowPos(NULL, 0, 0, szClient.cx, szClient.cy, SWP_NOZORDER);
-
-            Toolbar->AutoSize();
+            Toolbar.SetWindowPos(NULL, 0, 0, szClient.cx, szClient.cy, SWP_NOZORDER);
+            Toolbar.AutoSize();
             RECT rc;
-            Toolbar->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;
-            Toolbar->SetWindowPos(NULL, xOff, yOff, szBar.cx, szBar.cy, SWP_NOZORDER);
+            Toolbar.SetWindowPos(NULL, xOff, yOff, szBar.cx, szBar.cy, SWP_NOZORDER);
         }
         return Ret;
     }
Modified: branches/shell-experiments/include/reactos/rosctrls.h
URL:
http://svn.reactos.org/svn/reactos/branches/shell-experiments/include/react…
==============================================================================
--- branches/shell-experiments/include/reactos/rosctrls.h       [iso-8859-1] (original)
+++ branches/shell-experiments/include/reactos/rosctrls.h       [iso-8859-1] Mon Nov  3
16:05:09 2014
@@ -196,3 +196,134 @@
     }
 };
+
+template<typename TItemData>
+class CToolbar :
+    public CWindow
+{
+public: // Configuration methods
+
+    HWND Create(HWND hWndParent, DWORD dwStyles = 0, DWORD dwExStyles = 0)
+    {
+        if (!dwStyles)
+        {
+            dwStyles = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
+        }
+
+        if (!dwExStyles)
+        {
+            dwExStyles = WS_EX_TOOLWINDOW;
+        }
+
+        m_hWnd = CreateWindowEx(dwExStyles,
+                                TOOLBARCLASSNAME,
+                                NULL,
+                                dwStyles,
+                                0,
+                                0,
+                                0,
+                                0,
+                                hWndParent,
+                                NULL,
+                                _AtlBaseModule.GetModuleInstance(),
+                                NULL);
+
+        if (!m_hWnd)
+            return NULL;
+
+        /* Identify the version we're using */
+        SetButtonStructSize();
+
+        return m_hWnd;
+    }
+
+    DWORD SetButtonStructSize()
+    {
+        return SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
+    }
+
+public: // Button list management methods
+    int GetButtonCount()
+    {
+        return SendMessageW(TB_BUTTONCOUNT);
+    }
+
+    DWORD GetButton(int index, TBBUTTON * btn)
+    {
+        return SendMessageW(TB_GETBUTTON, index, (LPARAM) btn);
+    }
+
+    DWORD AddButton(TBBUTTON * btn)
+    {
+        return SendMessageW(TB_ADDBUTTONS, 1, (LPARAM) btn);
+    }
+
+    DWORD AddButtons(int count, TBBUTTON * buttons)
+    {
+        return SendMessageW(TB_ADDBUTTONS, count, (LPARAM) buttons);
+    }
+
+    DWORD InsertButton(int insertAt, TBBUTTON * btn)
+    {
+        return SendMessageW(TB_INSERTBUTTON, insertAt, (LPARAM) btn);
+    }
+
+    DWORD MoveButton(int oldIndex, int newIndex)
+    {
+        return SendMessageW(TB_MOVEBUTTON, oldIndex, newIndex);
+    }
+
+    DWORD DeleteButton(int index)
+    {
+        return SendMessageW(TB_DELETEBUTTON, index, 0);
+    }
+
+    DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
+    {
+        return SendMessageW(TB_GETBUTTONINFO, cmdId, (LPARAM) info);
+    }
+
+    DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
+    {
+        return SendMessageW(TB_SETBUTTONINFO, cmdId, (LPARAM) info);
+    }
+
+public: // Layout management methods
+    DWORD SetButtonSize(int w, int h)
+    {
+        return SendMessageW(TB_SETBUTTONSIZE, 0, MAKELONG(w, h));
+    }
+
+    DWORD AutoSize()
+    {
+        return SendMessageW(TB_AUTOSIZE);
+    }
+
+public: // Image list management methods
+    DWORD SetImageList(HIMAGELIST himl)
+    {
+        return SendMessageW(TB_SETIMAGELIST, 0, (LPARAM) himl);
+    }
+
+    DWORD SetMetrics(TBMETRICS * tbm)
+    {
+        return SendMessageW(TB_SETMETRICS, 0, (LPARAM) tbm);
+    }
+
+public: // Utility methods
+    TItemData * GetItemData(int index)
+    {
+        TBBUTTON btn;
+        GetButton(index, &btn);
+        return (TItemData*) btn.dwData;
+    }
+
+    DWORD SetItemData(int index, TItemData * data)
+    {
+        TBBUTTONINFOW info = { 0 };
+        info.cbSize = sizeof(info);
+        info.dwMask = TBIF_BYINDEX | TBIF_LPARAM;
+        info.lParam = (DWORD_PTR) data;
+        return SetButtonInfo(index, &info);
+    }
+};