[Win32k|User32]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / menu.c
index 1f6422f..9bdbe02 100644 (file)
@@ -1,23 +1,4 @@
 /*
- *  ReactOS W32 Subsystem
- *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
  * PURPOSE:          Menus
@@ -95,7 +76,7 @@ UserMenuInfo(
 { \
   if((MENU_ITEM_TYPE((MenuItem)->fType) == MF_STRING) && \
            (MenuItem)->Text.Length) { \
-    RtlFreeUnicodeString(&(MenuItem)->Text); \
+    ExFreePoolWithTag((MenuItem)->Text.Buffer, TAG_STRING); \
   } \
 }
 
@@ -134,7 +115,7 @@ PMENU_OBJECT FASTCALL UserGetMenuObject(HMENU hMenu)
       return NULL;
    }
 
-   ASSERT(USER_BODY_TO_HEADER(Menu)->RefCount >= 0);
+   ASSERT(Menu->head.cLockObj >= 0);
    return Menu;
 }
 
@@ -198,35 +179,17 @@ IntGetMenuObject(HMENU hMenu)
    PMENU_OBJECT Menu = UserGetMenuObject(hMenu);
    if (Menu)
    {
-      ASSERT(USER_BODY_TO_HEADER(Menu)->RefCount >= 0);
+      ASSERT(Menu->head.cLockObj >= 0);
 
-      USER_BODY_TO_HEADER(Menu)->RefCount++;
+      Menu->head.cLockObj++;
    }
    return Menu;
 }
 
 BOOL FASTCALL
-IntFreeMenuItem(PMENU_OBJECT Menu, PMENU_ITEM MenuItem,
-                BOOL RemoveFromList, BOOL bRecurse)
+IntFreeMenuItem(PMENU_OBJECT Menu, PMENU_ITEM MenuItem, BOOL bRecurse)
 {
    FreeMenuText(MenuItem);
-   if(RemoveFromList)
-   {
-      PMENU_ITEM CurItem = Menu->MenuItemList;
-      while(CurItem)
-      {
-         if (CurItem->Next == MenuItem)
-         {
-            CurItem->Next = MenuItem->Next;
-            break;
-         }
-         else
-         {
-            CurItem = CurItem->Next;
-         }
-      }
-      Menu->MenuInfo.MenuItemCount--;
-   }
    if(bRecurse && MenuItem->hSubMenu)
    {
       PMENU_OBJECT SubMenu;
@@ -248,7 +211,7 @@ IntRemoveMenuItem(PMENU_OBJECT Menu, UINT uPosition, UINT uFlags,
                   BOOL bRecurse)
 {
    PMENU_ITEM PrevMenuItem, MenuItem;
-   if(IntGetMenuItemByFlag(Menu, uPosition, uFlags, NULL, &MenuItem,
+   if(IntGetMenuItemByFlag(Menu, uPosition, uFlags, &Menu, &MenuItem,
                            &PrevMenuItem) > -1)
    {
       if(MenuItem)
@@ -259,7 +222,8 @@ IntRemoveMenuItem(PMENU_OBJECT Menu, UINT uPosition, UINT uFlags,
          {
             Menu->MenuItemList = MenuItem->Next;
          }
-         return IntFreeMenuItem(Menu, MenuItem, TRUE, bRecurse);
+         Menu->MenuInfo.MenuItemCount--;
+         return IntFreeMenuItem(Menu, MenuItem, bRecurse);
       }
    }
    return FALSE;
@@ -274,7 +238,7 @@ IntDeleteMenuItems(PMENU_OBJECT Menu, BOOL bRecurse)
    while(CurItem)
    {
       NextItem = CurItem->Next;
-      IntFreeMenuItem(Menu, CurItem, FALSE, bRecurse);
+      IntFreeMenuItem(Menu, CurItem, bRecurse);
       CurItem = NextItem;
       res++;
    }
@@ -309,17 +273,19 @@ IntDestroyMenuObject(PMENU_OBJECT Menu,
                                          NULL);
       if(NT_SUCCESS(Status))
       {
+         BOOL ret;
          if (Menu->MenuInfo.Wnd)
          {
             Window = UserGetWindowObject(Menu->MenuInfo.Wnd);
             if (Window)
             {
-               Window->IDMenu = 0;
+               Window->Wnd->IDMenu = 0;
             }
          }
-         ObmDeleteObject(Menu->MenuInfo.Self, otMenu);
+//         UserDereferenceObject(Menu);
+         ret = UserDeleteObject(Menu->MenuInfo.Self, otMenu);
          ObDereferenceObject(WindowStation);
-         return TRUE;
+         return ret;
       }
    }
    return FALSE;
@@ -329,11 +295,13 @@ PMENU_OBJECT FASTCALL
 IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
 {
    PMENU_OBJECT Menu;
+   PPROCESSINFO CurrentWin32Process;
 
-   Menu = (PMENU_OBJECT)ObmCreateObject(
-             gHandleTable, Handle,
-             otMenu, sizeof(MENU_OBJECT));
-
+   Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable,
+                                          NULL,
+                                          Handle,
+                                          otMenu,
+                                          sizeof(MENU_OBJECT));
    if(!Menu)
    {
       *Handle = 0;
@@ -346,8 +314,7 @@ IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
    Menu->MenuInfo.fMask = 0; /* not used */
    Menu->MenuInfo.dwStyle = 0; /* FIXME */
    Menu->MenuInfo.cyMax = 0; /* default */
