[EXPLORER] Reduce the spam due to the broken CBandSite in browseui
[reactos.git] / base / shell / explorer / taskband.cpp
index 91228b2..6dd4d9e 100644 (file)
@@ -21,7 +21,7 @@
 #include "precomp.h"
 
 /*****************************************************************************
- ** ITaskBand ****************************************************************
+ ** CTaskBand ****************************************************************
  *****************************************************************************/
 
 const GUID CLSID_ITaskBand = { 0x68284FAA, 0x6A48, 0x11D0, { 0x8C, 0x78, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0xB4 } };
@@ -30,64 +30,35 @@ class CTaskBand :
     public CComCoClass<CTaskBand>,
     public CComObjectRootEx<CComMultiThreadModelNoCS>,
     public IObjectWithSite,
-    public ITaskBand,
     public IDeskBand,
     public IDeskBar,
     public IPersistStream,
     public IWinEventHandler,
     public IOleCommandTarget
 {
-    CComPtr<ITrayWindow> Tray;
-    CComPtr<IUnknown> punkSite;
+    CComPtr<ITrayWindow> m_Tray;
+    CComPtr<IUnknown> m_Site;
 
-    HWND hWnd;
-    DWORD dwBandID;
+    HWND m_hWnd;
 
 public:
     CTaskBand() :
-        hWnd(NULL),
-        dwBandID(0)
+        m_hWnd(NULL)
     {
-
     }
 
     virtual ~CTaskBand() { }
 
-    virtual HRESULT STDMETHODCALLTYPE GetRebarBandID(
-        OUT DWORD *pdwBandID)
-    {
-        if (dwBandID != (DWORD) -1)
-        {
-            if (pdwBandID != NULL)
-                *pdwBandID = dwBandID;
-
-            return S_OK;
-        }
-
-        return E_FAIL;
-    }
-
     /*****************************************************************************/
 
-    virtual HRESULT STDMETHODCALLTYPE GetWindow(
-        OUT HWND *phwnd)
+    virtual HRESULT STDMETHODCALLTYPE GetWindow(OUT HWND *phwnd)
     {
-
-        /* NOTE: We have to return the tray window here so that ITaskBarClient
-                 knows the parent window of the Rebar control it creates when
-                 calling ITaskBarClient::SetDeskBarSite()! However, once we
-                 created a window we return the task switch window! */
-        if (hWnd != NULL)
-            *phwnd = hWnd;
-        else
-            *phwnd = Tray->GetHWND();
-
-        TRACE("ITaskBand::GetWindow(0x%p->0x%p)\n", phwnd, *phwnd);
-
-        if (*phwnd != NULL)
-            return S_OK;
-
-        return E_FAIL;
+        if (!m_hWnd)
+            return E_FAIL;
+        if (!phwnd)
+            return E_INVALIDARG;
+        *phwnd = m_hWnd;
+        return S_OK;
     }
 
     virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(
@@ -125,10 +96,12 @@ public:
         IN DWORD dwViewMode,
         IN OUT DESKBANDINFO *pdbi)
     {
-        TRACE("ITaskBand::GetBandInfo(0x%x,0x%x,0x%p) hWnd=0x%p\n", dwBandID, dwViewMode, pdbi, hWnd);
+        TRACE("CTaskBand::GetBandInfo(0x%x,0x%x,0x%p) hWnd=0x%p\n", dwBandID, dwViewMode, pdbi, m_hWnd);
 
-        if (hWnd != NULL)
+        if (m_hWnd != NULL)
         {
+            HWND hwndToolbar = ::GetWindow(m_hWnd, GW_CHILD);
+
             /* The task band never has a title */
             pdbi->dwMask &= ~DBIM_TITLE;
 
@@ -140,31 +113,30 @@ public:
             /* FIXME: What about DBIMF_NOGRIPPER and DBIMF_ALWAYSGRIPPER */
             pdbi->dwModeFlags = DBIMF_VARIABLEHEIGHT;
 
+            /* Obtain the button size, to be used as the minimum size */
+            DWORD size = SendMessageW(hwndToolbar, TB_GETBUTTONSIZE, 0, 0);
+            pdbi->ptMinSize.x = 0;
+            pdbi->ptMinSize.y = GET_Y_LPARAM(size);
+
             if (dwViewMode & DBIF_VIEWMODE_VERTICAL)
             {
+                pdbi->ptIntegral.x = 0;
                 pdbi->ptIntegral.y = 1;
-                pdbi->ptMinSize.y = 1;
-                /* FIXME: Get the button metrics from the task bar object!!! */
-                pdbi->ptMinSize.x = (3 * GetSystemMetrics(SM_CXEDGE) / 2) + /* FIXME: Might be wrong if only one column! */
-                    GetSystemMetrics(SM_CXSIZE) + (2 * GetSystemMetrics(SM_CXEDGE)); /* FIXME: Min button size, query!!! */
             }
             else
             {
-                pdbi->ptMinSize.y = GetSystemMetrics(SM_CYSIZE) + (2 * GetSystemMetrics(SM_CYEDGE)); /* FIXME: Query */
-                pdbi->ptIntegral.y = pdbi->ptMinSize.y + (3 * GetSystemMetrics(SM_CYEDGE) / 2); /* FIXME: Query metrics */
-                /* We're not going to allow task bands where not even the minimum button size fits into the band */
-                pdbi->ptMinSize.x = pdbi->ptIntegral.y;
+                pdbi->ptIntegral.x = 0;
+                pdbi->ptIntegral.y = GET_Y_LPARAM(size);
             }
 
             /* Ignored: pdbi->ptMaxSize.x */
             pdbi->ptMaxSize.y = -1;
 
+            RECT rcToolbar;
+            ::GetWindowRect(hwndToolbar, &rcToolbar);
             /* FIXME: We should query the height from the task bar object!!! */
-            pdbi->ptActual.y = GetSystemMetrics(SM_CYSIZE) + (2 * GetSystemMetrics(SM_CYEDGE));
-
-            /* Save the band ID for future use in case we need to check whether a given band
-               is the task band */
-            this->dwBandID = dwBandID;
+            pdbi->ptActual.x = rcToolbar.right - rcToolbar.left;
+            pdbi->ptActual.y = rcToolbar.bottom - rcToolbar.top;
 
             TRACE("H: %d, Min: %d,%d, Integral.y: %d Actual: %d,%d\n", (dwViewMode & DBIF_VIEWMODE_VERTICAL) == 0,
                 pdbi->ptMinSize.x, pdbi->ptMinSize.y, pdbi->ptIntegral.y,
@@ -231,7 +203,7 @@ public:
     virtual HRESULT STDMETHODCALLTYPE GetClassID(
         OUT CLSID *pClassID)
     {
-        TRACE("ITaskBand::GetClassID(0x%p)\n", pClassID);
+        TRACE("CTaskBand::GetClassID(0x%p)\n", pClassID);
         /* We're going to return the (internal!) CLSID of the task band interface */
         *pClassID = CLSID_ITaskBand;
         return S_OK;
@@ -246,7 +218,7 @@ public:
     virtual HRESULT STDMETHODCALLTYPE Load(
         IN IStream *pStm)
     {
-        TRACE("ITaskBand::Load called\n");
+        TRACE("CTaskBand::Load called\n");
         /* Nothing to do */
         return S_OK;
     }
@@ -262,7 +234,7 @@ public:
     virtual HRESULT STDMETHODCALLTYPE GetSizeMax(
         OUT ULARGE_INTEGER *pcbSize)
     {
-        TRACE("ITaskBand::GetSizeMax called\n");
+        TRACE("CTaskBand::GetSizeMax called\n");
         /* We don't need any space for the task band */
         pcbSize->QuadPart = 0;
         return S_OK;
@@ -272,68 +244,42 @@ public:
 
     virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite)
     {
-        HRESULT hRet = E_FAIL;
+        HRESULT hRet;
+        HWND hwndSite;
 
-        TRACE("ITaskBand::SetSite(0x%p)\n", pUnkSite);
+        TRACE("CTaskBand::SetSite(0x%p)\n", pUnkSite);
 
-        /* Release the current site */
-        if (punkSite != NULL)
+        hRet = IUnknown_GetWindow(pUnkSite, &hwndSite);
+        if (FAILED(hRet))
         {
-            punkSite->Release();
+            TRACE("Querying site window failed: 0x%x\n", hRet);
+            return hRet;
         }
 
-        punkSite = NULL;
-        hWnd = NULL;
+        TRACE("CreateTaskSwitchWnd(Parent: 0x%p)\n", hwndSite);
 
-        if (pUnkSite != NULL)
+        HWND hwndTaskSwitch = CreateTaskSwitchWnd(hwndSite, m_Tray);
+        if (!hwndTaskSwitch)
         {
-            IOleWindow *OleWindow;
-
-            /* Check if the site supports IOleWindow */
-            hRet = pUnkSite->QueryInterface(IID_PPV_ARG(IOleWindow, &OleWindow));
-            if (SUCCEEDED(hRet))
-            {
-                HWND hWndParent = NULL;
-
-                hRet = OleWindow->GetWindow(
-                    &hWndParent);
-                if (SUCCEEDED(hRet))
-                {
-                    /* Attempt to create the task switch window */
-
-                    TRACE("CreateTaskSwitchWnd(Parent: 0x%p)\n", hWndParent);
-                    hWnd = CreateTaskSwitchWnd(hWndParent, Tray);
-                    if (hWnd != NULL)
-                    {
-                        punkSite = pUnkSite;
-                        hRet = S_OK;
-                    }
-                    else
-                    {
-                        TRACE("CreateTaskSwitchWnd() failed!\n");
-                        OleWindow->Release();
-                        hRet = E_FAIL;
-                    }
-                }
-                else
-                    OleWindow->Release();
-            }
-            else
-                TRACE("Querying IOleWindow failed: 0x%x\n", hRet);
+            ERR("CreateTaskSwitchWnd failed");
+            return E_FAIL;
         }
 
-        return hRet;
+        m_Site = pUnkSite;
+        m_hWnd = hwndTaskSwitch;
+
+        return S_OK;
     }
 
     virtual HRESULT STDMETHODCALLTYPE GetSite(
         IN REFIID riid,
         OUT VOID **ppvSite)
     {
-        TRACE("ITaskBand::GetSite(0x%p,0x%p)\n", riid, ppvSite);
+        TRACE("CTaskBand::GetSite(0x%p,0x%p)\n", riid, ppvSite);
 
-        if (punkSite != NULL)
+        if (m_Site != NULL)
         {
-            return punkSite->QueryInterface(riid, ppvSite);
+            return m_Site->QueryInterface(riid, ppvSite);
         }
 
         *ppvSite = NULL;
@@ -349,17 +295,17 @@ public:
         IN LPARAM lParam,
         OUT LRESULT *plrResult)
     {
-        TRACE("ITaskBand: IWinEventHandler::ProcessMessage(0x%p, 0x%x, 0x%p, 0x%p, 0x%p)\n", hWnd, uMsg, wParam, lParam, plrResult);
+        TRACE("CTaskBand: IWinEventHandler::ProcessMessage(0x%p, 0x%x, 0x%p, 0x%p, 0x%p)\n", hWnd, uMsg, wParam, lParam, plrResult);
         return E_NOTIMPL;
     }
 
     virtual HRESULT STDMETHODCALLTYPE ContainsWindow(
         IN HWND hWnd)
     {
-        if (hWnd == hWnd ||
-            IsChild(hWnd, hWnd))
+        if (hWnd == m_hWnd ||
+            IsChild(m_hWnd, hWnd))
         {
-            TRACE("ITaskBand::ContainsWindow(0x%p) returns S_OK\n", hWnd);
+            TRACE("CTaskBand::ContainsWindow(0x%p) returns S_OK\n", hWnd);
             return S_OK;
         }
 
@@ -368,21 +314,20 @@ public:
 
     virtual HRESULT STDMETHODCALLTYPE OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
     {
-        UNIMPLEMENTED;
+        //UNIMPLEMENTED;
         return E_NOTIMPL;
     }
 
     virtual HRESULT STDMETHODCALLTYPE IsWindowOwner(HWND hWnd)
     {
-        return (hWnd == this->hWnd) ? S_OK : S_FALSE;
+        return (hWnd == m_hWnd) ? S_OK : S_FALSE;
     }
 
     /*****************************************************************************/
 
-    HRESULT STDMETHODCALLTYPE _Init(IN OUT ITrayWindow *tray)
+    HRESULT STDMETHODCALLTYPE Initialize(IN OUT ITrayWindow *tray, HWND hWndStartButton)
     {
-        Tray = tray;
-        dwBandID = (DWORD) -1;
+        m_Tray = tray;
         return S_OK;
     }
 
@@ -400,21 +345,7 @@ public:
     END_COM_MAP()
 };
 
-ITaskBand * CreateTaskBand(IN OUT ITrayWindow *Tray)
+HRESULT CTaskBand_CreateInstance(IN ITrayWindow *Tray, HWND hWndStartButton, REFIID riid, void **ppv)
 {
-    HRESULT hr;
-
-    CTaskBand * tb = new CComObject<CTaskBand>();
-
-    if (!tb)
-        return NULL;
-
-    hr = tb->AddRef();
-
-    hr = tb->_Init(Tray);
-
-    if (FAILED_UNEXPECTEDLY(hr))
-        tb->Release();
-
-    return tb;
+    return ShellObjectCreatorInit<CTaskBand>(Tray, hWndStartButton, riid, ppv);
 }