Author: gadamopoulos
Date: Tue Jul  5 10:09:26 2011
New Revision: 52543

URL: http://svn.reactos.org/svn/reactos?rev=52543&view=rev
Log:
[uxtheme]
- Implement drawing the menu bar

Modified:
    branches/GSoC_2011/ThemesSupport/dll/win32/uxtheme/nonclient.c

Modified: branches/GSoC_2011/ThemesSupport/dll/win32/uxtheme/nonclient.c
URL: 
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win32/uxtheme/nonclient.c?rev=52543&r1=52542&r2=52543&view=diff
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/uxtheme/nonclient.c [iso-8859-1] 
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/uxtheme/nonclient.c [iso-8859-1] 
Tue Jul  5 10:09:26 2011
@@ -58,6 +58,28 @@
 #define HAS_MENU(hwnd,style)  ((((style) & (WS_CHILD | WS_POPUP)) != WS_CHILD) 
&& GetMenu(hwnd))
 
 #define BUTTON_GAP_SIZE 2
+
+
+HFONT hMenuFont = NULL;
+HFONT hMenuFontBold = NULL;
+
+void InitMenuFont(VOID)
+{
+  NONCLIENTMETRICS ncm;
+
+    ncm.cbSize = sizeof(NONCLIENTMETRICS); 
+
+    if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0))
+    {
+      return ;
+    }
+
+    hMenuFont = CreateFontIndirect(&ncm.lfMenuFont);
+
+    ncm.lfMenuFont.lfWeight = max(ncm.lfMenuFont.lfWeight + 300, 1000);
+    hMenuFontBold = CreateFontIndirectW(&ncm.lfMenuFont);
+
+}
 
 static BOOL 
 IsWindowActive(HWND hWnd, DWORD ExStyle)
@@ -483,9 +505,142 @@
 }
 
 static void
