[SHELL32] Fix PIDL leak in CMenuSFToolbar::FillToolbar. CORE-13194
[reactos.git] / dll / win32 / shell32 / shellmenu / CMenuToolbars.cpp
index 0b13432..c1cd0b1 100644 (file)
@@ -105,8 +105,7 @@ HRESULT CMenuToolbarBase::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
         case NM_TOOLTIPSCREATED:
             break;
 
-            // Unknown
-        case -714: return S_FALSE;
+        case TBN_DRAGOUT: return S_FALSE;
 
         default:
             TRACE("WM_NOTIFY unknown code %d, %d\n", hdr->code, hdr->idFrom);
@@ -150,7 +149,7 @@ HRESULT CMenuToolbarBase::OnPagerCalcSize(LPNMPGCALCSIZE csize)
 
 HRESULT CMenuToolbarBase::OnCustomDraw(LPNMTBCUSTOMDRAW cdraw, LRESULT * theResult)
 {
-    bool     isHot, isPopup;
+    bool     isHot, isPopup, isActive;
     TBBUTTONINFO btni;
 
     switch (cdraw->nmcd.dwDrawStage)
@@ -161,9 +160,13 @@ HRESULT CMenuToolbarBase::OnCustomDraw(LPNMTBCUSTOMDRAW cdraw, LRESULT * theResu
 
     case CDDS_ITEMPREPAINT:
         
+        HWND tlw;
+        m_menuBand->_GetTopLevelWindow(&tlw);
+
         // The item with an active submenu gets the CHECKED flag.
         isHot = m_hotBar == this && (int) cdraw->nmcd.dwItemSpec == m_hotItem;
         isPopup = m_popupBar == this && (int) cdraw->nmcd.dwItemSpec == m_popupItem;
+        isActive = (GetForegroundWindow() == tlw) || (m_popupBar == this);
 
         if (m_hotItem < 0 && isPopup)
             isHot = TRUE;
@@ -207,6 +210,9 @@ HRESULT CMenuToolbarBase::OnCustomDraw(LPNMTBCUSTOMDRAW cdraw, LRESULT * theResu
         }
         else
         {
+            // Set the text color, will be used by the internal drawing code
+            cdraw->clrText = GetSysColor(isActive ? COLOR_MENUTEXT : COLOR_GRAYTEXT);
+
             // Remove HOT and CHECKED flags (will restore HOT if necessary)
             cdraw->nmcd.uItemState &= ~CDIS_HOT;
 
@@ -1315,7 +1321,11 @@ HRESULT CMenuSFToolbar::FillToolbar(BOOL clearFirst)
     {
         if (m_menuBand->_CallCBWithItemPidl(item, 0x10000000, 0, 0) == S_FALSE)
         {
-            DPA_AppendPtr(dpaSort, ILClone(item));
+            DPA_AppendPtr(dpaSort, item);
+        }
+        else
+        {
+            CoTaskMemFree(item);
         }
 
         hr = eidl->Next(1, &item, NULL);