[Win32k|User32]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / menu.c
index 41f0676..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
@@ -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,9 +179,9 @@ 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;
 }
@@ -292,6 +273,7 @@ IntDestroyMenuObject(PMENU_OBJECT Menu,
                                          NULL);
       if(NT_SUCCESS(Status))
       {
+         BOOL ret;
          if (Menu->MenuInfo.Wnd)
          {
             Window = UserGetWindowObject(Menu->MenuInfo.Wnd);
@@ -301,7 +283,7 @@ IntDestroyMenuObject(PMENU_OBJECT Menu,
             }
          }
 //         UserDereferenceObject(Menu);
-         BOOL ret = UserDeleteObject(Menu->MenuInfo.Self, otMenu);
+         ret = UserDeleteObject(Menu->MenuInfo.Self, otMenu);
          ObDereferenceObject(WindowStation);
          return ret;
       }
@@ -313,12 +295,13 @@ PMENU_OBJECT FASTCALL
 IntCreateMenu(PHANDLE Handle, BOOL IsMenuBar)
 {
    PMENU_OBJECT Menu;
-   PW32PROCESS CurrentWin32Process;
-
-   Menu = (PMENU_OBJECT)UserCreateObject(
-             gHandleTable, Handle,
-             otMenu, sizeof(MENU_OBJECT));
+   PPROCESSINFO CurrentWin32Process;
 
+   Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable,
+                                          NULL,
+                                          Handle,
+                                          otMenu,
+                                          sizeof(MENU_OBJECT));
    if(!Menu)
    {
       *Handle = 0;
@@ -418,17 +401,18 @@ IntCloneMenuItems(PMENU_OBJECT Destination, PMENU_OBJECT Source)
 PMENU_OBJECT FASTCALL
 IntCloneMenu(PMENU_OBJECT Source)
 {
-   PW32PROCESS CurrentWin32Process;
+   PPROCESSINFO CurrentWin32Process;
    HANDLE hMenu;
    PMENU_OBJECT Menu;
 
    if(!Source)
       return NULL;
 
-   Menu = (PMENU_OBJECT)UserCreateObject(
-             gHandleTable, &hMenu,
-             otMenu, sizeof(MENU_OBJECT));
-
+   Menu = (PMENU_OBJECT)UserCreateObject( gHandleTable,
+                                          NULL,
+                                         &hMenu,
+                                          otMenu,
+                                          sizeof(MENU_OBJECT));
    if(!Menu)
       return NULL;
 
@@ -502,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)
 {
@@ -609,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);
@@ -720,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;
@@ -872,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;
@@ -1026,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))
@@ -1264,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);
 
@@ -1280,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),
@@ -1297,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;
@@ -1326,7 +1297,7 @@ IntCleanupMenus(struct _EPROCESS *Process, PW32PROCESS Win32Process)
 }
 
 VOID APIENTRY
-co_InflateRect(LPRECT rect, int dx, int dy)
+co_InflateRect(RECTL *rect, int dx, int dy)
 {
     rect->left -= dx;
     rect->top -= dy;
@@ -1348,13 +1319,13 @@ intGetTitleBarInfo(PWINDOW_OBJECT pWindowObject, PTITLEBARINFO bti)
 
         bti->rgstate[0] = STATE_SYSTEM_FOCUSABLE;
 
-        dwStyle = pWindowObject->Wnd->Style;
+        dwStyle = pWindowObject->Wnd->style;
         dwExStyle = pWindowObject->Wnd->ExStyle;
 
         bti->rcTitleBar.top  = 0;
         bti->rcTitleBar.left = 0;
-        bti->rcTitleBar.right  = pWindowObject->Wnd->WindowRect.right - pWindowObject->Wnd->WindowRect.left;
-        bti->rcTitleBar.bottom = pWindowObject->Wnd->WindowRect.bottom - pWindowObject->Wnd->WindowRect.top;
+        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)
@@ -1395,9 +1366,9 @@ intGetTitleBarInfo(PWINDOW_OBJECT pWindowObject, PTITLEBARINFO bti)
             }
         }
 
-        bti->rcTitleBar.top += pWindowObject->Wnd->WindowRect.top;
-        bti->rcTitleBar.left += pWindowObject->Wnd->WindowRect.left;
-        bti->rcTitleBar.right += pWindowObject->Wnd->WindowRect.left;
+        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)
@@ -1438,7 +1409,7 @@ intGetTitleBarInfo(PWINDOW_OBJECT pWindowObject, PTITLEBARINFO bti)
                 {
                     bti->rgstate[4] = STATE_SYSTEM_INVISIBLE;
                 }
-                if (pWindowObject->Wnd->Class->Style & CS_NOCLOSE)
+                if (pWindowObject->Wnd->pcls->style & CS_NOCLOSE)
                 {
                     bti->rgstate[5] = STATE_SYSTEM_UNAVAILABLE;
                 }
@@ -1566,15 +1537,14 @@ HMENU FASTCALL UserCreateMenu(BOOL PopupMenu)
           return (HMENU)0;
        }
        Menu = IntCreateMenu(&Handle, !PopupMenu);
-       UserDereferenceObject(Menu);
        ObDereferenceObject(WinStaObject);
    }
    else
    {
        Menu = IntCreateMenu(&Handle, !PopupMenu);
-       UserDereferenceObject(Menu);
    }
 
+   if (Menu) UserDereferenceObject(Menu);
    return (HMENU)Handle;
 }
 
@@ -1876,7 +1846,7 @@ NtUserGetMenuBarInfo(
    PWINDOW_OBJECT WindowObject;
    HMENU hMenu;
    POINT Offset;
-   RECT Rect;
+   RECTL Rect;
    MENUBARINFO kmbi;
    DECLARE_RETURN(BOOL);
 
@@ -2098,12 +2068,12 @@ NtUserGetMenuItemRect(
    HWND hWnd,
    HMENU hMenu,
    UINT uItem,
-   LPRECT lprcItem)
+   PRECTL lprcItem)
 {
    ROSMENUINFO mi;
    PWINDOW_OBJECT ReferenceWnd;
    LONG XMove, YMove;
-   RECT Rect;
+   RECTL Rect;
    NTSTATUS Status;
    PMENU_OBJECT Menu;
    PMENU_ITEM MenuItem;
@@ -2136,13 +2106,13 @@ NtUserGetMenuItemRect(
 
    if(MenuItem->fType & MF_POPUP)
    {
-     XMove = ReferenceWnd->Wnd->ClientRect.left;
-     YMove = ReferenceWnd->Wnd->ClientRect.top;
+     XMove = ReferenceWnd->Wnd->rcClient.left;
+     YMove = ReferenceWnd->Wnd->rcClient.top;
    }
    else
    {
-     XMove = ReferenceWnd->Wnd->WindowRect.left;
-     YMove = ReferenceWnd->Wnd->WindowRect.top;
+     XMove = ReferenceWnd->Wnd->rcWindow.left;
+     YMove = ReferenceWnd->Wnd->rcWindow.top;
    }
 
    Rect.left   += XMove;
@@ -2323,8 +2293,8 @@ NtUserMenuItemFromPoint(
       RETURN( -1);
    }
 
-   X -= Window->Wnd->WindowRect.left;
-   Y -= Window->Wnd->WindowRect.top;
+   X -= Window->Wnd->rcWindow.left;
+   Y -= Window->Wnd->rcWindow.top;
 
    mi = Menu->MenuItemList;
    for (i = 0; NULL != mi; i++)