-   Menu->MenuInfo.hbrBack =
-      NtGdiCreateSolidBrush(RGB(192, 192, 192), 0); /* FIXME: default background color */
+   Menu->MenuInfo.hbrBack = NULL; /* no brush */
    Menu->MenuInfo.dwContextHelpID = 0; /* default */
    Menu->MenuInfo.dwMenuData = 0; /* default */
    Menu->MenuInfo.Self = *Handle;
@@ -363,7 +330,8 @@ IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
    Menu->MenuItemList = NULL;
 
    /* Insert menu item into process menu handle list */
-   InsertTailList(&PsGetCurrentProcessWin32Process()->MenuListHead, &Menu->ListEntry);
+   CurrentWin32Process = PsGetCurrentProcessWin32Process();
+   InsertTailList(&CurrentWin32Process->MenuListHead, &Menu->ListEntry);
 
    return Menu;
 }
@@ -402,7 +370,7 @@ IntCloneMenuItems(PMENU_OBJECT Destination, PMENU_OBJECT Source)
             NewMenuItem->Text.Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, MenuItem->Text.MaximumLength, TAG_STRING);
             if(!NewMenuItem->Text.Buffer)
             {
-               ExFreePool(NewMenuItem);
+               ExFreePoolWithTag(NewMenuItem, TAG_MENUITEM);
                break;
             }
             RtlCopyUnicodeString(&NewMenuItem->Text, &MenuItem->Text);
@@ -433,16 +401,18 @@ IntCloneMenuItems(PMENU_OBJECT Destination, PMENU_OBJECT Source)
 PMENU_OBJECT FASTCALL
 IntCloneMenu(PMENU_OBJECT Source)
 {
+   PPROCESSINFO CurrentWin32Process;
    HANDLE hMenu;
    PMENU_OBJECT Menu;
 
    if(!Source)
       return NULL;
 
-   Menu = (PMENU_OBJECT)ObmCreateObject(
-             gHandleTable, &hMenu,
-             otMenu, sizeof(MENU_OBJECT));
-
+   Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable,
+                                          NULL,
+                                         &hMenu,
+                                          otMenu,
+                                          sizeof(MENU_OBJECT));
    if(!Menu)
       return NULL;
 
@@ -467,7 +437,8 @@ IntCloneMenu(PMENU_OBJECT Source)
    Menu->MenuItemList = NULL;
 
    /* Insert menu item into process menu handle list */
-   InsertTailList(&PsGetCurrentProcessWin32Process()->MenuListHead, &Menu->ListEntry);
+   CurrentWin32Process = PsGetCurrentProcessWin32Process();
+   InsertTailList(&CurrentWin32Process->MenuListHead, &Menu->ListEntry);
 
    IntCloneMenuItems(Menu, Source);
 
@@ -515,20 +486,6 @@ IntGetMenuInfo(PMENU_OBJECT Menu, PROSMENUINFO lpmi)
    return TRUE;
 }
 
