+ str = res;
+ if(!unicode)
+ res += strlen(str) + 1;
+ else
+ res += (strlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
+ if (flags & MF_POPUP)
+ {
+ hSubMenu = CreatePopupMenu();
+ if(!hSubMenu) return NULL;
+ if(!(res = MENU_ParseResource(res, hSubMenu, unicode)))
+ return NULL;
+ if(!unicode)
+ AppendMenuA(hMenu, flags, (UINT)hSubMenu, str);
+ else
+ AppendMenuW(hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str);
+ }
+ else /* Not a popup */
+ {
+ if(!unicode)
+ AppendMenuA(hMenu, flags, id, *str ? str : NULL);
+ else
+ AppendMenuW(hMenu, flags, id,
+ *(LPCWSTR)str ? (LPCWSTR)str : NULL);
+ }
+ } while(!end);
+
+ return res;
+}
+
+
+NTSTATUS STDCALL
+User32LoadSysMenuTemplateForKernel(PVOID Arguments, ULONG ArgumentLength)
+{
+ LRESULT Result;
+ HMODULE hUser32;
+ hUser32 = GetModuleHandleW(L"USER32");
+ Result = (LRESULT)LoadMenuW(hUser32, L"SYSMENU");
+ return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
+}
+
+
+BOOL
+MenuInit(VOID)
+{
+ NONCLIENTMETRICSW ncm;
+
+ /* get the menu font */
+ if(!hMenuFont || !hMenuFontBold)
+ {
+ ncm.cbSize = sizeof(ncm);
+ if(!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0))
+ {
+ DbgPrint("MenuInit(): SystemParametersInfoW(SPI_GETNONCLIENTMETRICS) failed!\n");
+ return FALSE;
+ }
+
+ hMenuFont = CreateFontIndirectW(&ncm.lfMenuFont);
+ if(hMenuFont == NULL)
+ {
+ DbgPrint("MenuInit(): CreateFontIndirectW(hMenuFont) failed!\n");
+ return FALSE;
+ }
+
+ ncm.lfMenuFont.lfWeight = max(ncm.lfMenuFont.lfWeight + 300, 1000);
+ hMenuFontBold = CreateFontIndirectW(&ncm.lfMenuFont);
+ if(hMenuFontBold == NULL)
+ {
+ DbgPrint("MenuInit(): CreateFontIndirectW(hMenuFontBold) failed!\n");
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+ULONG
+MenuGetMenuBarHeight(HWND hWnd, ULONG MenuBarWidth, LONG OrgX, LONG OrgY)
+{
+ /*ULONG MenuId;
+ PPOPUP_MENU Menu;
+ RECT Rect;
+ HDC hDC;
+
+ MenuId = GetWindowLong(hWnd, GWL_ID);
+ Menu = MenuGetMenu((HMENU)MenuId);
+ if (Menu == NULL)
+ {
+ return(0);
+ }
+ hDC = GetDCEx(hWnd, 0, DCX_CACHE | DCX_WINDOW);
+ SelectObject(hDC, hMenuFont);
+ SetRect(&Rect, OrgX, OrgY, OrgX + MenuBarWidth,
+ OrgY + GetSystemMetrics(SM_CYMENU));
+ MenuMenuBarCalcSize(hDC, &Rect, Menu, hWnd);
+ ReleaseDC(hWnd, hDC);*/
+ return(GetSystemMetrics(SM_CYMENU));
+}
+
+static BOOL
+MeasureMenuItem(HWND hWnd, HMENU mnu, HDC hDC, MENUITEMINFOW *mii, RECT *mir, LPWSTR str)
+{
+ BOOL res = FALSE;
+ MEASUREITEMSTRUCT mis;
+ SIZE sz;
+
+ if(mii->fType & MFT_OWNERDRAW)
+ {
+ /* send WM_MEASUREITEM message to window */
+ mis.CtlType = ODT_MENU;
+ mis.CtlID = 0;
+ mis.itemID = mii->wID;
+ mis.itemWidth = 0;
+ mis.itemHeight = 0;
+ mis.itemData = mii->dwItemData;
+ res = (BOOL)SendMessageW(hWnd, WM_MEASUREITEM, 0, (LPARAM)&mis);
+ if(res)
+ {
+ mir->right = mir->left + mis.itemWidth;
+ mir->bottom = mir->top + mis.itemHeight;
+ }
+ else
+ {
+ /* FIXME calculate size internally assuming the menu item is empty */
+ mir->right = mir->left + 1;
+ mir->bottom = mir->top + 1;
+ }
+ return res;
+ }