+ThemeDrawMenuItem(PDRAW_CONTEXT pcontext, HMENU Menu, int imenu)
+{
+    PWCHAR Text;
+    BOOL flat_menu = FALSE;
+    MENUITEMINFOW Item;
+    RECT Rect,rcCalc;
+    WCHAR wstrItemText[20];
+    register int i = 0;
+    HFONT FontOld = NULL;
+    UINT uFormat = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
+
+    Item.cbSize = sizeof(MENUITEMINFOW);
+    Item.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
+    Item.dwTypeData = wstrItemText;
+    Item.cch = 20;
+    if (!GetMenuItemInfoW(Menu, imenu, TRUE, &Item))
+        return;
+
+    if(Item.fType & MF_SEPARATOR)
+        return;
+
+    if(Item.cch >= 20)
+    {
+        Item.cch++;
+        Item.dwTypeData = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, Item.cch  * 
sizeof(WCHAR));
+        Item.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
+        GetMenuItemInfoW(Menu, imenu, TRUE, &Item);
+    }
+
+    if(Item.cch == 0)
+        return;
+
+    flat_menu = GetThemeSysBool(pcontext->theme, TMT_FLATMENUS);
+
+    GetMenuItemRect(pcontext->hWnd, Menu, imenu, &Rect);
+
+    OffsetRect(&Rect, -pcontext->wi.rcWindow.left, -pcontext->wi.rcWindow.top);
+    
+    SetBkColor(pcontext->hDC, GetSysColor(flat_menu ? COLOR_MENUBAR : 
COLOR_MENU));
+    SetTextColor(pcontext->hDC, GetSysColor(Item.fState & MF_GRAYED ? 
COLOR_GRAYTEXT : COLOR_MENUTEXT));
+
+    if (0 != (Item.fState & MFS_DEFAULT))
+    {
+        FontOld = (HFONT)SelectObject(pcontext->hDC, hMenuFontBold);
+    }
+
+    Rect.left += MENU_BAR_ITEMS_SPACE / 2;
+    Rect.right -= MENU_BAR_ITEMS_SPACE / 2;
+
+    Text = (PWCHAR) Item.dwTypeData;
+    if(Text)
+    {
+        for (i = 0; L'\0' != Text[i]; i++)
+        {
+            if (L'\t' == Text[i] || L'\b' == Text[i])
+            {
+                break;
+            }
+        }
+    }
+
+    SetBkMode(pcontext->hDC, OPAQUE);
+
+    if (0 != (Item.fState & MF_GRAYED))
+    {
+        if (0 == (Item.fState & MF_HILITE))
+        {
+            ++Rect.left; ++Rect.top; ++Rect.right; ++Rect.bottom;
+            SetTextColor(pcontext->hDC, RGB(0xff, 0xff, 0xff));
+            DrawTextW(pcontext->hDC, Text, i, &Rect, uFormat);
+            --Rect.left; --Rect.top; --Rect.right; --Rect.bottom;
+        }
+        SetTextColor(pcontext->hDC, RGB(0x80, 0x80, 0x80));
+        SetBkMode(pcontext->hDC, TRANSPARENT);
+    }
+    
+    DrawTextW(pcontext->hDC, Text, i, &Rect, uFormat);
+
+    /* Exclude the area drawn by DrawText from the clip region */
+    SetRect(&rcCalc, 0,0,0,0);
+    DrawTextW(pcontext->hDC, Text, i, &rcCalc, uFormat | DT_CALCRECT);
+    InflateRect( &Rect, 0, -(rcCalc.bottom+1)/2);
+    ExcludeClipRect(pcontext->hDC, Rect.left, Rect.top, Rect.right, 
Rect.bottom);
+
+    if (NULL != FontOld)
+    {
+        SelectObject(pcontext->hDC, FontOld);
+    }
+}
+
+void WINAPI
 ThemeDrawMenuBar(PDRAW_CONTEXT pcontext, PRECT prcCurrent)
 {
-
+    HMENU Menu;
+    MENUBARINFO MenuBarInfo;
+    int i;
+    HFONT FontOld = NULL;
+    BOOL flat_menu;
+    RECT Rect;
+    HPEN oldPen ;
+
+    if (!hMenuFont)
+        InitMenuFont();
+
+    flat_menu = GetThemeSysBool(pcontext->theme, TMT_FLATMENUS);
+
+    MenuBarInfo.cbSize = sizeof(MENUBARINFO);
+    if (! GetMenuBarInfo(pcontext->hWnd, OBJID_MENU, 0, &MenuBarInfo))
+        return;
+
+    Menu = GetMenu(pcontext->hWnd);
+    if (GetMenuItemCount(Menu) == 0)
+        return;
+
+    Rect = MenuBarInfo.rcBar;
+    OffsetRect(&Rect, -pcontext->wi.rcWindow.left, -pcontext->wi.rcWindow.top);
+
+    /* Draw a line under the menu*/
+    oldPen = (HPEN)SelectObject(pcontext->hDC, GetStockObject(DC_PEN));
+    SetDCPenColor(pcontext->hDC, GetSysColor(COLOR_3DFACE));
+    MoveToEx(pcontext->hDC, Rect.left, Rect.bottom, NULL);
+    LineTo(pcontext->hDC, Rect.right, Rect.bottom);
+    SelectObject(pcontext->hDC, oldPen);
+
+    /* Draw menu items */
+    FontOld = (HFONT)SelectObject(pcontext->hDC, hMenuFont);
+
+    for (i = 0; i < GetMenuItemCount(Menu); i++)
+    {
+        ThemeDrawMenuItem(pcontext, Menu, i);
+    }
+
+    SelectObject(pcontext->hDC, FontOld);
+
+    /* Fill the menu background area that isn't painted yet*/
+    FillRect(pcontext->hDC, &Rect, GetSysColorBrush(flat_menu ? COLOR_MENUBAR 
: COLOR_MENU));
 }
 
 static void 


Reply via email to