-
-BOOL FASTCALL
-IntIsMenu(HMENU hMenu)
-{
-   PMENU_OBJECT Menu;
-
-   if((Menu = UserGetMenuObject(hMenu)))
-   {
-      return TRUE;
-   }
-   return FALSE;
-}
-
-
 BOOL FASTCALL
 IntSetMenuInfo(PMENU_OBJECT Menu, PROSMENUINFO lpmi)
 {
@@ -622,7 +579,7 @@ IntGetMenuItemByFlag(PMENU_OBJECT Menu, UINT uSearchBy, UINT fFlag,
             if(CurItem->fType & MF_POPUP)
             {
                PMENU_OBJECT NewMenu = UserGetMenuObject(CurItem->hSubMenu);
-               if(Menu)
+               if(NewMenu)
                {
                    ret = IntGetMenuItemByFlag(NewMenu, uSearchBy, fFlag,
                                               SubMenu, MenuItem, PrevMenuItem);
@@ -650,56 +607,25 @@ IntInsertMenuItemToList(PMENU_OBJECT Menu, PMENU_ITEM MenuItem, int pos)
    UINT npos = 0;
 
    CurItem = Menu->MenuItemList;
-   if(pos <= -1)
+   while(CurItem && (pos != 0))
    {
-      while(CurItem)
-      {
-         LastItem = CurItem;
-         CurItem = CurItem->Next;
-         npos++;
-      }
-   }
-   else
-   {
-      while(CurItem && (pos > 0))
-      {
-         LastItem = CurItem;
-         CurItem = CurItem->Next;
-         pos--;
-         npos++;
-      }
+      LastItem = CurItem;
+      CurItem = CurItem->Next;
+      pos--;
+      npos++;
    }
 
-   if(CurItem)
+   if(LastItem)
    {
-      if(LastItem)
-      {
-         /* insert the item before CurItem */
-         MenuItem->Next = LastItem->Next;
-         LastItem->Next = MenuItem;
-      }
-      else
-      {
-         /* insert at the beginning */
-         Menu->MenuItemList = MenuItem;
-         MenuItem->Next = CurItem;
-      }
+      /* insert the item after LastItem */
+      LastItem->Next = MenuItem;
    }
    else
    {
-      if(LastItem)
-      {
-         /* append item */
-         LastItem->Next = MenuItem;
-         MenuItem->Next = NULL;
-      }
-      else
-      {
-         /* insert first item */
-         Menu->MenuItemList = MenuItem;
-         MenuItem->Next = NULL;
-      }
+      /* insert at the beginning */
+      Menu->MenuItemList = MenuItem;
    }
+   MenuItem->Next = CurItem;
    Menu->MenuInfo.MenuItemCount++;
 
    return npos;
@@ -764,8 +690,8 @@ IntGetMenuItemInfo(PMENU_OBJECT Menu, /* UNUSED PARAM!! */
    if (sizeof(ROSMENUITEMINFO) == lpmii->cbSize)
    {
       lpmii->Rect = MenuItem->Rect;
-      lpmii->XTab = MenuItem->XTab;
-      lpmii->Text = MenuItem->Text.Buffer;
+      lpmii->dxTab = MenuItem->dxTab;
+      lpmii->lpstr = MenuItem->Text.Buffer; // Use DesktopHeap!
    }
 
    return TRUE;
@@ -916,8 +842,8 @@ IntSetMenuItemInfo(PMENU_OBJECT MenuObject, PMENU_ITEM MenuItem, PROSMENUITEMINF
    if (sizeof(ROSMENUITEMINFO) == lpmii->cbSize)
    {
       MenuItem->Rect = lpmii->Rect;
-      MenuItem->XTab = lpmii->XTab;
-      lpmii->Text = MenuItem->Text.Buffer; /* Send back new allocated string or zero */
+      MenuItem->dxTab = lpmii->dxTab;
+      lpmii->lpstr = MenuItem->Text.Buffer; /* Use DesktopHeap! Send back new allocated string or zero */
    }
 
    return TRUE;
@@ -929,7 +855,7 @@ IntInsertMenuItem(PMENU_OBJECT MenuObject, UINT uItem, BOOL fByPosition,
 {
    int pos = (int)uItem;
    PMENU_ITEM MenuItem;
-   PMENU_OBJECT SubMenu;
+   PMENU_OBJECT SubMenu = NULL;
 
    if (MAX_MENU_ITEMS <= MenuObject->MenuInfo.MenuItemCount)
    {
@@ -950,6 +876,14 @@ IntInsertMenuItem(PMENU_OBJECT MenuObject, UINT uItem, BOOL fByPosition,
    {
       pos = IntGetMenuItemByFlag(MenuObject, uItem, MF_BYCOMMAND, &SubMenu, NULL, NULL);
    }
+   if (SubMenu == NULL)
+   {
+       /* default to last position of menu */
+      SubMenu = MenuObject;
+      pos = MenuObject->MenuInfo.MenuItemCount;
+   }
+
+
    if (pos < -1)
    {
       pos = -1;
@@ -974,7 +908,7 @@ IntInsertMenuItem(PMENU_OBJECT MenuObject, UINT uItem, BOOL fByPosition,
 
    if(!IntSetMenuItemInfo(SubMenu, MenuItem, ItemInfo))
    {
-      ExFreePool(MenuItem);
+      ExFreePoolWithTag(MenuItem, TAG_MENUITEM);
       return FALSE;
    }
 
@@ -1002,29 +936,18 @@ IntEnableMenuItem(PMENU_OBJECT MenuObject, UINT uIDEnableItem, UINT uEnable)
 
    if(uEnable & MF_DISABLED)
    {
-      if(!(MenuItem->fState & MF_DISABLED))
-         MenuItem->fState |= MF_DISABLED;
-      if(uEnable & MF_GRAYED)
-      {
-         if(!(MenuItem->fState & MF_GRAYED))
-            MenuItem->fState |= MF_GRAYED;
-      }
+      MenuItem->fState |= MF_DISABLED;
+      MenuItem->fState |= uEnable & MF_GRAYED;
    }
    else
    {
       if(uEnable & MF_GRAYED)
       {
-         if(!(MenuItem->fState & MF_GRAYED))
-            MenuItem->fState |= MF_GRAYED;
-         if(!(MenuItem->fState & MF_DISABLED))
-            MenuItem->fState |= MF_DISABLED;
+         MenuItem->fState |= (MF_GRAYED | MF_DISABLED);
       }
       else
       {
-         if(MenuItem->fState & MF_DISABLED)
-            MenuItem->fState ^= MF_DISABLED;
-         if(MenuItem->fState & MF_GRAYED)
-            MenuItem->fState ^= MF_GRAYED;
+         MenuItem->fState &= ~(MF_DISABLED | MF_GRAYED);
       }
    }
 
@@ -1073,13 +996,14 @@ IntBuildMenuItemList(PMENU_OBJECT MenuObject, PVOID Buffer, ULONG nMax)
          }
          mii.fState = CurItem->fState;
          mii.fType = CurItem->fType;
+         mii.wID = CurItem->wID;
          mii.hbmpChecked = CurItem->hbmpChecked;
          mii.hbmpItem = CurItem->hbmpItem;
          mii.hbmpUnchecked = CurItem->hbmpUnchecked;
          mii.hSubMenu = CurItem->hSubMenu;
          mii.Rect = CurItem->Rect;
-         mii.XTab = CurItem->XTab;
-         mii.Text = CurItem->Text.Buffer;
+         mii.dxTab = CurItem->dxTab;
+         mii.lpstr = CurItem->Text.Buffer; // Use DesktopHeap!
 
          Status = MmCopyToCaller(Buf, &mii, sizeof(ROSMENUITEMINFO));
          if (! NT_SUCCESS(Status))
@@ -1146,13 +1070,11 @@ IntCheckMenuItem(PMENU_OBJECT MenuObject, UINT uIDCheckItem, UINT uCheck)
    res = (DWORD)(MenuItem->fState & MF_CHECKED);
    if(uCheck & MF_CHECKED)
    {
-      if(!(MenuItem->fState & MF_CHECKED))
-         MenuItem->fState |= MF_CHECKED;
+      MenuItem->fState |= MF_CHECKED;
    }
    else
    {
-      if(MenuItem->fState & MF_CHECKED)
-         MenuItem->fState ^= MF_CHECKED;
+      MenuItem->fState &= ~MF_CHECKED;
    }
 
    return (DWORD)res;
@@ -1171,13 +1093,11 @@ IntHiliteMenuItem(PWINDOW_OBJECT WindowObject, PMENU_OBJECT MenuObject,
 
    if(uHilite & MF_HILITE)
    {
-      if(!(MenuItem->fState & MF_HILITE))
-         MenuItem->fState |= MF_HILITE;
+      MenuItem->fState |= MF_HILITE;
    }
    else
    {
-      if(MenuItem->fState & MF_HILITE)
-         MenuItem->fState ^= MF_HILITE;
+      MenuItem->fState &= ~MF_HILITE;
    }
 
    /* FIXME - update the window's menu */
@@ -1195,8 +1115,7 @@ UserSetMenuDefaultItem(PMENU_OBJECT MenuObject, UINT uItem, UINT fByPos)
    {
       while(MenuItem)
       {
-         if(MenuItem->fState & MFS_DEFAULT)
-            MenuItem->fState ^= MFS_DEFAULT;
+         MenuItem->fState &= ~MFS_DEFAULT;
          MenuItem = MenuItem->Next;
       }
       return TRUE;
@@ -1209,14 +1128,12 @@ UserSetMenuDefaultItem(PMENU_OBJECT MenuObject, UINT uItem, UINT fByPos)
       {
          if(pos == uItem)
          {
-            if(!(MenuItem->fState & MFS_DEFAULT))
-               MenuItem->fState |= MFS_DEFAULT;
+            MenuItem->fState |= MFS_DEFAULT;
             ret = TRUE;
          }
          else
          {
-            if(MenuItem->fState & MFS_DEFAULT)
-               MenuItem->fState ^= MFS_DEFAULT;
+            MenuItem->fState &= ~MFS_DEFAULT;
          }
          pos++;
          MenuItem = MenuItem->Next;
@@ -1228,14 +1145,12 @@ UserSetMenuDefaultItem(PMENU_OBJECT MenuObject, UINT uItem, UINT fByPos)
       {
          if(!ret && (MenuItem->wID == uItem))
          {
-            if(!(MenuItem->fState & MFS_DEFAULT))
-               MenuItem->fState |= MFS_DEFAULT;
+            MenuItem->fState |= MFS_DEFAULT;
             ret = TRUE;
          }
          else
          {
-            if(MenuItem->fState & MFS_DEFAULT)
-               MenuItem->fState ^= MFS_DEFAULT;
+            MenuItem->fState &= ~MFS_DEFAULT;
          }
          MenuItem = MenuItem->Next;
       }
@@ -1320,14 +1235,14 @@ co_IntExitTracking(PWINDOW_OBJECT Window, PMENU_OBJECT Menu, BOOL Popup,
 
 INT FASTCALL
 IntTrackMenu(PMENU_OBJECT Menu, PWINDOW_OBJECT Window, INT x, INT y,
-             RECT lprect)
+             RECTL lprect)
 {
    return 0;
 }
 
 BOOL FASTCALL
 co_IntTrackPopupMenu(PMENU_OBJECT Menu, PWINDOW_OBJECT Window,
-                     UINT Flags, POINT *Pos, UINT MenuPos, RECT *ExcludeRect)
+                     UINT Flags, POINT *Pos, UINT MenuPos, RECTL *ExcludeRect)
 {
    co_IntInitTracking(Window, Menu, TRUE, Flags);
 
@@ -1336,7 +1251,7 @@ co_IntTrackPopupMenu(PMENU_OBJECT Menu, PWINDOW_OBJECT Window,
 }
 
 BOOL FASTCALL
-IntSetMenuItemRect(PMENU_OBJECT Menu, UINT Item, BOOL fByPos, RECT *rcRect)
+IntSetMenuItemRect(PMENU_OBJECT Menu, UINT Item, BOOL fByPos, RECTL *rcRect)
 {
    PMENU_ITEM mi;
    if(IntGetMenuItemByFlag(Menu, Item, (fByPos ? MF_BYPOSITION : MF_BYCOMMAND),
@@ -1353,7 +1268,7 @@ IntSetMenuItemRect(PMENU_OBJECT Menu, UINT Item, BOOL fByPos, RECT *rcRect)
  * Internal function. Called when the process is destroyed to free the remaining menu handles.
 */
 BOOL FASTCALL
-IntCleanupMenus(struct _EPROCESS *Process, PW32PROCESS Win32Process)
+IntCleanupMenus(struct _EPROCESS *Process, PPROCESSINFO Win32Process)
 {
    PEPROCESS CurrentProcess;
    PLIST_ENTRY LastHead = NULL;
@@ -1381,6 +1296,146 @@ IntCleanupMenus(struct _EPROCESS *Process, PW32PROCESS Win32Process)
    return TRUE;
 }
 
+VOID APIENTRY
+co_InflateRect(RECTL *rect, int dx, int dy)
+{
+    rect->left -= dx;
+    rect->top -= dy;
+    rect->right += dx;
+    rect->bottom += dy;
+}
+
+BOOLEAN APIENTRY
+intGetTitleBarInfo(PWINDOW_OBJECT pWindowObject, PTITLEBARINFO bti)
+{
+
+    DWORD dwStyle = 0;
+    DWORD dwExStyle = 0;
+    BOOLEAN retValue = TRUE;
+
+    if (bti->cbSize == sizeof(TITLEBARINFO))
+    {
+        RtlZeroMemory(&bti->rgstate[0],sizeof(DWORD)*(CCHILDREN_TITLEBAR+1));
+
+        bti->rgstate[0] = STATE_SYSTEM_FOCUSABLE;
+
+        dwStyle = pWindowObject->Wnd->style;
+        dwExStyle = pWindowObject->Wnd->ExStyle;
+
+        bti->rcTitleBar.top  = 0;
+        bti->rcTitleBar.left = 0;
+        bti->rcTitleBar.right  = pWindowObject->Wnd->rcWindow.right - pWindowObject->Wnd->rcWindow.left;
+        bti->rcTitleBar.bottom = pWindowObject->Wnd->rcWindow.bottom - pWindowObject->Wnd->rcWindow.top;
+
+        /* is it iconiced ? */ 
+        if ((dwStyle & WS_ICONIC)!=WS_ICONIC)
+        {
+            /* Remove frame from rectangle */
+            if (HAS_THICKFRAME( dwStyle, dwExStyle ))
+            {
+                /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXFRAME) and UserGetSystemMetrics(SM_CYFRAME) */
+                co_InflateRect( &bti->rcTitleBar, -UserGetSystemMetrics(SM_CXFRAME), -UserGetSystemMetrics(SM_CYFRAME) );
+            }
+            else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
+            {
+                /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXDLGFRAME) and UserGetSystemMetrics(SM_CYDLGFRAME) */
+                co_InflateRect( &bti->rcTitleBar, -UserGetSystemMetrics(SM_CXDLGFRAME), -UserGetSystemMetrics(SM_CYDLGFRAME));
+            }
+            else if (HAS_THINFRAME( dwStyle, dwExStyle))
+            {
+                /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXBORDER) and UserGetSystemMetrics(SM_CYBORDER) */
+                co_InflateRect( &bti->rcTitleBar, -UserGetSystemMetrics(SM_CXBORDER), -UserGetSystemMetrics(SM_CYBORDER) );
+            }
+
+            /* We have additional border information if the window
+             * is a child (but not an MDI child) */
+            if ( (dwStyle & WS_CHILD)  &&
+                 ((dwExStyle & WS_EX_MDICHILD) == 0 ) )
+            {
+                if (dwExStyle & WS_EX_CLIENTEDGE)
+                {
+                    /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXEDGE) and UserGetSystemMetrics(SM_CYEDGE) */
+                    co_InflateRect (&bti->rcTitleBar, -UserGetSystemMetrics(SM_CXEDGE), -UserGetSystemMetrics(SM_CYEDGE));
+                }
+
+                if (dwExStyle & WS_EX_STATICEDGE)
+                {
+                    /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CXBORDER) and UserGetSystemMetrics(SM_CYBORDER) */
+                    co_InflateRect (&bti->rcTitleBar, -UserGetSystemMetrics(SM_CXBORDER), -UserGetSystemMetrics(SM_CYBORDER));
+                }
+            }
+        }
+
+        bti->rcTitleBar.top += pWindowObject->Wnd->rcWindow.top;
+        bti->rcTitleBar.left += pWindowObject->Wnd->rcWindow.left;
+        bti->rcTitleBar.right += pWindowObject->Wnd->rcWindow.left;
+
+        bti->rcTitleBar.bottom = bti->rcTitleBar.top;
+        if (dwExStyle & WS_EX_TOOLWINDOW)
+        {
+            /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CYSMCAPTION) */
+            bti->rcTitleBar.bottom += UserGetSystemMetrics(SM_CYSMCAPTION);
+        }
+        else 
+        {
+            /* FIXME : Note this value should exists in pWindowObject for UserGetSystemMetrics(SM_CYCAPTION) and UserGetSystemMetrics(SM_CXSIZE) */
+            bti->rcTitleBar.bottom += UserGetSystemMetrics(SM_CYCAPTION);
+            bti->rcTitleBar.left += UserGetSystemMetrics(SM_CXSIZE);
+        }
+
+        if (dwStyle & WS_CAPTION) 
+        {
+            bti->rgstate[1] = STATE_SYSTEM_INVISIBLE;
+            if (dwStyle & WS_SYSMENU) 
+            {
+                if (!(dwStyle & (WS_MINIMIZEBOX|WS_MAXIMIZEBOX))) 
+                {
+                    bti->rgstate[2] = STATE_SYSTEM_INVISIBLE;
+                    bti->rgstate[3] = STATE_SYSTEM_INVISIBLE;
+                }
+                else 
+                {
+                    if (!(dwStyle & WS_MINIMIZEBOX))
+                    {
+                        bti->rgstate[2] = STATE_SYSTEM_UNAVAILABLE;
+                    }
+                    if (!(dwStyle & WS_MAXIMIZEBOX))
+                    {
+                        bti->rgstate[3] = STATE_SYSTEM_UNAVAILABLE;
+                    }
+                }
+
+                if (!(dwExStyle & WS_EX_CONTEXTHELP))
+                {
+                    bti->rgstate[4] = STATE_SYSTEM_INVISIBLE;
+                }
+                if (pWindowObject->Wnd->pcls->style & CS_NOCLOSE)
+                {
+                    bti->rgstate[5] = STATE_SYSTEM_UNAVAILABLE;
+                }
+            }
+            else 
+            {
+                bti->rgstate[2] = STATE_SYSTEM_INVISIBLE;
+                bti->rgstate[3] = STATE_SYSTEM_INVISIBLE;
+                bti->rgstate[4] = STATE_SYSTEM_INVISIBLE;
+                bti->rgstate[5] = STATE_SYSTEM_INVISIBLE;
+            }
+        }
+        else
+        {
+            bti->rgstate[0] |= STATE_SYSTEM_INVISIBLE;
+        }
+    }
+    else
+    {
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        retValue = FALSE;
+    }
+
+    return retValue;
+}
+
 /* FUNCTIONS *****************************************************************/
 
 
@@ -1388,7 +1443,7 @@ IntCleanupMenus(struct _EPROCESS *Process, PW32PROCESS Win32Process)
  * @implemented
  */
 DWORD
-STDCALL
+APIENTRY
 NtUserBuildMenuItemList(
    HMENU hMenu,
    VOID* Buffer,
@@ -1428,7 +1483,7 @@ CLEANUP:
 /*
  * @implemented
  */
-DWORD STDCALL
+DWORD APIENTRY
 NtUserCheckMenuItem(
    HMENU hMenu,
    UINT uIDCheckItem,
@@ -1458,6 +1513,7 @@ HMENU FASTCALL UserCreateMenu(BOOL PopupMenu)
 {
    PWINSTATION_OBJECT WinStaObject;
    HANDLE Handle;
+   PMENU_OBJECT Menu;
    NTSTATUS Status;
    PEPROCESS CurrentProcess = PsGetCurrentProcess();
 
@@ -1480,14 +1536,15 @@ HMENU FASTCALL UserCreateMenu(BOOL PopupMenu)
           SetLastNtError(Status);
           return (HMENU)0;
        }
-       IntCreateMenu(&Handle, !PopupMenu);
+       Menu = IntCreateMenu(&Handle, !PopupMenu);
        ObDereferenceObject(WinStaObject);
    }
    else
    {
-       IntCreateMenu(&Handle, !PopupMenu);
+       Menu = IntCreateMenu(&Handle, !PopupMenu);
    }
 
+   if (Menu) UserDereferenceObject(Menu);
    return (HMENU)Handle;
 }
 
@@ -1495,7 +1552,7 @@ HMENU FASTCALL UserCreateMenu(BOOL PopupMenu)
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserDeleteMenu(
    HMENU hMenu,
    UINT uPosition,
@@ -1520,6 +1577,73 @@ CLEANUP:
    END_CLEANUP;
 }
 
+/*
+ * @implemented
+ */
+BOOLEAN APIENTRY
+NtUserGetTitleBarInfo(
+    HWND hwnd,
+    PTITLEBARINFO bti)
+{
+    PWINDOW_OBJECT WindowObject;
+    TITLEBARINFO bartitleinfo;
+    DECLARE_RETURN(BOOLEAN);
+    BOOLEAN retValue = TRUE;
+
+    DPRINT("Enter NtUserGetTitleBarInfo\n");
+    UserEnterExclusive();
+
+    /* Vaildate the windows handle */
+    if (!(WindowObject = UserGetWindowObject(hwnd)))
+    {
+        SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
+        retValue = FALSE;
+    }
+
+    _SEH2_TRY
+    {
+        /* Copy our usermode buffer bti to local buffer bartitleinfo */
+        ProbeForRead(bti, sizeof(TITLEBARINFO), 1);
+        RtlCopyMemory(&bartitleinfo, bti, sizeof(TITLEBARINFO));
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        /* Fail copy the data */ 
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        retValue = FALSE;
+    }
+    _SEH2_END
+
+    /* Get the tile bar info */ 
+    if (retValue)
+    {
+        retValue = intGetTitleBarInfo(WindowObject, &bartitleinfo);
+        if (retValue)
+        {
+            _SEH2_TRY
+            {
+                /* Copy our buffer to user mode buffer bti */
+                ProbeForWrite(bti, sizeof(TITLEBARINFO), 1);
+                RtlCopyMemory(bti, &bartitleinfo, sizeof(TITLEBARINFO));
+            }
+            _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+            {
+                /* Fail copy the data */ 
+                SetLastWin32Error(ERROR_INVALID_PARAMETER);
+                retValue = FALSE;
+            }
+            _SEH2_END
+        }
+    }
+
+    RETURN( retValue );
+
+CLEANUP:
+    DPRINT("Leave NtUserGetTitleBarInfo, ret=%i\n",_ret_);
+    UserLeave();
+    END_CLEANUP;
+}
+
 
 
 /*
@@ -1546,7 +1670,7 @@ BOOL FASTCALL UserDestroyMenu(HMENU hMenu)
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserDestroyMenu(
    HMENU hMenu)
 {
@@ -1567,7 +1691,7 @@ NtUserDestroyMenu(
       RETURN( FALSE);
    }
 
-   RETURN( IntDestroyMenuObject(Menu, FALSE, TRUE));
+   RETURN( IntDestroyMenuObject(Menu, TRUE, TRUE));
 
 CLEANUP:
    DPRINT("Leave NtUserDestroyMenu, ret=%i\n",_ret_);
@@ -1579,7 +1703,7 @@ CLEANUP:
 /*
  * @implemented
  */
-UINT STDCALL
+UINT APIENTRY
 NtUserEnableMenuItem(
    HMENU hMenu,
    UINT uIDEnableItem,
@@ -1608,8 +1732,8 @@ CLEANUP:
 /*
  * @implemented
  */
-DWORD STDCALL
-NtUserInsertMenuItem(
+DWORD APIENTRY
+UserInsertMenuItem(
    HMENU hMenu,
    UINT uItem,
    BOOL fByPosition,
@@ -1620,7 +1744,7 @@ NtUserInsertMenuItem(
    ROSMENUITEMINFO ItemInfo;
    DECLARE_RETURN(DWORD);
 
-   DPRINT("Enter NtUserInsertMenuItem\n");
+   DPRINT("Enter UserInsertMenuItem\n");
    UserEnterExclusive();
 
    if(!(Menu = UserGetMenuObject(hMenu)))
@@ -1658,7 +1782,7 @@ NtUserInsertMenuItem(
    RETURN( FALSE);
 
 CLEANUP:
-   DPRINT("Leave NtUserInsertMenuItem, ret=%i\n",_ret_);
+   DPRINT("Leave UserInsertMenuItem, ret=%i\n",_ret_);
    UserLeave();
    END_CLEANUP;
 }
@@ -1667,7 +1791,7 @@ CLEANUP:
 /*
  * @unimplemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserEndMenu(VOID)
 {
    UNIMPLEMENTED
@@ -1679,7 +1803,7 @@ NtUserEndMenu(VOID)
 /*
  * @implemented
  */
-UINT STDCALL
+UINT APIENTRY
 NtUserGetMenuDefaultItem(
    HMENU hMenu,
    UINT fByPos,
@@ -1709,7 +1833,7 @@ CLEANUP:
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserGetMenuBarInfo(
    HWND hwnd,
    LONG idObject,
@@ -1722,7 +1846,7 @@ NtUserGetMenuBarInfo(
    PWINDOW_OBJECT WindowObject;
    HMENU hMenu;
    POINT Offset;
-   RECT Rect;
+   RECTL Rect;
    MENUBARINFO kmbi;
    DECLARE_RETURN(BOOL);
 
@@ -1735,7 +1859,7 @@ NtUserGetMenuBarInfo(
         RETURN(FALSE);
      }
 
-   hMenu = (HMENU)WindowObject->IDMenu;
+   hMenu = (HMENU)(DWORD_PTR)WindowObject->Wnd->IDMenu;
 
    if (!(MenuObject = UserGetMenuObject(hMenu)))
      {
@@ -1925,7 +2049,7 @@ CLEANUP:
 /*
  * @unimplemented
  */
-UINT STDCALL
+UINT APIENTRY
 NtUserGetMenuIndex(
    HMENU hMenu,
    UINT wID)
@@ -1939,16 +2063,17 @@ NtUserGetMenuIndex(
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserGetMenuItemRect(
    HWND hWnd,
    HMENU hMenu,
    UINT uItem,
-   LPRECT lprcItem)
+   PRECTL lprcItem)
 {
    ROSMENUINFO mi;
-   HWND referenceHwnd;
-   RECT Rect;
+   PWINDOW_OBJECT ReferenceWnd;
+   LONG XMove, YMove;
+   RECTL Rect;
    NTSTATUS Status;
    PMENU_OBJECT Menu;
    PMENU_ITEM MenuItem;
@@ -1967,19 +2092,33 @@ NtUserGetMenuItemRect(
    else
       RETURN(FALSE);
 
-   referenceHwnd = hWnd;
-
    if(!hWnd)
    {
       if(!UserMenuInfo(Menu, &mi, FALSE))
          RETURN( FALSE);
       if(mi.Wnd == 0)
          RETURN( FALSE);
-      referenceHwnd = mi.Wnd; /* Okay we found it, so now what do we do? */
    }
 
-   if (lprcItem == NULL)
-      RETURN( FALSE);
+   if (lprcItem == NULL) RETURN( FALSE);
+
+   if (!(ReferenceWnd = UserGetWindowObject(mi.Wnd))) RETURN( FALSE);
+
+   if(MenuItem->fType & MF_POPUP)
+   {
+     XMove = ReferenceWnd->Wnd->rcClient.left;
+     YMove = ReferenceWnd->Wnd->rcClient.top;
+   }
+   else
+   {
+     XMove = ReferenceWnd->Wnd->rcWindow.left;
+     YMove = ReferenceWnd->Wnd->rcWindow.top;
+   }
+
+   Rect.left   += XMove;
+   Rect.top    += YMove;
+   Rect.right  += XMove;
+   Rect.bottom += YMove;
 
    Status = MmCopyToCaller(lprcItem, &Rect, sizeof(RECT));
    if (! NT_SUCCESS(Status))
@@ -1999,7 +2138,7 @@ CLEANUP:
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserHiliteMenuItem(
    HWND hWnd,
    HMENU hMenu,
@@ -2023,7 +2162,7 @@ NtUserHiliteMenuItem(
       RETURN(FALSE);
    }
 
-   if(Window->IDMenu == (UINT)hMenu)
+   if(Window->Wnd->IDMenu == (UINT)(UINT_PTR)hMenu)
    {
       RETURN( IntHiliteMenuItem(Window, Menu, uItemHilite, uHilite));
    }
@@ -2098,7 +2237,7 @@ UserMenuInfo(
  * @implemented
  */
 BOOL
-STDCALL
+APIENTRY
 NtUserMenuInfo(
    HMENU hMenu,
    PROSMENUINFO UnsafeMenuInfo,
@@ -2128,7 +2267,7 @@ CLEANUP:
 /*
  * @implemented
  */
-int STDCALL
+int APIENTRY
 NtUserMenuItemFromPoint(
    HWND hWnd,
    HMENU hMenu,
@@ -2154,8 +2293,8 @@ NtUserMenuItemFromPoint(
       RETURN( -1);
    }
 
-   X -= Window->WindowRect.left;
-   Y -= Window->WindowRect.top;
+   X -= Window->Wnd->rcWindow.left;
+   Y -= Window->Wnd->rcWindow.top;
 
    mi = Menu->MenuItemList;
    for (i = 0; NULL != mi; i++)
@@ -2255,7 +2394,7 @@ UserMenuItemInfo(
  * @implemented
  */
 BOOL
-STDCALL
+APIENTRY
 NtUserMenuItemInfo(
    HMENU hMenu,
    UINT Item,
@@ -2287,7 +2426,7 @@ CLEANUP:
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserRemoveMenu(
    HMENU hMenu,
    UINT uPosition,
@@ -2317,7 +2456,7 @@ CLEANUP:
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserSetMenuContextHelpId(
    HMENU hMenu,
    DWORD dwContextHelpId)
@@ -2346,7 +2485,7 @@ CLEANUP:
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserSetMenuDefaultItem(
    HMENU hMenu,
    UINT uItem,
@@ -2375,7 +2514,7 @@ CLEANUP:
 /*
  * @implemented
  */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserSetMenuFlagRtoL(
    HMENU hMenu)
 {
@@ -2402,7 +2541,7 @@ CLEANUP:
 /*
  * @unimplemented
  */
-DWORD STDCALL
+DWORD APIENTRY
 NtUserThunkedMenuInfo(
    HMENU hMenu,
    LPCMENUINFO lpcmi)
@@ -2416,7 +2555,7 @@ NtUserThunkedMenuInfo(
 /*
  * @unimplemented
  */
-DWORD STDCALL
+DWORD APIENTRY
 NtUserThunkedMenuItemInfo(
    HMENU hMenu,
    UINT uItem,
@@ -2425,10 +2564,13 @@ NtUserThunkedMenuItemInfo(
    LPMENUITEMINFOW lpmii,
    PUNICODE_STRING lpszCaption)
 {
-   UNIMPLEMENTED
+
    /* lpszCaption may be NULL, check for it and call RtlInitUnicodeString()
-      if bInsert == TRUE call NtUserInsertMenuItem() else NtUserSetMenuItemInfo()
-   */
+      if bInsert == TRUE call NtUserInsertMenuItem() else NtUserSetMenuItemInfo()   */
+
+   if (bInsert) return UserInsertMenuItem(hMenu, uItem, fByPosition, lpmii);
+
+   UNIMPLEMENTED
    return 0;
 }
 
@@ -2437,7 +2579,7 @@ NtUserThunkedMenuItemInfo(
  * @implemented
  */
 /* NOTE: unused function */
-BOOL STDCALL
+BOOL APIENTRY
 NtUserTrackPopupMenuEx(
    HMENU hMenu,
    UINT fuFlags,