[COMCTL32] tab: Use DrawThemeText when drawing text with themes. CORE-13855
[reactos.git] / dll / win32 / comctl32 / tab.c
index d7da2be..c5e3a86 100644 (file)
@@ -357,14 +357,8 @@ static BOOL TAB_InternalGetItemRect(
          (itemIndex < infoPtr->leftmostVisible)))
     {
         TRACE("Not Visible\n");
-        /* need to initialize these to empty rects */
-        if (itemRect)
-        {
-            memset(itemRect,0,sizeof(RECT));
-            itemRect->bottom = infoPtr->tabHeight;
-        }
-        if (selectedRect)
-            memset(selectedRect,0,sizeof(RECT));
+        SetRect(itemRect, 0, 0, 0, infoPtr->tabHeight);
+        SetRectEmpty(selectedRect);
         return FALSE;
     }
 
@@ -444,7 +438,7 @@ static BOOL TAB_InternalGetItemRect(
   /* Now, calculate the position of the item as if it were selected. */
   if (selectedRect!=NULL)
   {
-    CopyRect(selectedRect, itemRect);
+    *selectedRect = *itemRect;
 
     /* The rectangle of a selected item is a bit wider. */
     if(infoPtr->dwStyle & TCS_VERTICAL)
@@ -1229,8 +1223,7 @@ static void TAB_SetItemBounds (TAB_INFO *infoPtr)
         tabwidth = max(tabwidth, infoPtr->tabMinWidth);
 
       curr->rect.right = curr->rect.left + tabwidth;
-      TRACE("for <%s>, l,r=%d,%d\n",
-         debugstr_w(curr->pszText), curr->rect.left, curr->rect.right);
+      TRACE("for <%s>, rect %s\n", debugstr_w(curr->pszText), wine_dbgstr_rect(&curr->rect));
     }
 
     /*
@@ -1249,8 +1242,7 @@ static void TAB_SetItemBounds (TAB_INFO *infoPtr)
 
        curr->rect.left = 0;
         curItemRowCount++;
-       TRACE("wrapping <%s>, l,r=%d,%d\n", debugstr_w(curr->pszText),
-           curr->rect.left, curr->rect.right);
+       TRACE("wrapping <%s>, rect %s\n", debugstr_w(curr->pszText), wine_dbgstr_rect(&curr->rect));
     }
 
     curr->rect.bottom = 0;
@@ -1363,9 +1355,7 @@ static void TAB_SetItemBounds (TAB_INFO *infoPtr)
           else
             curItemLeftPos = curr->rect.right;
 
-          TRACE("arranging <%s>, l,r=%d,%d, row=%d\n",
-             debugstr_w(curr->pszText), curr->rect.left,
-             curr->rect.right, curr->rect.top);
+          TRACE("arranging <%s>, rect %s\n", debugstr_w(curr->pszText), wine_dbgstr_rect(&curr->rect));
       }
 
       /*
@@ -1415,9 +1405,7 @@ static void TAB_SetItemBounds (TAB_INFO *infoPtr)
              item->rect.left += iCount * widthDiff;
              item->rect.right += (iCount + 1) * widthDiff;
 
-              TRACE("adjusting 1 <%s>, l,r=%d,%d\n",
-                 debugstr_w(item->pszText),
-                 item->rect.left, item->rect.right);
+              TRACE("adjusting 1 <%s>, rect %s\n", debugstr_w(item->pszText), wine_dbgstr_rect(&item->rect));
 
            }
            TAB_GetItem(infoPtr, iIndex - 1)->rect.right += remainder;
@@ -1427,13 +1415,9 @@ static void TAB_SetItemBounds (TAB_INFO *infoPtr)
            start->rect.left = clientRect.left;
            start->rect.right = clientRect.right - 4;
 
-            TRACE("adjusting 2 <%s>, l,r=%d,%d\n",
-               debugstr_w(start->pszText),
-               start->rect.left, start->rect.right);
-
+            TRACE("adjusting 2 <%s>, rect %s\n", debugstr_w(start->pszText), wine_dbgstr_rect(&start->rect));
          }
 
-
          iIndexStart = iIndexEnd;
        }
       }
@@ -1550,6 +1534,9 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
   HPEN   holdPen;
   INT    oldBkMode;
   HFONT  hOldFont;
+#ifdef __REACTOS__
+HTHEME    theme = GetWindowTheme (infoPtr->hwnd);
+#endif
   
 /*  if (drawRect == NULL) */
   {
@@ -1605,12 +1592,7 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
        }
       }
       else
-      {
-       drawRect->left   += 2;
-       drawRect->top    += 2;
-       drawRect->right  -= 2;
-       drawRect->bottom -= 2;
-      }
+        InflateRect(drawRect, -2, -2);
     }
     else
     {
@@ -1619,8 +1601,7 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
         if (iItem != infoPtr->iSelected)
        {
          drawRect->left   += 2;
-         drawRect->top    += 2;
-         drawRect->bottom -= 2;
+          InflateRect(drawRect, 0, -2);
        }
       }
       else if (infoPtr->dwStyle & TCS_VERTICAL)
@@ -1631,9 +1612,8 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
        }
        else
        {
-         drawRect->top    += 2;
          drawRect->right  -= 2;
-         drawRect->bottom -= 2;
+          InflateRect(drawRect, 0, -2);
        }
       }
       else if (infoPtr->dwStyle & TCS_BOTTOM)
@@ -1716,10 +1696,7 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
     drawRect->top += 2;
     drawRect->right -= 1;
     if ( iItem == infoPtr->iSelected )
-    {
-        drawRect->right -= 1;
-        drawRect->left += 1;
-    }
+        InflateRect(drawRect, -1, 0);
 
     id = (UINT)GetWindowLongPtrW( infoPtr->hwnd, GWLP_ID );
 
@@ -1735,7 +1712,7 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
       dis.itemState |= ODS_FOCUS;
     dis.hwndItem = infoPtr->hwnd;
     dis.hDC      = hdc;
-    CopyRect(&dis.rcItem,drawRect);
+    dis.rcItem = *drawRect;
 
     /* when extra data fits ULONG_PTR, store it directly */
     if (infoPtr->cbInfo > sizeof(LPARAM))
@@ -1765,8 +1742,7 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
     rcImage = *drawRect;
 
     rcTemp = *drawRect;
-
-    rcText.left = rcText.top = rcText.right = rcText.bottom = 0;
+    SetRectEmpty(&rcText);
 
     /* get the rectangle that the text fits in */
     if (item->pszText)
@@ -1931,6 +1907,29 @@ TAB_DrawItemInterior(const TAB_INFO *infoPtr, HDC hdc, INT iItem, RECT *drawRect
       TRACE("for <%s>, c_o_h=%d, c_o_v=%d, draw=(%s), textlen=%d\n",
          debugstr_w(item->pszText), center_offset_h, center_offset_v,
           wine_dbgstr_rect(drawRect), (rcText.right-rcText.left));
+#ifdef __REACTOS__
+      if (theme && item->pszText)
+      {
+          int partIndex = iItem == infoPtr->iSelected ? TABP_TABITEM : TABP_TOPTABITEM;
+          int stateId = TIS_NORMAL;
+
+          if (iItem == infoPtr->iSelected)
+              stateId = TIS_SELECTED;
+          else if (iItem == infoPtr->iHotTracked)
+              stateId = TIS_HOT;
+          else if (iItem == infoPtr->uFocus)
+              stateId = TIS_FOCUSED;
+
+          DrawThemeText(theme, 
+                        hdc, 
+                        partIndex, 
+                        stateId,
+                        item->pszText, 
+                        lstrlenW(item->pszText), 
+                        DT_LEFT | DT_SINGLELINE, 0, drawRect);
+      }
+      else
+#endif
       if (item->pszText)
       {
         DrawTextW